<?php

function get_page_id_by_title($zoo_safari_pagename){
  $zoo_safari_args = array(
 'post_type' => 'page',
 'posts_per_page' => 1,
 'title' => $zoo_safari_pagename
  );
  $zoo_safari_query = new WP_Query( $zoo_safari_args );    $zoo_safari_page_id = '1';
 if (isset($zoo_safari_query->post->ID)) {
      $zoo_safari_page_id = $zoo_safari_query->post->ID;
  } return $zoo_safari_page_id;
}
//about theme info
add_action( 'admin_menu', 'zoo_safari_gettingstarted' );
function zoo_safari_gettingstarted() {
	add_theme_page( esc_html__('Zoo Safari', 'zoo-safari'), esc_html__('Zoo Safari', 'zoo-safari'), 'edit_theme_options', 'zoo_safari_about', 'zoo_safari_mostrar_guide');
}

// Add a Custom CSS file to WP Admin Area
function zoo_safari_admin_theme_style() {
	wp_enqueue_style('zoo-safari-custom-admin-style', esc_url(get_template_directory_uri()) . '/includes/getstart/getstart.css');
	wp_enqueue_script('zoo-safari-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('zoo-safari-notice', esc_url(get_template_directory_uri()) . '/includes/getstart/js/notice.js', array('jquery'), time(), true);
	wp_enqueue_script('zoo-safari-notice');
	// Admin notice code END
}
add_action('admin_enqueue_scripts', 'zoo_safari_admin_theme_style');

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

function zoo_safari_changelog_screen() {
	global $wp_filesystem;
	$zoo_safari_changelog_file = apply_filters( 'zoo_safari_changelog_file', ZOO_SAFARI_CHANGELOG_URL );

	if ( $zoo_safari_changelog_file && is_readable( $zoo_safari_changelog_file ) ) {
		WP_Filesystem();
		$zoo_safari_changelog = $wp_filesystem->get_contents( $zoo_safari_changelog_file );
		$zoo_safari_changelog_list = zoo_safari_parse_changelog( $zoo_safari_changelog );

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

function zoo_safari_parse_changelog( $zoo_safari_content ) {
	$zoo_safari_content = explode ( '== ', $zoo_safari_content );
	$zoo_safari_changelog_isolated = '';

	foreach ( $zoo_safari_content as $key => $zoo_safari_value ) {
		if ( strpos( $zoo_safari_value, 'Changelog ==' ) === 0 ) {
	    	$zoo_safari_changelog_isolated = str_replace( 'Changelog ==', '', $zoo_safari_value );
	    }
	}

	$zoo_safari_changelog_array = explode( '= ', $zoo_safari_changelog_isolated );
	unset( $zoo_safari_changelog_array[0] );

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

	return wp_kses_post( $zoo_safari_changelog );
}

//guidline for about theme
function zoo_safari_mostrar_guide() { 
	//custom function about theme customizer
	$zoo_safari_return = add_query_arg( array()) ;
	$zoo_safari_theme = wp_get_theme( 'zoo-safari' );
	?>
<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( ZOO_SAFARI_BUY_NOW ); ?>" target="_blank"><?php esc_html_e('Buy Premium Theme', 'zoo-safari'); ?></a>
				    </span>
			    </div>
		    </div>
        </div>					
   <div class="top-head">
	    <div class="top-title">
		     <h2><?php esc_html_e( 'Zoo Safari', 'zoo-safari' ); ?></h2>
		     <h4><?php esc_html_e( 'Welcome to WP Elemento Theme!', 'zoo-safari' ); ?></h4>
		     <p><?php esc_html_e( 'Click on the quick start button to import the demo.', 'zoo-safari' ); ?></p>
			    <div class="iner-sidebar-pro-btn">
					<?php if(!class_exists('WPElemento_Importer_ThemeWhizzie')){
						$zoo_safari_plugin_ins = Zoo_Safari_Plugin_Activation_WPElemento_Importer::get_instance();
						$zoo_safari_actions = $zoo_safari_plugin_ins->zoo_safari_recommended_actions;
					?>
					<div class="zoo-safari-recommended-plugins ">
						<div class="zoo-safari-action-list">
							<?php if ($zoo_safari_actions): foreach ($zoo_safari_actions as $zoo_safari_key => $zoo_safari_actionValue): ?>
									<div class="zoo-safari-action" id="<?php echo esc_attr($zoo_safari_actionValue['id']);?>">
										<div class="action-inner plugin-activation-redirect">
											<?php echo wp_kses_post($zoo_safari_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', 'zoo-safari'); ?></a>
						<?php
						$zoo_safari_page_id = get_page_id_by_title('Home');
						?>
						<a href="<?php echo esc_url( admin_url('post.php?post=' . $zoo_safari_page_id . '&action=elementor') ); ?>" 
							target="_blank" class="elementor-edit-btn"><?php esc_html_e('Edit With Elementor', 'zoo-safari'); ?>
						</a>
                    <?php else: ?>
                        <a href="<?php echo esc_url( admin_url('admin.php?page=wpelementoimporter-wizard') ); ?>"><?php esc_html_e('Quick Start', 'zoo-safari'); ?></a>
                    <?php endif; ?>
					<?php } ?>
				   </span>
				    <span class="premium-btn"><a href="<?php echo esc_url( ZOO_SAFARI_BUY_NOW ); ?>" target="_blank"><?php esc_html_e('Buy Premium', 'zoo-safari'); ?></a>
				    </span>
				    <span class="demo-btn"><a href="<?php echo esc_url( ZOO_SAFARI_LIVE_DEMO ); ?>" target="_blank"><?php esc_html_e('Live Demo', 'zoo-safari'); ?></a>
				    </span>
				    <span class="doc-btn"><a href="<?php echo esc_url( ZOO_SAFARI_THEME_BUNDLE ); ?>" target="_blank"><?php esc_html_e('Theme Bundle at $79', 'zoo-safari'); ?></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', 'zoo-safari' ); ?>: <?php echo esc_html($zoo_safari_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', 'zoo-safari'); ?></h1>
			     <div>
				    <p class="product-price"><?php esc_html_e('Price:', 'zoo-safari'); ?>
                        <span class="regular-price"><?php esc_html_e('$1,999.00', 'zoo-safari'); ?></span>
                        <span class="sale-price"><?php esc_html_e('$79.00', 'zoo-safari'); ?></span>
                    </p>
					<p><?php esc_html_e('The Elementor WordPress Theme Bundle offers a stunning collection of 76+ Premium Elementor Themes', 'zoo-safari'); ?></p>
                 </div>
				</div> 
			    <div class="offer-box"> 
				    <div class="offer1-box">
                       <span class="off-text1"><a href="<?php echo esc_url( ZOO_SAFARI_THEME_BUNDLE ); ?>" target="_blank"><?php esc_html_e('Buy Bundle at 20% Discount', 'zoo-safari'); ?></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', 'zoo-safari' ); ?></h3>
			  <div class="lite-theme-inner">
				<div>
					<h3><?php esc_html_e('Theme Customizer', 'zoo-safari'); ?></h3>
					<p><?php esc_html_e('To begin customizing your website, start by clicking "Customize".', 'zoo-safari'); ?></p>
					<div class="info-link">
					   <a target="_blank" href="<?php echo esc_url( admin_url('customize.php') ); ?>"><?php esc_html_e('Open customizer', 'zoo-safari'); ?></a>
					</div>
				</div>
				<div>
					<h3><?php esc_html_e('Help Docs', 'zoo-safari'); ?></h3>
					<p><?php esc_html_e('The complete procedure to configure and manage a WordPress Website from the beginning is shown in this documentation .', 'zoo-safari'); ?></p>
					<div class="info-link">
						<a href="<?php echo esc_url( ZOO_SAFARI_FREE_THEME_DOC ); ?>" target="_blank"><?php esc_html_e('Documentation', 'zoo-safari'); ?></a>
					</div>
				</div>
				<div>
					<h3><?php esc_html_e('Need Support?', 'zoo-safari'); ?></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.', 'zoo-safari'); ?></p>
					<div class="info-link">
						<a href="<?php echo esc_url( ZOO_SAFARI_SUPPORT ); ?>" target="_blank"><?php esc_html_e('Support Forum', 'zoo-safari'); ?></a>
					</div>
				</div>
				<div>
					<h3><?php esc_html_e('Reviews & Testimonials', 'zoo-safari'); ?></h3>
					<p> <?php esc_html_e('All the features and aspects of this WordPress Theme are phenomenal. I\'d recommend this theme to all.', 'zoo-safari'); ?></p>
					<div class="info-link">
						<a href="<?php echo esc_url( ZOO_SAFARI_REVIEW ); ?>" target="_blank"><?php esc_html_e('Review', 'zoo-safari'); ?></a>
					</div>
				</div>
            </div>	
		</div>
			<div class="tab-outer-box-2-2">
			  <h3><?php esc_html_e( 'Link to customizer', 'zoo-safari' ); ?></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','zoo-safari'); ?></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','zoo-safari'); ?></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','zoo-safari'); ?></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','zoo-safari'); ?></a>
						</div>
					</div>
				</div>
            </div>	
			<div class="tab-outer-box-2-3">
				<h3><?php esc_html_e( 'Change log', 'zoo-safari' ); ?></h3>	
		     <?php zoo_safari_changelog_screen(); ?>
          </div>	
        </div>
    </div>
</div>	
<?php } ?>