"use client"; import { useEffect, useRef } from "react"; import gsap from "gsap"; import { ScrollTrigger } from "gsap/ScrollTrigger"; if (typeof window !== "undefined") { gsap.registerPlugin(ScrollTrigger); } const STATS = [ { prefix: "", from: 7000, to: 7500, suffix: "", label: "Delivered packages" }, { prefix: "2.", from: 1, to: 6, suffix: " bil", label: "Tonnes of goods" }, { prefix: "", from: 10, to: 100, suffix: "+", label: "Countries covered" }, { prefix: "", from: 100, to: 550, suffix: "+", label: "Warehouses" }, ]; export default function AirFreightCoverage() { const sectionRef = useRef(null); const countersRef = useRef<(HTMLSpanElement | null)[]>([]); useEffect(() => { const section = sectionRef.current; if (!section) return; const trigger = ScrollTrigger.create({ trigger: section, start: "top 75%", once: true, onEnter: () => { STATS.forEach((stat, i) => { const el = countersRef.current[i]; if (!el) return; const obj = { val: stat.from }; gsap.to(obj, { val: stat.to, duration: 2, ease: "power2.out", delay: i * 0.12, onUpdate: () => { if (el) { el.textContent = Math.round(obj.val).toLocaleString("en-IN"); } }, }); }); }, }); return () => { trigger.kill(); }; }, []); return ( <>