<div class="user-create">
    <x-title>
        Create User
    </x-title>

    <div class="row">
        <div class="col-12 col-md-9">
            <div class="card">
                <div class="card-body">

                    <div class="row mb-3">
                        <div class="col-6">
                            <x-ui.input name="name_first" label="First Name"/>
                        </div>

                        <div class="col-6">
                            <x-ui.input name="name_last" label="Last Name"/>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-6">
                            <x-ui.input name="email" type="email" label="Email Address"/>
                        </div>

                        <div class="col-6">
                            <x-ui.input name="username" label="Username"/>
                        </div>
                    </div>

                    <div class="mb-3">
                        <x-ui.input name="password" label="Password" type="password"/>
                    </div>

                    <div class="mb-3">
                    <label class="form-label">WIP Grade</label>
                        <select class="form-select" wire:model.defer="wip_grade">
                            <option value="">— No WIP Grade —</option>
                            <option value="D">Grade D - £150 + VAT p/hour</option>
                            <option value="C">Grade C - £218 + VAT p/hour</option>
                        </select>

                        @error('wip_grade')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                        @enderror
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Solicitor</label>
                        <select class="form-select" wire:model.defer="solicitor_id">
                            <option value="">— Platform User (no solicitor) —</option>
                            @foreach($solicitors as $solicitor)
                                <option value="{{ $solicitor->id }}">{{ $solicitor->name }}</option>
                            @endforeach
                        </select>
                        @error('solicitor_id') <div class="text-danger small mt-1">{{ $message }}</div> @enderror
                    </div>

                    <div class="mb-4">
                        <label class="form-label">Roles</label>
                        <div class="d-flex flex-wrap gap-3">
                            @foreach($roles as $role)
                                <div class="form-check">
                                    <input class="form-check-input"
                                           type="checkbox"
                                           wire:model.defer="selectedRoles[]"
                                           value="{{ $role->name }}">
                                    <label class="form-check-label">
                                        {{ $role->name }}
                                    </label>
                                </div>
                            @endforeach
                        </div>
                    </div>

                    <div class="d-flex justify-content-end">
                        <button class="btn btn-success"
                                wire:click="save">
                            Create User
                        </button>
                    </div>

                </div>
            </div>
        </div>

        {{-- SIDEBAR --}}
        <div class="col-12 col-md-3">
            <div class="card">
                <div class="card-body">
                    <h4 class="card-title">Guidance</h4>
                    <hr>

                    <p class="text-muted small mb-0">
                        Assign roles carefully. Permissions are inherited
                        automatically from roles.
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
