<?php

function get_page_id_by_title($comic_ebook_pagename){
  $comic_ebook_args = array(
 'post_type' => 'page',
 'posts_per_page' => 1,
 'title' => $comic_ebook_pagename
  );
  $comic_ebook_query = new WP_Query( $comic_ebook_args );    $comic_ebook_page_id = '1';
 if (isset($comic_ebook_query->post->ID)) {
      $comic_ebook_page_id = $comic_ebook_query->post->ID;
  } return $comic_ebook_page_id;
}
//about theme info
add_action( 'admin_menu', 'comic_ebook_gettingstarted' );
function comic_ebook_gettingstarted() {
	add_theme_page( esc_html__('Comic Ebook', 'comic-ebook'), esc_html__('Comic Ebook', 'comic-ebook'), 'edit_theme_options', 'comic_ebook_about', 'comic_ebook_mostrar_guide');
}

// Add a Custom CSS file to WP Admin Area
function comic_ebook_admin_theme_style() {
	wp_enqueue_style('comic-ebook-custom-admin-style', esc_url(get_template_directory_uri()) . '/includes/getstart/getstart.css');
	wp_enqueue_script('comic-ebook-tabs', esc_url(get_template_directory_uri()) . '/includes/getstart/js/tab.js');
	wp_enqueue_style( 'font-awesome-css', get_template_directory_uri().'/assets/css/fontawesome-all.css' );

	// Admin notice code START
	wp_register_script('comic-ebook-notice', esc_url(get_template_directory_uri()) . '/includes/getstart/js/notice.js', array('jquery'), time(), true);
	wp_enqueue_script('comic-ebook-notice');
	// Admin notice code END
}
add_action('admin_enqueue_scripts', 'comic_ebook_admin_theme_style');

// Changelog
if ( ! defined( 'COMIC_EBOOK_CHANGELOG_URL' ) ) {
    define( 'COMIC_EBOOK_CHANGELOG_URL', get_template_directory() . '/readme.txt' );
}

function comic_ebook_changelog_screen() {
	global $wp_filesystem;
	$comic_ebook_changelog_file = apply_filters( 'comic_ebook_changelog_file', COMIC_EBOOK_CHANGELOG_URL );

	if ( $comic_ebook_changelog_file && is_readable( $comic_ebook_changelog_file ) ) {
		WP_Filesystem();
		$comic_ebook_changelog = $wp_filesystem->get_contents( $comic_ebook_changelog_file );
		$comic_ebook_changelog_list = comic_ebook_parse_changelog( $comic_ebook_changelog );

		// ✅ wrapper + button add kiya gaya hai
		echo '<div id="comic-ebook-changelog-container">';
		echo wp_kses_post( $comic_ebook_changelog_list );
		echo '</div>';
		echo '<button id="comic-ebook-load-more" class="button button-primary" style="margin-top:15px;">Load More</button>';
	}
}

function comic_ebook_parse_changelog( $comic_ebook_content ) {
	$comic_ebook_content = explode ( '== ', $comic_ebook_content );
	$comic_ebook_changelog_isolated = '';

	foreach ( $comic_ebook_content as $key => $comic_ebook_value ) {
		if ( strpos( $comic_ebook_value, 'Changelog ==' ) === 0 ) {
	    	$comic_ebook_changelog_isolated = str_replace( 'Changelog ==', '', $comic_ebook_value );
	    }
	}

	$comic_ebook_changelog_array = explode( '= ', $comic_ebook_changelog_isolated );
	unset( $comic_ebook_changelog_array[0] );

	$comic_ebook_changelog = '<div class="changelog">';
	foreach ( $comic_ebook_changelog_array as $comic_ebook_value ) {
		$comic_ebook_value = preg_replace( '/\n+/', '</span><span>', $comic_ebook_value );
		$comic_ebook_value = '<div class="block-changelog"><span class="heading">= ' . $comic_ebook_value . '</span></div>';
		$comic_ebook_changelog .= str_replace( '<span></span>', '', $comic_ebook_value );
	}
	$comic_ebook_changelog .= '</div>';

	return wp_kses_post( $comic_ebook_changelog );
}

