let Admin = {
    OnLastClick: null,
    OnLastButton: null,
    OnLoad: null,
    OnActiveEffect: null, /* PageList: {
        404: 'page-404',
        0: 'home_page',
        1: 'acceptor',
        2: 'client',
        3: 'category',
        4: 'cdc',
        5: 'anic',
        6: 'reports',
        7: 'application',
        8: 'comments',
        9: 'sms',
        10: 'Operator',
        11: 'agency',
        12: 'store'
        13: mobile-services
    }*/
    OnTableFixItem: null
};

$(function () {
    Admin.OnLoad = function (e) {
        let item = $('#system').find('li.item-menu.active').first().find('a');
        let mode = item.attr('target-mod');
        if (mode !== null) {
            Admin.OnLastButton = item;
            LoadData({request: 'proxy', action: mode}, LoadScreen(true), false, null);
            Admin.OnLastClick = mode;
        } else
            LoadData({request: 'proxy', action: 'page-404'}, LoadScreen(true), false, null);
    };
    Admin.OnTableFixItem = function () {
        return $.extend(true, {}, {
            exportOptions: {
                format: {
                    body: function (data, column, row) {
                        if (column === 5) {
                            data = data.replace(/<br\s*\/?>/ig, "\n");
                        }
                        return column === 1 ? data.replace(/<.*?>/ig, "") : data;
                    }
                }
            }
        }, {});
    };
    $(document).ready(function () {
        Admin.OnLoad(-1);
        Admin.OnActiveEffect = function () {
            $(function () {
                $.AdminBSB.browser.activate();
                $.AdminBSB.leftSideBar.activate();
                $.AdminBSB.rightSideBar.activate();
                $.AdminBSB.navbar.activate();
                $.AdminBSB.dropdownMenu.activate();
                $.AdminBSB.input.activate();
                $.AdminBSB.select.activate();
                $.AdminBSB.search.activate();
                $('[data-toggle="tooltip"]').tooltip({
                    container: 'body'
                });
                setTimeout(function () {
                    $('.page-loader-wrapper').fadeOut();
                }, 50);
            });
        };
        SideBarItemClick.find('a').unbind().bind("click", function (e) {
            let button = $(this);
            try {
                if (typeof button.attr('target-mod') !== typeof undefined && button.attr('target-mod') !== false) {
                    let target = button.attr('target-mod');
                    if (Admin.OnLastClick !== target) {
                        if (target !== null) {
                            LoadScreen(false);
                            if (Admin.OnLastButton !== null)
                                Admin.OnLastButton.parents('li').removeClass("active");
                            Admin.OnLastButton = button;
                            Admin.OnLastButton.parents('li').addClass("active");
                            if ((Admin.OnLastClick !== target)) {
                                Admin.OnLastClick = target;
                                LoadData({
                                    request: 'proxy',
                                    action: target
                                }, LoadScreen(true), false, null);
                                $("body").tooltip({selector: '[data-toggle=tooltip]'});
                            }
                        }
                    }
                }
            } catch (err) {
                console.log(err.message);
            }
        });

        // LoadData({request: 'proxy', action: 'page-404'}, LoadScreen(true), false, null);

    });
}(jQuery));