<?php
/**
 * Get Started Page
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Add menu under Appearance
function blogging_hub_add_theme_info_page() {
    add_theme_page(
        esc_html__('Get Started', 'blogging-hub'),
        esc_html__('Get Started', 'blogging-hub'),
        'manage_options',
        'blogging-hub-info',
        'blogging_hub_render_theme_info_page'
    );
}
add_action('admin_menu', 'blogging_hub_add_theme_info_page');


// Enqueue styles only on this page
function blogging_hub_admin_assets($blogging_hub_hook) {

    if ( $blogging_hub_hook !== 'appearance_page_blogging-hub-info' ) {
        return;
    }

    wp_enqueue_style(
        'blogging-hub-theme-info',
        get_template_directory_uri() . '/assets/css/theme-info.css',
        array(),
        wp_get_theme()->get('Version')
    );
}
add_action('admin_enqueue_scripts', 'blogging_hub_admin_assets');


// Render Page
function blogging_hub_render_theme_info_page() {

    $blogging_hub_theme = wp_get_theme();
    $blogging_hub_version = $blogging_hub_theme->get('Version');
    $blogging_hub_import_completed = (bool) get_option( 'blogging_hub_demo_import_completed', false );

    ?>
    <div class="wrap blogging-hub-dashboard">
		<h1 class="main-head-hidden"><?php echo esc_html( $blogging_hub_theme->get('Name') ); ?></h1>

        <!-- Header -->
        <div class="blogging-hub-header">
            <div class="blogging-hub-title">
                <h1><?php echo esc_html( $blogging_hub_theme->get('Name') ); ?></h1>
                <span><?php esc_html_e('Version', 'blogging-hub'); ?> <?php echo esc_html($blogging_hub_version); ?></span>
            </div>

            <div class="blogging-hub-header-buttons">
                <a href="<?php echo esc_url('https://www.apexthemes.net/products/blogging-wordpress-theme/'); ?>" target="_blank" rel="noopener noreferrer" class="btn-outline">
                    <?php esc_html_e('Get Premium', 'blogging-hub'); ?>
                </a>
                <a href="<?php echo esc_url('https://trial.apexthemes.net/blogging-hub/'); ?>" target="_blank" rel="noopener noreferrer" class="btn-outline">
                    <?php esc_html_e('Live Demo', 'blogging-hub'); ?>
                </a>
                <a href="<?php echo esc_url('https://trial.apexthemes.net/docs/blogging-hub-pro/'); ?>" target="_blank" rel="noopener noreferrer" class="btn-outline">
                    <?php esc_html_e('Documentation', 'blogging-hub'); ?>
                </a>
            </div>
        </div>

        <!-- Content -->
        <div class="blogging-hub-main">

            <!-- Left -->
            <div class="blogging-hub-left">
                <img src="<?php echo esc_url( get_template_directory_uri() . '/screenshot.png' ); ?>" alt="theme">

                <div class="blogging-hub-buttons">
                    <a href="<?php echo esc_url('https://www.apexthemes.net/products/blogging-wordpress-theme/'); ?>" target="_blank" rel="noopener noreferrer" class="btn-gradient">
                        <?php esc_html_e('Get Premium', 'blogging-hub'); ?>
                    </a>
                    <a href="<?php echo esc_url('https://trial.apexthemes.net/blogging-hub/'); ?>" target="_blank" rel="noopener noreferrer" class="btn-gradient">
                        <?php esc_html_e('Live Demo', 'blogging-hub'); ?>
                    </a>
                    <a href="<?php echo esc_url('https://trial.apexthemes.net/docs/blogging-hub-pro/'); ?>" target="_blank" rel="noopener noreferrer" class="btn-gradient">
                        <?php esc_html_e('Documentation', 'blogging-hub'); ?>
                    </a>
                </div>
            </div>

            <!-- Right -->
            <div class="blogging-hub-right">

                <h2>
                    <?php echo esc_html($blogging_hub_theme->get('Name')); ?>
                </h2>
                <div class="blogging-hub-default-content">

                    <p>
                        <?php echo esc_html($blogging_hub_theme->get('Description')); ?>
                    </p>

                    <?php if ( ! $blogging_hub_import_completed ) : ?>
                        <a href="#" id="blogging-hub-import-btn" class="btn-gradient">
                            <?php esc_html_e('Import Demo Now', 'blogging-hub'); ?>
                        </a>
                    <?php else : ?>
                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="btn-gradient" target="_blank" rel="noopener noreferrer">
                            <?php esc_html_e('Visit Site', 'blogging-hub'); ?>
                        </a>
                    <?php endif; ?>
                </div>

                <div class="blogging-hub-import-content">
                    <?php
                    require_once get_template_directory() . '/apex-library/dashboard/dashboard-contents.php';
                    
                    global $blogging_hub_config;
                    
                    if ( class_exists( 'Blogging_Hub_Whizzie' ) ) {
                        $blogging_hub_wiz = new Blogging_Hub_Whizzie( $blogging_hub_config );
                    
                        // NOTE: Only render the wizard UI — NOT header/wrapper/tabs
                        $blogging_hub_wiz->wizard_page();
                    }
                    ?>
                </div>
                    
			</div>

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