<?php
/**
 * Welcome Screen Class
 * Sets up the welcome screen page, hides the menu item
 * and contains the screen content.
 */
class Culinary_Welcome {

	/**
	 * Constructor
	 * Sets up the welcome screen
	 */
	public function __construct() {

		add_action( 'admin_menu', array( $this, 'recuethemes_culinary_welcome_register_menu' ) );
		add_action( 'load-themes.php', array( $this, 'recuethemes_culinary_activation_admin_notice' ) );
		add_action( 'admin_enqueue_scripts', array( $this, 'recuethemes_culinary_welcome_scripts' ) );

		add_action( 'recuethemes_culinary_welcome', array( $this, 'recuethemes_culinary_welcome_intro' ), 				10 );
		add_action( 'recuethemes_culinary_welcome', array( $this, 'recuethemes_culinary_welcome_tabs' ), 				20 );
		add_action( 'recuethemes_culinary_welcome', array( $this, 'recuethemes_culinary_welcome_getting_started' ), 	30 );
		add_action( 'recuethemes_culinary_welcome', array( $this, 'recuethemes_culinary_welcome_enhance' ), 				40 );
		add_action( 'recuethemes_culinary_welcome', array( $this, 'recuethemes_culinary_welcome_changelog' ), 		50 );

	} // end constructor

	/**
	 * Adds an admin notice upon successful activation.
	 */
	public function recuethemes_culinary_activation_admin_notice() {
		global $pagenow;

		if ( is_admin() && 'themes.php' == $pagenow && isset( $_GET['activated'] ) ) { // input var okay
			add_action( 'admin_notices', array( $this, 'recuethemes_culinary_welcome_admin_notice' ), 99 );
		}
	}

	/**
	 * Display an admin notice linking to the welcome screen
	 */
	public function recuethemes_culinary_welcome_admin_notice() {
		?>
			<div class="updated notice is-dismissible">
				<p><?php echo sprintf( esc_html__( 'Thanks for choosing Culinary! Get started by activating the recommended plugins and importing the demo content! Read instructions on the %1$stheme info screen%2$s.', 'culinary' ), '<a href="' . esc_url( admin_url( 'themes.php?page=culinary-welcome' ) ) . '">', '</a>' ); ?></p>
				<p><a href="<?php echo esc_url( admin_url( 'themes.php?page=culinary-welcome' ) ); ?>" class="button" style="text-decoration: none;"><?php _e( 'Theme Info Page', 'culinary' ); ?></a></p>
			</div>
		<?php
	}

	/**
	 * Load welcome screen style and scripts
	 * @return void
	 */
	public function recuethemes_culinary_welcome_scripts() {
		global $recuethemes_culinary_version;

		wp_enqueue_style( 'culinary-theme-info', get_template_directory_uri() . '/inc/theme-info/css/welcome.css', $recuethemes_culinary_version );
		wp_enqueue_script( 'thickbox' );
		wp_enqueue_style( 'thickbox' );
	}

	/**
	 * Creates the dashboard page
	 * @see  add_theme_page()
	 */
	public function recuethemes_culinary_welcome_register_menu() {
		add_theme_page( 'Theme Info', 'Theme Info', 'read', 'culinary-welcome', array( $this, 'recuethemes_culinary_welcome_screen' ) );
	}

	/**
	 * The welcome screen
	 */
	public function recuethemes_culinary_welcome_screen() {
		require_once( ABSPATH . 'wp-admin/admin.php' );
		require_once( ABSPATH . 'wp-admin/admin-header.php' );
		?>
		<div class="wrap about-wrap">

			<?php
			/**
			 * @hooked recuethemes_culinary_welcome_intro - 10
			 * @hooked recuethemes_culinary_welcome_getting_started - 20
			 * @hooked recuethemes_culinary_welcome_addons - 30
			 */
			do_action( 'recuethemes_culinary_welcome' ); ?>

		</div>
		<?php
	}

	/**
	 * Welcome screen intro
	 */
	public function recuethemes_culinary_welcome_intro() {
		require_once( get_template_directory() . '/inc/theme-info/sections/intro.php' );
	}

	/**
	 * Welcome screen intro
	 */
	public function recuethemes_culinary_welcome_tabs() {
		require_once( get_template_directory() . '/inc/theme-info/sections/tabs.php' );
	}

	/**
	 * Welcome screen getting started section
	 */
	public function recuethemes_culinary_welcome_getting_started() {
		require_once( get_template_directory() . '/inc/theme-info/sections/start.php' );
	}

	/**
	 * Welcome screen enhance theme
	 */
	public function recuethemes_culinary_welcome_enhance() {
		require_once( get_template_directory() . '/inc/theme-info/sections/enhance.php' );
	}

	/**
	 * Welcome screen changelog
	 */
	public function recuethemes_culinary_welcome_changelog() {
		require_once( get_template_directory() . '/inc/theme-info/sections/changelog.php' );
	}

	/**
	 * Display the changelog file from the theme
	 */
	public function recuethemes_culinary_changlog() {

		WP_Filesystem();
		global $wp_filesystem;

		$file = $wp_filesystem->get_contents( get_template_directory_uri() . '/changelog.txt' );
		$readme = nl2br( $file );

		return $readme;

	}

}

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