//guidline for about theme
function comic_ebook_mostrar_guide() { 
	//custom function about theme customizer
	$comic_ebook_return = add_query_arg( array()) ;
	$comic_ebook_theme = wp_get_theme( 'comic-ebook' );
	?>
<div class="container-getstarted">
		<div class="inner-side-content1">
			<div class="tab-outer-box">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/includes/getstart/images/sticky-header-logo.png" />
			</div>
		    <div class="coupon-container-box-left">
			    <div class="iner-sidebar-pro-btn">
				    <span class="premium-btn"><a href="<?php echo esc_url( COMIC_EBOOK_BUY_NOW ); ?>" target="_blank"><?php esc_html_e('Buy Premium Theme', 'comic-ebook'); ?></a>
				    </span>
			    </div>
		    </div>
        </div>					
   <div class="top-head">
	    <div class="top-title">
		     <h2><?php esc_html_e( 'Comic Ebook', 'comic-ebook' ); ?></h2>
		     <h4><?php esc_html_e( 'Welcome to WP Elemento Theme!', 'comic-ebook' ); ?></h4>
		     <p><?php esc_html_e( 'Click on the quick start button to import the demo.', 'comic-ebook' ); ?></p>
			    <div class="iner-sidebar-pro-btn">
					<?php if(!class_exists('WPElemento_Importer_ThemeWhizzie')){
						$comic_ebook_plugin_ins = Comic_Ebook_Plugin_Activation_WPElemento_Importer::get_instance();
						$comic_ebook_actions = $comic_ebook_plugin_ins->comic_ebook_recommended_actions;
					?>
					<div class="comic-ebook-recommended-plugins ">
						<div class="comic-ebook-action-list">
							<?php if ($comic_ebook_actions): foreach ($comic_ebook_actions as $comic_ebook_key => $comic_ebook_actionValue): ?>
									<div class="comic-ebook-action" id="<?php echo esc_attr($comic_ebook_actionValue['id']);?>">
										<div class="action-inner plugin-activation-redirect">
											<?php echo wp_kses_post($comic_ebook_actionValue['link']); ?>
										</div>
									</div>
								<?php endforeach;
							endif; ?>
						</div>
					</div>
				   <?php }else{ ?>
					<span class="quick-btn">
				    <?php if (isset($_GET['imported']) && $_GET['imported'] == 'true'): ?>
                        <a href="<?php echo esc_url( site_url() ); ?>" target="_blank"><?php esc_html_e('Visit Site', 'comic-ebook'); ?></a>
						<?php
						$comic_ebook_page_id = get_page_id_by_title('Home');
						?>
						<a href="<?php echo esc_url( admin_url('post.php?post=' . $comic_ebook_page_id . '&action=elementor') ); ?>" 
							target="_blank" class="elementor-edit-btn"><?php esc_html_e('Edit With Elementor', 'comic-ebook'); ?>
						</a>
                    <?php else: ?>
                        <a href="<?php echo esc_url( admin_url('admin.php?page=wpelementoimporter-wizard') ); ?>"><?php esc_html_e('Quick Start', 'comic-ebook'); ?></a>
                    <?php endif; ?>
					<?php } ?>
				   </span>
				    <span class="premium-btn"><a href="<?php echo esc_url( COMIC_EBOOK_BUY_NOW ); ?>" target="_blank"><?php esc_html_e('Buy Premium', 'comic-ebook'); ?></a>
				    </span>
				    <span class="demo-btn"><a href="<?php echo esc_url( COMIC_EBOOK_LIVE_DEMO ); ?>" target="_blank"><?php esc_html_e('Live Demo', 'comic-ebook'); ?></a>
				    </span>
				    <span class="doc-btn"><a href="<?php echo esc_url( COMIC_EBOOK_THEME_BUNDLE ); ?>" target="_blank"><?php esc_html_e('Theme Bundle at $89', 'comic-ebook'); ?></a>
				    </span>
			    </div>
            </div>			
		<div class="inner-side-content">
			<div class="tab-outer-box">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/screenshot.png" />
			</div>
			<div class="top-right">
			  <span class="version"><?php esc_html_e( 'Version', 'comic-ebook' ); ?>: <?php echo esc_html($comic_ebook_theme['Version']);?></span>
		    </div>
		</div>
    </div>
    <div class="inner-cont">
	    <div class="tab-outer-box1">
		   <div class="tab-inner-box">
			   <div class= "bundle-box">
				    <img src="<?php echo esc_url(get_template_directory_uri()); ?>/includes/getstart/images/bundle.png"/>
				    <h1><?php esc_html_e('ELEMENTOR WORDPRESS THEME BUNDLE', 'comic-ebook'); ?></h1>
			     <div>
				    <p class="product-price"><?php esc_html_e('Price:', 'comic-ebook'); ?>
                        <span class="regular-price"><?php esc_html_e('$1,999.00', 'comic-ebook'); ?></span>
                        <span class="sale-price"><?php esc_html_e('$89.00', 'comic-ebook'); ?></span>
                    </p>
					<p><?php esc_html_e('The Elementor WordPress Theme Bundle offers a stunning collection of 120+ Premium Elementor Themes', 'comic-ebook'); ?></p>
                 </div>
				</div> 
			    <div class="offer-box"> 
				    <div class="offer1-box">
                       <span class="off-text1"><a href="<?php echo esc_url( COMIC_EBOOK_THEME_BUNDLE ); ?>" target="_blank"><?php esc_html_e('Buy Bundle at 20% Discount', 'comic-ebook'); ?></a></span>
				    </div> 
		        </div>
			</div>	
		</div>	
		<div class="tab-outer-box2">
			<div class="tab-outer-box-2-1">
			  <h3><?php esc_html_e( 'Customizer Setting', 'comic-ebook' ); ?></h3>
			  <div class="lite-theme-inner">
				<div>
					<h3><?php esc_html_e('Theme Customizer', 'comic-ebook'); ?></h3>
					<p><?php esc_html_e('To begin customizing your website, start by clicking "Customize".', 'comic-ebook'); ?></p>
					<div class="info-link">
					   <a target="_blank" href="<?php echo esc_url( admin_url('customize.php') ); ?>"><?php esc_html_e('Open customizer', 'comic-ebook'); ?></a>
					</div>
				</div>
				<div>
					<h3><?php esc_html_e('Help Docs', 'comic-ebook'); ?></h3>
					<p><?php esc_html_e('The complete procedure to configure and manage a WordPress Website from the beginning is shown in this documentation .', 'comic-ebook'); ?></p>
					<div class="info-link">
						<a href="<?php echo esc_url( COMIC_EBOOK_FREE_THEME_DOC ); ?>" target="_blank"><?php esc_html_e('Documentation', 'comic-ebook'); ?></a>
					</div>
				</div>
				<div>
					<h3><?php esc_html_e('Need Support?', 'comic-ebook'); ?></h3>
					<p><?php esc_html_e('Our dedicated team is well prepared to help you out in case of queries and doubts regarding our theme.', 'comic-ebook'); ?></p>
					<div class="info-link">
						<a href="<?php echo esc_url( COMIC_EBOOK_SUPPORT ); ?>" target="_blank"><?php esc_html_e('Support Forum', 'comic-ebook'); ?></a>
					</div>
				</div>
				<div>
					<h3><?php esc_html_e('Reviews & Testimonials', 'comic-ebook'); ?></h3>
					<p> <?php esc_html_e('All the features and aspects of this WordPress Theme are phenomenal. I\'d recommend this theme to all.', 'comic-ebook'); ?></p>
					<div class="info-link">
						<a href="<?php echo esc_url( COMIC_EBOOK_REVIEW ); ?>" target="_blank"><?php esc_html_e('Review', 'comic-ebook'); ?></a>
					</div>
				</div>
            </div>	
		</div>
			<div class="tab-outer-box-2-2">
			  <h3><?php esc_html_e( 'Link to customizer', 'comic-ebook' ); ?></h3>
				<div class="first-row">
					<div class="row-box">
						<div class="row-box1">
							<span class="dashicons dashicons-buddicons-buddypress-logo"></span><a href="<?php echo esc_url( admin_url('customize.php?autofocus[control]=custom_logo') ); ?>" target="_blank"><?php esc_html_e('Upload your Website logo','comic-ebook'); ?></a>
						</div>
						<div class="row-box2">
							<span class="dashicons dashicons-menu"></span><a href="<?php echo esc_url( admin_url('customize.php?autofocus[panel]=nav_menus') ); ?>" target="_blank"><?php esc_html_e('Edit Your Menus','comic-ebook'); ?></a>
						</div>
					</div>
							
					<div class="row-box">
						<div class="row-box1">
							<span class="dashicons dashicons-align-center"></span><a href="<?php echo esc_url( admin_url('customize.php?autofocus[section]=header_image') ); ?>" target="_blank"><?php esc_html_e('Add Header Image','comic-ebook'); ?></a>
						</div>
						<div class="row-box2">
							<span class="dashicons dashicons-screenoptions"></span><a href="<?php echo esc_url( admin_url('customize.php?autofocus[panel]=widgets') ); ?>" target="_blank"><?php esc_html_e('Add Footer Widget','comic-ebook'); ?></a>
						</div>
					</div>
				</div>
            </div>	
			<div class="tab-outer-box-2-3">
				<h3><?php esc_html_e( 'Change log', 'comic-ebook' ); ?></h3>	
		     <?php comic_ebook_changelog_screen(); ?>
          </div>	
        </div>
    </div>
</div>	
<?php } ?>