<?php
/**
 * Functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package nas-construction-lite
 * @since 1.0.0
 */

/**
 * The theme version.
 *
 * @since 1.0.0
 */
define( 'NAS_CONSTRUCTION_LITE_VERSION', wp_get_theme()->get( 'Version' ) );

/**
 * Add theme support for block styles and editor style.
 *
 * @since 1.0.0
 *
 * @return void
 */
function nas_construction_lite_setup() {
	add_editor_style( './assets/css/style-shared.css' );

	/*
	 * Load additional block styles.
	 * See details on how to add more styles in the readme.txt.
	 */
	$styled_blocks = [ 'button', 'quote', 'navigation', 'search', 'blocks' ];
	foreach ( $styled_blocks as $block_name ) {
		$args = array(
			'handle' => "nas-construction-lite-$block_name",
			'src'    => get_theme_file_uri( "assets/css/blocks/$block_name.min.css" ),
			'path'   => get_theme_file_path( "assets/css/blocks/$block_name.min.css" ),
		);
		// Replace the "core" prefix if you are styling blocks from plugins.
		wp_enqueue_block_style( "core/$block_name", $args );
	}

}
add_action( 'after_setup_theme', 'nas_construction_lite_setup' );

/**
 * Enqueue the CSS files.
 *
 * @since 1.0.0
 *
 * @return void
 */
function nas_construction_lite_styles() {
	wp_enqueue_style(
		'nas-construction-lite-style',
		get_stylesheet_uri(),
		[],
		NAS_CONSTRUCTION_LITE_VERSION
	);
	wp_enqueue_style(
		'nas-construction-lite-shared-styles',
		get_theme_file_uri( 'assets/css/style-shared.css' ),
		[],
		NAS_CONSTRUCTION_LITE_VERSION
	);
}
add_action( 'wp_enqueue_scripts', 'nas_construction_lite_styles' );

/**
 * Enqueue the admin CSS files.
 *
 * @since 1.0.0
 *
 * @return void
 */
function nas_construction_lite_admin_styles() {
	wp_enqueue_style(
		'nas-construction-lite-theme-info-style',
		get_template_directory_uri() . '/assets/css/theme-info.css',
		[],
		NAS_CONSTRUCTION_LITE_VERSION
	);
}
add_action( 'admin_enqueue_scripts', 'nas_construction_lite_admin_styles' );

/**
 * Custom Menu Page.
 *
 * @since 1.0.0
 *
 * @return void
 */
function nas_construction_lite_menu_page() {
    add_submenu_page(
        'themes.php', // Parent slug: 'themes.php' is for Appearance menu
        'Theme Page', // Page title
        'Theme Demos', // Menu title
        'manage_options', // Capability
        'theme-menu-page', // Menu slug
        'nas_construction_lite_menu_page_callback' // Callback function
    );
}
add_action('admin_menu', 'nas_construction_lite_menu_page');

function nas_construction_lite_menu_page_callback() {
	$theme         = wp_get_theme();
    $theme_name    = $theme->get('Name');
    $theme_version = $theme->get( 'Version' );
    $theme_slug    = $theme->get_template();
    ?>
    <div class="theme-wrap">
    	<div class="theme-wrap-inner">
	        <h1><?php echo esc_html__( 'Welcome to the', 'nas-construction-lite' ) . ' ' . esc_html( $theme_name ) . ' ' . esc_html( $theme_version ); ?></h1>
	        <p><?php echo esc_html( $theme_name ) . ' ' . esc_html__( 'is now installed and ready to use.', 'nas-construction-lite' ); ?></p>

		<div class="theme-demo">

			<ul>
				<li>
				<?php echo '<img src="' . get_template_directory_uri() . '/screenshot.png" alt="screenshot" />'; ?>	
				<?php echo '<h2 "class="button button-hero button-secondary">' . esc_html__( 'Construction ', 'nas-construction-lite' ).'</h2>'; ?>
				<?php echo '<a href="' . esc_url( 'https://demo.templatehouse.net/constructionpro/', 'nas-construction-lite' ) . '" rel="nofollow" target="_blank" class="button button-hero button-secondary">' . esc_html__( 'Live Preview', 'nas-construction-lite' ).'</a>'; ?>
			
			</li>
			</ul>

		</div>


	        <div class="quick-links">
	        	<?php
	        	echo '<a href="' . esc_url( 'https://www.templatehouse.net/themes/nas-responsive-multi-purpose-wordpress-theme/', 'nas-construction-lite' ) . '" rel="nofollow" target="_blank" class="button button-hero button-primary">' . esc_html__( 'Buy Pro', 'nas-construction-lite' ).'</a>';
	        	echo '<a href="' . esc_url( 'https://www.templatehouse.net/themes/nas-responsive-multi-purpose-wordpress-theme/', 'nas-construction-lite' ) . '" rel="nofollow" target="_blank" class="button button-hero button-secondary">' . esc_html__( 'Theme Info', 'nas-construction-lite' ).'</a>';
	        	?>
	        </div>
    	</div>
    </div>
    <?php
}

// Filters.
require_once get_theme_file_path( 'inc/filters.php' );

// Block variation example.
require_once get_theme_file_path( 'inc/register-block-variations.php' );

// Block style examples.
require_once get_theme_file_path( 'inc/register-block-styles.php' );

// Block pattern and block category examples.
require_once get_theme_file_path( 'inc/register-block-patterns.php' );

/**
 * Info
 */
require get_theme_file_path( '/inc/admin/info.php' );