import { useState } from 'react'; import { Crown, Sparkles } from 'lucide-react'; import type { HomeNode } from '@/api'; import { useAppData } from '@/state/AppData'; import { findUnit, unitColor, unitProgress } from '@/state/curriculum'; import { useNav } from '@/nav/Navigator'; import { IslandPath } from '@/components/IslandPath'; import { IslandSheet } from '@/components/IslandSheet'; import { EmptyState, ErrorState, LoadingState, ProgressBar, Screen, ScreenHeader } from '@/components/ui'; import { toFa } from '@/lib/format'; import { MathText } from '@/lib/MathText'; /** نقشه‌ی جزیره‌های یک فصل، مثلِ مسیرِ دولینگو. */ export function UnitScreen({ unitId }: { unitId: string }) { const { home, homeError, refreshHome, companion } = useAppData(); const nav = useNav(); const paywall = () => nav.push({ name: 'subscription' }); const [openNode, setOpenNode] = useState(null); const found = findUnit(home, unitId); if (!found) { return ( {homeError ? void refreshHome()} /> : home ? : } ); } const { unit, unitIndex } = found; const color = unitColor(unitIndex); const progress = unitProgress(unit); const current = unit.nodes.find((n) => n.status !== 'completed' && n.status !== 'locked') ?? null; return ( : `${toFa(progress.done)} از ${toFa(progress.total)} جزیره`} color={color} back mascot={{ char: companion, mood: progress.percent >= 50 ? 'happy' : 'idle', size: 72 }} >
پیشرفت تو {toFa(progress.percent)}٪
{unit.nodes.length === 0 ? ( ) : ( <> (unit.requiresSubscription ? paywall() : setOpenNode(node))} onStart={(node) => (unit.requiresSubscription ? paywall() : nav.push({ name: 'quiz', nodeId: node.id }))} /> {unit.requiresSubscription && ( )}
{progress.done === progress.total ? 'این فصل تموم شد!' : 'ادامه بده!'}
)}
setOpenNode(null)} />
); }