<?php
/**
 * @package BlaminhorEssentials
 * @var Blaminhor_Essentials_Module_Cookies              $module
 * @var Blaminhor_Essentials_Cookies_TCF_Adapter         $tcf_adapter
 * @var Blaminhor_Essentials_Cookies_Geo_Resolver        $geo_resolver
 * @var array                                            $settings
 */

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

$bla_tcf_desc        = $tcf_adapter->get_runtime_descriptor();
$bla_geo_present     = $geo_resolver->has_database();
$bla_geo_path        = str_replace( ABSPATH, '', $geo_resolver->get_database_path() );
$bla_geo_dir         = dirname( $bla_geo_path );
?>
<p class="description" style="margin-bottom: 24px;">
	<?php esc_html_e( 'These options are off by default. Turn them on only if your site needs them — each card explains when to enable it.', 'blaminhor-essentials' ); ?>
</p>

<!-- ====================================================================== -->
<!-- Section 1 — Geolocation opt-in                                          -->
<!-- ====================================================================== -->
<div class="blaminhor-essentials-card" style="border-left: 4px solid #1d4ed8; padding: 16px 20px; margin-bottom: 24px;">
	<h3 style="margin-top:0;">
		<label>
			<input type="checkbox" name="auto_geo" value="1" <?php checked( ! empty( $settings['auto_geo'] ) ); ?>>
			<?php esc_html_e( 'Adapt the banner automatically to each visitor\'s country', 'blaminhor-essentials' ); ?>
		</label>
	</h3>

	<p><strong><?php esc_html_e( 'What does it do?', 'blaminhor-essentials' ); ?></strong></p>
	<p>
		<?php esc_html_e( 'By default, your banner uses ONE rule set for every visitor (the jurisdiction picked in the General tab). This option switches to a per-visitor banner: GDPR for Europeans, CCPA for Californians, LGPD for Brazilians, etc.', 'blaminhor-essentials' ); ?>
	</p>

	<p><strong><?php esc_html_e( 'Should you enable it?', 'blaminhor-essentials' ); ?></strong></p>
	<ul style="margin-left: 20px;">
		<li><?php esc_html_e( 'Your site targets a single market (90% of cases): NO, keep it simple.', 'blaminhor-essentials' ); ?></li>
		<li><?php esc_html_e( 'Your site receives international traffic AND you want to comply with several jurisdictions simultaneously: YES.', 'blaminhor-essentials' ); ?></li>
	</ul>

	<p><strong><?php esc_html_e( 'How does it work?', 'blaminhor-essentials' ); ?></strong></p>
	<p>
		<?php esc_html_e( 'The plugin uses a free local database (MaxMind GeoLite2) that maps IP addresses to country codes. The lookup happens on your server. Your visitors are NOT tracked by a third party.', 'blaminhor-essentials' ); ?>
	</p>

	<p><strong><?php esc_html_e( 'How to enable it', 'blaminhor-essentials' ); ?></strong></p>
	<ol style="margin-left: 20px;">
		<li><?php echo wp_kses_post( __( 'Create a free account on <a href="https://www.maxmind.com/en/geolite2/signup" target="_blank" rel="noopener noreferrer">maxmind.com</a> (GeoLite2 Free section).', 'blaminhor-essentials' ) ); ?></li>
		<li><?php esc_html_e( 'Download the GeoLite2-Country.mmdb file.', 'blaminhor-essentials' ); ?></li>
		<li>
			<?php
			printf(
				/* translators: %s: directory path */
				esc_html__( 'Upload it to %s via FTP/SFTP (the directory is created automatically when this module is active).', 'blaminhor-essentials' ),
				'<code>' . esc_html( $bla_geo_dir ) . '/</code>'
			);
			?>
		</li>
		<li><?php esc_html_e( 'Tick the box above and save settings.', 'blaminhor-essentials' ); ?></li>
	</ol>

	<p>
		<?php if ( $bla_geo_present ) : ?>
			<span style="color: #228b22;">●</span>
			<strong><?php esc_html_e( 'Database detected.', 'blaminhor-essentials' ); ?></strong>
			<code><?php echo esc_html( $bla_geo_path ); ?></code>
		<?php else : ?>
			<span style="color: #c62828;">●</span>
			<strong><?php esc_html_e( 'Database not found.', 'blaminhor-essentials' ); ?></strong>
			<?php esc_html_e( 'Visitor-country detection will not work until you upload the file.', 'blaminhor-essentials' ); ?>
		<?php endif; ?>
	</p>
</div>

