
$(function () { // start of document ready:

    if ($(".panel-colors-wrapper")[0]) {
        $('.panel-color-item').each(function (i, obj) {
            $(this).click(function () {
                let color = $(this).find('.color-show').data('value');
                let theme = $(this).find('.color-show').data('theme');
                let btncolor = $(this).find('.color-show').data('btncolor');
                let btntxtcolor = $(this).find('.color-show').data('btntxtcolor');
                $('#panel-current-selected-color').attr("data-value",color);
                $('#panel-current-selected-color').attr("data-theme",theme);
                $('#panel-current-selected-color').attr("data-btncolor",btncolor);
                $('#panel-current-selected-color').attr("data-btntxtcolor",btntxtcolor);
                $('#panel-current-selected-color').css('background-color',color);
                $('.wrapper > aside.main-sidebar > div.sidebar').css('background-color',color);
                $('.wrapper > aside.main-sidebar > div.sidebar .nav-sidebar > .nav-item > .nav-treeview > .nav-item > a.active').css('background-color',btncolor);
                $('.wrapper > aside.main-sidebar > div.sidebar .nav-sidebar > .nav-item > .nav-treeview > .nav-item > a.active').css('color',btntxtcolor);
                $('.wrapper > aside.main-sidebar').removeClass('sidebar-light-primary');
                $('.wrapper > aside.main-sidebar').removeClass('sidebar-dark-primary');
                let sidebar_class = "sidebar-" + theme + "-primary";
                $('.wrapper > aside.main-sidebar').addClass(sidebar_class);
            });
        });
    }

    $('#panel_sidebar_state[type=checkbox]').change(
        function () {
            if (this.checked) {
                $('body.sidebar-mini').removeClass('sidebar-collapse');
                $('body.sidebar-mini').removeClass('sidebar-open');
                $('body.sidebar-mini').addClass('sidebar-open');
            } else {
                $('body.sidebar-mini').removeClass('sidebar-collapse');
                $('body.sidebar-mini').removeClass('sidebar-open');
                $('body.sidebar-mini').addClass('sidebar-collapse');
            }
        });

    $('#panel-color_edit_save').click(function () {

        let sidebar = "1";
        if ($('#panel_sidebar_state').is(":checked")) {
            sidebar = "0"; //ON means private
        }

        let sendData = {
            panel_sidebar_color: $('#panel-current-selected-color').data('value'),
            panel_sidebar_theme: $('#panel-current-selected-color').data('theme'),
            panel_sidebar_btn_color: $('#panel-current-selected-color').data('btncolor'),
            panel_sidebar_btn_txt_color: $('#panel-current-selected-color').data('btntxtcolor'),
            panel_sidebar_collapsed: sidebar
        }
        RequestSuperHandler(
            $(this), //Current Obj
            'آیا از ذخیره تغییرات اعمال شده بروی رنگ بندی پنل اطمینان دارید؟', //Alert Title
            '', //Alert Desc
            1, // alertType -> 1:confirm - 2:delete
            '/update_panelconfig', //Request URL
            "", //Return URL
            sendData
        );

    });

});