<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">
                {{ __('Edit') }} Înregistrare DNS
            </h2>
            <a href="{{ route('dns-zones.show', $zoneName) }}" 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>

    <div class="py-12">
        <div class="px-6 lg:px-8">
            <div class="flex flex-col lg:flex-row gap-6">
                <!-- Formular (2/3 pe desktop) -->
                <div class="w-full lg:w-2/3">
                    <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                        <div class="p-6">
                            <form method="POST" action="{{ route('powerdns.records.update', [$zoneName, $record['name'], $record['type']]) }}">
                        @csrf
                        @method('PATCH')

                        <!-- 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>
@php
$displayName = rtrim($record['name'], '.');
$zoneName = rtrim($zoneName, '.');
if ($displayName === $zoneName) {
    $subdomain = '@';
} elseif (str_ends_with($displayName, '.' . $zoneName)) {
    $subdomain = substr($displayName, 0, -(strlen($zoneName) + 1));
} else {
    $subdomain = $displayName;
}
@endphp
                            <div class="flex items-center">
                                <input type="text"
                                       name="subdomain"
                                       id="subdomain"
                                       value="{{ old('subdomain', $subdomain) }}"
                                       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">
                                    .{{ $zoneName }}
                                </span>
                            </div>
                            <input type="hidden" name="old_name" value="{{ $record['name'] }}">
                            <input type="hidden" name="name" id="hidden-name" value="{{ $record['name'] }}">
                            @error('subdomain')
                                <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="{{ old('type', $record['type']) }}">
                                <input type="hidden" name="type" id="type" value="{{ old('type', $record['type']) }}" required>
                                <input type="hidden" name="old_type" value="{{ $record['type'] }}">
                                <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">
                                @php
                                    $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',
                                        'SPF' => 'SPF - Sender Policy Framework',
                                        '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',
                                    ];
                                    // Pentru PowerDNS, permitem toate tipurile (admin are acces complet)
                                    $allowedTypes = array_keys($typeDescriptions);
                                @endphp
                                @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>
                            @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>
@php
$content = old('content');
$oldContent = '';
if (!$content) {
    // Dacă editează o înregistrare specifică din RRset
    if (isset($record['specific_content'])) {
        $content = $record['specific_content'];
        $oldContent = $record['specific_content'];
    } elseif (isset($record['records']) && is_array($record['records'])) {
        $content = collect($record['records'])->pluck('content')->first();
        $oldContent = $content;
    } elseif (isset($record['content'])) {
        $content = $record['content'];
        $oldContent = $content;
    } else {
        $content = '';
    }
} else {
    $oldContent = request()->query('content', '');
}
@endphp
                            <input type="hidden" name="old_content" value="{{ $oldContent }}">
                            <input type="text"
                                   name="content"
                                   id="content"
                                   value="{{ $content }}"
                                   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>
                            @error('content')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                            @if(isset($record['editing_single']) && $record['editing_single'])
                                <p class="mt-2 text-sm text-blue-600 dark:text-blue-400">
                                    <i class="fas fa-info-circle mr-1"></i>
                                    Editezi o înregistrare specifică dintr-un set de {{ count($record['records']) }} înregistrări
                                </p>
                            @endif
                        </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" {{ old('ttl', $record['ttl']) == '60' ? 'selected' : '' }}>1 minut (60)</option>
                                    <option value="300" {{ old('ttl', $record['ttl']) == '300' ? 'selected' : '' }}>5 minute (300)</option>
                                    <option value="1800" {{ old('ttl', $record['ttl']) == '1800' ? 'selected' : '' }}>30 minute (1800)</option>
                                    <option value="3600" {{ old('ttl', $record['ttl']) == '3600' ? 'selected' : '' }}>60 minute (3600)</option>
                                    <option value="86400" {{ old('ttl', $record['ttl']) == '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>
                                <label for="priority" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    {{ __('Priority') }}
                                </label>
                                <input type="number"
                                       name="priority"
                                       id="priority"
                                       value="{{ old('priority', $record['priority'] ?? '') }}"
                                       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
                            </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', $record['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', $zoneName) }}" 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-save mr-2"></i>
                                {{ __('Save') }}
                            </button>
                        </div>
                    </form>
                        </div>
                    </div>
                </div>

                <!-- Ghid și Legendă (1/3 pe desktop) -->
                <div class="w-full lg:w-1/3">
                    <!-- 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 ({{ rtrim($zoneName, '.') }})</li>
                                    <li><code class="bg-blue-100 dark:bg-blue-900 px-2 py-1 rounded">www</code> = subdomeniu (www.{{ rtrim($zoneName, '.') }})</li>
                                    <li><code class="bg-blue-100 dark:bg-blue-900 px-2 py-1 rounded">mail</code> = subdomeniu (mail.{{ rtrim($zoneName, '.') }})</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> {{ rtrim($zoneName, '.') }}
                                        </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.{{ rtrim($zoneName, '.') }}<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=spf1 mx ~all"
                                        </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>
                                </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>TTL (Time To Live) determină cât timp este cache-uită înregistrarea (în secunde)</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 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;

            // Set initial value
            const currentType = hiddenInput.value;
            if (currentType) {
                const currentOption = allOptions.find(opt => opt.dataset.value === currentType);
                if (currentOption) {
                    input.value = currentOption.dataset.label;
                }
            }

            // 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');
                }
            });

            // 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');
                }
            });

            // 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;
                    }
                } else if (e.key === 'Tab') {
                    dropdown.classList.add('hidden');
                    selectedIndex = -1;
                }
            });
        });

        // JavaScript simplu pentru actualizare câmp name
        const subdomainInput = document.getElementById('subdomain');
        const nameInput = document.getElementById('hidden-name');
        const zoneName = '{{ rtrim($zoneName, ".") }}';

        function updateName() {
            if (subdomainInput && nameInput) {
                const subdomain = subdomainInput.value.trim();
                if (subdomain === '@' || subdomain === '') {
                    nameInput.value = zoneName + '.';
                } else {
                    nameInput.value = subdomain + '.' + zoneName + '.';
                }
            }
        }

        // Actualizează la modificare
        if (subdomainInput) {
            subdomainInput.addEventListener('input', updateName);
            subdomainInput.addEventListener('change', updateName);
            updateName(); // Inițializează
        }
    </script>
</x-app-layout>
