"use client"; import { useState, useEffect, useRef } from "react"; import { CHAMFER } from "@/lib/chamfer"; import Link from "next/link"; import { ChevronDown, ArrowRight } from "lucide-react"; import styles from "./ScreenshotAccordion.module.css"; /* ─── Types ───────────────────────────────────────────────────────────── */ export interface ScreenshotAccordionItem { title: string; body: string; /** Path to screenshot image — falls back to a generated placeholder */ screenshot?: string; /** Optional deep-link to the matching product page (e.g. "/produkt/chat") */ href?: string; } interface ScreenshotAccordionProps { items: ScreenshotAccordionItem[]; /** Optional section badge (e.g. "FUNKTIONEN") */ badge?: string; /** Optional section headline */ headline?: string; /** Optional section subtext */ subtext?: string; /** Auto-cycle interval in ms — set 0 to disable (default: 5000) */ interval?: number; /** Section background (default white); set to match an adjacent section. */ background?: string; /** Optional section spacing overrides (default: 80px each). */ paddingTop?: number; paddingBottom?: number; } /* ─── Placeholder SVG ─────────────────────────────────────────────────── */ function placeholderSvg(label: string, index: number): string { const colors = ["#EEF2FF", "#F0FDF4", "#FFF7ED", "#FDF2F8"]; const accents = ["#6366F1", "#22C55E", "#F97316", "#EC4899"]; const bg = colors[index % colors.length]; const accent = accents[index % accents.length]; return `data:image/svg+xml,${encodeURIComponent(` ${label} `)}`; } /* ─── Component ───────────────────────────────────────────────────────── */ export default function ScreenshotAccordion({ items, badge, headline, subtext, interval = 5000, background = "var(--surface)", paddingTop = 80, paddingBottom = 80, }: ScreenshotAccordionProps) { const [activeIndex, setActiveIndex] = useState(0); const [progressRunId, setProgressRunId] = useState(0); const [isInView, setIsInView] = useState(true); const [bodyMinHeight, setBodyMinHeight] = useState(0); const cycleTimeoutRef = useRef | null>(null); const sectionRef = useRef(null); const accordionColumnRef = useRef(null); const autoCycleEnabled = interval > 0 && items.length > 1; const shouldAutoCycle = autoCycleEnabled && isInView; useEffect(() => { const section = sectionRef.current; if (!section || typeof IntersectionObserver === "undefined") { return; } const observer = new IntersectionObserver( (entries) => { const entry = entries[0]; setIsInView(Boolean(entry?.isIntersecting)); }, { threshold: 0.2 } ); observer.observe(section); return () => { observer.disconnect(); }; }, []); useEffect(() => { if (!shouldAutoCycle) { if (cycleTimeoutRef.current) { clearTimeout(cycleTimeoutRef.current); cycleTimeoutRef.current = null; } return; } cycleTimeoutRef.current = setTimeout(() => { setActiveIndex((prev) => (prev + 1) % items.length); setProgressRunId((prev) => prev + 1); }, interval); return () => { if (cycleTimeoutRef.current) { clearTimeout(cycleTimeoutRef.current); cycleTimeoutRef.current = null; } }; }, [activeIndex, interval, items.length, shouldAutoCycle]); useEffect(() => { const column = accordionColumnRef.current; if (!column || typeof window === "undefined") { return; } let frameId = 0; const measure = () => { const columnWidth = column.clientWidth; if (columnWidth <= 0) { return; } const bodyWidth = Math.max(0, columnWidth - 24 * 2); const probe = document.createElement("p"); probe.style.position = "absolute"; probe.style.visibility = "hidden"; probe.style.pointerEvents = "none"; probe.style.margin = "0"; probe.style.padding = "0"; probe.style.width = `${bodyWidth}px`; probe.style.fontSize = "14px"; probe.style.lineHeight = "1.625"; probe.style.fontFamily = "var(--font-sans)"; probe.style.whiteSpace = "normal"; probe.style.color = "var(--text-secondary)"; column.appendChild(probe); let maxHeight = 0; for (const item of items) { probe.textContent = item.body; const height = Math.ceil(probe.getBoundingClientRect().height); if (height > maxHeight) { maxHeight = height; } } column.removeChild(probe); setBodyMinHeight(maxHeight); }; const scheduleMeasure = () => { if (frameId) { cancelAnimationFrame(frameId); } frameId = requestAnimationFrame(measure); }; scheduleMeasure(); const resizeObserver = typeof ResizeObserver !== "undefined" ? new ResizeObserver(scheduleMeasure) : null; resizeObserver?.observe(column); window.addEventListener("resize", scheduleMeasure); return () => { resizeObserver?.disconnect(); window.removeEventListener("resize", scheduleMeasure); if (frameId) { cancelAnimationFrame(frameId); } }; }, [items]); const handleClick = (index: number) => { setActiveIndex(index); setProgressRunId((prev) => prev + 1); }; const hasHeader = badge || headline || subtext; const activeHref = items[activeIndex]?.href; return (
{/* Optional header */} {hasHeader && (
{badge && ( {badge} )} {headline && (

{headline}

)} {subtext && (

{subtext}

)}
)} {/* Content: Accordion + Screenshot */}
{/* Left: Accordion */}
{items.map((item, i) => { const isActive = i === activeIndex; return ( {/* Right: fixed screenshot stage. Every image occupies the same absolute layer, so switching modules never changes the row dimensions. The stage itself lifts on hover; the image is never zoomed inside a clipped frame, keeping every edge of the product UI visible. */}
{(() => { const screenLayer = ( {items.map((item, i) => ( {`Screenshot: ))} ); return activeHref ? ( {screenLayer} ) : (
{screenLayer}
); })()}
); }