import React, { useEffect, useRef, useState } from 'react' import { Activity, FolderTree, HardDrive } from 'lucide-react' import { STORAGE_CATEGORIES, type StorageBackend, type StorageCategory, type StorageConfig, type StorageMigrationStatus, type StorageTestResponse, } from '@trek/shared' import { useTranslation } from '../../../i18n' import { formatBytes } from '../../../utils/formatBytes' import { relativeTime } from '../../../utils/relativeTime' import ConfirmDialog from '../../shared/ConfirmDialog' import CustomSelect from '../../shared/CustomSelect' import { useToast } from '../../shared/Toast' import Section from '../../Settings/Section' import BackendForm, { type BackendFormMirrorProps } from './BackendForm' import { CACHE_CATEGORIES, adoptedMirrorFor, computeMigrationCandidates, effectiveCategoryMap, foldBackends, mirrorProbeTargets, primaryNameOf, removeBackend, removeBackendAndMirrors, renameBackendRefs, replicaCandidates, replicaOfPrimaries, settingsDocumentOf, setMirrorTargets, 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(', ') 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}` : ''}
))}