@extends('layouts.app')
@section('title', 'SPK Penerimaan karyawan ')
@section('topbar', 'Daftar Pelamar')
@section('css')
<link href="{{ asset('vendor/datatables/dataTables.bootstrap4.min.css') }}" rel="stylesheet">
@stop
@section('content')

<div class="row">
    <!-- Kosongkan bagian kiri agar layout tetap seimbang -->
    <div class="col-md-4"></div>

    <div class="col-md-12">
        <div class="card shadow mb-4">
            <a href="#listkriteria" class="d-block card-header py-3" data-toggle="collapse"
                role="button" aria-expanded="true" aria-controls="collapseCardExample">
                <h6 class="m-0 font-weight-bold text-primary">List Pelamar</h6>
            </a>

            <div class="collapse show" id="listkriteria">
                <div class="card-body">
                    <div class="table-responsive">
                        <a href="{{ URL::to('download-alternatif-pdf') }}" target="_blank" class="d-none d-sm-inline-block btn btn-sm btn-success shadow-sm float-left"><i
                            class="fas fa-download fa-sm text-white-50"></i>Download Laporan</a>
                        <table class="table table-striped table-hover" id="DataTable" data-paging="false">
                            <thead>
                                <tr>
                                    <th>Nama</th>
                                    <th>Usia</th>
                                    <th>Pendidikan</th>
                                    <th>IPK</th>
                                    <th>Jurusan</th>
                                    <th>Lama Studi</th>
                                    <th>Pengalaman</th>
                                    <th>Serkom</th>  
                                    <th>CV</th>   
                                    <th>Dokumen Pendukung</th> 
                                    <th>Aksi</th>       
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($alternatifs as $row)
                                    <tr>
                                        <td>{{ $row->nama_alternatif }}</td>
                                        <td>{{ $row->usia }}</td>
                                        <td>{{ $row->pendidikan }}</td>
                                        <td>{{ $row->ipk }}</td>
                                        <td>{{ $row->jurusan }}</td>
                                        <td>{{ $row->lama_studi }}</td>
                                        <td>{{ $row->pengalaman }}</td>
                                        <td>{{ $row->serkom ? 'Punya' : 'Tidak punya' }}</td>
                                        <td>
                                            <a href="{{ asset('storage/' . $row->cv) }}" target="_blank">Lihat CV</a>
                                        </td>
                                        <td>
                                            <a href="{{ asset('storage/' . $row->dokumen_pendukung) }}" target="_blank">Lihat Dokumen Pendukung</a>
                                        </td>  
                                        <td>
                                            <a href="{{ route('alternatif.edit',$row->id) }}" class="btn btn-sm btn-circle btn-warning">
                                                <i class="fa fa-edit"></i>
                                            </a>
                                            <a href="{{ route('alternatif.destroy',$row->id) }}" class="btn btn-sm btn-circle btn-danger hapus">
                                                <i class="fa fa-trash"></i>
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                        <div class="d-flex justify-content-end">
                            {{ $alternatifs->links() }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
@stop

@section('js')
<script src="{{ asset('vendor/datatables/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('vendor/datatables/dataTables.bootstrap4.min.js') }}"></script>
<script src="{{ asset('js/sweetalert.js')}}"></script>
<script>
    $(document).ready(function(){
        $('#DataTable').DataTable();

        $('.hapus').on('click', function(){
            swal({
                title: "Apa anda yakin?",
                text: "Sekali anda menghapus data, data tidak dapat dikembalikan lagi!",
                icon: "warning",
                buttons: true,
                dangerMode: true,
            }).then((willDelete) => {
                if (willDelete) {
                    $.ajax({
                        url: $(this).attr('href'),
                        type: 'DELETE',
                        data: {
                            '_token' : "{{ csrf_token() }}"
                        },
                        success:function()
                        {
                            swal("Data berhasil dihapus!", {
                                icon: "success",
                            }).then(() => {
                                window.location = "{{ route('alternatif.index') }}"
                            });
                        }
                    })
                } else {
                    swal("Data Aman!");
                }
            });

            return false;
        })
    })
</script>
@stop
