@include('components.theme.pages.header')

<section>
    <!-- basic table -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex">
                    <h6 class="m-0 font-weight-bold text-primary">Perbarui Pengguna</h6>
                    <p class="m-0 ml-auto small"><span class="text-danger">*</span> Wajib diisi</p>
                </div>
                <div class="card-body">
                    <form method="POST" action="{{ app_url('users/update') . '/' . $data['records']['id'] }}" enctype="multipart/form-data">
                    @csrf
                    @if(session()->has('success'))
                        <div class="alert alert-success">
                            {{ session()->get('success') }}
                        </div>
                    @else
                        @if(session()->has('error'))
                            <div class="alert alert-danger">
                                {{ session()->get('error') }}
                            </div>
                        @endif
                    @endif
                        <div class="row mb-3">
                            <div class="col">
                                <label>Email Address<sup class="text-danger">*</sup></label>
                                <input type="email" name="email" value="{{ $data['records']['email'] }}" autocomplete="off" class="form-control mt-1 {{ $errors->has('email') ? 'is-invalid' : '' }}" placeholder="Enter Email Address">
                                @error('email') <small class="text-danger">{{ $message }}</small> @enderror
                            </div>
                            <div class="col">
                                <label>Full Name<sup class="text-danger">*</sup></label>
                                <input type="text" name="name" value="{{ $data['records']['name'] }}" autocomplete="off" class="form-control mt-1 {{ $errors->has('name') ? 'is-invalid' : '' }}" placeholder="Enter Name">
                                @error('name') <small class="text-danger">{{ $message }}</small> @enderror
                            </div>
                        </div>

                        <div class="form-group mb-3" data-kt-password-meter="true">
                            <label>Password<sup class="text-danger">*</sup></label>
                            <input type="password" name="password" value="{{ old('password') }}" autocomplete="off" class="form-control mt-1 {{ $errors->has('password') ? 'is-invalid' : '' }}" placeholder="Enter Password">
                            @error('password') <small class="text-danger">{{ $message }}</small> @enderror
                        </div>
                        <div class="row mb-3">
                            <div class="col">
                                <label>Roles<sup class="text-danger">*</sup></label>
                                <select name="level" class="form-control mt-2 {{ $errors->has('level') ? 'is-invalid' : '' }}">
                                    @foreach ($roles as $role)
                                        @php $selected = $data['records']['level'] == $role->id ? 'selected' : '' @endphp
                                        @php $selected_name = $data['records']['level'] == $role->id ? '(selected)' : '' @endphp
                                        <option value="{{ $role->id }}" {{ $selected }}>{{ $role->name }} {{ $selected_name }}</option>
                                    @endforeach
                                </select>
                                @error('level') <small class="text-danger">{{ $message }}</small> @enderror
                            </div>
                        </div>
                        <div class="form-group mb-0">
                            <button type="submit" class="btn btn-primary">Simpan</button>
                            <a href="{{ route('users') }}" class="btn btn-light btn-light">Kembali</a>
                        </div>
                    {{ Form::close() }}
                </div>
            </div>
        </div>
    </div>
</section>

@include('components.theme.pages.footer')
