// Add Script
(function ($) {
  ("use strict");

  /*
  function getHeaderHeight() {
    var header_height = $(".okta-header").height();
    $(".okta-slider").css({ top: +header_height });
  }
  getHeaderHeight();
  */

  jQuery(document).ready(function ($) {
    // Open Offcanvas
    $(document).on("click", ".okta-offcanvas-toggle", function () {
      jQuery(".okta-wrapper").addClass("offcanvas-open");
      jQuery(".okta-offcanvas-toggle").addClass("active");
      jQuery(".okta-offcanvas").addClass("open");
    });

    // Close Offcanvas
    $(document).on("click", ".toggler-close", function () {
      if (jQuery(".okta-offcanvas").hasClass("open")) {
        jQuery(".okta-offcanvas").removeClass("open");
        jQuery(".okta-wrapper").removeClass("offcanvas-open");
      }
    });

    $(document).on("click", ".okta-wrapper.offcanvas-open", function () {
      if (jQuery(".okta-offcanvas").hasClass("open")) {
        jQuery(".okta-offcanvas").removeClass("open");
        jQuery(".okta-wrapper").removeClass("offcanvas-open");
      }
    });

    /**
     * Back-to-top action: scroll back to top
     */
    $("body").on("click", "#back-to-top", function () {
      $("body,html,.okta-wrapper").animate(
        {
          scrollTop: 0,
        },
        500
      );
      return false;
    });

    // Loader
    $(document).ready(function () {
      setTimeout(() => {
        $("#loader").fadeToggle(250);
      }, 800); // hide delay when page load
    });

    // Go Back
    $(".goBack").click(function () {
      window.history.back();
    });

    // Tooltip
    $(function () {
      $('[data-bs-toggle="tooltip"]').tooltip();
    });
  });

  /*********************************************
   * Button
   **********************************************/
  $(document).ready(function () {
    // $("#qty_input").prop("disabled", true);
    $("#plus-btn").click(function () {
      $("#qty_input").val(parseInt($("#qty_input").val()) + 1);
    });
    $("#minus-btn").click(function () {
      $("#qty_input").val(parseInt($("#qty_input").val()) - 1);
      if ($("#qty_input").val() == 0) {
        $("#qty_input").val(1);
      }
    });
  });

  $(document).ready(function () {
    //Submit
    $("#add-to-cart").on("click", function (e) {
      e.preventDefault();
      const oktaAdd = document.querySelector("#add-to-cart");
      $(oktaAdd).find("#addtocart").addClass("d-none").removeClass("d-block");
      $(oktaAdd).find("#adding").addClass("d-block").removeClass("d-none");

      setInterval(function () {
        $(oktaAdd).find("#adding").addClass("d-none").removeClass("d-block");
        $(oktaAdd).find("#added").addClass("d-block").removeClass("d-none");
      }, 2000); // 2 detik
    });
  });
})(jQuery);
