<?php

namespace CPBW\Notices;

use CPBW\App\Badge;

class PromotionalNotices {
	public function __construct() {
		// add_action( 'admin_notices', [ $this, 'display_promotional_notice' ] );
	}

	/**
	 * Display the promotional notice.
	 *
	 * @return void
	 */
	public function display_promotional_notice() {

		if ( Badge::is_pro() ) {
			return; // Don't show promotional notice if Pro is active
		}

		if ( ! is_user_logged_in() ) {
			return;
		}

		global $pagenow;

		// Allowed pages: Dashboard (index.php) and plugin page (cpbw)
		$plugin_page_slug = 'cpbw';

		$is_dashboard = ($pagenow === 'index.php');
		$is_plugin_page = (isset($_GET['page']) && $_GET['page'] === $plugin_page_slug);

		if ( ! $is_dashboard && ! $is_plugin_page ) {
			return; // Not on dashboard & not on plugin page
		}

		// Promo time window
		$current_time = time();
		$promo_start  = strtotime('2025-06-24 00:00:00');
		$promo_end    = strtotime('2025-12-20 11:59:00');

		if ( $current_time < $promo_start || $current_time > $promo_end ) {
			return;
		}

		// Check dismiss status
		$user_id = get_current_user_id();
		$dismiss = get_user_meta( $user_id, 'cpbw_promotional_notice_november_2025', true );

		if ( $dismiss === 'never' ) {
			return;
		}

		?>
		<div class="cpbw-promotional-notice-wrapper">
			<div class="notice notice-success is-dismissible" style="margin:0px; padding:0px;">
				<a href="https://innocodia.com/plugins/woocommerce-product-badges-pro/" target="_blank">
					<img src="<?php echo esc_url( plugins_url( 'assets/image/promotional/blackFirday_2025.gif', CPBW_FILE ) ); ?>"
						alt="Promotional Banner"
						style="width: 100%; height: auto;">
				</a>
			</div>
		</div>
		<?php
	}

}
