"use client"; import Headline from "@/components/ui/headline"; import { useSplitHeading } from "@/lib/useTextRevealHeading"; import Image from "next/image"; import { useRef, useEffect } from "react"; import { gsap } from "gsap"; import { ScrollTrigger } from "gsap/ScrollTrigger"; gsap.registerPlugin(ScrollTrigger); const HowWork = () => { const headingRef = useRef(null); const paraRef = useRef(null); const containerRef = useRef(null); // Refs for animation targets const imageRef = useRef(null); const leftStepsRef = useRef<(HTMLDivElement | null)[]>([]); const rightStepsRef = useRef<(HTMLDivElement | null)[]>([]); useSplitHeading(headingRef, paraRef); const steps = [ { id: "01", text: "Deploy Whispering Trees Pulse sensor directly onto your tree.", position: "left", }, { id: "02", text: "Real-time data automatically streams to Whispering Trees Cloud.", position: "left", }, { id: "03", text: "Dashboard displays tree health, history, and irrigation requirements.", position: "right", }, { id: "04", text: "Export data or integrate seamlessly with city systems.", position: "right", }, ]; useEffect(() => { const ctx = gsap.context(() => { const tl = gsap.timeline({ scrollTrigger: { trigger: imageRef.current, start: "top 70%", toggleActions: "play none none none", }, }); // 1. Image: clip-path from bottom → top if (imageRef.current) { gsap.set(imageRef.current, { clipPath: "inset(100% 0% 0% 0%)" }); tl.to(imageRef.current, { clipPath: "inset(0% 0% 0% 0%)", duration: 1.2, ease: "power3.out", }); } leftStepsRef.current.forEach((el, i) => { if (el) { gsap.set(el, { opacity: 0, x: -80 }); tl.to( el, { opacity: 1, x: 0, duration: 0.8, ease: "power2.out", }, i === 0 ? "-=0.8" : "-=0.6" // stagger ); } }); rightStepsRef.current.forEach((el, i) => { if (el) { gsap.set(el, { opacity: 0, x: 80 }); tl.to( el, { opacity: 1, x: 0, duration: 0.8, ease: "power2.out", }, i === 0 ? "-=0.8" : "-=0.6" ); } }); }, containerRef); return () => ctx.revert(); }, []); return (
{/* Heading */}

The Whispering Trees{" "} Process.

Monitor tree health in real-time and optimize irrigation schedules with our intelligent sensor system, ensuring urban forests thrive while conserving water.

{/* Steps + Image */}
{/* Left Steps */}
{steps .filter((s) => s.position === "left") .map((step, i) => (
{ leftStepsRef.current[i] = el; }} className="tab:h-[200px] tab:w-[350px] flex h-[180px] w-full flex-col items-center gap-4 sm:h-[180px]" >

{step.id}

{step.text}

))}
{/* Center Image */}
Product
{/* Right Steps */}
{steps .filter((s) => s.position === "right") .map((step, i) => (
{ rightStepsRef.current[i] = el; }} className="tab:h-[200px] tab:w-[350px] flex h-[180px] w-full flex-col items-center gap-4 sm:h-[180px]" >

{step.id}

{step.text}

))}
); }; export default HowWork;