import { VNode, h } from "preact";
import { OfficerNotReady } from "../hooks/useOfficer.js";
import { CreateAccount } from "./CreateAccount.js";
import { UnlockAccount } from "./UnlockAccount.js";

export function HandleAccountNotReady({
  officer,
}: {
  officer: OfficerNotReady;
}): VNode {
  if (officer.state === "not-found") {
    return (
      <CreateAccount
        onNewAccount={(password) => {
          officer.create(password);
        }}
      />
    );
  }

  if (officer.state === "locked") {
    return (
      <UnlockAccount
        onAccountUnlocked={(pwd) => {
          officer.tryUnlock(pwd);
        }}
      />
    );
  }
  throw Error(`unexpected account state ${(officer as any).state}`);
}
