"use client"; import { useState, useEffect, useCallback, useRef } from "react"; import Image from "next/image"; import { Link } from "@/i18n/routing"; import { vipnagorgialla } from "@/components/Vipnagorgialla"; import { useTranslations } from "next-intl"; type Slide = { key: "compete" | "play" | "explore"; image: string; imageAlt: string; hero: string; href: "/turniirid" | "/piletid" | "/messiala"; flip?: boolean; fullBrightness?: boolean; }; // Helper to highlight "LAN" in "TIPILAN" with blue color function highlightLAN(text: string) { const parts = text.split(/(TIPILAN\w*)/gi); return parts.map((part, i) => { const upper = part.toUpperCase(); if (upper.startsWith("TIPILAN")) { const suffix = part.slice(7); // Everything after "TIPILAN" return ( TIPILAN {suffix.toUpperCase()} ); } return part; }); } const slides: Slide[] = [ { key: "compete", image: "/images/landing/compete_teaser.jpg", imageAlt: "Võistle", hero: "/images/landing/compete_hero.png", href: "/turniirid", }, { key: "play", image: "/images/landing/play_teaser.png", imageAlt: "Mängi", hero: "/images/landing/play_hero.png", href: "/piletid", flip: true, fullBrightness: true, }, { key: "explore", image: "/images/landing/explore_teaser.png", imageAlt: "Avasta", hero: "/images/landing/explore_hero.png", href: "/messiala", fullBrightness: true, }, ]; export default function TeaserCarousel() { const t = useTranslations("home.teaser"); const [current, setCurrent] = useState(0); const intervalRef = useRef | null>(null); const next = useCallback( () => setCurrent((c) => (c + 1) % slides.length), [], ); const prev = () => setCurrent((c) => (c - 1 + slides.length) % slides.length); const restartAutoplay = useCallback(() => { if (intervalRef.current) { clearInterval(intervalRef.current); } intervalRef.current = setInterval(next, 5000); }, [next]); useEffect(() => { restartAutoplay(); return () => { if (intervalRef.current) { clearInterval(intervalRef.current); } }; }, [restartAutoplay]); const headingOnRight = Boolean(slides[current]?.flip); return (
{/* Slides (fade transition + hero lift effect) */}
{slides.map((slide, i) => { const title = t(`${slide.key}.title`); const description = t(`${slide.key}.description`); const isActive = i === current; return (
{/* Background image */} {slide.imageAlt} {/* Overlay */}
{/* Content */}
{/* Title + description at bottom */}

{title}

{description}

{/* Hero image */}
{slide.imageAlt}
); })} {/* Floating heading (mobile) */}

{highlightLAN(t("heading"))}

{/* Floating heading (desktop/tablet) */}

{highlightLAN(t("heading"))}

{/* Arrow buttons */} {/* Navigation dots */}
{slides.map((_, i) => (
); }