import {
Check,
Clock,
Download,
HardDrive,
Plus,
RefreshCw,
RotateCcw,
Trash2,
Upload,
} from 'lucide-react'
import {
DAYS_OF_MONTH,
DAYS_OF_WEEK,
HOURS,
INTERVAL_OPTIONS,
KEEP_OPTIONS,
useBackupAdmin,
} from '../../../components/Admin/useBackupAdmin'
import { useTranslation } from '../../../i18n'
import MChip from '../../components/MChip'
import MToggle from '../../components/MToggle'
import MConfirmSheet from '../settings/MConfirmSheet'
import { MAdminButton, MAdminCard, MAdminCardHead, MAdminField, MAdminRow } from './MAdminUi'
const SELECT_CLASS =
'h-[42px] w-full rounded-xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-3 text-[0.84375rem] text-m-ink outline-none focus:border-[color:var(--m-faint)]'
export default function MAdminBackupPanel() {
const {
backups, isLoading, isCreating, restoringFile, isUploading, autoSettings, autoSettingsSaving, autoSettingsDirty,
serverTimezone, restoreConfirm, setRestoreConfirm, deleteTarget: deleteConfirm, setDeleteTarget: setDeleteConfirm,
fileInputRef, is12h, loadBackups, handleCreate, handleDownload, handleRestore, handleUploadRestore,
executeRestore, handleDelete, executeDelete, handleAutoSettingsChange, handleSaveAutoSettings, formatSize,
formatDate, isAuto,
} = useBackupAdmin({ keepSettingsWhenMissing: true })
const { t } = useTranslation()
return (
{/* Manual Backups */}
{t('backup.title')}
}
hint={t('backup.subtitle')}
trailing={
}
/>
{/* Upload & Create actions */}
fileInputRef.current?.click()}
title={isUploading ? t('backup.uploading') : t('backup.upload')}
>
{!isUploading && }
{isUploading ? t('backup.uploading') : t('backup.upload')}
{!isCreating && }
{isCreating ? t('backup.creating') : t('backup.create')}
{isLoading && backups.length === 0 ? (
) : backups.length === 0 ? (
{t('backup.empty')}
) : (
{backups.map((backup, i) => (
{isAuto(backup.filename)
?
:
}
{backup.filename}
{isAuto(backup.filename) && (
Auto
)}
{formatDate(backup.created_at)}
{formatSize(backup.size)}
handleDownload(backup.filename)}
>
{t('backup.download')}
handleRestore(backup.filename)}
className="text-[color:var(--m-st-pending)]"
>
{restoringFile !== backup.filename && }
{t('backup.restore')}
))}
)}
{/* Auto-Backup Settings */}
{t('backup.auto.title')}
}
hint={t('backup.auto.subtitle')}
/>
{/* Enable toggle */}
handleAutoSettingsChange('enabled', v)}
/>
}
/>
{autoSettings.enabled && (
<>
{/* Interval */}
{INTERVAL_OPTIONS.map(opt => (
handleAutoSettingsChange('interval', opt.value)}
>
{t(opt.labelKey)}
))}
{/* Hour picker (for daily, weekly, monthly) */}
{autoSettings.interval !== 'hourly' && (
)}
{/* Day of week (for weekly) */}
{autoSettings.interval === 'weekly' && (
{DAYS_OF_WEEK.map(opt => (
handleAutoSettingsChange('day_of_week', opt.value)}
>
{t(opt.labelKey)}
))}
)}
{/* Day of month (for monthly) */}
{autoSettings.interval === 'monthly' && (
)}
{/* Keep duration */}
{KEEP_OPTIONS.map(opt => (
handleAutoSettingsChange('keep_days', opt.value)}
>
{t(opt.labelKey)}
))}
>
)}
{/* Save button */}
{!autoSettingsSaving && }
{autoSettingsSaving ? t('common.saving') : t('common.save')}
{/* Restore Warning */}
setRestoreConfirm(null)}
title={t('backup.restoreConfirmTitle')}
message={
<>
{restoreConfirm?.filename}
{t('backup.restoreWarning')}
>
}
confirmLabel={t('backup.restoreConfirm')}
cancelLabel={t('common.cancel')}
danger
onConfirm={executeRestore}
>
{t('backup.restoreTip')}
{/* Delete confirm */}
setDeleteConfirm(null)}
title={t('common.delete')}
message={t('backup.confirm.delete', { name: deleteConfirm ?? '' })}
confirmLabel={t('common.delete')}
cancelLabel={t('common.cancel')}
danger
onConfirm={executeDelete}
/>
)
}