<?php
/**
 * About Wacko
 *
 * @package Wacko
 */

function about_wacko() {
	add_theme_page( esc_html__( 'About Wacko', 'wacko' ), esc_html__( 'About Wacko', 'wacko' ), 'edit_theme_options', 'about-wacko', 'about_wacko_page' );
}

add_action( 'admin_menu', 'about_wacko' );


/**
 * Enqueue css
 */

function wacko_enqueue_about_info_scripts($hook) {
	if ( 'appearance_page_about-wacko' != $hook ) {
		return;
	}
	// enqueue CSS
	wp_enqueue_style( 'about-wacko-page-css', get_theme_file_uri( '/inc/about-wacko/css/about-wacko.css' ) );
}

add_action( 'admin_enqueue_scripts', 'wacko_enqueue_about_info_scripts' );


/**
 * Check if plugin is installed
 */

function wacko_check_if_plugin_installed( $slug, $filename ) {
	return file_exists( ABSPATH . 'wp-content/plugins/' . $slug . '/' . $filename . '.php' ) ? true : false;
}


/**
 * Generate Recommended Plugin HTML
 */

function wacko_recommended_plugin( $slug, $filename, $name, $description) {
	$img_size = '128x128';
?>

	<div class="plugin-card">
		<div class="name column-name">
			<h3>
				<?php echo esc_html( $name ); ?>
				<img src="<?php echo esc_url('https://ps.w.org/'. $slug .'/assets/icon-'. $img_size .'.png') ?>" class="plugin-icon" alt="">
			</h3>
		</div>
		<div class="action-links">

			<?php if ( wacko_check_if_plugin_installed( $slug, $filename ) ) : ?>

			<button type="button" class="button button-disabled" disabled="disabled"><?php esc_html_e( 'Installed', 'wacko' ); ?></button>

			<?php else : ?>

			<a class="install-now button-primary" href="<?php echo esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin='. $slug ), 'install-plugin_'. $slug ) ); ?>" >

				<?php esc_html_e( 'Install Now', 'wacko' ); ?>

			</a>							

			<?php endif; ?>

		</div>

		<div class="desc column-description">

			<p><?php echo esc_html( $description ); ?></p>

		</div>
	</div>

<?php

}

/**
 * Changelog tab
 */

function parse_changelog() {

    WP_Filesystem();
    global $wp_filesystem;
    $changelog = $wp_filesystem->get_contents( get_template_directory() . '/inc/about-wacko/changelog.txt' );
    if ( is_wp_error( $changelog ) ) {
        $changelog = '';
    }
    return $changelog;
}


/**
 * Render About Wacko HTML
 */

