import { useId } from 'react'; import { useTranslation } from '../../i18n'; import type { Trip } from '../../types'; import ToggleSwitch from '../Settings/ToggleSwitch'; import { fs } from '../shared/DialogShell'; import { useCostsMode } from './useCostsMode'; /** * The switch between splitting a trip's costs and keeping the totals only * (#1714), at the foot of the Costs sidebar. Nothing is shown to someone who may * not change it, or on a trip of one. */ export function CostsModeCard({ trip, memberCount, canEdit, className, }: { trip: Trip | null | undefined; memberCount: number; canEdit: boolean; className: string; }) { const { t } = useTranslation(); const hintId = useId(); const { splitting, setSplitting, saving, offered } = useCostsMode(trip, memberCount, canEdit); if (!offered) return null; return (
{t('costs.mode.label')}

{splitting ? t('costs.mode.hintSplit') : t('costs.mode.hintTotals')}

void setSplitting(!splitting)} label={t('costs.mode.label')} describedBy={hintId} disabled={saving} />
); }