import { useState } from "react"; import { api } from "../api/client"; import { useSession } from "../session/SessionContext"; import { useNavigate } from "react-router-dom"; import { AppShell, Notice } from "../components/AppShell"; import { Icon, type IconName } from "../components/Icon"; import { ru } from "../content/ru"; import { useDialog } from "../dialog/DialogContext"; import { humanDate, useToday } from "./useToday"; // F1 / F2 · Врач: следующий визит и связь с врачом (действия выполняет движок диалога) export function Doctor() { const t = ru.doctor; const navigate = useNavigate(); const dialog = useDialog(); const { plan, failed } = useToday(); const { session } = useSession(); const [connecting, setConnecting] = useState(false); const [connectFailed, setConnectFailed] = useState(false); const connect = async () => { if (!session || connecting) return; setConnecting(true); setConnectFailed(false); try { await api.connectDoctor(session.token); navigate("/today"); } catch { setConnectFailed(true); setConnecting(false); } }; const go = (button: string, label: string) => void dialog.send({ type: "button", button }, label).then((ok) => ok && navigate("/flow")); const actions: { button: string; label: string; icon: IconName }[] = [ { button: "menu:contact_doctor", label: t.write, icon: "message" }, { button: "menu:visit", label: t.earlier, icon: "calendar" }, { button: "safety_plan", label: t.plan, icon: "shield" }, ]; return (

{t.title}

{(failed || connectFailed) && {ru.common.networkError}} {!plan ? (!failed &&
) : !plan.has_doctor ? (
{t.noDoctor}
) : (
{t.visit} {plan?.next_visit ? humanDate(plan.next_visit) : t.visitNone}
{t.attending}
{actions.map((a) => ( ))}
{t.writeNote}
)}
); }