@extends('super-admin.layout')

@section('title', 'Admin users')

@section('content')
<div class="pg-head">
    <div>
        <h1>Admin users</h1>
        <p>Super Admin accounts for {{ config('mexco.apps.super.name') }}.</p>
    </div>
    <a href="{{ route('mexco.super.admins.create') }}" class="btn-purple">+ Add admin</a>
</div>

<div class="card">
    <div class="tbl-wrap">
        <table class="data-tbl">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Status</th>
                    <th>Last login</th>
                    <th style="text-align:right">Actions</th>
                </tr>
            </thead>
            <tbody>
                @forelse($admins as $admin)
                    <tr>
                        <td class="cell-name">{{ $admin->name }}</td>
                        <td>{{ $admin->email }}</td>
                        <td>
                            <span class="status-pill {{ $admin->isActive() ? 'success' : 'muted' }}">
                                {{ $admin->isActive() ? 'Active' : 'Suspended' }}
                            </span>
                        </td>
                        <td class="cell-sub">{{ $admin->last_login_at?->format('d M Y, H:i') ?? 'Never' }}</td>
                        <td>
                            <div class="action-group">
                                <a href="{{ route('mexco.super.admins.edit', $admin) }}" class="btn-outline btn-sm">Edit</a>
                                @if($admin->isActive() && $admin->id !== session('meetup_super_admin_id'))
                                    <form method="POST" action="{{ route('mexco.super.admins.suspend', $admin) }}" style="display:inline">
                                        @csrf
                                        <button type="submit" class="btn-danger btn-sm" onclick="return confirm('Suspend this admin?')">Suspend</button>
                                    </form>
                                @elseif(! $admin->isActive())
                                    <form method="POST" action="{{ route('mexco.super.admins.activate', $admin) }}" style="display:inline">
                                        @csrf
                                        <button type="submit" class="btn-outline btn-sm">Activate</button>
                                    </form>
                                @endif
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="text-center cell-sub py-4">No admin users.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection
