@extends('layouts.app')

@section('content')
    <div class="card">
        <div class="card-header">
            <div class="row align-items-center">
                <div class="col">
                    <h5 class="mb-0">Employee Rejoins</h5>
                </div>
                <div class="col-auto">
                    <a href="{{ route('core.employee-rejoins.create') }}" class="btn btn-primary btn-sm">
                        Add Rejoin
                    </a>
                </div>
            </div>       
        </div>
        <div class="card-body">
        <table class="table table-bordered yajra-datatable w-100" id="rejoin-table">
                <thead>
                <tr>
                    <th>No</th>
                    <th>Name</th>
                    <th>Date</th>
                    <th>Exit Date</th>
                    <th>Remarks</th>
                    <th>System</th>
                    <th width="80">Action</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
@endsection

@section('scripts')
<script>
$('#rejoin-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('core.employee-rejoins.index') }}",
        dom:
        "<'row mb-3 align-items-center'<'col-md-6'l><'col-md-6 d-flex justify-content-end'f>>" +
        "<'table-responsive'tr>" +
        "<'row mt-3 align-items-center'<'col-md-6'i><'col-md-6 d-flex justify-content-end'p>>",

        language: {
        search: "",
        searchPlaceholder: "Search rejoins...",
        lengthMenu: "Show _MENU_ entries",
        info: "Showing _START_–_END_ of _TOTAL_ dynamic rejoins"
        },
        columns: [
        { data: 'emp_no' },
        { data: 'name' },
        { data: 'created_date' },
        { data: 'exit_date' },
        { data: 'remarks' },
        { data: 'system_generated' },
        { data: 'action' },
    ]
});

  $(document).on('click', '.btn-delete', function () {
        let id = $(this).data('id');

        Swal.fire({
            title: 'Delete this record?',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#d33'
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    url: "{{ url('core/employee-rejoins') }}/" + id,
                    type: 'DELETE',
                    data: { _token: "{{ csrf_token() }}" },
                    success: function (res) {
                        Swal.fire('Deleted', res.message, 'success');
                        table.ajax.reload();
                    }
                });
            }
        });
    });
</script>
@endsection
