<?php

namespace EasyCriticalCSS;

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

class Compatibility_Jetpack_Boost extends Compatibility {
	public static function init() {
		self::add_conditional_action( [ __CLASS__, 'is_jetpack_boost_installed' ], 'admin_notices', [ __CLASS__, 'display_admin_notice' ] );
	}

	public static function is_jetpack_boost_installed() {
		if ( defined( 'JETPACK_BOOST_VERSION' ) ) {
			return true;
		}

		if ( class_exists( 'Jetpack_Boost' ) ) {
			return true;
		}

		return false;
	}

	public static function display_admin_notice() {
		$admin_url = add_query_arg( [ 's' => 'Jetpack Boost' ], admin_url( 'plugins.php' ) );
		?>

		<div class="notice notice-warning">
			<p>
				<?php esc_html_e( 'Jetpack Boost is an active plugin. Easy Critical CSS has been paused to avoid conflicts.', 'easy-critical-css' ); ?>
			</p>
			<?php if ( current_user_can( 'activate_plugins' ) ) { ?>
				<p>
					<a href="<?php echo esc_url( $admin_url ); ?>" class="button button-primary">
						<?php esc_html_e( 'Manage Jetpack Boost', 'easy-critical-css' ); ?>
					</a>
				</p>
			<?php } ?>
		</div>
		<?php
	}
}
