import { useEffect, useRef, useState } from 'react'; import { Link } from 'react-router-dom'; import { X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { useTranslation } from '@/contexts/language'; const DISMISS_KEY = 'skatespots:first-run-dismissed'; /** Set once, the first time the tip has actually been shown. */ const SEEN_KEY = 'skatespots:first-run-seen'; /** The signup flow stamps this (ms). Only a *recent* signup counts as "first run". */ const SIGNUP_KEY = 'signup_completed'; const FRESH_WINDOW_MS = 2 * 24 * 60 * 60 * 1000; // 2 days /** * One-shot, frictionless first-run tip. * * It deliberately does NOT ask a new skater to create a spot, crew or wallet. * The map is already populated; the only action is an optional "Near Me" (one * location prompt) and a dismiss. Any content creation is left to the user's * own intent, not onboarding. */ export function FirstRunChecklist({ onFindNearby }: { onFindNearby?: () => void }) { const { t } = useTranslation(); const { user } = useCurrentUser(); const [dismissed, setDismissed] = useLocalStorage(DISMISS_KEY, false); const [seen, setSeen] = useLocalStorage(SEEN_KEY, false); const [fresh] = useState(() => { try { const at = Number(localStorage.getItem(SIGNUP_KEY) ?? 0); return Number.isFinite(at) && at > 0 && Date.now() - at < FRESH_WINDOW_MS; } catch { return false; } }); // Capture at mount so marking it seen doesn't hide the tip in this session. const seenAtMount = useRef(seen); useEffect(() => { if (user && fresh && !dismissed && !seenAtMount.current) setSeen(true); }, [user, fresh, dismissed, setSeen]); if (!user || dismissed || !fresh || seenAtMount.current) return null; return (

{t('mapUi.firstRunTitle')}

{t('mapUi.firstRunTip')}

{onFindNearby && ( )} setDismissed(true)} className="self-center rounded text-xs font-medium text-gray-500 underline underline-offset-2 hover:text-gray-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#ccff00] focus-visible:ring-offset-2 focus-visible:ring-offset-black" > {t('mapUi.firstRunJoinCrew')}
); }