@push('script')
    <script>
        $(document).ready(function () {
            function load_job(params = []) {
                $("table.table").DataTable().destroy()
                $("table.table").DataTable({
                    "deferRender": true,
                    "responsive": true,
                    'serverSide': true,
                    'processing': true,
                    "ordering": false,
                    "ajax": {
                        "url": "{{ route('api.job.index2') }}",
                        "type": "GET",
                        "data": {
                            "sort": "ASC"
                        },
                        "headers": {
                            "Authorization" : getAuthorization()
                        },
                        "dataSrc": "data"
                    },
                    "columns": [
                        {
                            data: null,
                            render: function (data, type, row, meta) {
                                return meta.row + meta.settings._iDisplayStart + 1 + '.';
                            }
                        },
                        {
                            data: 'name'
                        },
                        {
                            data: 'description'
                        },
                        {
                            data: 'accommodation'
                        },
                        {
                            data: 'working_days'
                        },
                        {
                            data: 'working_hours'
                        },
                        {
                            data: 'salary'
                        },
                        {
                            data: 'address'
                        },
                        {
                            data: 'recommended_age'
                        },
                        {
                            data: null,
                            render: res => {
                                console.log(res);
                                let html = `<ul>`;
                                for (let index = 0; index < res.skills.length; index++) {
                                    html += `<li>${res.skills[index].name}</li>`
                                }
                                html += `</ul>`;
                                if (res.skills.length == 0) {
                                    html = '-'
                                }
                                return html;
                            }
                        },
                        {
                            data: 'applicant'
                        }
                    ]
                });
            }

            load_job();
        })
    </script>
@endpush
