<x-layout.universal pageTitle="NetGesCon" showBreadcrumb="true" showSidebar="true">
<div class="space-y-6">
    <!-- Header File Manager -->
    <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
        <div class="p-6 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700">
            <div class="flex items-center justify-between">
                <div>
                    <h2 class="text-3xl font-bold text-gray-800 dark:text-white">
                        <i class="fas fa-folder text-blue-500 mr-2"></i>
                        Gestione File
                    </h2>
                    <p class="text-gray-600 dark:text-gray-300 mt-2">
                        Archivio documenti per {{ $amministratore->nome_completo }}
                        <span class="text-sm bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200 px-2 py-1 rounded ml-2">
                            {{ $amministratore->codice_univoco }}
                        </span>
                    </p>
                </div>
                <div class="flex space-x-3">
                    <button onclick="showUploadModal()" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
                        <i class="fas fa-upload mr-2"></i>Upload File
                    </button>
                    <button class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">
                        <i class="fas fa-folder-plus mr-2"></i>Nuova Cartella
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Statistiche Storage -->
    <div class="grid grid-cols-1 md:grid-cols-4 gap-6">
        <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
            <div class="p-6">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center">
                            <i class="fas fa-file text-white text-sm"></i>
                        </div>
                    </div>
                    <div class="ml-5 w-0 flex-1">
                        <dl>
                            <dt class="text-sm font-medium text-gray-500 dark:text-gray-400 truncate">Totale File</dt>
                            <dd class="text-lg font-medium text-gray-900 dark:text-gray-100">{{ $stats['total_files'] }}</dd>
                        </dl>
                    </div>
                </div>
            </div>
        </div>

        <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
            <div class="p-6">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 bg-green-500 rounded-full flex items-center justify-center">
                            <i class="fas fa-hdd text-white text-sm"></i>
                        </div>
                    </div>
                    <div class="ml-5 w-0 flex-1">
                        <dl>
                            <dt class="text-sm font-medium text-gray-500 dark:text-gray-400 truncate">Spazio Usato</dt>
                            <dd class="text-lg font-medium text-gray-900 dark:text-gray-100">
                                {{ number_format($stats['total_size'] / 1024 / 1024, 2) }} MB
                            </dd>
                        </dl>
                    </div>
                </div>
            </div>
        </div>

        <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
            <div class="p-6">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 bg-yellow-500 rounded-full flex items-center justify-center">
                            <i class="fas fa-folder text-white text-sm"></i>
                        </div>
                    </div>
                    <div class="ml-5 w-0 flex-1">
                        <dl>
                            <dt class="text-sm font-medium text-gray-500 dark:text-gray-400 truncate">Documenti</dt>
                            <dd class="text-lg font-medium text-gray-900 dark:text-gray-100">
                                {{ $folders['documenti']['allegati']['files'] + $folders['documenti']['contratti']['files'] + $folders['documenti']['assemblee']['files'] + $folders['documenti']['preventivi']['files'] }}
                            </dd>
                        </dl>
                    </div>
                </div>
            </div>
        </div>

        <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
            <div class="p-6">
                <div class="flex items-center">
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 bg-purple-500 rounded-full flex items-center justify-center">
                            <i class="fas fa-database text-white text-sm"></i>
                        </div>
                    </div>
                    <div class="ml-5 w-0 flex-1">
                        <dl>
                            <dt class="text-sm font-medium text-gray-500 dark:text-gray-400 truncate">Backup</dt>
                            <dd class="text-lg font-medium text-gray-900 dark:text-gray-100">
                                {{ $folders['backup']['database']['files'] + $folders['backup']['files']['files'] }}
                            </dd>
                        </dl>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Struttura Cartelle -->
    <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
        <div class="p-6">
            <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-4">
                <i class="fas fa-sitemap text-blue-500 mr-2"></i>
                Struttura Archivio
            </h3>
            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                <!-- Documenti -->
                <div class="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-800 dark:text-gray-200 mb-3">
                        <i class="fas fa-file-alt text-blue-500 mr-2"></i>Documenti
                    </h4>
                    <div class="space-y-2">
                        <a href="{{ route('admin.files.folder', 'documenti/allegati') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">📎 Allegati</span>
                            <span class="text-xs text-gray-500">{{ $folders['documenti']['allegati']['files'] }} file</span>
                        </a>
                        <a href="{{ route('admin.files.folder', 'documenti/contratti') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">📋 Contratti</span>
                            <span class="text-xs text-gray-500">{{ $folders['documenti']['contratti']['files'] }} file</span>
                        </a>
                        <a href="{{ route('admin.files.folder', 'documenti/assemblee') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">🏛️ Assemblee</span>
                            <span class="text-xs text-gray-500">{{ $folders['documenti']['assemblee']['files'] }} file</span>
                        </a>
                        <a href="{{ route('admin.files.folder', 'documenti/preventivi') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">💰 Preventivi</span>
                            <span class="text-xs text-gray-500">{{ $folders['documenti']['preventivi']['files'] }} file</span>
                        </a>
                    </div>
                </div>

                <!-- Backup -->
                <div class="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-800 dark:text-gray-200 mb-3">
                        <i class="fas fa-shield-alt text-green-500 mr-2"></i>Backup
                    </h4>
                    <div class="space-y-2">
                        <a href="{{ route('admin.files.folder', 'backup/database') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">🗄️ Database</span>
                            <span class="text-xs text-gray-500">{{ $folders['backup']['database']['files'] }} file</span>
                        </a>
                        <a href="{{ route('admin.files.folder', 'backup/files') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">📁 File</span>
                            <span class="text-xs text-gray-500">{{ $folders['backup']['files']['files'] }} file</span>
                        </a>
                    </div>
                </div>

                <!-- Altri -->
                <div class="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
                    <h4 class="font-semibold text-gray-800 dark:text-gray-200 mb-3">
                        <i class="fas fa-cogs text-purple-500 mr-2"></i>Sistema
                    </h4>
                    <div class="space-y-2">
                        <a href="{{ route('admin.files.folder', 'exports') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">📊 Esportazioni</span>
                            <span class="text-xs text-gray-500">{{ $folders['exports']['files'] ?? 0 }} file</span>
                        </a>
                        <a href="{{ route('admin.files.folder', 'logs') }}" class="flex items-center justify-between p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
                            <span class="text-sm">📝 Log</span>
                            <span class="text-xs text-gray-500">{{ $folders['logs']['files'] ?? 0 }} file</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal Upload -->
<div id="uploadModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
    <div class="relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white dark:bg-gray-800">
        <div class="mt-3">
            <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">Upload File</h3>
            <form action="{{ route('admin.files.upload') }}" method="POST" enctype="multipart/form-data" class="mt-4">
                @csrf
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">Cartella</label>
                    <select name="folder" class="mt-1 block w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700">
                        <option value="documenti/allegati">Documenti - Allegati</option>
                        <option value="documenti/contratti">Documenti - Contratti</option>
                        <option value="documenti/assemblee">Documenti - Assemblee</option>
                        <option value="documenti/preventivi">Documenti - Preventivi</option>
                    </select>
                </div>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">File</label>
                    <input type="file" name="file" required class="mt-1 block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
                </div>
                <div class="flex justify-end space-x-3">
                    <button type="button" onclick="hideUploadModal()" class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded">
                        Annulla
                    </button>
                    <button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
                        Upload
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
function showUploadModal() {
    document.getElementById('uploadModal').classList.remove('hidden');
}

function hideUploadModal() {
    document.getElementById('uploadModal').classList.add('hidden');
}
</script>
</x-layout.universal>