import { designToken } from "@ekklesia/design-tokens";
import { Button, ErrorState, InlineNotice, PageHeader, Panel } from "@ekklesia/ui";
import {
type ReactElement,
useCallback,
useEffect,
useId,
useRef,
useState,
useSyncExternalStore,
} from "react";
import type { DashboardDestination } from "../dashboard-routes.js";
import {
type EkklesiaHostConfig,
type HostAccount,
type HostAccountPreferences,
HostProtocolError,
saveHostAccountPreferences,
} from "../host-protocol.js";
import { AccountAvatar, accountDisplayName } from "./AccountAvatar.js";
import type { AppearancePreference } from "./appearance-preference.js";
import { dashboardBack } from "./dashboard-back.js";
import { DashboardLink } from "./DashboardLink.js";
import type { HostHistory } from "./host-history.js";
import { ShellIcon } from "./shell-icons.js";
/**
* The account area (DESIGN.md §9.2, ADR 0062): who you are signed in as, and your own settings.
*
* Personal, never church administration — that is Settings (ADR 0061). Nothing here needs a
* management permission, and nothing here can affect anyone else.
*/
const ACCOUNT: DashboardDestination = { kind: "account" };
const APPEARANCE: DashboardDestination = { kind: "account-section", section: "appearance" };
/**
* `/account`: the person's own account. Their name and email as they signed up with them, and the
* personal settings they can change. There is no profile editing yet, so nothing here pretends to
* be editable.
*/
export function AccountHomePage(props: {
readonly account: HostAccount;
readonly history: HostHistory;
readonly onSignOut: () => void;
}): ReactElement {
const { account } = props;
const hasName = account.name.trim().length > 0;
return (
{hasName ? (
Name
{accountDisplayName(account)}
) : undefined}
Email
{account.email}
Appearance
Light, dark, or matching your device, and how much the Dashboard moves.
);
}
interface ChoiceOption {
readonly value: Value;
readonly label: string;
readonly description: string;
}
const APPEARANCE_OPTIONS: readonly ChoiceOption[] = [
{ description: "Match your device's light or dark setting.", label: "System", value: "system" },
{ description: "Always use the light appearance.", label: "Light", value: "light" },
{ description: "Always use the dark appearance.", label: "Dark", value: "dark" },
];
const MOTION_OPTIONS: readonly ChoiceOption[] = [
{
description: "Reduce motion when your device asks for less.",
label: "System",
value: "system",
},
{ description: "Always keep animation to a minimum.", label: "Reduce", value: "reduce" },
{
description: "Keep the Dashboard's subtle animation, even if your device asks for less.",
label: "Allow",
value: "allow",
},
];
/**
* One preference as a native radio group: a `