<x-app-layout>
    <x-slot name="header">
        <div>
            <h2 class="font-semibold text-lg text-gray-800 dark:text-gray-200 leading-tight">
                <i class="fas fa-edit mr-2"></i>{{ __('Editează Client DynDNS') }}
            </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('dyndns.index') }}" class="text-blue-600 dark:text-blue-400 hover:underline">DynDNS</a>
                <span class="mx-2">/</span>
                <a href="{{ route('dyndns.show', $client) }}" class="text-blue-600 dark:text-blue-400 hover:underline">{{ $client->hostname }}</a>
                <span class="mx-2">/</span>
                <span>Editează</span>
            </p>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6">
                    <form action="{{ route('dyndns.update', $client) }}" method="POST">
                        @csrf
                        @method('PUT')

                        <!-- Hostname (read-only) -->
                        <div class="mb-6">
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Hostname
                            </label>
                            <input type="text"
                                   value="{{ $client->hostname }}"
                                   readonly
                                   disabled
                                   class="w-full font-mono rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-400 bg-gray-100 cursor-not-allowed">
                            <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
                                <i class="fas fa-lock mr-1"></i>Hostname-ul nu poate fi modificat. Pentru a schimba hostname-ul, creează un client nou.
                            </p>
                        </div>

                        <!-- Zonă DNS (read-only) -->
                        <div class="mb-6">
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Zonă DNS
                            </label>
                            <input type="text"
                                   value="{{ $client->dnsZone->domain }}"
                                   readonly
                                   disabled
                                   class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-400 bg-gray-100 cursor-not-allowed">
                        </div>

                        <!-- IP Curent (read-only) -->
                        <div class="mb-6">
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                IP Curent
                            </label>
                            <input type="text"
                                   value="{{ $client->current_ip ?? 'Nedetectat încă' }}"
                                   readonly
                                   disabled
                                   class="w-full font-mono rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-400 bg-gray-100 cursor-not-allowed">
                        </div>

                        <hr class="my-6 border-gray-200 dark:border-gray-700">

                        <!-- TTL -->
                        <div class="mb-6">
                            <label for="ttl" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                TTL (Time To Live) <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-blue-500 focus:ring focus:ring-blue-200">
                                <option value="60" {{ old('ttl', $client->ttl) == 60 ? 'selected' : '' }}>1 minut</option>
                                <option value="300" {{ old('ttl', $client->ttl) == 300 ? 'selected' : '' }}>5 minute (recomandat)</option>
                                <option value="600" {{ old('ttl', $client->ttl) == 600 ? 'selected' : '' }}>10 minute</option>
                                <option value="1800" {{ old('ttl', $client->ttl) == 1800 ? 'selected' : '' }}>30 minute</option>
                                <option value="3600" {{ old('ttl', $client->ttl) == 3600 ? 'selected' : '' }}>1 oră</option>
                            </select>
                            <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
                                Timpul după care înregistrarea DNS expiră în cache. Valori mai mici = actualizare mai rapidă, dar mai mult trafic DNS.
                            </p>
                            @error('ttl')
                                <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Notificări -->
                        <div class="mb-6">
                            <label class="flex items-center">
                                <input type="checkbox"
                                       name="notify_on_change"
                                       value="1"
                                       {{ old('notify_on_change', $client->notify_on_change) ? 'checked' : '' }}
                                       class="rounded border-gray-300 dark:border-gray-700 text-blue-600 focus:ring-blue-500">
                                <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">
                                    Trimite notificare prin email la schimbarea IP-ului
                                </span>
                            </label>
                            <p class="mt-1 ml-6 text-sm text-gray-500 dark:text-gray-400">
                                Vei primi un email de fiecare dată când IP-ul se schimbă.
                            </p>
                        </div>

                        <!-- Info Box -->
                        <div class="mb-6 p-4 bg-yellow-50 dark:bg-yellow-900/20 rounded-lg border border-yellow-200 dark:border-yellow-800">
                            <h4 class="font-medium text-yellow-900 dark:text-yellow-300 mb-2">
                                <i class="fas fa-exclamation-triangle mr-2"></i>Notă
                            </h4>
                            <p class="text-sm text-yellow-800 dark:text-yellow-300">
                                Modificarea TTL-ului nu afectează scripturile existente. Dacă vrei să regenerezi token-ul (de ex. în caz de compromitere),
                                folosește butonul de regenerare din pagina de detalii.
                            </p>
                        </div>

                        <!-- Actions -->
                        <div class="flex items-center justify-end space-x-3">
                            <a href="{{ route('dyndns.show', $client) }}"
                               class="px-4 py-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-300 rounded-lg transition">
                                Anulează
                            </a>
                            <button type="submit"
                                    class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition">
                                <i class="fas fa-save mr-2"></i>Salvează Modificările
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
