document.addEventListener('DOMContentLoaded', function() {
  // Check device type
  const isMobile = window.matchMedia('(max-width: 767px)').matches;
  const isTablet = window.matchMedia('(min-width: 768px) and (max-width: 1024px)').matches;
  const isDesktop = !isMobile && !isTablet;

  // Find all Elementor sections with visibility classes
  document.querySelectorAll('.elementor-section').forEach(section => {
    const isHiddenOnThisDevice = 
      (isMobile && section.classList.contains('elementor-hidden-mobile')) ||
      (isTablet && section.classList.contains('elementor-hidden-tablet')) ||
      (isDesktop && section.classList.contains('elementor-hidden-desktop'));

    if (isHiddenOnThisDevice) {
      // Remove content to prevent loading assets
      section.style.display = 'none';
      
      // Optionally, store HTML for later loading
      section.setAttribute('data-lazy-content', section.innerHTML);
      section.innerHTML = ''; // Clear to prevent image/iframe loading
    }
  });
});

jQuery(document).ready(function($) {

  // call init function
  initSwipers();

  function initSwipers(selector = "[data-swiper]") {
    let swipers = document.querySelectorAll(selector);
    swipers.forEach((swiper) => {
      // get options
      let optionsData = swiper.dataset.swiper
        ? JSON.parse(swiper.dataset.swiper)
        : {};
      // init
      new Swiper(swiper, optionsData);
    });
  }



  /*!
    * add to cart js
    */
  jQuery("#tab-more_seller_product .col-sm-6.col-lg-4:nth-child(1),#tab-more_seller_product .col-sm-6.col-lg-4:nth-child(2),#tab-more_seller_product .col-sm-6.col-lg-4:nth-child(3),#tab-more_seller_product .col-sm-6.col-lg-4:nth-child(4),#tab-more_seller_product .col-sm-6.col-lg-4:nth-child(5),#tab-more_seller_product .col-sm-6.col-lg-4:nth-child(6)").wrapAll('<div class="row mt-4"></div>');
  jQuery("#tab-more_seller_product .col-sm-6.col-lg-4").removeClass("col-lg-4").addClass("col-lg-3");

  jQuery('#theOutput').keypress(function (e) {
    if (e.which == 13) return false;
  });

  jQuery('#maninpu').keypress(function (e) {
    if (e.which == 13) return false;
  });

  jQuery('#butno').click(function () {
    // custom handling here
    return false;
  });


  if (document.querySelector('.vsup')) {
    jQuery('.wpcvs-term span').click(function () {
      var ariaLabel = jQuery(this).closest('.wpcvs-term').attr('aria-label');
      var amir2 = jQuery('.wpcvs-term[aria-label="' + ariaLabel + '"]')[1];
      amir2.click();

      // Get the first div
      var firstDiv = jQuery(".woocommerce-variation-price");

      // Get all the children of the first div and clone them
      var children = firstDiv.children().clone();

      // Get the second div
      var secondDiv = jQuery(".price.d-flex.align-items-center.mt-3.mt-sm-0");

      if (jQuery('.woocommerce-variation-price').find('.woocommerce-Price-amount.amount').length > 0) {
        // Append the cloned children of the first div to the second div
        jQuery(secondDiv).html(children);
      }
    });
  }

  if (document.querySelector('.detail-product-three')) {
    jQuery('.variations').on('change', function () {
      // Run your code here to handle the changes
      // Get the first div
      var firstDiv = jQuery(".woocommerce-variation-price");

      // Get all the children of the first div and clone them
      var children = firstDiv.children().clone();

      // Get the second div
      var secondDiv = jQuery(".price.d-flex.align-items-center.mt-3.mt-sm-0");

      if (jQuery('.woocommerce-variation-price').find('.woocommerce-Price-amount.amount').length > 0) {
        // Append the cloned children of the first div to the second div
        jQuery(secondDiv).html(children);
      }

    });
  }


  // Open Cart Sliding
  const btnCartSliding = document.querySelectorAll('[data-open-cart="true"]'),
    cartSliding = document.querySelector("body .cart-sliding"),
    closeCartSliding = document.querySelector(
      "body .cart-sliding-backdrop"
    )

  if (btnCartSliding.length > 0) {
    btnCartSliding.forEach((btn) => {
      btn.addEventListener("click", (ev) => {
        ev.preventDefault();
        cartSliding.classList.add("opened");
      });
    });
  }

  if (closeCartSliding) {
    closeCartSliding.addEventListener("click", () => {
      cartSliding.classList.remove("opened");
    });
  }


  document.addEventListener('click', event => {
    const clickedElement = event.target;

    if (clickedElement.matches('body .cart-sliding .btn .icon-close')) {
      // Code to execute when the close button is clicked
      cartSliding.classList.remove('opened');
    }
  });


  



  
  /*!
    * Main JS
    */

  const htmlTag = document.documentElement;


  // Nav Responsive
  const btnNavRes = document.querySelector('.btn-nav-kheader'),
    navRes = document.querySelector('.nav-mobile-six-menu'),
    navResitemsHasChild = document.querySelectorAll('.nav-mobile-six-menu-content .menu li.has-child > a'),
    navResbackBtn = document.querySelectorAll('.nav-mobile-six-menu-content .menu li ul li.back'),
    navResSocials = document.querySelector('.nav-mobile-six-menu-socials'),
    navResBottom = document.querySelector('.nav-mobile-six-bottom');
  navkBottom = document.querySelector('.nav-bottom');
  senav = document.querySelector('.nav-mobile-eight-down');
  senavcontainer = document.querySelector('.mykheader');
  navbackdropm = document.querySelector('.nav-mobile-six-menu-backdrop');

  if (navbackdropm) {
    navbackdropm.addEventListener('click', () => {
      document.querySelector('html').classList.toggle('overflow-hidden');
      navRes.classList.toggle('opened');
      navResBottom.classList.toggle('opened');
      navkBottom.classList.toggle('d-none');
      senav.classList.toggle('d-none');
      senavcontainer.style.padding = '18px 10px';
    })
  }

  if (btnNavRes) {
    btnNavRes.addEventListener('click', () => {
      document.querySelector('html').classList.toggle('overflow-hidden');
      navRes.classList.toggle('opened');
      navResBottom.classList.toggle('opened');
      navkBottom.classList.toggle('d-none');
      senav.classList.toggle('d-none');
      
    })
  }

  if (navResitemsHasChild.length > 0) {
    navResitemsHasChild.forEach(item => {
      item.addEventListener('click', (ev) => {
        ev.preventDefault();

        const el = ev.currentTarget,
          content = el.nextElementSibling;

        if (content) {
          content.classList.add('opened');
          navResSocials.classList.add('opened');
        }
      })
    })
  }

  if (navResbackBtn.length > 0) {
    navResbackBtn.forEach(btnBack => {
      btnBack.addEventListener('click', (ev) => {
        const el = ev.currentTarget,
          parent = el.parentElement;

        if (parent) {
          parent.classList.remove('opened')
          navResSocials.classList.remove('opened')
        }
      })
    })
  }




  // Nav Responsive
  const btnavcustom = document.querySelectorAll(".boostify-menu-toggle")
  const btnNavResponsive = document.querySelector(".btn-nav-kkheader")
  navResponsive = document.querySelector(".nav-responsive")
  contentNavResponsive = document.querySelector(".nav-responsive-content")
  closeNavResponsive = document.querySelector(".nav-responsive-close")
  backNavResponsive = document.querySelectorAll(".nav-responsive-back");
  navkBottom = document.querySelector('.nav-bottom');

  childrenNavResponsive = document.querySelectorAll(
    ".nav-responsive-content-menu > li.has-child > a > .icon-angle-left"
  ),

    childrenTwoNavResponsive = document.querySelectorAll(
      ".nav-responsive-content-menu > li.has-child > .children > ul > li.has-child > a > .icon-angle-left"
    );
  childrenThreeNavResponsive = document.querySelectorAll(
    ".nav-responsive-content-menu > li.has-child > .children > ul > li.has-child  > .children > ul > li.has-child > a > .icon-angle-left"
  );
  childrenFourNavResponsive = document.querySelectorAll(
    ".nav-responsive-content-menu > li.has-child > .children > ul > li.has-child  > .children > ul > li.has-child > .children > ul > li.has-child > a > .icon-angle-left"
  );

  if (btnNavResponsive) {
    btnNavResponsive.addEventListener("click", () => {
      htmlTag.style.overflow = "hidden";
      navResponsive.classList.add("opened");
      if (jQuery('.proccedk').length > 0) {
        jQuery('.proccedk').hide();
      }
      if (jQuery('.select2-container.select2-container--default').length > 0) {
        jQuery('.select2-container.select2-container--default').hide();
      }
      navkBottom.classList.add('d-none');

    });
  }
  for (i = 0; i < btnavcustom.length; ++i) {

    if (btnavcustom[i]) {
      btnavcustom[i].addEventListener("click", () => {
        htmlTag.style.overflow = "hidden";
        navResponsive.classList.add("opened");
        if (jQuery('.proccedk').length > 0) {
          jQuery('.proccedk').hide();
        }
        if (jQuery('.select2-container.select2-container--default').length > 0) {
          jQuery('.select2-container.select2-container--default').hide();
        }
        navkBottom.classList.add('d-none');

      });
    }
  }


  if (closeNavResponsive) {
    closeNavResponsive.addEventListener("click", () => {
      navResponsive.classList.remove("opened");
      htmlTag.style.overflow = null;
      if (jQuery('.proccedk').length > 0) {
        jQuery('.proccedk').show();
      }
      if (jQuery('.select2-container.select2-container--default').length > 0) {
        jQuery('.select2-container.select2-container--default').show();
      }
      navkBottom.classList.remove('d-none');


    });
  }

  if (childrenNavResponsive.length > 0) {
    childrenNavResponsive.forEach((item) => {
      item.addEventListener("click", (ev) => {
        ev.preventDefault();

        const el = ev.currentTarget,
          children = el.parentNode.nextElementSibling;

        children.classList.add("opened");

        contentNavResponsive.scrollTo({ top: 0, behavior: "smooth" });
        contentNavResponsive.classList.add("opened-children");
      });
    });
  }



  if (childrenTwoNavResponsive.length > 0) {
    childrenTwoNavResponsive.forEach((item) => {
      item.addEventListener("click", (ev) => {

        ev.preventDefault();

        const el = ev.currentTarget,
          children = el.parentNode.nextElementSibling;

        children.classList.add("opened");

        contentNavResponsive.scrollTo({ top: 0, behavior: "smooth" });
        contentNavResponsive.classList.add("opened-children");


      });
    });
  }

  if (childrenThreeNavResponsive.length > 0) {
    childrenThreeNavResponsive.forEach((item) => {
      item.addEventListener("click", (ev) => {

        ev.preventDefault();

        const el = ev.currentTarget,
          children = el.parentNode.nextElementSibling;

        children.classList.add("opened");

        contentNavResponsive.scrollTo({ top: 0, behavior: "smooth" });
        contentNavResponsive.classList.add("opened-children");


      });
    });
  }

  if (childrenFourNavResponsive.length > 0) {
    childrenFourNavResponsive.forEach((item) => {
      item.addEventListener("click", (ev) => {

        ev.preventDefault();

        const el = ev.currentTarget,
          children = el.parentNode.nextElementSibling;

        children.classList.add("opened");

        contentNavResponsive.scrollTo({ top: 0, behavior: "smooth" });
        contentNavResponsive.classList.add("opened-children");


      });
    });
  }

  if (backNavResponsive.length > 0) {
    backNavResponsive.forEach((btnBack) => {
      btnBack.addEventListener("click", (ev) => {
        const el = ev.currentTarget,
          parent = el.closest(".children");

        parent.classList.remove("opened");

        contentNavResponsive.classList.remove("opened-children");
      });
    });
  }

  const scrollTo = document.querySelectorAll("[data-scroll-to]");

  if (scrollTo.length > 0) {
    scrollTo.forEach((item) => {
      item.addEventListener("click", (ev) => {
        const el = ev.currentTarget,
          { scrollTo } = el.dataset,
          content = document.querySelector(scrollTo);

        if (content) {
          content.scrollIntoView({ block: "start", behavior: "smooth" });
        }
      });
    });
  }




  // Tooltip
  const tooltipTriggerList = document.querySelectorAll(
    '[data-bs-toggle="tooltip"]'
  );

  const tooltipList = [...tooltipTriggerList].map(
    (tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl)
  );



  jQuery(document).on('click', '.modal-body .gallery-item img', function (e) {
    // Attach click event handler to images in .swiper-product-2
    e.preventDefault();
    // Get the src attribute of the clicked image
    var clickedSrc = jQuery(this).attr('src');
    // Update the src attribute of the corresponding image in .swiper-product-1
    jQuery('.modal-body .gallery-origin img').attr('src', clickedSrc);
  });



  // Review Product
  const btnReviewProduct = document.querySelector(
    ".detail-product-review .btn"
  ),
    contentReview = document.querySelector(".detail-product-review-content");

  if (btnReviewProduct) {
    const heightContentReview = contentReview.clientHeight;

    btnReviewProduct.addEventListener("click", (ev) => {
      const el = ev.currentTarget;

      if (!el.classList.contains("opened")) {
        el.classList.add("opened");
        el.innerHTML = "نمایش کمتر <i class='icon-angle-up'></i>";

        contentReview.style.height = contentReview.scrollHeight + "px";

        setTimeout(() => {
          contentReview.style.height = "auto";
        }, 300);
      } else {
        el.classList.remove("opened");
        el.innerHTML = "نمایش بیشتر <i class='icon-angle-down'></i>";

        contentReview.style.height = contentReview.scrollHeight + "px";

        setTimeout(() => {
          contentReview.style.height = heightContentReview + "px";
        }, 10);
      }
    });
  }



  // Search Boxes
  const btnSearchList = document.querySelectorAll(".top-header-four-btn-search"),
    searchBoxList = document.querySelectorAll(".top-header-four-search");

  btnSearchList.forEach((btnSearch, index) => {
    const searchBox = searchBoxList[index];
    const backdropSearchBox = searchBox.querySelector(".backdrop");

    btnSearch.addEventListener("click", () => {
      searchBox.classList.add("opened");
    });

    backdropSearchBox.addEventListener("click", () => {
      searchBox.classList.remove("opened");
    });
  });


  if (document.querySelector(".detail-blog .like-share")) {
    // Fixed Like Detail Blog
    const likeDetailBlog = document.querySelector(".detail-blog .like-share");

    if (likeDetailBlog) {
      const offsetLikeDetailBlog =
        likeDetailBlog.offsetTop + likeDetailBlog.scrollHeight,
        contentDetailBlog = document.querySelector(".detail-blog-wrapper"),
        heightContentDetailBlog =
          contentDetailBlog.offsetTop + contentDetailBlog.scrollHeight;

      window.addEventListener("scroll", () => {
        if (
          window.scrollY > offsetLikeDetailBlog + 35 &&
          window.scrollY < heightContentDetailBlog &&
          window.outerWidth > 991
        ) {
          likeDetailBlog.classList.add("fix");
        } else {
          likeDetailBlog.classList.remove("fix");
        }
      });
    }
  }




  // Swiper Top Selling Products
  new Swiper(".swiper-detail-product-four-related", {
    watchSlidesProgress: true,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    pagination: {
      el: ".swiper-pagination",
      type: "bullets",
      clickable: true,
    },
    breakpoints: {
      320: {
        slidesPerView: 2,
        spaceBetween: 8,
      },
      500: {
        slidesPerView: 2,
        spaceBetween: 12,
      },
      768: {
        slidesPerView: 3,
        spaceBetween: 12,
      },
      992: {
        slidesPerView: 4,
        spaceBetween: 20,
      },
      1200: {
        slidesPerView: 4,
        spaceBetween: 30,
      },
    },
  });



  // Swiper Discount Products
  const move = () => {
    const elem = document.querySelectorAll(".swiper__progress");

    elem.forEach((item) => {
      let width = 1;
      const autoplayTime = 5000 / 100;
      const id = setInterval(() => {
        if (width >= 100) {
          clearInterval(id);
        } else {
          width++;
          item.style.width = width + "%";
        }
      }, autoplayTime);
    });
  };

  new Swiper(".swiper-discount-products", {
    slidesPerView: 1,
    spaceBetween: 0,
    loop: true,
    autoplay: {
      delay: 5000,
      disableOnInteraction: false,
    },
    effect: "fade",
    fadeEffect: {
      crossFade: true,
    },
    on: {
      progress: () => {
        move();
      },
    },
  });


  // Open Description Product Two
  const btnDescriptionProduct = document.querySelector(
    ".detail-product-two-review .btn"
  );

  if (btnDescriptionProduct) {
    btnDescriptionProduct.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        content = el.previousElementSibling;

      content.classList.toggle("open");

      if (content.classList.contains("open")) {
        content.style.height = content.scrollHeight + "px";
        el.innerHTML = 'نمایش کمتر<i class="icon-angle-up"></i>';

        setTimeout(() => {
          content.style.height = "auto";
        }, 300);
      } else {
        content.style.height = content.scrollHeight + "px";
        el.innerHTML = 'نمایش بیشتر<i class="icon-angle-down"></i>';

        setTimeout(() => {
          content.removeAttribute("style");
        }, 10);
      }
    });
  }


  // Scroll To Header
  const btnScrollToHeader = document.querySelector('[data-to-header="true"]');

  if (btnScrollToHeader) {
    btnScrollToHeader.addEventListener("click", () => {
      window.scrollTo({ top: 0, behavior: "smooth" });
    });
  }

  // Swiper Products Panel
  new Swiper(".swiper-products-panel", {
    breakpoints: {
      320: {
        slidesPerView: "auto",
        spaceBetween: 8,
        pagination: {
          el: ".swiper-pagination",
          type: "bullets",
          clickable: true,
        },
      },
      370: {
        slidesPerView: "auto",
        spaceBetween: 12,
        pagination: {
          el: ".swiper-pagination",
          type: "bullets",
          clickable: true,
        },
      },
      768: {
        slidesPerView: "auto",
        spaceBetween: 20,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
      992: {
        slidesPerView: "auto",
        spaceBetween: 32,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
    },
  });

  const swiperDynamic = (className, navigation = false, pagination = false) => {
    const swiperEl = document.querySelectorAll(className);

    let options = {};

    if (navigation) {
      options.navigation = {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      };
    }

    if (pagination) {
      options.pagination = {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      };
    }

    if (swiperEl.length > 0) {
      swiperEl.forEach((swiper) => {
        options.breakpoints = JSON.parse(swiper.dataset.breakpoints);

        new Swiper(swiper, options);

        swiper.removeAttribute("data-breakpoints");
      });
    }
  };

  // Swiper Products
  swiperDynamic(".swiper-products-test", true);

  // Timer
  const timer = document.querySelectorAll("[data-time]");

  const formatTime = (time) => {
    if (Number(time) < 10) {
      time = "0" + time;
    }

    return time;
  };

  if (timer.length > 0) {
    timer.forEach((time) => {
      const timeElement = time.dataset.time,
        secondElement = time.querySelector(".second"),
        minuteElement = time.querySelector(".minute"),
        hourElement = time.querySelector(".hour"),
        dayElement = time.querySelector(".day");

      const timear = setInterval(() => {
        const d = new Date(timeElement).getTime() - new Date().getTime();

        const second = Math.floor((d % (1000 * 60)) / 1000),
          minute = Math.floor((d % (1000 * 60 * 60)) / (1000 * 60)),
          hour = Math.floor((d % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
          day = Math.floor(d / (1000 * 60 * 60 * 24));

        if (d <= 0) {
          clearInterval(timear);
        } else {
          secondElement.textContent = formatTime(second);
          minuteElement.textContent = formatTime(minute);
          hourElement.textContent = formatTime(hour);
          dayElement.textContent = formatTime(day);
        }
      }, 500);
    });
  }

  // Sidebar Panel
  const btnOpenSidebarPanel = document.querySelectorAll(".panel-open-nav"),
    closeSidebarPanel = document.querySelector(".panel-sidebar-backdrop"),
    sidebarPanel = document.querySelector(".panel-sidebar");

  if (btnOpenSidebarPanel.length > 0) {
    btnOpenSidebarPanel.forEach((btn) => {
      btn.addEventListener("click", () => {
        sidebarPanel.classList.add("opened");
        htmlTag.style.overflow = "hidden";
      });
    });

    closeSidebarPanel.addEventListener("click", () => {
      sidebarPanel.classList.remove("opened");
      htmlTag.removeAttribute("style");
    });
  }







  // Megamenu
  const tabsMegamenu = document.querySelectorAll(
    ".megamenu-tabs span, .megamenu-two-tabs-item"
  );

  if (tabsMegamenu.length > 0) {
    tabsMegamenu.forEach((tab) => {
      tab.addEventListener("mouseover", (ev) => {
        const el = ev.currentTarget,
          id = el.dataset.target,
          content = document.getElementById(id);

        if (content) {
          [...el.parentElement.children].map((tabItems) => {
            const id = tabItems.dataset.target;

            tabItems.classList.remove("active");
            document.getElementById(id).classList.remove("active");
          });

          el.classList.add("active");
          content.classList.add("active");

          content.style.opacity = 0;

          setTimeout(() => {
            content.style.opacity = 1;
            content.removeAttribute("style");
          }, 50);
        }
      });
    });
  }
  if (document.querySelector(".about-us-statistics")) {
    // Counter
    const contentCounters = document.querySelector(".about-us-statistics"),
      counters = document.querySelectorAll(".about-us-statistics-item .count");

    let isCountred = false;

    if (counters.length > 0) {
      const animateCounter = () => {
        if (counters.length > 0 && !isCountred) {
          isCountred = true;

          counters.forEach((item) => {
            const number = Number(item.textContent);

            let initalNumber = 0;

            const interval = setInterval(() => {
              initalNumber += 20;

              item.textContent = initalNumber;

              if (initalNumber >= number) {
                clearInterval(interval);
                item.textContent = number;
              }
            }, 1);
          });
        }
      };

      window.addEventListener("scroll", () => {
        if (
          window.scrollY >=
          contentCounters.offsetTop - contentCounters.scrollHeight - 242
        ) {
          animateCounter();
        }
      });

      if (
        window.scrollY >=
        contentCounters.offsetTop - contentCounters.scrollHeight - 242
      ) {
        animateCounter();
      }
    }
  }


  if (document.querySelector('.manblog')) {
    // Sidebar Category
    const btnOpenSidebarCategory = document.querySelector(".manblog.category-btn-filter"),
      sidebarCategory = document.querySelector(".category-sidebar"),
      backdropSidebarCategory = document.querySelector(
        ".category-sidebar-backdrop"
      );

    if (btnOpenSidebarCategory) {
      btnOpenSidebarCategory.addEventListener("click", () => {
        sidebarCategory.classList.add("open");
      });

      backdropSidebarCategory.addEventListener("click", () => {
        sidebarCategory.classList.remove("open");
      });
    }
  }

  //login ajax sms
  const KEYBOARDS = {
    backspace: 8,
    arrowLeft: 37,
    arrowRight: 39,
  };

  function handleInput(e) {
    const input = e.target;
    const nextInput = input.nextElementSibling;
    if (nextInput && input.value) {
      nextInput.focus();
      if (nextInput.value) {
        nextInput.select();
      }
    }
  }

  function handlePaste(e) {
    e.preventDefault();
    const paste = e.clipboardData.getData('text');
    Array.from(document.querySelectorAll('input.verifyinput')).forEach((input, i) => {
      input.value = paste[i] || '';
    });
  }

  function handleBackspace(e) {
    const input = e.target;
    if (input.value) {
      input.value = '';
      return;
    }
    if (input.previousElementSibling) {
      input.previousElementSibling.focus();
    }
  }

  function handleArrowLeft(e) {
    const previousInput = e.target.previousElementSibling;
    if (!previousInput) return;
    previousInput.focus();
  }

  function handleArrowRight(e) {
    const nextInput = e.target.nextElementSibling;
    if (!nextInput) return;
    nextInput.focus();
  }

  document.body.addEventListener('input', e => {
    if (e.target.matches('input.verifyinput')) {
      handleInput(e);
    }
  });

  document.body.addEventListener('paste', e => {
    if (e.target.matches('input.verifyinput')) {
      handlePaste(e);
    }
  });

  document.body.addEventListener('focus', e => {
    if (e.target.matches('input.verifyinput')) {
      setTimeout(() => {
        e.target.select();
      }, 0);
    }
  });

  document.body.addEventListener('keydown', e => {
    if (e.target.matches('input.verifyinput')) {
      switch (e.keyCode) {
        case KEYBOARDS.backspace:
          handleBackspace(e);
          break;
        case KEYBOARDS.arrowLeft:
          handleArrowLeft(e);
          break;
        case KEYBOARDS.arrowRight:
          handleArrowRight(e);
          break;
        default:
      }
    }
  });

  // New Code

  // Swiper Landing Seventeen
  const landingSevenTeen = document.querySelector(".landing-seventeen");

  if (landingSevenTeen) {
    let timeSwiper = 0,
      timearSwiper;

    const swiperLandingSevenTeen = new Swiper(".swiper-landing-seventeen", {
      slidesPerView: 1,
      spaceBetween: 0,
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      on: {
        init: () => {
          document.documentElement.style.setProperty(
            "--time-landing-seventeen",
            "5000ms"
          );
        },

        slideChange: () => {
          timeSwiper = 0;
        },
      },
    });

    const itemsPaginations = landingSevenTeen.querySelectorAll(
      ".swiper-pagination-bullet"
    );

    const startLandingSevenTeen = () => {
      timearSwiper = setInterval(() => {
        timeSwiper += 1000;

        if (timeSwiper >= 5000) {
          timeSwiper = 0;
          swiperLandingSevenTeen.slideNext(300);
        }
      }, 1 * 1000);
    };

    startLandingSevenTeen();
  }


  // Swiper Carousel Home
  const carouselHome = document.querySelector(".swiper-carousel-home");

  if (carouselHome) {
    let timeSwiper = 0,
      timearSwiper;

    const iconPlayPause = carouselHome.querySelector(".swiper-bottom i");

    const swiperCarouselHome = new Swiper(".swiper-carousel-home", {
      slidesPerView: 1,
      spaceBetween: 0,
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      on: {
        init: () => {
          document.documentElement.style.setProperty(
            "--time-carousel-home",
            "5000ms"
          );
        },

        slideChange: () => {
          timeSwiper = 0;
        },
      },
    });

    const itemsPaginations = carouselHome.querySelectorAll(
      ".swiper-pagination-bullet"
    );

    const startCarouselHome = () => {
      timearSwiper = setInterval(() => {
        timeSwiper += 500;

        if (timeSwiper >= 5000) {
          timeSwiper = 0;
          swiperCarouselHome.slideNext(300);
        }
      }, 1 * 500);
    };

    startCarouselHome();

    carouselHome.addEventListener("mouseover", () => {
      [...itemsPaginations].map((item) => {
        item.classList.add("stoped");
      });

      clearInterval(timearSwiper);

      iconPlayPause.classList.remove("icon-play");
      iconPlayPause.classList.add("icon-pause");
    });

    carouselHome.addEventListener("mouseleave", () => {
      [...itemsPaginations].map((item) => {
        item.classList.remove("stoped");
      });

      startCarouselHome();

      iconPlayPause.classList.remove("icon-pause");
      iconPlayPause.classList.add("icon-play");
    });
  }


  // Swiper Discount Product Special
  new Swiper(".swiper-discount-product-special", {
    watchSlidesProgress: true,
    pagination: {
      el: ".swiper-pagination",
      type: "bullets",
      clickable: true,
    },
    autoplay: {
      delay: 3000,
    },
    loop: true,
    breakpoints: {
      320: {
        slidesPerView: 2,
        spaceBetween: 12,
      },
      768: {
        slidesPerView: 1,
        spaceBetween: 20,
        effect: "fade",
        fadeEffect: {
          crossFade: true,
        },
      },
    }
  });



  new Swiper(".swiper-best-category-four", {
    grid: {
      fill: "row",
      rows: 2,
    },
    breakpoints: {
      320: {
        slidesPerView: 1.2,
        spaceBetween: 12,
      },
      460: {
        slidesPerView: 1.7,
        spaceBetween: 12,
      },
      576: {
        slidesPerView: 2,
        spaceBetween: 12,
      },
      768: {
        slidesPerView: 3,
        spaceBetween: 12,
      },
      992: {
        slidesPerView: 4,
        spaceBetween: 12,
      },
      1200: {
        slidesPerView: 4,
        spaceBetween: 22,
      },
    },
    on: {
      init: (swiper) => {
        swiper.slides.forEach((item, index) => {
          const thisIndex = index + 1,
            allSlides = swiper.slides.length / 2;

          if (thisIndex > allSlides) {
            item.firstElementChild.classList.add("two");
          }
        });
      },
    },
  });

  // Carousel Home Two
  new Swiper(".swiper-carousel-home-two", {
    slidesPerView: 1,
    spaceBetween: 0,
    pagination: {
      el: ".swiper-pagination",
      type: "bullets",
      clickable: true,
    },
    autoplay: {
      delay: 3000,
    },
    effect: "fade",
    fadeEffect: {
      crossFade: true,
    },
    loop: true,
  });






  // Swiper Specials Sale
  new Swiper(".swiper-specials-sale", {
    watchSlidesProgress: true,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    breakpoints: {
      320: {
        slidesPerView: 1,
        spaceBetween: 4,
      },
      576: {
        slidesPerView: 2,
        spaceBetween: 12,
      },
      768: {
        slidesPerView: 3,
        spaceBetween: 20,
      },
      992: {
        slidesPerView: 4,
        spaceBetween: 20,
      },
      1200: {
        slidesPerView: 4,
        spaceBetween: 31,
      },
    },
  });


  // Swiper New Products
  new Swiper(".swiper-new-products", {
    watchSlidesProgress: true,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    breakpoints: {
      320: {
        slidesPerView: 1.3,
        spaceBetween: 12,
      },
      370: {
        slidesPerView: 1.5,
        spaceBetween: 12,
      },
      470: {
        slidesPerView: 2,
        spaceBetween: 12,
      },
      576: {
        slidesPerView: 1,
        spaceBetween: 12,
      },
      768: {
        slidesPerView: 2,
        spaceBetween: 12,
      },
      992: {
        slidesPerView: 3,
        spaceBetween: 23,
      },
    },
  });


  // Swiper Amazing Offer Fiveteen
  const amazingOfferFiveteen = new Swiper(".swiper-amazing-offer-fiveteen", {
    slidesPerView: 1,
    spaceBetween: 0,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    pagination: {
      el: ".swiper-pagination",
      type: "bullets",
      clickable: true,
      renderBullet: (index, className) => {
        const slidesImg = document.querySelectorAll(
          ".amazing-offer-fiveteen-item .image img"
        ),
          slidesName = document.querySelectorAll(
            ".amazing-offer-fiveteen-item h2"
          );

        return `<div class="swiper-pagination-bullet d-flex align-items-center">
        <img src="${slidesImg[index].src}" alt="${slidesName[index].textContent}" />
        <span>${slidesName[index].textContent}</span>
      </div>`;
      },
    },
    autoplay: {
      delay: 5000,
      disableOnInteraction: false,
      pauseOnMouseEnter: true,
    },
    effect: "fade",
    fadeEffect: {
      crossFade: true,
    },
    on: {
      paginationUpdate: (swiper, paginationEl) => {
        const active = paginationEl.querySelector(
          ".swiper-pagination-bullet-active"
        ),
          prev = active.previousElementSibling,
          oldPrev = paginationEl.querySelector(
            ".swiper-pagination-bullet-prev"
          );

        if (prev !== null) {
          if (oldPrev) {
            oldPrev.classList.remove("swiper-pagination-bullet-prev");
          }

          prev.classList.add("swiper-pagination-bullet-prev");
        }
      },
    },
  });


  // Swiper Amazing Offer Products
  const swiperAmazingOfferProduct = new Swiper(
    ".swiper-amazing-offer-products-pagination",
    {

      watchSlidesProgress: true,
      breakpoints: {
        320: {
          slidesPerView: 1.5,
          spaceBetween: 0,
        },
        400: {
          slidesPerView: 2,
          spaceBetween: 0,
        },
        768: {
          slidesPerView: 3,
          spaceBetween: 0,
        },
        992: {
          slidesPerView: 3,
          spaceBetween: 0,
        },
      },
      on: {
        init: (swiper) => {
          if (window.outerWidth > 991) {
            const height =
              (swiper.slides[0].firstElementChild.scrollHeight + 32) * 3;

            swiper.el.style.height = height + "px";
          }
        },
      },
    }
  );



  // Carousel Gifts
  new Swiper(".swiper-carousel-gifts", {
    slidesPerView: 1,
    spaceBetween: 0,
    pagination: {
      el: ".swiper-pagination",
      type: "bullets",
      clickable: true,
    },
    autoplay: {
      delay: 3000,
    },
    effect: "fade",
    fadeEffect: {
      crossFade: true,
    },
    loop: true,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
  });


  // Mega Menu Three
  const megamenuThreeTabs = document.querySelectorAll(
    ".megamenu-three-tabs ul li"
  );

  if (megamenuThreeTabs.length > 0) {
    megamenuThreeTabs.forEach((tab) => {
      tab.addEventListener("mouseover", (ev) => {
        const el = ev.currentTarget,
          id = el.dataset.tab,
          content = document.querySelector(id);

        if (content) {
          [...el.parentElement.children].map((tabItem) => {
            const contentItem = document.querySelector(tabItem.dataset.tab);

            if (contentItem) {
              contentItem.classList.remove("active");
              tabItem.classList.remove("active");
            }
          });

          el.classList.add("active");

          content.classList.add("active");
          content.style.opacity = "0.5";

          setTimeout(() => {
            content.style.opacity = 1;
          }, 5);
        }
      });
    });
  }

  // Swiper To Selling Products Kala
  new Swiper(".swiper-proposal-kala", {
    spaceBetween: 0,
    breakpoints: {
      320: {
        slidesPerView: 2,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
      400: {
        slidesPerView: 3,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
      500: {
        slidesPerView: 4,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
      576: {
        slidesPerView: 4,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
      768: {
        slidesPerView: 5,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
      992: {
        slidesPerView: 7,
        grid: {
          fill: "row",
          rows: 2,
        },
      },
    },
    on: {
      init: (swiper) => {
        swiper.slides.forEach((item, index) => {
          const thisIndex = index + 1,
            allSlides = swiper.slides.length / 2;

          if (thisIndex === allSlides + 1) {
            item.classList.add("two-one");
          }

          if (thisIndex > allSlides) {
            item.firstElementChild.classList.add("two");
          }
        });
      },
    },
  });


  // Toggle Icons Detail Products
  const btnIconsDetailProducts = document.querySelectorAll(
    ".icons-detail-product > button"
  );

  if (btnIconsDetailProducts.length > 0) {
    btnIconsDetailProducts.forEach((btnIcons) => {
      btnIcons.addEventListener("click", (ev) => {
        const el = ev.currentTarget,
          icons = el.nextElementSibling;

        icons.classList.toggle("hidden");
      });
    });
  }

  // Swiper Volume Detail Product
  new Swiper(".swiper-volume-detail-product", {
    slidesPerView: "auto",
    spaceBetween: 7,
    autoplay: true,
    on: {
      init: (swiper) => {
        swiper.el.classList.add("not-last");
      },
      slideChange: (swiper) => {
        swiper.el.classList.remove("not-last");
      },
    },
  });

  var elementgal = jQuery('.woocommerce-product-gallery__image a');

  // Add the attributes
  elementgal.attr('data-bs-toggle', 'modal');
  elementgal.attr('data-bs-target', '#modal-gallery');

  jQuery(".woocommerce-product-gallery__image a").click(function (e) {
    e.preventDefault();
    e.stopPropagation();
  })

  // Gallery Images Modal Origin
  const galleryImages = document.querySelectorAll(
    ".detail-product-four-modal-gallery-images img"
  );

  if (galleryImages.length > 0) {
    // Swiper Gallery Detail Product
    const swiperGalleryDetailProduct = new Swiper(
      ".swiper-detail-product-four-modal-galler-origin",
      {
        slidesPerView: 1,
        spaceBetween: 0,
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      }
    );

    galleryImages.forEach((image, index) => {
      image.addEventListener("click", () => {
        swiperGalleryDetailProduct.slideTo(index, 300);
      });
    });
  }

  // Gallery Images Modal Users
  const galleryImagesUsers = document.querySelectorAll(
    ".detail-product-four-modal-gallery-images-users img"
  );

  if (galleryImagesUsers.length > 0) {
    // Swiper Gallery Detail Product
    const swiperGalleryDetailProductUsers = new Swiper(
      ".swiper-detail-product-four-modal-galler-users",
      {
        slidesPerView: 1,
        spaceBetween: 0,
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev",
        },
      }
    );

    galleryImagesUsers.forEach((image, index) => {
      image.addEventListener("click", () => {
        swiperGalleryDetailProductUsers.slideTo(index, 300);
      });
    });
  }

  // Buy Images
  const buyImages = document.querySelectorAll(
    ".images-users-items .item, .images-users-link"
  );

  if (buyImages.length > 0) {
    buyImages.forEach((image) => {
      image.addEventListener("click", () => {
        const item = document.querySelector(
          ".detail-product-four-modal-gallery .nav li:last-child"
        );

        const tab = new bootstrap.Tab(item);

        tab.show();
      });
    });
  }





  // Swiper Gallery Detail Product Four Origin
  let enabled = false;

  if (window.outerWidth < 992) {
    enabled = true;
  }

  new Swiper(".swiper-detail-product-four-gallery", {
    slidesPerView: 1,
    spaceBetween: 0,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    pagination: {
      el: ".swiper-pagination",
      type: "bullets",
      clickable: true,
    },
    enabled: enabled,
  });

  new Swiper(".swiper-mobile", {
    slidesPerView: 2,
    spaceBetween: 8,
  });


  // Counter Cart
  const counterCart = document.querySelectorAll("[data-counter]");

  if (counterCart.length > 0) {
    counterCart.forEach((item) => {
      item.addEventListener("click", (ev) => {
        const el = ev.target,
          type = el.dataset.counter,
          parent = el.parentElement,
          input = parent.children[1];
        const kquan = document.querySelector('.kquan');

        if (type === "add") {
          if (Number(input.value) < Number(input.getAttribute("max"))) {
            input.setAttribute("value", Number(input.value) + 1);
            kquan.setAttribute("value", Number(input.value) + 1 - 1);
          }
        } else {
          if (Number(input.value) > Number(input.getAttribute("min"))) {
            input.setAttribute("value", Number(input.value) - 1);
            kquan.setAttribute("value", Number(input.value) - 1 + 1);
          }
        }
      });
    });
  }


  // Select all elements with the class 'fas fa-shopping-cart'
  var elements = document.querySelectorAll('.fas.fa-shopping-cart');

  // Loop through all selected elements
  for (var i = 0; i < elements.length; i++) {
    // Remove old classes
    elements[i].classList.remove('fas');
    elements[i].classList.remove('fa-shopping-cart');

    // Add new classes
    elements[i].classList.add('icon');
    elements[i].classList.add('icon-cart-3');
  }

  // Select all elements with the class 'far fa-eye'
  var elements = document.querySelectorAll('.far.fa-eye');

  // Loop through all selected elements
  for (var i = 0; i < elements.length; i++) {
    // Remove old classes
    elements[i].classList.remove('far');
    elements[i].classList.remove('fa-eye');

    // Add new classes
    elements[i].classList.add('isax');
    elements[i].classList.add('isax-eye');
  }


  // Select all elements with the class 'fas fa-external-link-alt'
  var elements = document.querySelectorAll('.fas.fa-external-link-alt');

  // Loop through all selected elements
  for (var i = 0; i < elements.length; i++) {
    // Remove old classes
    elements[i].classList.remove('fas');
    elements[i].classList.remove('fa-external-link-alt');

    // Add new classes
    elements[i].classList.add('isax');
    elements[i].classList.add('isax-activity');
  }
  // Select the first element with the class "dokan-other-vendor-camparison"
  var element = document.querySelector('.dokan-other-vendor-camparison');

  // Check if the element exists
  if (element) {
    // Set the ID of the element to "other_sellers"
    element.id = 'other_sellers';
  }

var theDiv = jQuery('#seeebox');
var theInput = jQuery('.maninpu');
var theOutput = jQuery('#keyword');

function updateElements() {
    theDiv.addClass('active');
    theOutput.val(theInput.val());
    theOutput.focus();
}

// Listen for both 'input' and 'paste' events
theInput.on('input paste', function () {
    updateElements();
});

theOutput.on('input', function () {
    theInput.val(theOutput.val());
});

jQuery('.closesee').on('click', function () {
    theDiv.removeClass('active');
});



  // Tabs
  const tabss = document.querySelectorAll('[data-auth-toggle="tab"]');

  if (tabss.length > 0) {
    tabss.forEach((tab) => {
      tab.addEventListener("click", (ev) => {
        const el = ev.currentTarget,
          content = document.getElementById(el.dataset.authTarget);

        if (content) {
          [...el.parentElement.children].map((tabItem) => {
            const contentTab = document.getElementById(
              tabItem.dataset.authTarget
            );

            tabItem.classList.remove("active");

            if (contentTab) {
              contentTab.classList.remove("active");
            }
          });

          el.classList.add("active");

          content.classList.add("active");
          content.style.opacity = "0";

          setTimeout(() => {
            content.removeAttribute("style");
          }, 5);
        }
      });
    });
  }


  const tabsb = document.querySelectorAll('[data-tab-swiper="true"]');

  if (tabsb.length > 0) {
    tabsb.forEach((tab) => {
      tab.addEventListener("click", (ev) => {
        const el = ev.currentTarget,
          content = document.querySelector(el.dataset.bsTarget);

        if (content) {
          const swiperEl = content.querySelector('.swiper')

          if (swiperEl) {
            const options = JSON.parse(swiperEl.dataset.swiper)

            setTimeout(() => {
              new Swiper(swiperEl, options)
            }, 150);
          }
        }
      });
    });
  }



  // Modal
  const btnsModal = document.querySelectorAll('[data-auth-toggle="modal"]');

  if (btnsModal.length > 0) {
    btnsModal.forEach((btnModal) => {
      btnModal.addEventListener("click", (ev) => {
        ev.preventDefault();

        const el = ev.currentTarget,
          id = el.dataset.authTarget,
          modal = document.getElementById(id);

        if (modal) {
          const modalOpened = document.querySelector(".auth__modal.opened"),
            backdropModalOpened = document.querySelector(
              ".auth__modal__backdrop"
            ),
            backdrop = document.createElement("div");
          backdrop.classList.add("auth__modal__backdrop");
          backdrop.style.opacity = 0;

          if (modalOpened && backdropModalOpened) {
            modalOpened.classList.remove("opened");
            backdropModalOpened.style.opacity = 0;

            setTimeout(() => {
              backdropModalOpened.remove();
            }, 300);
          }

          document.body.appendChild(backdrop);

          setTimeout(() => {
            backdrop.style.opacity = 1;
          }, 5);

          modal.classList.add("opened");
        }
      });
    });

    window.addEventListener("click", (ev) => {
      const el = ev.target,
        modalOpened = document.querySelector(".auth__modal.opened"),
        backdropModalOpened = document.querySelector(".auth__modal__backdrop");

      if (
        el.classList.contains("auth__modal__dialog") ||
        el.classList.contains("auth__modal__content") ||
        el.classList.contains("auth__modal__body") ||
        el.classList.contains("auth__modal__close")
      ) {
        modalOpened.classList.remove("opened");
        backdropModalOpened.style.opacity = 0;

        setTimeout(() => {
          backdropModalOpened.remove();
        }, 300);
      }
    });
  }

  // Show Password
  const showPassword = document.querySelectorAll("[data-show-password]");

  if (showPassword.length > 0) {
    showPassword.forEach((btnPassword) => {
      btnPassword.addEventListener("click", (ev) => {
        const el = ev.currentTarget,
          input = document.querySelector(el.dataset.showPassword),
          { iconShow, iconHide } = el.dataset;

        if (input) {
          input.type = input.type === "password" ? "text" : "password";
          el.classList.toggle("showing");
          iconShow && el.classList.toggle(iconShow);
          iconHide && el.classList.toggle(iconHide);
        }
      });
    });
  }


  // Find the input element
  var inputElement = document.querySelector(".insingle_pr .quantity input[type=\"number\"]");
  if (inputElement) {
    // Create plus button
    var plusButton = document.createElement("button");
    plusButton.innerHTML = "+";
    plusButton.setAttribute("type", "button");
    plusButton.classList.add("kplus-button"); // Add custom CSS class

    // Create minus button
    var minusButton = document.createElement("button");
    minusButton.innerHTML = "-";
    minusButton.setAttribute("type", "button");
    minusButton.classList.add("kminus-button"); // Add custom CSS class

    // Insert minus button before the input element
    inputElement.parentNode.insertBefore(minusButton, inputElement);

    // Append plus button after the input element
    inputElement.parentNode.insertBefore(plusButton, inputElement.nextSibling);

    // Add event listener for plus button
    plusButton.addEventListener("click", function () {
      var currentValue = parseInt(inputElement.value);
      inputElement.value = currentValue + 1;
    });

    // Add event listener for minus button
    minusButton.addEventListener("click", function () {
      var currentValue = parseInt(inputElement.value);
      if (currentValue > 1) {
        inputElement.value = currentValue - 1;
      }
    });
  }


  var navBottom = document.querySelector('.nav-bottom');
  var detailProductFourBottom = document.querySelector('.detail-product-four-bottom');
  var switchButton = document.querySelector('.switch_footer_kaveh');
  var det4simple = document.querySelector('.det4simple form.cart');
  var detailfourprice = document.querySelector('.detailfourprice .price');
  var detailfourvaradd = document.querySelector('.detail-product-four .woocommerce-variation-add-to-cart');

  if (navBottom) {
    // Function to toggle footer elements
    function toggleFooter() {
      if (detailProductFourBottom.style.display === 'none') {
        detailProductFourBottom.classList.toggle('d4prshow');
        navBottom.classList.toggle('d4prnone');
      } else {
        if (det4simple) {
          det4simple.classList.toggle('d4prnone');
        }
        if (detailfourprice) {
          detailfourprice.classList.toggle('d4prnone');
        }
        if (detailfourvaradd) {
          detailfourvaradd.classList.toggle('d4prnone');
        }
        detailProductFourBottom.classList.toggle('d4prnone');
        navBottom.classList.toggle('d4prshow');
      }
    }

    // Check if .detail-product-four-bottom exists on page load
    if (detailProductFourBottom) {
      // Hide nav-bottom initially
      navBottom.classList.toggle('d4prnone');
      // Add click event listener to switch_button
      switchButton.addEventListener('click', toggleFooter);
    }
  }


  jQuery("#kcopysource").click(function () {
    var copyTargetInput = jQuery("#kcopytarget");
    copyTargetInput.select();
    document.execCommand("copy");

    // Change icon class
    jQuery("#kcopysource i").removeClass("isax-document-copy").addClass("isax-document-copy5");

    // Revert back to original class after 2 seconds
    setTimeout(function () {
      jQuery("#kcopysource i").removeClass("isax-document-copy5").addClass("isax-document-copy");
    }, 2000);
  });


  // Form Focused
  const formControl = document.querySelectorAll(".form-control-js");

  if (formControl.length > 0) {
    formControl.forEach((input) => {
      input.addEventListener("focus", () => {
        input.classList.add("focused");
      });

      input.addEventListener("blur", (ev) => {
        const el = ev.target,
          { value } = el;

        if (value === "") {
          el.classList.remove("focused");
        }
      });
    });
  }

  // Select Two
  const selectTwo = document.querySelector(".select-two");

  if (selectTwo) {
    $(".select-two").select2({
      dropdownParent: $(".modal")[0] ? $(".modal") : "",
    });
  }

  if (jQuery('.insingle_pr').length > 0) {

  } else {
    jQuery('select').select2();
  }



  // Swiper search box
  new Swiper(".swiper-seabox", {
    navigation: {
      nextEl: ".swiper-sea-next",
      prevEl: ".swiper-sea-prev",
    },
    breakpoints: {
      320: {
        slidesPerView: 1,
        spaceBetween: 3,
      },
      576: {
        slidesPerView: 1,
        spaceBetween: 8,
      },
      768: {
        slidesPerView: 3,
        spaceBetween: 8,
      },
      992: {
        slidesPerView: 2.5,
        spaceBetween: 15,
      },
    },
  });
  // Swiper search box
  new Swiper(".swiper-geabox", {
    slidesPerView: 1,
    spaceBetween: 0,
    pagination: {
      el: '.swiper-pagination',
      type: 'bullets',
      clickable: true,
    },
    autoplay: {
      delay: 2000,
    },
    effect: "fade",
    fadeEffect: {
      crossFade: true,
    },
    loop: true,

  });

  setTimeout(function () {
    jQuery('.kel-widget .skeleton-display').hide();
    jQuery('.kel-widget .kel-content').show();
  }, 2000);

  /* new elements */
  // Swiper Set Navigtion & Pagination
  const swiperSetControllers = (
    swiper,
    parent,
    elNext,
    elPrev,
    paginationEl,
    paginationElMobile
  ) => {
    const { el, params } = swiper,
      { navigation, pagination } = params;

    const container = $(el).closest(parent);

    navigation.nextEl = container.find(elNext)[0];
    navigation.prevEl = container.find(elPrev)[0];

    if (paginationElMobile && window.innerWidth <= 1024) {
      pagination.el = container.find(paginationElMobile)[0];
    } else if (paginationEl !== "") {
      pagination.el = container.find(paginationEl)[0];
    }

    pagination.clickable = true;

    swiper.update();
  };

  // Swiper Products Fast Sending
  const swiperProductsFastSending = $(".swiper-products-fast-sending");

  if (swiperProductsFastSending.length > 0) {
    new Swiper(".swiper-products-fast-sending", {
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
    });
  }

  // Swiper Categories One
  const swiperCategoriesOne = $(".swiper-categories-one");

  if (swiperCategoriesOne.length > 0) {
    new Swiper(".swiper-categories-one", {
      watchSlidesProgress: true,
      breakpoints: {
        320: {
          slidesPerView: "auto",
          spaceBetween: 12,
        },
        576: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 6,
          spaceBetween: 12,
        },
        1200: {
          slidesPerView: 8,
          spaceBetween: 12,
        },
      },
      on: {
        beforeInit: (s) =>
          swiperSetControllers(
            s,
            ".container",
            ".swiper-button-next",
            ".swiper-button-prev",
            "",
            ""
          ),
      },
    });
  }

  // Swiper Box Products One
  const swiperBoxProductsOne = $(".swiper-box-products-one");

  if (swiperBoxProductsOne.length > 0) {
    new Swiper(".swiper-box-products-one", {
      watchSlidesProgress: true,
      breakpoints: {
        320: {
          slidesPerView: 2,
          spaceBetween: 8,
        },
        576: {
          slidesPerView: 3,
          spaceBetween: 8,
        },
        768: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 6,
          spaceBetween: 12,
        },
        1200: {
          slidesPerView: 7,
          spaceBetween: 12,
        },
      },
    });
  }

  // Swiper Products Bed
  const swiperProductsBed = $(".swiper-products-bed-one");

  if (swiperProductsBed.length > 0) {
    new Swiper(".swiper-products-bed-one", {
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
    });
  }

  // Swiper Products Bed Two
  const swiperProductsBedTwo = $(".swiper-products-bed-two");

  if (swiperProductsBedTwo.length > 0) {
    new Swiper(".swiper-products-bed-two", {
      watchSlidesProgress: true,
      slidesPerView: 1.35,
      spaceBetween: 12,
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      loop: true,
      breakpoints: {
        576: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
      },
    });
  }

  // Swiper Products Bed Three
  const swiperProductsBedThree = $(".swiper-products-bed-three");

  if (swiperProductsBedThree.length > 0) {
    new Swiper(".swiper-products-bed-three", {
      watchSlidesProgress: true,
      slidesPerView: 1,
      spaceBetween: 12,
      breakpoints: {
        992: {
          slidesPerView: 1.5,
          spaceBetween: 24,
        },
        1200: {
          slidesPerView: 2,
          spaceBetween: 24,
        },
      },
    });
  }

  // Swiper Images Product Bed Three
  const swiperImagesProductBedThree = $(".swiper-images-product-bed-three");

  if (swiperImagesProductBedThree.length > 0) {
    new Swiper(".swiper-images-product-bed-three", {
      watchSlidesProgress: true,
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      autoplay: {
        delay: 3000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
    });
  }

  // Swiper Products Bed Four
  const swiperProductsBedFour = $(".swiper-products-bed-four");

  if (swiperProductsBedFour.length > 0) {
    new Swiper(".swiper-products-bed-four", {
      watchSlidesProgress: true,
      slidesPerView: 1.1,
      spaceBetween: 12,
      breakpoints: {
        576: {
          slidesPerView: 1.4,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 2,
          spaceBetween: 24,
        },
        1200: {
          slidesPerView: 3,
          spaceBetween: 24,
        },
      },
    });
  }

  // Swiper Contex Users
  const swiperContexUsers = $(".swiper-contex-users");

  if (swiperContexUsers.length > 0) {
    new Swiper(".swiper-contex-users", {
      autoHeight: true,
      watchSlidesProgress: true,
      slidesPerView: 1.3,
      spaceBetween: 12,
      breakpoints: {
        400: {
          slidesPerView: 1.6,
          spaceBetween: 12,
        },
        500: {
          slidesPerView: 1.9,
          spaceBetween: 12,
        },
        576: {
          slidesPerView: 2.1,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 2.7,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 3.3,
          spaceBetween: 16,
        },
        1200: {
          slidesPerView: 4,
          spaceBetween: 24,
        },
      },
      on: {
        beforeInit: (s) =>
          swiperSetControllers(
            s,
            ".container",
            ".swiper-button-next",
            ".swiper-button-prev",
            "",
            ""
          ),
      },
    });
  }

  // Swiper Articles Bed
  const swiperArticlesBed = $(".swiper-articles-bed");

  if (swiperArticlesBed.length > 0) {
    new Swiper(".swiper-articles-bed", {
      autoHeight: true,
      watchSlidesProgress: true,
      slidesPerView: 1.3,
      spaceBetween: 12,
      breakpoints: {
        576: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 2.8,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 4,
          spaceBetween: 16,
        },
        1200: {
          slidesPerView: 4,
          spaceBetween: 24,
        },
      },
    });
  }

  // Swiper Comments Bed
  const swiperCommentsBed = $(".swiper-comments-bed");

  if (swiperCommentsBed.length > 0) {
    new Swiper(".swiper-comments-bed", {
      autoHeight: true,
      watchSlidesProgress: true,
      slidesPerView: 1.2,
      spaceBetween: 12,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      breakpoints: {
        576: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 3,
          spaceBetween: 16,
        },
        1200: {
          slidesPerView: 3,
          spaceBetween: 24,
        },
      },
      on: {
        beforeInit: (s) =>
          swiperSetControllers(
            s,
            ".container",
            ".swiper-button-next",
            ".swiper-button-prev",
            "",
            ""
          ),
      },
    });
  }

  // Swiper Shopping Guide Bed
  const swiperShoppingGuideBed = $(".swiper-shopping-guide");

  if (swiperShoppingGuideBed.length > 0) {
    new Swiper(".swiper-shopping-guide", {
      autoHeight: true,
      watchSlidesProgress: true,
      slidesPerView: 2.1,
      spaceBetween: 12,
      breakpoints: {
        576: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 4,
          spaceBetween: 16,
        },
        992: {
          slidesPerView: 5,
          spaceBetween: 32,
        },
        1200: {
          slidesPerView: 5,
          spaceBetween: 64,
        },
        1400: {
          slidesPerView: 5,
          spaceBetween: 80,
        },
      },
    });
  }


  // Swiper Slider Books
  const swiperSliderBooks = $(".swiper-books-slider");

  if (swiperSliderBooks.length > 0) {
    new Swiper(".swiper-books-slider", {
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    });
  }

  // Swiper Discounted Products
  const swiperDiscountedProducts = $(".swiper-discounted-products-book");

  if (swiperDiscountedProducts.length > 0) {
    new Swiper(".swiper-discounted-products-book", {
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
    });
  }

  // Swiper Categories Books
  const swiperCategoriesBooks = $(".swiper-categories-books");

  if (swiperCategoriesBooks.length > 0) {
    new Swiper(".swiper-categories-books", {
      watchSlidesProgress: true,
      autoHeight: true,
      slidesPerView: 1.3,
      spaceBetween: 12,
      breakpoints: {
        400: {
          slidesPerView: 1.6,
          spaceBetween: 12,
        },
        500: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        768: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
        1200: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
      },
    });
  }

  // Swiper Products Book
  const swiperProductsBook = $(".swiper-products-book");

  if (swiperProductsBook.length > 0) {
    new Swiper(".swiper-products-book", {
      watchSlidesProgress: true,
      autoHeight: true,
      slidesPerView: 2,
      spaceBetween: 8,
      breakpoints: {
        576: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
        1200: {
          slidesPerView: 4,
          spaceBetween: 12,
        },
      },
    });
  }

  // Swiper Articles Book
  const swiperArticlesBook = $(".swiper-articles-book");

  if (swiperArticlesBook.length > 0) {
    new Swiper(".swiper-articles-book", {
      watchSlidesProgress: true,
      autoHeight: true,
      slidesPerView: 1.2,
      spaceBetween: 12,
      breakpoints: {
        576: {
          slidesPerView: 2,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        1200: {
          slidesPerView: 3,
          spaceBetween: 24,
        },
      },
    });
  }

  // Swiper Discounted Products Tech
  const swiperDiscountedProductsTech = $(".swiper-discounted-products-tech");

  if (swiperDiscountedProductsTech.length > 0) {
    new Swiper(".swiper-discounted-products-tech", {
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      autoplay: {
        delay: 5000,
        disableOnInteraction: false,
        pauseOnMouseEnter: true,
      },
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
    });
  }

  // Swiper Categories Tech
  const swiperCategoriesTech = $(".swiper-categories-tech");

  if (swiperCategoriesTech.length > 0) {
    new Swiper(".swiper-categories-tech", {
      watchSlidesProgress: true,
      autoHeight: true,
      slidesPerView: 1.2,
      spaceBetween: 40,
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
      breakpoints: {
        400: {
          slidesPerView: 1.5,
          spaceBetween: 40,
        },
        500: {
          slidesPerView: 1.7,
          spaceBetween: 40,
        },
        576: {
          slidesPerView: 2,
          spaceBetween: 40,
        },
        992: {
          slidesPerView: 3,
          spaceBetween: 40,
        },
        1200: {
          slidesPerView: 4,
          spaceBetween: 32,
        },
        1400: {
          slidesPerView: 4,
          spaceBetween: 61,
        },
      },
    });
  }

  // Swiper Products Tech
  const swiperProductsTech = $(".swiper-products-tech");

  if (swiperProductsTech.length > 0) {
    new Swiper(".swiper-products-tech", {
      watchSlidesProgress: true,
      autoHeight: true,
      slidesPerView: 2,
      spaceBetween: 12,
      breakpoints: {
        576: {
          slidesPerView: 3,
          spaceBetween: 12,
        },
        992: {
          slidesPerView: 4,
          spaceBetween: 16,
        },
        1200: {
          slidesPerView: 4,
          spaceBetween: 24,
        },
      },
    });
  }

  // Swiper Landing Gold
  const swiperLandingGold = $(".swiper-hero-landing-one");

  if (swiperLandingGold.length > 0) {
    new Swiper(".swiper-hero-landing-one", {
      slidesPerView: 1,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
      // autoplay: {
      //   delay: 5000,
      //   disableOnInteraction: false,
      //   pauseOnMouseEnter: true,
      // },
      effect: "fade",
      fadeEffect: {
        crossFade: true,
      },
      loop: true,
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    });
  }

  // Bg Body
  const bgBody = window
    .getComputedStyle(document.body, null)
    .getPropertyValue("background-color");

  document.documentElement.style.setProperty("--bg-document", bgBody);

  // Rate Progress
  $("[data-rate-progress]").each((index, element) => {
    const roundRadius = $(element).children().last().attr("r"),
      roundPercent = $(element).data("rateProgress"),
      roundCircum = 2 * roundRadius * Math.PI,
      roundDraw = (roundPercent * 20 * roundCircum) / 100;
    $(element).children().last().css("stroke-dasharray", roundDraw);
  });


    /* new stuff */


const getFractional = (val) => {
  const fractional = val.toString().split(".")[1];

  return fractional ? fractional : 1;
};

// Modal
const btnOpenModal = document.querySelectorAll('[data-kav-toggle="modal"]'),
  btnsCloseModal = document.querySelectorAll('[data-kav-dismiss="modal"]');

if (btnOpenModal.length > 0) {
  btnOpenModal.forEach((btnModal) => {
    btnModal.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        content = document.querySelector(el.dataset.kavTarget);

      if (content) {
        const backdrop = document.createElement("div");
        backdrop.classList.add("kav__modal-backdrop");
        backdrop.style.opacity = 0;

        bodyTag.appendChild(backdrop);

        setTimeout(() => {
          backdrop.removeAttribute("style");
        }, 5);

        content.classList.add("opened");
        htmlTag.style.overflow = "hidden";
      }
    });
  });
}

if (btnsCloseModal.length > 0) {
  btnsCloseModal.forEach((btnCloseModal) => {
    btnCloseModal.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        modal = el.closest(".kav__modal.opened"),
        backdrop = document.querySelector(".kav__modal-backdrop");

      if (modal) {
        modal.classList.remove("opened");
        backdrop.style.opacity = 0;

        setTimeout(() => {
          backdrop.remove();
          htmlTag.removeAttribute("style");
        }, 300);
      }
    });
  });
}

document.addEventListener("click", (ev) => {
  const el = ev.target,
    backdrop = document.querySelector(".kav__modal-backdrop");

  if (el.classList.contains("kav__modal-dialog")) {
    el.closest(".kav__modal.opened").classList.remove("opened");
    backdrop.style.opacity = 0;

    setTimeout(() => {
      backdrop.remove();
      htmlTag.removeAttribute("style");
    }, 300);
  }
});

// Max Length Value
const maxLengthValue = document.querySelectorAll("[data-kav-max-length]");

if (maxLengthValue.length > 0) {
  maxLengthValue.forEach((maxLengthEl) => {
    maxLengthEl.addEventListener("keyup", (ev) => {
      const el = ev.target,
        value = el.value,
        maxLength = el.dataset.kavMaxLength,
        elCounter = document.querySelector(el.dataset.kavTarget);

      if (Number(maxLength) >= value.length) {
        elCounter.textContent = `${maxLength}/${value.length}`;
      } else {
        elCounter.textContent = `${maxLength}/${maxLength}`;
        el.value = value.slice(0, maxLength);
      }
    });
  });
}

const toolTopMethod = (ev, text, durationFade) => {
  const el = ev.currentTarget,
    offset = el.getBoundingClientRect();

  const tooltip = document.createElement("div");
  tooltip.classList.add("kav__tooltip");
  tooltip.textContent = text;

  tooltip.style.cssText = `top:${offset.top - (el.scrollHeight + 32)}px;left:${
    offset.left + offset.width / 2 - tooltip.offsetWidth / 2
  }px;opacity:0;`;

  bodyTag.appendChild(tooltip);

  tooltip.style.left =
    offset.left + offset.width / 2 - tooltip.offsetWidth / 2 + "px";

  setTimeout(() => {
    tooltip.style.cssText = `top:${
      offset.top - tooltip.offsetHeight - 20
    }px;left:${
      offset.left + offset.width / 2 - tooltip.offsetWidth / 2
    }px;opacity:1;`;
  }, 5);

  if (durationFade) {
    setTimeout(() => {
      tooltip.style.cssText = `top:${
        offset.top - (el.scrollHeight + 32)
      }px;left:${
        offset.left + offset.width / 2 - tooltip.offsetWidth / 2
      }px;opacity:0;`;

      setTimeout(() => {
        tooltip.remove();
      }, 300);
    }, durationFade);
  }
};

// Copy Text
const btnCopy = document.querySelectorAll("[data-kav-copy]");

if (btnCopy.length > 0) {
  btnCopy.forEach((btn) => {
    btn.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        text = el.dataset.kavCopy;

      if (text) {
        navigator.clipboard.writeText(text);
        if (!document.querySelector(".kav__tooltip")) {
          toolTopMethod(ev, "کپی شد!", 3000);
        }
      }
    });
  });
}

