<?php
/**
 * Nexter Settings Panel
 *
 * @package    Nexter
 * @since    1.0.0
 */
if (!defined('ABSPATH')) {
    exit;
}

/**
 * White Label Content
 */
function nexter_white_label_content() {
    echo '<div class="nxt-pro-note-title"><p style="margin-bottom:50px;">' . esc_html__('White Label our plugin and setup client\'s branding all around. You can update name, description, Icon and even hide the menu from dashboard. Get our pro version to have access of this feature.', 'nexter-fse') . '</p></div>
		<div style="text-align:center;">
			<img style="width:55%;" src="' . esc_url(NEXTER_FSE_URI . 'assets/images/white-lable.png') . '" alt="' . esc_attr__('White Label', 'nexter-fse') . '" class="panel-plus-white-lable" />
		</div>';
}

add_action('nexter_white_label_notice', 'nexter_white_label_content');

/**
 * Activate Content
 */
function nexter_activate_content() {
    echo '<div class="nxt-active-notice-pro">
			<img style="width:55%;" src="' . esc_url(NEXTER_FSE_URI . 'assets/images/activate.png') . '" alt="' . esc_attr__('Activate', 'nexter-fse') . '" class="panel-plus-activate" />
			<div class="nxt-pro-active-msg">Have you already bought a <a href="' . esc_url('https://nexterwp.com/pricing/') . '" target="_blank" rel="noreferrer noopener">PRO</a> version? Visit store <a href="' . esc_url('https://store.posimyth.com/download/') . '" target="_blank" rel="noreferrer noopener">https://store.posimyth.com/download/</a> to download latest pro plugin</div>
		</div>';
}

add_action('nexter_activate_notice', 'nexter_activate_content');

/**
 * Performance Notice Content
 */
function nexter_site_performance_notice_content() {
    echo '<div class="nxt-pro-note-title"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/free-notice.svg') . '" alt="free-pro-notice"/><p style="margin-bottom:40px;">' . esc_html__('Sorry! You have to install & activate “Nexter Extension” plugin to use available option.', 'nexter-fse') . '</p></div>
		<div class="nxt-pro-note-link">' . wp_kses_post(nexter_ext_plugin_load_notice()) . '</div>';
}

add_action('nexter_site_performance_notice', 'nexter_site_performance_notice_content');

/**
 * Security Notice Content
 */
function nexter_site_security_notice_content() {
    echo '<div class="nxt-pro-note-title"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/free-notice.svg') . '" alt="free-pro-notice"/><p style="margin-bottom:40px;">' . esc_html__('Sorry! You have to install & activate “Nexter Extension” plugin to use available option.', 'nexter-fse') . '</p></div>
		<div class="nxt-pro-note-link">' . wp_kses_post(nexter_ext_plugin_load_notice()) . '</div>';
}

add_action('nexter_site_security_notice', 'nexter_site_security_notice_content');

/**
 * Extra Options Notice Content
 */
function nexter_site_extras_notice_content() {
    echo '<div class="nxt-pro-note-title"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/free-notice.svg') . '" alt="free-pro-notice"/><p style="margin-bottom:40px;">' . esc_html__('Sorry! You have to install & activate “Nexter Extension” plugin to use available option.', 'nexter-fse') . '</p></div>
		<div class="nxt-pro-note-link">' . wp_kses_post(nexter_ext_plugin_load_notice()) . '</div>';
}

add_action('nexter_site_extras_notice', 'nexter_site_extras_notice_content');

/**
 * Nexter Extensions load Notice
 */
function nexter_ext_plugin_load_notice() {
    $plugin = 'nexter-extension/nexter-extension.php';
    $output = '';
    $installed_plugins = get_plugins();
    if (isset($installed_plugins[$plugin])) {
        if (!current_user_can('activate_plugins')) {
            return;
        }
        $activation_url = wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin);
        $output .= sprintf('<a href="%s">%s</a>', $activation_url, esc_html__('Activate Nexter Extensions', 'nexter-fse'));
    } else {
        if (!current_user_can('install_plugins')) {
            return;
        }
        $install_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=nexter-extension'), 'install-plugin_nexter-extension');
        $output .= sprintf('<a href="%s">%s</a>', $install_url, esc_html__('Install Nexter Extension', 'nexter-fse'));
    }
    return wp_kses_post($output);
}

