<?php
if (!defined('ABSPATH')) exit;
// add_action( 'admin_init', 'flexyconsent_settings_updateEmailValidateKeyPage' );
// function flexyconsent_settings_updateEmailValidateKeyPage() { 
// 	// 	global $flexyconsentSettings; 
// 	// 	$pageNameMain = 'updateEmailValidateKeyPage';
// 	// $pageName = flexyconsent_getPageName($pageNameMain);
// 	// $sectionName = flexyconsent_getSectionName($pageNameMain);
// }
 
function flexyconsent_updateEmailValidateKeyPage() { 
	global $flexyconsent_email;
	$pageNameMain = 'updateEmailValidateKeyPage'; ?>
		<div class="container py-3">
			<div class="row">
				<div class="col-12 text-center">
				<?php flexyconsent_get_top_section(); ?>
				</div>
				<div class="col-12">
					<form action='options.php' method='post' id="<?php echo esc_attr($pageNameMain); ?>" class="d-table mx-auto my-3 flexyconsent-form">
						<?php
						settings_fields( $pageNameMain );
						do_settings_sections( $pageNameMain ); ?>
						<h4><?php esc_html_e("Check your email box","flexyconsent"); ?>
						<p><?php esc_html_e("Copy and paste new API key here from [email]","flexyconsent"); ?> (<?php echo esc_html($flexyconsent_email); ?>)</p>
						<table class="form-table" role="presentation">
							<tbody>
								<tr>
									<th scope="row"><?php esc_html_e('API Key', 'flexyconsent'); ?></th>
									<td>
										<input type="text" id="new-apikey" name="new-apikey" placeholder='<?php esc_html_e('API Key', 'flexyconsent'); ?>'>
									</td>
								</tr>
							</tbody>
						</table>
						<div class="d-flex justify-content-between">
							<a class="button button-back" href="<?php echo esc_url(flexyconsent_generateGoPage('dashboardPage')); ?>"><?php esc_html_e('Cancel','flexyconsent'); ?></a>
							<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e('Continue', 'flexyconsent'); ?>">
						</div>
					</form>
				</div>
				<div class="col-12 text-center">
					<?php flexyconsent_get_bottom_section(); ?>
				</div>
			</div>
		</div>
		<?php
}
add_action( 'current_screen', 'flexyconsent_updateEmailValidateKeyPage_before' );
function flexyconsent_updateEmailValidateKeyPage_before(){
	global $flexyconsent_menu_title, $flexyconsent_email;
	$my_current_screen = get_current_screen();
	if ($my_current_screen->base == sanitize_title($flexyconsent_menu_title) . '_page_flexyconsent-updateEmailValidateKeyPage') {
		$qs = isset($_SERVER['QUERY_STRING']) ? sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])) : '';
		parse_str($qs, $params);

		if (isset($params['email'])) {
			$flexyconsent_email = sanitize_text_field($params['email']);
		} else {
			flexyconsent_goPage('updateEmailPage');
		}
	} 
}