// Open Element
const btnsOpen = document.querySelectorAll("[data-kav-open]");

if (btnsOpen.length > 0) {
  btnsOpen.forEach((btnOpen) => {
    btnOpen.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        content = document.querySelector(el.dataset.kavOpen);

      content && content.classList.add("opened");
    });
  });
}

// Toggle Element
const btnsToggle = document.querySelectorAll("[data-kav-toggle]");

if (btnsToggle.length > 0) {
  btnsToggle.forEach((btnToggle) => {
    btnToggle.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        content = document.querySelector(el.dataset.kavToggle);

      content && content.classList.toggle("opened");
    });
  });
}

// Close Element
const btnsClose = document.querySelectorAll("[data-kav-close]");

if (btnsClose.length > 0) {
  btnsClose.forEach((btnClose) => {
    btnClose.addEventListener("click", (ev) => {
      const el = ev.currentTarget,
        content = document.querySelector(el.dataset.kavClose);

      content && content.classList.remove("opened");
    });
  });
}

// Close Socials Suport
document.addEventListener("click", (ev) => {
  const el = ev.target,
    socialsSuport = document.querySelector(".kav__socials-suport__drop");

  if (
    socialsSuport &&
    socialsSuport.classList.contains("opened") &&
    el.contains(socialsSuport)
  ) {
    socialsSuport.classList.remove("opened");
  }
});

