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

  function closeSidebar() {
    $("body").removeClass("sidebar-open");
  }

  $(function () {
    // Mobile sidebar controls
    $("#openSidebar").on("click", function () {
      $("body").addClass("sidebar-open");
    });

    $("#closeSidebar, #sidebarOverlay").on("click", function () {
      closeSidebar();
    });

    // Active state for primary nav links (static demo behavior)
    $(".menu-link").on("click", function (e) {
      e.preventDefault();
      $(".menu-link").removeClass("is-active");
      $(this).addClass("is-active");
      closeSidebar();
    });

    // Reset sidebar state when returning to desktop
    $(window).on("resize", function () {
      if (window.matchMedia("(min-width: 992px)").matches) {
        closeSidebar();
      }
    });
  });
})(jQuery);




(function ($) {
  "use strict";

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

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

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

      if (!this.checkValidity()) {
        e.stopPropagation();
        $form.addClass("was-validated");

        $feedback
          .removeClass("d-none alert-success")
          .addClass("alert-danger")
          .text("All Fields Are Required.");

        return;
      }

      if (newPass !== cnfPass) {

        $("#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 changed successfully.");

      this.submit();
    });

    $("#cnfpassword").on("keyup", function () {
      if ($("#newpassword").val() === $("#cnfpassword").val()) {
        $("#cnfpassword").removeClass("is-invalid");
        $("#formFeedback").addClass("d-none");
      }
    });

  });

})(jQuery);