@extends('super-admin.layout')

@section('title', 'Organiser access')

@section('content')
<div class="pg-head">
    <div>
        <h1>Organiser access</h1>
        <p>Create organiser accounts and assign them to organisations and events.</p>
    </div>
    <a href="{{ route('mexco.super.organisers.create') }}" class="btn-purple">+ Create organiser</a>
</div>

<div class="card section-card" style="margin-bottom:1rem">
    <form method="GET">
        <input type="search" name="q" class="form-input" style="max-width:280px" placeholder="Search name or email…" value="{{ $q }}">
    </form>
</div>

<div class="card">
    <div class="tbl-wrap">
        <table class="data-tbl">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Organisation</th>
                    <th>Role</th>
                    <th>Events</th>
                    <th>Status</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse($organisers as $user)
                    <tr>
                        <td>
                            <div class="cell-name">{{ $user->name }}</div>
                            <div class="cell-sub">{{ $user->email }}</div>
                        </td>
                        <td>{{ $user->organisation?->name ?? '-' }}</td>
                        <td>{{ \App\Models\MexcoOrganisationUser::roles()[$user->role] ?? $user->role }}</td>
                        <td>{{ $user->isOrganisationAdmin() ? 'All org events' : $user->assignedEvents->count() }}</td>
                        <td><span class="status-pill {{ $user->status === 'active' ? 'success' : 'muted' }}">{{ ucfirst($user->status) }}</span></td>
                        <td><a href="{{ route('mexco.super.organisers.edit', $user) }}" class="btn-outline btn-sm">Edit</a></td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="text-center cell-sub py-4">No organiser accounts yet.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
