/* 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 $form = $("#instructorRegisterForm");
    const $feedback = $("#formFeedback");

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

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

	  if (!this.checkValidity()) {
		e.preventDefault();   // stop only when invalid
		e.stopPropagation();
	
		$form.addClass("was-validated");
	
		$feedback
		  .removeClass("d-none alert-success")
		  .addClass("alert-danger")
		  .text("All Fields Are Required.");
	
		return;
	  }
	
	  // if valid allow submission
	  $form.addClass("was-validated");
	
	});
  });
})(jQuery);
