import { useState } from "react"; import { api, asUiError, type DatabaseCheck } from "@/lib/api"; import { repairServer, useRepair, clearRepairResult } from "@/lib/repairJob"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useT } from "@/i18n"; export function RepairCard({ serverId }: { serverId: string }) { const t = useT(); const job = useRepair(serverId); const [checking, setChecking] = useState(false); const [database, setDatabase] = useState(null); const [files, setFiles] = useState<{ path: string; kind: "missing" | "changed" | string }[] | null>(null); const [error, setError] = useState(null); async function check() { clearRepairResult(serverId); setChecking(true); setError(null); setDatabase(null); setFiles(null); try { setFiles(await api.verifyFiles(serverId)); setDatabase(await api.checkDatabase(serverId)); } catch (e) { setError(asUiError(e).technical); } finally { setChecking(false); } } const checks = job.result?.database ?? database; const busy = checking || job.busy; return

{t("repair.title")}

{t("repair.hint")}

{job.result &&

{t("repair.result", { files: job.result.restored.length, sql: job.result.applied.length })}

{t("repair.backup", { id: job.result.backup })}

{job.result.error &&

{job.result.error}

}
} {files && !job.result &&

{t("repair.fileCount", { n: files.length })}

} {files && !job.result && files.length > 0 && (
    {files.slice(0, 200).map((f) =>
  • {t(f.kind === "missing" ? "repair.fileMissing" : "repair.fileChanged")} {f.path}
  • )} {files.length > 200 &&
  • …
  • }
)} {checks?.map(c => { const pending = c.migrations.filter(m => m.status !== "applied"); return

{c.realm === "coa" ? "Conquest of Azeroth" : "Wildcard"}

{t("repair.dbCount", { columns: c.problems.length, sql: pending.length })}

{!c.full_schema &&

{t("repair.limited")}

}
    {c.problems.map((p,i) =>
  • {p.database}.{p.table}{p.column ? `.${p.column}` : ""}: {p.detail}
  • )} {pending.map(m =>
  • {m.db}/{m.id}: {m.status}{m.error ? ` — ${m.error}` : ""}
  • )}
{c.problems.length > 0 &&

{t("repair.unresolved")}

}
; })} {(error || job.error) &&

{job.error ?? error}

}
; }