/* global jQuery */
(function ($) {
  "use strict";

  function togglePassword(selector, $btn) {
    const $input = $(selector);
    if (!$input.length) return;
    const isPassword = $input.attr("type") === "password";
    $input.attr("type", isPassword ? "text" : "password");
    $btn.find("i").attr("class", isPassword ? "bi bi-eye-slash" : "bi bi-eye");
  }

  $(function () {
    const $registerForm = $("#kidsRegisterForm");
    const $loginForm = $("#kidsLoginForm");
    const $feedback = $("#formFeedback");

    $(".toggle-pass").on("click", function () {
      togglePassword($(this).data("target"), $(this));
    });

    $registerForm.on("submit", function (e) {
	  if (!this.checkValidity()) {
		e.preventDefault();
		e.stopPropagation();
		$registerForm.addClass("was-validated");
		$feedback
		  .removeClass("d-none alert-success")
		  .addClass("alert-danger")
		  .text("All Fields Required.");
	
		return;
	  }
	  $registerForm.addClass("was-validated");
	});

    $loginForm.on("submit", function (e) 
	{
		if (!this.checkValidity()) {
			e.preventDefault();
			e.stopPropagation();
			$loginForm.addClass("was-validated");
			$feedback
			  .removeClass("d-none alert-success")
			  .addClass("alert-danger")
			  .text("Enter Your Email And Password.");
			return;
		  }
		  
		  $loginForm.addClass("was-validated");
		
		});
	
  });
})(jQuery);


(function ($) {
  "use strict";

  $(function () {

    const $form = $("#change_password");
    const $feedback = $("#formFeedback");

    $form.on("submit", function (e) {

      const newPass = $("#newpassword").val();
      const cnfPass = $("#cnfpassword").val();

      if (!this.checkValidity()) {

        e.preventDefault();
        e.stopPropagation();

        $form.addClass("was-validated");

        $feedback
          .removeClass("d-none alert-success")
          .addClass("alert-danger")
          .text("All fields are required.");

        return;
      }

      if (newPass !== cnfPass) {

        e.preventDefault();

        $("#cnfpassword").focus().addClass("is-invalid");

        $feedback
          .removeClass("d-none alert-success")
          .addClass("alert-danger")
          .text("New Password and Confirm Password do not match.");

        return;
      }

      $("#cnfpassword").removeClass("is-invalid");

      $feedback
        .removeClass("d-none alert-danger")
        .addClass("alert-success")
        .text("Password validation successful.");

    });

    $("#cnfpassword").on("keyup", function () {

      if ($("#newpassword").val() === $("#cnfpassword").val()) {

        $("#cnfpassword").removeClass("is-invalid");
        $("#formFeedback").addClass("d-none");

      }

    });

  });

})(jQuery);
