@extends('admin.layout')

@section('title', 'Modifier l\'utilisateur')
@section('header', 'Modifier l\'utilisateur')

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

<form method="POST" action="{{ route('admin.users.update', $user) }}" class="max-w-xl space-y-6">
    @csrf
    @method('PUT')

    <div class="bg-white rounded-2xl border border-slate-200 p-6 space-y-6">
        <div>
            <label class="block text-sm font-medium text-slate-700 mb-1">Nom</label>
            <input type="text" name="name" value="{{ old('name', $user->name) }}" required class="w-full px-4 py-2.5 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
            @error('name')<p class="text-red-500 text-sm mt-1">{{ $message }}</p>@enderror
        </div>

        <div>
            <label class="block text-sm font-medium text-slate-700 mb-1">Email</label>
            <input type="email" name="email" value="{{ old('email', $user->email) }}" required class="w-full px-4 py-2.5 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
            @error('email')<p class="text-red-500 text-sm mt-1">{{ $message }}</p>@enderror
        </div>

        <div>
            <label class="block text-sm font-medium text-slate-700 mb-1">Nouveau mot de passe</label>
            <input type="password" name="password" class="w-full px-4 py-2.5 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-500 focus:border-primary-500" placeholder="Laisser vide pour ne pas modifier">
            @error('password')<p class="text-red-500 text-sm mt-1">{{ $message }}</p>@enderror
        </div>

        <div>
            <label class="block text-sm font-medium text-slate-700 mb-1">Confirmer le mot de passe</label>
            <input type="password" name="password_confirmation" class="w-full px-4 py-2.5 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
        </div>

        <div>
            <label class="block text-sm font-medium text-slate-700 mb-2">Rôle</label>
            <select name="role" required class="w-full px-4 py-2.5 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                <option value="admin" {{ old('role', $user->role) === 'admin' ? 'selected' : '' }}>Administrateur – Accès complet</option>
                <option value="editor" {{ old('role', $user->role) === 'editor' ? 'selected' : '' }}>Éditeur – Pages, médias, contenu</option>
                <option value="viewer" {{ old('role', $user->role) === 'viewer' ? 'selected' : '' }}>Lecteur – Consultation uniquement</option>
            </select>
            @error('role')<p class="text-red-500 text-sm mt-1">{{ $message }}</p>@enderror
        </div>
    </div>

    <div class="flex gap-3">
        <button type="submit" class="px-6 py-2.5 bg-primary-500 text-white rounded-xl font-medium hover:bg-primary-600 transition">Enregistrer</button>
        <a href="{{ route('admin.users.index') }}" class="px-6 py-2.5 border border-slate-200 rounded-xl text-slate-700 hover:bg-slate-50 transition">Annuler</a>
    </div>
</form>
@endsection
