<?php
/**
 * File: Ecre_Notice.php
 *
 * The Ecre_Notice class manages all admon notices.
 *
 * @package ECRE
 * @since   1.2.3
 */

namespace ECRE;

if ( ! class_exists( 'Ecre_Notice' ) ) {
	/**
	 * The Ecre_Notice class manages all admon notices.
	 *
	 * @since 1.0.0
	 */
	class Ecre_Notice {
		/**
		 * Ecre_Notice constructor.
		 *
		 * Initializes all notice
		 *
		 * @since 1.2.3
		 */
		public function __construct() {
			$this->review_notice_by_condition();
			$this->review_affiliate_notice_by_condition();
			$this->review_upgrade_notice_by_condition();
		}

		/**
		 * Loads review notice based on condition.
		 *
		 * @since 1.2.3
		 */
		public function review_notice_by_condition() {
			$ecre_review_notice = get_option( 'ecre_review_notice' );
			if ( time() >= intval( get_option( 'ecre_deafult_review_notice_interval' ) ) ) {
				if ( false === $ecre_review_notice || empty( $ecre_review_notice ) ) {
					add_action( 'admin_notices', array( $this, 'show_review_notice' ) );
				}
			}
		}

		/**
		 * Load review affiliate notice condition.
		 *
		 * @since 1.2.3
		 */
		public function review_affiliate_notice_by_condition() {
			$affiliate_notice = get_option( 'ecre_affiliate_notice' );
			if ( time() >= intval( get_option( 'ecre_deafult_affiliate_notice_interval' ) ) ) {
				if ( false === $affiliate_notice || empty( $affiliate_notice ) ) {
					add_action( 'admin_notices', array( $this, 'show_affiliate_notice' ) );
				}
			}
		}

		/**
		 * Load Upgrade notice condition.
		 *
		 * @since 1.2.3
		 */
		public function review_upgrade_notice_by_condition() {
			$plugin_list = get_option( 'active_plugins' );

			if ( is_multisite() ) {
				$network_active_plugins = get_site_option( 'active_sitewide_plugins', array() );
				$plugin_list            = array_merge( $plugin_list, array_keys( $network_active_plugins ) );
			}

			$ecre_pro_path = 'echo-rewards-pro/echo-rewards.php';

			if ( ! ecre_check_pro_plugin_exists() || ! in_array( $ecre_pro_path, $plugin_list, true ) ) {
				$upgrade_notice = get_option( 'ecre_upgrade_notice' );
				if ( time() >= intval( get_option( 'ecre_deafult_upgrade_notice_interval' ) ) ) {
					if ( false === $upgrade_notice || empty( $upgrade_notice ) ) {
						add_action( 'admin_notices', array( $this, 'show_upgrade_notice' ) );
					}
				}
			}
		}

		/**
		 * Display plugin review notice.
		 *
		 * @return void
		 */
		public function show_review_notice() {
			load_template( ECRE_WP_DIR_PATH . 'includes/Templates/notices/review_notice.php' );
		}

		/**
		 * Display plugin review notice.
		 *
		 * @return void
		 */
		public function show_affiliate_notice() {
			load_template( ECRE_WP_DIR_PATH . 'includes/Templates/notices/affiliate_notice.php' );
		}

		/**
		 * Display plugin review notice.
		 *
		 * @return void
		 */
		public function show_upgrade_notice() {
			load_template( ECRE_WP_DIR_PATH . 'includes/Templates/notices/upgrade_notice.php' );
		}
	}

}
