<?php

namespace Breakdance\Admin;

use function Breakdance\BreakdanceOxygen\Strings\__bdox;

if (BREAKDANCE_MODE === 'breakdance') {
    add_action('admin_menu', 'Breakdance\Admin\breakdance_admin_menu');
} else if (BREAKDANCE_MODE === 'oxygen') {
    add_action('admin_menu', 'Breakdance\Admin\oxygen_admin_menu');
}

function breakdance_admin_menu()
{
    $formCap = \Breakdance\Forms\Submission\getFormSubmissionCapability();
    $hide_partner_discounts = \Breakdance\Data\get_global_option('settings_hide_partner_discounts') === 'yes';

    if (\Breakdance\Permissions\hasPermission('full')) {
        add_menu_page('Breakdance', 'Breakdance', 'edit_posts', 'breakdance', '', 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4gPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI2OCIgaGVpZ2h0PSI2OCIgdmlld0JveD0iMCAwIDQ5IDY4IiBmaWxsPSJub25lIj48cGF0aCBkPSJNMjcuODk5NCA2Ni4wMDFDMzEuNzA5OCA2Ni4wMDEgMzQuNzk4OCA2Mi45MTIgMzQuNzk4OCA1OS4xMDE2QzM0Ljc5ODggNTUuMjkxMSAzMS43MDk4IDUyLjIwMjEgMjcuODk5NCA1Mi4yMDIxQzI0LjA4OSA1Mi4yMDIxIDIxIDU1LjI5MTEgMjEgNTkuMTAxNkMyMSA2Mi45MTIgMjQuMDg5IDY2LjAwMSAyNy44OTk0IDY2LjAwMVoiIGZpbGw9ImJsYWNrIj48L3BhdGg+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00LjgzNCA0OC4zNEMzLjU1MTg0IDQ4LjMzOTIgMi4zMjI0NSA0Ny44Mjk0IDEuNDE2MDIgNDYuOTIyNkMwLjUwOTU4MSA0Ni4wMTU4IDAuMDAwMjY0ODI3IDQ0Ljc4NjIgMCA0My41MDRDMC4wMDEwN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NDcuODI5NSA2NS4zNTMyIDQ2LjkyMjkgNjYuMjU5NkM0Ni4wMTYzIDY3LjE2NiA0NC43ODcgNjcuNjc1NSA0My41MDUgNjcuNjc2QzQyLjIyMzEgNjcuNjc1NSA0MC45OTM5IDY3LjE2NiA0MC4wODc0IDY2LjI1OTZDMzkuMTgxIDY1LjM1MzEgMzguNjcxNSA2NC4xMjM5IDM4LjY3MSA2Mi44NDJWNTguMDA4QzM4LjY3MSA1Mi42NzEgMzQuMzM5IDQ4LjMzOSAyOS4wMDQgNDguMzM5TDQuODM0IDQ4LjM0WiIgZmlsbD0iYmxhY2siPjwvcGF0aD48L3N2Zz4g');
        add_submenu_page('breakdance', 'Home', 'Home', 'edit_posts', 'breakdance', 'Breakdance\Admin\breakdanceHomePage');
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('breakdance', 'Templates', 'Templates', 'edit_posts', BREAKDANCE_TEMPLATE_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('breakdance', 'Headers', 'Headers', 'edit_posts', BREAKDANCE_HEADER_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('breakdance', 'Footers', 'Footers', 'edit_posts', BREAKDANCE_FOOTER_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('breakdance', 'Global Blocks', 'Global Blocks', 'edit_posts', BREAKDANCE_BLOCK_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        add_submenu_page('breakdance', 'Popups', 'Popups', 'edit_posts', BREAKDANCE_POPUP_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        add_submenu_page('breakdance', 'Form Submissions', 'Form Submissions', $formCap, 'edit.php?post_type=breakdance_form_res');
        add_submenu_page('breakdance', 'Design Library', 'Design Library', 'manage_options', 'breakdance_design_library', "Breakdance\DesignLibrary\getDesignLibraryAppLoader");

        if (!$hide_partner_discounts) {
            /** @psalm-suppress UndefinedFunction  */
            add_submenu_page('breakdance', 'Partner Discounts', 'Partner Discounts', 'manage_options', 'breakdance-partner-discounts', 'Breakdance\Admin\render_breakdance_partner_discounts_page');
        }
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('breakdance', 'Quickstart', 'Quickstart', 'manage_options', 'breakdance_onboarding', 'Breakdance\Onboarding\getOnboardingAppLoader');

        bdox_run_action('breakdance_admin_menu');
    } else if (\Breakdance\Forms\Submission\canViewSubmissions()) {
        add_menu_page('Breakdance Form Submissions', 'Submissions', $formCap, 'edit.php?post_type=breakdance_form_res', '', 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4gPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI2OCIgaGVpZ2h0PSI2OCIgdmlld0JveD0iMCAwIDQ5IDY4IiBmaWxsPSJub25lIj48cGF0aCBkPSJNMjcuODk5NCA2Ni4wMDFDMzEuNzA5OCA2Ni4wMDEgMzQuNzk4OCA2Mi45MTIgMzQuNzk4OCA1OS4xMDE2QzM0Ljc5ODggNTUuMjkxMSAzMS43MDk4IDUyLjIwMjEgMjcuODk5NCA1Mi4yMDIxQzI0LjA4OSA1Mi4yMDIxIDIxIDU1LjI5MTEgMjEgNTkuMTAxNkMyMSA2Mi45MTIgMjQuMDg5IDY2LjAwMSAyNy44OTk0IDY2LjAwMVoiIGZpbGw9ImJsYWNrIj48L3BhdGg+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00LjgzNCA0OC4zNEMzLjU1MTg0IDQ4LjMzOTIgMi4zMjI0NSA0Ny44Mjk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EuNDE2MDJDNDcuODI5MSAyLjMyMjIxIDQ4LjMzODkgMy41NTExOSA0OC4zNCA0LjgzM1Y2Mi44NDJDNDguMzM5MiA2NC4xMjQgNDcuODI5NSA2NS4zNTMyIDQ2LjkyMjkgNjYuMjU5NkM0Ni4wMTYzIDY3LjE2NiA0NC43ODcgNjcuNjc1NSA0My41MDUgNjcuNjc2QzQyLjIyMzEgNjcuNjc1NSA0MC45OTM5IDY3LjE2NiA0MC4wODc0IDY2LjI1OTZDMzkuMTgxIDY1LjM1MzEgMzguNjcxNSA2NC4xMjM5IDM4LjY3MSA2Mi44NDJWNTguMDA4QzM4LjY3MSA1Mi42NzEgMzQuMzM5IDQ4LjMzOSAyOS4wMDQgNDguMzM5TDQuODM0IDQ4LjM0WiIgZmlsbD0iYmxhY2siPjwvcGF0aD48L3N2Zz4g');
        add_submenu_page('breakdance', 'Form Submissions', 'Form Submissions', 'editor', 'edit.php?post_type=breakdance_form_res');
    }
}


function oxygen_admin_menu()
{
    $hide_partner_discounts = \Breakdance\Data\get_global_option('settings_hide_partner_discounts') === 'yes';

    if (\Breakdance\Permissions\hasPermission('full')) {
        /** @psalm-suppress UndefinedFunction  */
        add_menu_page(
            'Oxygen',
            'Oxygen',
            'manage_options',
            'oxygen',
            '',
            'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzMiIGhlaWdodD0iMzMiIHZpZXdCb3g9IjAgMCAzMyAzMyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNi41IDI5LjVDMTcuNzgwNiAyOS41IDE5LjAxOCAyOS4zMTQ4IDIwLjE4NjggMjguOTY5OEMxOS43MjQyIDI4LjA3NDYgMTkuNDYzIDI3LjA1ODYgMTkuNDYzIDI1Ljk4MTVDMTkuNDYzIDIyLjM4MTQgMjIuMzgxN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', 'oxygen', 'Breakdance\Admin\oxygenHomePage');
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', 'Templates', 'Templates', 'edit_posts', BREAKDANCE_TEMPLATE_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', 'Headers', 'Headers', 'edit_posts', BREAKDANCE_HEADER_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', 'Footers', 'Footers', 'edit_posts', BREAKDANCE_FOOTER_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', __bdox('global_blocks'), __bdox('global_blocks'), 'edit_posts', BREAKDANCE_BLOCK_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', 'Design Library', 'Design Library', 'manage_options', 'breakdance_design_library', "Breakdance\DesignLibrary\getDesignLibraryAppLoader");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', __bdox('global_blocks'), __bdox('global_blocks'), 'manage_options', BREAKDANCE_BLOCK_POST_TYPE, "Breakdance\Themeless\ManageTemplates\getManageBreakdancePostTypesSpaHtml");
        /** @psalm-suppress UndefinedFunction  */
        add_submenu_page('oxygen', 'Design Library', 'Design Library', 'manage_options', 'oxygen_design_library', "Breakdance\DesignLibrary\getDesignLibraryAppLoader");
        if (!$hide_partner_discounts) {
            /** @psalm-suppress UndefinedFunction  */
            add_submenu_page('oxygen', 'Partner Discounts', 'Partner Discounts', 'manage_options', 'oxygen-partner-discounts', 'Breakdance\Admin\render_oxygen_partner_discounts_page');
        }

        bdox_run_action('breakdance_admin_menu');
    }
}
