'use client'; import * as React from 'react'; import { motion } from 'framer-motion'; import Link from 'next/link'; import Image from 'next/image'; import { HoverShineOverlay } from '@/components/ui/HoverShineOverlay'; export interface Reference { id: string; title: string; slug: string; category: string; image?: { url: string; alt?: string; } | string | null; } interface ReferencesSliderProps { references?: Reference[]; badge?: string; title?: string; description?: string; ctaLabel?: string; ctaHref?: string; data?: { badge?: string; title?: string; description?: string; ctaLabel?: string; ctaHref?: string; } } export function ReferencesSlider(props: ReferencesSliderProps) { const { data } = props; const references = props.references || []; const containerRef = React.useRef(null); const [isDragging, setIsDragging] = React.useState(false); const [startX, setStartX] = React.useState(0); const [scrollLeft, setScrollLeft] = React.useState(0); const badge = props.badge || data?.badge || 'Ausgewählte Projekte'; const title = props.title || data?.title || 'Referenzen & Erfolge'; const description = props.description || data?.description || 'Ein Auszug unserer erfolgreich abgeschlossenen Projekte im Bereich Kabeltiefbau, Bohrtechnik und Netzinfrastruktur.'; const ctaLabel = props.ctaLabel || data?.ctaLabel || 'Alle Referenzen ansehen'; const ctaHref = props.ctaHref || data?.ctaHref || '/referenzen'; if (!references || references.length === 0) return null; // Fallback images pool if CMS doesn't provide one const fallbacks = [ '/assets/photos/DSC01123.JPG', '/assets/photos/DSC00850.JPG', '/assets/photos/DSC01129.JPG', '/assets/photos/DSC00010.JPG', ]; const onMouseDown = (e: React.MouseEvent) => { if (!containerRef.current) return; setIsDragging(true); setStartX(e.pageX - containerRef.current.offsetLeft); setScrollLeft(containerRef.current.scrollLeft); }; const onMouseLeave = () => { setIsDragging(false); }; const onMouseUp = () => { setIsDragging(false); }; const onMouseMove = (e: React.MouseEvent) => { if (!isDragging || !containerRef.current) return; e.preventDefault(); const x = e.pageX - containerRef.current.offsetLeft; const walk = (x - startX) * 2; // Scroll-fast containerRef.current.scrollLeft = scrollLeft - walk; }; return (

{badge}

{title}

{description}

{references.map((ref, i) => { const imgSrc = (ref.image && typeof ref.image === 'object' && ref.image.url) ? ref.image.url : fallbacks[i % fallbacks.length]; return (
{ref.title}
{ref.category}

{ref.title}

); })}
{ctaLabel}
); }