/**
* Offline settings tab (#1135) — controls for:
* - Offline mode: a force-offline switch that first downloads everything, then
* routes the app to the cache + mutation queue.
* - Prepare for offline: an awaited, progress-tracked full download.
* - What to store: a map-tiles toggle plus a per-trip on/off.
* - Sync conflicts: a keep-mine / keep-theirs resolver and a default strategy.
* - Cache stats + clear.
*
* All of the logic lives in `useOfflineSettings`, shared with the phone twin
* `MSettingsOffline`; this file is the desktop markup over it.
*/
import React, { useState } from 'react'
import { RefreshCw, Trash2, Database, CloudOff, Download, Check, GitMerge, Map as MapIcon, AlertTriangle } from 'lucide-react'
import Section from './Section'
import ToggleSwitch from './ToggleSwitch'
import { SettingRow, SettingRows, SettingsHint, StatusPill, SETTINGS_BUTTON, SETTINGS_BUTTON_DANGER, SettingsColumns } from './settingsKit'
import { useOfflineSettings, offlineNoticeKey, isOfflineNoticeWarning, offlineProgressLabel, offlineRowMeta } from './useOfflineSettings'
import { useTranslation } from '../../i18n'
import CustomSelect from '../shared/CustomSelect'
import ConfirmDialog from '../shared/ConfirmDialog'
import { fs } from '../shared/DialogShell'
import type { ConflictStrategy } from '../../sync/offlinePrefs'
import type { QueuedMutation } from '../../db/offlineDb'
const EYEBROW = 'm-0 mb-2 font-geist font-bold uppercase tracking-[.08em] text-content-faint'
function conflictName(m: QueuedMutation): string {
const body = (m.body ?? {}) as { name?: unknown }
const server = (m.conflictServer ?? {}) as { name?: unknown }
return (typeof body.name === 'string' && body.name)
|| (typeof server.name === 'string' && server.name)
|| `#${m.entityId ?? ''}`
}
export default function OfflineTab(): React.ReactElement {
const { t, locale } = useTranslation()
const {
offline, forced,
rows, allTrips, pendingCount, failedCount, conflicts,
syncing, clearing, loading, preparing, progress, notice, prefs, canClear,
runPrepare, handleToggleForce, handleResync, handleClear,
handleToggleTiles, tripStorageState, handleToggleTrip, resolveConflict,
handleConflictStrategy, retryFailed, discardFailed,
} = useOfflineSettings()
const [confirmClear, setConfirmClear] = useState(false)
const progressLabel = offlineProgressLabel(progress, t)
return (
{/* Two columns by length: what the mode does and what is cached on the
left, the per-trip choice of what to keep on the right. */}
{/* Offline mode + prepare */}
}
>
{forced && (
)
}
/** One counter tile: the number big, what it counts under it. */
function Stat({ label, value, danger }: { label: string; value: number; danger?: boolean }) {
return (