import { useState, type FormEvent } from 'react'; import { useI18n } from '../lib/i18n'; import { DEFAULT_PROFILE } from '../lib/profile'; import type { Profile, ProfileKind } from '../lib/types'; import { Icon } from './ui'; interface Props { initial: Profile | null; onSave: (p: Profile) => void; } export function ProfileView({ initial, onSave }: Props) { const { t } = useI18n(); const [p, setP] = useState(initial ?? DEFAULT_PROFILE.wheelchair); const set = (k: K, v: Profile[K]) => setP((cur) => ({ ...cur, [k]: v })); const submit = (e: FormEvent) => { e.preventDefault(); onSave(p); }; const pickKind = (kind: ProfileKind) => setP(DEFAULT_PROFILE[kind]); return (

{t('profile.title')}

{t('profile.intro')}

{t('profile.kind')} {(['wheelchair', 'stroller'] as const).map((k) => (
pickKind(k)} />
))}
{t('profile.limits')} set('maxKerbCm', v)} /> set('minWidthM', v / 100)} /> set('maxInclinePct', v)} />
{t('profile.prefs')} set('avoidCobbles', v)} /> set('needToilet', v)} /> set('needRest', v)} /> {p.kind === 'stroller' && ( set('needChanging', v)} /> )}

{t('profile.privacy')}

); } function Range({ id, label, min, max, step, value, unit, onChange }: { id: string; label: string; min: number; max: number; step: number; value: number; unit: string; onChange: (v: number) => void; }) { return (
onChange(Number(e.target.value))} />
); } function Check({ id, label, checked, onChange }: { id: string; label: string; checked: boolean; onChange: (v: boolean) => void }) { return (
onChange(e.target.checked)} />
); }