function nexter_help_actions_render() {
    echo '<div class="nxt-welcome-support-toggle" title="' . esc_attr__('Need Help?', 'nexter-fse') . '"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M202.021 0C122.202 0 70.503 32.703 29.914 91.026c-7.363 10.58-5.093 25.086 5.178 32.874l43.138 32.709c10.373 7.865 25.132 6.026 33.253-4.148 25.049-31.381 43.63-49.449 82.757-49.449 30.764 0 68.816 19.799 68.816 49.631 0 22.552-18.617 34.134-48.993 51.164-35.423 19.86-82.299 44.576-82.299 106.405V320c0 13.255 10.745 24 24 24h72.471c13.255 0 24-10.745 24-24v-5.773c0-42.86 125.268-44.645 125.268-160.627C377.504 66.256 286.902 0 202.021 0zM192 373.459c-38.196 0-69.271 31.075-69.271 69.271 0 38.195 31.075 69.27 69.271 69.27s69.271-31.075 69.271-69.271-31.075-69.27-69.271-69.27z"/></svg></div>';

    echo '<div class="nxt-welcome-support-content">';
    echo '<div class="nxt-sup-top">';
    echo '<h3 class="nxt-quick-sup-title">' . esc_html__('Quick support', 'nexter-fse') . '</h3>';
    if (defined('NXT_PRO_EXT') && class_exists('Nexter_Pro_Ext_Activate')) {
        $active_status = Nexter_Pro_Ext_Activate::nexter_ext_pro_activate_msg();
        if (!empty($active_status) && isset($active_status['status']) && $active_status['status'] == 'valid') {
            echo '<a class="nxt-sup-free-btn pro-activated" ><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/diamond.svg') . '" />' . esc_html__('PRO ACTIVATED', 'nexter-fse') . '</a>';
        }
    } else {
        echo '<a class="nxt-sup-free-btn">' . esc_html__('FREE', 'nexter-fse') . '</a>';
    }
    echo '</div>';
    echo '<div class="nxt-support-inner">';
    echo '<ul class="nxt-support-list">';
    echo '<li><a href="' . ((!defined('NXT_PRO_EXT')) ? esc_url('https://wordpress.org/support/theme/nexter/') : esc_url('https://store.posimyth.com/helpdesk/')) . '"  target="_blank" rel="noopener noreferrer"><span class="support-title-wrap"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/free-support-icon.svg') . '" />' . ((!defined('NXT_PRO_EXT')) ? esc_html__('Get Free Support', 'nexter-fse') : esc_html__('Get Premium Support', 'nexter-fse')) . '</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="16" fill="none" stroke="#22379c"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.4" d="m1 15 7-7-7-7" class="arrow-one"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.4" d="m1 15 7-7-7-7" class="arrow-two"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.4" d="m1 15 7-7-7-7" class="arrow-three"/></svg></a></li>';
    echo '<li><a href="' . ((!defined('NXT_PRO_EXT')) ? esc_url('https://roadmap.nexterwp.com/updates?filter=Free+Theme') : esc_url('https://roadmap.nexterwp.com/updates')) . '"  target="_blank" rel="noopener noreferrer"><span class="support-title-wrap sup-latest-update"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/support-latest-update.svg') . '" />' . esc_html__('Latest Updates', 'nexter-fse') . '</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="16" fill="none" stroke="#22379c"><path class="arrow-one" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-two" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-three" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg></a></li>';
    echo '<li><a href="' . esc_url('https://www.facebook.com/groups/139678088029161/') . '" target="_blank" rel="noopener noreferrer"><span class="support-title-wrap"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/support-join-fb.svg') . '" />' . esc_html__('Join Facebook Community', 'nexter-fse') . '</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="16" fill="none" stroke="#22379c"><path class="arrow-one" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-two" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-three" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg></a></li>';
    echo '<li><a href="' . esc_url('https://roadmap.nexterwp.com/boards/feature-requests') . '" target="_blank" rel="noopener noreferrer"><span class="support-title-wrap"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/support-new-fea.svg') . '" />' . esc_html__('Suggest New Features', 'nexter-fse') . '</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="16" fill="none" stroke="#22379c"><path class="arrow-one" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-two" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-three" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg></a></li>';
    echo '<li><a href="' . esc_url('https://roadmap.nexterwp.com/boards/bug') . '" target="_blank" rel="noopener noreferrer"><span class="support-title-wrap"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/support-report-bug.svg') . '" />' . esc_html__('Report Bug', 'nexter-fse') . '</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="16" fill="none" stroke="#22379c"><path class="arrow-one" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-two" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/><path class="arrow-three" d="m1 15 7-7-7-7" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg></a></li>';
    echo '</ul>';
    if (!defined('NXT_PRO_EXT')) {
        echo '<a href="' . esc_url('https://nexterwp.com/pricing/') . '" class="sup-upgrade-get-pro"><img src="' . esc_url(NEXTER_FSE_URI . '/assets/images/panel-icon/sup-upgrade-pro.svg') . '" />' . esc_html__('Upgrade to PRO Version', 'nexter-fse') . '</a>';
    }
    echo '<div class="nxt-panel-row" style="justify-content: space-between;">';
    echo '<a href="' . esc_url('https://www.youtube.com/c/POSIMYTHInnovations/?sub_confirmation=1') . '" class="nxt-panel-col sup-social-link" title="' . esc_html__('Youtube', 'nexter-fse') . '" target="_blank" rel="noopener noreferrer"><span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="none"><path d="M13.69 4.09a1.76 1.76 0 0 0-1.24-1.24c-1.09-.3-5.45-.3-5.45-.3s-4.36 0-5.45.3C.95 3 .48 3.48.3 4.09.02 5.19.02 7.47.02 7.47s0 2.29.3 3.38c.16.6.63 1.06 1.23 1.22 1.09.3 5.45.3 5.45.3s4.36 0 5.45-.3c.6-.16 1.07-.62 1.24-1.22.29-1.1.29-3.38.29-3.38s0-2.29-.3-3.38zM5.57 9.54V5.4l3.65 2.07-3.65 2.07z" fill="#22379b"/></svg></span></a>';
    echo '<a href="' . esc_url('https://twitter.com/posimyth') . '" class="nxt-panel-col sup-social-link" title="' . esc_html__('Twitter', 'nexter-fse') . '" target="_blank" rel="noopener noreferrer"><span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="none"><path d="m12.56 4.15.01.37c0 3.8-2.89 8.16-8.16 8.16A8.11 8.11 0 0 1 0 11.4a5.86 5.86 0 0 0 4.25-1.2 2.88 2.88 0 0 1-2.68-1.98 3.62 3.62 0 0 0 .54.04c.26 0 .52-.03.76-.1a2.87 2.87 0 0 1-2.3-2.81V5.3a2.89 2.89 0 0 0 1.3.37 2.87 2.87 0 0 1-1.28-2.4 2.85 2.85 0 0 1 .39-1.44 8.16 8.16 0 0 0 5.91 3 3.24 3.24 0 0 1-.07-.66A2.87 2.87 0 0 1 9.7 1.32a2.86 2.86 0 0 1 2.1.9 5.65 5.65 0 0 0 1.82-.7 2.86 2.86 0 0 1-1.26 1.59A5.75 5.75 0 0 0 14 2.67a6.17 6.17 0 0 1-1.44 1.48z" fill="#22379b"/></svg></span></a>';
    echo '<a href="' . esc_url('https://www.facebook.com/nexterwp') . '" class="nxt-panel-col sup-social-link" title="' . esc_html__('Facebook', 'nexter-fse') . '" target="_blank" rel="noopener noreferrer"><span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="none"><path d="m10.26 7.88.39-2.54H8.2V3.7c0-.7.34-1.37 1.43-1.37h1.1V.17S9.75 0 8.8 0c-2 0-3.31 1.21-3.31 3.41v1.93H3.25v2.54h2.23V14H8.2V7.87h2.05z" fill="#22379b"/></svg></span></a>';
    echo '<a href="' . esc_url('https://www.instagram.com/posimyth') . '" class="nxt-panel-col sup-social-link" title="' . esc_html__('Instagram', 'nexter-fse') . '" target="_blank" rel="noopener noreferrer"><span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="none"><path d="M7 3.85a3.14 3.14 0 1 0 0 6.28 3.14 3.14 0 0 0 0-6.28zm0 5.19a2.05 2.05 0 1 1 .01-4.1 2.05 2.05 0 0 1 0 4.1zm4-5.31a.73.73 0 1 1-1.46 0 .73.73 0 1 1 1.47 0zm2.09.74c-.05-.98-.27-1.85-1-2.57S10.52.96 9.54.91a74.77 74.77 0 0 0-5.06 0c-.98.05-1.84.27-2.56.99S.96 3.49.9 4.47a74.77 74.77 0 0 0 0 5.05c.05.99.28 1.85 1 2.57s1.58.94 2.56 1c1.02.05 4.05.05 5.06 0 .98-.05 1.85-.28 2.57-1s.94-1.58.99-2.57c.06-1 .06-4.04 0-5.05zm-1.31 6.14c-.21.54-.63.95-1.17 1.16-.8.32-2.72.25-3.6.25s-2.82.07-3.62-.25a2.07 2.07 0 0 1-1.16-1.16C1.9 9.8 1.98 7.89 1.98 7s-.07-2.81.25-3.61c.2-.54.62-.95 1.16-1.17.8-.32 2.72-.25 3.61-.25s2.81-.07 3.61.25a2.07 2.07 0 0 1 1.17 1.17c.32.8.25 2.72.25 3.6s.07 2.82-.25 3.62z" fill="#22379b"/></svg></span></a>';
    echo '<a href="' . esc_url('https://nexterwp.com/blog') . '" class="nxt-panel-col sup-social-link" title="' . esc_html__('Blogs', 'nexter-fse') . '" target="_blank" rel="noopener noreferrer"><span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="none"><path d="M1.57 4.82a.66.66 0 0 0-.7.6c-.02.37.26.68.62.7a7.06 7.06 0 0 1 6.38 6.39c.03.35.32.62.63.62h.05a.66.66 0 0 0 .61-.7 8.34 8.34 0 0 0-7.59-7.61zM1.75.87a.87.87 0 1 0 0 1.75 9.64 9.64 0 0 1 9.63 9.63.87.87 0 1 0 1.74 0A11.39 11.39 0 0 0 1.76.87zm.85 8.75c-.94 0-1.73.79-1.73 1.76s.79 1.74 1.73 1.74a1.77 1.77 0 0 0 1.75-1.74c0-.97-.76-1.76-1.75-1.76z" fill="#22379b"/></svg></span></a>';
    echo '<a href="' . esc_url('https://store.posimyth.com/join-affiliate/') . '" class="nxt-panel-col sup-social-link" title="' . esc_html__('Join Affliate', 'nexter-fse') . '" target="_blank" rel="noopener noreferrer"><span><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="none"><path d="M7.03 11.87c-.65 0-1.24-.07-1.76-.23a4.31 4.31 0 0 1-1.5-.87 1.1 1.1 0 0 1-.28-.35.87.87 0 0 1-.1-.4.79.79 0 0 1 .22-.55.78.78 0 0 1 .6-.26.74.74 0 0 1 .47.17 3.37 3.37 0 0 0 3.3.73 2 2 0 0 0 .7-.43.9.9 0 0 0 .27-.63 1.06 1.06 0 0 0-.25-.72c-.17-.2-.43-.36-.77-.49a5.66 5.66 0 0 0-1.32-.32c-.5-.08-.95-.19-1.33-.34-.38-.16-.7-.35-.97-.58a2.45 2.45 0 0 1-.57-.84c-.13-.33-.2-.7-.2-1.1a2.6 2.6 0 0 1 1.74-2.53 4.87 4.87 0 0 1 4.72.63c.27.21.4.46.4.74 0 .2-.07.4-.23.56s-.35.25-.56.25a.61.61 0 0 1-.38-.12 2.37 2.37 0 0 0-.6-.37 4.52 4.52 0 0 0-.8-.29 2.98 2.98 0 0 0-1.8.03c-.28.1-.48.24-.62.42s-.21.38-.21.61c0 .28.08.52.23.7.17.18.41.33.72.44a9.02 9.02 0 0 0 1.1.28c.56.1 1.05.22 1.47.36.43.14.79.32 1.07.55a1.98 1.98 0 0 1 .63.82c.14.33.2.73.2 1.2 0 .61-.16 1.14-.5 1.58s-.77.77-1.32 1c-.55.24-1.13.35-1.77.35zm1 .76a.8.8 0 0 1-.24.6.8.8 0 0 1-.6.25.78.78 0 0 1-.6-.25.81.81 0 0 1-.23-.6V1.37A.84.84 0 0 1 7.2.52c.25 0 .44.08.6.25.15.16.23.36.23.6v11.26z" fill="#22379c"/></svg></span></a>';
    echo '</div>';
    echo '</div>';
    echo '<a href="' . esc_url('https://posimyth.com/') . '" class="nxt-support-bottom" target="_blank" rel="noopener noreferrer">' . esc_html__('Powered by POSIMYTH Innovations', 'nexter-fse') . '</a>';
    echo '</div>';
}

