import React, { type ReactNode } from 'react' import { Paintbrush, Eye, LayoutDashboard, Sun, Moon, Monitor, RotateCcw } from 'lucide-react' import { useTranslation } from '../../i18n' import { DialogSection, fs } from '../shared/DialogShell' import { Segmented } from '../shared/dialogParts' import Section from './Section' import ToggleSwitch from './ToggleSwitch' import { SETTINGS_BUTTON, SettingRow, SettingRows, StatusPill } from './settingsKit' import { APPEARANCE_SCHEMES, CUSTOM_ACCENT_PRESETS } from '../../theme/schemes' import { APPEARANCE_SCALE_MIN, APPEARANCE_SCALE_MAX } from '@trek/shared' import { DESKTOP_GROUPS, MOBILE_GROUPS, isHex } from './appearanceModel' import { useAppearanceEditor } from './useAppearanceEditor' const WIDGET_LABELS: Record = { sidebar: 'Right sidebar', currency: 'Currency', collections: 'Collections', timezones: 'Timezones', upcomingReservations: 'Upcoming reservations', atlas: 'Atlas / countries', tripsTotal: 'Trips total', daysTraveled: 'Days traveled', distanceFlown: 'Distance flown', } /** A tile of the scheme grid: a colour dot and a name, raised and outlined while chosen. */ const SWATCH = 'flex min-w-0 items-center gap-2 rounded-[12px] border bg-surface-card px-3 py-2.5 text-start font-medium text-content transition-colors' const swatchLook = (active: boolean) => active ? 'border-[color:var(--text-primary)] shadow-sm' : 'border-edge hover:border-content-faint' /** The round colour sample in a swatch tile. */ const DOT = 'h-4 w-4 flex-none rounded-full shadow-[inset_0_0_0_1px_var(--border-faint)]' export default function AppearanceSettingsTab(): React.ReactElement { const { t } = useTranslation() const tr = (key: string, fallback: string) => t(key) || fallback const { cfg, darkMode, isDark, update, setMode, setWidget, resetAll, accentLight, accentDark, customRatio } = useAppearanceEditor() // The stored mode, read the way the old boolean values meant it. const cur = darkMode const mode = cur === true ? 'dark' : cur === false ? 'light' : String(cur ?? '') return ( <> {/* ── Theme ───────────────────────────────────────────────── */}
{/* Color mode */} }, { value: 'dark', label: tr('settings.dark', 'Dark'), icon: }, { value: 'auto', icon: , label: ( <> {tr('settings.auto', 'Auto')} Auto ), }, ]} /> } /> {/* Color scheme swatches */}
{APPEARANCE_SCHEMES.map((s) => { const active = cfg.schemeId === s.id const dot = isDark ? s.swatch.dark : s.swatch.light return ( ) })} {/* Custom */}
{/* Custom accent picker */} {cfg.schemeId === 'custom' && (
{CUSTOM_ACCENT_PRESETS.map((c) => { const picked = accentLight === c && accentDark === c return (
update({ accent: { light: v, dark: accentDark } })} /> update({ accent: { light: accentLight, dark: v } })} /> = 4.5 ? 'success' : 'warning'}> {customRatio >= 4.5 ? `${tr('settings.appearance.contrastOk', 'Good contrast')} (${customRatio.toFixed(1)}:1)` : `${tr('settings.appearance.contrastLow', 'Low contrast')} (${customRatio.toFixed(1)}:1)`}
)}
{/* ── Readability ─────────────────────────────────────────── */}
{tr('settings.appearance.experimental', 'Experimental')}} > update({ transparency: !cfg.transparency })} /> update({ reduceMotion: !cfg.reduceMotion })} /> {/* Density */} update({ density: value })} options={[ { value: 'comfortable', label: tr('settings.appearance.comfortable', 'Comfortable') }, { value: 'compact', label: tr('settings.appearance.compact', 'Compact') }, ]} /> } /> {/* Text size — global, plus an always-visible row per size class with a live sample and an example of what each size affects. */} update({ fontScale: v })} />
update({ typeScale: { ...cfg.typeScale, title: v } })} /> update({ typeScale: { ...cfg.typeScale, subtitle: v } })} /> update({ typeScale: { ...cfg.typeScale, body: v } })} /> update({ typeScale: { ...cfg.typeScale, caption: v } })} />
{/* ── Dashboard widgets ───────────────────────────────────── */}
{DESKTOP_GROUPS.map((g) => { const masterOn = g.master ? cfg.dashboard.desktop[g.master] : true const rows = g.keys.map((k) => ( setWidget('desktop', k, !cfg.dashboard.desktop[k])} /> )) if (!g.master) { return {rows} } return ( setWidget('desktop', g.master as string, !masterOn)} label={tr(`settings.appearance.widget.${g.master}`, WIDGET_LABELS[g.master])} />} > {/* Its widgets only matter while the column is shown: dimmed, not hidden, while it is off. */} {rows} ) })}
{MOBILE_GROUPS.map((g) => ( {g.keys.map((k) => ( setWidget('mobile', k, !cfg.dashboard.mobile[k])} /> ))} ))}
) } function schemeFallback(id: string): string { const map: Record = { default: 'Default', highContrast: 'High contrast', indigo: 'Indigo', teal: 'Teal', rose: 'Rose', amber: 'Amber', violet: 'Violet', } return map[id] || id } function ToggleRow({ label, hint, on, onToggle }: { label: string; hint?: string; on: boolean; onToggle: () => void }) { return } /> } /** Where a set of widgets sits on the dashboard: a caption over its box of switches. */ function WidgetGroup({ caption, children }: { caption: string; children: ReactNode }) { return (
{caption}
{children}
) } /** A colour input with its name, in the box look of the fields. */ function ColorField({ label, value, onChange }: { label: string; value: string; onChange: (v: string) => void }) { return ( ) } const fill = (value: number) => ({ '--fill': `${((value - APPEARANCE_SCALE_MIN) / (APPEARANCE_SCALE_MAX - APPEARANCE_SCALE_MIN)) * 100}%` } as React.CSSProperties) /** A percentage in the corner of a slider. */ function Percent({ value }: { value: number }) { return {Math.round(value * 100)}% } function SliderRow({ label, value, onChange }: { label: string; value: number; onChange: (v: number) => void }) { return (
{label}
onChange(Number(e.target.value))} className="trek-range" style={fill(value)} />
) } function SizeRow({ sampleClass, name, example, sample, value, onChange }: { sampleClass: string; name: string; example: string; sample: string; value: number; onChange: (v: number) => void }) { return (
{sample}
{name} · {example}
onChange(Number(e.target.value))} className="trek-range" style={fill(value)} />
) }