@extends('layouts.admin')

@section('title', $faq->exists ? 'Edit FAQ' : 'Add FAQ')

@section('content')
<div class="container mx-auto max-w-3xl">
    <div class="flex items-center gap-4 mb-6">
        <a href="{{ route('admin.faqs.index') }}" class="w-10 h-10 rounded-full bg-white border border-slate-200 flex items-center justify-center text-slate-500 hover:text-brand-primary hover:border-brand-primary transition shadow-sm">
            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg>
        </a>
        <h1 class="text-2xl font-bold text-slate-900">{{ $faq->exists ? 'Edit' : 'Add' }} FAQ</h1>
    </div>

    <div class="bg-white shadow-sm rounded-xl border border-slate-100 p-8">
        <form action="{{ $faq->exists ? route('admin.faqs.update', $faq) : route('admin.faqs.store') }}" method="POST">
            @csrf
            @if($faq->exists)
                @method('PUT')
            @endif

            <div class="space-y-6">
                <!-- Question -->
                <div>
                    <label class="block text-slate-700 text-sm font-bold mb-2">Question <span class="text-red-500">*</span></label>
                    <input class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-lg focus:ring-2 focus:ring-brand-primary focus:border-transparent outline-none transition" 
                           name="question" type="text" placeholder="e.g. How does support work?" required
                           value="{{ old('question', $faq->question) }}">
                </div>

                <!-- Answer -->
                <div>
                    <label class="block text-slate-700 text-sm font-bold mb-2">Answer Content <span class="text-red-500">*</span></label>
                    <textarea class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-lg focus:ring-2 focus:ring-brand-primary focus:border-transparent outline-none transition" 
                              name="answer" rows="5" placeholder="Detailed answer..." required>{{ old('answer', $faq->answer) }}</textarea>
                </div>

                <!-- Sort & Visibility -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div>
                        <label class="block text-slate-700 text-sm font-bold mb-2">Sort Order</label>
                        <input class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-lg focus:ring-2 focus:ring-brand-primary focus:border-transparent outline-none transition" 
                               name="sort_order" type="number" min="0" required
                               value="{{ old('sort_order', $faq->sort_order ?? 0) }}">
                        <p class="text-xs text-slate-500 mt-2">Lower numbers appear first on the site.</p>
                    </div>
                    
                    <div class="flex flex-col justify-center pt-2">
                        <label class="flex items-center cursor-pointer group">
                            <div class="relative">
                                <input type="checkbox" name="is_active" class="sr-only" {{ old('is_active', $faq->exists ? $faq->is_active : true) ? 'checked' : '' }}>
                                <div class="block bg-slate-200 w-14 h-8 rounded-full transition-colors group-hover:bg-slate-300"></div>
                                <div class="dot absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition-transform shadow-sm"></div>
                            </div>
                            <div class="ml-3 font-bold text-slate-700">Make Active/Visible</div>
                        </label>
                        <style>
                            input:checked ~ .block { background-color: #38bdf8; }
                            input:checked ~ .dot { transform: translateX(100%); }
                        </style>
                    </div>
                </div>
            </div>

            <div class="mt-8 pt-6 border-t border-slate-100 flex items-center justify-end gap-3">
                <a href="{{ route('admin.faqs.index') }}" class="px-6 py-3 font-bold text-sm text-slate-500 hover:text-slate-800 hover:bg-slate-100 rounded-lg transition">Cancel</a>
                <button type="submit" class="bg-brand-primary hover:bg-brand-accent text-white font-bold py-3 px-8 rounded-lg shadow-lg shadow-brand-primary/30 transition flex items-center gap-2">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
                    {{ $faq->exists ? 'Update FAQ' : 'Save FAQ' }}
                </button>
            </div>
        </form>
    </div>
</div>
@endsection
