@extends('admin.layout')

@section('title', 'Utilisateurs')
@section('header', 'Utilisateurs')

@section('content')
<nav class="mb-6">
    <a href="{{ route('admin.dashboard') }}" class="text-slate-500 hover:text-slate-900 text-sm">← Tableau de bord</a>
</nav>

<div class="flex items-center justify-between mb-6">
    <p class="text-slate-600 text-sm">Gérer les comptes et les droits d'accès à l'admin.</p>
    <a href="{{ route('admin.users.create') }}" class="inline-flex items-center gap-2 px-4 py-2 bg-primary-500 text-white rounded-xl font-medium hover:bg-primary-600 transition text-sm">
        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
        Nouvel utilisateur
    </a>
</div>

<div class="bg-white rounded-2xl border border-slate-200 overflow-hidden">
    @if($users->isEmpty())
        <div class="p-12 text-center text-slate-500">
            <svg class="w-16 h-16 mx-auto mb-4 text-slate-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/></svg>
            <p class="font-medium">Aucun utilisateur</p>
            <p class="text-sm mt-1">Créez le premier utilisateur pour gérer l'accès au CMS.</p>
        </div>
    @else
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-slate-50 border-b border-slate-200">
                    <tr>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Nom</th>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Email</th>
                        <th class="text-left px-6 py-4 text-sm font-semibold text-slate-700">Rôle</th>
                        <th class="text-right px-6 py-4 text-sm font-semibold text-slate-700">Actions</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    @foreach($users as $u)
                        <tr class="hover:bg-slate-50/80 transition">
                            <td class="px-6 py-4 font-medium text-slate-900">{{ $u->name }}</td>
                            <td class="px-6 py-4 text-slate-600">{{ $u->email }}</td>
                            <td class="px-6 py-4">
                                <span class="inline-flex px-2.5 py-0.5 rounded-full text-xs font-medium
                                    @if($u->role === 'admin') bg-violet-100 text-violet-800
                                    @elseif($u->role === 'editor') bg-emerald-100 text-emerald-800
                                    @else bg-slate-100 text-slate-700
                                    @endif">
                                    {{ $u->getRoleLabel() }}
                                </span>
                            </td>
                            <td class="px-6 py-4 text-right">
                                <a href="{{ route('admin.users.edit', $u) }}" class="text-primary-600 hover:underline text-sm">Modifier</a>
                                @if($u->id !== auth()->id())
                                    <form method="POST" action="{{ route('admin.users.destroy', $u) }}" class="inline ml-2" onsubmit="return confirm('Supprimer cet utilisateur ?')">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="text-red-600 hover:underline text-sm">Supprimer</button>
                                    </form>
                                @endif
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <div class="px-6 py-4 border-t border-slate-200">
            {{ $users->links() }}
        </div>
    @endif
</div>
@endsection
