@extends('layouts.admin')

@section('title', __('admin.registrations.title'))

@section('subtitle', $event->title)

@section('content')
<div class="d-flex justify-content-between align-items-center mb-4 flex-wrap gap-2">
    <form method="GET" class="d-flex gap-2">
        <select name="status" class="form-select">
            <option value="">{{ __('admin.registrations.filter_status') }}</option>
            @foreach(\App\Enums\RegistrationStatus::cases() as $status)
                <option value="{{ $status->value }}" @selected(request('status') === $status->value)>{{ $status->label() }}</option>
            @endforeach
        </select>
        <button class="btn-arena btn-ghost">{{ __('admin.actions.filter') }}</button>
    </form>
    <a href="{{ route('admin.events.registrations.export', $event) }}" class="btn-arena btn-primary">{{ __('admin.actions.export') }}</a>
</div>

<div class="card-arena overflow-hidden">
    <div class="table-responsive">
        <table class="table table-dark table-hover mb-0 align-middle">
            <thead>
                <tr>
                    <th>Participant</th>
                    <th>Status</th>
                    <th>Payment</th>
                    <th>Registered</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse($registrations as $registration)
                    <tr>
                        <td>
                            <div class="fw-600">{{ $registration->contact_name }}</div>
                            <div class="fs-xs text-muted">{{ $registration->user?->email }}</div>
                        </td>
                        <td>{{ $registration->status->label() }}</td>
                        <td>{{ $registration->payment_status->label() }}</td>
                        <td>{{ $registration->registered_at?->format('M j, Y') }}</td>
                        <td class="text-end">
                            @if($registration->status === \App\Enums\RegistrationStatus::Pending)
                                <form method="POST" action="{{ route('admin.events.registrations.approve', [$event, $registration]) }}" class="d-inline">
                                    @csrf
                                    <button class="btn-arena btn-primary btn-sm">{{ __('admin.actions.approve') }}</button>
                                </form>
                                <form method="POST" action="{{ route('admin.events.registrations.reject', [$event, $registration]) }}" class="d-inline">
                                    @csrf
                                    <input type="hidden" name="reason" value="Rejected by admin">
                                    <button class="btn-arena btn-danger btn-sm">{{ __('admin.actions.reject') }}</button>
                                </form>
                            @endif
                            @if($registration->status === \App\Enums\RegistrationStatus::Waitlisted)
                                <form method="POST" action="{{ route('admin.events.registrations.promote', [$event, $registration]) }}" class="d-inline">
                                    @csrf
                                    <button class="btn-arena btn-ghost btn-sm">{{ __('admin.actions.promote_waitlist') }}</button>
                                </form>
                            @endif
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="text-center py-5 text-muted">{{ __('admin.empty.no_registrations') }}</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>

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