"use client"; import type { TFunction } from "i18next"; import { useTranslation } from "react-i18next"; import { Button } from "@kandev/ui/button"; import { Spinner } from "@kandev/ui/spinner"; import { IconCheck, IconAlertTriangle } from "@tabler/icons-react"; import type { SelfUpdatePhase } from "@/hooks/domains/system/use-self-update"; type SelfUpdateProgressProps = { phase: SelfUpdatePhase; targetVersion: string | null; errorMessage: string | null; onDismiss: () => void; }; /** * The version string is a value; only the frame around it is copy. When the * target version is not known yet the whole sentence switches to a variant * that does not name one, rather than interpolating a translated noun phrase. */ function activeText(phase: SelfUpdatePhase, target: string | null, t: TFunction): string { switch (phase) { case "starting": return target ? t("system:selfUpdateStarting", { version: target }) : t("system:selfUpdateStartingUnknown"); case "installing": return target ? t("system:selfUpdateInstalling", { version: target }) : t("system:selfUpdateInstallingUnknown"); case "restarting": return t("system:selfUpdateRestarting"); default: return ""; } } function ActiveRow({ phase, targetVersion, }: { phase: SelfUpdatePhase; targetVersion: string | null; }) { const { t } = useTranslation(); return (
{activeText(phase, targetVersion, t)}

{t("system:selfUpdateKeepOpen")}

); } function DoneRow({ targetVersion }: { targetVersion: string | null }) { const { t } = useTranslation(); return (
{targetVersion ? t("system:selfUpdateDone", { version: targetVersion }) : t("system:selfUpdateDoneUnknown")}
); } function ErrorRow({ message, onDismiss }: { message: string | null; onDismiss: () => void }) { const { t } = useTranslation(); return (
{/* `message` comes from the update API and stays as sent. */} {message ?? t("system:selfUpdateFailed")}
); } function ProgressBody({ phase, targetVersion, errorMessage, onDismiss }: SelfUpdateProgressProps) { if (phase === "done") return ; if (phase === "error") return ; return ; } export function SelfUpdateProgress(props: SelfUpdateProgressProps) { if (props.phase === "idle") return null; return (
); }