@extends('super-admin.layout')

@section('title', 'Campus Sponsorship')

@section('content')
<div class="pg-head">
    <div>
        <h1>Campus Sponsorship</h1>
        <p>Review university applications, approve sponsored CAMPUS events, and monitor {{ config('mexco.campus.default_retention_days') }}-day data retention.</p>
    </div>
    <a href="{{ route('mexco.super.campus.create') }}" class="btn-purple">+ Record application</a>
</div>

<div class="stat-row">
    <div class="card stat-card">
        <div class="stat-label">Pending review</div>
        <div class="stat-num">{{ $stats['pending'] }}</div>
    </div>
    <div class="card stat-card">
        <div class="stat-label">Active / approved</div>
        <div class="stat-num">{{ $stats['approved'] }}</div>
    </div>
    <div class="card stat-card">
        <div class="stat-label">Expiring (14 days)</div>
        <div class="stat-num" style="color:var(--mexco-accent)">{{ $stats['expiring_soon'] }}</div>
    </div>
    <div class="card stat-card">
        <div class="stat-label">Total in-kind value</div>
        <div class="stat-num" style="font-size:1.25rem">MYR {{ number_format($stats['total_sponsorship_value_cents'] / 100, 0) }}</div>
    </div>
</div>

<div class="card section-card" style="margin-bottom:1rem">
    <form method="GET" class="d-flex flex-wrap gap-2 align-items-center">
        <input type="search" name="q" class="form-input" style="max-width:280px" placeholder="Reference, institution, event…" value="{{ $q }}">
        <select name="status" class="form-input" style="max-width:200px">
            <option value="">All statuses</option>
            <option value="pending" @selected($status === 'pending')>Needs approval</option>
            @foreach(\App\Models\MexcoCampusApplication::statuses() as $code => $label)
                <option value="{{ $code }}" @selected($status === $code)>{{ $label }}</option>
            @endforeach
        </select>
        <button type="submit" class="btn-outline btn-sm">Filter</button>
    </form>
</div>

<div class="card">
    <div class="tbl-wrap">
        <table class="data-tbl">
            <thead>
                <tr>
                    <th>Reference</th>
                    <th>Institution / event</th>
                    <th>Contact</th>
                    <th>Event date</th>
                    <th>Sponsorship</th>
                    <th>Status</th>
                    <th style="text-align:right">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($applications as $app)
                    @php
                        $pill = match($app->status) {
                            'submitted', 'under_review' => '',
                            'rejected', 'deleted' => 'muted',
                            'active', 'event_created' => 'success',
                            'retention' => 'accent',
                            default => '',
                        };
                    @endphp
                    <tr>
                        <td class="mono">{{ $app->reference_no }}</td>
                        <td>
                            <div class="cell-name">{{ $app->institution }}</div>
                            <div class="cell-sub">{{ $app->event_name }}</div>
                            @if($app->event_id)
                                <div class="cell-sub mono">{{ $app->event_id }}</div>
                            @endif
                        </td>
                        <td class="cell-sub">
                            {{ $app->contact_person }}<br>
                            {{ $app->contact_email }}
                        </td>
                        <td>{{ $app->event_date?->format('d M Y') ?? '-' }}</td>
                        <td>{{ $app->formattedSponsorshipValue() }}</td>
                        <td><span class="status-pill {{ $pill }}">{{ $app->statusLabel() }}</span></td>
                        <td>
                            <div class="action-group">
                                <a href="{{ route('mexco.super.campus.show', $app) }}" class="btn-outline btn-sm">View</a>
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="7" class="text-center cell-sub py-4">No campus applications yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