add_action('nexter_help_actions', 'nexter_help_actions_render');

class Nexter_Fse_Settings_Panel {

    /**
     * Option key, and option page slug
     */
    private $key = 'nexter_settings_opts';

    /**
     * Array of meta boxes/fields
     * @var array
     */
    protected $option_metabox = array();

    /**
     * Setting Name/Title
     * @var string
     */
    protected $setting_name = '';

    /**
     * Constructor
     * @since 1.0.0
     */
    public function __construct() {
        add_action('init', [$this, 'initialize_plugin_name']);
        $this->fields = array();
    }

    public function initialize_plugin_name() {
		if (defined('NXT_PRO_EXT')) {
            $options = get_option('nexter_white_label');
            $this->setting_name = (!empty($options['brand_name'])) ? $options['brand_name'] . esc_html__(' Settings', 'nexter-fse') : esc_html__('Nexter Settings', 'nexter-fse');
        } else {
            $this->setting_name = esc_html__('Nexter Settings', 'nexter-fse');
        }
	}

    /**
     * Initiate hooks
     * @since 1.0.11
     */
    public function hooks() {
        add_action('admin_init', array($this, 'init'));
        add_action('admin_menu', array($this, 'nxt_add_menu_page'));

        add_action('wp_ajax_nexter_import_activate_builder', [$this, 'nexter_import_activate_builder_ajax']);

        add_action('wp_ajax_nexter_ext_save_data', [$this, 'nexter_ext_save_data_ajax']);
    }

