@extends('layouts.contentLayoutMaster')

@section('title','Tambah SKKP')

@section('vendor-styles')
<link rel="stylesheet" type="text/css" href="{{asset('css/plugins/forms/validation/form-validation.css')}}">
<link rel="stylesheet" type="text/css" href="{{asset('vendors/css/forms/select/select2.min.css')}}">
<link rel="stylesheet" type="text/css" href="{{asset('vendors/css/pickers/pickadate/pickadate.css')}}">
<link rel="stylesheet" type="text/css" href="{{asset('vendors/css/pickers/daterange/daterangepicker.css')}}">
@endsection

@section('page-styles')
<link rel="stylesheet" type="text/css" href="{{asset('css/pages/page-users.css')}}">
@endsection

@section('content')
<!-- users edit start -->
<section class="users-edit">
<form method="post" action="{{ route('skkp.store') }}" autocomplete="off" class="form" enctype="multipart/form-data">
    @csrf
    @method('post')
    <div class="card">
        <div class="card-content">
        <div class="card-body">
            <div class="row">
                <div class="col-12 col-sm-6">
                    <div class="form-group">
                        <div class="controls">
                            <label>NIK Pemohon</label>
                            <input id="pemohon_nik" type="number" class="form-control @error('pemohon_nik') is-invalid @enderror" class="form-control" name="pemohon_nik" 
                                value="{{ auth()->user()->nik, old('pemohon_nik') }}" readonly 
                                autofocus placeholder="Nomor KTP">
                                @if ($errors->has('pemohon_nik'))
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $errors->first('pemohon_nik') }}</strong>
                                </span>
                                @endif
                        </div>
                    </div>
                </div>
                <div class="col-12 col-sm-6">
                    <div class="form-group">
                        <div class="controls">
                            <label>Nama Pemohon</label>
                            <input type="text" name="pemohon_nama" minlength="3" id="pemohon_nama" class="form-control" placeholder="Nama"
                                value="{{ auth()->user()->name, old('pemohon_nama') }}" readonly>
                                @if ($errors->has('pemohon_nama'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('pemohon_nama') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                </div>
            </div> 
        </div>
        </div>
    </div>
    <div class="card">
        <div class="card-content">
        <div class="card-body">
            <div class="row">
                <div class="col-12">
                    <div class="form-group">
                        <div class="controls">
                            <label>Nama</label>
                            <input type="text" name="nama" minlength="3" id="nama" class="form-control @error('nama') is-invalid @enderror" placeholder="Nama"
                                    value="{{ old('nama') }}" required
                                    data-validation-required-message="Nama wajib diisi."
                                    data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                @if ($errors->has('nama'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('nama') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>NIK</label>
                            <input id="nik" type="number" minlength="16" maxlength="16" class="form-control @error('nik') is-invalid @enderror" class="form-control" name="nik" value="{{ old('nik') }}" required 
                                autocomplete="nik" autofocus placeholder="NIK"
                                data-validation-required-message="NIK wajib diisi."
                                data-validation-minlength-message="Harus terdiri dari minimal 16 karakter."
                                data-validation-maxlength-message="Harus terdiri dari minimal 16 karakter.">
                                @if ($errors->has('nik'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('nik') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label class="d-block">Jenis Kelamin</label>
                            <div class="custom-control-inline">
                                <div class="radio mr-1">
                                    <input type="radio" name="jenis_kelamin" id="radio1" class="form-control  @error('jenis_kelamin') is-invalid @enderror" value="Laki-Laki" required>
                                    <label for="radio1">Laki-Laki</label>
                                </div>
                                <div class="radio">
                                    <input type="radio" name="jenis_kelamin" id="radio2" class="form-control  @error('jenis_kelamin') is-invalid @enderror" value="Perempuan" required>
                                    <label for="radio2">Perempuan</label>
                                </div>
                                @if ($errors->has('jenis_kelamin'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('jenis_kelamin') }}</li>
                                    </ul>
                                </div>
                                @endif
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Tempat Lahir</label>
                            <input type="text" name="tempat_lahir" minlength="3" id="tempat_lahir" class="form-control  @error('tempat_lahir') is-invalid @enderror" placeholder="Tempat Lahir" required
                                value="{{ old('tempat_lahir') }}" 
                                data-validation-required-message="Tempat Lahir wajib diisi."
                                data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                @if ($errors->has('tempat_lahir'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('tempat_lahir') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                    <div class="form-group position-relative has-icon-left">
                        <div class="controls">
                            <label>Tanggal Lahir</label>
                            <input type="text" name="tanggal_lahir" class="form-control @error('tanggal_lahir') is-invalid @enderror pickadate" placeholder="Pilih Tanggal">
                            <div class="form-control-position">
                                <i class='bx bx-calendar' style="top: 24px"></i>
                            </div>
                            @if ($errors->has('tanggal_lahir'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('tanggal_lahir') }}</li>
                                    </ul>
                                </div>
                            @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Kewarganegaraan</label>
                            <input type="text" name="kewarganegaraan" id="kewarganegaraan" class="form-control @error('kewarganegaraan') is-invalid @enderror" placeholder="Kewarganegaraan"
                                    value="{{ old('kewarganegaraan') }}" required
                                    data-validation-required-message="Kewarganegaraan wajib diisi.">
                                @if ($errors->has('kewarganegaraan'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('kewarganegaraan') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Agama</label>
                            <select class="select2 form-control @error('agama') is-invalid @enderror" id="agama" name="agama" required>
                                <option value="" selected disabled>Pilih Agama</option>
                                <option value="Islam">Islam</option>
                                <option value="Katolik">Katolik</option>
                                <option value="Kristen">Kristen</option>
                                <option value="Hindu">Hindu</option>
                                <option value="Budha">Budha</option>
                                <option value="Konghucu">Konghucu</option>
                                <option value="Lainnya">Lainnya</option>
                            </select>
                            @if ($errors->has('agama'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('agama') }}</li>
                                    </ul>
                                </div>
                            @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Status Perkawinan</label>
                            <select class="select2 form-control @error('status_perkawinan') is-invalid @enderror" id="status_perkawinan" name="status_perkawinan" required>
                                <option value="" selected disabled>Pilih Status Perkawinan</option>
                                <option value="MENIKAH">MENIKAH</option>
                                <option value="BELUM MENIKAH">BELUM MENIKAH</option>
                                <option value="JANDA/DUDA">JANDA/DUDA</option>
                            </select>
                            @if ($errors->has('status_perkawinan'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('status_perkawinan') }}</li>
                                    </ul>
                                </div>
                            @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Pekerjaan</label>
                            <input type="text" name="pekerjaan" minlength="3" id="pekerjaan" class="form-control @error('pekerjaan') is-invalid @enderror" placeholder="Pekerjaan"
                                    value="{{ old('pekerjaan') }}" required
                                    data-validation-required-message="Pekerjaan wajib diisi."
                                    data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                @if ($errors->has('pekerjaan'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('pekerjaan') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Alamat</label>
                            <input type="text" name="alamat" minlength="3" id="alamat" class="form-control @error('alamat') is-invalid @enderror" placeholder="Alamat"
                                    value="{{ old('alamat') }}" required
                                    data-validation-required-message="Alamat wajib diisi."
                                    data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                @if ($errors->has('alamat'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('alamat') }}</li>
                                    </ul>
                                </div>
                                @endif
                        </div>
                    </div>
                </div>

                <div class="col-12">
                    <div class="border rounded px-1 mb-1">
                        <h6 class="border-bottom py-1 mb-1 font-medium-2"><i
                        class="bx bx-body mr-50 "></i>Data Kematian</h6>
                        <div class="form-group position-relative has-icon-left">
                            <div class="controls">
                                <label>Tanggal Kematian</label>
                                <input type="text" name="tanggal_meninggal" class="form-control @error('tanggal_meninggal') is-invalid @enderror pickadate" placeholder="Pilih Tanggal">
                                <div class="form-control-position">
                                    <i class='bx bx-calendar' style="top: 24px"></i>
                                </div>
                                @if ($errors->has('tanggal_meninggal'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('tanggal_meninggal') }}</li>
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Tempat Kematian</label>
                                <input type="text" name="tempat_meninggal" minlength="3" id="tempat_meninggal" class="form-control @error('tempat_meninggal') is-invalid @enderror" placeholder="Tempat Kematian""
                                        value="{{ old('tempat_meninggal') }}" required
                                        data-validation-required-message="Tempat Kematian wajib diisi."
                                        data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                    @if ($errors->has('tempat_meninggal'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('tempat_meninggal') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Provinsi</label>
                                <select class="select2 form-control @error('provinsi') is-invalid @enderror" id="provinsi" name="provinsi" required>
                                    <option value="" selected disabled>Pilih Provinsi</option>
                                    @foreach ($provinces as $item)
                                        <option value="{{ $item->id ?? '' }}">{{ $item->name ?? '' }}</option>
                                    @endforeach
                                </select>
                                @if ($errors->has('provinsi'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('provinsi') }}</li>
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Kabupaten / Kota</label>
                                <select class="select2 form-control @error('kabupaten_kota') is-invalid @enderror" id="kabupaten_kota" name="kabupaten_kota" required>
                                    <option value="" selected disabled>Pilih Kabupaten / Kota</option>
                                </select>
                                @if ($errors->has('kabupaten_kota'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('kabupaten_kota') }}</li>
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Kecamatan</label>
                                <select class="select2 form-control @error('kecamatan') is-invalid @enderror" id="kecamatan" name="kecamatan" required>
                                    <option value="" selected disabled>Pilih Kecamatan</option>
                                </select>
                                @if ($errors->has('kecamatan'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('kecamatan') }}</li>
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Desa / Kelurahan</label>
                                <select class="select2 form-control @error('desa_kelurahan') is-invalid @enderror" id="desa_kelurahan" name="desa_kelurahan" required>
                                    <option value="" selected disabled>Pilih Desa / Kelurahan</option>
                                </select>
                                @if ($errors->has('desa_kelurahan'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('desa_kelurahan') }}</li>
                                        </ul>
                                    </div>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Sebab Kematian</label>
                                <input type="text" name="sebab_meninggal" minlength="3" id="sebab_meninggal" class="form-control @error('sebab_meninggal') is-invalid @enderror" placeholder="Sebab Kematian"
                                        value="{{ old('sebab_meninggal') }}" required
                                        data-validation-required-message="Sebab Kematian wajib diisi."
                                        data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                    @if ($errors->has('sebab_meninggal'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('sebab_meninggal') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Yang Menentukan</label>
                                <input type="text" name="saksi_meninggal" id="saksi_meninggal" class="form-control @error('saksi_meninggal') is-invalid @enderror" placeholder="Yang Menentukan"
                                        value="{{ old('saksi_meninggal') }}"
                                        data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                    @if ($errors->has('saksi_meninggal'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('saksi_meninggal') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Keterangan Visum</label>
                                <input type="text" name="keterangan_meninggal" id="keterangan_meninggal" class="form-control @error('keterangan_meninggal') is-invalid @enderror" placeholder="Keterangan Visum"
                                        value="{{ old('keterangan_meninggal') }}" 
                                        data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                    @if ($errors->has('keterangan_meninggal'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('keterangan_meninggal') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>Tempat Dikuburkan</label>
                                <input type="text" name="tempat_dikuburkan" minlength="3" id="tempat_dikuburkan" class="form-control @error('tempat_dikuburkan') is-invalid @enderror" placeholder="Tempat Dikuburkan"
                                        value="{{ old('tempat_dikuburkan') }}" required
                                        data-validation-required-message="Tempat Dikuburkan wajib diisi."
                                        data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                    @if ($errors->has('tempat_dikuburkan'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('tempat_dikuburkan') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <label>Scan KTP</label>
                            <div class="form-group">
                                <div class="controls">
                                    <div class="custom-file">
                                        <input type="file" class="form-controll @error('scan_ktp') is-invalid @enderror custom-file-input" id="scan_ktp" name="scan_ktp">
                                        <label class="custom-file-label" for="scan_ktp">Pilih foto</label>
                                        <small class="text-warning">Foto KTP diusakan jelas dan tidak terpotong.</small>
                                    </div>
                                    @if ($errors->has('scan_ktp'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('scan_ktp') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                                </div>
                            </div>    
                        </div>
                        <div class="form-group">
                            <label>Scan KK</label>
                            <div class="form-group">
                                <div class="controls">
                                    <div class="custom-file">
                                        <input type="file" class="form control @error('scan_kk') is-invalid @enderror custom-file-input" id="scan_kk" name="scan_kk">
                                        <label class="custom-file-label" for="scan_kk">Pilih foto</label>
                                        <small class="text-warning">Foto KK diusakan jelas dan tidak terpotong.</small>
                                    </div>
                                    @if ($errors->has('scan_kk'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('scan_kk') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                                </div>
                            </div>    
                        </div>
                        <div class="form-group">
                            <label>Scan Keterangan Kematian</label>
                            <div class="form-group">
                                <div class="controls">
                                    <div class="custom-file">
                                        <input type="file" class="form control @error('scan_keterangan') is-invalid @enderror custom-file-input" id="scan_keterangan" name="scan_keterangan">
                                        <label class="custom-file-label" for="scan_keterangan">Pilih foto</label>
                                        <small class="text-warning">Foto keterangan kematian diusakan jelas dan tidak terpotong.</small>
                                    </div>
                                    @if ($errors->has('scan_keterangan'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('scan_keterangan') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                                </div>
                            </div>    
                        </div>
                    </div>
                </div>
                <div class="col-12 d-flex flex-sm-row flex-column justify-content-start mt-1">
                    <button type="submit" class="btn btn-danger glow mb-1 mb-sm-0 mr-0 mr-sm-1">Simpan</button>
                    <button type="reset" class="btn btn-light">Cancel</button>
                </div>
            </div> 
        </div>
        </div>
    </div>
</form>
</section>
<!-- users edit ends -->
@endsection

{{-- vendor scripts --}}
@section('vendor-scripts')
<script>
    function onChangeSelect(url, id, name) {
        // send ajax request to get the cities of the selected province and append to the select tag
        $.ajax({
            url: url,
            type: 'GET',
            data: {
                id: id
            },
            success: function (data) {
                $('#' + name).empty();
                $('#' + name).append('<option>Pilih Salah Satu</option>');

                $.each(data, function (key, value) {
                    $('#' + name).append('<option value="' + key + '">' + value + '</option>');
                });
            }
        });
    }
    $(function () {
        $('#provinsi').on('change', function () {
            onChangeSelect('{{ route("cities") }}', $(this).val(), 'kabupaten_kota');
        });
        $('#kabupaten_kota').on('change', function () {
            onChangeSelect('{{ route("districts") }}', $(this).val(), 'kecamatan');
        })
        $('#kecamatan').on('change', function () {
            onChangeSelect('{{ route("villages") }}', $(this).val(), 'desa_kelurahan');
        })
    });
</script>
<script src="{{asset('vendors/js/forms/select/select2.full.min.js')}}"></script>
<script src="{{asset('vendors/js/forms/validation/jqBootstrapValidation.js')}}"></script>
<script src="{{asset('vendors/js/pickers/pickadate/picker.js')}}"></script>
<script src="{{asset('vendors/js/pickers/pickadate/picker.date.js')}}"></script>
@endsection

{{-- page scripts --}}
@section('page-scripts')
<script src="{{asset('js/scripts/pages/page-users.js')}}"></script>
<script src="{{asset('js/scripts/navs/navs.js')}}"></script>
<script src="{{asset('js/scripts/forms/validation/form-validation.js')}}"></script>
<script src="{{asset('js/scripts/pickers/dateTime/pick-a-datetime.js')}}"></script>   
@endsection