import { useCompanion } from '@/state/companion'; import { Brain, Play, Zap } from 'lucide-react'; import { api } from '@/api'; import { useAppData } from '@/state/AppData'; import { findNode, findNodeOfLesson, unitColor } from '@/state/curriculum'; import { useNav } from '@/nav/Navigator'; import { useAsync } from '@/lib/useAsync'; import { SeyarMascot } from '@/mascots/SeyarMascot'; import { moodFromServer } from '@/mascots/seyar'; import { ErrorState, LoadingState, PrimaryButton, Screen, ScreenBody, ScreenHeader, Sep } from '@/components/ui'; import { toFa } from '@/lib/format'; import { MathText } from '@/lib/MathText'; import { Diagram } from '@/diagram'; import { StepText } from '@/lib/StepText'; import { FeedbackBar } from '@/components/FeedbackBar'; /** معرفیِ درس، پیش از تمرین. */ export function LessonScreen({ lessonId, nodeId }: { lessonId: number; nodeId?: string }) { const { home, companion } = useAppData(); const companionName = useCompanion().name; const nav = useNav(); const intro = useAsync(() => api.lesson.intro(lessonId), [lessonId], { key: `lesson-intro:${lessonId}` }); const ref = findNode(home, nodeId) ?? findNodeOfLesson(home, lessonId); const color = ref ? unitColor(ref.unitIndex) : '#ED6956'; const data = intro.data; const figs = (where: 'intro' | 'example' | 'step', index?: number) => (data?.figures ?? []) .filter((f) => f.where === where && (where !== 'step' || f.index === index)) .map((f, k) => ); return ( : '…'} color={color} back mascot={{ char: companion, mood: moodFromServer(data?.mascotAnimation), size: 72 }} subtitle={ ref && ( {/* ترتیبِ lessonIds «درسِ بعدی اول» است، نه ترتیبِ کتاب؛ پس شمارهی درس از آن درنمیآید. */} {toFa(ref.node.lessonIds.length)} درس ) } /> {intro.loading ? ( ) : intro.error || !data ? ( ) : ( <> {figs('intro')} {data.kind === 'video' && data.videoUrl && ( )} {data.example && ( مثال {figs('example')} )} {data.steps.length > 0 && ( قدمبهقدم {data.steps.map((step, i) => ( {toFa(i + 1)} {figs('step', i)} ))} )} {data.questionCount === 0 ? ( تمرین این درس بهزودی اضافه میشه ) : ( nav.replace({ name: 'quiz', lessonId, nodeId: ref?.node.id ?? nodeId })}> شروع تمرین ({toFa(data.questionCount)} سوال) )} nav.push({ name: 'ask', lessonId })} className="flex items-center justify-center gap-2 rounded-2xl bg-[#F5F1FF] py-3 text-sm font-bold text-[#7857E0]" > درباره این درس از {companionName} بپرس > )} ); }