    /*
     * Save Nexter Extension Data
     * @since 1.1.0
     */
    public function nexter_ext_save_data_ajax() {
        check_ajax_referer('nexter_fse_admin_nonce', 'nexter_nonce');
        $ext = (isset($_POST['extension_type'])) ? sanitize_text_field(wp_unslash($_POST['extension_type'])) : '';

        $wpWLSet = (isset($_POST['wpWLSet'])) ? wp_unslash($_POST['wpWLSet']) : '';

        $option_page = 'nexter_extra_ext_options';
        $get_option = get_option($option_page);

        $wlOption = 'nexter_white_label';
        $get_wl_option = get_option($wlOption);

        if (!empty($ext) && $ext === 'white-label' && !empty($wpWLSet)) {
            $whiteLabelData = (array)json_decode($wpWLSet);
            if (False === $get_wl_option) {
                add_option($wlOption, $whiteLabelData);
            } else {
                update_option($wlOption, $whiteLabelData);
            }
            wp_send_json_success();
        }

        wp_send_json_error();
    }

    public function nexter_import_activate_builder_ajax() {
        check_ajax_referer('nexter_fse_admin_nonce', 'nexter_nonce');

        if (!current_user_can('install_plugins') || !isset($_POST['file']) || !sanitize_text_field(wp_unslash($_POST['file']))) {
            wp_send_json_error(
                array(
                    'success' => false,
                    'content' => __('No plugin..', 'nexter-fse'),
                )
            );
        }

        $file = (isset($_POST['file'])) ? sanitize_text_field(wp_unslash($_POST['file'])) : '';

        $activate = activate_plugin($file, '', false, true);

        if (is_wp_error($activate)) {
            wp_send_json_error(
                array(
                    'success' => false,
                    'content' => $activate->get_error_message(),
                )
            );
        }

        wp_send_json_success(
            array(
                'success' => true,
                'content' => __('Activated', 'nexter-fse'),
            )
        );

    }

