<?php


if ( ! defined( 'ABSPATH' ) ) {
	exit;
} // Exit if accessed directly.

function inpost_intl_system_check(): bool {

	if ( \PHP_VERSION_ID < 70200 ) {

		\add_action(
			'admin_notices',
			function () {
				echo "<div class='notice notice-error error'><p><strong style='color: red;'>Inpost International: ";
				echo esc_html__(
					'PHP version is older than 7.2 so this plugin will not work. Please contact your host and ask them to upgrade.',
					'inpost-international'
				);
				echo '</strong></p></div>';
			}
		);

		return false;
	}

	if (
		( function_exists( 'is_plugin_active' ) && is_plugin_active( 'woocommerce/woocommerce.php' ) )
		|| in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )
		|| ( defined( 'WC_PLUGIN_FILE' ) && defined( 'WC_VERSION' ) )
	) {

		return true;

	} else {

		add_action(
			'admin_notices',
			function () {

				$message = sprintf(
				/* translators: Placeholders: %1$s and %3$s are <strong> tags. %2$s and %4$s are text */
					'%1$s %2$s %3$s %4$s',
					'<strong>',
					esc_html__( 'InPost International', 'inpost-international' ),
					'</strong>',
					esc_html__( 'requires WooCommerce to function.', 'inpost-international' )
				);
				printf( '<div class="error"><p>%s</p></div>', wp_kses_post( $message ) );
			}
		);

		return false;
	}
}
