<form action="{{ route('super-admin.users.update','id='.$user->id) }}" method="POST" role="form" id="form1"
      enctype="multipart/form-data">
    @csrf

    <div class="row mt-3">
        <div class="col-md-12">
            <div class="form-group">
                <label class="form-label" for="employee_id">{{ __('messages.employee_name')}} <span
                        class="text-danger">*</span></label>
                <select class="form-select select2" name="employee_id" id="employee_id" required>
                    @foreach ($employees as $dta)
                        <option value="{{$dta->id}}" {{($user->employee_id === $dta->id) ? 'selected' : ''}}>{{$dta->employee_name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="username">{{ __('messages.name')}}<span
                        class="text-danger">*</span></label>
                <input type="text" class="form-control @error('name') is-invalid @enderror" name="name" id="username"
                       placeholder="Enter name" value="{{($user->name) ?? old('name')}}" readonly required autocomplete="off"/>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="useremail">{{ __('messages.email')}}<span
                        class="text-danger">*</span></label>
                <input type="email" class="form-control @error('email') is-invalid @enderror" name="email"
                       id="useremail"
                       placeholder="Enter email" value="{{($user->email) ?? old('email')}}" readonly required/>
            </div>
        </div>
    </div>

    <div class="row mt-3">
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="useraddress">{{ __('messages.address')}}</label>
                <input type="text" class="form-control" name="address" placeholder="Enter address" id="useraddress"
                       value="{{($user->address) ?? old('address')}}" readonly/>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="userphone">{{ __('messages.phone')}}</label>
                <input type="text" class="form-control" name="phone" placeholder="ex: 017XXXXXXXX" id="userphone"
                       value="{{($user->phone) ?? old('phone')}}" readonly/>
            </div>
        </div>
    </div>
    <div class="row mt-3">
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="usergender">{{ __('messages.gender')}} <span class="text-danger">*</span></label>
                <select class="form-control" name="gender" id="usergender">
                    <option value=""> Select Gender</option>
                    <option value="male" {{($user->gender === 'male') ? 'selected' : ''}}>Male</option>
                    <option value="female" {{($user->gender === 'female') ? 'selected' : ''}}>Female</option>
                    <option value="other" {{($user->gender === 'other') ? 'selected' : ''}}>Other</option>
                </select>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="user_roles">{{ __('messages.assign_roles')}} <span
                        class="text-danger">*</span></label>
                <select class="form-control @error('assign_roles') is-invalid @enderror"
                        name="assign_roles" id="user_roles">
                    <option value="">Select Roles</option>
                    @foreach ($roles as $item)
                        <option
                            value="{{$item->id}}" {{$user->hasRole($item->name) ? 'selected' : '' }}>{{$item->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>
    <div class="row mt-3">
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label" for="organizationEdit">{{ __('messages.branch')}} <span
                        class="text-danger">*</span></label>
                <select class="form-control @error('organizations') is-invalid @enderror"
                        name="organizations[]" id="organizationEdit" multiple="multiple" required>
                    @foreach ($organizations as $organization)
                        <option value="{{$organization->id}}"
                                @foreach($user->organizations as $fa) @if($organization->id === $fa->id) selected="selected"@endif @endforeach>{{$organization->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
    </div>
    <div class="row mt-3">
        <div class="col-md-6">
            <div class="form-group">
                <label class="form-label">{{ __('messages.profile_photo')}}</label>
                <input type="file" class="form-control" name="profile_photo" accept="image/*">
            </div>
        </div>
    </div>
    <div class="row mt-3" style="height: 70px;">
        <div class="col-md-4">
            <div class="form-group">
                <label class="form-label">{{ __('messages.status')}}</label><br>
                <label>
                    <input type="radio" class="form-check-input" name="status"
                           value="active" {{($user->status === 'active') ? 'checked' : ''}}/> Active
                </label>
                <label>
                    <input type="radio" class="form-check-input ms-3" name="status"
                           value="inactive" {{($user->status === 'inactive') ? 'checked' : ''}}/> Inactive
                </label>
            </div>
        </div>
    </div>
    <div class="mt-3 d-flex justify-content-end">
        <button type="button" class="btn  me-2" data-bs-dismiss="modal"
                style="background: #EAECF0;">{{ __('messages.close')}}
        </button>
        @can('user.edit')
            <button type="submit" class="btn btn-primary">{{ __('messages.update')}}</button>
        @endcan
    </div>
</form>
<script>
    $(document).ready(function ($) {
        $('.select2-multiple').select2({
            dropdownParent: $('#userCreateModal'),
            width: 'resolve',
        });
        $('.select2').select2({
            dropdownParent: $('#user_edit_modal'),
            width: 'resolve',
        });
    });
    $('#doctor_check_edit').change(function() {
        if($(this).is(':checked')) {
            console.log('Checkbox is checked');
            $('.doctorType_section_edit').removeClass('d-none');
        }
    });
    $('#other_check_edit').change(function() {
        if($(this).is(':checked')) {
            console.log('Checkbox is other');
            $('.doctorType_section_edit').addClass('d-none');
        }
    });
</script>

