import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Database, HardDrive, Cloud, Download, Upload, CircleNotch, CloudArrowUp, } from '@phosphor-icons/react' import { storageSettingsCopy, getBackendCopy, type StorageBackendKey } from '@/components/storage/storageSettingsConfig' import { useStorageSettingsHandlers } from '@/components/storage/useStorageSettingsHandlers' const getBackendIcon = (backend: StorageBackendKey | null) => { switch (backend) { case 'flask': return case 'sqlite': return case 'indexeddb': return case 'sparkkv': return default: return } } const StorageSettingsPanelHeader = ({ description }: { description: string }) => ( {storageSettingsCopy.panel.title} {description} ) const BackendStatusSummary = ({ backend }: { backend: StorageBackendKey | null }) => { const backendCopy = getBackendCopy(backend) return (
{storageSettingsCopy.panel.currentBackendLabel} {getBackendIcon(backend)} {backendCopy.panelLabel}
{backend?.toUpperCase() || backendCopy.badgeLabel.toUpperCase()}

{backendCopy.panelDescription}

) } type BackendSwitcherProps = { backend: StorageBackendKey | null flaskUrl: string isSwitching: boolean onFlaskUrlChange: (value: string) => void onSwitchToIndexedDB: () => void onSwitchToFlask: () => void onSwitchToSQLite: () => void } const BackendSwitcher = ({ backend, flaskUrl, isSwitching, onFlaskUrlChange, onSwitchToIndexedDB, onSwitchToFlask, onSwitchToSQLite, }: BackendSwitcherProps) => (

{storageSettingsCopy.panel.switchTitle}

onFlaskUrlChange(e.target.value)} placeholder={storageSettingsCopy.panel.flaskUrlPlaceholder} className="mt-1" />

{storageSettingsCopy.panel.flaskUrlHelp}

{storageSettingsCopy.panel.switchHelp}

) type DataManagementSectionProps = { isExporting: boolean isImporting: boolean onExport: () => void onImport: () => void } const DataManagementSection = ({ isExporting, isImporting, onExport, onImport, }: DataManagementSectionProps) => (

{storageSettingsCopy.panel.dataTitle}

{storageSettingsCopy.panel.dataHelp}

) export function StorageSettingsPanel() { const { backend, isLoading, flaskUrl, setFlaskUrl, isSwitching, handleSwitchToFlask, handleSwitchToSQLite, handleSwitchToIndexedDB, isExporting, isImporting, handleExport, handleImport, } = useStorageSettingsHandlers({ defaultFlaskUrl: storageSettingsCopy.panel.flaskUrlPlaceholder, exportFilename: () => { const dateStamp = new Date().toISOString().split('T')[0] return `${storageSettingsCopy.panel.exportFilenamePrefix}-${dateStamp}.json` }, importAccept: 'application/json', }) if (isLoading && !backend) { return (
) } return ( ) }