import { STORAGE_CATEGORIES, type StorageBackend, type StorageCategory, type StorageConfig, type StorageMigrationStatus, type StorageTestResponse, } from '@trek/shared'; import { Activity, AlertTriangle, ArrowRightLeft, Check, CheckCircle2, Cloud, Copy, FolderTree, HardDrive, Loader2, Lock, Pencil, PlugZap, Plus, RefreshCw, RotateCcw, Trash2, X, type LucideIcon, } from 'lucide-react'; import React, { useEffect, useId, useRef, useState } from 'react'; import { useTranslation } from '../../../i18n'; import { formatBytes } from '../../../utils/formatBytes'; import { relativeTime } from '../../../utils/relativeTime'; import Section from '../../Settings/Section'; import { SETTINGS_BUTTON, SETTINGS_BUTTON_PRIMARY, SETTINGS_ICON_BUTTON, SettingRows, SettingsHint, StatusPill, } from '../../Settings/settingsKit'; import ConfirmDialog from '../../shared/ConfirmDialog'; import CustomSelect from '../../shared/CustomSelect'; import { NEUTRAL_TINT, fs } from '../../shared/DialogShell'; import { useToast } from '../../shared/Toast'; import { Tooltip } from '../../shared/Tooltip'; import BackendForm, { type BackendFormMirrorProps } from './BackendForm'; import { CACHE_CATEGORIES, adoptedMirrorFor, computeMigrationCandidates, effectiveCategoryMap, foldBackends, mirrorProbeTargets, primaryNameOf, removeBackend, removeBackendAndMirrors, renameBackendRefs, replicaCandidates, replicaOfPrimaries, setMirrorTargets, settingsDocumentOf, stripCategories, upsertBackend, usageByBackend, type FoldedBackendRow, type MigrationCandidate, } from './storageModel'; import { useStorageAdmin } from './useStorageAdmin'; /** Display-name mapper for joined category lists — the raw id renders only in the badge. */ const categoryNames = (t: (key: string) => string, ids: readonly string[]): string => ids.map((id) => t(`storage.category.${id}`)).join(', '); /** The compact buttons of a backend row: white on a hairline, a size under the card's own. */ const ROW_BUTTON = 'inline-flex items-center gap-1.5 rounded-[10px] bg-surface-card px-2.5 py-1.5 font-medium text-content shadow-sm ring-1 ring-edge-faint hover:bg-surface-secondary disabled:cursor-default disabled:opacity-50'; const ROW_BUTTON_PRIMARY = 'inline-flex items-center gap-1.5 rounded-[10px] bg-accent px-2.5 py-1.5 font-medium text-accent-text hover:opacity-90 disabled:cursor-default disabled:opacity-50'; /** The icon square on the left of a row. */ const TILE = 'grid h-9 w-9 flex-none place-items-center rounded-[10px] bg-surface-tertiary text-content-muted'; /** What a row says under its head line, lined up with the name rather than the tile. */ const DETAILS = 'mt-2 flex flex-col items-start gap-1.5 empty:hidden sm:pl-12'; const META = 'm-0 leading-snug text-content-faint'; const TYPE_ICON: Record = { local: HardDrive, s3: Cloud, mirror: Copy }; function TestResult({ result, failedLabel, okLabel, }: { result: StorageTestResponse | undefined; failedLabel: string; okLabel: string; }): React.ReactElement | null { if (result === undefined) return null; return (
: } > {result.ok ? okLabel : failedLabel} {result.targets.map((target) => (

{target.ok ? ( ) : ( )} {target.name} {target.error ? ` — ${target.error}` : ''}

))}
); } /** A thin bar for a running sync or move. */ function Progress({ done, total }: { done: number; total: number }): React.ReactElement { const share = total > 0 ? Math.min(100, Math.round((done / total) * 100)) : 0; return (