    /**
     * Register nexter setting to WP
     */
    public function init() {
        $option_tabs = self::option_fields();

        foreach ($option_tabs as $index => $option_tab) {
            register_setting($option_tab['id'], $option_tab['id']);
        }
    }

    /**
     * Add menu options page
     */
    public function nxt_add_menu_page() {
        $option_tabs = self::option_fields();
        global $_registered_pages, $submenu;

        unset($submenu['themes.php'][20]);
        unset($submenu['themes.php'][15]);

        foreach ($option_tabs as $index => $option_tab) {
            if ($index == 0) {
                add_theme_page($this->setting_name, $this->setting_name, 'manage_options', $option_tab['id'], array(
                    $this,
                    'admin_page_display'
                ));
            } else {
                if (isset($option_tabs) && $option_tab['id'] != "nexter_white_label" && $option_tab['id'] != "nexter_activate") {
                    $function_name = array($this, 'admin_page_display');
                    $hookname = get_plugin_page_hookname($option_tab['id'], $option_tabs[0]['id']);
                    if (!empty($function_name) && !empty($hookname)) {
                        add_action($hookname, $function_name);
                    }
                    $_registered_pages[$hookname] = true;    // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
                } else {
                    $label_options = get_option('nexter_white_label');
                    if (((empty($label_options['nxt_hidden_label']) || $label_options['nxt_hidden_label'] != 'on') && ($option_tab['id'] == "nexter_white_label" || $option_tab['id'] == "nexter_activate")) || !defined('NXT_PRO_EXT_VER')) {
                        $function_name = array($this, 'admin_page_display');
                        $hookname = get_plugin_page_hookname($option_tab['id'], $option_tabs[0]['id']);
                        if (!empty($function_name) && !empty($hookname)) {
                            add_action($hookname, $function_name);
                        }
                        $_registered_pages[$hookname] = true;    // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
                    }
                }
            }
        }
    }

