<div class="form-grid two-columns">
    <label>
        <span>Name</span>
        <input name="name" value="{{ old('name', $adminUser->name ?? '') }}" required>
    </label>

    <label>
        <span>Email</span>
        <input name="email" type="email" value="{{ old('email', $adminUser->email ?? '') }}" required>
    </label>
</div>

<label>
    <span>Password {{ isset($adminUser) ? '(leave blank to keep current password)' : '' }}</span>
    <input name="password" type="password" {{ isset($adminUser) ? '' : 'required' }}>
</label>

<section class="settings-card">
    <div class="settings-card-head">
        <div>
            <span class="eyebrow">Access</span>
            <h2>Roles</h2>
        </div>
    </div>
    <div class="checkbox-grid">
        @foreach ($roles as $role)
            <label class="checkbox-label">
                <input
                    name="role_ids[]"
                    type="checkbox"
                    value="{{ $role->id }}"
                    @checked(collect(old('role_ids', isset($adminUser) ? $adminUser->roles->pluck('id')->all() : []))->contains($role->id))
                >
                <span>{{ $role->name }}</span>
            </label>
        @endforeach
    </div>
</section>

<section class="settings-card">
    <div class="settings-card-head">
        <div>
            <span class="eyebrow">Access</span>
            <h2>Direct Permissions</h2>
        </div>
    </div>
    <div class="checkbox-grid">
        @foreach ($permissions as $permission)
            <label class="checkbox-label">
                <input
                    name="permission_ids[]"
                    type="checkbox"
                    value="{{ $permission->id }}"
                    @checked(collect(old('permission_ids', isset($adminUser) ? $adminUser->permissions->pluck('id')->all() : []))->contains($permission->id))
                >
                <span>{{ $permission->name }}</span>
            </label>
        @endforeach
    </div>
</section>

<label class="checkbox-label">
    <input name="is_active" type="checkbox" value="1" @checked(old('is_active', $adminUser->is_active ?? true))>
    <span>Active</span>
</label>

@if ($errors->any())
    <p class="form-error">{{ $errors->first() }}</p>
@endif
