"use client"; import Image from "next/image"; import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from "react"; import { Icon } from "./ui"; import { homeAssets } from "../../shared/header"; import s from "./home.module.css"; export type GalleryShot = { label?: string; icon?: string; image: string; alt: string; available: boolean }; export type GallerySlide = { name: string; icon: string; title: string; description: ReactNode; /** One screenshot, or several views of the same capability switched inside the figure. */ shots: GalleryShot[]; link?: string; /** Optional external reference shown beside "了解更多", e.g. an upstream repository. */ external?: { label: string; href: string; logo?: string }; }; // The showcase plays itself once it is on screen: every screenshot stays for // STEP_MS, and multi-view items walk through their views before moving on. // Keyboard focus pauses it; any click stops it for good. const STEP_MS = 4000; const AUTO_ROUNDS = 2; /** Feature descriptions beside a shared screenshot; each item switches its corresponding view. */ export function ProductGallery({ id, label, slides, layout = "sidebar" }: { id: string; label: string; slides: GallerySlide[]; layout?: "sidebar" | "compact" }) { const root = useRef(null); const [item, setItem] = useState(0); const [shot, setShot] = useState(0); const [auto, setAuto] = useState(true); const [steps, setSteps] = useState(0); const [visible, setVisible] = useState(false); const [paused, setPaused] = useState(false); const totalSteps = slides.reduce((count, slide) => count + slide.shots.length, 0); const active = slides[item]; const activeShot = active.shots[shot]; useEffect(() => { const element = root.current; if (!element) return; const observer = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting), { threshold: 0.4 }); observer.observe(element); return () => observer.disconnect(); }, []); const running = auto && visible && !paused; useEffect(() => { if (!running || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; const timer = window.setTimeout(() => { const lastView = shot + 1 >= slides[item].shots.length; setShot(lastView ? 0 : shot + 1); if (lastView) setItem((item + 1) % slides.length); setSteps(steps + 1); if (steps + 1 >= totalSteps * AUTO_ROUNDS) setAuto(false); }, STEP_MS); return () => window.clearTimeout(timer); }, [running, item, shot, steps, slides, totalSteps]); function selectItem(index: number) { setAuto(false); setItem(index); setShot(0); } function selectView(index: number, view: number) { setAuto(false); setItem(index); setShot(view); } return
setPaused(true)} onBlur={() => setPaused(false)}>
{slides.map((slide, index) =>
{ if (index !== item) selectItem(index); }}>

{slide.description}

{slide.shots.length > 1 &&
{slide.shots.map((entry, view) => { const current = index === item && view === shot; return ; })}
} {(slide.link || slide.external) && }
)}
{active.name}{active.shots.length > 1 && activeShot.label && · {activeShot.label}}
{activeShot.available ? 查看原图 : 待补充}
{/* Every screenshot stays mounted in one cell so switching cross-fades without resizing. */}
{slides.flatMap((slide, index) => slide.shots.map((entry, shotIndex) => { const current = index === item && shotIndex === shot; return
{entry.available ? {entry.alt} :
截图待补充{`website-docs/homepage/public${homeAssets}/product/${entry.image}.png`}
}
; }))}
; }