    /**
     * Theplus Gutenberg Display Page
     * @since  1.0.0
     */
    public function admin_page_display() {
        $option_tabs = self::option_fields();
        $tab_forms = array();

        $output = '';

        $output .= '<div class="' . esc_attr($this->key) . '">';

        $output .= '<div id="nxt-setting-header-wrapper">';
        $output .= '<div class="nxt-head-inner">';

        $options = get_option('nexter_white_label');
        if (defined('NXT_PRO_EXT') && (!empty($options['theme_logo']))) {
            $output .= '<img src="' . esc_url($options['theme_logo']) . '" style="max-width:150px;"/>';
        } else {
            $output .= '<svg xmlns="http://www.w3.org/2000/svg" width="202" height="65" fill="none"><g fill="#fff" clip-path="url(#a)"><path d="M45.61 22.466 35.309.178h-6.902v63.227h6.902V11.51l10.288 22.284.015 29.612h6.902V.178H45.61v22.288ZM104.905 38.569c0 .449-.27.798-.808 1.052l-4.368 1.69-4.374-1.664c-.54-.247-.808-.603-.808-1.055V.026L87.652 0v38.694c0 2.166 1.313 3.881 3.938 5.147l1.236.589-1.236.591c-2.626 1.266-3.938 2.978-3.938 5.138v13.066h6.914V50.331c0-.466.27-.845.808-1.1l4.355-1.683 4.35 1.684c.538.254.808.624.808 1.099v12.894h6.928V50.16c0-2.158-1.314-3.87-3.94-5.138l-1.237-.591 1.237-.59c2.623-1.265 3.937-2.98 3.94-5.146V0h-6.91v38.569ZM119.4 5.578l8.314-.007v57.834h6.884l.023-57.834h8.302V.178h-23.516l-.007 5.4ZM197.181 51.037c2.92-.986 4.379-2.799 4.376-5.438V6.08c0-1.631-.753-3.028-2.241-4.193C197.828.722 196.72.133 194.673.133H178.06v63.232h6.902v-9.627h7.035c.058 0 .107.02.161.028.304.032.602.105.887.217.093.032.177.07.263.109l.07.033c.459.205.835.56 1.067 1.006l.027.05c.043.092.079.186.108.283.021.063.04.128.055.193.054.229.081.463.082.699l-.033 7.011h6.91v-6.846c0-2.643-1.481-4.474-4.402-5.482l-.011-.002Zm-2.497-4.972a1.977 1.977 0 0 1-.866 1.6c-.6.459-1.34.697-2.096.675h-6.753V5.57h8.109c.406-.008.803.119 1.129.361a1.072 1.072 0 0 1 .487.902l-.01 39.232ZM60.107 63.398h19.955v-5.405H67.028v-10.83h9.238v-5.399h-9.238V5.571h13.034V.173H60.107v63.225ZM150.51 5.578l13.041.007v14.12h-9.236v5.404h9.229v32.896H150.51v5.4h19.962V.178H150.51v5.4ZM10.36 57.176l-.032 7.196H0v-9.995h7.47c.066 0 .115.023.17.03.32.036.633.114.932.233.096.033.193.075.284.114.023.017.05.026.072.042a2.33 2.33 0 0 1 1.13 1.071l.032.056c.047.097.085.197.114.3.025.07.044.14.056.212.06.242.09.49.089.739M10.328 4.05v42.08c0 .657-.3 1.225-.918 1.714a3.46 3.46 0 0 1-2.233.722H0V2.69h8.616c.433-.009.856.128 1.202.389a1.165 1.165 0 0 1 .51.966"></path></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h201.571v64.371H0z"></path></clipPath></defs></svg>';
        }
        $output .= '<div class="nxt-panel-head-inner">';
        $output .= '<h2 class="nxt-head-setting-panel">' . esc_html__('Settings', 'nexter-fse') . '</h2>';
        $output .= '<div class="nxt-current-version"> ' . esc_html__('Version', 'nexter-fse') . ' ' . NEXTER_FSE_VERSION . '</div>';
        $output .= '</div>';
        $output .= '</div>';

        $output .= '<div class="nxt-nav-tab-wrapper">';
        $output .= '<div class="nav-tab-wrapper">';
        ob_start();
        foreach ($option_tabs as $option_tab):
            $tab_slug = $option_tab['id'];
            $nav_class = 'nav-tab';
            if (isset($_GET['page']) && $tab_slug == $_GET['page']) {
                $nav_class .= ' nav-tab-active'; //add active class to current tab
                $tab_forms[] = $option_tab; //add current tab to forms to be rendered
            }
            $navicon = $nav_url = '';

            if ($tab_slug == "nexter_settings_welcome") {
                wp_enqueue_script('nexter-fse-panel-setting');
            }
            if ($tab_slug == "nexter_settings_welcome") {
                $nav_url = menu_page_url($tab_slug, false);
                $navicon = '<svg class="tab-nav-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.56 1.5a.67.67 0 0 1 .88 0L16 4.64v-.97c0-.56-.05-.67.5-.67h4c.55 0 .5.11.5.67v5.5l2.5 2.16c.28.24.66.55.4.89-.2.28-.62.28-.9 0l-2-1.72v8.83c0 1.85-1.16 2.67-3 2.67H6c-1.84 0-3-.82-3-2.67V10.5l-2 1.72c-.28.28-.63.28-.87 0-.24-.31.1-.65.37-.89L11.56 1.5ZM20 8.3V4h-3v1.82l3 2.48ZM4 9.62v9.71c0 1.1.9 1.67 2 1.67h3v-6.33c0-.74.26-.67 1-.67h4c.74 0 1-.07 1 .67V21h3c1.1 0 2-.56 2-1.67v-9.7l-8-6.97-8 6.96ZM10 15v6h4v-6h-4Z"/></svg>';
            }
            if ($tab_slug == "nexter_activate") {
                $nav_url = admin_url('admin.php?page=' . $tab_slug);
                $navicon = '<svg class="tab-nav-icon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_1467_14917)"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.24 10.16a7 7 0 1 1 5.59 4.77l-.06-.01a.5.5 0 0 0-.41.14l-2.45 2.45H9.1a.5.5 0 0 0-.5.5v2.5h-2.5a.5.5 0 0 0-.5.5v2h-4.5v-4.3l8-8a.5.5 0 0 0 .15-.32.55.55 0 0 0-.02-.22Zm10.07 5.08a8 8 0 0 1-4.42.7l-2.42 2.42a.5.5 0 0 1-.35.15h-2.5V21a.5.5 0 0 1-.5.5h-2.5v2a.5.5 0 0 1-.5.5H.62a.5.5 0 0 1-.5-.5v-5a.5.5 0 0 1 .14-.35l7.95-7.95a8 8 0 1 1 11.1 5.03ZM18.02 7.3a1 1 0 1 1-1.41-1.42 1 1 0 0 1 1.41 1.42Zm.7.7a2 2 0 1 1-2.82-2.82A2 2 0 0 1 18.73 8Z"/></g><defs><clipPath id="clip0_1467_14917"><path d="M0 0h24v24H0z"/></clipPath></defs></svg>';
            }
            if ($tab_slug == "nexter_site_performance") {
                $nav_url = admin_url('admin.php?page=' . $tab_slug);
                $navicon = '<svg class="tab-nav-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0 1a10 10 0 1 0 0-20 10 10 0 0 0 0 20ZM6.02 11.5a6 6 0 0 1 8.54-4.93l.07.03c.23.07.5-.01.62-.23a.47.47 0 0 0-.19-.67 7.25 7.25 0 0 0-.07-.03l-.06-.03a7 7 0 0 0-9.9 5.72v.06l-.01.08c-.02.28.2.5.48.5a.53.53 0 0 0 .52-.5Zm11.45-1.97a.53.53 0 0 1 .21-.68.47.47 0 0 1 .67.2l.03.07.02.05a7 7 0 0 1 .57 2.2v.05l.01.08c.02.28-.2.5-.48.5a.53.53 0 0 1-.52-.5 6 6 0 0 0-.5-1.97ZM12 13a1 1 0 1 0 0-2 1 1 0 0 0 0 2Zm0 1a2 2 0 0 0 1.58-3.22l3.72-3.72a.5.5 0 1 0-.7-.7l-3.81 3.8A2 2 0 0 0 10 12c0 1.1.9 2 2 2Z"/></svg>';
            }
            if ($tab_slug == "nexter_site_security") {
                $nav_url = admin_url('admin.php?page=' . $tab_slug);
                $navicon = '<svg class="tab-nav-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.82 1.53a.5.5 0 0 1 .36 0l8 3c.2.08.32.26.32.47v7c0 3.22-2.14 5.85-4.17 7.63a22.18 22.18 0 0 1-4.08 2.8l-.02.01L12 22l-.22.45h-.01l-.02-.02a8.81 8.81 0 0 1-.34-.18 22.17 22.17 0 0 1-3.74-2.63C5.64 17.86 3.5 15.23 3.5 12V5c0-.2.13-.4.32-.47l8-3ZM12 22l.22.45a.5.5 0 0 1-.44 0L12 22Zm0-.57a13.58 13.58 0 0 1-.98-.57 21.2 21.2 0 0 1-2.7-1.99C6.37 17.15 4.5 14.77 4.5 12V5.35L12 2.53l7.5 2.82V12c0 2.78-1.86 5.15-3.83 6.87A21.2 21.2 0 0 1 12 21.43ZM12 11a1 1 0 1 0 0-2 1 1 0 0 0 0 2Zm-.5.94v2.56a.5.5 0 0 0 1 0v-2.56a2 2 0 1 0-1 0Z"/></svg>';
            }

            if ($tab_slug == "nexter_extra_options") {
                $nav_url = admin_url('admin.php?page=' . $tab_slug);
                $navicon = '<svg class="tab-nav-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.5 6a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm.96-.5a3 3 0 0 0-5.92 0H2a.5.5 0 0 0 0 1h2.54a3 3 0 0 0 5.92 0H22a.5.5 0 0 0 0-1H10.46ZM13.5 18a2 2 0 1 0-4 0 2 2 0 0 0 4 0Zm-4.96-.5H2a.5.5 0 0 0 0 1h6.54a3 3 0 0 0 5.92 0H22a.5.5 0 0 0 0-1h-7.54a3 3 0 0 0-5.92 0ZM1.5 12c0-.28.22-.5.5-.5h14.04a3 3 0 1 1 0 1H2a.5.5 0 0 1-.5-.5ZM19 14a2 2 0 1 1 0-4 2 2 0 0 1 0 4Z"/></svg>';
            }

            if ($tab_slug == "nexter_white_label") {
                $nav_url = admin_url('admin.php?page=' . $tab_slug);
                $navicon = '<svg class="tab-nav-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M18.18 7.93a.94.94 0 1 1-.33-.82 1.78 1.78 0 0 0 .72-.7h-.02l-3.77-.23c-1.46-.09-2.9.4-4.01 1.36l-6.3 5.47a.66.66 0 0 0-.06.93l5.52 6.1c.24.26.65.29.92.05l6.36-5.52c1.1-.95 1.8-2.3 1.92-3.76l.3-3.39a.93.93 0 0 0-.09-.48 2.73 2.73 0 0 1-1.14 1.04l-.02-.05Zm1.55-2.23-.02.21c.44.38.7.96.65 1.6l-.3 3.38c-.08 1-.39 1.94-.89 2.78v6.67c0 .47-.38.85-.84.85h-7.8a1.6 1.6 0 0 1-1.3-.52l-5.51-6.1a1.6 1.6 0 0 1 .13-2.27l6.3-5.46a6.56 6.56 0 0 1 4.16-1.6 2.72 2.72 0 0 1 5.42.46ZM12.1 20.25h6.13V14.9l-.4.38-5.73 4.97Zm6.5-15.52c.12.24.19.5.2.76a1.9 1.9 0 0 0-.2-.02l-3.35-.2a1.78 1.78 0 0 1 3.36-.54ZM6.54 12.64c.2-.17.5-.16.67.03l1.85 2.05a.47.47 0 0 1-.69.63L6.5 13.3a.47.47 0 0 1 .03-.67Z"/></svg>';
            }

            $label_options = get_option('nexter_white_label');
            if ((empty($label_options['nxt_hidden_label']) || $label_options['nxt_hidden_label'] != 'on') && ($tab_slug == "nexter_white_label" || $tab_slug == "nexter_activate")) {
                echo '<a class="' . esc_attr($nav_class) . '" href="' . esc_url($nav_url) . '">';
                echo '<span>' . $navicon . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                echo '<span>' . esc_html($option_tab['title']) . '</span>';
                echo '</a>';
            } else if (($tab_slug != "nexter_white_label" && $tab_slug != "nexter_activate") || !defined('NXT_PRO_EXT_VER')) {
                echo '<a class="' . esc_attr($nav_class) . '" href="' . esc_url($nav_url) . '">';
                echo '<span>' . $navicon . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                echo '<span>' . esc_html($option_tab['title']) . '</span>';
                echo '</a>';
            }
        endforeach;
        $out = ob_get_clean();
        $output .= $out;
        $output .= '</div>';
        $output .= '</div>';

        $output .= '</div>';


        /*Content Options*/
        $output .= '<div class="nxt-settings-form-wrapper form-' . esc_attr($tab_forms[0]['id']) . '">';

        if (!empty($tab_forms)) {
            ob_start();
            foreach ($tab_forms as $tab_form):

                if ($tab_form['id'] == 'nexter_white_label') {
                    do_action('nexter_white_label_notice');
                } else if ($tab_form['id'] == 'nexter_activate') {
                    do_action('nexter_activate_notice');
                } else if ($tab_form['id'] == 'nexter_extra_options') {
                    do_action('nexter_site_extras_notice');
                } else if (!defined('NEXTER_EXT') && $tab_form['id'] == 'nexter_site_performance') {
                    do_action('nexter_site_performance_notice');
                } else if (!defined('NEXTER_EXT') && $tab_form['id'] == 'nexter_site_security') {
                    do_action('nexter_site_security_notice');
                }

                if ((defined('NXT_PRO_EXT') && $tab_form['id'] == 'nexter_white_label') || (defined('NEXTER_EXT') && ($tab_form['id'] == 'nexter_site_performance' || $tab_form['id'] == 'nexter_site_security') || $tab_form['id'] == 'nexter_extra_options')) {
                    do_action('nexter_ext_extra_option', $tab_form['id']);
                } else if ($tab_form['id'] == 'nexter_settings_welcome') {
                    include_once NEXTER_FSE_DIR . 'inc/panel-settings/welcome-page.php';
                }
            endforeach;
            do_action('nexter_help_actions');
            $out = ob_get_clean();
            $output .= $out;
        }
        $output .= '</div>';

        $output .= '</div>';

        echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

    }

