<x-app-layout>
    <x-slot name="header">
        <div>
            <h2 class="font-semibold text-lg text-gray-800 dark:text-gray-200 leading-tight flex items-center">
                <i class="fas fa-history mr-2"></i>
                {{ __('Jurnal Activitate Backup-uri') }}
            </h2>
            <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
                <a href="{{ route('dashboard') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Dashboard</a>
                <span class="mx-2">/</span>
                <a href="{{ route('admin.dashboard') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Admin</a>
                <span class="mx-2">/</span>
                <a href="{{ route('admin.backups.index') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Backup-uri</a>
                <span class="mx-2">/</span>
                <span>Jurnal Activitate</span>
            </p>
        </div>
    </x-slot>

    <div class="py-6">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">

            <!-- Tabs Navigation -->
            <div class="mb-6">
                <div class="border-b border-gray-200 dark:border-gray-700">
                    <nav class="-mb-px flex space-x-8">
                        <a href="{{ route('admin.backups.index') }}"
                           class="border-b-2 border-transparent py-4 px-1 text-sm font-medium text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300 dark:hover:border-gray-600">
                            <i class="fas fa-list mr-2"></i>Backup-uri
                        </a>
                        <a href="{{ route('admin.backups.activity-log') }}"
                           class="border-b-2 border-blue-500 py-4 px-1 text-sm font-medium text-blue-600 dark:text-blue-400">
                            <i class="fas fa-history mr-2"></i>Jurnal Activitate
                        </a>
                        <a href="{{ route('admin.backups.settings') }}"
                           class="border-b-2 border-transparent py-4 px-1 text-sm font-medium text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:border-gray-300 dark:hover:border-gray-600">
                            <i class="fas fa-cog mr-2"></i>Setări & Destinații
                        </a>
                    </nav>
                </div>
            </div>

            <!-- Jurnal Activitate -->
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900 dark:text-gray-100">
                    <h3 class="text-lg font-semibold mb-4">
                        <i class="fas fa-history mr-2"></i>Istoric Activități
                    </h3>

                    @if($activities->isEmpty())
                        <div class="text-center py-8 text-gray-500 dark:text-gray-400">
                            <i class="fas fa-inbox text-4xl mb-2"></i>
                            <p>Nu există activități înregistrate</p>
                        </div>
                    @else
                        <div class="overflow-x-auto">
                            <table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
                                <thead class="bg-gray-50 dark:bg-gray-700">
                                    <tr>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            Data & Ora
                                        </th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            Acțiune
                                        </th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            Backup
                                        </th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            Utilizator
                                        </th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            IP
                                        </th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            Detalii
                                        </th>
                                    </tr>
                                </thead>
                                <tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
                                    @foreach($activities as $activity)
                                        <tr class="hover:bg-gray-50 dark:hover:bg-gray-700">
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">
                                                <div>{{ $activity->created_at->format('d.m.Y') }}</div>
                                                <div class="text-xs text-gray-500 dark:text-gray-400">{{ $activity->created_at->format('H:i:s') }}</div>
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap">
                                                <span class="inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-semibold border {{ $activity->action_badge_class }}">
                                                    <i class="fas {{ $activity->action_icon }} mr-1"></i>
                                                    {{ $activity->action_label }}
                                                </span>
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">
                                                @if($activity->backup)
                                                    <div class="flex items-center">
                                                        <i class="fas fa-file-archive mr-2 text-gray-400"></i>
                                                        <div>
                                                            <div class="font-medium">#{{ $activity->backup->id }}</div>
                                                            <div class="text-xs text-gray-500 dark:text-gray-400">{{ $activity->backup->filename }}</div>
                                                        </div>
                                                    </div>
                                                @elseif($activity->action === 'deleted' && $activity->details && isset($activity->details['id']))
                                                    <div class="flex items-center">
                                                        <i class="fas fa-file-archive mr-2 text-red-400"></i>
                                                        <div>
                                                            <div class="font-medium text-red-600 dark:text-red-400">#{{ $activity->details['id'] }} (șters)</div>
                                                            <div class="text-xs text-gray-500 dark:text-gray-400">{{ $activity->details['filename'] ?? '-' }}</div>
                                                        </div>
                                                    </div>
                                                @elseif($activity->details && isset($activity->details['backup_id']))
                                                    <div class="flex items-center">
                                                        <i class="fas fa-file-archive mr-2 text-red-400"></i>
                                                        <div>
                                                            <div class="font-medium text-red-600 dark:text-red-400">#{{ $activity->details['backup_id'] }} (șters)</div>
                                                            <div class="text-xs text-gray-500 dark:text-gray-400">{{ $activity->details['filename'] ?? '-' }}</div>
                                                        </div>
                                                    </div>
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-500">-</span>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-100">
                                                @if($activity->user)
                                                    <div class="flex items-center">
                                                        <i class="fas fa-user mr-2 text-gray-400"></i>
                                                        {{ $activity->user->name }}
                                                    </div>
                                                @elseif($activity->user_name)
                                                    <div class="flex items-center">
                                                        <i class="fas fa-user mr-2 text-gray-400"></i>
                                                        {{ $activity->user_name }}
                                                    </div>
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-500">System</span>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                                                @if($activity->ip_address)
                                                    <code class="text-xs bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded">{{ $activity->ip_address }}</code>
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-500">-</span>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 text-sm font-medium">
                                                <div class="flex items-center justify-center">
                                                    @if($activity->details)
                                                        <button type="button"
                                                                class="inline-flex items-center justify-center w-9 h-9 rounded-lg bg-blue-50 dark:bg-blue-900/20 text-blue-600 dark:text-blue-400 hover:bg-blue-100 dark:hover:bg-blue-900/40 border border-blue-200 dark:border-blue-800 transition"
                                                                onclick="showDetails{{ $activity->id }}()"
                                                                title="Vezi detalii">
                                                            <i class="fas fa-info-circle"></i>
                                                        </button>

                                                        <script>
                                                            function showDetails{{ $activity->id }}() {
                                                                alert(JSON.stringify(@json($activity->details), null, 2));
                                                            }
                                                        </script>
                                                    @else
                                                        <span class="inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-semibold bg-gray-50 dark:bg-gray-900/50 text-gray-500 dark:text-gray-400 border border-gray-200 dark:border-gray-700">-</span>
                                                    @endif
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>

                        <!-- Paginare -->
                        <div class="mt-4">
                            {{ $activities->links() }}
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
