@extends('admin._layout.layout')

@section('header')
    {{ trans('SMS log') }}

    &nbsp;&nbsp;

@endsection

@section('main')
    <div class="row">
        <div class="col-md-12">

            <div class="panel">
                <div class="table-primary">
                    <table class="table table-striped table-bordered" id="sms-log-table" width="100%">
                        <thead>
                        <tr>
                            <th>{{ 'Phone code' }}</th>
                            <th>{{ 'Phone number' }}</th>
                            <th>{{ 'SMS code' }}</th>
                            <th>{{ 'Is sent' }}</th>
                            <th>{{ 'Is valid' }}</th>
                            <th>{{ 'Created At' }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <tr>
                            <th class="column-searchable"><input class="form-control table-footer-search" /></th>
                            <th class="column-searchable"><input class="form-control table-footer-search" /></th>
                            <th class="column-searchable"><input class="form-control table-footer-search" /></th>
                            <th class="column-searchable">
                                <select class="form-control table-footer-search">
                                    <option value=""></option>
                                    <option value="true">True</option>
                                    <option value="false">False</option>
                                </select>
                            </th>
                            <th class="column-searchable">
                                <select class="form-control table-footer-search">
                                    <option value=""></option>
                                    <option value="true">True</option>
                                    <option value="false">False</option>
                                </select>
                            </th>
                            <th class="column-searchable"><input class="form-control table-footer-search" /></th>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('scripts')
    <style>
        th{
            vertical-align: center;
        }
        td{
            vertical-align: center;
        }
    </style>
    <script>
        $(function() {
            var sms_log_table = $('#sms-log-table').DataTable({
                "processing": true,
                "serverSide": true,
                "pageLength": 20,
                "lengthMenu": [[15, 30], [15, 30]],
                "order": [[ 5, "desc" ]],
                "ajax": {
                    "url": "{{ route('admin.sms_log.list') }}"
                },
                "columns": [
                    {data: 'phone_code', name: 'phone_code'},
                    {data: 'phone_number', name: 'phone_number'},
                    {data: 'code', name: 'code'},
                    {data: 'is_sent', name: 'is_sent'},
                    {data: 'is_valid', name: 'is_valid'},
                    {data: 'created_at', name: 'created_at'}
                ],
                "initComplete": function () {
                    this.api().columns().every(function () {
                        var column = this;
                        var column_class = column.footer().className;
                        if (column_class === 'column-searchable') {
                            var input = $(column.footer()).find('input');
                            var select = $(column.footer()).find('select');

                            if (input.length) {
                                input.on('change', function () {
                                    column.search($(this).val(), false, false, true).draw();
                                });
                            } else if (select.length) {
                                select.on('change', function () {
                                    column.search($(this).val(), false, false, true).draw();
                                });
                            }
                        }
                    });
                }
            });
        });
    </script>
@endsection