    /**
     * Nexter Settings fields configuration
     */
    public function option_fields() {
        // Only need to initiate the array once per page-load
        if (!empty($this->option_metabox)) {
            return $this->option_metabox;
        }

        $this->option_metabox[] = array(
            'id' => 'nexter_settings_welcome',
            'title' => esc_html__('Welcome', 'nexter-fse'),
            'show_on' => array(
                'key' => 'options-page',
                'value' => array(
                    'nexter_settings_welcome'
                )
            ),
            'show_names' => true,
            'fields' => ''
        );

        $this->option_metabox[] = array(
            'id' => 'nexter_extra_options',
            'title' => esc_html__('Extra Options', 'nexter-fse'),
            'show_on' => array(
                'key' => 'options-page',
                'value' => array(
                    'nexter_extra_options'
                )
            ),
            'show_names' => true,
            'fields' => '',
        );

        $performance_options = [];
        if (has_filter('nexter_site_performance_options')) {
            $performance_options = apply_filters('nexter_site_performance_options', $performance_options);
        }

        $this->option_metabox[] = array(
            'id' => 'nexter_site_performance',
            'title' => esc_html__('Performance', 'nexter-fse'),
            'show_on' => array(
                'key' => 'options-page',
                'value' => array(
                    'nexter_site_performance'
                )
            ),
            'show_names' => true,
            'fields' => $performance_options,
        );

        $security_options = [];
        if (has_filter('nexter_site_security_options')) {
            $security_options = apply_filters('nexter_site_security_options', $security_options);
        }
        $this->option_metabox[] = array(
            'id' => 'nexter_site_security',
            'title' => esc_html__('Security', 'nexter-fse'),
            'show_on' => array(
                'key' => 'options-page',
                'value' => array(
                    'nexter_site_security'
                )
            ),
            'show_names' => true,
            'fields' => $security_options,
        );
        $this->option_metabox[] = array(
            'id' => 'nexter_activate',
            'title' => esc_html__('Activate', 'nexter-fse'),
            'show_on' => array(
                'key' => 'options-page',
                'value' => array(
                    'nexter_activate'
                )
            ),
            'show_names' => true,
            'fields' => '',
        );

        $this->option_metabox[] = array(
            'id' => 'nexter_white_label',
            'title' => esc_html__('White Label', 'nexter-fse'),
            'show_on' => array(
                'key' => 'options-page',
                'value' => array(
                    'nexter_white_label'
                )
            ),
            'show_names' => true,
            'fields' => '',
        );

        return $this->option_metabox;
    }

    /**
     * Public getter method for retrieving protected/private variables
     * @param string $field Field to retrieve
     * @return mixed    Field value or exception is thrown
     * @since  1.0.0
     */
    public function __get($field) {

        // Allowed fields to retrieve
        if (in_array($field, array('key', 'fields', 'title', 'options_page'), true)) {
            return $this->{$field};
        }
        if ('option_metabox' === $field) {
            return $this->option_fields();
        }
        /* translators: Invalid property: Fields */
        throw new Exception(sprintf(esc_html__('Invalid property: %1$s', 'nexter-fse'), $field));
    }

}

// Get it started
if(!defined('NEXTER_EXT')){
    $Nexter_Fse_Settings_Panel = new Nexter_Fse_Settings_Panel();
    $Nexter_Fse_Settings_Panel->hooks();
}

