@extends('layouts.app')

@section('title', 'Registration')

@section('content')
<div class="container-fluid px-4 py-4">
    <div class="mb-4">
        <h1 class="display-md text-white mb-1">{{ $registration->event->title }}</h1>
        <p class="text-muted mb-0">Registration #{{ $registration->public_id }}</p>
    </div>

    @if (session('status'))
        <div class="alert alert-success">{{ session('status') }}</div>
    @endif

    <div class="row g-4">
        <div class="col-lg-8">
            <div class="card-arena p-4 mb-4">
                <div class="row g-3">
                    <div class="col-md-6">
                        <div class="text-muted fs-xs">Status</div>
                        <div class="text-white fw-600">{{ $registration->status->label() }}</div>
                    </div>
                    <div class="col-md-6">
                        <div class="text-muted fs-xs">Payment</div>
                        <div class="text-white fw-600">{{ $registration->payment_status->label() }}</div>
                    </div>
                    <div class="col-md-6">
                        <div class="text-muted fs-xs">Registered</div>
                        <div class="text-white">{{ $registration->registered_at?->format('M d, Y H:i') }}</div>
                    </div>
                    @if($registration->waitlist_position)
                        <div class="col-md-6">
                            <div class="text-muted fs-xs">{{ __('events.waitlist.position') }}</div>
                            <div class="text-white">#{{ $registration->waitlist_position }}</div>
                        </div>
                    @endif
                </div>
            </div>

            <div class="card-arena p-4">
                <h2 class="text-white fs-5 mb-3">Status Timeline</h2>
                <ul class="list-unstyled mb-0">
                    @foreach($registration->statusEvents as $event)
                        <li class="mb-3 pb-3 border-bottom border-secondary-subtle">
                            <div class="text-white fs-sm">{{ $event->new_status->label() }}</div>
                            <div class="text-muted fs-xs">{{ $event->created_at?->format('M d, Y H:i') }}</div>
                            @if($event->reason)
                                <div class="text-muted fs-xs mt-1">{{ $event->reason }}</div>
                            @endif
                        </li>
                    @endforeach
                </ul>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card-arena p-4 mb-3">
                <h3 class="text-white fs-6 mb-3">Actions</h3>
                @if($registration->status->isActive() && $registration->user_id === auth()->id())
                    <form method="POST" action="{{ route('registrations.cancel', $registration) }}" onsubmit="return confirm('Cancel registration?');">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn-arena btn-sm btn-outline-light w-100 mb-2">{{ __('events.register.cancel') }}</button>
                    </form>
                @endif
                @if(in_array($registration->status, [\App\Enums\RegistrationStatus::PendingPayment, \App\Enums\RegistrationStatus::PaymentReview], true))
                    <a href="{{ route('registrations.payment-proof.create', $registration) }}" class="btn-arena btn-sm btn-primary w-100">{{ __('events.payment.submit_proof') }}</a>
                @endif
                <a href="{{ route('my-events.index') }}" class="btn-arena btn-sm btn-ghost w-100 mt-2">My Events</a>
            </div>

            @if($registration->paymentProofs->isNotEmpty())
                <div class="card-arena p-4">
                    <h3 class="text-white fs-6 mb-3">Payment Proofs</h3>
                    @foreach($registration->paymentProofs as $proof)
                        <div class="mb-2">
                            <span class="badge-arena badge-muted">{{ $proof->review_status->label() }}</span>
                            <a href="{{ route('payment-proofs.show', $proof) }}" class="d-block fs-xs mt-1" style="color:var(--arena-accent);">Download proof</a>
                        </div>
                    @endforeach
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
