import { useNavigate } from "react-router-dom"; import type { TodayDose, TodayPrescription } from "../api/types"; import { AppShell, Notice } from "../components/AppShell"; import { Icon, type IconName } from "../components/Icon"; import { useCatalog } from "../content/reference"; import { ru } from "../content/ru"; import { useDialog } from "../dialog/DialogContext"; import { classify } from "../dialog/step"; import { WeekDots } from "./Meds"; import { humanDate, useToday } from "./useToday"; // Spec «Модуль Лекарства»: the expected-effect card is pushed on these days of therapy. const EFFECT_DAYS = [1, 7, 14]; function Task({ icon, title, sub, hero, chip, onClick, disabled, }: { icon: IconName; title: string; sub: string; hero?: boolean; chip?: string; onClick: () => void; disabled?: boolean; }) { return ( ); } function VisitCard({ date, onOpen }: { date: string; onOpen: () => void }) { return ( ); } function WeekCard({ rx, onOpen }: { rx: TodayPrescription; onOpen: () => void }) { const taken = rx.week.filter((w) => w.status === "taken").length; const counted = rx.week.filter((w) => w.status !== "none").length; return ( ); } // C1 / C2 · Сегодня export function Today() { const t = ru.today; const navigate = useNavigate(); const dialog = useDialog(); const { plan, failed } = useToday(); const catalog = useCatalog(); // An unanswered engine question (reminder, check-in, scale, unfinished onboarding) waits on the focus screen. const waiting = classify(dialog.pending); // A paused questionnaire is not an open step: the «continue the questionnaire» card below resumes it. const paused = waiting?.kind === "notice" && waiting.primary?.data === "intake:resume"; const hasOpenStep = waiting !== null && waiting.kind !== "idle" && waiting.kind !== "ack" && !paused; const surveyItem = waiting?.kind === "survey" ? catalog?.items[waiting.itemId] : undefined; const surveyForm = surveyItem ? catalog?.forms[surveyItem.form] : undefined; const go = (button: string, label: string) => void dialog.send({ type: "button", button }, label).then((ok) => ok && navigate("/flow")); // Questionnaires (stage 1 intake → stage 2 diary) replace the simple check-in once they are switched on. const q = plan?.questionnaires; const surveys = q?.enabled === true; const intakeOpen = surveys && q.intake !== "complete" && q.intake !== "review"; const diaryDue = surveys && q.intake === "complete" && !q.diary_done; const effectRx = plan?.prescriptions.find((p) => p.ref_id && p.therapy_day && EFFECT_DAYS.includes(p.therapy_day)); const pendingDoses = plan?.doses.filter((d) => d.status === "pending") ?? []; const takenDoses = plan?.doses.filter((d) => d.status === "taken") ?? []; const doseNow = pendingDoses.some((d) => d.time <= (plan?.now ?? "00:00")); const allDone = plan !== null && pendingDoses.length === 0 && plan.checkin_done && !hasOpenStep && !intakeOpen && !diaryDue && q?.intake !== "review"; const nextDose = plan?.prescriptions.flatMap((p) => p.times).sort()[0]; const noDoctor = plan !== null && !plan.has_doctor; const now = plan?.now ?? "00:00"; const openDose = (d: TodayDose) => navigate(`/dose/${d.id}`); const visit = plan?.next_visit ? navigate("/doctor")} /> : null; const hasDone = takenDoses.length > 0 || plan?.checkin_done; return (

{t.title}

{plan &&

{humanDate(plan.today)}

}
{failed && {ru.common.networkError}}
{hasOpenStep && (waiting?.kind === "survey" ? ( navigate("/flow")} /> ) : ( navigate("/flow")} /> ))} {surveys && q.intake === "review" && {t.intakeReview}} {effectRx && ( )} {allDone ? (

{t.allDoneTitle}

{nextDose ? t.allDoneNext(`завтра в ${nextDose}`) : t.allDoneNoMeds}

{plan && plan.prescriptions.length > 0 && ( )}
) : (
{pendingDoses.map((d) => ( ))} {intakeOpen && waiting?.kind !== "survey" && ( q.intake === "none" ? go("intake:start", t.intakeStart) : go("intake:resume", t.intakeResume) } /> )} {diaryDue && waiting?.kind !== "survey" && ( go("menu:checkin", q.diary_next ? t.diaryPart[q.diary_next] : t.diary)} /> )} {plan && !surveys && !plan.checkin_done && ( go("menu:checkin", t.checkin)} /> )}
)}
{plan?.next_visit && (
navigate("/doctor")} />
)} {!allDone && hasDone && (

{t.done}

{takenDoses.map((d) => (
{t.medTaken} {t.medTakenAt(d.time)}
))} {plan?.checkin_done && (
{surveys ? t.diaryDone : t.checkinDone}
)}
)} {plan?.prescriptions[0] && navigate("/meds")} />} {noDoctor ? (
{t.noDoctor}
) : (
)}
); }