<?php
/**
 * Settings page template
 * @since  1.0.0
 */


$opts = geot_settings();
$defaults = [
	'license'                   => '',
	'api_secret'                => '',
	'region'                    => [['name','countries']],
	'city_region'               => [['name','cities']],
	'cache_mode'                => '0',
	'ajax_mode'                 => '0',
	'debug_mode'                => '0',
	'disable_menu_integration'  => '0',
	'disable_widget_integration'=> '0',
	'geot_uninstall'            => '',
];
$opts = wp_parse_args( $opts, apply_filters ('geot/default_settings', $defaults ) );

$countries 	= geot_countries();

?>
<div class="wrap geot-settings">
	<h2>GeoTargetingWP</h2>
	<form name="geot-settings" method="post" enctype="multipart/form-data">
		<table class="form-table">
			<?php do_action( 'geot/settings_page/before' ); ?>

			<tr valign="top" class="">
				<th><h3><?php _e( 'Main settings:', 'geot'); ?></h3></th>
			</tr>

			<tr valign="top" class="">
				<th><label for=""><?php _e( 'Cache Mode', 'geot'); ?></label></th>
				<td colspan="3">
					<label><input type="checkbox" id="" disabled name="geot_settings[cache_mode]" value="1" <?php checked($opts['cache_mode'],'1');?>/> (premium only)
						<p class="help"><?php _e( 'Check this if you want to save the user location into PHP Sessions', 'geot'); ?></p>
				</td>
			</tr>
			<tr valign="top" class="">
				<th><label for=""><?php _e( 'Debug Mode', 'geot'); ?></label></th>
				<td colspan="3">
					<label><input type="checkbox" id="" name="geot_settings[debug_mode]" value="1" <?php checked($opts['debug_mode'],'1');?> disabled/> (premium only)
						<p class="help"><?php _e( 'Check this if you want to print in the html code some debug info.', 'geot'); ?></p>
				</td>
			</tr>

			<tr valign="top" class="">
				<th><label for="region"><?php _e( 'Fallback Country', 'geot'); ?></label></th>
				<td colspan="3">

					<select name="geot_settings[fallback_country]" disabled class="geot-chosen-select" data-placeholder="<?php _e('Type country name...', 'geot');?>" >
						<option value=""><?php _e( 'Choose One', 'geot');?></option>
						<?php
						foreach ($countries as $c) {
							?>
							<option value="<?php echo $c->iso_code?>" <?php isset( $opts['fallback_country'] ) ? selected( $c->iso_code, $opts['fallback_country'] ) : ''; ?>> <?php echo $c->country; ?></option>
							<?php
						}
						?>
					</select>

					<p class="help"><?php _e( 'If the user IP is not detected plugin will fallback to this country', 'geot' ); ?> (premium only)</p>
				</td>

			</tr>
			<tr valign="top" class="">
				<th><label for="bots"><?php _e( 'Bots Country', 'geot' ); ?></label></th>
				<td colspan="3">
					<select disabled name="geot_settings[bots_country]"  class="geot-chosen-select" data-placeholder="<?php _e('Type country name...', 'geot' );?>" >
						<option value=""><?php _e( 'Choose One', 'geot' );?></option>
						<?php
						foreach ($countries as $c) {
							?>
							<option value="<?php echo $c->iso_code?>" <?php isset( $opts['bots_country'] ) ? selected( $c->iso_code, $opts['bots_country'] ) :''; ?>> <?php echo $c->country; ?></option>
							<?php
						}
						?>
					</select>

					<p class="help"><?php _e( 'All bots / crawlers will be treated as the are from this country. More info in ', 'geot' ); ?><a href="https://timersys.com/geotargeting/docs/bots-seo/">Bots in Geotargeting</a> (premium only)</p>
				</td>
			</tr>

			<tr valign="top" class="">
				<th><h3><?php _e( 'Countries:', 'geot' ); ?></h3></th>
				<td colspan="3">
				</td>
			</tr>
			<tr valign="top" class="">
				<th><label for="region"><?php _e( 'Create new region', 'geot' ); ?></label></th>
				<td colspan="3">

					<p class="help"><?php _e( 'Add as many countries you need for each region', 'geot' ); ?> (premium only)</p>
				</td>

			</tr>

			<tr valign="top" class="">
				<th><h3><?php _e( 'Uninstall:', 'geot' ); ?></h3></th>
				<td colspan="3">
					<p><?php _e( 'Check this if you want to <strong>delete all plugin data</strong> on uninstall' , 'geot' ); ?></p>
				</td>
			</tr>
			<?php do_action( 'geot/settings_page/after' ); ?>
			<tr valign="top" class="">
				<th><label for=""><?php _e( 'Uninstall', 'geot' ); ?></label></th>
				<td colspan="3">
				        <input type="checkbox" id="" name="geot_settings[geot_uninstall]" value="1" <?php checked($opts['geot_uninstall'],'1');?>/>
						<p class="help"><?php _e( 'Will delete all database records and plugin settings when you delete the plugin', 'geot' ); ?></p>
				</td>
			</tr>


			<tr><td><input type="submit" class="button-primary" value="<?php _e( 'Save settings', 'geot' );?>"/></td>
			<?php wp_nonce_field('geot_save_settings','geot_nonce'); ?>
		</table>
	</form>
</div>
