<x-admin-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-tachometer-alt mr-2"></i>Editează Pachet: {{ $plan->name }}
                </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('admin.dashboard') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Admin</a>
                    <span class="mx-2">/</span>
                    <a href="{{ route('admin.plans.index') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Pachete</a>
                    <span class="mx-2">/</span>
                    <span>Editare</span>
                </p>
            </div>
            <a href="{{ route('admin.plans.index') }}" 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="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 method="POST" action="{{ route('admin.plans.update', $plan) }}">
                        @csrf
                        @method('PATCH')

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                            <!-- Name -->
                            <div>
                                <label for="name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Nume Pachet <span class="text-red-500">*</span>
                                </label>
                                <input type="text"
                                       name="name"
                                       id="name"
                                       value="{{ old('name', $plan->name) }}"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"
                                       required>
                                @error('name')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- Slug -->
                            <div>
                                <label for="slug" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Slug <span class="text-red-500">*</span>
                                </label>
                                <input type="text"
                                       name="slug"
                                       id="slug"
                                       value="{{ old('slug', $plan->slug) }}"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"
                                       required>
                                @error('slug')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>

                        <!-- Price -->
                        <div class="mb-6">
                            <label for="price" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Preț (RON/lună) <span class="text-red-500">*</span>
                            </label>
                            <input type="number"
                                   name="price"
                                   id="price"
                                   value="{{ old('price', $plan->price) }}"
                                   step="0.01"
                                   min="0"
                                   class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"
                                   required>
                            @error('price')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- Stripe Integration -->
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                            <div>
                                <label for="stripe_price_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    <i class="fab fa-stripe mr-1"></i> Stripe Price ID
                                </label>
                                <input type="text"
                                       name="stripe_price_id"
                                       id="stripe_price_id"
                                       value="{{ old('stripe_price_id', $plan->stripe_price_id) }}"
                                       placeholder="price_xxxxxxxxxxxxx"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">ID-ul prețului din Stripe Dashboard</p>
                                @error('stripe_price_id')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <div>
                                <label for="stripe_product_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    <i class="fab fa-stripe mr-1"></i> Stripe Product ID
                                </label>
                                <input type="text"
                                       name="stripe_product_id"
                                       id="stripe_product_id"
                                       value="{{ old('stripe_product_id', $plan->stripe_product_id) }}"
                                       placeholder="prod_xxxxxxxxxxxxx"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">ID-ul produsului din Stripe Dashboard</p>
                                @error('stripe_product_id')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
                            <!-- DNS Zones Limit -->
                            <div>
                                <label for="dns_zones_limit" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Zone DNS <span class="text-red-500">*</span>
                                </label>
                                <input type="number"
                                       name="dns_zones_limit"
                                       id="dns_zones_limit"
                                       value="{{ old('dns_zones_limit', $plan->dns_zones_limit) }}"
                                       min="1"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"
                                       required>
                                @error('dns_zones_limit')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- Subdomains Limit -->
                            <div>
                                <label for="subdomains_limit" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Subdomenii <span class="text-red-500">*</span>
                                </label>
                                <input type="number"
                                       name="subdomains_limit"
                                       id="subdomains_limit"
                                       value="{{ old('subdomains_limit', $plan->subdomains_limit) }}"
                                       min="1"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"
                                       required>
                                @error('subdomains_limit')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- Nameservers Limit -->
                            <div>
                                <label for="nameservers_limit" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Nameservere <span class="text-red-500">*</span>
                                </label>
                                <input type="number"
                                       name="nameservers_limit"
                                       id="nameservers_limit"
                                       value="{{ old('nameservers_limit', $plan->nameservers_limit) }}"
                                       min="1"
                                       class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300"
                                       required>
                                @error('nameservers_limit')
                                    <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>

                        <!-- Secțiune Limite Query-uri DNS -->
                        <div class="mb-6 p-6 bg-gradient-to-r from-amber-50 to-orange-50 dark:from-amber-900/20 dark:to-orange-900/20 border border-amber-200 dark:border-amber-800 rounded-lg">
                            <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">
                                <i class="fas fa-tachometer-alt mr-2 text-amber-600"></i>
                                Limite Query-uri DNS
                            </h3>
                            <p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
                                Configurează limitele de interogări DNS și acțiunile la depășire pentru a proteja infrastructura.
                            </p>

                            <!-- Limite Lunare și Zilnice -->
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                                <!-- Limită Lunară -->
                                <div class="p-4 bg-white/60 dark:bg-gray-800/60 rounded-lg">
                                    <label for="dns_queries_limit" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        <i class="fas fa-calendar-alt mr-1 text-blue-500"></i>
                                        Limită Query-uri/Lună
                                    </label>
                                    <input type="number"
                                           name="dns_queries_limit"
                                           id="dns_queries_limit"
                                           value="{{ old('dns_queries_limit', $plan->dns_queries_limit) }}"
                                           min="0"
                                           placeholder="Ex: 1000000 (1 milion)"
                                           class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    @error('dns_queries_limit')
                                        <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">
                                        Lasă gol pentru nelimitat lunar
                                    </p>
                                </div>

                                <!-- Limită Zilnică -->
                                <div class="p-4 bg-white/60 dark:bg-gray-800/60 rounded-lg">
                                    <label for="dns_queries_limit_daily" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        <i class="fas fa-calendar-day mr-1 text-amber-500"></i>
                                        Limită Query-uri/Zi
                                    </label>
                                    <input type="number"
                                           name="dns_queries_limit_daily"
                                           id="dns_queries_limit_daily"
                                           value="{{ old('dns_queries_limit_daily', $plan->dns_queries_limit_daily) }}"
                                           min="0"
                                           placeholder="Ex: 50000"
                                           class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    @error('dns_queries_limit_daily')
                                        <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">
                                        Lasă gol pentru fără limită zilnică
                                    </p>
                                </div>
                            </div>

                            <!-- Setări Depășire -->
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
                                <!-- Acțiune la Depășire -->
                                <div>
                                    <label for="overage_action" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        <i class="fas fa-exclamation-triangle mr-1 text-red-500"></i>
                                        Acțiune la Depășire
                                    </label>
                                    <select name="overage_action"
                                            id="overage_action"
                                            class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                        <option value="notify" {{ old('overage_action', $plan->overage_action) === 'notify' ? 'selected' : '' }}>
                                            📧 Doar Notificare (serviciul continuă)
                                        </option>
                                        <option value="refuse" {{ old('overage_action', $plan->overage_action) === 'refuse' ? 'selected' : '' }}>
                                            🚫 Refuză Query-uri (REFUSED)
                                        </option>
                                        <option value="suspend" {{ old('overage_action', $plan->overage_action) === 'suspend' ? 'selected' : '' }}>
                                            ⛔ Suspendă Zonele DNS
                                        </option>
                                    </select>
                                    @error('overage_action')
                                        <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                    @enderror
                                </div>

                                <!-- Procent Grație -->
                                <div>
                                    <label for="overage_grace_percent" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        <i class="fas fa-percent mr-1 text-green-500"></i>
                                        Toleranță Depășire (%)
                                    </label>
                                    <input type="number"
                                           name="overage_grace_percent"
                                           id="overage_grace_percent"
                                           value="{{ old('overage_grace_percent', $plan->overage_grace_percent ?? 0) }}"
                                           min="0"
                                           max="100"
                                           placeholder="Ex: 10"
                                           class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    @error('overage_grace_percent')
                                        <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">
                                        0% = acțiune exactă la limită, 10% = 10% buffer extra
                                    </p>
                                </div>
                            </div>

                            <!-- Explicație acțiuni -->
                            <div class="p-3 bg-white/50 dark:bg-gray-800/50 rounded-lg border border-amber-100 dark:border-amber-900">
                                <p class="text-xs text-gray-600 dark:text-gray-400 leading-relaxed">
                                    <span class="inline-block mb-1"><strong>📧 Doar Notificare:</strong> Serviciul DNS continuă să funcționeze, utilizatorul primește email de avertizare.</span><br>
                                    <span class="inline-block mb-1"><strong>🚫 Refuză Query-uri:</strong> Nameserverele returnează REFUSED pentru zonele utilizatorului care a depășit limita.</span><br>
                                    <span class="inline-block"><strong>⛔ Suspendă Zonele:</strong> Zonele DNS sunt dezactivate complet până la upgrade sau reset (lunar/zilnic).</span>
                                </p>
                            </div>
                        </div>

                        <!-- API Access Settings -->
                        <div class="mb-6 p-6 bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-900/20 dark:to-indigo-900/20 border border-blue-200 dark:border-blue-800 rounded-lg">
                            <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">
                                <i class="fas fa-plug mr-2 text-blue-600"></i>
                                API Access Settings
                            </h3>

                            <!-- Enable API -->
                            <div class="mb-4">
                                <label class="flex items-center">
                                    <input type="checkbox"
                                           name="api_enabled"
                                           id="api_enabled"
                                           value="1"
                                           {{ old('api_enabled', $plan->api_enabled) ? 'checked' : '' }}
                                           class="rounded border-gray-300 dark:border-gray-700 text-blue-600 shadow-sm focus:ring-blue-500"
                                           onchange="toggleApiSettings(this.checked)">
                                    <span class="ml-2 text-sm font-medium text-gray-700 dark:text-gray-300">
                                        Enable API Access for this plan
                                    </span>
                                </label>
                            </div>

                            <div id="apiSettings" style="display: {{ old('api_enabled', $plan->api_enabled) ? 'block' : 'none' }}">
                                <!-- Rate Limits -->
                                <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
                                    <div>
                                        <label for="api_rate_limit_hour" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            Requests/Hour
                                        </label>
                                        <input type="number"
                                               name="api_rate_limit_hour"
                                               id="api_rate_limit_hour"
                                               value="{{ old('api_rate_limit_hour', $plan->api_rate_limit_hour ?? 60) }}"
                                               min="1"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    </div>

                                    <div>
                                        <label for="api_rate_limit_day" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            Requests/Day
                                        </label>
                                        <input type="number"
                                               name="api_rate_limit_day"
                                               id="api_rate_limit_day"
                                               value="{{ old('api_rate_limit_day', $plan->api_rate_limit_day ?? 1000) }}"
                                               min="1"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    </div>

                                    <div>
                                        <label for="api_max_tokens" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            Max API Tokens
                                        </label>
                                        <input type="number"
                                               name="api_max_tokens"
                                               id="api_max_tokens"
                                               value="{{ old('api_max_tokens', $plan->api_max_tokens ?? 1) }}"
                                               min="1"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    </div>
                                </div>

                                <!-- Endpoints Access -->
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        Endpoints Access
                                    </label>
                                    <div class="grid grid-cols-2 md:grid-cols-3 gap-3">
                                        @php
                                            $endpoints = [
                                                'zones:read' => 'Zones (Read)',
                                                'zones:write' => 'Zones (Write)',
                                                'zones:delete' => 'Zones (Delete)',
                                                'records:read' => 'Records (Read)',
                                                'records:write' => 'Records (Write)',
                                                'records:delete' => 'Records (Delete)',
                                                'statistics:read' => 'Statistics',
                                            ];
                                            $selectedEndpoints = old('api_endpoints_access', $plan->api_endpoints_access ?? []);
                                        @endphp
                                        @foreach($endpoints as $value => $label)
                                            <label class="flex items-center p-2 bg-white dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-700">
                                                <input type="checkbox"
                                                       name="api_endpoints_access[]"
                                                       value="{{ $value }}"
                                                       {{ in_array($value, $selectedEndpoints) ? 'checked' : '' }}
                                                       class="rounded border-gray-300 text-blue-600">
                                                <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">{{ $label }}</span>
                                            </label>
                                        @endforeach
                                    </div>
                                </div>

                                <!-- Advanced Features -->
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        Advanced Features
                                    </label>
                                    <div class="grid grid-cols-2 md:grid-cols-3 gap-3">
                                        @php
                                            $features = [
                                                'bulk_operations' => 'Bulk Operations',
                                                'webhooks' => 'Webhooks',
                                                'ip_whitelist' => 'IP Whitelist',
                                            ];
                                            $selectedFeatures = old('api_features', $plan->api_features ?? []);
                                        @endphp
                                        @foreach($features as $value => $label)
                                            <label class="flex items-center p-2 bg-white dark:bg-gray-800 rounded border border-gray-200 dark:border-gray-700">
                                                <input type="checkbox"
                                                       name="api_features[]"
                                                       value="{{ $value }}"
                                                       {{ in_array($value, $selectedFeatures) ? 'checked' : '' }}
                                                       class="rounded border-gray-300 text-blue-600">
                                                <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">{{ $label }}</span>
                                            </label>
                                        @endforeach
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- DynDNS Settings -->
                        <div class="mb-6 p-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
                            <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">
                                <i class="fas fa-sync-alt mr-2 text-purple-600"></i>
                                DynDNS Settings
                            </h3>

                            <!-- Enable DynDNS -->
                            <div class="mb-4">
                                <label class="flex items-center">
                                    <input type="checkbox"
                                           name="dyndns_enabled"
                                           id="dyndns_enabled"
                                           value="1"
                                           {{ old('dyndns_enabled', $plan->dyndns_enabled) ? 'checked' : '' }}
                                           class="rounded border-gray-300 dark:border-gray-700 text-purple-600 shadow-sm focus:ring-purple-500"
                                           onchange="toggleDynDnsSettings(this.checked)">
                                    <span class="ml-2 text-sm font-medium text-gray-700 dark:text-gray-300">
                                        Activează DynDNS pentru acest plan
                                    </span>
                                </label>
                                <p class="mt-1 ml-6 text-xs text-gray-500 dark:text-gray-400">
                                    Permite utilizatorilor să creeze clienți DynDNS pentru actualizare automată a IP-ului
                                </p>
                            </div>

                            <div id="dyndnsSettings" style="display: {{ old('dyndns_enabled', $plan->dyndns_enabled) ? 'block' : 'none' }}">
                                <!-- Max DynDNS Clients -->
                                <div>
                                    <label for="dyndns_max_clients" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                        Număr Maxim de Clienți DynDNS
                                        <span class="text-gray-500 text-xs ml-2">(0 = nelimitat)</span>
                                    </label>
                                    <input type="number"
                                           name="dyndns_max_clients"
                                           id="dyndns_max_clients"
                                           value="{{ old('dyndns_max_clients', $plan->dyndns_max_clients) }}"
                                           min="0"
                                           class="w-full md:w-1/3 rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                    <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
                                        Setează câți clienți DynDNS pot crea utilizatorii cu acest plan (0 pentru nelimitat)
                                    </p>
                                </div>
                            </div>
                        </div>

                        <!-- Cloudflare Settings -->
                        <div class="mb-6 p-4 bg-orange-50 dark:bg-orange-900/10 rounded-lg border border-orange-200 dark:border-orange-800">
                            <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-4">
                                <i class="fas fa-cloud mr-2 text-orange-500"></i>
                                Cloudflare Settings
                            </h3>

                            <!-- Enable Cloudflare -->
                            <div class="mb-4">
                                <label class="flex items-center">
                                    <input type="checkbox"
                                           name="cloudflare_enabled"
                                           id="cloudflare_enabled"
                                           value="1"
                                           {{ old('cloudflare_enabled', $plan->cloudflare_enabled) ? 'checked' : '' }}
                                           class="rounded border-gray-300 dark:border-gray-700 text-orange-600 shadow-sm focus:ring-orange-500"
                                           onchange="toggleCloudflareSettings(this.checked)">
                                    <span class="ml-2 text-sm font-medium text-gray-700 dark:text-gray-300">
                                        Activează Cloudflare pentru acest plan
                                    </span>
                                </label>
                                <p class="mt-1 ml-6 text-xs text-gray-500 dark:text-gray-400">
                                    Permite utilizatorilor să conecteze zonele DNS la Cloudflare
                                </p>
                            </div>

                            <div id="cloudflareSettings" style="display: {{ old('cloudflare_enabled', $plan->cloudflare_enabled) ? 'block' : 'none' }}">
                                <!-- Limite Cloudflare pe un singur rând -->
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                                    <!-- Max Cloudflare Zones -->
                                    <div>
                                        <label for="cloudflare_max_zones" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            <i class="fas fa-globe text-orange-500 mr-1"></i>
                                            Număr Maxim Zone Cloudflare
                                            <span class="text-gray-500 text-xs ml-1">(0 = nelimitat)</span>
                                        </label>
                                        <input type="number"
                                               name="cloudflare_max_zones"
                                               id="cloudflare_max_zones"
                                               value="{{ old('cloudflare_max_zones', $plan->cloudflare_max_zones) }}"
                                               min="0"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                        <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
                                            Câte zone pot conecta la Cloudflare
                                        </p>
                                    </div>

                                    <!-- Max Cloudflare Credentials -->
                                    <div>
                                        <label for="cloudflare_max_credentials" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                            <i class="fas fa-key text-orange-500 mr-1"></i>
                                            Număr Maxim Credențiale CF
                                            <span class="text-gray-500 text-xs ml-1">(0 = nelimitat)</span>
                                        </label>
                                        <input type="number"
                                               name="cloudflare_max_credentials"
                                               id="cloudflare_max_credentials"
                                               value="{{ old('cloudflare_max_credentials', $plan->cloudflare_max_credentials ?? 1) }}"
                                               min="0"
                                               class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">
                                        <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
                                            Câte conturi/API keys CF pot adăuga
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Allowed Record Types -->
                        <div class="mb-6">
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">
                                Tipuri Înregistrări DNS Permise
                                <span class="text-gray-500 text-xs ml-2">(lasă toate nebifate pentru acces complet)</span>
                            </label>
                            <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-3">
                                @php
                                    $recordTypes = [
                                        'A' => ['icon' => 'fa-arrow-right', 'color' => 'blue', 'desc' => 'IPv4 Address'],
                                        'AAAA' => ['icon' => 'fa-arrows-alt-h', 'color' => 'indigo', 'desc' => 'IPv6 Address'],
                                        'AFSDB' => ['icon' => 'fa-database', 'color' => 'cyan', 'desc' => 'AFS Database'],
                                        'ALIAS' => ['icon' => 'fa-link', 'color' => 'teal', 'desc' => 'Auto-resolved alias'],
                                        'CAA' => ['icon' => 'fa-shield-alt', 'color' => 'red', 'desc' => 'Certification Authority'],
                                        'CERT' => ['icon' => 'fa-certificate', 'color' => 'amber', 'desc' => 'Certificate Record'],
                                        'CDNSKEY' => ['icon' => 'fa-key', 'color' => 'lime', 'desc' => 'Child DNSKEY'],
                                        'CDS' => ['icon' => 'fa-fingerprint', 'color' => 'emerald', 'desc' => 'Child DS'],
                                        'CNAME' => ['icon' => 'fa-link', 'color' => 'purple', 'desc' => 'Canonical Name'],
                                        'DNSKEY' => ['icon' => 'fa-key', 'color' => 'yellow', 'desc' => 'DNSSEC Public Key'],
                                        'DNAME' => ['icon' => 'fa-sitemap', 'color' => 'violet', 'desc' => 'Delegation Name'],
                                        'DS' => ['icon' => 'fa-shield-virus', 'color' => 'fuchsia', 'desc' => 'Delegation Signer'],
                                        'HINFO' => ['icon' => 'fa-info-circle', 'color' => 'slate', 'desc' => 'Host Information'],
                                        'KEY' => ['icon' => 'fa-key', 'color' => 'zinc', 'desc' => 'Public Key'],
                                        'LOC' => ['icon' => 'fa-map-marker-alt', 'color' => 'rose', 'desc' => 'Location'],
                                        'MX' => ['icon' => 'fa-envelope', 'color' => 'pink', 'desc' => 'Mail Exchange'],
                                        'NAPTR' => ['icon' => 'fa-random', 'color' => 'orange', 'desc' => 'Naming Authority Pointer'],
                                        'NS' => ['icon' => 'fa-server', 'color' => 'yellow', 'desc' => 'Name Server'],
                                        'NSEC' => ['icon' => 'fa-lock', 'color' => 'gray', 'desc' => 'Next Secure'],
                                        'NSEC3' => ['icon' => 'fa-lock', 'color' => 'stone', 'desc' => 'NSEC version 3'],
                                        'NSEC3PARAM' => ['icon' => 'fa-cog', 'color' => 'neutral', 'desc' => 'NSEC3 Parameters'],
                                        'OPENPGPKEY' => ['icon' => 'fa-key', 'color' => 'sky', 'desc' => 'OpenPGP Public Key'],
                                        'PTR' => ['icon' => 'fa-reply', 'color' => 'gray', 'desc' => 'Pointer'],
                                        'RP' => ['icon' => 'fa-user', 'color' => 'blue', 'desc' => 'Responsible Person'],
                                        'RRSIG' => ['icon' => 'fa-signature', 'color' => 'green', 'desc' => 'DNSSEC Signature'],
                                        'SOA' => ['icon' => 'fa-crown', 'color' => 'gold', 'desc' => 'Start of Authority'],
                                        'SPF' => ['icon' => 'fa-envelope-open-text', 'color' => 'blue', 'desc' => 'Sender Policy Framework'],
                                        'SSHFP' => ['icon' => 'fa-fingerprint', 'color' => 'indigo', 'desc' => 'SSH Fingerprint'],
                                        'SRV' => ['icon' => 'fa-network-wired', 'color' => 'orange', 'desc' => 'Service'],
                                        'TKEY' => ['icon' => 'fa-key', 'color' => 'purple', 'desc' => 'Transaction Key'],
                                        'TLSA' => ['icon' => 'fa-certificate', 'color' => 'green', 'desc' => 'TLS Authentication'],
                                        'TSIG' => ['icon' => 'fa-signature', 'color' => 'red', 'desc' => 'Transaction Signature'],
                                        'TXT' => ['icon' => 'fa-file-alt', 'color' => 'green', 'desc' => 'Text Record'],
                                        'URI' => ['icon' => 'fa-link', 'color' => 'blue', 'desc' => 'Uniform Resource Identifier'],
                                    ];
                                    $oldTypes = old('allowed_record_types', $plan->allowed_record_types ?? []);
                                @endphp

                                @foreach($recordTypes as $type => $config)
                                    <label class="flex items-start p-2 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-{{ $config['color'] }}-400 dark:hover:border-{{ $config['color'] }}-500 cursor-pointer transition hover:bg-gray-50 dark:hover:bg-gray-700/30">
                                        <input type="checkbox"
                                               name="allowed_record_types[]"
                                               value="{{ $type }}"
                                               {{ in_array($type, $oldTypes) ? 'checked' : '' }}
                                               class="mt-0.5 rounded border-gray-300 dark:border-gray-700 text-{{ $config['color'] }}-600 focus:ring-{{ $config['color'] }}-500">
                                        <span class="ml-2 flex-1">
                                            <span class="flex items-center">
                                                <i class="fas {{ $config['icon'] }} text-{{ $config['color'] }}-600 dark:text-{{ $config['color'] }}-400 text-xs mr-1"></i>
                                                <span class="font-semibold text-gray-900 dark:text-gray-100 text-sm">{{ $type }}</span>
                                            </span>
                                            <span class="block text-xs text-gray-500 dark:text-gray-400 leading-tight">{{ $config['desc'] }}</span>
                                        </span>
                                    </label>
                                @endforeach
                            </div>
                            <p class="mt-3 text-xs text-gray-500 dark:text-gray-400 bg-blue-50 dark:bg-blue-900/20 p-3 rounded-lg border border-blue-200 dark:border-blue-800">
                                <i class="fas fa-info-circle mr-1 text-blue-600"></i>
                                <strong>Notă:</strong> Dacă niciun tip nu este selectat, utilizatorii vor putea crea toate tipurile de înregistrări DNS suportate de PowerDNS.
                            </p>
                        </div>

                        <!-- Name Servers Permise -->
                        <div class="mb-6">
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">
                                <i class="fas fa-server text-cyan-600 mr-2"></i>
                                Name Servers Permise
                                <span class="text-xs text-gray-500 dark:text-gray-400 font-normal ml-2">(lasă toate nebifate pentru acces complet)</span>
                            </label>
                            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 max-h-64 overflow-y-auto p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
                                @php
                                    $nameServers = \App\Models\NameServer::where('is_active', true)->orderBy('name')->get();
                                    $oldNameServers = old('allowed_nameservers', $plan->allowed_nameservers ?? []);
                                @endphp

                                @forelse($nameServers as $ns)
                                    <label class="flex items-start p-3 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-cyan-400 dark:hover:border-cyan-500 cursor-pointer transition hover:bg-white dark:hover:bg-gray-800">
                                        <input type="checkbox"
                                               name="allowed_nameservers[]"
                                               value="{{ $ns->id }}"
                                               {{ in_array($ns->id, $oldNameServers) ? 'checked' : '' }}
                                               class="mt-0.5 rounded border-gray-300 dark:border-gray-700 text-cyan-600 focus:ring-cyan-500">
                                        <span class="ml-2 flex-1">
                                            <span class="flex items-center">
                                                <i class="fas fa-server text-cyan-600 dark:text-cyan-400 text-xs mr-1"></i>
                                                <span class="font-semibold text-gray-900 dark:text-gray-100 text-sm">{{ $ns->name }}</span>
                                            </span>
                                            <span class="block text-xs text-gray-500 dark:text-gray-400 leading-tight">{{ $ns->hostname }}</span>
                                            <span class="inline-block mt-1 px-2 py-0.5 text-xs rounded-full {{ $ns->status === 'online' ? 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400' : 'bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400' }}">
                                                {{ ucfirst($ns->status) }}
                                            </span>
                                        </span>
                                    </label>
                                @empty
                                    <div class="col-span-full text-center py-8 text-gray-500 dark:text-gray-400">
                                        <i class="fas fa-server text-4xl mb-2 opacity-50"></i>
                                        <p>Nu există name servers active în sistem.</p>
                                    </div>
                                @endforelse
                            </div>
                            <p class="mt-3 text-xs text-gray-500 dark:text-gray-400 bg-cyan-50 dark:bg-cyan-900/20 p-3 rounded-lg border border-cyan-200 dark:border-cyan-800">
                                <i class="fas fa-info-circle mr-1 text-cyan-600"></i>
                                <strong>Notă:</strong> Dacă niciun name server nu este selectat, utilizatorii vor putea folosi toate name servers active din sistem.
                            </p>
                        </div>

                        <!-- DNS Templates Permise -->
                        <div class="mb-6">
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">
                                <i class="fas fa-file-code text-purple-600 mr-2"></i>
                                DNS Templates Permise
                                <span class="text-xs text-gray-500 dark:text-gray-400 font-normal ml-2">(lasă toate nebifate pentru acces complet)</span>
                            </label>
                            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3 max-h-64 overflow-y-auto p-4 bg-gray-50 dark:bg-gray-900/50 rounded-lg border border-gray-200 dark:border-gray-700">
                                @php
                                    $templates = \App\Models\DnsTemplate::orderBy('name')->get();
                                    $oldTemplates = old('allowed_templates', $plan->allowed_templates ?? []);
                                @endphp

                                @forelse($templates as $template)
                                    <label class="flex items-start p-3 border border-gray-200 dark:border-gray-700 rounded-lg hover:border-purple-400 dark:hover:border-purple-500 cursor-pointer transition hover:bg-white dark:hover:bg-gray-800">
                                        <input type="checkbox"
                                               name="allowed_templates[]"
                                               value="{{ $template->id }}"
                                               {{ in_array($template->id, $oldTemplates) ? 'checked' : '' }}
                                               class="mt-0.5 rounded border-gray-300 dark:border-gray-700 text-purple-600 focus:ring-purple-500">
                                        <span class="ml-2 flex-1">
                                            <span class="flex items-center">
                                                <i class="fas fa-file-code text-purple-600 dark:text-purple-400 text-xs mr-1"></i>
                                                <span class="font-semibold text-gray-900 dark:text-gray-100 text-sm">{{ $template->name }}</span>
                                            </span>
                                            @if($template->description)
                                                <span class="block text-xs text-gray-500 dark:text-gray-400 leading-tight">{{ Str::limit($template->description, 50) }}</span>
                                            @endif
                                            <span class="block text-xs text-gray-400 dark:text-gray-500 mt-1">
                                                {{ $template->dns_records_count ?? $template->dnsRecords()->count() }} înregistrări
                                            </span>
                                        </span>
                                    </label>
                                @empty
                                    <div class="col-span-full text-center py-8 text-gray-500 dark:text-gray-400">
                                        <i class="fas fa-file-code text-4xl mb-2 opacity-50"></i>
                                        <p>Nu există template-uri DNS în sistem.</p>
                                    </div>
                                @endforelse
                            </div>
                            <p class="mt-3 text-xs text-gray-500 dark:text-gray-400 bg-purple-50 dark:bg-purple-900/20 p-3 rounded-lg border border-purple-200 dark:border-purple-800">
                                <i class="fas fa-info-circle mr-1 text-purple-600"></i>
                                <strong>Notă:</strong> Dacă niciun template nu este selectat, utilizatorii vor putea folosi toate template-urile DNS disponibile.
                            </p>
                        </div>

                        <!-- Allow Zone Export -->
                        <div class="mb-6">
                            <label class="flex items-center p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-800">
                                <input type="checkbox"
                                       name="allow_zone_export"
                                       value="1"
                                       {{ old('allow_zone_export', $plan->allow_zone_export) ? 'checked' : '' }}
                                       class="rounded border-gray-300 dark:border-gray-700 text-blue-600 focus:ring-blue-500">
                                <span class="ml-3 text-sm">
                                    <span class="font-medium text-gray-900 dark:text-gray-100">
                                        <i class="fas fa-download text-blue-600 mr-1"></i>
                                        Permite Export Zone DNS
                                    </span>
                                    <span class="block text-xs text-gray-600 dark:text-gray-400 mt-1">
                                        Utilizatorii cu acest plan vor putea exporta zonele DNS în formate TXT, BIND, HTML, JSON, Excel și XML
                                    </span>
                                </span>
                            </label>
                        </div>

                        <!-- Allow Zone Import -->
                        <div class="mb-6 bg-gradient-to-r from-green-50 to-emerald-50 dark:from-green-900/20 dark:to-emerald-900/20 border border-green-200 dark:border-green-700 rounded-lg p-4">
                            <label class="flex items-start cursor-pointer">
                                <input type="checkbox"
                                       name="allow_zone_import"
                                       value="1"
                                       {{ old('allow_zone_import', $plan->allow_zone_import) ? 'checked' : '' }}
                                       class="mt-1 rounded border-gray-300 dark:border-gray-700 text-green-600 focus:ring-green-500">
                                <span class="ml-3 text-sm">
                                    <span class="font-medium text-gray-900 dark:text-gray-100">
                                        <i class="fas fa-upload text-green-600 mr-1"></i>
                                        Permite Import Zone DNS
                                    </span>
                                    <span class="block text-xs text-gray-600 dark:text-gray-400 mt-1">
                                        Utilizatorii cu acest plan vor putea importa zone DNS din formate JSON și Excel
                                    </span>
                                </span>
                            </label>
                        </div>

                        <!-- Description -->
                        <div class="mb-6">
                            <label for="description" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                Descriere
                            </label>
                            <textarea name="description"
                                      id="description"
                                      rows="3"
                                      class="w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300">{{ old('description', $plan->description) }}</textarea>
            @error('description')
                                <p class="mt-2 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                            @enderror
                        </div>
                        <!-- Is Active & Is Visible -->
                        <div class="mb-6 grid grid-cols-1 md:grid-cols-2 gap-4">
                            <label class="flex items-center">
                                <input type="checkbox"
                                       name="is_active"
                                       value="1"
                                       {{ old('is_active', $plan->is_active) ? 'checked' : '' }}
                                       class="rounded border-gray-300 dark:border-gray-700 text-indigo-600 shadow-sm focus:ring-indigo-500 dark:focus:ring-indigo-600 dark:bg-gray-900">
                                <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Pachet activ</span>
                            </label>

                            <label class="flex items-center">
                                <input type="checkbox"
                                       name="is_visible"
                                       value="1"
                                       {{ old('is_visible', $plan->is_visible) ? 'checked' : '' }}
                                       class="rounded border-gray-300 dark:border-gray-700 text-indigo-600 shadow-sm focus:ring-indigo-500 dark:focus:ring-indigo-600 dark:bg-gray-900">
                                <span class="ml-2 text-sm text-gray-700 dark:text-gray-300">Pachet vizibil pe site</span>
                            </label>
                        </div>

                        <!-- Info -->
                        <div class="mb-6 p-4 bg-blue-50 dark:bg-blue-900/30 border border-blue-200 dark:border-blue-800 rounded-lg">
                            <p class="text-sm text-blue-800 dark:text-blue-300">
                                <i class="fas fa-info-circle mr-2"></i>
                                Acest pachet are <strong>{{ $plan->users()->count() }}</strong> utilizatori asociați
                            </p>
                        </div>

                        <!-- Buttons -->
                        <div class="flex items-center justify-end space-x-4">
                            <a href="{{ route('admin.plans.index') }}" 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">
                                Anulează
                            </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>
                                Salvează Modificările
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    @push('scripts')
    <script>
        function toggleApiSettings(enabled) {
            document.getElementById('apiSettings').style.display = enabled ? 'block' : 'none';
        }

        function toggleDynDnsSettings(enabled) {
            document.getElementById('dyndnsSettings').style.display = enabled ? 'block' : 'none';
        }

        function toggleCloudflareSettings(enabled) {
            document.getElementById('cloudflareSettings').style.display = enabled ? 'block' : 'none';
        }
    </script>
    @endpush
</x-admin-layout>

