const sectionScripts = {
about_stats:
`
    document.addEventListener("DOMContentLoaded", () => {
  const statCards = document.querySelectorAll(".aboutsection .grid > div");

  statCards.forEach((card, index) => {
    card.classList.add("scroll-animation", "scroll-fade-up");
    const delayClass = "delay-" + ((index + 1) * 100);
    card.classList.add(delayClass);
  });

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if(entry.isIntersecting){
        entry.target.classList.add("scroll-show");
        animateNumber(entry.target);
        observer.unobserve(entry.target);
      }
    });
  }, { threshold: 0.2 });

  statCards.forEach((card) => observer.observe(card));

  function animateNumber(card) {
    const numberDiv = card.querySelector(".text-4xl");
    if (!numberDiv || numberDiv.dataset.animated === "true") return;
    numberDiv.dataset.animated = "true";

    const originalText = numberDiv.innerText.trim();
    const numericValue = parseInt(originalText.replace(/[^0-9]/g, ""));
    const suffix = originalText.replace(/[0-9]/g, "");

    if (isNaN(numericValue)) return;

    let start = 0;
    const duration = 2000;
    const stepTime = 16;
    const increment = numericValue / (duration / stepTime);

    const timer = setInterval(() => {
      start += increment;
      if (start >= numericValue) {
        numberDiv.innerText = numericValue + suffix;
        clearInterval(timer);
      } else {
        numberDiv.innerText = Math.floor(start) + suffix;
      }
    }, stepTime);
  }
})`,

  gallery_grid:`
    function initGridGallery() {
     const modal = document.getElementById("lightboxModal");
    const modalImg = document.getElementById("lightboxImage");
    const galleryItems = document.querySelectorAll(".gallery-item");

    function handleClick(item) {
      const img = item.querySelector("img");
      const src = img?.getAttribute("src") || "";
      modalImg.src = src;
        modalImg.setAttribute("srcSet", src);
      modal.classList.remove("hidden");
    }

    galleryItems.forEach((item) => {
      item.addEventListener("click", () => handleClick(item));
    });

    // close modal
    modal?.addEventListener("click", () => {
      modal.classList.add("hidden");
      modalImg.src = "";
    });

    modal?.querySelector("div")?.addEventListener("click", (e) => {
      e.stopPropagation();
    });
  }
document.addEventListener("DOMContentLoaded", () => {
  initGridGallery();
})
  `,
  gallery_masonry:`
      function initMasonryGallery() {
     const closemodal = document.getElementById("closemodal");
    const modal = document.getElementById("lightboxModal");
    const modalImg = document.getElementById("lightboxImage");
    const galleryItems = document.querySelectorAll(".gallery-item-mas");

    function handleClick(item) {
      const img = item.querySelector("img");
      const src = img?.getAttribute("src") || "";
      modalImg.src = src;
        modalImg.setAttribute("srcSet", src);
      modal.classList.remove("hidden");
    }

    galleryItems.forEach((item) => {
      item.addEventListener("click", () => handleClick(item));
    });

    // close modal
    modal?.addEventListener("click", () => {
      modal.classList.add("hidden");
      modalImg.src = "";
    });
  closemodal?.addEventListener("click", () => {
      modal.classList.add("hidden");
      modalImg.src = "";
    });
    modal?.querySelector("div")?.addEventListener("click", (e) => {
      e.stopPropagation();
    });
  }
document.addEventListener("DOMContentLoaded", () => {
  initMasonryGallery();
})
  `,
    gallery_slider:`
   function initSliderGallery() {
  const galleries = document.querySelectorAll(".gallery-section");

  galleries.forEach((gallery) => {
    let currentIndex = 0;

    const modalImg = document.getElementById("lightboxImage");
    const gallerytitle = document.getElementById("gallerytitle");
    const gallerycategory = document.getElementById("gallerycategory");
    const gallerycounter = document.getElementById("gallerycounter");

    const thumbs = gallery.querySelectorAll(".thumb");
    const nextBtn = gallery.querySelector(".nextBtn");
    const prevBtn = gallery.querySelector(".prevBtn");

    function show(index) {
      thumbs.forEach((t) => t.classList.remove("galleryActive"));
      thumbs.forEach((t) => t.classList.add("galleryInActive"));
   const img = thumbs[index]?.querySelector("img");
   const src = img?.getAttribute("src") || "";
      modalImg.src = src;
      modalImg.alt = img?.getAttribute("data-title") || "Gallery item "+index + 1;
      gallerytitle.textContent = img?.getAttribute("data-title") || "";
      gallerycategory.textContent = img?.getAttribute("data-category") || "";
      gallerycounter.textContent =String(index + 1).padStart(2, "0") + " / "+String(thumbs.length).padStart(2, "0")

      thumbs[index]?.classList.remove("galleryInActive");
      thumbs[index]?.classList.add("galleryActive");
    }

    function next() {
      currentIndex = (currentIndex + 1) % thumbs.length;
      show(currentIndex);
    }

    function prev() {
      currentIndex = (currentIndex - 1 + thumbs.length) % thumbs.length;
      show(currentIndex);
    }

    nextBtn?.addEventListener("click", next);
    prevBtn?.addEventListener("click", prev);

    thumbs.forEach((thumb, index) => {
      thumb.addEventListener("click", () => {
        currentIndex = index;
        show(index);
      });
    });

    show(0);
  });
}
document.addEventListener("DOMContentLoaded", () => {
  initSliderGallery();
})
  `,
 stats_grid:`
 document.addEventListener("DOMContentLoaded", () => {

      const section = document.querySelector(".stats-section");
  if (!section) return;

  const cards = section.querySelectorAll(
    ".bg-gradient-extra-light.rounded-xl.border.border-gray-200"
  );

    cards.forEach((card, index) => {
      // Add smooth transition like framer-motion
      card.style.transition = "opacity 0.7s ease, transform 0.7s ease";
      card.style.transitionDelay = index * 0.1 + "s";

      const valueEl = card.querySelector(
        ".stat-number"
      );

      if (!valueEl) return;

      const originalText = valueEl.innerText.trim();
      const numericValue = parseInt(originalText.replace(/[^0-9]/g, ""));

      const prefix = originalText.match(/^[^0-9]+/)?.[0] || "";
      const suffix = originalText.match(/[^0-9]+$/)?.[0] || "";

      const observer = new IntersectionObserver(
        (entries) => {
          entries.forEach((entry) => {
            if (entry.isIntersecting) {
              // show animation
              card.style.opacity = "1";
              card.style.transform = "scale(1)";

              // counting animation
              if (!isNaN(numericValue)) {
                let start = 0;
                const duration = 2000;
                const increment = numericValue / (duration / 16);

                const timer = setInterval(() => {
                  start += increment;

                  if (start >= numericValue) {
                    valueEl.innerText = prefix + numericValue + suffix;
                    clearInterval(timer);
                  } else {
                    valueEl.innerText =
                      prefix + Math.floor(start) + suffix;
                  }
                }, 16);
              }

              observer.unobserve(card);
            }
          });
        },
        { threshold: 0.3 }
      );

      observer.observe(card);
    });
  })
`,

faq_accordion:`

document.addEventListener("DOMContentLoaded", () => {
   const faqButtons = document.querySelectorAll(".faq-item button");

    faqButtons.forEach((btn) => {
        btn.addEventListener("click", function() {
            // Button ka parent (.faq-item) dhundo
            const currentItem = this.closest(".faq-item");
            
            // Check karo ki ye pehle se khula hai ya nahi
            const isOpen = currentItem.classList.contains("active");

            // STEP A: Baaki sabko band kar do (Reset All)
            document.querySelectorAll(".faq-item").forEach((item) => {
                item.classList.remove("active");
                item.classList.remove("border-primary", "shadow-lg"); // Highlight hatao
                item.classList.add("border-primary-light"); // Default border wapas lao
            });

            // STEP B: Agar clicked item band tha, to use khol do
            if (!isOpen) {
                currentItem.classList.add("active");
                currentItem.classList.remove("border-primary-light");
                currentItem.classList.add("border-primary", "shadow-lg"); // Highlight add karo
            }
        });
    });
    });`,

products_carousel:`
document.addEventListener("DOMContentLoaded", function () {

  const slides = document.querySelectorAll(".product-slide");
  const prevBtn = document.querySelector(".carousel-prev");
  const nextBtn = document.querySelector(".carousel-next");
  const dots = document.querySelectorAll(".product-dot"); // sirf existing dots use

  let currentIndex = 0;

  // ----------------------------
  // SHOW SLIDE FUNCTION
  // ----------------------------
  function showSlide(index, direction = 1) {

    slides.forEach((slide, i) => {
      slide.classList.add("hidden");
      slide.classList.remove("slide-enter-right", "slide-enter-left");

      if (i === index) {
        slide.classList.remove("hidden");
        slide.classList.add(
          direction > 0 ? "slide-enter-right" : "slide-enter-left"
        );
      }
    });

    // DOT ACTIVE STYLE
    dots.forEach((dot, i) => {
      dot.classList.remove("w-8", "bg-primary");
      dot.classList.add("w-2", "bg-gray-300");

      if (i === index) {
        dot.classList.remove("w-2", "bg-gray-300");
        dot.classList.add("w-8", "bg-primary");
      }
    });

    currentIndex = index;
  }

  // ----------------------------
  // NEXT BUTTON
  // ----------------------------
  if (nextBtn) {
    nextBtn.addEventListener("click", function () {
      const next = (currentIndex + 1) % slides.length;
      showSlide(next, 1);
    });
  }

  // ----------------------------
  // PREV BUTTON
  // ----------------------------
  if (prevBtn) {
    prevBtn.addEventListener("click", function () {
      const prev = (currentIndex - 1 + slides.length) % slides.length;
      showSlide(prev, -1);
    });
  }

  // ----------------------------
  // DOT CLICK
  // ----------------------------
  dots.forEach((dot, index) => {
    dot.addEventListener("click", function () {
      showSlide(index, index > currentIndex ? 1 : -1);
    });
  });

  // INITIAL
  showSlide(0);

});
`,
testimonials_carousel:`
document.addEventListener("DOMContentLoaded", function () {

  const slides = document.querySelectorAll(".testimonial-slide");
  const prevBtn = document.querySelector(".testimonial-prev");
  const nextBtn = document.querySelector(".testimonial-next");
  const dots = document.querySelectorAll(".testimonial-dot");

  let currentIndex = 0;

  function showSlide(index, direction = 1) {

    slides.forEach((slide, i) => {
      slide.classList.add("hidden");
      slide.classList.remove("slide-enter-right", "slide-enter-left");

      if (i === index) {
        slide.classList.remove("hidden");
        slide.classList.add(
          direction > 0 ? "slide-enter-right" : "slide-enter-left"
        );
      }
    });

    dots.forEach((dot, i) => {
      dot.classList.remove("w-12", "bg-primary");
      dot.classList.add("w-3", "bg-gray-300");

      if (i === index) {
        dot.classList.remove("w-3", "bg-gray-300");
        dot.classList.add("w-12", "bg-primary");
      }
    });

    currentIndex = index;
  }

  // NEXT
  if (nextBtn) {
    nextBtn.addEventListener("click", () => {
      const next = (currentIndex + 1) % slides.length;
      showSlide(next, 1);
    });
  }

  // PREV
  if (prevBtn) {
    prevBtn.addEventListener("click", () => {
      const prev = (currentIndex - 1 + slides.length) % slides.length;
      showSlide(prev, -1);
    });
  }

  // DOT CLICK
  dots.forEach((dot, index) => {
    dot.addEventListener("click", () => {
      showSlide(index, index > currentIndex ? 1 : -1);
    });
  });

  // INIT
  showSlide(0);

});

`
}

module.exports = sectionScripts;