import { useEffect, useState } from "react"; import type { ReactNode } from "react"; import { Link, useParams } from "react-router-dom"; import type { SessionUser } from "@ledger/shared"; import { PageHeader } from "./PageHeader"; export type PreferencesState = { theme: "system" | "light" | "dark"; compactSidebar: boolean; emailNotifications: boolean; productUpdates: boolean; smartText: boolean; showLineNumbers: boolean; }; const sections = [ ["profile", "Profile"], ["preferences", "Preferences"], ["appearance", "Appearance"], ["notifications", "Notifications"], ["account", "Account"] ] as const; function SettingsRow({ label, description, control }: { label: string; description: string; control: ReactNode; }) { return (
{label}

{description}

{control}
); } function Toggle({ checked, onChange, disabled = false, label }: { checked: boolean; onChange: (next: boolean) => void; disabled?: boolean; label: string; }) { return ( ); } export function PreferencesPage({ user, preferences, onUpdatePreferences, onLogout }: { user: SessionUser; preferences: PreferencesState; onUpdatePreferences: (patch: Partial) => void; onLogout: () => Promise; }) { const { section = "preferences" } = useParams(); const currentSection = sections.some(([key]) => key === section) ? section : "preferences"; const [displayName, setDisplayName] = useState(user.displayName); useEffect(() => { setDisplayName(user.displayName); }, [user.displayName]); function renderSection() { switch (currentSection) { case "profile": return (

Profile

setDisplayName(event.target.value)} />} /> } />
); case "appearance": return (

Appearance

onUpdatePreferences({ theme: event.target.value as PreferencesState["theme"] }) } > } /> onUpdatePreferences({ compactSidebar: next })} /> } />
); case "notifications": return (

Notifications

onUpdatePreferences({ emailNotifications: next })} /> } /> onUpdatePreferences({ productUpdates: next })} /> } />
); case "account": return (

Account

{user.role}} /> void onLogout()}> Sign out } /> Unavailable} />
); case "preferences": default: return ( <>

Preferences

onUpdatePreferences({ smartText: next })} /> } /> onUpdatePreferences({ showLineNumbers: next })} /> } />
); } } return (
key === currentSection)?.[1] ?? "Preferences"} description="Manage settings that affect your personal Ledger experience on this device." /> {renderSection()}
); }