// Swiper Products
const swiperKavProducts = document.querySelector(".swiper-kav-products");

if (swiperKavProducts) {
  new Swiper(".swiper-kav-products", {
    direction: "vertical",
    slidesPerView: 1.5,
    spaceBetween: 24,
    autoHeight: true,
    mousewheel: {
      invert: true,
    },
    scrollbar: {
      el: ".swiper-scrollbar",
      draggable: true,
    },
    on: {
      init: (s) => {
        const { slides, params, el } = s,
          { slidesPerView, spaceBetween } = params;

        heightSwiper = -spaceBetween;

        for (let i = 0; i < slidesPerView; i++) {
          if (i !== Number(Math.floor(slidesPerView))) {
            heightSwiper += slides[i].children[0].scrollHeight + spaceBetween;
          } else {
            heightSwiper +=
              slides[i].children[0].scrollHeight *
                Number("0." + getFractional(slidesPerView)) +
              spaceBetween;
          }
        }

        el.style.height = heightSwiper + "px";

        if (slides.length > slidesPerView && window.innerWidth >= 992) {
          el.classList.add("has-items");
        }

        s.update();
      },
      transitionStart: (s) => {
        const { realIndex, slides, params, el } = s,
          { slidesPerView } = params;

        console.log(
          slides.length - Math.ceil(slidesPerView) >= realIndex ? "ok" : "err"
        );

        if (slides.length - Math.ceil(slidesPerView) >= realIndex) {
          el.classList.add("has-items");
        } else {
          el.classList.remove("has-items");
        }

        s.update();
      },
      toEdge: (s) => {
        const { el } = s;

        el.classList.remove("has-items");
      },
    },
  });
}

});

