@extends('admin.layout')

@section('title', 'Administradores - Admin OnAPB')

@section('content')
<div class="mb-5 d-flex justify-content-between align-items-end">
    <div>
        <span class="text-primary fw-bold text-uppercase tracking-widest d-block mb-2">Control de Accesos</span>
        <h1 class="display-4 fw-bold font-header mb-0">Administradores<span class="text-primary">.</span></h1>
    </div>
    <a href="{{ route('admin.usuarios.create') }}" class="btn-admin-primary">
        <i class="bi bi-person-plus-fill me-2"></i> NUEVO USUARIO
    </a>
</div>

<div class="admin-card">
    @if($usuarios->isEmpty())
        <div class="text-center py-5">
            <i class="bi bi-person-lock text-muted mb-3" style="font-size: 3rem;"></i>
            <p class="fs-5 text-muted">No hay otros administradores registrados.</p>
        </div>
    @else
        <div class="table-responsive">
            <table class="kinetic-table">
                <thead>
                    <tr>
                        <th>Usuario</th>
                        <th>Nivel de Acceso</th>
                        <th>Club Responsable</th>
                        <th class="text-end">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($usuarios as $user)
                    <tr>
                        <td>
                            <span class="fw-bold fs-5">{{ $user->username }}</span>
                        </td>
                        <td>
                            @if($user->role == 1)
                                <span class="badge bg-dark text-white text-uppercase px-2 py-1"><i class="bi bi-shield-lock-fill me-1"></i> Súper Admin</span>
                            @else
                                <span class="badge bg-light text-dark border text-uppercase px-2 py-1"><i class="bi bi-shield-check me-1"></i> Admin Club</span>
                            @endif
                        </td>
                        <td>
                            <span class="fw-bold">{{ $user->club->nombre ?? 'SISTEMA INTEGRAL' }}</span>
                        </td>
                        <td class="text-end">
                            <a href="{{ route('admin.usuarios.edit', $user->id) }}" class="btn btn-sm btn-light border me-1">
                                <i class="bi bi-pencil"></i>
                            </a>
                            @if($user->id != session('admin_id'))
                            <form action="{{ route('admin.usuarios.destroy', $user->id) }}" method="POST" class="d-inline delete-form confirm-submit" data-confirm-text="¿Eliminar este administrador?">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="btn btn-sm btn-outline-danger">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </form>
                            @endif
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        <div class="mt-4 d-flex justify-content-center">
            {{ $usuarios->links('pagination::bootstrap-5') }}
        </div>
    @endif
</div>
@endsection
