<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <div>
                <h2 class="font-semibold text-lg text-gray-800 dark:text-gray-200 leading-tight">
                    <i class="fas fa-plus-circle mr-2 text-orange-500"></i>Adaugă Credential Cloudflare
                </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('cloudflare.index') }}" class="text-blue-600 dark:text-blue-400 hover:underline">Cloudflare</a>
                    <span class="mx-2">/</span>
                    <span>Adaugă Credential</span>
                </p>
            </div>
            <a href="{{ route('cloudflare.index') }}" class="inline-flex items-center justify-center w-10 h-10 text-gray-600 dark:text-gray-400 hover:text-indigo-600 dark:hover:text-indigo-400 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition" title="Înapoi">
                <i class="fas fa-arrow-left"></i>
            </a>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="px-6 lg:px-8">
            <div class="max-w-2xl mx-auto">
                <div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6">
                        <form action="{{ route('cloudflare.credentials.store') }}" method="POST">
                            @csrf

                            <!-- Name -->
                            <div class="mb-6">
                                <label for="name" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    Nume Credential
                                </label>
                                <input type="text" name="name" id="name" value="{{ old('name') }}"
                                    class="w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white shadow-sm focus:border-orange-500 focus:ring-orange-500"
                                    placeholder="Ex: Contul meu principal" required>
                                @error('name')
                                    <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- API Token -->
                            <div class="mb-6">
                                <label for="api_token" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                    API Token Cloudflare
                                </label>
                                <input type="password" name="api_token" id="api_token"
                                    class="w-full rounded-md border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-white shadow-sm focus:border-orange-500 focus:ring-orange-500"
                                    placeholder="Introdu API Token-ul tău Cloudflare" required>
                                <button type="button" onclick="togglePassword('api_token')" class="mt-1 text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
                                    <i class="fas fa-eye"></i> Arată/Ascunde
                                </button>
                                @error('api_token')
                                    <p class="mt-1 text-sm text-red-600 dark:text-red-400">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- Info Box -->
                            <div class="mb-6 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg p-4">
                                <h4 class="font-semibold text-blue-800 dark:text-blue-300 mb-2">
                                    <i class="fas fa-info-circle mr-2"></i>Cum obții un API Token?
                                </h4>
                                <ol class="text-sm text-blue-700 dark:text-blue-400 space-y-2 list-decimal list-inside">
                                    <li>Accesează <a href="https://dash.cloudflare.com/profile/api-tokens" target="_blank" class="underline hover:no-underline">Cloudflare Dashboard → API Tokens</a></li>
                                    <li>Click pe "Create Token"</li>
                                    <li>Folosește template-ul "Edit zone DNS" sau creează unul custom</li>
                                    <li>Permisiuni minime necesare:
                                        <ul class="ml-4 mt-1 list-disc list-inside">
                                            <li><strong>Zone - DNS - Edit</strong></li>
                                            <li><strong>Zone - Zone - Read</strong></li>
                                        </ul>
                                    </li>
                                    <li>Selectează zonele pentru care vrei să permiți acces</li>
                                    <li>Copiază token-ul generat și lipește-l aici</li>
                                </ol>
                            </div>

                            <!-- Warning -->
                            <div class="mb-6 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-lg p-4">
                                <p class="text-sm text-yellow-700 dark:text-yellow-400">
                                    <i class="fas fa-exclamation-triangle mr-2"></i>
                                    <strong>Important:</strong> Token-ul va fi criptat și stocat în siguranță. Nu-l vei putea vizualiza după salvare.
                                </p>
                            </div>

                            <!-- Submit -->
                            <div class="flex justify-end gap-3">
                                <a href="{{ route('cloudflare.index') }}" class="px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition">
                                    Anulează
                                </a>
                                <button type="submit" class="px-4 py-2 bg-orange-600 hover:bg-orange-700 text-white rounded-lg transition">
                                    <i class="fas fa-save mr-2"></i>Salvează Credential
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function togglePassword(fieldId) {
            const field = document.getElementById(fieldId);
            field.type = field.type === 'password' ? 'text' : 'password';
        }
    </script>
</x-app-layout>
