'use client'; import React, { useState, useEffect, useRef, useCallback } from 'react'; import Image from 'next/image'; import { UploadCloud, Cpu, Download, ArrowRight, Check, ShieldCheck, Sparkles, Zap, Lock, CheckCircle2 } from 'lucide-react'; import { InteractiveHoverButton } from '@/components/magicui/interactive-hover-button'; import { KineticText } from '@/components/magicui/kinetic-text'; import { AnimatedShinyText } from '@/components/magicui/animated-shiny-text'; interface HowItWorksSectionProps { title?: string; badge?: string; subtitle?: string; } export function HowItWorks3DSection({ title = 'How the process works', badge = 'Neural pipeline', subtitle = 'Synchronous GPU inference in volatile memory, returning studio-quality exports in seconds.', }: HowItWorksSectionProps) { const [activeStep, setActiveStep] = useState<1 | 2 | 3>(1); const [isPaused, setIsPaused] = useState(false); const [isInView, setIsInView] = useState(false); const sectionRef = useRef(null); const cardsContainerRef = useRef(null); const card1Ref = useRef(null); const card2Ref = useRef(null); const card3Ref = useRef(null); const scrollTimeoutRef = useRef(null); // Auto-scroll active card into view on mobile screens when activeStep changes useEffect(() => { if (typeof window === 'undefined' || window.innerWidth >= 768) return; const targetRef = activeStep === 1 ? card1Ref.current : activeStep === 2 ? card2Ref.current : card3Ref.current; if (targetRef && cardsContainerRef.current) { targetRef.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' }); } }, [activeStep]); // Sync active step when user swipes horizontally on mobile const handleMobileScroll = useCallback(() => { if (typeof window === 'undefined' || window.innerWidth >= 768) return; if (scrollTimeoutRef.current) clearTimeout(scrollTimeoutRef.current); scrollTimeoutRef.current = setTimeout(() => { const container = cardsContainerRef.current; if (!container) return; const scrollLeft = container.scrollLeft; const cardWidth = container.clientWidth * 0.85; const newStep = Math.round(scrollLeft / cardWidth) + 1; const clamped = Math.max(1, Math.min(3, newStep)) as 1 | 2 | 3; if (clamped !== activeStep) { setActiveStep(clamped); } }, 80); }, [activeStep]); useEffect(() => { return () => { if (scrollTimeoutRef.current) clearTimeout(scrollTimeoutRef.current); }; }, []); // Only run auto-advance interval when section is visible in viewport (0% CPU offscreen) useEffect(() => { const el = sectionRef.current; if (!el) return; const observer = new IntersectionObserver( ([entry]) => { setIsInView(entry.isIntersecting); }, { threshold: 0.08 } ); observer.observe(el); return () => observer.disconnect(); }, []); // Auto-advance traveling pipeline every 4.2 seconds only when visible useEffect(() => { if (!isInView || isPaused) return; const interval = setInterval(() => { setActiveStep((prev) => (prev === 3 ? 1 : ((prev + 1) as 1 | 2 | 3))); }, 4200); return () => clearInterval(interval); }, [isInView, isPaused]); return (
setIsPaused(true)} onMouseLeave={() => setIsPaused(false)} > {/* Studio Background Ambient Lighting */}
); }