<?php
if (!defined('ABSPATH')) exit;

add_action( 'current_screen', 'flexyconsent_startPage_before' );
function flexyconsent_startPage_before() {
	$my_current_screen = get_current_screen();
	if ($my_current_screen->base == 'toplevel_page_flexyconsent-startPage') {
		flexyconsent_checkStartPage();
	} else if(str_starts_with($my_current_screen->base, 'flexy-consent_page')) {
		flexyconsent_checkOtherPages();
	}
}


function flexyconsent_startPage() { ?>
	<div class="container py-3 flexyconsent-container">
		<div class="row">
			<div class="col-12 text-center">
			<?php flexyconsent_get_top_section(); ?>
			</div>
			<div class="col-12">
				<div>
					<h3 style="text-align:center"><?php esc_html_e('Welcome to Flexy Consent', 'flexyconsent'); ?></h3>
					<p><?php esc_html_e("Don't let consent management intimidate you. Protect your users' privacy with the most affordable CMP without compromising security. Continue now to become compliant or view pricing to pick a plan suitable for you.", "flexyconsent"); ?></p>
					<p><?php echo wp_kses_post(str_replace(['[LinkBefore]', '[LinkAfter]'], ['<a href="https://flexyconsent.com/#contact" target="_blank">', '</a>'], __('If you require any further information, feel free to [LinkBefore]contact us[LinkAfter].', 'flexyconsent'))); ?></p>
				</div>	
				<br>
				<div class="d-flex justify-content-center flex-wrap">
					<button id="continue" name="continue" class="mx-3 button button-primary"><?php esc_html_e("Continue","flexyconsent"); ?></button>
				</div>
			
			<div class="col-12 text-center">
				<?php flexyconsent_get_bottom_section(); ?>
			</div>
		</div>
	</div>
	<?php
}

function flexyconsent_checkStartPage() {
	// global $flexyconsentSettings;	
	$email = flexyconsent_getOption('email');
	$apikey = flexyconsent_getOption('apiKey');
	$projectId = flexyconsent_getOption('projectId');

	if ($email && $apikey && $projectId) {
		flexyconsent_goPage('dashboardPage');
	}	
}

function flexyconsent_checkOtherPages() {
	$email = flexyconsent_getOption('email');
	$apikey = flexyconsent_getOption('apiKey');
	$projectId = flexyconsent_getOption('projectId');

	if (!($email && $apikey && $projectId)) {
		flexyconsent_goPage('startPage');
	}	
}