@extends('layouts.epelcon')
@section('title', 'Guest Reviews')

@section('content')
<div>
    <div class="mb-5">
        <h1 class="text-xl font-extrabold text-slate-900 lg:text-2xl">Guest Reviews</h1>
        <p class="text-sm text-slate-500">Moderate guest feedback — approved reviews appear on the public site.</p>
    </div>

    <div class="mb-5 grid grid-cols-2 gap-3 lg:grid-cols-4">
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Pending</p><p class="mt-1 text-2xl font-extrabold text-amber-600">{{ $counts['pending'] }}</p></div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Approved</p><p class="mt-1 text-2xl font-extrabold text-emerald-600">{{ $counts['approved'] }}</p></div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Rejected</p><p class="mt-1 text-2xl font-extrabold text-rose-600">{{ $counts['rejected'] }}</p></div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Avg rating (approved)</p><p class="mt-1 text-2xl font-extrabold text-slate-900">{{ number_format($counts['avg'], 1) }} <span class="text-amber-400">★</span></p></div>
    </div>

    <div class="no-scrollbar mb-4 flex gap-2 overflow-x-auto">
        @foreach (['' => 'All', 'pending' => 'Pending', 'approved' => 'Approved', 'rejected' => 'Rejected'] as $value => $label)
            <a href="{{ route('epelcon.reviews.index', array_filter(['status' => $value])) }}"
               class="shrink-0 rounded-full px-4 py-2 text-xs font-bold {{ request('status', '') === $value ? 'bg-slate-900 text-white' : 'bg-white text-slate-600 ring-1 ring-slate-200' }}">{{ $label }}</a>
        @endforeach
    </div>

    <div class="space-y-3">
        @forelse ($reviews as $review)
            @php $badge = ['pending' => 'amber', 'approved' => 'emerald', 'rejected' => 'rose'][$review->status] ?? 'slate'; @endphp
            <div class="rounded-2xl bg-white p-5 shadow-sm ring-1 ring-slate-200">
                <div class="flex flex-wrap items-start justify-between gap-3">
                    <div class="min-w-0">
                        <div class="flex items-center gap-2">
                            <span class="text-base tracking-wide">
                                @for ($i = 1; $i <= 5; $i++)<span class="{{ $i <= $review->rating ? 'text-amber-400' : 'text-slate-200' }}">★</span>@endfor
                            </span>
                            <span class="rounded-full bg-{{ $badge }}-100 px-2.5 py-1 text-[10px] font-bold uppercase text-{{ $badge }}-700">{{ $review->status }}</span>
                        </div>
                        <p class="mt-1.5 font-bold text-slate-900">{{ $review->title ?: 'No title' }}</p>
                        <p class="text-xs text-slate-400">
                            {{ $review->customer_name }}
                            @if ($review->booking) · <span class="font-mono">{{ $review->booking->code }}</span>@endif
                            · {{ $review->created_at->format('j M Y, g:ia') }}
                        </p>
                    </div>
                    <div class="flex shrink-0 gap-1.5">
                        @if ($review->status !== 'approved')
                            <form method="POST" action="{{ route('epelcon.reviews.status', $review) }}">@csrf<input type="hidden" name="status" value="approved">
                                <button class="rounded-lg bg-emerald-50 px-3 py-1.5 text-[11px] font-bold text-emerald-700 hover:bg-emerald-100">Approve</button></form>
                        @endif
                        @if ($review->status !== 'rejected')
                            <form method="POST" action="{{ route('epelcon.reviews.status', $review) }}">@csrf<input type="hidden" name="status" value="rejected">
                                <button class="rounded-lg bg-rose-50 px-3 py-1.5 text-[11px] font-bold text-rose-600 hover:bg-rose-100">Reject</button></form>
                        @endif
                        @if ($review->status !== 'pending')
                            <form method="POST" action="{{ route('epelcon.reviews.status', $review) }}">@csrf<input type="hidden" name="status" value="pending">
                                <button class="rounded-lg bg-slate-100 px-3 py-1.5 text-[11px] font-bold text-slate-600 hover:bg-slate-200">Reset</button></form>
                        @endif
                    </div>
                </div>
                @if ($review->comment)
                    <p class="mt-3 rounded-xl bg-slate-50 px-4 py-3 text-sm leading-relaxed text-slate-600">{{ $review->comment }}</p>
                @endif
            </div>
        @empty
            <div class="rounded-2xl bg-white px-4 py-12 text-center text-slate-400 shadow-sm ring-1 ring-slate-200">No reviews found.</div>
        @endforelse
    </div>

    <div class="mt-5">{{ $reviews->links() }}</div>
</div>
@endsection
