<?php
    use App\Packages\Core\Models\Report;

    $type_problem = Report::TYPE_PROBLEM;
    $type_feedback = Report::TYPE_FEEDBACK;

    $status_open = Report::STATUS_OPEN;
    $status_closed = Report::STATUS_CLOSED;
?>



<?php $__env->startSection('header'); ?>
    <?php echo e(trans('admin.head.support')); ?>


    &nbsp;&nbsp;

<?php $__env->stopSection(); ?>

<?php $__env->startSection('main'); ?>
    <div class="row">
        <div class="col-md-12">

            <div class="panel">
                <div class="table-primary">
                    <table class="table table-striped table-bordered" id="support-table" width="100%">
                        <thead>
                        <tr>
                            <th><?php echo e(trans('admin.fields.id')); ?></th>
                            <th><?php echo e(trans('admin.support.status')); ?></th>
                            <th><?php echo e(trans('admin.support.type')); ?></th>
                            <th><?php echo e(trans('admin.support.content')); ?></th>
                            <th><?php echo e(trans('admin.support.nickname')); ?></th>
                            <th><?php echo e(trans('admin.support.email')); ?></th>
                            <th><?php echo e(trans('admin.support.phone')); ?></th>
                            <th><?php echo e(trans('admin.fields.created')); ?></th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <tr>
                            <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="<?php echo e($status_open); ?>"><?php echo e(trans('admin.support.status_name.open')); ?></option>
                                    <option value="<?php echo e($status_closed); ?>"><?php echo e(trans('admin.support.status_name.closed')); ?></option>
                                </select>
                            </th>
                            <th class="column-searchable">
                                <select class="form-control table-footer-search">
                                    <option value=""></option>
                                    <option value="<?php echo e($type_problem); ?>"><?php echo e(trans('admin.support.type_name.problem')); ?></option>
                                    <option value="<?php echo e($type_feedback); ?>"><?php echo e(trans('admin.support.type_name.feedback')); ?></option>
                                </select>
                            </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"><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></th>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <style>
        th{
            vertical-align: center;
        }
        td{
            vertical-align: center;
        }
    </style>
    <script>
        $(function() {
            var support_table = $('#support-table').DataTable({
                "processing": true,
                "serverSide": true,
                "pageLength": 20,
                "lengthMenu": [[15, 30], [15, 30]],
                "order": [[ 0, "desc" ]],
                "ajax": {
                    "url": "<?php echo e(route('admin.support.list')); ?>"
                },
                "columns": [
                    {data: 'id', name: 'rep.id'},
                    {data: 'status', name: 'rep.status'},
                    {data: 'report_type', name: 'rep.report_type'},
                    {data: 'content', name: 'rep.content'},
                    {data: 'nickname', name: 'user.nickname'},
                    {data: 'email', name: 'user.email'},
                    {data: 'phone_number', name: 'user.phone_number'},
                    {data: 'created_at', name: 'rep.created_at'},
                    {
                        data: 'id',
                        name: 'id',
                        render: function (data, type, row) {
                            return "<a class='btn btn-xs btn-info' href='" + row.showLink + "'><?php echo e(__('admin.buttons.show')); ?></a>" +
                                "<a class='btn btn-xs btn-primary status-change-report' href='" + row.statusLink + "'><?php echo e(__('admin.support.toggle_status')); ?></a>" +
                                //"<a class='btn btn-xs btn-primary' href='" + row.editLink + "'><?php echo e(__('admin.buttons.edit')); ?></a>" +
                                "<a class='btn btn-xs btn-danger delete-report' href='" + row.deleteLink + "'><?php echo e(__('admin.buttons.delete')); ?></a>";
                        },
                        orderable: false,
                        searchable: false
                    }
                ],
                "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();
                                });
                            }
                        }
                    });
                }
            });

            $(document).on('click', '.status-change-report', function (e) {
                e.preventDefault();

                $.ajax({
                    url: $(this).attr('href'),
                    type: 'GET',
                    dataType: 'json',
                    data: { method: '_GET' }
                }).always(function (result) {
                    if (typeof result.status !== 'undefined' && result.status === 'success') {
                        support_table.draw(false);
                    }
                });
            });

            $(document).on('click', '.delete-report', function (e) {
                e.preventDefault();

                if (confirm('<?php echo e(__('admin.support.ask.delete')); ?>')) {
                    $.ajax({
                        url: $(this).attr('href'),
                        type: 'DELETE',
                        dataType: 'json',
                        data: { method: '_DELETE' }
                    }).always(function (result) {
                        if (typeof result.status !== 'undefined' && result.status === 'success') {
                            support_table.draw(false);
                        }
                    });
                }
            });
        });
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin._layout.layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/resources/views.admin/admin/support/list.blade.php ENDPATH**/ ?>