<div class="user-edit">
    <x-title>
        Editing User: {{ $user->name_first }} {{ $user->name_last }}

        <x-slot:buttons>
            <a wire:navigate href="{{ route('admin.users.show', $user) }}"
               class="btn btn-outline-secondary">
                View Profile
            </a>
        </x-slot:buttons>
    </x-title>

    @if(session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
    @endif

    <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">
                            <label class="form-label">First Name</label>
                            <input class="form-control" wire:model.defer="name_first">
                        </div>

                        <div class="col-6">
                            <label class="form-label">Last Name</label>
                            <input class="form-control" wire:model.defer="name_last">
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Email</label>
                        <input class="form-control" wire:model.defer="email">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">
                            New Password
                            <span class="text-muted small">(optional)</span>
                        </label>
                        <input type="password"
                               class="form-control"
                               wire:model.defer="password">
                    </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-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-4">
                        <label class="form-label">Roles</label>
                        <div class="d-flex flex-wrap gap-3">
                            @foreach($allRoles as $role)
                                <div class="form-check">
                                    <input class="form-check-input"
                                           type="checkbox"
                                           wire:model.defer="roles"
                                           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-primary"
                                wire:click="save">
                            Save Changes
                        </button>
                    </div>

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

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

                    <p class="text-muted small mb-0">
                        Role changes apply immediately and may
                        affect system access.
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
