@extends('layouts.contentLayoutMaster')

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

@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('skpd.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</label>
                            <input id="nik" type="number" class="form-control @error('nik') is-invalid @enderror" class="form-control" name="nik" 
                                value="{{ auth()->user()->nik, old('nik') }}" readonly 
                                autocomplete="nik" autofocus placeholder="Nomor KTP">
                                @if ($errors->has('nik'))
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $errors->first('nik') }}</strong>
                                </span>
                                @endif
                        </div>
                    </div>
                </div>
                <div class="col-12 col-sm-6">
                    <div class="form-group">
                        <div class="controls">
                            <label>Nama</label>
                            <input type="text" name="name" minlength="3" id="name" class="form-control" placeholder="Nama"
                                value="{{ auth()->user()->name, old('name') }}" readonly>
                                @if ($errors->has('name'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('name') }}</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="border rounded px-1 mb-1">
                        <h6 class="border-bottom py-1 mb-1 font-medium-2"><i
                        class="feather icon-map-pin mr-50 "></i>Pindah Alamat Ke :</h6>
                        <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 class="form-group">
                            <div class="controls">
                                <label>RT</label>
                                <input type="text" id="rt" minlength="1" maxlength="4" class="form-control @error('rt') is-invalid @enderror" name="rt" placeholder="RT" 
                                    value="{{ old('rt') }}" required
                                    data-validation-required-message="RT wajib diisi."
                                    data-validation-containsnumber-regex="(\d)+"
                                    data-validation-containsnumber-message="Masukkan RT yang valid."
                                    data-validation-minlength-message="Harus terdiri dari minimal 1 karakter."
                                    data-validation-maxlength-message="Harus terdiri dari maksimal 4 karakter.">
                                    @if ($errors->has('rt'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('rt') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="controls">
                                <label>RW</label>
                                <input type="text" id="rw" minlength="1" maxlength="4" class="form-control @error('rw') is-invalid @enderror" name="rw" placeholder="RW" 
                                    value="{{ old('rw') }}" required
                                    data-validation-required-message="RW wajib diisi."
                                    data-validation-containsnumber-regex="(\d)+"
                                    data-validation-containsnumber-message="Masukkan RW yang valid."
                                    data-validation-minlength-message="Harus terdiri dari minimal 1 karakter."
                                    data-validation-maxlength-message="Harus terdiri dari maksimal 4 karakter.">
                                    @if ($errors->has('rw'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('rw') }}</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>Kode Pos</label>
                                <input type="text" id="kode_pos" minlength="4" maxlength="6" class="form-control @error('kode_pos') is-invalid @enderror" name="kode_pos" placeholder="Kode Pos" 
                                    value="{{ old('kode_pos') }}" required
                                    data-validation-required-message="Kode Pos wajib diisi."
                                    data-validation-containsnumber-regex="(\d)+"
                                    data-validation-containsnumber-message="Masukkan Kode Pos yang valid."
                                    data-validation-minlength-message="Harus terdiri dari minimal 4 karakter."
                                    data-validation-maxlength-message="Harus terdiri dari maksimal 6 karakter.">
                                    @if ($errors->has('kode_pos'))
                                    <div class="help-block text-danger">
                                        <ul role="alert">
                                            <li>{{ $errors->first('kode_pos') }}</li>
                                        </ul>
                                    </div>
                                    @endif
                            </div>
                        </div>
                    </div>   
                </div>
                <div class="col-12">
                    <div class="form-group position-relative has-icon-left">
                        <div class="controls">
                            <label>Tanggal Pindah</label>
                            <input type="text" name="tanggal_pindah" class="form-control @error('tanggal_pindah') 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_pindah'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('tanggal_pindah') }}</li>
                                    </ul>
                                </div>
                            @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="controls">
                            <label>Alasan Pindah</label>
                            <input type="text" name="alasan" minlength="3" id="alasan" class="form-control @error('alasan') is-invalid @enderror" placeholder="Alasan Pindah"
                                    value="{{ old('alasan') }}" required
                                    data-validation-required-message="Alasan Pindah wajib diisi."
                                    data-validation-minlength-message="Harus terdiri dari minimal 3 karakter.">
                                @if ($errors->has('alasan'))
                                <div class="help-block text-danger">
                                    <ul role="alert">
                                        <li>{{ $errors->first('alasan') }}</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>
                <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>
<script src="{{asset('vendors/js/pickers/pickadate/picker.time.js')}}"></script>
<script src="{{asset('vendors/js/pickers/pickadate/legacy.js')}}"></script>
<script src="{{asset('vendors/js/pickers/daterange/moment.min.js')}}"></script>
<script src="{{asset('vendors/js/pickers/daterange/daterangepicker.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/forms/validation/form-validation.js')}}"></script>
<script src="{{asset('js/scripts/pickers/dateTime/pick-a-datetime.js')}}"></script>   
@endsection