@extends('admin.layout')

@section('title', 'Pases - 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">Mercado de Jugadores</span>
        <h1 class="display-4 fw-bold font-header mb-0">Solicitudes de <span class="text-primary">Pase.</span></h1>
    </div>
    <a href="{{ route('admin.pases.create') }}" class="btn-admin-primary">
        <i class="bi bi-plus-lg me-2"></i> SOLICITAR PASE
    </a>
</div>

<div class="admin-card">
    @if($pases->isEmpty())
        <div class="text-center py-5">
            <i class="bi bi-person-badge text-muted mb-3" style="font-size: 3rem;"></i>
            <p class="fs-5 text-muted">No hay solicitudes de pase registradas.</p>
        </div>
    @else
        <div class="table-responsive">
            <table class="kinetic-table">
                <thead>
                    <tr>
                        <th>Jugador</th>
                        <th>Origen</th>
                        <th>Destino</th>
                        <th>Estado</th>
                        <th>Fecha Solicitud</th>
                        @if(session('admin_role') == 1)
                            <th class="text-end">Acciones</th>
                        @endif
                    </tr>
                </thead>
                <tbody>
                    @foreach($pases as $pase)
                    <tr>
                        <td>
                            <span class="fw-bold d-block">{{ $pase->jugador->apellido ?? '—' }}, {{ $pase->jugador->nombre ?? '—' }}</span>
                            <span class="small text-muted text-uppercase">DNI: {{ $pase->jugador->documento ?? '—' }}</span>
                        </td>
                        <td><span class="fw-bold">{{ $pase->clubOrigen->nombre ?? 'Libre' }}</span></td>
                        <td><span class="fw-bold text-primary">{{ $pase->clubDestino->nombre ?? '—' }}</span></td>
                        <td>
                            @if($pase->estado === 'Pendiente')
                                <span class="badge bg-warning text-dark text-uppercase px-2" style="font-size: 0.65rem;"><i class="bi bi-hourglass-split"></i> Pendiente</span>
                            @elseif($pase->estado === 'Aprobado')
                                <span class="badge bg-success text-uppercase px-2" style="font-size: 0.65rem;"><i class="bi bi-check-circle"></i> Aprobado</span>
                            @else
                                <span class="badge bg-danger text-uppercase px-2" style="font-size: 0.65rem;"><i class="bi bi-x-circle"></i> Rechazado</span>
                            @endif
                        </td>
                        <td><span class="small fw-bold text-muted">{{ $pase->created_at->format('d/m/Y') }}</span></td>
                        @if(session('admin_role') == 1)
                            <td class="text-end">
                                @if($pase->estado === 'Pendiente')
                                    <div class="d-flex justify-content-end gap-2">
                                        <form action="{{ route('admin.pases.aprobar', $pase->id_pase) }}" method="POST" class="confirm-submit" data-confirm-text="¿Aprobar este pase?">
                                            @csrf @method('PUT')
                                            <button type="submit" class="btn btn-sm btn-dark fw-bold text-uppercase">Aprobar</button>
                                        </form>
                                        <form action="{{ route('admin.pases.rechazar', $pase->id_pase) }}" method="POST" class="confirm-submit" data-confirm-text="¿Rechazar este pase?">
                                            @csrf @method('PUT')
                                            <button type="submit" class="btn btn-sm btn-outline-danger fw-bold text-uppercase">Rechazar</button>
                                        </form>
                                    </div>
                                @endif
                            </td>
                        @endif
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        
        <div class="mt-4 d-flex justify-content-center">
            {{ $pases->links() }}
        </div>
    @endif
</div>
@endsection
