<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <div>
                <h2 class="font-semibold text-lg text-gray-800 dark:text-gray-200 leading-tight">
                    <i class="fas fa-{{ isset($duplicateRecord) && $duplicateRecord ? 'copy' : 'plus' }} mr-2"></i>{{ isset($duplicateRecord) && $duplicateRecord ? 'Duplică Înregistrare' : __('Add Record') }} pentru {{ $dnsZone->domain }}
                </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('dns-zones.index') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Zone DNS</a>
                    <span class="mx-2">/</span>
                    <a href="{{ route('dns-zones.show', $dnsZone) }}" class="text-blue-600 dark:text-blue-400 hover:underline">{{ $dnsZone->domain }}</a>
                    <span class="mx-2">/</span>
                    <span>{{ isset($duplicateRecord) && $duplicateRecord ? 'Duplică Înregistrare' : 'Adaugă Înregistrare' }}</span>
                </p>
            </div>
            <a href="{{ route('dns-zones.show', $dnsZone) }}" class="text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200">
                <i class="fas fa-arrow-left mr-2"></i>Înapoi
            </a>
        </div>
    </x-slot>

    @php
        // Definiții tipuri de înregistrări
        $typeDescriptions = [
            'A' => 'A - Adresă IPv4',
            'AAAA' => 'AAAA - Adresă IPv6',
            'AFSDB' => 'AFSDB - AFS Database Record',
            'ALIAS' => 'ALIAS - Auto-resolved alias',
            'CAA' => 'CAA - Certification Authority Authorization',
            'CERT' => 'CERT - Certificate Record',
            'CDNSKEY' => 'CDNSKEY - Child DNSKEY',
            'CDS' => 'CDS - Child DS',
            'CNAME' => 'CNAME - Alias către alt domeniu',
            'DNSKEY' => 'DNSKEY - DNSSEC Public Key',
            'DNAME' => 'DNAME - Delegation Name',
            'DS' => 'DS - Delegation Signer',
            'HINFO' => 'HINFO - Host Information',
            'KEY' => 'KEY - Public Key',
            'LOC' => 'LOC - Location Information',
            'MX' => 'MX - Mail Exchange',
            'NAPTR' => 'NAPTR - Naming Authority Pointer',
            'NS' => 'NS - Name Server',
            'NSEC' => 'NSEC - Next Secure',
            'NSEC3' => 'NSEC3 - NSEC version 3',
            'NSEC3PARAM' => 'NSEC3PARAM - NSEC3 Parameters',
            'OPENPGPKEY' => 'OPENPGPKEY - OpenPGP Public Key',
            'PTR' => 'PTR - Pointer Record',
            'RP' => 'RP - Responsible Person',
            'RRSIG' => 'RRSIG - DNSSEC Signature',
            'SOA' => 'SOA - Start of Authority',
            'SSHFP' => 'SSHFP - SSH Fingerprint',
            'SRV' => 'SRV - Service Record',
            'TKEY' => 'TKEY - Transaction Key',
            'TLSA' => 'TLSA - TLS Authentication',
            'TSIG' => 'TSIG - Transaction Signature',
            'TXT' => 'TXT - Text Record',
            'URI' => 'URI - Uniform Resource Identifier',
        ];

        // Pre-populează valorile din recordul duplicat sau din old()
        $prefillName = old('name', isset($duplicateRecord) && $duplicateRecord ? $duplicateRecord->name : '');
        $prefillType = old('type', isset($duplicateRecord) && $duplicateRecord ? $duplicateRecord->type : 'A');
        $prefillContent = old('content', isset($duplicateRecord) && $duplicateRecord ? $duplicateRecord->content : '');
        $prefillTtl = old('ttl', isset($duplicateRecord) && $duplicateRecord ? $duplicateRecord->ttl : 3600);
        $prefillPriority = old('priority', isset($duplicateRecord) && $duplicateRecord ? $duplicateRecord->priority : 10);
        $prefillNotes = old('notes', isset($duplicateRecord) && $duplicateRecord ? $duplicateRecord->notes : '');
    @endphp

    <div class="py-12">
        <div class="px-6 lg:px-8">
            @if(isset($duplicateRecord) && $duplicateRecord)
                <div class="bg-teal-50 dark:bg-teal-900/20 border-l-4 border-teal-500 p-4 mb-6 rounded-r-lg">
                    <div class="flex items-center">
                        <i class="fas fa-copy text-teal-500 mr-3"></i>
                        <p class="text-sm text-teal-700 dark:text-teal-300">
                            <strong>Duplicare din:</strong> {{ $duplicateRecord->type }} - {{ $duplicateRecord->name }}
                            <span class="text-teal-600 dark:text-teal-400 ml-2">→ {{ $duplicateRecord->content }}</span>
                        </p>
                    </div>
                </div>
            @endif
            <div class="flex flex-col lg:flex-row gap-6">
                <!-- Formular (50% pe desktop) -->
                <div class="w-full lg:w-1/2">
                    <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="p-6">
                            <form method="POST" action="{{ route('dns-records.store', $dnsZone) }}">
                        @csrf

                        <!-- Name -->
                        <div class="mb-6">
                            <label for="name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Nume <span class="text-red-500">*</span>
                            </label>
                            <div class="flex items-center">
                                <input type="text"
                                       name="name"
                                       id="name"
                                       value="{{ $prefillName }}"
                                       class="flex-1 rounded-l-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600"
                                       placeholder="www"
                                       required>
                                <span class="px-4 py-2 bg-gray-100 dark:bg-gray-700 border border-l-0 border-gray-300 dark:border-gray-600 rounded-r-lg text-gray-600 dark:text-gray-400">
                                    .{{ $dnsZone->domain }}
                                </span>
                            </div>
                            @error('name')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                            <p class="mt-2 text-sm text-gray-500 dark:text-gray-400">
                                Introdu numele subdomeniului (ex: www, mail, ftp) sau @ pentru domeniul principal
                            </p>
                        </div>

                        <!-- Type -->
                        <div class="mb-6">
                            <label for="type" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                {{ __('Record Type') }} <span class="text-red-500">*</span>
                            </label>
                            <div class="relative">
                                <input type="text"
                                       id="type-input"
                                       placeholder="Selectează sau caută tip înregistrare..."
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 pr-10"
                                       autocomplete="off"
                                       value="{{ $typeDescriptions[$prefillType] ?? $prefillType }}">
                                <input type="hidden" name="type" id="type" value="{{ $prefillType }}" required>
                                <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
                                    <svg class="h-5 w-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                                    </svg>
                                </div>
                                <div id="type-dropdown" class="hidden absolute z-10 w-full mt-1 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-lg overflow-y-auto" style="max-height: 400px;">
                                    <div id="type-options">
                                @foreach($allowedTypes as $type)
                                    <div class="px-4 py-2 cursor-pointer hover:bg-indigo-50 dark:hover:bg-indigo-900/30 text-gray-900 dark:text-gray-100"
                                         data-value="{{ $type }}"
                                         data-label="{{ $typeDescriptions[$type] ?? $type }}">
                                        {{ $typeDescriptions[$type] ?? $type }}
                                    </div>
                                @endforeach
                                    </div>
                                </div>
                            </div>
                            @if(count($allowedTypes) < 9)
                                <p class="mt-1 text-xs text-amber-600 dark:text-amber-400">
                                    <i class="fas fa-info-circle mr-1"></i>
                                    Planul tău permite doar: {{ implode(', ', $allowedTypes) }}
                                </p>
                            @endif
                            @error('type')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Content -->
                        <div class="mb-6">
                            <label for="content" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                {{ __('Content') }} <span class="text-red-500">*</span>
                            </label>
                            <input type="text"
                                   name="content"
                                   id="content"
                                   value="{{ $prefillContent }}"
                                   class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600"
                                   placeholder="192.168.1.1"
                                   required>
                            @error('content')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                            <p class="mt-2 text-sm text-gray-500 dark:text-gray-400">
                                Valoarea înregistrării (ex: IP pentru A, domeniu pentru CNAME)
                            </p>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                            <!-- TTL -->
                            <div>
                                <label for="ttl" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    {{ __('TTL') }} (secunde) <span class="text-red-500">*</span>
                                </label>
                                <select name="ttl"
                                        id="ttl"
                                        class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600"
                                        required>
                                    <option value="60" {{ $prefillTtl == '60' ? 'selected' : '' }}>1 minut (60)</option>
                                    <option value="300" {{ $prefillTtl == '300' ? 'selected' : '' }}>5 minute (300)</option>
                                    <option value="1800" {{ $prefillTtl == '1800' ? 'selected' : '' }}>30 minute (1800)</option>
                                    <option value="3600" {{ $prefillTtl == '3600' ? 'selected' : '' }}>60 minute (3600)</option>
                                    <option value="86400" {{ $prefillTtl == '86400' ? 'selected' : '' }}>1 zi (86400)</option>
                                </select>
                                @error('ttl')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- Priority -->
                            <div id="priority-field">
                                <label for="priority" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    {{ __('Priority') }} <span id="priority-required" class="text-red-500 hidden">*</span> <span id="priority-optional" class="text-gray-500 text-xs">(opțional)</span>
                                </label>
                                <input type="number"
                                       name="priority"
                                       id="priority"
                                       value="{{ $prefillPriority }}"
                                       min="0"
                                       max="65535"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600">
                                @error('priority')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                                <p class="mt-2 text-sm text-gray-500 dark:text-gray-400" id="priority-help">
                                    Necesar pentru MX și SRV (valoare mai mică = prioritate mai mare)
                                </p>
                            </div>
                        </div>

                        <!-- SRV Specific Fields -->
                        <div id="srv-fields" class="hidden">
                            <div class="bg-purple-50 dark:bg-purple-900/20 border border-purple-200 dark:border-purple-800 rounded-lg p-4 mb-6">
                                <h4 class="font-semibold text-purple-800 dark:text-purple-200 mb-3">
                                    <i class="fas fa-network-wired mr-2"></i>
                                    Câmpuri Specifice SRV Record
                                </h4>

                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <!-- Weight -->
                                    <div>
                                        <label for="weight" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            Weight (Pondere) <span class="text-red-500">*</span>
                                        </label>
                                        <input type="number"
                                               name="weight"
                                               id="weight"
                                               value="{{ old('weight', 10) }}"
                                               min="0"
                                               max="65535"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600">
                                        @error('weight')
                                            <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                        @enderror
                                        <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
                                            Pentru load balancing între servere cu aceeași prioritate
                                        </p>
                                    </div>

                                    <!-- Port -->
                                    <div>
                                        <label for="port" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            Port <span class="text-red-500">*</span>
                                        </label>
                                        <input type="number"
                                               name="port"
                                               id="port"
                                               value="{{ old('port', 80) }}"
                                               min="1"
                                               max="65535"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600">
                                        @error('port')
                                            <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                        @enderror
                                        <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
                                            Portul pe care rulează serviciul (ex: 5060 pentru SIP)
                                        </p>
                                    </div>
                                </div>

                                <div class="mt-3 p-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded">
                                    <p class="text-xs text-blue-900 dark:text-blue-100">
                                        <i class="fas fa-info-circle mr-1"></i>
                                        <strong>Format SRV:</strong> Numele trebuie să fie în formatul <code class="bg-blue-100 dark:bg-blue-900 px-1 rounded">_service._protocol</code> (ex: <code class="bg-blue-100 dark:bg-blue-900 px-1 rounded">_sip._tcp</code>)
                                    </p>
                                </div>
                            </div>
                        </div>

                        <!-- Notițe -->
                        <div class="mb-6">
                            <label for="notes" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Notițe (opțional)
                            </label>
                            <textarea name="notes"
                                      id="notes"
                                      rows="3"
                                      class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600"
                                      placeholder="Adaugă notițe sau comentarii despre această înregistrare...">{{ old('notes') }}</textarea>
                            @error('notes')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                            <p class="mt-2 text-sm text-gray-500 dark:text-gray-400">
                                Poți adăuga notițe sau comentarii pentru a documenta scopul acestei înregistrări
                            </p>
                        </div>

                        <!-- Buttons -->
                        <div class="flex items-center justify-end space-x-4">
                            <a href="{{ route('dns-zones.show', $dnsZone) }}" class="px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition">
                                {{ __('Cancel') }}
                            </a>
                            <button type="submit" class="px-6 py-2 bg-indigo-600 hover:bg-indigo-700 text-white font-semibold rounded-lg transition">
                                <i class="fas fa-plus mr-2"></i>
                                {{ __('Create') }}
                            </button>
                        </div>
                    </form>
                        </div>
                    </div>
                </div>

                <!-- Ghid și Legendă (50% pe desktop) -->
                <div class="w-full lg:w-1/2">
                    <!-- Conținut Ghid (întotdeauna vizibil pe desktop) -->
                    <div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-6 lg:sticky lg:top-6">
                <h3 class="text-lg font-semibold text-blue-900 dark:text-blue-100 mb-4">
                    <i class="fas fa-info-circle mr-2"></i>
                    Ghid Adăugare Înregistrări DNS
                </h3>

                <div class="space-y-4">
                    <!-- Explicație Nume -->
                    <div>
                        <h4 class="font-semibold text-blue-800 dark:text-blue-200 mb-2">📝 Câmpul "Nume":</h4>
                        <ul class="list-disc list-inside text-sm text-blue-900 dark:text-blue-100 space-y-1 ml-4">
                            <li><code class="bg-blue-100 dark:bg-blue-900 px-2 py-1 rounded">@</code> = domeniul principal ({{ $dnsZone->domain }})</li>
                            <li><code class="bg-blue-100 dark:bg-blue-900 px-2 py-1 rounded">www</code> = subdomeniu (www.{{ $dnsZone->domain }})</li>
                            <li><code class="bg-blue-100 dark:bg-blue-900 px-2 py-1 rounded">mail</code> = subdomeniu (mail.{{ $dnsZone->domain }})</li>
                        </ul>
                    </div>

                    <!-- Exemple per Tip -->
                    <div>
                        <h4 class="font-semibold text-blue-800 dark:text-blue-200 mb-2">🎯 Exemple Înregistrări:</h4>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-3 text-sm">
                            <!-- A Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-blue-700 dark:text-blue-300 mb-1">
                                    <span class="bg-blue-100 dark:bg-blue-900 px-2 py-1 rounded text-xs">A</span> Adresă IPv4
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> @ sau www<br>
                                    <strong>Conținut:</strong> 192.168.1.1
                                </div>
                            </div>

                            <!-- CNAME Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-green-700 dark:text-green-300 mb-1">
                                    <span class="bg-green-100 dark:bg-green-900 px-2 py-1 rounded text-xs">CNAME</span> Alias
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> www<br>
                                    <strong>Conținut:</strong> {{ $dnsZone->domain }}
                                </div>
                            </div>

                            <!-- MX Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-orange-700 dark:text-orange-300 mb-1">
                                    <span class="bg-orange-100 dark:bg-orange-900 px-2 py-1 rounded text-xs">MX</span> Mail Server
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> @<br>
                                    <strong>Conținut:</strong> mail.{{ $dnsZone->domain }}<br>
                                    <strong>Prioritate:</strong> 10
                                </div>
                            </div>

                            <!-- TXT Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-yellow-700 dark:text-yellow-300 mb-1">
                                    <span class="bg-yellow-100 dark:bg-yellow-900 px-2 py-1 rounded text-xs">TXT</span> Text Record
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> @ sau _dmarc<br>
                                    <strong>Conținut:</strong> "v=DMARC1; p=none"<br>
                                    <span class="text-xs text-blue-600 dark:text-blue-400 mt-1 block">
                                        <strong>SPF:</strong> v=spf1 mx ~all
                                    </span>
                                </div>
                            </div>

                            <!-- NS Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-indigo-700 dark:text-indigo-300 mb-1">
                                    <span class="bg-indigo-100 dark:bg-indigo-900 px-2 py-1 rounded text-xs">NS</span> Name Server
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> @<br>
                                    <strong>Conținut:</strong> ns1.example.com
                                </div>
                            </div>

                            <!-- AAAA Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-purple-700 dark:text-purple-300 mb-1">
                                    <span class="bg-purple-100 dark:bg-purple-900 px-2 py-1 rounded text-xs">AAAA</span> Adresă IPv6
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> @ sau www<br>
                                    <strong>Conținut:</strong> 2001:db8::1
                                </div>
                            </div>

                            <!-- SRV Record -->
                            <div class="bg-white dark:bg-gray-800 p-3 rounded border border-blue-200 dark:border-blue-700">
                                <div class="font-semibold text-pink-700 dark:text-pink-300 mb-1">
                                    <span class="bg-pink-100 dark:bg-pink-900 px-2 py-1 rounded text-xs">SRV</span> Service Record
                                </div>
                                <div class="text-xs text-gray-600 dark:text-gray-400">
                                    <strong>Nume:</strong> _sip._tcp<br>
                                    <strong>Conținut:</strong> sipserver.{{ $dnsZone->domain }}<br>
                                    <strong>Prioritate:</strong> 10<br>
                                    <strong>Weight:</strong> 60<br>
                                    <strong>Port:</strong> 5060
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Note Importante -->
                    <div class="bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded p-3">
                        <h4 class="font-semibold text-yellow-800 dark:text-yellow-200 mb-2">
                            <i class="fas fa-exclamation-triangle mr-1"></i>
                            Note Importante:
                        </h4>
                        <ul class="list-disc list-inside text-sm text-yellow-900 dark:text-yellow-100 space-y-1 ml-4">
                            <li>Înregistrările CNAME nu pot coexista cu alte tipuri pentru același nume</li>
                            <li>Înregistrările MX necesită prioritate (valoare mai mică = prioritate mai mare)</li>
                            <li>Înregistrările TXT trebuie să fie între ghilimele dacă conțin spații</li>
                            <li><strong>SPF trebuie creat ca TXT record</strong> (nu ca tip SPF - depreciat)</li>
                            <li>TTL (Time To Live) determină cât timp este cache-uită înregistrarea (în secunde)</li>
                        </ul>
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Toggle ghid cu animație chevron
        function toggleGuide() {
            const content = document.getElementById('guide-content');
            const button = event.currentTarget;
            const chevron = button.querySelector('.fa-chevron-down, .fa-chevron-up');

            content.classList.toggle('hidden');

            if (chevron) {
                if (content.classList.contains('hidden')) {
                    chevron.classList.remove('fa-chevron-up');
                    chevron.classList.add('fa-chevron-down');
                } else {
                    chevron.classList.remove('fa-chevron-down');
                    chevron.classList.add('fa-chevron-up');
                }
            }
        }

        // Custom combo box cu dropdown integrat
        document.addEventListener('DOMContentLoaded', function() {
            const input = document.getElementById('type-input');
            const hiddenInput = document.getElementById('type');
            const dropdown = document.getElementById('type-dropdown');
            const optionsContainer = document.getElementById('type-options');
            const allOptions = Array.from(optionsContainer.children);
            let selectedIndex = -1;

            // Toggle dropdown
            input.addEventListener('click', function() {
                dropdown.classList.toggle('hidden');
                filterOptions('');
                selectedIndex = -1;
            });

            // Search/filter
            input.addEventListener('input', function() {
                const searchTerm = this.value.toLowerCase();
                dropdown.classList.remove('hidden');
                filterOptions(searchTerm);
                selectedIndex = -1;
            });

            // Filter options
            function filterOptions(searchTerm) {
                let hasResults = false;
                allOptions.forEach(option => {
                    const label = option.dataset.label.toLowerCase();
                    if (label.includes(searchTerm)) {
                        option.style.display = 'block';
                        hasResults = true;
                    } else {
                        option.style.display = 'none';
                    }
                });

                if (!hasResults) {
                    optionsContainer.innerHTML = '<div class="px-4 py-2 text-gray-500 dark:text-gray-400">Nu s-au găsit rezultate</div>';
                } else if (optionsContainer.children[0].textContent === 'Nu s-au găsit rezultate') {
                    optionsContainer.innerHTML = '';
                    allOptions.forEach(opt => optionsContainer.appendChild(opt));
                }
            }

            // Get visible options
            function getVisibleOptions() {
                return allOptions.filter(opt => opt.style.display !== 'none');
            }

            // Highlight option
            function highlightOption(index) {
                const visibleOptions = getVisibleOptions();
                // Remove previous highlight
                visibleOptions.forEach(opt => opt.classList.remove('bg-indigo-100', 'dark:bg-indigo-800'));

                if (index >= 0 && index < visibleOptions.length) {
                    visibleOptions[index].classList.add('bg-indigo-100', 'dark:bg-indigo-800');
                    // Scroll into view
                    visibleOptions[index].scrollIntoView({ block: 'nearest', behavior: 'smooth' });
                }
            }

            // Select option
            optionsContainer.addEventListener('click', function(e) {
                const option = e.target.closest('[data-value]');
                if (option) {
                    input.value = option.dataset.label;
                    hiddenInput.value = option.dataset.value;
                    dropdown.classList.add('hidden');

                    // Trigger change event to show/hide SRV fields
                    const event = new Event('change');
                    hiddenInput.dispatchEvent(event);
                }
            });

            // Hover effect
            optionsContainer.addEventListener('mouseover', function(e) {
                const option = e.target.closest('[data-value]');
                if (option) {
                    const visibleOptions = getVisibleOptions();
                    selectedIndex = visibleOptions.indexOf(option);
                    highlightOption(selectedIndex);
                }
            });

            // Close dropdown when clicking outside
            document.addEventListener('click', function(e) {
                if (!input.contains(e.target) && !dropdown.contains(e.target)) {
                    dropdown.classList.add('hidden');
                }
            });

            // Watch for type selection to show/hide SRV fields
            hiddenInput.addEventListener('change', function() {
                const selectedType = this.value;
                const srvFields = document.getElementById('srv-fields');
                const priorityField = document.getElementById('priority');
                const priorityRequired = document.getElementById('priority-required');
                const priorityOptional = document.getElementById('priority-optional');
                const priorityHelp = document.getElementById('priority-help');
                const weightField = document.getElementById('weight');
                const portField = document.getElementById('port');
                const nameInput = document.getElementById('name');
                const contentInput = document.getElementById('content');

                if (selectedType === 'SRV') {
                    // Show SRV fields
                    srvFields.classList.remove('hidden');
                    priorityRequired.classList.remove('hidden');
                    priorityOptional.classList.add('hidden');
                    priorityField.setAttribute('required', 'required');
                    weightField.setAttribute('required', 'required');
                    portField.setAttribute('required', 'required');

                    // Update placeholders
                    nameInput.placeholder = '_sip._tcp';
                    contentInput.placeholder = 'sipserver.example.com';
                    priorityHelp.textContent = 'Prioritate (valoare mai mică = prioritate mai mare)';
                } else {
                    // Hide SRV fields
                    srvFields.classList.add('hidden');
                    priorityRequired.classList.add('hidden');
                    weightField.removeAttribute('required');
                    portField.removeAttribute('required');

                    // Reset placeholders
                    nameInput.placeholder = 'www';
                    contentInput.placeholder = '192.168.1.1';

                    // Handle priority for MX
                    if (selectedType === 'MX') {
                        priorityRequired.classList.remove('hidden');
                        priorityOptional.classList.add('hidden');
                        priorityField.setAttribute('required', 'required');
                        priorityHelp.textContent = 'Necesar pentru MX (valoare mai mică = prioritate mai mare)';
                    } else {
                        priorityOptional.classList.remove('hidden');
                        priorityField.removeAttribute('required');
                        priorityHelp.textContent = 'Necesar pentru MX și SRV (valoare mai mică = prioritate mai mare)';
                    }
                }
            });

            // Keyboard navigation
            input.addEventListener('keydown', function(e) {
                const visibleOptions = getVisibleOptions();
                const isDropdownOpen = !dropdown.classList.contains('hidden');

                // Previne scroll-ul paginii când dropdown-ul este deschis
                if (isDropdownOpen && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {
                    e.preventDefault();
                    e.stopPropagation();
                }

                if (e.key === 'Escape') {
                    dropdown.classList.add('hidden');
                    selectedIndex = -1;
                } else if (e.key === 'ArrowDown') {
                    e.preventDefault();
                    if (dropdown.classList.contains('hidden')) {
                        dropdown.classList.remove('hidden');
                        filterOptions('');
                    }
                    selectedIndex = Math.min(selectedIndex + 1, visibleOptions.length - 1);
                    highlightOption(selectedIndex);
                } else if (e.key === 'ArrowUp') {
                    e.preventDefault();
                    selectedIndex = Math.max(selectedIndex - 1, 0);
                    highlightOption(selectedIndex);
                } else if (e.key === 'Enter') {
                    e.preventDefault();
                    if (selectedIndex >= 0 && selectedIndex < visibleOptions.length) {
                        const selectedOption = visibleOptions[selectedIndex];
                        input.value = selectedOption.dataset.label;
                        hiddenInput.value = selectedOption.dataset.value;
                        dropdown.classList.add('hidden');
                        selectedIndex = -1;

                        // Trigger change event to show/hide SRV fields
                        const event = new Event('change');
                        hiddenInput.dispatchEvent(event);
                    }
                } else if (e.key === 'Tab') {
                    dropdown.classList.add('hidden');
                    selectedIndex = -1;
                }
            });
        });
    </script>
</x-app-layout>
