@extends('layouts.front.masterapp')

@section('content')
<div class="content-wrapper container">
    <div class="page-heading">
        <div class="page-title">
            <div class="row">
                <div class="col-12 col-md-6 order-md-1 order-last">
                    <h3>Data Diri Pelamar</h3>
                    <p class="text-subtitle text-muted">Universitas Negeri Surabaya</p>
                </div>
                <div class="col-12 col-md-6 order-md-2 order-first">
                    <nav aria-label="breadcrumb" class="breadcrumb-header float-start float-lg-end">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="{{ route('lowongan.index') }}">Formasi</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Data Diri</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- // Basic multiple Column Form section start -->
    <section id="multiple-column-form">
        <div class="row match-height">
            <div class="col-12">
                <div class="card">

                    <div class="card-content">
                        <div class="card-body">

                        @if(Session::has('message'))
                          <div class="alert alert-danger">{{ Session::get('message') }}</div>
                        @endif
                        @if(Session::has('sukses'))
                          <div class="alert alert-success">{{ Session::get('sukses') }}</div>
                        @endif
                        @if ($Pendaftaran == null)
                          <div class="alert alert-danger">Silahkan mengisi Isian FORMASI terlebih dahulu.</div>
                        @endif

                        @if (!empty($Pendaftaran->konfirmasi_at) || empty($Pendaftaran))
                        <form id="myForm">
                        @endif
                        @if (empty($Pendaftaran->konfirmasi_at))
                        <form action="{{route('biodata.update', Auth::user()->id)}}"  method="POST" enctype="multipart/form-data">
                        @endif
                        @csrf @method('PATCH')
                                <div class="row">

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">Nama *</label>
                                            <input type="text" class="form-control"
                                                placeholder="Nama" name="nama" value="{{ @$Biodata->nama }}">
                                        </div>
                                        @if ($errors->has('nama'))
                                             <span class="text-danger">{{$errors->first('nama')}}</span>
	                                    @endif
                                    </div>


                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">NIK *</label>
                                            <input type="text" class="form-control"
                                                placeholder="NIK" name="nik" value="{{@$Biodata->nik }}" maxlength="16" minlength="16">
                                        </div>
                                        @if ($errors->has('nik'))
                                             <span class="text-danger">{{$errors->first('nik')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">Gelar Depan</label>
                                            <input type="text" class="form-control"
                                                placeholder="Gelar Depan" name="gelar_depan" value="{{ @$Biodata->gelardepan }}" >
                                        </div>
                                        @if ($errors->has('gelar_depan'))
                                             <span class="text-danger">{{$errors->first('gelar_depan')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">Gelar Belakang *</label>
                                            <input type="text" class="form-control"
                                                placeholder="Gelar Belakang" name="gelar_belakang" value="{{@$Biodata->gelar_belakang }}" >
                                        </div>
                                        @if ($errors->has('gelar_belakang'))
                                             <span class="text-danger">{{$errors->first('gelar_belakang')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="first-name-column">Tempat Lahir *</label>
                                            <input type="text" class="form-control"
                                                placeholder="Tempat Lahir" name="tempat_lahir" value="{{@$Biodata->tempat_lahir }}">
                                        </div>
                                        @if ($errors->has('tempat_lahir'))
                                             <span class="text-danger">{{$errors->first('tempat_lahir')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="city-column">Tanggal Lahir (yyyy-mm-dd)*</label>
                                            <input type="text" class="form-control mydob"
                                                name="tgl_lahir" value="{{ @$Biodata->tgl_lahir }}"  id="input" data-inputmask="'alias': 'datetime', 'inputFormat': 'yyyy/mm/dd'" />

                                        </div>
                                        @if ($errors->has('tgl_lahir'))
                                             <span class="text-danger">{{$errors->first('tgl_lahir')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="country-floating">Jenis Kelamin *</label>
                                            <select class="form-select" name="jenis_kelamin">
                                                <option value="L" @if (!empty($Biodata) && $Biodata->jenis_kelamin == "L"){{ 'selected' }} @endif>Laki-Laki</option>
                                                <option value="P" @if (!empty($Biodata) && $Biodata->jenis_kelamin == "P"){{ 'selected' }} @endif>Perempuan</option>
                                            </select>
                                        </div>
                                        @if ($errors->has('jenis_kelamin'))
                                             <span class="text-danger">{{$errors->first('jenis_kelamin')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="country-floating">Nomer HP *</label>
                                            <input type="number" class="form-control"
                                                name="hp" placeholder="Nomer HP" value="{{@$Biodata->hp }}" >
                                        </div>
                                        @if ($errors->has('hp'))
                                             <span class="text-danger">{{$errors->first('hp')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-12 col-12">
                                        <div class="form-group">
                                            <label for="company-column">Alamat (Sesuai KTP) *</label>
                                            <input type="text" class="form-control"
                                                name="alamat_ktp" placeholder="Alamat (Sesuai KTP)" value="{{ @$Biodata->alamat_ktp }}">
                                        </div>
                                        @if ($errors->has('alamat_ktp'))
                                             <span class="text-danger">{{$errors->first('alamat_ktp')}}</span>
	                                    @endif
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Provinsi</label>
                                            <select name="provinsi" class="form-select">
                                                    <option value="">Pilih Provinsi</option>
                                                    @foreach ($MsProvinsi as $key => $value)
                                                        <option value="{{ $key }}"
                                                        @if (!empty($Biodata->kelurahanKtp->kecamatan->kabupaten->provinsi->code))
                                                        {{ $Biodata->kelurahanKtp->kecamatan->kabupaten->provinsi->code == $key ? 'selected' : '' }}
                                                        @endif
                                                        >{{ $value }}</option>
                                                    @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Kota/Kabupaten</label>
                                            <select name="kabupaten" class="form-select">
                                            @foreach($MsKabupatenKtp as $kabupaten)
                                                <option value="{{ $kabupaten->code }}"
                                                {{ $Biodata->kelurahanKtp->kecamatan->kabupaten->code == $kabupaten->code ? 'selected' : '' }}>{{$kabupaten->name }}</option>
                                                
                                            @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Kecamatan</label>
                                            <select name="kecamatan" class="form-select">
                                            @foreach($MsKecamatanKtp as $kecamatan)
                                                <option value="{{ $kecamatan->code }}" {{ $Biodata->kelurahanKtp->kecamatan->code == $kecamatan->code ? 'selected' : '' }}>{{$kecamatan->name }}</option>
                                            @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Kelurahan</label>
                                            <select name="kelurahan_ktp_id" class="form-select">
                                            @foreach($MsKelurahanKtp as $kelurahan)
                                                <option value="{{ $kelurahan->code }}" {{ $Biodata->kelurahanKtp->code == $kelurahan->code ? 'selected' : '' }}>{{$kelurahan->name }}</option>
                                            @endforeach
                                            </select>
                                        </div>
                                     </div>

                                     <div class="col-md-3 col-12">
                                        <div class="form-group">
                                            <label for="company-column">RT</label>
                                            <input type="number" class="form-control"
                                                name="rt_ktp" placeholder="RT" value="{{ @$Biodata->rt_ktp }}">
                                        </div>
                                        @if ($errors->has('rt_ktp'))
                                             <span class="text-danger">{{$errors->first('rt_ktp')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-3 col-12">
                                        <div class="form-group">
                                            <label for="company-column">RW</label>
                                            <input type="number" class="form-control"
                                                name="rw_ktp" placeholder="RW" value="{{ @$Biodata->rw_ktp }}">
                                        </div>
                                        @if ($errors->has('rw_ktp'))
                                             <span class="text-danger">{{$errors->first('rw_ktp')}}</span>
	                                    @endif
                                    </div>


                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="email-id-column">&nbsp;</label>
                                            <label for="email-id-column">&nbsp;</label>
                                        </div>
                                    </div>

                                    <div class="col-md-12 col-12">
                                        <div class="form-group">
                                            <label for="company-column">Alamat Domisili *</label>
                                            <input type="text" class="form-control"
                                                name="alamat_domisili" placeholder="Alamat Domisili" value="{{ @$Biodata->alamat_domisili }}">
                                        </div>
                                        @if ($errors->has('alamat_domisili'))
                                             <span class="text-danger">{{$errors->first('alamat_domisili')}}</span>
	                                    @endif
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Provinsi</label>
                                            <select name="provinsidomisili" class="form-select">
                                                    <option value="">Pilih Provinsi</option>

                                                    @foreach ($MsProvinsi as $key => $value)
                                                        <option value="{{ $key }}"
                                                        @if (!empty($Biodata->kelurahanDomisili->kecamatan->kabupaten->provinsi->code))
                                                        {{ $Biodata->kelurahanDomisili->kecamatan->kabupaten->provinsi->code == $key ? 'selected' : '' }}
                                                        @endif >
                                                            {{ $value }}</option>
                                                    @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Kota/Kabupaten</label>
                                            <select name="kabupatendomisili" class="form-select">
                                            @foreach($MsKabupatenDomisili as $kabupaten)
                                                <option value="{{ $kabupaten->code }}"
                                                {{ $Biodata->kelurahanDomisili->kecamatan->kabupaten->code == $kabupaten->code ? 'selected' : '' }}>{{$kabupaten->name }}</option>
                                            @endforeach
                                            </select>

                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Kecamatan</label>
                                            <select name="kecamatandomisili" class="form-select">
                                            @foreach($MsKecamatanDomisili as $kecamatan)
                                                <option value="{{ $kecamatan->code }}" {{ $Biodata->kelurahanDomisili->kecamatan->code == $kecamatan->code ? 'selected' : '' }}>{{$kecamatan->name }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-12">
                                        <div class="input-group mb-3">
                                            <label class="input-group-text" for="inputGroupSelect01">Kelurahan</label>
                                            <select name="kelurahan_domisili_id" class="form-select">
                                                @foreach($MsKelurahanDomisili as $kelurahan)
                                                <option value="{{ $kelurahan->code }}" {{ $Biodata->kelurahanDomisili->code == $kelurahan->code ? 'selected' : '' }}>{{$kelurahan->name }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                     </div>

                                     <div class="col-md-3 col-12">
                                        <div class="form-group">
                                            <label for="company-column">RT</label>
                                            <input type="number" class="form-control"
                                                name="rt_domisili" placeholder="RT" value="{{ @$Biodata->rt_domisili }}">
                                        </div>
                                        @if ($errors->has('rt_domisili'))
                                             <span class="text-danger">{{$errors->first('rt_domisili')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-3 col-12">
                                        <div class="form-group">
                                            <label for="company-column">RW</label>
                                            <input type="number" class="form-control"
                                                name="rw_domisili" placeholder="RW" value="{{@$Biodata->rw_domisili }}">
                                        </div>
                                        @if ($errors->has('rw_domisili'))
                                             <span class="text-danger">{{$errors->first('rw_domisili')}}</span>
	                                    @endif
                                    </div>


                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="email-id-column">&nbsp;</label>
                                            <label for="email-id-column">&nbsp;</label>
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="email-id-column">Unggah Foto *<code>.jpg ukuran Maks. 500 kb</code></label>
                                            <input type="file" class="form-control"
                                                name="foto" accept=".jpg,.jpeg,.png"
                                                @if (empty($Biodata->foto)) required @endif>
                                        </div>
                                        @if (!empty($Biodata->ktp))
                                            <a href="https://statik.unesa.ac.id/profileunesa_konten_statik/uploads/rekrutmen/foto/{!!$Biodata->foto!!}" target="_blank"><span class="badge bg-info">Foto</span></a>
                                        @endif
                                        @if ($errors->has('foto'))
                                             <span class="text-danger">{{$errors->first('foto')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-md-6 col-12">
                                        <div class="form-group">
                                            <label for="email-id-column">Unggah KTP *<code>.jpg ukuran Maks. 500 kb</code></label>
                                            <input type="file" class="form-control"
                                                name="ktp" accept=".jpg,.jpeg,.png"
                                                @if (empty($Biodata->ktp)) required @endif>
                                        </div>
                                        @if (!empty($Biodata->ktp))
                                            <a href="https://statik.unesa.ac.id/profileunesa_konten_statik/uploads/rekrutmen/ktp/{!!$Biodata->ktp!!}" target="_blank"><span class="badge bg-info">KTP</span></a>
                                        @endif
                                        @if ($errors->has('ktp'))
                                             <span class="text-danger">{{$errors->first('ktp')}}</span>
	                                    @endif
                                    </div>

                                    <div class="col-12 d-flex justify-content-end">
                                        @if ($Pendaftaran != null && empty($Pendaftaran->konfirmasi_at))
                                            <button type="submit" class="btn btn-primary me-1 mb-1">Submit</button>
                                        @endif
                                        @if (!empty($Biodata))
                                            <a class="btn btn-success me-1 mb-1" href="{{ route('pendidikan.index') }}">
                                            Lanjut  <i class="bi bi bi-arrow-right"></i>
                                            </a>
                                        @endif
                                    </div>


                                </div>
                        </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>



    </div>
</div>
<script>
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
</script>


@endsection
@push('js')
<script>

    $(document).ready(function() {
        $('select[name="provinsi"]').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: 'kabupaten/'+stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {


                        $('select[name="kabupaten"]').empty();
                        $.each(data, function(key, value) {
                            $('select[name="kabupaten"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });


                    }
                });
            }else{
                $('select[name="kabupaten"]').empty();
            }
        });
    });

    $(document).ready(function() {
        $('select[name="provinsidomisili"]').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: 'kabupatendomisili/'+stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {


                        $('select[name="kabupatendomisili"]').empty();
                        $.each(data, function(key, value) {
                            $('select[name="kabupatendomisili"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });


                    }
                });
            }else{
                $('select[name="kabupatendomisili"]').empty();
            }
        });
    });


</script>
<script>

    $(document).ready(function() {
        $('select[name="kabupaten"]').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: 'kecamatan/'+stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {


                        $('select[name="kecamatan"]').empty();
                        $.each(data, function(key, value) {
                            $('select[name="kecamatan"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });


                    }
                });
            }else{
                $('select[name="kecamatan"]').empty();
            }
        });
    });

    $(document).ready(function() {
        $('select[name="kabupatendomisili"]').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: 'kecamatandomisili/'+stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {


                        $('select[name="kecamatandomisili"]').empty();
                        $.each(data, function(key, value) {
                            $('select[name="kecamatandomisili"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });


                    }
                });
            }else{
                $('select[name="kecamatandomisili"]').empty();
            }
        });
    });

</script>

<script>

    $(document).ready(function() {
        $('select[name="kecamatan"]').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: 'kelurahan/'+stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {


                        $('select[name="kelurahan_ktp_id"]').empty();
                        $.each(data, function(key, value) {
                            $('select[name="kelurahan_ktp_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });


                    }
                });
            }else{
                $('select[name="kelurahan_ktp_id"]').empty();
            }
        });
    });

    $(document).ready(function() {
        $('select[name="kecamatandomisili"]').on('change', function() {
            var stateID = $(this).val();
            if(stateID) {
                $.ajax({
                    url: 'kelurahandomisili/'+stateID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {


                        $('select[name="kelurahan_domisili_id"]').empty();
                        $.each(data, function(key, value) {
                            $('select[name="kelurahan_domisili_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                        });


                    }
                });
            }else{
                $('select[name="kelurahan_domisili_id"]').empty();
            }
        });
    });


    Inputmask().mask("input");
</script>
<script>

function getAge(tgl_lahir) { return ~~((new Date()-new Date(tgl_lahir))/(31556952000)) }
$("tgl_lahir").val()
$("input.mydob").change(function(){
  $('.age').val(getAge($(this).val()));
});

</script>







@endpush
