<?php
/**
 * Bundle Tab Template
 *
 * China Plugins Bundle — cross-promote CPC + BIC + SIC.
 *
 * @package SpeedInChina
 */

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

$current_tab = 'bundle';
global $speeinch_fs;

// Plugin detection — file paths as they appear in wp_get_active_and_recently_activated_plugins()
$bundle_plugins = array(
	'cpc' => array(
		'slug'     => 'china-payments-plugin',
		'file'     => 'china-payments-plugin/wpstripeglobal.php',
		'label'    => '💳 China Payments',
		'desc'     => 'Accept WeChat Pay, Alipay, and UnionPay payments from Chinese customers via Stripe integration.',
		'features' => array(
			'WeChat Pay & Alipay',
			'UnionPay via Stripe',
			'Multi-currency display (CNY)',
			'Checkout localization',
		),
	),
	'bic' => array(
		'slug'     => 'blocked-in-china',
		'file'     => 'blocked-in-china/blocked-in-china.php',
		'label'    => '🔒 Blocked in China',
		'desc'     => 'Check if your site is accessible in China and monitor Great Firewall blocking status with real-time alerts.',
		'features' => array(
			'GFW blocking detection',
			'Real-time monitoring',
			'Email/Slack alerts',
			'DNS propagation check',
		),
	),
);

// Determine plugin states
foreach ( $bundle_plugins as $key => &$plugin ) {
	$plugin_dir             = WP_PLUGIN_DIR . '/' . $plugin['slug'];
	$plugin['is_active']    = is_plugin_active( $plugin['file'] );
	$plugin['is_installed'] = file_exists( WP_PLUGIN_DIR . '/' . $plugin['file'] );
}
unset( $plugin );
?>
<div class="wrap speeinch-wrap">

	<h1><?php esc_html_e( 'Speed in China', 'speed-in-china' ); ?></h1>

	<?php require_once SPEEINCH_PLUGIN_PATH . 'admin/templates/nav-tabs.php'; ?>

	<div class="speeinch-bundle-header" style="margin-top: 20px; text-align: center; padding: 30px 20px; background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%); color: #fff; border-radius: 8px;">
		<h2 style="color: #fff; font-size: 24px; margin: 0 0 8px;"><?php esc_html_e( '⭐ China Plugins Bundle ⭐', 'speed-in-china' ); ?></h2>
		<p style="font-size: 16px; opacity: 0.9; margin: 0 0 16px;"><?php esc_html_e( 'Everything you need to optimize your WordPress site for China', 'speed-in-china' ); ?></p>
		<p style="font-size: 14px; background: rgba(255,255,255,0.15); display: inline-block; padding: 6px 16px; border-radius: 20px; margin: 0 0 16px;">
			<?php esc_html_e( '💰 Save 35% with the Bundle vs. individual plugins', 'speed-in-china' ); ?>
		</p>
		<br>
		<a href="https://chinaplugins.com" target="_blank" class="button button-hero" style="background: #fff; color: #1e3a5f; border: none; font-weight: 600;">
			<?php esc_html_e( '🎯 Get the Bundle', 'speed-in-china' ); ?>
		</a>
	</div>

	<div class="speeinch-bundle-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin-top: 24px;">

		<!-- Speed in China (Current Plugin — always active) -->
		<div class="speeinch-bundle-card" style="background: #fff; border: 2px solid #2563eb; border-radius: 8px; padding: 24px; position: relative;">
			<span style="position: absolute; top: -10px; right: 16px; background: #2563eb; color: #fff; padding: 2px 12px; border-radius: 12px; font-size: 11px; font-weight: 600;"><?php esc_html_e( 'CURRENT', 'speed-in-china' ); ?></span>
			<h3 style="margin-top: 0;">⚡ <?php esc_html_e( 'Speed in China', 'speed-in-china' ); ?></h3>
			<p><?php esc_html_e( 'Test your website speed from China, detect blocked resources, localize Google Fonts, and get optimization recommendations.', 'speed-in-china' ); ?></p>
			<ul style="list-style: none; padding: 0; margin: 12px 0;">
				<li>✅ <?php esc_html_e( 'Speed tests from China locations', 'speed-in-china' ); ?></li>
				<li>✅ <?php esc_html_e( 'GFW resource analysis', 'speed-in-china' ); ?></li>
				<li>✅ <?php esc_html_e( 'Google Font localization', 'speed-in-china' ); ?></li>
				<li>✅ <?php esc_html_e( 'Plugin slowdown detection', 'speed-in-china' ); ?></li>
			</ul>
			<span class="button button-primary" style="width: 100%; text-align: center; pointer-events: none; opacity: 0.7;"><?php esc_html_e( 'Active', 'speed-in-china' ); ?></span>
		</div>

		<?php foreach ( $bundle_plugins as $key => $plugin ) : ?>
		<div class="speeinch-bundle-card" style="background: #fff; border: 1px solid <?php echo $plugin['is_active'] ? '#2563eb' : '#d1d5db'; ?>; border-radius: 8px; padding: 24px; position: relative;">
			<?php if ( $plugin['is_active'] ) : ?>
				<span style="position: absolute; top: -10px; right: 16px; background: #22c55e; color: #fff; padding: 2px 12px; border-radius: 12px; font-size: 11px; font-weight: 600;"><?php esc_html_e( 'INSTALLED', 'speed-in-china' ); ?></span>
			<?php endif; ?>
			<h3 style="margin-top: 0;"><?php echo esc_html( $plugin['label'] ); ?></h3>
			<p><?php echo esc_html( $plugin['desc'] ); ?></p>
			<ul style="list-style: none; padding: 0; margin: 12px 0;">
				<?php foreach ( $plugin['features'] as $feature ) : ?>
					<li>✅ <?php echo esc_html( $feature ); ?></li>
				<?php endforeach; ?>
			</ul>

			<?php if ( $plugin['is_active'] ) : ?>
				<span class="button" style="width: 100%; text-align: center; pointer-events: none; opacity: 0.7;"><?php esc_html_e( 'Active', 'speed-in-china' ); ?></span>
			<?php elseif ( $plugin['is_installed'] ) : ?>
				<button class="button button-primary speeinch-activate-plugin" style="width: 100%; text-align: center;"
					data-plugin-file="<?php echo esc_attr( $plugin['file'] ); ?>"
					data-nonce="<?php echo esc_attr( wp_create_nonce( 'speeinch_activate_plugin' ) ); ?>">
					<?php esc_html_e( 'Activate', 'speed-in-china' ); ?>
				</button>
			<?php else : ?>
				<button class="button button-primary speeinch-install-plugin" style="width: 100%; text-align: center;"
					data-slug="<?php echo esc_attr( $plugin['slug'] ); ?>"
					data-plugin-file="<?php echo esc_attr( $plugin['file'] ); ?>"
					data-nonce="<?php echo esc_attr( wp_create_nonce( 'speeinch_install_plugin' ) ); ?>">
					<?php esc_html_e( 'Install Plugin', 'speed-in-china' ); ?>
				</button>
			<?php endif; ?>
		</div>
		<?php endforeach; ?>

	</div>



	<!--Features-->
	<?php
		require_once SPEEINCH_PLUGIN_PATH . 'admin/templates/features.php';
	?>
</div>