<!-- ====================================================================== -->
<!-- Section 2 — IAB TCF v2.2 opt-in                                         -->
<!-- ====================================================================== -->
<div class="blaminhor-essentials-card" style="border-left: 4px solid #1d4ed8; padding: 16px 20px; margin-bottom: 24px;">
	<h3 style="margin-top:0;">
		<label>
			<input type="checkbox" name="tcf_enabled" value="1" <?php checked( ! empty( $settings['tcf_enabled'] ) ); ?>>
			<?php esc_html_e( 'Programmatic advertising compatibility (IAB TCF v2.2)', 'blaminhor-essentials' ); ?>
		</label>
	</h3>

	<p><strong><?php esc_html_e( 'What is it?', 'blaminhor-essentials' ); ?></strong></p>
	<p>
		<?php esc_html_e( 'TCF v2.2 (Transparency & Consent Framework) is a standard used by European programmatic ad networks (Google Ad Manager, Criteo, Xandr, etc.) to check whether a visitor consented to personalized advertising.', 'blaminhor-essentials' ); ?>
	</p>

	<p><strong><?php esc_html_e( 'Should you enable it?', 'blaminhor-essentials' ); ?></strong></p>
	<ul style="margin-left: 20px;">
		<li><?php esc_html_e( 'Your site monetizes through PROGRAMMATIC ADS (header bidding, Google Ad Manager, auto-filled ad slots): YES.', 'blaminhor-essentials' ); ?></li>
		<li><?php esc_html_e( 'You only use Google Analytics, Meta Pixel or classic marketing tools: NO — it is useless for you.', 'blaminhor-essentials' ); ?></li>
		<li><?php esc_html_e( 'When in doubt: NO. You can turn it on later.', 'blaminhor-essentials' ); ?></li>
	</ul>

	<p><strong><?php esc_html_e( 'How to enable it', 'blaminhor-essentials' ); ?></strong></p>
	<p>
		<?php esc_html_e( 'Tick the box above and save. Blaminhor Essentials declares your site as a "limited" CMP automatically and exposes the standard window.__tcfapi API to your ad networks. The official Global Vendor List is refreshed monthly via cron.', 'blaminhor-essentials' ); ?>
	</p>

	<p><strong><?php esc_html_e( 'Important limits', 'blaminhor-essentials' ); ?></strong></p>
	<p>
		<?php esc_html_e( 'Blaminhor Essentials is NOT an IAB Europe-certified CMP (certification costs €5,000/year). Some networks operating in strict mode may ignore our signal. For those specific cases, use a paid certified CMP (Didomi, Cookiebot, Sourcepoint).', 'blaminhor-essentials' ); ?>
	</p>

	<p>
		<strong><?php esc_html_e( 'Current status:', 'blaminhor-essentials' ); ?></strong>
		<?php
		printf(
			/* translators: 1: CMP id, 2: vendor list version */
			esc_html__( 'CMP ID %1$d, vendor list version %2$d.', 'blaminhor-essentials' ),
			(int) $bla_tcf_desc['cmpId'],
			(int) $bla_tcf_desc['vendorListVersion']
		);
		?>
	</p>
</div>

<!-- ====================================================================== -->
<!-- Section 3 — Force re-consent                                            -->
<!-- ====================================================================== -->
<div class="blaminhor-essentials-card" style="border-left: 4px solid #1d4ed8; padding: 16px 20px; margin-bottom: 24px;">
	<h3 style="margin-top:0;"><?php esc_html_e( 'Force a fresh consent from every visitor', 'blaminhor-essentials' ); ?></h3>

	<p>
		<?php esc_html_e( 'Use this after a significant change in your privacy policy (a new service added, a new processing purpose, etc.). Every visitor will see the banner again on their next visit.', 'blaminhor-essentials' ); ?>
	</p>

	<p>
		<label for="policy_version"><strong><?php esc_html_e( 'Current policy version', 'blaminhor-essentials' ); ?></strong></label><br>
		<input type="text" id="policy_version" name="policy_version" value="<?php echo esc_attr( $settings['policy_version'] ); ?>" class="regular-text">
		<br>
		<span class="description"><?php esc_html_e( 'Free-form identifier (e.g. "2026.05"). Bump it any time you want existing consents to expire.', 'blaminhor-essentials' ); ?></span>
	</p>

	<p>
		<button type="submit" name="force_reconsent" value="1" class="button">
			<?php esc_html_e( 'Force re-consent now', 'blaminhor-essentials' ); ?>
		</button>
	</p>
</div>
