import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { Save, Server, Cloud, HardDrive, Clock, Calendar, Shield, AlertCircle, Info, Eye, EyeOff, Wifi, CheckCircle, XCircle, Loader2, FolderOpen, Database, Image, FileArchive } from 'lucide-react'; import { toast } from 'react-toastify'; import { Button, Card, Input } from '../common'; export const BackupConfiguration = ({ config, onSave, isSaving }) => { const { t } = useTranslation(); const destinationTypes = [ { id: 'local', name: t('backup.configuration.destinationTypes.local.name'), icon: HardDrive, description: t('backup.configuration.destinationTypes.local.description'), fields: ['backup_destination_path'] }, { id: 'rsync', name: t('backup.configuration.destinationTypes.rsync.name'), icon: Server, description: t('backup.configuration.destinationTypes.rsync.description'), fields: ['backup_rsync_host', 'backup_rsync_user', 'backup_rsync_path', 'backup_rsync_ssh_key'] }, { id: 's3', name: t('backup.configuration.destinationTypes.s3.name'), icon: Cloud, description: t('backup.configuration.destinationTypes.s3.description'), fields: ['backup_s3_endpoint', 'backup_s3_bucket', 'backup_s3_access_key', 'backup_s3_secret_key', 'backup_s3_region'] } ]; const scheduleOptions = [ { value: 'hourly', label: t('backup.configuration.schedule.options.hourly') }, { value: 'daily', label: t('backup.configuration.schedule.options.daily') }, { value: 'weekly', label: t('backup.configuration.schedule.options.weekly') }, { value: 'custom', label: t('backup.configuration.schedule.options.custom') } ]; const [formData, setFormData] = useState({ backup_enabled: false, backup_destination_type: 'local', backup_destination_path: '', backup_rsync_host: '', backup_rsync_user: '', backup_rsync_path: '', backup_rsync_ssh_key: '', backup_s3_endpoint: '', backup_s3_bucket: '', backup_s3_access_key: '', backup_s3_secret_key: '', backup_s3_region: '', backup_schedule: 'daily', backup_schedule_cron: '0 3 * * *', backup_retention_days: 30, backup_include_database: true, backup_include_photos: true, backup_include_archives: true, backup_include_thumbnails: false, backup_include_temp: false, backup_compression: true, backup_encryption: false, backup_encryption_passphrase: '' }); const [showSecrets, setShowSecrets] = useState({ s3_secret_key: false, ssh_key: false, encryption_passphrase: false }); const [testingConnection, setTestingConnection] = useState(false); useEffect(() => { if (config) { setFormData(prev => ({ ...prev, ...config })); } }, [config]); const handleChange = (field, value) => { setFormData(prev => ({ ...prev, [field]: value })); }; const handleSubmit = (e) => { e.preventDefault(); // Validate required fields const destinationType = destinationTypes.find(t => t.id === formData.backup_destination_type); const missingFields = []; if (formData.backup_enabled && destinationType) { destinationType.fields.forEach(field => { if (!formData[field] && !field.includes('optional')) { missingFields.push(field); } }); } if (missingFields.length > 0) { toast.error(t('backup.configuration.messages.requiredFields')); return; } onSave(formData); }; const testConnection = async () => { setTestingConnection(true); try { // TODO: Implement connection test endpoint await new Promise(resolve => setTimeout(resolve, 2000)); toast.success(t('backup.configuration.messages.connectionSuccess')); } catch (error) { toast.error(t('backup.configuration.messages.connectionFailed') + ': ' + error.message); } finally { setTestingConnection(false); } }; const selectedDestination = destinationTypes.find(t => t.id === formData.backup_destination_type); return (
{/* Enable/Disable Toggle */}

{t('backup.configuration.enableBackup')}

{t('backup.configuration.enableBackupHelp')}

{/* Destination Configuration */}

{t('backup.configuration.destinationType')}

{/* Destination Type Selection */}
{destinationTypes.map((type) => { const Icon = type.icon; return ( ); })}
{/* Destination-specific fields */}
{formData.backup_destination_type === 'local' && ( <>
handleChange('backup_destination_path', e.target.value)} placeholder={t('backup.configuration.fields.destinationPathPlaceholder')} required />

{t('backup.configuration.fields.destinationPathHelp')}

)} {formData.backup_destination_type === 'rsync' && ( <>
handleChange('backup_rsync_host', e.target.value)} placeholder={t('backup.configuration.fields.rsyncHostPlaceholder')} required />
handleChange('backup_rsync_user', e.target.value)} placeholder={t('backup.configuration.fields.rsyncUserPlaceholder')} required />
handleChange('backup_rsync_path', e.target.value)} placeholder={t('backup.configuration.fields.rsyncPathPlaceholder')} required />