"use client"; import { useEffect, useRef, useState } from "react"; import Link from "next/link"; import type { AppPromo } from "@/app/lib/types"; import { useTheme } from "@/app/lib/ThemeContext"; const isExternal = (url: string) => /^https?:\/\//i.test(url); /** Fixed cadence for hands-off slide advance; matches AnnouncementMarquee's constant-feel pacing. */ const AUTO_ADVANCE_MS = 5000; /** Minimum horizontal drag (px) before a touch gesture counts as a swipe rather than a tap. */ const SWIPE_THRESHOLD_PX = 40; const prefersReducedMotion = () => typeof window !== "undefined" && !!window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches; /** Tracks the OS-level "reduce motion" preference; used to pause auto-advance and video autoplay. * Reads the media query synchronously on first render (rather than defaulting to false and * correcting in an effect) so a reduced-motion video never autoplays even for one tick. */ function useReducedMotion(): boolean { const [reduced, setReduced] = useState(prefersReducedMotion); useEffect(() => { if (typeof window === "undefined" || !window.matchMedia) return; const mq = window.matchMedia("(prefers-reduced-motion: reduce)"); const onChange = () => setReduced(mq.matches); mq.addEventListener("change", onChange); return () => mq.removeEventListener("change", onChange); }, []); return reduced; } function Media({ promo, active, reducedMotion }: { promo: AppPromo; active: boolean; reducedMotion: boolean }) { const videoRef = useRef(null); useEffect(() => { const video = videoRef.current; if (!video) return; if (active && !reducedMotion) video.play().catch(() => {}); else video.pause(); }, [active, reducedMotion]); if (promo.mediaType === "VIDEO") { return (