<?php
defined( 'ABSPATH' ) || exit;

/**
 * Wisnia Intro Page From The WordPress Admin Menu
 *
 * @author  Wisnia
 * @package Wisnia
 * @since   1.0.2
 */
/**
 * Class to handle notices and Advanced Demo Import
 *
 * Class Wisnia_Intro
 */
class Wisnia_Intro {

	/**
	 * current added Menu hook_suffix
	 *
	 * @since    1.0.0
	 * @access   public
	 * @var      array    $logs    Store logs and errors.
	 */
	private $hook_suffix;

	/**
	 * Empty Constructor
	 */
	public function __construct() {}

	/**
	 * Gets an instance of this object.
	 * Prevents duplicate instances which avoid artefacts and improves performance.
	 *
	 * @static
	 * @access public
	 * @since 1.0.0
	 * @return object
	 */
	public static function instance() {
		// Store the instance locally to avoid private static replication
		static $instance = null;

		// Only run these methods if they haven't been ran previously
		if ( null === $instance ) {
			$instance = new self();
		}

		// Always return the instance
		return $instance;
	}

	/**
	 * Initialize the class
	 *
	 * 3 Different Process
	 */
	public function run() {
		add_action( 'admin_menu', array( $this, 'intro' ) );
		add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts' ) );
	}

	/**
	 * Register the JavaScript for the admin area.
	 *
	 * @since    1.0.0
	 */
	public function add_scripts( $hook_suffix ) {
		if ( ! is_array( $this->hook_suffix ) || ! in_array( $hook_suffix, $this->hook_suffix ) ) {
			return;
		}
		wp_enqueue_style( 'wpness-grid', WISNIA_URL . '/inc/assets/library/wpness-grid/wpness-grid' . WISNIA_SCRIPT_PREFIX . '.css', array(), '1.0.0' );

		wp_enqueue_style( 'wisnia-notice', WISNIA_URL . '/inc/admin/notice.css', array(), '1.0.0' );
		wp_enqueue_script( 'wisnia-adi-install', WISNIA_URL . '/inc/admin/notice.js', array( 'jquery' ), '', true );

		$translation = array(
			'btn_text' => esc_html__( 'Processing...', 'wisnia' ),
			'nonce'    => wp_create_nonce( 'wisnia_demo_import_nonce' ),
		);
		wp_localize_script( 'wisnia-adi-install', 'wisnia_adi_install', $translation );
	}

	/**
	 * Add admin menus
	 * @access public
	 */
	public function intro() {
		$this->hook_suffix[] = add_theme_page( esc_html__( 'Wisnia Intro', 'wisnia' ), esc_html__( 'Wisnia Intro', 'wisnia' ), 'manage_options', 'wisnia-intro', array( $this, 'intro_screen' ) );
	}

	/**
	 * Show the plugin recommended screen
	 * @access public
	 * @return void
	 */
	public function intro_screen() {
		?>
		<div class="cwp-intro">
			<div class="cwp-intro-banner">
				<div class="grid-container">

					<div class="grid-row">
						<div class="grid-md-7 grid-lg-7">
							<div class="cwp-intro-banner-caption">
								<h2><?php esc_html_e( 'Welcome to Wisnia', 'wisnia' ); ?></h2>
								<p>
									<?php esc_html_e( 'Wisnia is now installed, to get the most out of this Theme we recommended that you complete the following steps:', 'wisnia' ); ?>
									<ul>
										<li><?php esc_html_e( '1. Click Download the Demo Zip and grab your zip file from the page', 'wisnia' ); ?></li>
										<li><?php esc_html_e( '2. Next click Get Started below to start the setup wizard', 'wisnia' ); ?></li>
										<li><?php esc_html_e( '3. On the following screen browse and select the 3 files (by file type) that you\'ll find in the zip you downloaded previously', 'wisnia' ); ?></li>
										<li><?php esc_html_e( '4. Finally click Import Demo Data to ensure your theme looks similar to the preview', 'wisnia' ); ?></li>
										<li><br></li>
										<li><em><?php esc_html_e( 'The entire process only takes a few clicks to complete and will speed up your setup by installing and activating the required plugins for things to display correctly. As well as importing example pages and layouts that can be easily customized.', 'wisnia' ); ?></em></li>
									</ul>
								</p>
								<a href="<?php echo esc_url( __( 'https://www.individualobligation.com/wordpress-theme-wisnia/#demo-setup', 'wisnia' ) ); ?>" class="cwp-btn cwp-btn-white-outline" target="_blank"><?php esc_html_e( 'Download the Demo Zip', 'wisnia' ); ?></a>
								<a href="#" class="cwp-btn wisnia-gsm-btn cwp-btn-primary"><?php esc_html_e( 'Get Started', 'wisnia' ); ?></a>

							</div>
						</div>
						<div class="grid-md-5 grid-lg-5">
							<img src="<?php echo esc_url( WISNIA_URL . '/assets/img/wisnia-welcome-page.png' ); ?>" alt="<?php esc_attr_e( 'Wisnia', 'wisnia' ); ?>" />
						</div>
					</div>
				</div>
			</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		<?php
	}
}

/**
 * Begins execution of the hooks.
 *
 * @since    1.0.0
 */
function wisnia_intro() {
	return Wisnia_Intro::instance();
}
wisnia_intro()->run();
