/**
* Wiped-storage recovery screen. Shown when wipeCheck() says an identity
* existed on this device but the browser evicted its storage (iOS does this
* to rarely-used sites). We explain what happened and offer seed import —
* NEVER a silent new identity: that would orphan the user's contacts and
* profile without them understanding why. Starting over is available, but
* only behind an explicit, worded confirmation.
*/
import { abandonLostIdentity, type ActiveIdentity } from "../../core/identity-store";
import { t } from "../i18n";
import { h, sheet } from "../ui-kit";
import { importPanel } from "./identity-onboarding";
export function renderRecovery(
root: HTMLElement,
onDone: (id: ActiveIdentity) => void,
onStartOver: () => void,
): void {
const startOver = h(
"button",
{ type: "button", class: "btn ghost danger-ghost", "data-testid": "rec-start-over" },
t("recStartOver"),
);
startOver.addEventListener("click", () => {
const yes = h("button", { type: "button", class: "btn danger", "data-testid": "rec-start-over-yes" }, t("recStartOverYes"));
const no = h("button", { type: "button", class: "btn ghost" }, t("cancel"));
const s = sheet(
h(
"div",
{},
h("h2", { class: "sheet-title" }, t("recStartOver")),
h("p", { class: "muted" }, t("recStartOverConfirm")),
h("div", { class: "btn-row" }, no, yes),
),
);
no.addEventListener("click", () => s.close());
yes.addEventListener("click", () => {
abandonLostIdentity();
s.close();
onStartOver();
});
});
root.replaceChildren(
h(
"div",
{ class: "onboarding", "data-testid": "recovery" },
h(
"div",
{ class: "onb-inner" },
h("div", { class: "glyph" }, "🌪️"),
h("h2", {}, t("recTitle")),
h("p", { class: "muted" }, t("recBody")),
h("h3", { class: "sub-title" }, t("recImport")),
importPanel(onDone),
startOver,
),
),
);
}