<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-question-circle mr-2 text-indigo-500"></i>Centru de Ajutor
            </h2>
            <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
                Găsește răspunsuri la întrebările tale despre Panel DNS
            </p>
        </div>
    </x-slot>

    <div class="py-6">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-6">

            {{-- Căutare --}}
            <div class="bg-gradient-to-r from-indigo-600 to-purple-600 rounded-xl p-8 text-center">
                <h1 class="text-2xl font-bold text-white mb-2">Cum te putem ajuta?</h1>
                <p class="text-indigo-100 mb-6">Caută în documentație sau explorează categoriile de mai jos</p>
                <form action="{{ route('help.search') }}" method="GET" class="max-w-xl mx-auto">
                    <div class="relative">
                        <input type="text" name="q" placeholder="Caută articole, ghiduri, întrebări..."
                            class="w-full pl-12 pr-4 py-4 rounded-xl border-0 shadow-lg focus:ring-4 focus:ring-indigo-300 text-gray-900">
                        <i class="fas fa-search absolute left-4 top-1/2 -translate-y-1/2 text-gray-400"></i>
                        <button type="submit" class="absolute right-2 top-1/2 -translate-y-1/2 px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition">
                            Caută
                        </button>
                    </div>
                </form>
            </div>

            {{-- Categorii --}}
            <div>
                <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">Explorează Categoriile</h2>
                <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
                    @foreach($categories as $category)
                        @php
                            $colorClasses = match($category['color']) {
                                'blue' => 'from-blue-400 to-blue-600 group-hover:from-blue-500 group-hover:to-blue-700',
                                'green' => 'from-green-400 to-green-600 group-hover:from-green-500 group-hover:to-green-700',
                                'purple' => 'from-purple-400 to-purple-600 group-hover:from-purple-500 group-hover:to-purple-700',
                                'cyan' => 'from-cyan-400 to-cyan-600 group-hover:from-cyan-500 group-hover:to-cyan-700',
                                'orange' => 'from-orange-400 to-orange-600 group-hover:from-orange-500 group-hover:to-orange-700',
                                'red' => 'from-red-400 to-red-600 group-hover:from-red-500 group-hover:to-red-700',
                                'amber' => 'from-amber-400 to-amber-600 group-hover:from-amber-500 group-hover:to-amber-700',
                                'gray' => 'from-gray-400 to-gray-600 group-hover:from-gray-500 group-hover:to-gray-700',
                                default => 'from-gray-400 to-gray-600',
                            };
                        @endphp
                        <a href="{{ route('help.search', ['category' => $category['id']]) }}"
                           class="group bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 p-6 hover:shadow-lg transition">
                            <div class="w-14 h-14 rounded-xl bg-gradient-to-br {{ $colorClasses }} flex items-center justify-center mb-4 group-hover:scale-110 transition shadow-lg">
                                <i class="{{ $category['icon'] }} text-white text-xl"></i>
                            </div>
                            <h3 class="font-semibold text-gray-900 dark:text-white mb-1">{{ $category['name'] }}</h3>
                            <p class="text-sm text-gray-500 dark:text-gray-400 mb-2">{{ $category['description'] }}</p>
                            <span class="text-xs text-indigo-600 dark:text-indigo-400">{{ $category['articles_count'] }} articole</span>
                        </a>
                    @endforeach
                </div>
            </div>

            {{-- Articole Populare --}}
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 p-6">
                <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">
                    <i class="fas fa-fire text-orange-500 mr-2"></i>
                    Articole Populare
                </h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    @foreach($popularArticles as $article)
                        <a href="{{ route('help.show', $article['slug']) }}"
                           class="flex items-center gap-4 p-4 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700/50 transition group">
                            <div class="w-10 h-10 rounded-lg bg-indigo-100 dark:bg-indigo-900/50 flex items-center justify-center flex-shrink-0">
                                <i class="fas fa-file-alt text-indigo-600 dark:text-indigo-400"></i>
                            </div>
                            <div class="flex-1 min-w-0">
                                <h4 class="font-medium text-gray-900 dark:text-white group-hover:text-indigo-600 dark:group-hover:text-indigo-400 transition truncate">
                                    {{ $article['title'] }}
                                </h4>
                                <p class="text-sm text-gray-500 dark:text-gray-400">
                                    <i class="fas fa-eye mr-1"></i>{{ number_format($article['views']) }} vizualizări
                                </p>
                            </div>
                            <i class="fas fa-chevron-right text-gray-400 group-hover:text-indigo-600 transition"></i>
                        </a>
                    @endforeach
                </div>
            </div>

            {{-- Legături Rapide --}}
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                {{-- API Docs --}}
                <a href="{{ route('api-docs') }}" class="bg-gradient-to-r from-cyan-500 to-blue-600 rounded-xl p-6 text-white hover:shadow-lg transition group">
                    <div class="flex items-center gap-4">
                        <div class="w-12 h-12 rounded-xl bg-white/20 flex items-center justify-center">
                            <i class="fas fa-code text-xl"></i>
                        </div>
                        <div>
                            <h3 class="font-semibold">Documentație API</h3>
                            <p class="text-cyan-100 text-sm">Swagger/OpenAPI docs</p>
                        </div>
                        <i class="fas fa-external-link-alt ml-auto opacity-50 group-hover:opacity-100 transition"></i>
                    </div>
                </a>

                {{-- Contact Suport --}}
                <a href="mailto:support@gazduiredns.ro" class="bg-gradient-to-r from-green-500 to-emerald-600 rounded-xl p-6 text-white hover:shadow-lg transition group">
                    <div class="flex items-center gap-4">
                        <div class="w-12 h-12 rounded-xl bg-white/20 flex items-center justify-center">
                            <i class="fas fa-envelope text-xl"></i>
                        </div>
                        <div>
                            <h3 class="font-semibold">Contact Suport</h3>
                            <p class="text-green-100 text-sm">Trimite un email</p>
                        </div>
                        <i class="fas fa-external-link-alt ml-auto opacity-50 group-hover:opacity-100 transition"></i>
                    </div>
                </a>

                {{-- Status Sistem --}}
                <div class="bg-gradient-to-r from-purple-500 to-pink-600 rounded-xl p-6 text-white">
                    <div class="flex items-center gap-4">
                        <div class="w-12 h-12 rounded-xl bg-white/20 flex items-center justify-center">
                            <i class="fas fa-server text-xl"></i>
                        </div>
                        <div>
                            <h3 class="font-semibold">Status Sistem</h3>
                            <p class="text-purple-100 text-sm flex items-center gap-2">
                                <span class="w-2 h-2 bg-green-400 rounded-full animate-pulse"></span>
                                Toate sistemele funcționează
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            {{-- FAQ Rapid --}}
            <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 p-6">
                <h2 class="text-xl font-semibold text-gray-900 dark:text-white mb-4">
                    <i class="fas fa-comments text-blue-500 mr-2"></i>
                    Întrebări Frecvente
                </h2>
                <div class="space-y-4" x-data="{ open: null }">
                    @php
                        $faqs = [
                            ['q' => 'Cât durează propagarea DNS?', 'a' => 'Propagarea DNS poate dura între 5 minute și 48 de ore, în funcție de TTL-ul setat pentru înregistrările tale. Pentru schimbări rapide, setează un TTL scăzut (300-600 secunde) înainte de a face modificări.'],
                            ['q' => 'Cum activez DNSSEC pentru zona mea?', 'a' => 'Accesează pagina zonei DNS, apoi click pe "DNSSEC" și "Activează". După activare, copiază înregistrarea DS generată și adaug-o în panelul registrar-ului domeniului tău.'],
                            ['q' => 'Ce tipuri de înregistrări DNS suportați?', 'a' => 'Suportăm toate tipurile majore: A, AAAA, CNAME, MX, TXT, NS, SRV, CAA, PTR și multe altele. Disponibilitatea poate varia în funcție de planul tău.'],
                            ['q' => 'Cum folosesc Dynamic DNS?', 'a' => 'Din meniul lateral, accesează "DynDNS", creează un client nou, apoi descarcă scriptul pentru sistemul tău (Windows, Linux, macOS). Scriptul va actualiza automat IP-ul când se schimbă.'],
                        ];
                    @endphp
                    @foreach($faqs as $index => $faq)
                        <div class="border border-gray-200 dark:border-gray-700 rounded-lg overflow-hidden">
                            <button @click="open = open === {{ $index }} ? null : {{ $index }}"
                                    class="w-full flex items-center justify-between p-4 text-left hover:bg-gray-50 dark:hover:bg-gray-700/50 transition">
                                <span class="font-medium text-gray-900 dark:text-white">{{ $faq['q'] }}</span>
                                <i class="fas fa-chevron-down text-gray-400 transition-transform" :class="{ 'rotate-180': open === {{ $index }} }"></i>
                            </button>
                            <div x-show="open === {{ $index }}" x-collapse class="px-4 pb-4 text-gray-600 dark:text-gray-400">
                                {{ $faq['a'] }}
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
