<?php

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

if( !class_exists( 'tipcg_admin_notice' ) ) {

	class tipcg_admin_notice {
	
		/**
		 * Constructor
		 */
		 
		public function __construct( $fields = array() ) {

			if ( 
				current_user_can('manage_options') &&
				!get_user_meta( get_current_user_id(), 'tipcg_notice_userid_' . get_current_user_id() , TRUE )
			) {

				add_action( 'admin_init', array(&$this, 'add_script') ,11);
				add_action( 'admin_notices', array(&$this, 'admin_notice') );
				add_action( 'admin_head', array( $this, 'dismiss' ) );

			}

		}

		/**
		 * Loads the plugin scripts and styles
		 */

		public function add_script() {

			global $wp_version, $pagenow;

			$file_dir = plugins_url('/assets/', dirname(__FILE__));
			wp_enqueue_style( 'tipcg_notice', $file_dir . 'css/notice.css', array(), TIPCG_VERSION );

		}

		/**
		 * Dismiss notice.
		 */
		
		public function dismiss() {
		
			if (
				current_user_can( 'manage_options' ) &&
				isset( $_GET['tipcg-dismiss'], $_GET['_wpnonce'] ) &&
				wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'tipcg_dismiss_notice' )
			) {
		
				update_user_meta( get_current_user_id(), 'tipcg_notice_userid_' . get_current_user_id() , absint( wp_unslash( $_GET['tipcg-dismiss'] ) ) );
				remove_action( 'admin_notices', array(&$this, 'admin_notice') );
				
			} 
		
		}

		/**
		 * Admin notice.
		 */
		 
		public function admin_notice() {
			
			global $pagenow;
			$redirect = ( 'admin.php' == $pagenow ) ? '?page=tipcg_panel&tipcg-dismiss=1' : '?tipcg-dismiss=1';
			$dismiss_url = wp_nonce_url( $redirect, 'tipcg_dismiss_notice' );
			
		?>
			
            <div class="update-nag notice tipcg-notice">
            
            	<div class="tipcg-noticedescription">

					<strong><?php esc_html_e( 'Upgrade to TIP Countdown Generator to unlock premium features like...', 'tip-countdown-generator' );?></strong>

					<p class="notice-coupon-message">

						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Premium countdown templates and animations', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Recurring countdown schedules', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Action on expiry settings', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Redirect or message after countdown expiry', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Dynamic shortcode generator', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Gutenberg blocks', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Elementor widgets', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Duplicate countdowns', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Logged-in user tracking', 'tip-countdown-generator' ); ?><br/>
						<span class="dashicon dashicons dashicons-yes-alt" size="10"></span><?php esc_html_e( 'Advanced recurring start and pause behavior', 'tip-countdown-generator' ); ?><br/>

					</p>

					<a class="button" href="<?php echo esc_url(admin_url( 'admin.php?page=tipcg_panel&tab=Free_vs_Pro' )); ?>" ><?php esc_html_e( 'Free vs Pro', 'tip-countdown-generator' ); ?></a>

					<a class="button" target="_blank" href="<?php echo esc_url( TIPCG_UPGRADE_LINK . '/?ref=2&campaign=tipcg-notice' ); ?>"><?php esc_html_e( 'Upgrade Now', 'tip-countdown-generator' ); ?></a>
					
					<div class="clear"></div>

					<?php printf( '<a href="%1$s" class="dismiss-notice">'. esc_html__( 'Dismiss this notice', 'tip-countdown-generator' ) .'</a>', esc_url($dismiss_url) ); ?>

				</div>

				<div class="clear"></div>

            </div>
		
		<?php
		
		}

	}

}

new tipcg_admin_notice();

?>
