<!-- Form -->
<div class="content-animation animated">
    <div class="row clearfix fBTitrBold ">

        <!-- Exportable Table -->
        <div class="row clearfix text-center">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                <div class="card ">
                    <div class="header">
                        <h2>پیام های خوانده نشده</h2>
                    </div>
                    <div class="body ">
                        <div class="row">
                            <div class="col-md-12 ">
                                <div class="table-responsive text-center p-t-20 align-center no-overflow-y no-overflow-x">
                                    <table class="table table-bordered table-striped table-hover dataTable js-exportable-unread  text-center full_width align-center">
                                        <thead>
                                        <tr class="align-center">
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">وضعیت</td>
                                            <td class="text-center">نوع درخواست</td>
                                            <td class="text-center">نام - نام خانوادگی</td>
                                            <td class="text-center">شماره پیام</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </thead>
                                        <tbody class="bordered align-center text-center">


                                        </tbody>
                                        <tfoot>
                                        <tr class="align-center text-center">
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">وضعیت</td>
                                            <td class="text-center">نوع درخواست</td>
                                            <td class="text-center">نام - نام خانوادگی</td>
                                            <td class="text-center">شماره پیام</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Exportable Table -->
        <div class="row clearfix text-center">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                <div class="card ">
                    <div class="header">
                        <h2>پیام های خوانده شده</h2>
                    </div>
                    <div class="body ">
                        <div class="row">
                            <div class="col-md-12 ">
                                <div class="table-responsive text-center p-t-20 align-center no-overflow-y no-overflow-x">
                                    <table class="table table-bordered table-striped table-hover dataTable js-exportable-read text-center full_width align-center">
                                        <thead>
                                        <tr class="align-center text-center">
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">وضعیت</td>
                                            <td class="text-center">نوع درخواست</td>
                                            <td class="text-center">نام - نام خانوادگی</td>
                                            <td class="text-center">شماره پیام</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </thead>
                                        <tbody class="bordered align-center text-center"></tbody>
                                        <tfoot>
                                        <tr class="align-center text-center">
                                            <td class="text-center">تنظیمات</td>
                                            <td class="text-center">وضعیت</td>
                                            <td class="text-center">نوع درخواست</td>
                                            <td class="text-center">نام - نام خانوادگی</td>
                                            <td class="text-center">شماره پیام</td>
                                            <td class="text-center">شماره</td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- #END# Exportable Table -->
    </div>
</div>
<!-- #END# Form -->

<script type="text/javascript">
    (function ($) {

        let DataStructuresRequest = {
            tableRead: {
                table: null,
                OnInit: null,
            },
            tableUnread: {
                table: null,
                OnInit: null,
            },
            windowHelp: null,
            OnRead: null,
            OnDelete: null

        };


        DataStructuresRequest.OnRead = function (id) {
            if (DataStructuresRequest.windowHelp !== null)
                DataStructuresRequest.windowHelp.close();
            DataStructuresRequest.windowHelp = window.open('request_load.php?id=' + id + '&uid=' + user.uid + '', 'DataStructuresRequest.windowHelp', 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=768,height=350');
        };
        DataStructuresRequest.OnDelete = function (index, tr, table) {
            swal({
                title: "آیا این مورد حذف شود؟",
                text: "شما قادر به بازگردانی این مورد نخواهید بود",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله حذف شود",
                cancelButtonText: "نه حذف نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        object: {
                            user: user.uid,
                            ID: index
                        },
                        action: 'requestController',
                        "header-type": 'delete'
                    }, null, false, function (data) {
                        if (data === '1') {
                            tr.fadeOut(function (e) {
                                DataStructuresRequest[table].table.row(tr)
                                    .remove()
                                    .draw();
                            });
                            swal("حذف شد", "این مورد حذف شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        };

        DataStructuresRequest.tableUnread.OnInit = function () {
            if (DataStructuresRequest.tableUnread.table !== null)
                DataStructuresRequest.tableUnread.table.destroy();

            LoadData({
                request: 'proxy',
                object: {
                    user: user.uid,
                    mode: 'unread',
                },
                action: 'requestController',
                "header-type": "load"
            }, null, true, function (data) {
                DataStructuresRequest.tableUnread.table = $('.js-exportable-unread').DataTable({
                    "data": data,
                    "fnInitComplete": function (e) {
                        $(".js-exportable-unread tbody").find("button").unbind().bind("tap, click", function (e) {

                            let btn = $(this),
                                mode = btn.attr("data-mod");
                            switch (mode) {
                                case "request":
                                    let action = btn.attr("data-action"),
                                        id = btn.attr("data-id");
                                    switch (action) {
                                        case "delete-item":
                                            // OnDeleteButton(id, btn.parents('tr'));
                                            DataStructuresRequest.OnDelete(id, btn.parents('tr'), "tableUnread");
                                            break;
                                        case 'read-item':
                                            DataStructuresRequest.OnRead(id);
                                            break;
                                        default:
                                            break;
                                    }
                                    break;
                                default:
                                    break;
                            }
                        });
                    },
                    columns: [
                        {"data": "option"},
                        {"data": "state"},
                        {"data": "type"},
                        {"data": "full-name"},
                        {"data": "msg-code"},
                        {"data": "counter"}
                    ],
                    responsive: true,
                    "language": {
                        "lengthMenu": "نمایش _MENU_ کاربر در صفحه",
                        "zeroRecords": " چیزی یافت نشد",
                        "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                        "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                        "infoFiltered": "(filtered from _MAX_ total records)",
                        "paginate": {
                            "next": "بعدی",
                            "previous": "قبلی"
                        }
                    }
                });
            });

        };
        DataStructuresRequest.tableRead.OnInit = function () {
            if (DataStructuresRequest.tableUnread.table !== null)
                DataStructuresRequest.tableUnread.table.destroy();

            LoadData({
                request: 'proxy',
                object: {
                    user: user.uid,
                    mode: 'read',
                },
                action: 'requestController',
                "header-type": "load"
            }, null, true, function (data) {
                DataStructuresRequest.tableUnread.table = $('.js-exportable-read').DataTable({
                    "data": data,
                    "fnInitComplete": function (e) {
                        $(".js-exportable-read tbody").find("button").unbind().bind("tap, click", function (e) {

                            let btn = $(this),
                                mode = btn.attr("data-mod");
                            switch (mode) {
                                case "request":
                                    let action = btn.attr("data-action"),
                                        id = btn.attr("data-id");
                                    switch (action) {
                                        case "delete-item":
                                            // OnDeleteButton(id, btn.parents('tr'));
                                            DataStructuresRequest.OnDelete(id, btn.parents('tr'), "tableUnread");
                                            break;
                                        case 'read-item':
                                            DataStructuresRequest.OnRead(id);
                                            break;
                                        default:
                                            break;
                                    }
                                    break;
                                default:
                                    break;
                            }
                        });
                    },
                    columns: [
                        {"data": "option"},
                        {"data": "state"},
                        {"data": "type"},
                        {"data": "full-name"},
                        {"data": "msg-code"},
                        {"data": "counter"}
                    ],
                    responsive: true,
                    "language": {
                        "lengthMenu": "نمایش _MENU_ کاربر در صفحه",
                        "zeroRecords": " چیزی یافت نشد",
                        "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                        "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                        "infoFiltered": "(filtered from _MAX_ total records)",
                        "paginate": {
                            "next": "بعدی",
                            "previous": "قبلی"
                        }
                    }
                });
            });

        };

        $(document).ready(function () {

            DataStructuresRequest.tableUnread.OnInit();
            DataStructuresRequest.tableRead.OnInit();

        });
    }(jQuery));
</script>