"use client"; import { useEffect, useId, useRef } from "react"; import { MapPin } from "lucide-react"; import { useI18n } from "./I18nProvider"; const storageKey = "minegeo:intro:v1"; let seenThisSession = false; /** Home-only, decorative welcome. The underlying page always renders normally. */ export function FirstVisitIntro() { const { t } = useI18n(); const titleId = useId(); const dialog = useRef(null); useEffect(() => { const element = dialog.current; if (!element) return; const motion = window.matchMedia("(prefers-reduced-motion: reduce)"); let end: ReturnType | undefined; const finish = () => { clearTimeout(end); if (element.open) element.close(); }; // Defer the browser-only decision; Strict Mode can clean up its first setup. const start = setTimeout(() => { if (seenThisSession) return; try { if (localStorage.getItem(storageKey)) return; localStorage.setItem(storageKey, "seen"); } catch { try { if (sessionStorage.getItem(storageKey)) return; sessionStorage.setItem(storageKey, "seen"); } catch { // Both stores denied: keep the fallback for this page session in memory. } } seenThisSession = true; // This is decorative delight, so reduced motion goes straight to the site. if (motion.matches || !element.isConnected) return; // A welcome must never interrupt another modal, such as account notices. if (document.querySelector("dialog[open]")) return; element.showModal(); end = setTimeout(finish, 4000); }, 0); const motionChanged = () => { if (motion.matches) finish(); }; motion.addEventListener("change", motionChanged); element.addEventListener("close", finish); return () => { clearTimeout(start); finish(); motion.removeEventListener("change", motionChanged); element.removeEventListener("close", finish); }; }, []); return ( ); }