@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>Riwayat Pendidikan</h3>
                    @if(!empty($Pendaftaran->formasi->wajib_s1_s2))
                    <div class="alert alert-danger">Formasi Dosen Wajib Mengisi S1 dan S2</div>
                    @endif
                    @if(!empty($Pendaftaran->formasi->wajib_s1))
                    <div class="alert alert-danger">Formasi Dosen Wajib Mengisi S1</div>
                    @endif
                    @if(!empty($Pendaftaran->formasi->wajib_s2))
                    <div class="alert alert-danger">Formasi Dosen Wajib Mengisi S2</div>
                    @endif
                   
                </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"><a href="{{ route('biodata.index') }}">Data Diri</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Pendidikan</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

    
    <section id="multiple-column-form">
        <div class="row match-height">
            <div class="col-12">
                <div class="card">
                     @if ($Biodata == null)
                     <br>
                                <div class="alert alert-danger">
                                    Silahkan mengisi Isian DATA DIRI terlebih dahulu.
                                </div>
                    @endif
               
                    <div class="card-content">
                        <div class="card-body">
                        @if(Session::has('sukses'))
                          <div class="alert alert-success">{{ Session::get('sukses') }}</div>
                        @endif
                        @if (empty($Pendaftaran->konfirmasi_at) && empty($Pendaftaran->sms_id) && !empty($Biodata))
                            <a class="btn btn-outline-danger block" href="{{ route('creatependidikan', ['data' => encrypt(0)]) }}">Tambah Riwayat Pendidikan (Sesuai Formasi)</a>
                        @endif
                        @if (empty($Pendaftaran->konfirmasi_at) && !empty($Pendaftaran->sms_id) && !empty($Biodata))
                            <a class="btn btn-outline-primary block" href="{{ route('creatependidikan', ['data' => encrypt(1)]) }}">Tambah Riwayat Pendidikan</a>
                        @endif
                       
                        <table class="table table-striped" id="table1">
                            <thead>
                                <tr>	
                                    <th>No</th>
                                    <th>Kejuruan</th>
                                    <th>Lembaga</th>
                                    <th>IPK</th>
                                    <th>Akreditasi</th>
                                    <th>Tahun Masuk</th>
                                    <th>Tahun Lulus</th>
                                </tr>
                            </thead>
                            <tbody>
                            @if (!empty($Pendaftaran->sms_id))
                                <tr>
                                    <td>1. </td>
                                    <td>{{$Pendaftaran->prodi->jenjangPendidikan->nm_jenj_didik}} {{$Pendaftaran->prodi->nama}}</td>
                                    <td>{{$Pendaftaran->lembaga}}</td>
                                    <td>{{$Pendaftaran->ipk}}</td>
                                    <td>{{$Pendaftaran->akreditasi}}</td>
                                    <td>{{$Pendaftaran->tahun_masuk}}</td>
                                    <td>{{$Pendaftaran->tahun_lulus}}</td>
                                    <td>
                                    
                                        <a><span class="badge bg-success">Pendidikan Sesuai Formasi</span></a> 
                                        &nbsp;&nbsp;
                                        @if (empty($Pendaftaran->konfirmasi_at)) 
                                        <button onclick="destroy('{{ route('pendidikan.destroy', ['pendidikan' => encrypt($Pendaftaran->id)]) }}')" class="btn btn-danger btn-sm">Hapus</button>
                                        @endif 

                                        <a href="{{ route('pendidikan.show', ['pendidikan' => encrypt($Pendaftaran->id)]) }}" class="btn btn-info btn-sm">Detail</a>
                                   
                                    </td>
                                </tr>
                            @endif
                            @foreach ($biodatapendidikan as $data)   
                                <tr>
                                    <td>{{ $loop->iteration }}</td>
                                    <td>{{$data->prodi->jenjangPendidikan->nm_jenj_didik}} {{$data->prodi->nama}}</td>
                                    <td>{{$data->lembaga}}</td>
                                    <td>{{$data->ipk}}</td>
                                    <td>{{$data->akreditasi}}</td>
                                    <td>{{$data->tahun_masuk}}</td>
                                    <td>{{$data->tahun_lulus}}</td>
                                    <td>
                                   
                                    @if (empty($Pendaftaran->konfirmasi_at)) 
                                        <a href="{{ route('pendidikan.edit', ['pendidikan' => encrypt($data->id)]) }}" class="btn btn-warning btn-sm">Edit</a>
                                        
                                        <button onclick="destroy('{{ route('pendidikan.destroy', ['pendidikan' => encrypt($data->id)]) }}')" class="btn btn-danger btn-sm">Hapus</button>
                                    @endif  
                                    
                                   
                                    <a href="{{ route('pendidikan.show', ['pendidikan' => encrypt($data->id)]) }}" class="btn btn-info btn-sm">Detail</a>
                                    </td>
                                </tr>
                            @endforeach 
                            </tbody>
                        </table>

                        @if (!empty($Pendaftaran->sms_id))
                                <div class="col-12 d-flex justify-content-end">
                                    <a class="btn btn-success me-1 mb-1" href="{{ route('dokumenpelengkap.index') }}">  
                                        Lanjut  <i class="bi bi bi-arrow-right"></i>
                                    </a>
                                </div>               
                         @endif

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

    </div>
</div>
<script>

function destroy(url){
        Swal.fire({
        title: 'Apakah Anda Yakin?',
        text: "Anda akan menghapus data ini!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Ya'
        }).then((result) => {
            if (result.isConfirmed) {
                var token = "{{ csrf_token() }}";
                var request = $.ajax({
                    url : url,
                    type : "DELETE",
                    dataType : "html",
                    data : {_token: token, _method: 'PUT'},
                    success: function(data){
                        Swal.fire({
                            position: 'top-end',
                            icon: 'success',
                            title: 'Berhasil menghapus data',
                            showConfirmButton: false,
                            timer: 1500
                        });
                        location.reload();
                },
                error: function(data){
                    Swal.fire({
                        position: 'top-end',
                        icon: 'error',
                        title: 'Gagal menghapus data',
                        showConfirmButton: false,
                        timer: 1500
                    })
                }
            })
            }
        })
    }
      
</script>
@endsection
