import type { RefObject } from "react"; import { Box, Text, TextAttributes, useUiHost, type InputRenderable } from "../../../ui"; import { colors } from "../../../theme/colors"; import { t } from "../../../i18n"; import { TextField } from "../../ui"; import type { AccountMode, AccountSubmitError } from "../../../plugins/builtin/cloud/auth-model"; import { ONBOARDING_DESKTOP } from "../onboarding-frame"; function TuiFieldRow({ label, active, value, masked, placeholder, editing, inputRef, onChange, }: { label: string; active: boolean; value: string; masked: boolean; placeholder: string; editing: boolean; inputRef: RefObject; onChange: (value: string) => void; }) { if (!active) { return ( {"✓ "} {`${label}: ${masked ? "*".repeat(value.length) : value}`} ); } return ( {label} {editing ? ( ) : ( {value ? (masked ? "*".repeat(value.length) : value) : t("Press enter to type...")} )} ); } export function AccountFormPanel({ mode, email, password, fieldIdx, editing, inputRef, submitting, submitError, validationError, onEmailChange, onPasswordChange, onFieldFocus, }: { mode: AccountMode; email: string; password: string; fieldIdx: number; editing: boolean; inputRef: RefObject; submitting: boolean; submitError: AccountSubmitError | null; validationError: string | null; onEmailChange: (value: string) => void; onPasswordChange: (value: string) => void; onFieldFocus: (index: 0 | 1) => void; }) { const desktop = useUiHost().kind === "desktop-web"; const onEmail = fieldIdx <= 0; if (desktop) { const status = submitting ? { color: colors.text, text: mode === "signup" ? t("Creating your account...") : t("Signing you in...") } : validationError || submitError ? { color: colors.negative, text: validationError ?? submitError?.message ?? "" } : null; return ( onFieldFocus(0)} onChange={onEmailChange} /> onFieldFocus(1)} onChange={onPasswordChange} /> {/* Reserved so the footer does not jump when a message appears. */} {status ? {status.text} : null} ); } return ( {!onEmail ? ( <> ) : null} {submitting ? ( {mode === "signup" ? t("Creating your account...") : t("Signing you in...")} ) : validationError || submitError ? ( {validationError ?? submitError?.message ?? ""} ) : ( {mode === "signup" ? t("New accounts get a verification email.") : t("Signs this terminal in to your account.")} )} {!submitting && submitError?.kind === "switch-to-login" ? ( {t("Press enter to log in with this email.")} ) : null} ); }