'use client'; import {useEffect, useRef} from 'react'; import {gsap} from 'gsap'; import {ScrollTrigger} from 'gsap/ScrollTrigger'; import VendingCard from './VendingCard'; import {featuredMachines} from '@/data/products'; import {useLanguage} from '@/app/context/LanguageContext'; gsap.registerPlugin(ScrollTrigger); export default function HorizontalShowcase() { const sectionRef = useRef(null); const trackRef = useRef(null); const backgroundRef = useRef(null); const {t} = useLanguage(); useEffect(() => { const ctx = gsap.context(() => { const track = trackRef.current; const section = sectionRef.current; const background = backgroundRef.current; if (!track || !section) return; const scrollDistance = () => Math.max(track.scrollWidth - window.innerWidth, 0); const backgroundColors = ['#062522', '#0b3d38', '#123d67', '#45235e', '#4a2c18']; const colorAtProgress = (progress: number) => gsap.utils.interpolate(backgroundColors, progress); const horizontalTween = gsap.to(track, { x: () => -scrollDistance(), ease: 'none', scrollTrigger: { trigger: section, start: 'top top', end: () => `+=${scrollDistance()}`, scrub: 1, pin: true, invalidateOnRefresh: true, onUpdate: self => { if (!background) return; background.style.backgroundColor = colorAtProgress(self.progress); background.style.backgroundPosition = `${self.progress * 100}% ${50 + self.progress * 30}%`; }, }, }); return () => { horizontalTween.scrollTrigger?.kill(); horizontalTween.kill(); }; }, sectionRef); return () => ctx.revert(); }, []); return (
{featuredMachines(t.machines).map(machine => ( ))}
); }