<?php
/**
 * Welcome Screen Class
 */
class non_profit_elementor_screen {

	/**
	 * Constructor for the Notice
	 */
	public function __construct() {
		/* activation notice */
		add_action( 'load-themes.php', array( $this, 'non_profit_elementor_activation_admin_notice' ) );
		add_action( 'wp_ajax_non_profit_elementor_dismiss_notice', array( $this, 'non_profit_elementor_dismiss_notice' ) );
	}
	
	public function non_profit_elementor_activation_admin_notice() {
		global $pagenow;

		if ( is_admin() && ('themes.php' == $pagenow) ) {
			add_action( 'admin_notices', array( $this, 'non_profit_elementor_admin_notice' ), 99 );
		}
	}

	
	public function non_profit_elementor_admin_notice() {
		// Check if user has already dismissed the notice
	    if ( get_user_meta( get_current_user_id(), 'non_profit_elementor_notice_dismissed', true ) ) {
	        return;
	    }
	    ?>	
		
		<div class="notice notice-success is-dismissible non-profit-elementor-notice">
	        <h1>
	        	<?php
				$theme_info = wp_get_theme();
				printf( 
					esc_html__('Thanks for installing  %1$s ', 'non-profit-elementor'), 
					esc_html( $theme_info->Name ), 
					esc_html( $theme_info->Version ) 
				);
				?>
			</h1>
	        <p><?php echo  esc_html__("Welcome! Thank you for choosing non profit elementor WordPress theme. To take full advantage of the features this theme Please Install Our Demo", "non-profit-elementor"); ?></p>
	        <p class="note1">
	        	<a href="https://testerwp.com/docs/non-profit-elementor/how-to-install-non-profit-elementor-theme/" class="button button-blue-secondary button_info" style="text-decoration: none;" target="_blank"><?php echo esc_html__('Read Documentation','non-profit-elementor'); ?></a> 
	        	<a href="themes.php?page=texture_started" target="_blank" class="button button-blue-secondary button_info" style="text-decoration: none;"><?php echo esc_html__('View Details','non-profit-elementor'); ?></a>
	        </p>
	    </div>

		<script type="text/javascript">
	    jQuery(document).on('click', '.non-profit-elementor-notice .notice-dismiss', function () {
	        jQuery.post(ajaxurl, {
	            action: 'non_profit_elementor_dismiss_notice'
	        });
	    });
	    </script>
	    <?php
	}

	public function non_profit_elementor_dismiss_notice() {
	    update_user_meta(get_current_user_id(), 'non_profit_elementor_notice_dismissed', 1);
	    wp_die();
	}
	
}

$GLOBALS['non_profit_elementor_screen'] = new non_profit_elementor_screen();

function non_profit_elementor_scripts_fn() {

    global $non_profit_elementor_theme_version;

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'admin_enqueue_scripts', 'non_profit_elementor_scripts_fn' );


?>