<x-app-layout>
    <x-slot name="header">
        <div class="flex items-center justify-between">
            <h2 class="font-semibold text-lg text-gray-800 dark:text-gray-200 leading-tight">
                {{ __('Jurnal de Activitate DNS') }}
            </h2>
            <div class="flex items-center space-x-4">
                <span class="text-sm text-gray-600 dark:text-gray-400">
                    Total activități: {{ $activities->total() }}
                </span>
                <a href="{{ route('dns-zones.index') }}" class="inline-flex items-center px-4 py-2 bg-gray-500 hover:bg-gray-600 text-white font-medium rounded-lg transition">
                    <i class="fas fa-arrow-left mr-2"></i>
                    {{ __('Înapoi la Zone DNS') }}
                </a>
            </div>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    @if($activities->count() > 0)
                        <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 scope="col" 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 scope="col" 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 scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            {{ __('Zonă') }}
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            {{ __('Înregistrare') }}
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            {{ __('Tip') }}
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            {{ __('Detalii') }}
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
                                            {{ __('IP') }}
                                        </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="px-2 py-1 text-xs font-semibold rounded-full
                                                    @if($activity->action == 'create') bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200
                                                    @elseif($activity->action == 'update') bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200
                                                    @elseif($activity->action == 'delete') bg-red-100 dark:bg-red-900 text-red-800 dark:text-red-200
                                                    @elseif($activity->action == 'restore') bg-lime-100 dark:bg-lime-900 text-lime-800 dark:text-lime-200
                                                    @elseif($activity->action == 'activate') bg-emerald-100 dark:bg-emerald-900 text-emerald-800 dark:text-emerald-200
                                                    @elseif($activity->action == 'deactivate') bg-orange-100 dark:bg-orange-900 text-orange-800 dark:text-orange-200
                                                    @elseif(str_starts_with($activity->action, 'view')) bg-indigo-100 dark:bg-indigo-900 text-indigo-800 dark:text-indigo-200
                                                    @elseif(str_ends_with($activity->action, 'form')) bg-purple-100 dark:bg-purple-900 text-purple-800 dark:text-purple-200
                                                    @else bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200
                                                    @endif">
                                                    @switch($activity->action)
                                                        @case('create') <i class="fas fa-plus mr-1"></i>Creare @break
                                                        @case('update') <i class="fas fa-edit mr-1"></i>Modificare @break
                                                        @case('delete') <i class="fas fa-trash mr-1"></i>Ștergere @break
                                                        @case('restore') <i class="fas fa-undo mr-1"></i>Restaurare @break
                                                        @case('activate') <i class="fas fa-play mr-1"></i>Activare @break
                                                        @case('deactivate') <i class="fas fa-pause mr-1"></i>Dezactivare @break
                                                        @case('view_zones') <i class="fas fa-eye mr-1"></i>Vizualizare zone @break
                                                        @case('view_zone') <i class="fas fa-eye mr-1"></i>Vizualizare zonă @break
                                                        @case('view_records') <i class="fas fa-eye mr-1"></i>Vizualizare înregistrări @break
                                                        @case('view_changelog') <i class="fas fa-history mr-1"></i>Vizualizare changelog @break
                                                        @case('view_activity_log') <i class="fas fa-list mr-1"></i>Vizualizare activitate @break
                                                        @case('edit_form') <i class="fas fa-edit mr-1"></i>Formular editare @break
                                                        @case('create_form') <i class="fas fa-plus mr-1"></i>Formular creare @break
                                                        @default <i class="fas fa-question mr-1"></i>{{ ucfirst($activity->action) }} @break
                                                    @endswitch
                                                </span>
                                            </td>
                                            <td class="px-6 py-4 text-sm text-gray-900 dark:text-gray-100">
                                                @if($activity->zone_name)
                                                    <a href="{{ route('dns-zones.show', $activity->zone_name) }}" class="text-blue-600 dark:text-blue-400 hover:underline">
                                                        {{ rtrim($activity->zone_name, '.') }}
                                                    </a>
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-600">-</span>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 text-sm text-gray-900 dark:text-gray-100">
                                                @if($activity->record_name)
                                                    {{ rtrim($activity->record_name, '.') }}
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-600">-</span>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap">
                                                @if($activity->record_type)
                                                    <span class="px-2 py-1 text-xs font-semibold rounded-full
                                                        @if($activity->record_type == 'A') bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200
                                                        @elseif($activity->record_type == 'AAAA') bg-purple-100 dark:bg-purple-900 text-purple-800 dark:text-purple-200
                                                        @elseif($activity->record_type == 'CNAME') bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200
                                                        @elseif($activity->record_type == 'MX') bg-orange-100 dark:bg-orange-900 text-orange-800 dark:text-orange-200
                                                        @elseif($activity->record_type == 'TXT') bg-yellow-100 dark:bg-yellow-900 text-yellow-800 dark:text-yellow-200
                                                        @else bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200
                                                        @endif">
                                                        {{ $activity->record_type }}
                                                    </span>
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-600">-</span>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 text-sm text-gray-900 dark:text-gray-100">
                                                @if($activity->new_content && $activity->old_content && $activity->new_content != $activity->old_content)
                                                    <div class="space-y-1">
                                                        <div class="text-red-600 dark:text-red-400 text-xs">
                                                            Vechi: {{ \Str::limit($activity->old_content, 30) }}
                                                        </div>
                                                        <div class="text-green-600 dark:text-green-400 text-xs">
                                                            Nou: {{ \Str::limit($activity->new_content, 30) }}
                                                        </div>
                                                    </div>
                                                @elseif($activity->new_content)
                                                    <div class="text-xs">{{ \Str::limit($activity->new_content, 40) }}</div>
                                                @elseif($activity->old_content)
                                                    <div class="text-xs">{{ \Str::limit($activity->old_content, 40) }}</div>
                                                @else
                                                    <span class="text-gray-400 dark:text-gray-600 text-xs">-</span>
                                                @endif

                                                @if($activity->new_ttl && $activity->old_ttl && $activity->new_ttl != $activity->old_ttl)
                                                    <div class="mt-1 text-xs">
                                                        TTL: {{ $activity->old_ttl }}s → {{ $activity->new_ttl }}s
                                                    </div>
                                                @endif
                                            </td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
                                                @if($activity->ip_address === '::1')
                                                    <span class="text-blue-600 dark:text-blue-400" title="IPv6 Localhost">localhost (::1)</span>
                                                @elseif($activity->ip_address === '127.0.0.1')
                                                    <span class="text-blue-600 dark:text-blue-400" title="IPv4 Localhost">localhost (127.0.0.1)</span>
                                                @else
                                                    {{ $activity->ip_address }}
                                                @endif
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>

                        <!-- Pagination -->
                        <div class="mt-6">
                            {{ $activities->links() }}
                        </div>
                    @else
                        <div class="text-center py-12">
                            <i class="fas fa-history text-gray-400 text-6xl mb-4"></i>
                            <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-2">{{ __('Nicio activitate înregistrată') }}</h3>
                            <p class="text-gray-500 dark:text-gray-400">{{ __('Toate acțiunile PowerDNS vor fi afișate aici.') }}</p>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
