<?php // Google Analytics - Display Settings

if (!defined('ABSPATH')) exit;

function ga_google_analytics_pro_add_options_page() {
	
	$title_page = esc_html__('GA Google Analytics Pro', 'ga-google-analytics-pro');
	$title_menu = esc_html__('Google Analytics', 'ga-google-analytics-pro');
	
	// add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function )
	
	add_options_page($title_page, $title_menu, 'manage_options', 'ga-google-analytics-pro', 'ga_google_analytics_pro_display_settings');
	
}

function ga_google_analytics_pro_get_tabs() {
	
	$tabs = array(
		'tab1' => esc_html__('Configure', 'ga-google-analytics-pro'), 
		'tab2' => esc_html__('Customize', 'ga-google-analytics-pro'), 
		'tab3' => esc_html__('Advanced',  'ga-google-analytics-pro'), 
		'tab4' => esc_html__('Opt Out',   'ga-google-analytics-pro'), 
		'tab5' => esc_html__('About',     'ga-google-analytics-pro'), 
		'tab6' => esc_html__('License',   'ga-google-analytics-pro'), 
	);
	
	return $tabs;
	
}

function ga_google_analytics_pro_display_settings() {
	
	$tab_active = isset($_GET['tab']) ? $_GET['tab'] : 'tab1'; 
	
	$tab_href = admin_url('options-general.php?page=ga-google-analytics-pro');
	
	$tab_names = ga_google_analytics_pro_get_tabs();
	
	?>
	
	<div class="wrap wrap-<?php echo $tab_active; ?>">
		<h1><?php echo GAPRO_NAME; ?> <span class="gapro-version"><?php echo GAPRO_VERSION; ?></span></h1>
		<?php echo (!isset($_GET['activate_license']) || (isset($_GET['activate_license']) && $_GET['activate_license'] !== 'true')) ? ga_google_analytics_pro_license_status() : ''; ?>
		<p><?php esc_html_e('Thanks for using GA Pro! Visit the Help tab above for usage information. To view your stats, log in to your Google account.', 'ga-google-analytics-pro'); ?></p>
		<h2 class="nav-tab-wrapper">
			
			<?php 
				
				foreach ($tab_names as $key => $value) {
					
					$active = ($tab_active === $key) ? ' nav-tab-active' : '';
					
					echo '<a href="'. esc_url($tab_href .'&tab='. $key) .'" class="nav-tab nav-'. esc_attr($key) . esc_attr($active) .'">'. esc_html($value) .'</a>';
					
				}
				
			?>
			
		</h2>
		<form method="post" action="options.php">
			
			<?php 
				
				if ($tab_active === 'tab1') {
					
					settings_fields('gapro_configure');
					do_settings_sections('gapro_configure');
				
				} elseif ($tab_active === 'tab2') {
					
					settings_fields('gapro_customize');
					do_settings_sections('gapro_customize');
					
				} elseif ($tab_active === 'tab3') {
					
					settings_fields('gapro_advanced');
					do_settings_sections('gapro_advanced');
					
				} elseif ($tab_active === 'tab4') {
					
					settings_fields('gapro_optout');
					do_settings_sections('gapro_optout');
					
				} elseif ($tab_active === 'tab5') {
					
					ga_google_analytics_pro_settings_about();
					
				} elseif ($tab_active === 'tab6') {
					
					settings_fields('gapro_license');
					ga_google_analytics_pro_display_license();
					
				}
				
				if (($tab_active !== 'tab5') && ($tab_active !== 'tab6')) submit_button();
				
			?>
			
		</form>
	</div>
	
<?php 

}
