<?php

require_once dirname(__FILE__) . '/includes/settings_reader.php';
require_once dirname(__FILE__) . '/includes/settings_writer.php';

function wp_example_site_health_navigation_tabs( $tabs ) {
    // translators: Tab heading for Site Health navigation.
	$tabs['bdp_enhanced_security'] = esc_html_x('Erweiterte Sicherheit', 'Site Health', 'text-domain');

    return $tabs;
}
add_filter( 'site_health_navigation_tabs', 'wp_example_site_health_navigation_tabs' );

function wp_example_site_health_tab_content($tab)
{
	if ('bdp_enhanced_security' === $tab) {
		if (isset($_GET['subpage']) && $_GET['subpage'] == 'botlist') {
			if (isset($_POST['save_settings']) && isset($_POST['existing_bots']) && isset($_POST['new_bots'])) {
				protect_wp_save_bots($_POST['existing_bots'], $_POST['new_bots']);
			}

			echo '<div class="health-check-body health-check-status-tab hide-if-no-js">';
			echo '<form method="post" action="site-health.php?tab=' . BDP_LV_PLUGIN_SLUG . '&subpage=botlist">';
			echo '<input type="hidden" name="save_settings" value="true" />';
			require BDP_LV_PLUGIN_DIR . 'modules/security/internal/botlist-tab.php';
			echo '</form>';
			echo '</div>';
			return;
		}

		update_option('protect_wp_needs_attention', false);
		if (isset($_POST['save_settings'])) {
			$securitySettings = [];
			if (isset($_POST['security_settings'])) {
				$securitySettings = $_POST['security_settings'];
			}
			kompass_sec_save_settings($securitySettings);
		}
		if (isset($_GET['action']) && $_GET['action'] == 'updatesitekeys') {
			kompass_sec_site_keys();
		}

		echo '<div class="health-check-body health-check-status-tab hide-if-no-js">';
		echo '<form method="post" action="site-health.php?tab=bdp_enhanced_security">';
		echo '<input type="hidden" name="save_settings" value="true" />';
		require BDP_LV_PLUGIN_DIR . 'modules/security/internal/site-health-tab.php';
		echo '</form>';
		echo '</div>';
		return;
	}
}

add_action('site_health_tab_content', 'wp_example_site_health_tab_content');

require_once dirname(__FILE__) . '/classes/Security.class.php';


