<x-filament-panels::page>
    <div class="space-y-6">
        {{-- Info Cards --}}
        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow border border-gray-200 dark:border-gray-700 p-5">
                <div class="text-sm text-gray-500 dark:text-gray-400">Dimensiune bază de date</div>
                <div class="text-2xl font-bold text-gray-900 dark:text-white mt-1">{{ $this->getDbSize() }}</div>
            </div>
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow border border-gray-200 dark:border-gray-700 p-5">
                <div class="text-sm text-gray-500 dark:text-gray-400">Backup-uri active</div>
                <div class="text-2xl font-bold text-gray-900 dark:text-white mt-1">{{ $this->getBackupCount() }}</div>
            </div>
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow border border-gray-200 dark:border-gray-700 p-5">
                <div class="text-sm text-gray-500 dark:text-gray-400">Politică retenție</div>
                <div class="text-2xl font-bold text-gray-900 dark:text-white mt-1">50 ani</div>
                <div class="text-xs text-gray-400 mt-1">Conform legislație MEN — registrul matricol</div>
            </div>
        </div>

        {{-- Politica de retenție --}}
        <div class="bg-blue-50 dark:bg-blue-900/20 rounded-xl border border-blue-200 dark:border-blue-800 p-5">
            <h3 class="text-sm font-semibold text-blue-800 dark:text-blue-300 mb-2">
                <x-heroicon-o-information-circle class="w-4 h-4 inline mr-1" />
                Politica de backup și retenție date
            </h3>
            <ul class="text-sm text-blue-700 dark:text-blue-400 space-y-1">
                <li>Registrul matricol: retenție <strong>50 de ani</strong> (conform Legea Educației Naționale)</li>
                <li>Cataloage și situații școlare: retenție <strong>50 de ani</strong></li>
                <li>Date cu caracter personal (GDPR): procesate conform <strong>Regulamentului UE 679/2016</strong></li>
                <li>Backup automat zilnic recomandat via <code>php artisan catalog:backup</code></li>
                <li>Backup-urile expirate sunt șterse automat, cu minimum 5 backup-uri păstrate</li>
            </ul>
        </div>

        {{-- Acțiuni --}}
        <div class="flex gap-3">
            <button wire:click="runBackup"
                wire:confirm="Creați un backup manual al bazei de date?"
                class="inline-flex items-center px-4 py-2 bg-green-600 hover:bg-green-700 text-white text-sm font-medium rounded-lg">
                <x-heroicon-s-arrow-down-tray class="w-5 h-5 mr-2" />
                Backup manual acum
            </button>
        </div>

        {{-- Istoric backup-uri --}}
        <div class="bg-white dark:bg-gray-800 rounded-xl shadow border border-gray-200 dark:border-gray-700 overflow-hidden">
            <div class="px-5 py-3 bg-gray-50 dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700">
                <h3 class="font-medium text-gray-700 dark:text-gray-300">Istoric backup-uri</h3>
            </div>
            @php $logs = $this->getBackupLogs(); @endphp
            @if($logs->isNotEmpty())
                <table class="w-full text-sm">
                    <thead>
                        <tr class="border-b border-gray-200 dark:border-gray-700">
                            <th class="px-4 py-3 text-left font-medium text-gray-600 dark:text-gray-400">Data</th>
                            <th class="px-4 py-3 text-left font-medium text-gray-600 dark:text-gray-400">Fișier</th>
                            <th class="px-4 py-3 text-right font-medium text-gray-600 dark:text-gray-400">Dimensiune</th>
                            <th class="px-4 py-3 text-center font-medium text-gray-600 dark:text-gray-400">Status</th>
                            <th class="px-4 py-3 text-left font-medium text-gray-600 dark:text-gray-400">Expiră</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-100 dark:divide-gray-700">
                        @foreach($logs as $log)
                            <tr>
                                <td class="px-4 py-3 text-gray-700 dark:text-gray-300">{{ $log->creat_la?->format('d.m.Y H:i') }}</td>
                                <td class="px-4 py-3 text-gray-600 dark:text-gray-400 font-mono text-xs">{{ $log->fisier }}</td>
                                <td class="px-4 py-3 text-right text-gray-600 dark:text-gray-400">
                                    {{ $log->dimensiune > 0 ? number_format($log->dimensiune / 1024, 1) . ' KB' : '—' }}
                                </td>
                                <td class="px-4 py-3 text-center">
                                    @php
                                        $statusColors = ['succes' => 'bg-green-100 text-green-800 dark:bg-green-800 dark:text-green-100', 'eroare' => 'bg-red-100 text-red-800', 'expirat' => 'bg-gray-100 text-gray-600'];
                                    @endphp
                                    <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium {{ $statusColors[$log->status] ?? 'bg-gray-100 text-gray-600' }}">
                                        {{ ucfirst($log->status) }}
                                    </span>
                                </td>
                                <td class="px-4 py-3 text-gray-600 dark:text-gray-400">{{ $log->expira_la?->format('d.m.Y') ?? '—' }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            @else
                <p class="px-5 py-4 text-gray-400 text-sm">Niciun backup înregistrat. Rulați primul backup manual sau configurați backup automat.</p>
            @endif
        </div>

        {{-- Instrucțiuni cron --}}
        <div class="bg-gray-50 dark:bg-gray-900 rounded-xl border border-gray-200 dark:border-gray-700 p-5">
            <h3 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2">Configurare backup automat (cron)</h3>
            <p class="text-sm text-gray-600 dark:text-gray-400 mb-2">Adăugați în crontab pentru backup zilnic la ora 2:00:</p>
            <code class="block bg-gray-800 text-green-400 rounded-lg px-4 py-2 text-xs font-mono">
                0 2 * * * cd {{ base_path() }} && php artisan catalog:backup >> /dev/null 2>&1
            </code>
        </div>
    </div>
</x-filament-panels::page>
