@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 Exit</h5>
                </div>
                <div class="col-auto">
                    <a href="{{ route('core.employee-exits.create') }}" class="btn btn-primary btn-sm">
                        Add Exit
                    </a>
                </div>
            </div>       
        </div>
        <div class="card-body">
        <table class="table table-bordered yajra-datatable w-100" id="exit-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>
$('#exit-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('core.employee-exits.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 exits...",
        lengthMenu: "Show _MENU_ entries",
        info: "Showing _START_–_END_ of _TOTAL_ dynamic exits"
        },
        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-exits') }}/" + id,
                    type: 'DELETE',
                    data: { _token: "{{ csrf_token() }}" },
                    success: function (res) {
                        Swal.fire('Deleted', res.message, 'success');
                        table.ajax.reload();
                    }
                });
            }
        });
    });
</script>
@endsection
