<x-app-layout>
    <x-ui.page-header title="Nouveau compte admin" description="Créer un administrateur ou un super administrateur" />
    <x-alert />

    <div class="card p-6 max-w-2xl">
        <form method="POST" action="{{ route('admin.admins.store') }}" class="space-y-5">
            @csrf
            <div class="grid grid-cols-1 md:grid-cols-2 gap-5">
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-slate-700 mb-1">Nom *</label>
                    <input type="text" name="name" value="{{ old('name') }}" class="input-modern" required>
                    @error('name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                </div>
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-slate-700 mb-1">Email *</label>
                    <input type="email" name="email" value="{{ old('email') }}" class="input-modern" required>
                    @error('email')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                </div>
                <div>
                    <label class="block text-sm font-medium text-slate-700 mb-1">Mot de passe *</label>
                    <input type="password" name="password" class="input-modern" required>
                    @error('password')<p class="mt-1 text-sm text-red-600">{{ $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="input-modern" required>
                </div>
                <div class="md:col-span-2">
                    <label class="block text-sm font-medium text-slate-700 mb-1">Rôle *</label>
                    <select name="role" class="input-modern" required>
                        <option value="admin" @selected(old('role', 'admin') === 'admin')>Administrateur (consultation filiales & soumissions)</option>
                        <option value="super_admin" @selected(old('role') === 'super_admin')>Super administrateur (tous les droits)</option>
                    </select>
                    @error('role')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
                </div>
                <div class="md:col-span-2">
                    <label class="inline-flex items-center gap-2">
                        <input type="hidden" name="is_active" value="0">
                        <input type="checkbox" name="is_active" value="1" class="rounded border-slate-300 text-transtev-600" @checked(old('is_active', true))>
                        <span class="text-sm font-medium text-slate-700">Compte actif</span>
                    </label>
                </div>
            </div>

            <div class="flex gap-3 pt-2">
                <button type="submit" class="btn-primary">Créer le compte</button>
                <a href="{{ route('admin.admins.index') }}" class="btn-secondary">Annuler</a>
            </div>
        </form>
    </div>
</x-app-layout>
