import { useState } from 'react'; import { BookOpen, CheckCircle2, ChevronDown, Circle, Lock, Play, RotateCw } from 'lucide-react'; import { api, type HomeNode } from '@/api'; import { useNav } from '@/nav/Navigator'; import { useAsync } from '@/lib/useAsync'; import { Sheet } from '@/components/Sheet'; import { ErrorState, PrimaryButton } from '@/components/ui'; import { toFa } from '@/lib/format'; import { MathText } from '@/lib/MathText'; /** * برگه‌ی جزیره. دو دکمه: «اول درس‌ها رو بخون» (رنگی و بالا، چون تست‌کننده‌ها * دکمه‌ی کم‌رنگِ قبلی را پیدا نمی‌کردند) و «شروعِ آزمونِ جزیره». فهرستِ درس‌ها زیرِ دکمه‌ی اول باز می‌شود. */ export function IslandSheet({ node, color, onClose }: { node: HomeNode | null; color: string; onClose: () => void }) { const nav = useNav(); const [showLessons, setShowLessons] = useState(false); const lessons = useAsync( () => (node && showLessons ? api.nodeLessons(node.id) : Promise.resolve(null)), [node?.id, showLessons], ); const locked = node?.status === 'locked'; const done = node?.status === 'completed'; const close = () => { setShowLessons(false); onClose(); }; const start = () => { if (!node) return; close(); nav.push({ name: 'quiz', nodeId: node.id }); }; const openLesson = (lessonId: number) => { if (!node) return; close(); nav.push({ name: 'lesson', lessonId, nodeId: node.id }); }; // فقط درس‌هایی که سوال دارند در lessonIds هستند. const playable = new Set(node?.lessonIds ?? []); const list = lessons.data?.lessons.filter((l) => playable.has(Number(l.id))) ?? []; return ( : undefined}> {locked ? (

این جزیره هنوز قفله. جزیره قبلی رو تموم کن تا باز بشه.

) : ( <>

{done ? 'این جزیره رو تموم کردی! می‌تونی دوباره تمرینش کنی (امتیاز تازه نداره).' : 'اگه مطمئن نیستی، اول درس‌ها رو بخون؛ بعد آزمون کوتاه جزیره رو بده. هر جوابی بدی، آخرش جزیره بعدی باز می‌شه.'}

{done ? <> دوباره تمرین کن : <> شروع آزمون جزیره} {showLessons && ( lessons.loading ? (
دارم درس‌ها رو میارم…
) : lessons.error ? ( ) : ( <>

{toFa(list.filter((l) => l.done).length)} از {toFa(list.length)} درس خونده شده

) )} )}
); }