<?php
if (!defined('ABSPATH')) {
    exit;
}
if (!class_exists('hpixl_securicheck_ScreenProtectionSpam')) {

    class hpixl_securicheck_ScreenProtectionSpam
    {
        public function __construct() {}

        function render_screen()
        {

?>
            <?php settings_errors(); ?>
            <div class='wrap'>
                <h1 style="display:none;"></h1>
                <div class="hpixl-securicheck-admin-audit-header">
                    <div class="hpixl-securicheck-admin-audit-header-panneau-logo">
                        <img src="<?php echo esc_html(HPIXL_SECURICHECK_PLUGIN_URL . "images/securicheck.png"); ?>" alt="logo hpixl-securicheck" />
                        <h1><?php esc_html_e('Securicheck - PROTECTION SPAM', 'securicheck'); ?></h1>
                    </div>
                    <span>V<?php echo esc_html(HPIXL_SECURICHECK_PLUGIN_VERSION); ?></span>
                </div>

                <?php
                $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'commentaires';
                ?>

                <h2 class="nav-tab-wrapper">
                    <a href="?page=<?php echo esc_html(HPIXL_SECURICHECK_SETTINGS_SLUG . '-protection-spam'); ?>&tab=commentaires" class="nav-tab <?php echo esc_html($active_tab == 'commentaires' ? 'nav-tab-active' : ''); ?>"><?php esc_html_e('Commentaires', 'securicheck'); ?></a>
                </h2>

                <?php if ($active_tab == 'commentaires'): ?>
                    <div class='hpixl-securicheck-settings-form-panel'>
                        <form action='options.php' method='POST'>
                            <?php
                            settings_fields('hpixl_securicheck_settings_securite_groupe_anti_spam');
                            do_settings_sections('hpixl_securicheck_settings_securite_groupe_anti_spam');
                            hpixl_securicheck_render_protection_spam_onglet_commentaires();
                            ?>
                        </form>
                    </div>
                    <?php hpixl_securicheck_render_protection_spam_onglet_commentaires_logs(); ?>
                <?php endif; ?>

            </div>
<?php
        }
    }
}

//Ajout d'un settings pour notre plugin 
add_action('admin_init', 'hpixl_securicheck_settings_protection_spam');
function hpixl_securicheck_settings_protection_spam()
{
    register_setting('hpixl_securicheck_settings_securite_groupe_anti_spam', 'hpixl_securicheck_toggle_page_anti_spam_commentaires');
    //valeurs par défaut
    add_option('hpixl_securicheck_toggle_page_anti_spam_commentaires', '0');
}


function hpixl_securicheck_render_protection_spam_onglet_commentaires()
{
    require plugin_dir_path(dirname(__FILE__)) . 'admin/Screen_protection_spam_onglet_commentaires.php';
}

function hpixl_securicheck_render_protection_spam_onglet_commentaires_logs()
{
    require plugin_dir_path(dirname(__FILE__)) . 'admin/Screen_protection_spam_onglet_commentaires_logs.php';
}
