'use client'; import React, { useRef, useState, useEffect, useCallback } from 'react'; import Link from 'next/link'; import { ArrowRight, Check, Smartphone, ChevronLeft, ChevronRight } from 'lucide-react'; import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider'; export interface ShowcaseItem { id: string; index: string; tabLabel?: string; category: string; model: string; latency: string; title: string; tagline: string; description: string; variant?: 'comparison' | 'banner'; beforeUrl?: string; afterUrl?: string; bannerImage?: string; bannerBadge?: string; toolSlug: string; appSlug: string; appName: string; specs: string[]; } interface CinematicHorizontalProps { title?: string; badge?: string; subtitle?: string; items?: ShowcaseItem[]; animationMode?: 'horizontal' | 'vertical'; } export function CinematicHorizontalScrollSection({ title = 'Interactive Model Showcase', badge = 'FLAGSHIP TRANSFORMATION MODELS', subtitle = 'Browse the flagship tools with native cinematic pan controls.', items = [], animationMode = 'horizontal', }: CinematicHorizontalProps) { const containerRef = useRef(null); const trackRef = useRef(null); const [activeIndex, setActiveIndex] = useState(0); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(true); // Compute fluid horizontal translation directly from vertical scroll progress const updateTranslation = useCallback(() => { const container = containerRef.current; const track = trackRef.current; if (!container || !track) return; const rect = container.getBoundingClientRect(); const totalScrollable = container.offsetHeight - window.innerHeight; if (totalScrollable <= 0) return; // Direct proportional progress through the sticky section [0.0, 1.0] // 0.0: Card 0 centered, exactly as section pins // 1.0: Final card centered, seamlessly unpins into vertical scroll const progress = Math.max(0, Math.min(1, -rect.top / totalScrollable)); const cards = Array.from(track.querySelectorAll('article')); if (cards.length <= 1) return; const firstCenter = cards[0].offsetLeft + cards[0].offsetWidth / 2; const lastCenter = cards[cards.length - 1].offsetLeft + cards[cards.length - 1].offsetWidth / 2; const maxDistance = lastCenter - firstCenter; const translateX = progress * maxDistance; track.style.transform = `translate3d(-${translateX.toFixed(2)}px, 0, 0)`; // Sync active card index and button states const active = Math.min( cards.length - 1, Math.max(0, Math.round(progress * (cards.length - 1))) ); setActiveIndex(active); setCanScrollLeft(progress > 0.02); setCanScrollRight(progress < 0.98); }, []); useEffect(() => { const container = containerRef.current; const handleScroll = () => { updateTranslation(); }; // Support horizontal trackpad swipe (deltaX) on the showcase container const handleWheel = (e: WheelEvent) => { if (Math.abs(e.deltaX) > Math.abs(e.deltaY) && Math.abs(e.deltaX) > 6) { e.preventDefault(); window.scrollBy({ top: e.deltaX * 1.2, behavior: 'auto' }); } }; // Support touch horizontal swipe on mobile / tablet screens let touchStartX = 0; let touchStartY = 0; let initialScrollY = 0; const handleTouchStart = (e: TouchEvent) => { if (!e.touches[0]) return; touchStartX = e.touches[0].clientX; touchStartY = e.touches[0].clientY; initialScrollY = window.scrollY; }; const handleTouchMove = (e: TouchEvent) => { if (!e.touches[0]) return; const deltaX = touchStartX - e.touches[0].clientX; const deltaY = touchStartY - e.touches[0].clientY; if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > 10) { window.scrollTo({ top: initialScrollY + deltaX * 1.3, behavior: 'auto', }); } }; updateTranslation(); window.addEventListener('scroll', handleScroll, { passive: true }); window.addEventListener('resize', handleScroll); if (container) { container.addEventListener('wheel', handleWheel, { passive: false }); container.addEventListener('touchstart', handleTouchStart, { passive: true }); container.addEventListener('touchmove', handleTouchMove, { passive: true }); } return () => { window.removeEventListener('scroll', handleScroll); window.removeEventListener('resize', handleScroll); if (container) { container.removeEventListener('wheel', handleWheel); container.removeEventListener('touchstart', handleTouchStart); container.removeEventListener('touchmove', handleTouchMove); } }; }, [updateTranslation, items.length]); // Slide smoothly between cards using side arrows const scrollDirection = (direction: 'left' | 'right') => { const container = containerRef.current; if (!container) return; const totalScrollable = container.offsetHeight - window.innerHeight; if (totalScrollable <= 0) return; const cardsCount = items.length; if (cardsCount <= 1) return; const rect = container.getBoundingClientRect(); const containerTopInDoc = window.scrollY + rect.top; const progress = Math.max(0, Math.min(1, -rect.top / totalScrollable)); const currentCardIndex = Math.min( cardsCount - 1, Math.max(0, Math.round(progress * (cardsCount - 1))) ); let targetIndex = currentCardIndex; if (direction === 'right') { targetIndex = Math.min(cardsCount - 1, currentCardIndex + 1); } else if (direction === 'left') { targetIndex = Math.max(0, currentCardIndex - 1); } const targetProgress = targetIndex / (cardsCount - 1); const targetScrollY = Math.round(containerTopInDoc + targetProgress * totalScrollable); window.scrollTo({ top: targetScrollY, behavior: 'smooth', }); }; if (!items.length) return null; // Clean fluid vertical stack when horizontal scroll animation is disabled if (animationMode === 'vertical') { return (

{badge}

{title}

{subtitle}

{items.map((item) => ( ))}
); } // Fluid vertical scroll distance: 100vh base + 85vh per additional card const containerHeightVh = 100 + (items.length - 1) * 85; return (
{/* Section Header */}

{badge}

{title}

{subtitle}

Scroll down to explore models

{/* Carousel Viewport with Pinned Rail & Floating Side Arrows */}
{/* Soft edge fades for polished boundary */}
); } function ShowcaseCard({ item, isVertical }: { item: ShowcaseItem; isVertical?: boolean }) { const comparison = item.variant !== 'banner' && item.beforeUrl && item.afterUrl; return (
{comparison ? ( ) : (
{/* eslint-disable-next-line @next/next/no-img-element */} {item.title}
{item.bannerBadge || item.model}
)}
{item.index} {item.latency}

{item.category}

{item.title}

{item.description}

    {item.specs.slice(0, 3).map((spec) => (
  • {spec}
  • ))}
Try online App
); }