/**
 * Legacy Cleaning Company Theme - Main JavaScript
 * Handles theme interactive functionality
 */

// Faq
document.addEventListener("DOMContentLoaded", function () {
  const legacy_cleaning_company_game_details = document.querySelectorAll(".faq-btm-title");

  legacy_cleaning_company_game_details.forEach((targetDetail) => {
    targetDetail.addEventListener("toggle", () => {
      if (targetDetail.open) {
        legacy_cleaning_company_game_details.forEach((legacy_cleaning_company_game_detail) => {
          if (legacy_cleaning_company_game_detail !== targetDetail) {
            legacy_cleaning_company_game_detail.removeAttribute("open");
          }
        });
      }
    });
  });
});

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

  var $legacy_cleaning_company_owl = $('.banner-main-section.owl-carousel');

  $legacy_cleaning_company_owl.owlCarousel({
      margin: 20,
      nav: false,
      autoplay: true,
      lazyLoad: true,
      autoplayTimeout: 3000,
      loop: true,
      dots: true,
      autoplayHoverPause: true,
      mouseDrag: true,
      responsive: {
          0: { items: 1 },
          600: { items: 1 },
          1000: { items: 1 }
      },
      onInitialized: function (event) {
          legacy_cleaning_company_dots_addNumericDots(event);
      }
  });

  function legacy_cleaning_company_dots_addNumericDots(event) {
      var $legacy_cleaning_company_dots = $(event.target).find('.owl-dot');

      $legacy_cleaning_company_dots.each(function (index) {
          var number = index + 1;
          var formatted = number < 10 ? '0' + number : number;
          $(this).html('<span>' + formatted + '</span>');
      });
  }


  // Category Slider
  $('.cat-position.owl-carousel').owlCarousel({
      nav: false,
      autoplay: true,
      lazyLoad: true,
      autoplayTimeout: 2000,
      loop: true,
      dots: false,
      responsive: {
        0: { items: 1 },
        768: { items: 2 },
        992: { items: 2 },
        1200: { items: 3 }
      },
      autoplayHoverPause: true,
      mouseDrag: true
  });
});

jQuery(document).ready(function () {
  jQuery("h3.product-main-heading").each(function () {
    var text = jQuery(this).text().trim();
    var words = text.split(" ");

    if (words.length >= 1) {
      var lastIndex = words.length - 1;
      words[lastIndex] =
        "<span style='color:var(--wp--preset--color--primary)'>" +
        words[lastIndex] +
        "</span>";
    }

    jQuery(this).html(words.join(" "));
  });
});