@extends('layouts.seller')

@section('title', 'Manage FAQs')

@section('content')
@section('content')
<div class="page-header">
    <div>
        <h4 class="page-title">Frequently Asked Questions</h4>
        <p class="text-muted mb-0">Add common questions and answers for your customers</p>
    </div>
    <a href="{{ route('seller.microsite.settings') }}" class="btn btn-light border shadow-sm">
        <i class="bi bi-arrow-left me-1"></i> Back to Settings
    </a>
</div>

@if(session('success'))
    <div class="alert alert-success alert-dismissible fade show border-0 shadow-sm" role="alert">
        <i class="bi bi-check-circle-fill me-2"></i>{{ session('success') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
@endif

<div class="row g-4">
    <!-- Add New -->
    <div class="col-lg-4">
        <div class="card border-0 shadow-sm sticky-top" style="top: 100px;">
            <div class="card-header bg-white py-3 border-bottom">
                <h5 class="mb-0 fw-bold text-success"><i class="bi bi-plus-circle me-2"></i>Add FAQ</h5>
            </div>
            <div class="card-body p-4">
                <form action="{{ route('seller.microsite.faqs.store') }}" method="POST">
                    @csrf
                    <div class="mb-3">
                        <label class="form-label fw-bold">Question <span class="text-danger">*</span></label>
                        <input type="text" name="question" class="form-control" required maxlength="255"
                               placeholder="e.g., What is your minimum order quantity?">
                    </div>
                    <div class="mb-4">
                        <label class="form-label fw-bold">Answer <span class="text-danger">*</span></label>
                        <textarea name="answer" class="form-control" rows="5" required maxlength="1000"
                                  placeholder="Provide a detailed answer..."></textarea>
                    </div>
                    <button type="submit" class="btn btn-primary-gradient w-100 py-2 fw-bold">
                        <i class="bi bi-plus-lg me-1"></i> Add FAQ
                    </button>
                </form>
            </div>
        </div>
    </div>

    <!-- List -->
    <div class="col-lg-8">
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-white py-3 border-bottom d-flex justify-content-between align-items-center">
                <h5 class="mb-0 fw-bold text-primary"><i class="bi bi-list-ul me-2"></i>All FAQs <span class="badge bg-primary-subtle text-primary rounded-pill ms-2">{{ $faqs->count() }}</span></h5>
            </div>
            <div class="card-body p-0">
                @forelse($faqs as $faq)
                    <div class="p-4 border-bottom hover-bg transition-all">
                        <div class="d-flex justify-content-between align-items-start mb-3">
                            <h6 class="fw-bold mb-0 d-flex align-items-start text-dark">
                                <span class="badge bg-primary-subtle text-primary me-3 rounded-pill px-3">Q</span>
                                <span class="mt-1">{{ $faq->question }}</span>
                            </h6>
                            <form action="{{ route('seller.microsite.faqs.destroy', $faq) }}" method="POST" 
                                  onsubmit="return confirm('Delete this FAQ?')">
                                @csrf @method('DELETE')
                                <button type="submit" class="btn btn-sm btn-outline-danger border-0" title="Delete"><i class="bi bi-trash"></i></button>
                            </form>
                        </div>
                        <div class="d-flex align-items-start ps-2">
                            <span class="badge bg-success-subtle text-success me-3 rounded-pill px-3">A</span>
                            <p class="mb-0 text-muted mt-1">{{ $faq->answer }}</p>
                        </div>
                    </div>
                @empty
                    <div class="text-center py-5">
                        <div class="text-muted opacity-50 mb-3">
                            <i class="bi bi-question-circle display-4"></i>
                        </div>
                        <h5 class="fw-bold text-muted">No FAQs yet</h5>
                        <p class="text-muted mb-0">Add your first question to help customers.</p>
                    </div>
                @endforelse
            </div>
        </div>
    </div>
</div>

<style>
    .hover-bg:hover { background-color: #f8f9fa; }
    .transition-all { transition: all 0.2s ease; }
</style>
@endsection
