"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { heroSlides as fallbackSlides, site } from "@/lib/site-data"; const SLIDE_INTERVAL = 5200; export type HeroSlide = { eyebrow: string; title: string; description: string; image: string; linkUrl?: string | null; }; export function HeroSlider({ slides }: { slides?: HeroSlide[] }) { const items: HeroSlide[] = slides?.length ? slides : fallbackSlides; const [activeIndex, setActiveIndex] = useState(0); const [isPaused, setIsPaused] = useState(false); const activeSlide = items[activeIndex] ?? items[0]; useEffect(() => { setActiveIndex(0); }, [items.length]); useEffect(() => { if (isPaused || items.length <= 1) return; const timer = window.setInterval(() => { setActiveIndex((current) => (current + 1) % items.length); }, SLIDE_INTERVAL); return () => window.clearInterval(timer); }, [isPaused, items.length]); if (!activeSlide) return null; const media = (
); return (
setIsPaused(true)} onMouseLeave={() => setIsPaused(false)} > {activeSlide.linkUrl ? ( {media} ) : ( media )}

{activeSlide.eyebrow}

{activeSlide.title}

{activeSlide.description}

مشاهده محصولات {site.phone}
{items.map((slide, index) => (
); }