<x-admin-layout>
    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 bg-white border-b border-gray-200">
                    <div class="flex justify-between items-center mb-6">
                        <h2 class="text-2xl font-bold text-gray-800">
                            <i class="fas fa-server mr-2 text-cyan-600"></i>
                            PowerDNS Management
                        </h2>
                        <a href="{{ route('admin.powerdns.zones') }}"
                           class="bg-cyan-600 hover:bg-cyan-700 text-white px-4 py-2 rounded-lg transition">
                            <i class="fas fa-globe mr-2"></i>Vezi toate zonele
                        </a>
                    </div>

                    @if(session('success'))
                        <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
                            {{ session('success') }}
                        </div>
                    @endif

                    @if(session('error'))
                        <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                            {{ session('error') }}
                        </div>
                    @endif

                    @if(isset($error) && $error)
                        <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                            <p class="font-bold">
                                <i class="fas fa-exclamation-triangle mr-2"></i>
                                Eroare conexiune PowerDNS
                            </p>
                            <p class="text-sm mt-2">{{ $error }}</p>
                            @if(isset($nameServers) && $nameServers->isNotEmpty())
                                <p class="text-sm mt-2">
                                    <i class="fas fa-info-circle mr-1"></i>
                                    Vă rugăm să configurați nameserverele (API URL și API Port) în 
                                    <a href="{{ route('admin.nameservers.index') }}" class="underline font-semibold hover:text-red-900">Setări Nameservere</a>
                                </p>
                            @endif
                        </div>
                    @endif

                    @if(!isset($error) || !$error)
                    <!-- Statistici Zone DNS -->
                    <div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
                        <div class="bg-gradient-to-br from-blue-500 to-blue-600 rounded-lg shadow-lg p-6 text-white">
                            <div class="flex items-center justify-between">
                                <div>
                                    <p class="text-blue-100 text-sm">Total Zone</p>
                                    <p class="text-3xl font-bold">{{ $stats['data']['total'] ?? 0 }}</p>
                                </div>
                                <div class="bg-white bg-opacity-20 rounded-full p-3">
                                    <i class="fas fa-database text-2xl"></i>
                                </div>
                            </div>
                        </div>

                        <div class="bg-gradient-to-br from-green-500 to-green-600 rounded-lg shadow-lg p-6 text-white">
                            <div class="flex items-center justify-between">
                                <div>
                                    <p class="text-green-100 text-sm">Zone Forward</p>
                                    <p class="text-3xl font-bold">{{ $stats['data']['forward'] ?? 0 }}</p>
                                </div>
                                <div class="bg-white bg-opacity-20 rounded-full p-3">
                                    <i class="fas fa-globe text-2xl"></i>
                                </div>
                            </div>
                        </div>

                        <div class="bg-gradient-to-br from-purple-500 to-purple-600 rounded-lg shadow-lg p-6 text-white">
                            <div class="flex items-center justify-between">
                                <div>
                                    <p class="text-purple-100 text-sm">Zone .arpa IPv4</p>
                                    <p class="text-3xl font-bold">{{ $stats['data']['arpa_v4'] ?? 0 }}</p>
                                </div>
                                <div class="bg-white bg-opacity-20 rounded-full p-3">
                                    <i class="fas fa-network-wired text-2xl"></i>
                                </div>
                            </div>
                        </div>

                        <div class="bg-gradient-to-br from-orange-500 to-orange-600 rounded-lg shadow-lg p-6 text-white">
                            <div class="flex items-center justify-between">
                                <div>
                                    <p class="text-orange-100 text-sm">Zone .arpa IPv6</p>
                                    <p class="text-3xl font-bold">{{ $stats['data']['arpa_v6'] ?? 0 }}</p>
                                </div>
                                <div class="bg-white bg-opacity-20 rounded-full p-3">
                                    <i class="fas fa-project-diagram text-2xl"></i>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Link-uri rapide -->
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                        <a href="{{ route('admin.powerdns.zones', ['type' => 'forward']) }}"
                           class="bg-white border-2 border-green-200 hover:border-green-400 rounded-lg p-6 transition group">
                            <div class="flex items-center">
                                <div class="bg-green-100 rounded-full p-4 mr-4 group-hover:bg-green-200 transition">
                                    <i class="fas fa-globe text-green-600 text-2xl"></i>
                                </div>
                                <div>
                                    <h3 class="text-lg font-semibold text-gray-800">Zone Forward</h3>
                                    <p class="text-gray-600 text-sm">Domenii și subdomenii</p>
                                </div>
                            </div>
                        </a>

                        <a href="{{ route('admin.powerdns.zones', ['type' => 'arpa_v4']) }}"
                           class="bg-white border-2 border-purple-200 hover:border-purple-400 rounded-lg p-6 transition group">
                            <div class="flex items-center">
                                <div class="bg-purple-100 rounded-full p-4 mr-4 group-hover:bg-purple-200 transition">
                                    <i class="fas fa-network-wired text-purple-600 text-2xl"></i>
                                </div>
                                <div>
                                    <h3 class="text-lg font-semibold text-gray-800">Zone .arpa IPv4</h3>
                                    <p class="text-gray-600 text-sm">Reverse DNS IPv4</p>
                                </div>
                            </div>
                        </a>

                        <a href="{{ route('admin.powerdns.zones', ['type' => 'arpa_v6']) }}"
                           class="bg-white border-2 border-orange-200 hover:border-orange-400 rounded-lg p-6 transition group">
                            <div class="flex items-center">
                                <div class="bg-orange-100 rounded-full p-4 mr-4 group-hover:bg-orange-200 transition">
                                    <i class="fas fa-project-diagram text-orange-600 text-2xl"></i>
                                </div>
                                <div>
                                    <h3 class="text-lg font-semibold text-gray-800">Zone .arpa IPv6</h3>
                                    <p class="text-gray-600 text-sm">Reverse DNS IPv6</p>
                                </div>
                            </div>
                        </a>
                    </div>

                    <!-- Info server -->
                    @if($servers['success'])
                        <div class="mt-8 bg-gray-50 rounded-lg p-6">
                            <h3 class="text-lg font-semibold text-gray-800 mb-4">
                                <i class="fas fa-info-circle mr-2 text-cyan-600"></i>
                                Informații Server
                            </h3>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                <div>
                                    <p class="text-gray-600 text-sm">Status conexiune</p>
                                    <p class="text-green-600 font-semibold">
                                        <i class="fas fa-check-circle mr-1"></i>Conectat
                                    </p>
                                </div>
                                <div>
                                    <p class="text-gray-600 text-sm">Server ID</p>
                                    <p class="text-gray-800 font-semibold">{{ config('powerdns.server_id') }}</p>
                                </div>
                            </div>
                        </div>
                    @else
                        <div class="mt-8 bg-red-50 border border-red-200 rounded-lg p-6">
                            <h3 class="text-lg font-semibold text-red-800 mb-2">
                                <i class="fas fa-exclamation-triangle mr-2"></i>
                                Eroare conexiune PowerDNS
                            </h3>
                            <p class="text-red-600">{{ $servers['error'] ?? 'Nu s-a putut conecta la serverul PowerDNS' }}</p>
                        </div>
                    @endif
                    @endif
                </div>
            </div>
        </div>
    </div>
</x-admin-layout>
