import { useState } from 'react'; import { CheckCircle2, ChevronDown, Circle, X } from 'lucide-react'; import { __, sprintf } from '../lib/i18n'; type ChecklistItem = { id: string; label: string; done: boolean; href?: string; }; type FirstWeekEmptyStateProps = { llmsTxtExists: boolean; robotsHasLlmsReference: boolean; botVisits30Days: number; contentSettingsUrl: string; agentReadyUrl: string; }; const DISMISSED_STORAGE_KEY = 'llmagnet_journey_dismissed'; const COLLAPSED_STORAGE_KEY = 'llmagnet_journey_collapsed'; function readFlag(key: string): boolean { try { return localStorage.getItem(key) === '1'; } catch { return false; } } function writeFlag(key: string, value: boolean): void { try { if (value) { localStorage.setItem(key, '1'); } else { localStorage.removeItem(key); } } catch { // localStorage unavailable — state just won't persist across reloads. } } export function FirstWeekEmptyState({ llmsTxtExists, robotsHasLlmsReference, botVisits30Days, contentSettingsUrl, agentReadyUrl, }: FirstWeekEmptyStateProps) { const [dismissed, setDismissed] = useState(() => readFlag(DISMISSED_STORAGE_KEY)); const [collapsed, setCollapsed] = useState(() => readFlag(COLLAPSED_STORAGE_KEY)); const hasBotVisit = botVisits30Days > 0; const items: ChecklistItem[] = [ { id: 'llms', label: __('Generate your llms.txt file', 'llmagnet-llm-txt-generator'), done: llmsTxtExists, href: contentSettingsUrl, }, { id: 'robots', label: __('Add llms.txt to robots.txt', 'llmagnet-llm-txt-generator'), done: robotsHasLlmsReference, href: agentReadyUrl, }, { id: 'wait', label: hasBotVisit ? __('First AI bot visit detected', 'llmagnet-llm-txt-generator') : __('Wait for the first AI bot crawl (usually 24–72 hours)', 'llmagnet-llm-txt-generator'), done: hasBotVisit, }, ]; const doneCount = items.filter((item) => item.done).length; const allDone = doneCount === items.length; // Once everything is complete the card celebrates in full; collapse only applies mid-journey. const isCollapsed = !allDone && collapsed; if (dismissed) { return null; } const handleDismiss = () => { setDismissed(true); writeFlag(DISMISSED_STORAGE_KEY, true); }; const toggleCollapsed = () => { setCollapsed((prev) => { const next = !prev; writeFlag(COLLAPSED_STORAGE_KEY, next); return next; }); }; return (
{allDone ? __( 'All steps are complete — AI crawlers have discovered your content. You can close this checklist.', 'llmagnet-llm-txt-generator' ) : __( 'No AI bot visits yet — that is normal on a fresh install. Complete these steps so crawlers can discover your content.', 'llmagnet-llm-txt-generator' )}