<?php
/**
 * FASTX_Admin_Notice Action.
 * @package FASTX
 * @since v.1.0.0
 */
namespace FASTX;

defined('ABSPATH') || exit;

/**
 * FASTX_Admin_Notice class.
 */
class FASTX_Admin_Notice {

    /**
	 * Setup class.
	 * @since v.1.0.0
	*/
    public function __construct() {
        add_action( 'admin_notices', array( $this, 'render_dependency_notices' ), 0 );
    }

    /**
	 * Setup function to show notices
     * 
     * @since v1.0.0
	 * @return content
	*/
    public function render_dependency_notices() {
		if ( !$this->check_notice_show() ) {
            return;
        }
        wp_enqueue_style( "fastx-themepage", FASTX_DIR . '/assets/css/themepage.css', array(), FASTX_VER, 'all' );
        wp_enqueue_script( "fastx-themepage", FASTX_DIR . '/assets/js/themepage.js', array('jquery'), FASTX_VER, 'all' );
        
        ?>
            <div class="fsx_admin_notice_wrapper">
                <div class="fsx_admin_notice_close">&#x2715;</div>
                <div class="fsx_admin_notice_content">
                    <!-- welcome section -->
                    <div class="fsx_theme_welcome">
                    <div class="fsx_theme_welcome_left">
                        <div class="fsx_wc_title_sm">Hello, admin</div>
                        <div class="fsx_wc_title_wrap">
                            <div class="fsx_wc_title"><?php echo esc_html__( 'Get Premade', 'fastx' ) ?> <strong><?php echo esc_html__( 'Starter Sites Templates', 'fastx' ) ?></strong>  with  <strong>PostX</strong> </div>
                        </div>
                        <div class="fsx_theme_descp"><?php echo esc_html__( 'Install PostX now and unlock all exclusive templates along with the first ever ', 'fastx' ) ?> <strong>Dynamic Site Builder</strong> <?php echo esc_html__( ' that works with Gutenberg and 100s of other features.', 'fastx' ) ?></div>
                        <div class="fsx_wc_btns">
                            <div class="fsx_wc_imports">
                                <?php
                                    if( !file_exists(WP_PLUGIN_DIR.'/ultimate-post/ultimate-post.php') ) {
                                        ?> 
                                            <a id="fsx_install_btn" href="#"><span class="dashicons dashicons-image-rotate"></span><?php echo esc_html__('Install PostX', 'fastx'); ?></a>
                                        <?php 
                                    } else {
                                        if( ( file_exists(WP_PLUGIN_DIR.'/ultimate-post/ultimate-post.php') && ! is_plugin_active('ultimate-post/ultimate-post.php') ) ) {
                                            ?>
                                                <a id="fsx_activate_btn" href="<?php echo esc_url(add_query_arg(array('action' => 'ultp_activate'), admin_url())); ?>"><span class="dashicons dashicons-image-rotate"></span><?php echo esc_html__('Activate PostX', 'fastx'); ?></a>
                                            <?php
                                        } else {
                                            ?> 
                                                <a class="fsx_starter_btn" href="<?php echo esc_url(admin_url('admin.php?page=ultp-settings#startersites')) ?>"><?php echo esc_html__( 'Import Starter Sites', 'fastx' ) ?></a>
                                            <?php 
                                        }
                                    }
                                ?>
                            </div>
                            <div class="fsx_wc_demos">
                                <a href=<?php echo esc_url("https://www.wpxpo.com/postx/?utm_source=FastX-Dashboard&utm_medium=Learn-More&utm_campaign=FastX"); ?> target="_blank"><?php echo esc_html__( 'Learn More', 'fastx' ) ?><span class="dashicons dashicons-arrow-right-alt"></span></a>
                            </div>
                        </div>
                    </div>
                    <div class="fsx_theme_welcome_right">
                        <img class="thumbnail" src=" <?php echo FASTX_DIR.'/assets/img/postx_banner.jpg'; ?>" alt="PostX Intro Video">
                    </div>
                </div>
                </div>
            </div>
        <?php
	}
    /**
	 * Setup function to show notices
     * 
     * @since v1.0.0
	 * @return bool
	*/
    public function check_notice_show() {
        $current_screen = get_current_screen();
        if ( 
            is_plugin_active('ultimate-post/ultimate-post.php') ||
            get_option('fastx_postx_install_notice') == "no"  ||
            ( $current_screen != null && ! in_array( $current_screen->id, array( 'dashboard', 'themes', 'edit-post' ) ) ) ||
            ( defined('DOING_AJAX') && DOING_AJAX ) ||
            !current_user_can('manage_options')
        ) {
            return false;
        }
        return true;
    }

}