@extends('layouts.app')
@section('title', 'Comptes')
@section('content')
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3>Comptes (admin / coursiers)</h3>
    <a href="{{ route('admin.users.create') }}" class="btn btn-primary">+ Nouveau compte</a>
</div>

<div class="card p-3">
    <div class="table-responsive">
        <table class="table align-middle">
            <thead>
                <tr>
                    <th>Nom</th>
                    <th>Email</th>
                    <th>Role</th>
                    <th>Partenaire</th>
                    <th>Statut</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @forelse($users as $u)
                <tr>
                    <td>{{ $u->name }}</td>
                    <td>{{ $u->email }}</td>
                    <td><span class="badge bg-info text-dark">{{ $u->role }}</span></td>
                    <td>{{ $u->partner->name ?? '-' }}</td>
                    <td>
                        <span class="badge {{ $u->active ? 'bg-success' : 'bg-secondary' }}">
                            {{ $u->active ? 'Actif' : 'Inactif' }}
                        </span>
                    </td>
                    <td class="table-actions">
                        <form action="{{ route('admin.users.toggle', $u) }}" method="POST">
                            @csrf
                            <button class="btn btn-sm btn-outline-secondary">
                                {{ $u->active ? 'Desactiver' : 'Activer' }}
                            </button>
                        </form>
                    </td>
                </tr>
                @empty
                <tr><td colspan="6" class="text-center text-muted">Aucun compte.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    {{ $users->links() }}
</div>
@endsection
