import React from 'react' import { Loader2, Map as MapIcon, Settings2 } from 'lucide-react' import { useTranslation } from '../../i18n' import Section from '../Settings/Section' import { SettingRows, SettingsHint } from '../Settings/settingsKit' import { fs } from '../shared/DialogShell' import { EditorField, INPUT, Segmented } from '../shared/dialogParts' import CustomSelect from '../shared/CustomSelect' import { MapView } from '../Map/MapView' import { SYMBOLS, currenciesWith } from '../Budget/BudgetPanel.constants' import type { DistanceUnit, WeekStart } from '../../types' import { weekStartOptions } from '../../utils/calendarWeek' import { withTileApiKey } from '../../utils/tileUrl' import { defaultStyleForProvider } from '../Map/glProviders' import { MAP_PRESETS, type MapProvider } from '../Settings/mapSettingsModel' import RoutingInstanceFields from './RoutingInstanceFields' import { useDefaultUserSettings, type Defaults } from './useDefaultUserSettings' /** * One default as a row of the card's white box: its name (with the reset link * once it is set) on the left, the choice on the right. `stacked` puts a wide * choice and a hint under the name. The label sits straight in the row, so the * row is the nearest box around both the name and its choice. */ function ChoiceRow({ label, hint, stacked = false, children, }: { label: React.ReactNode hint?: string stacked?: boolean children: React.ReactNode }) { return (
{hint &&

{hint}

}
{children}
) } /** A wide field box inside the white rows, for the map card's token and style. */ const FIELD_ROW = 'px-3.5 py-3' /** On/Off for a boolean default; neither is pressed while it is unset. */ function onOffValue(value: boolean | undefined): string { if (value === true) return 'on' if (value === false) return 'off' return '' } /** The stored colour mode as one of the three choices; a legacy boolean still picks light or dark. */ function colorModeValue(value: string | boolean | undefined): string { if (value === true) return 'dark' if (value === false) return 'light' return value ?? '' } /** A failed save names the error it threw, or falls back to the generic one. */ function errorText(err: unknown, fallback: string): string { return err instanceof Error ? err.message : fallback } export default function DefaultUserSettingsTab(): React.ReactElement { const { t, locale } = useTranslation() const { defaults, loaded, managed, isSet, save, reset, mapTileUrl, setMapTileUrl, mapboxToken, setMapboxToken, cartoKey, setCartoKey, mapboxStyle, setMapboxStyle, mapPreviewPlaces, mapProvider, glStylePresets, styleKey, saveMapProvider, pickTilePreset, pickStylePreset, commitStyle, } = useDefaultUserSettings({ errorMessage: errorText, previewCreatedAt: () => String(new Date()) }) // Inside the row's own