@extends('app.app')

@section('title')
    Logs Gps Trackers
@endsection

@section('customcss')
@endsection

@section('content')
    <div class="container-fluid">
        <div class="content">
            <div class="card">
                <div class="card-header">
                    <div class="row d-flex align-items-center">
                        <div class="col-3">
                            <p class="card-title text-bold mb-0">Logs Gps Trackers
								(<span id="count_logs">0</span>)
							</p>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="tLogs" class="table table-hover dataTable">
                            <thead>
                                <tr class="">
                                    <th class="">#</th>
                                    <th class="text-end text-nowrap">Device ID / IMEI</th>
                                    <th class="text-center text-nowrap">At</th>
                                </tr>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('customjs')
    <script>
        'use strict';
        const State = {
            storage_lara: "{{ asset('storage') }}/",
        };

        const Wrapper = {
            activate: function() {
                Wrapper.event();
                DTable.activate();
            },
            event: function() {
				setInterval(() => {
					DTable.reload();
				}, 10000);
			},
        };

        const DTable = {
            activate: function() {
                DTable.reload();
            },
            reload: function() {
                // $('#tLogs').DataTable();
                // if (Driver.Table.firstInitDataTable == 1) { loadTableSkeletonLoading() } else { Driver.Table.firstInitDataTable = 1; }
                $('#tLogs').DataTable({
                    processing: true,
                    serverSide: false,
                    bLengthChange: true,
                    deferRender: true,
                    destroy: true,
                    ajax: {
                        url: "{{ route('api_conf_list_logs_gps') }}",
                        type: 'GET',
                        complete: function(jqXHR, textStatus, c) {
                            let count = jqXHR.responseJSON.count;
                            if (typeof count != 'undefined') {
                                $('#count_logs').text(count);
                            }
                            // removeTableSkeletonLoading()
                        },
                    },
                    deferRender: true,
                    columns: [{
                            data: 'DT_RowIndex',
                            className: 'text-end',
                            visible: true,
                            orderable: true,
                            searchable: true,
                        },
                        {
                            data: 'device_id',
                            className: 'text-end text-nowrap',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            // createdCell: function(td, cellData, rowData, row, col) {
                            //     $(td).attr('data-ttid', rowData.id);
                            //     $(td).attr('data-type_name', rowData.type_name);
                            // },
                        },
                        {
                            data: 'crt',
                            className: 'text-center text-nowrap',
                            visible: true,
                            orderable: true,
                            searchable: true,
                            render: function(data, type, row, meta) {
                                return moment.unix(data).format('DD MMM YYYY HH:mm:ss');
                            }
                        },
                    ],
                });
            },
        };

        Wrapper.activate();
    </script>
@endsection
