/**
 * Online Courier Services Theme - Main JavaScript
 * Handles theme interactive functionality
 */

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

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

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

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

  $online_courier_services_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) {
          online_courier_services_dots_addNumericDots(event);
      }
  });

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

      $online_courier_services_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,
      margin: 20,
      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(" "));
  });
});