(function ($) {
    'use strict';

    var show_on_label = '#peeao_header_footer_action_show_on_label';
    var show_on = '#peeao_header_footer_action_show_on';
    var show_on_group = '#peeao_header_footer_action_show_on_group';
    var show_on_manual = '#peeao_header_footer_action_show_on_manual';

    $('input[name="peeao_header_footer_action"]').click(function(){
       
        if($(this).prop("checked") == true){
            $(show_on_label).show();
            $(show_on).show();

            var show_on_val = $(show_on).val();
            if(show_on_val == 'group'){
                $(show_on_group).show();
                $(show_on_manual).hide();
            }else if(show_on_val == 'manual'){
                $(show_on_manual).show();
                $(show_on_group).hide();
            }else{
                $(show_on_group).hide();
                $(show_on_manual).hide();
            }
            
        }else if($(this).prop("checked") == false){
            $(show_on).hide();
            $(show_on_group).hide();
            $(show_on_manual).hide();
            $(show_on_label).hide();
        }
    });


    var show_on_val = $(show_on).val();
    if(show_on_val == 'group'){
        $(show_on_group).show();
        $(show_on_manual).hide();
    }else if(show_on_val == 'manual'){
        $(show_on_manual).show();
        $(show_on_group).hide();
    }else{
        $(show_on_group).hide();
        $(show_on_manual).hide();
    }

    $(show_on).change(function(){
        if($(this).val() == 'manual'){
            $(show_on_manual).show();
            $(show_on_group).hide();
        }else if($(this).val() == 'group'){
            $(show_on_group).show(); 
            $(show_on_manual).hide();
        }else{
            $(show_on_manual).hide();
            $(show_on_group).hide();
        }
    })

    var urlParams = new URLSearchParams(window.location.search);

    if(urlParams.get('post_type') == 'peeao_header_footer'){
        var menu_id = $('#toplevel_page_power-elements-dashboard');
        menu_id.addClass('wp-has-current-submenu wp-menu-open');
        menu_id.addClass('wp-not-current-submenu');

        $('#toplevel_page_power-elements-dashboard .wp-submenu li:nth-child(2)').addClass('current');
    }
    if(urlParams.get('post_type') == 'peeao_nested'){
        var menu_id = $('#toplevel_page_power-elements-dashboard');
        menu_id.addClass('wp-has-current-submenu wp-menu-open');
        menu_id.addClass('wp-not-current-submenu');

        $('#toplevel_page_power-elements-dashboard .wp-submenu li:nth-child(3)').addClass('current');
    }
    if(urlParams.get('post_type') == 'peeao_block'){
        var menu_id = $('#toplevel_page_power-elements-dashboard');
        menu_id.addClass('wp-has-current-submenu wp-menu-open');
        menu_id.addClass('wp-not-current-submenu');

        $('#toplevel_page_power-elements-dashboard .wp-submenu li:nth-child(4)').addClass('current');
    }
    if(urlParams.get('post_type') == 'peeao_form'){
        var menu_id = $('#toplevel_page_power-elements-dashboard');
        menu_id.addClass('wp-has-current-submenu wp-menu-open');
        menu_id.addClass('wp-not-current-submenu');

        $('#toplevel_page_power-elements-dashboard .wp-submenu li:nth-child(6)').addClass('current');
    }
    if(urlParams.get('admin_tab') == 'widgets'){
        $('#toplevel_page_power-elements-dashboard .wp-submenu li:nth-child(5)').addClass('current');
    }
    if(urlParams.get('admin_tab') == 'integrations'){
        $('#toplevel_page_power-elements-dashboard .wp-submenu li:nth-child(7)').addClass('current');
    }

})(jQuery);