function about_wacko_page() {

?>

	<div class="info-wrap">
		<h1> <?php esc_html_e( 'Welcome to Wacko !', 'wacko' ); ?> </h1>
		<p class="welcome-text">
			<?php esc_html_e( 'Wacko is a clean, responsive theme that’s versatile and easy to use. Suitable for both corporate and creative businesses, this elegant themes design gives you maximum flexibility. Wacko has definitely been designed with business owners in mind. With an intuitive design and userfriendly theme options, building your business website can be a breeze.', 'wacko' ); ?>
		</p>

		<!-- Tabs -->
		<?php $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'getting_started'; ?>  

		<div class="tab-navigation-wrapper">
			<a href="?page=about-wacko&tab=getting_started" class="nav-tab <?php echo $active_tab == 'getting_started' ? 'nav-tab-active' : ''; ?>">
				<?php esc_html_e( 'Getting Started', 'wacko' ); ?>
			</a>
			<a href="?page=about-wacko&tab=recommended_plugins" class="nav-tab <?php echo $active_tab == 'recommended_plugins' ? 'nav-tab-active' : ''; ?>">
				<?php esc_html_e( 'Recommended Plugins', 'wacko' ); ?>
			</a>

			<a href="?page=about-wacko&tab=support" class="nav-tab <?php echo $active_tab == 'support' ? 'nav-tab-active' : ''; ?>">
				<?php esc_html_e( 'Support', 'wacko' ); ?>
			</a>
			<a href="?page=about-wacko&tab=changelog" class="nav-tab <?php echo $active_tab == 'changelog' ? 'nav-tab-active' : ''; ?>">
				<?php esc_html_e( 'Changelog', 'wacko' ); ?>
			</a>
			<a href="?page=about-wacko&tab=free_vs_pro" class="nav-tab <?php echo $active_tab == 'free_vs_pro' ? 'nav-tab-active' : ''; ?>">
				<?php esc_html_e( 'Free vs Pro', 'wacko' ); ?>
			</a>
		</div>

		<!-- Tab Content -->

		<?php if ( $active_tab == 'getting_started' ) : ?>
			<div class="col-3-wrapper">
				<div class="col-3">
					<h3>
						<span class="dashicons dashicons-book"></span>
						<?php esc_html_e( 'Theme Documentation', 'wacko' ); ?>
					</h3>
					<p>
						<?php esc_html_e( 'Highly recommended to begin with this, read the full theme documentation to understand the basics and even more details about how to use Wacko.', 'wacko' ); ?>
					</p>

					<a target="_blank" href="<?php echo esc_url('https://www.lilyturfthemes.com/docs/wacko/'); ?>" class="button button-primary"><?php esc_html_e( 'View documentation', 'wacko' ); ?></a>
				</div>

				<div class="col-3">
					<h3>
						<span class="dashicons dashicons-admin-customizer"></span>
						<?php esc_html_e( 'Theme Customizer', 'wacko' ); ?>
					</h3>
					<p>
					<?php esc_html_e( 'After reading the Theme Documentation we recommend you to open the Theme Customizer and play with available options. You will enjoy it.', 'wacko' ); ?>
					</p>
					<a target="_blank" href="<?php echo esc_url( wp_customize_url() );?>" class="button button-primary"><?php esc_html_e( 'Customize Your Site', 'wacko' ); ?></a>
				</div>

				<div class="col-3">
					<h3>
						<span class="dashicons dashicons-star-filled"></span>
						<?php esc_html_e( 'Pro Version', 'wacko' ); ?>
					</h3>
					<p>
						<?php esc_html_e( 'Upgrade to pro version for much more advanced features and theme options.', 'wacko' ); ?>
					</p>
					<a target="_blank" target="_blank" href="<?php echo esc_url('https://www.lilyturfthemes.com/themes/wacko-plus/'); ?>" class="button button-primary"><?php esc_html_e( 'View Pro Version', 'wacko' ); ?></a>
				</div>

			</div>

		<?php elseif ( $active_tab == 'recommended_plugins' ) : ?>
			<div class="col-3-wrapper">

				<p><?php esc_html_e( 'Recommended Plugins are fully supported by Wacko theme, they are styled to fit the theme design and performing well. Not mandatory, but may be useful.', 'wacko' ); ?></p>

				<br>
				<?php
				// Contact Form 7

				wacko_recommended_plugin( 'contact-form-7', 'wp-contact-form-7', esc_html__( 'Contact Form 7', 'wacko' ), esc_html__( 'Contact Form 7 can manage multiple contact forms, plus you can customize the form and the mail contents flexibly with simple markup. ', 'wacko' ) );

				?>
			</div>

		<?php elseif ( $active_tab == 'support' ) : ?>
			<div class="col-3-wrapper">
				<div class="col-3">
					<h3>
						<span class="dashicons dashicons-sos"></span>
						<?php esc_html_e( 'Contact Support', 'wacko' ); ?>
					</h3>
					<p>

						<?php esc_html_e( 'If you have any problem, feel free to contact us through our online chat system or you can email us at any time.', 'wacko' ); ?>

						<hr>

						<a target="_blank" href="<?php echo esc_url('https://www.lilyturfthemes.com/contact-us/'); ?>" class="button button-primary"><?php esc_html_e( 'Contact Support', 'wacko' ); ?></a>
					</p>
				</div>

				<div class="col-3">
					<h3>
						<span class="dashicons dashicons-book"></span>
						<?php esc_html_e( 'Theme Documentation', 'wacko' ); ?>
					</h3>
					<p>
						<?php esc_html_e( 'Need more details ? Please check out our Wacko Theme Documentation for detailed information.', 'wacko' ); ?>

						<hr>

						<a target="_blank" href="<?php echo esc_url('https://www.lilyturfthemes.com/docs/wacko/'); ?>" class="button button-primary"><?php esc_html_e( 'View Documentation', 'wacko' ); ?></a>

					</p>
				</div>

				<div class="col-3">
					<h3>
						<span class="dashicons dashicons-star-filled"></span>
						<?php esc_html_e( 'Pro Version', 'wacko' ); ?>
					</h3>
					<p>
						<?php esc_html_e( 'Upgrade to pro version for much more advanced features and theme options.', 'wacko' ); ?>

						<hr>

						<a target="_blank" href="<?php echo esc_url('https://www.lilyturfthemes.com/themes/wacko-plus/'); ?>" class="button button-primary"><?php esc_html_e( 'View Pro Version', 'wacko' ); ?></a>

					</p>
				</div>
			</div>

		<?php elseif ( $active_tab == 'changelog' ) : ?>

		<div class="col-3-wrapper">
			<p> 
				<?php
					echo '<pre class="changelog">';

					echo esc_html( parse_changelog() );

					echo '</pre>';

				?> 
			</p>

		</div>
		<?php elseif ( $active_tab == 'free_vs_pro' ) : ?>
			<table class="free-vs-pro-table form-table">
				<thead>
					<tr>
						<th>

							<a href="<?php echo esc_url('https://www.lilyturfthemes.com/themes/wacko-plus/'); ?>" target="_blank" class="button button-primary button-hero">
								<?php esc_html_e( 'Get Wacko Plus', 'wacko' ); ?>
							</a>
						</th>

						<th><?php esc_html_e( 'Wacko', 'wacko' ); ?></th>

						<th><?php esc_html_e( 'Wacko Plus', 'wacko' ); ?></th>

					</tr>

				</thead>

				<tbody>
					<tr>
						<td>
							<h3><?php esc_html_e( '100% Responsive', 'wacko' ); ?></h3>

							<p><?php esc_html_e( 'Compatible with various desktop, tablet, and mobile devices.', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Translation Ready', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Each hard-coded string is ready for translation, means you can translate everything. Language wacko.pot file included.', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Top Header', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Option to enable/disable top header', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-no"></span></td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Custom Post Type', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Custom posts for slider, featured section, testimonials', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-no"></span></td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Font Options', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Google fonts options for changing the overall site fonts', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-no"></span></td>
						<td class="compare-icon">100+</td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Color Options', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Options to change primary color of the site', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-no"></span></td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Advanced Footer Options', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Option to Override existing Power By credit of footer', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-no"></span></td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
					</tr>

					<tr>
						<td>
							<h3><?php esc_html_e( 'Support Forum', 'wacko' ); ?></h3>
							<p><?php esc_html_e( 'Highly experienced and dedicated support team for your help plus online chat.', 'wacko' ); ?></p>
						</td>
						<td class="compare-icon"><span class="dashicons-before dashicons-yes"></span></td>
						<td class="compare-icon"> <?php esc_html_e('High Priority','wacko'); ?> </span></td>
					</tr>

					<tr>
						<td></td>
						<td colspan="2">
							<a href="<?php echo esc_url('https://www.lilyturfthemes.com/themes/wacko-plus/'); ?>" target="_blank" class="button button-primary button-hero">
								<?php esc_html_e( 'Get Wacko Plus', 'wacko' ); ?>
							</a>
						</td>
					</tr>
				</tbody>
			</table>

	    <?php endif; ?>

	</div><!-- /.wrap -->
<?php
} // end about_wacko_page
