@extends('admin.layouts.app')

@section('content')
    <div class="row px-5">
        <div class="col-xl-12">
            <div class="card shadow">
                <div class="card-header bg-transparent">
                    <div class="row align-items-center">
                        <div class="col">
                            <h6 class="text-uppercase text-muted ls-1 mb-1">User Management | Petugas UDD</h6>
                            <h2 class="mb-0">Edit Petugas UDD</h2>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <form action="{{ route($route.'update_action') }}" class="form-global-handle" method="POST" enctype="multipart/form-data">
                        @csrf
                        <input type="hidden" name="petugas_id" value="{{ Hashids::encode($data->id) }}">
                        <div class="form-group">
                            <label for="RoleName">Nama <span class="text-danger">*</span></label>
                            <input type="text" name="nama" value="{{ $data->nama }}" required class="form-control" id="RoleName" placeholder="Example : Admin">
                        </div>
                        <div class="form-group">
                            <label for="RoleName">Email <span class="text-danger">*</span></label>
                            <input type="text" name="email" value="{{ $data->user->email }}" required class="form-control" id="RoleName" placeholder="Example : Admin">
                        </div>
                        <div class="form-group">
                            <label for="password">Password <span class="text-danger">*</span></label>
                            <input type="password" name="password" class="form-control" id="password" placeholder="Example : *******">
                            <div>
                                <small>Minimal adalah 6 karakter</small>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                @if (!empty($udds))
                                    <div class="form-group">
                                        <label> List UDD <span class="text-danger">*</span> </label>
                                        @foreach ($udds as $key => $value)
                                            <div class="card mr-2 my-2 p-3">
                                                @foreach ($value as $key_value => $value_udd)
                                                    <div class="custom-control custom-control-alternative custom-radio mb-3">
                                                        <input class="custom-control-input" name="unit_donor_darah_id" value="{{ $value_udd->id }}" {{ $data->udd->id == $value_udd->id ? 'checked' : null }} required id="udd{{$key.$key_value}}" type="radio">
                                                        <label class="custom-control-label" for="udd{{$key.$key_value}}">{{ $value_udd->nama }}</label>
                                                    </div>
                                                @endforeach
                                            </div>
                                        @endforeach
                                    </div>
                                @endif
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <label> List Role <span class="text-danger">*</span></label>
                                    @php
                                        $role_petugas = $data->user->roles()->get()->pluck('id')->toArray();
                                    @endphp
                                    @foreach ($roles as $key => $value)
                                        <div class="card mr-2 my-2 p-3">
                                            @foreach ($value as $key_value => $value_role)
                                                <div class="custom-control custom-control-alternative custom-checkbox mb-3">
                                                    <input class="custom-control-input" name="role_id[]" value="{{ $value_role->id }}" {{ in_array($value_role->id, $role_petugas) ? 'checked' : null }} id="role{{$key.$key_value}}" type="checkbox">
                                                    <label class="custom-control-label" for="role{{$key.$key_value}}">{{ $value_role->name }}</label>
                                                </div>
                                            @endforeach
                                        </div>
                                    @endforeach
                                </div>
                            </div>
                        </div>
                        <div class="group">
                            <button type="submit" class="btn btn-success">Simpan</button>
                            <a class="btn btn-default bg-back" href="{{ route($route.'index') }}">Kembali</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

 {{-- load JS yang lu perluin, selain itu no --}}
@push('js')
    <script src="{{ asset('assets') }}/js/blockUI.js"></script>
    <script src="{{ asset('assets') }}/js/sweetalert2.js"></script>
    <script src="{{ asset('assets') }}/js/custom.js"></script>
@endpush