<?php
/**
 * Add admin notice
 */


add_action( 'admin_notices', 'wpazure_admin_notice'  );
add_action( 'wp_ajax_dismiss_admin_notice', 'wpazure_dismiss_admin_notice' );
add_action( 'admin_enqueue_scripts', 'wpazure_welcome_static'  );

if ( ! function_exists( 'wpazure_get_theme_name' ) ) :

	/**
	 * Get theme name.
	 *
	 * @return string Theme Name.
	 */
	function wpazure_get_theme_name() {

		$theme_name = __( 'Wpazure', 'wpazure' );

		return apply_filters( 'wpazure_theme_name', $theme_name );
	}

endif;
 

 
function wpazure_admin_notice() {
	if ( is_admin() && ! get_user_meta( get_current_user_id(), 'welcome_box' ) ) {
		?>
		<div class="wpazure-admin-notice wpazure-options-notice notice is-dismissible" data-notice="welcome_box">
			<div class="wpazure-notice-content">
				<div class="wpazure-notice-img">
					<img src="<?php echo esc_url( WPAZURE_THEME_URI . 'images/azure-logo.png' ); ?>" alt="<?php esc_attr_e( 'logo', 'wpazure' ); ?>">
				</div>
				<div class="wpazure-notice-text">
					<div class="wpazure-notice-heading"><?php 
					printf( esc_html__('Thanks for installing  %s', 'wpazure' ), wpazure_get_theme_name() );
					
					?></div>
					<p>
						<?php
						printf( // WPCS: XSS OK.
							/* translators: Theme options */
							__( 'To fully take advantage of the best our theme can offer please make sure you visit our <a href="%1$s">Welcome page</a>.', 'wpazure' ),
							esc_url( admin_url( 'admin.php?page=wpazure-welcome' ) )
						);
						?>
					</p>
				</div>
			</div>
		</div>
		<?php
	}
}


/**
 * Dismiss admin notice
 */
function wpazure_dismiss_admin_notice() {

	// Nonce check.
	check_ajax_referer( 'wpazure_dismiss_admin_notice', 'nonce' );

	// Bail if user can't edit theme options.
	if ( ! current_user_can( 'edit_theme_options' ) ) {
		wp_send_json_error();
	}

	$notice = isset( $_POST['notice'] ) ? sanitize_text_field( wp_unslash( $_POST['notice'] ) ) : '';

	if ( $notice ) {
		update_user_meta( get_current_user_id(), $notice, true );
		wp_send_json_success();
	}

	wp_send_json_error();
}

/**
 * Load welcome screen script and css
 */
function wpazure_welcome_static() {
	// Dismiss admin notice.
	wp_enqueue_script(
		'wpazure-dismiss-admin-notice',
		get_template_directory_uri() . '/inc/admin/js/dismiss-admin-notice.js',
		[],
		'1.0',
		true
	);

	wp_localize_script(
		'wpazure-dismiss-admin-notice',
		'wpazure_dismiss_admin_notice',
		[
			'nonce' => wp_create_nonce( 'wpazure_dismiss_admin_notice' ),
		]
	);

	// Welcome screen style.
	wp_enqueue_style('wpazure-admin-styles', get_template_directory_uri().'/inc/admin/css/wpazure-welcome.css');

}



add_action('admin_menu', 'wpazure_welcome_page');


// Wpazure welcome page register
function wpazure_welcome_page() {
	$wpazure_page_title =  apply_filters( 'wpazure_menu_page_title', __( 'Wpazure Options', 'wpazure' ) );
    add_theme_page('Wpazure Theme Options', $wpazure_page_title, 'manage_options', 'wpazure-welcome', 'wpazure_settings_page');
}

function wpazure_settings_page(){
	global $wpazure_active_tab;
	$wpazure_active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'welcome'; ?>
  <div class="wpazure-admin wrap">
    <h1>
    <?php
    $wpazure_theme = wp_get_theme();
	$wpazure_theme_name = wpazure_get_theme_name();
    echo $wpazure_theme_name . "  v." . $wpazure_theme->get( 'Version' );
    ?>
    </h1>
  	<h2 class="nav-tab-wrapper">
      <a class="nav-tab <?php echo $wpazure_active_tab == 'welcome' || '' ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( admin_url( 'themes.php?page=wpazure-welcome&tab=welcome' ) ); ?>"><?php esc_html_e( 'Welcome', 'wpazure' ); ?></a>
	 
	  <?php	do_action( 'wpazure_settings_headding' ); ?>
	  
	   <a class="nav-tab <?php echo $wpazure_active_tab == 'support' || '' ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( admin_url( 'themes.php?page=wpazure-welcome&tab=support' ) ); ?>"><?php esc_html_e( 'Support', 'wpazure' ); ?></a>
	  
	   <a class="nav-tab <?php echo $wpazure_active_tab == 'freevspro' || '' ? 'nav-tab-active' : ''; ?>" href="<?php echo esc_url( admin_url( 'themes.php?page=wpazure-welcome&tab=freevspro' ) ); ?>"><?php esc_html_e( 'Free VS Pro', 'wpazure' ); ?></a>
  	</h2>
  	<?php	do_action( 'wpazure_settings_content' ); ?>
  </div><!-- /.wrap -->
  <?php
}


add_action( 'wpazure_settings_content', 'wpazure_welcome_render_options_page' );

function wpazure_welcome_render_options_page() {
	global $wpazure_active_tab;
	if ('welcome' == $wpazure_active_tab ){
	?>
  <div class="wp-pointer-content">
	<h2 class="wpazure-admin-h2" style="margin-left: 20px;">
	<?php //esc_html_e( 'Thank You for installing '.wpazure_get_theme_name().' Theme!', 'wpazure' );
	
	printf( esc_html__('Thank You for installing %s Theme!', 'wpazure' ), wpazure_get_theme_name() ); ?>
	
	
	</h2>
  <h3><?php printf( esc_html__('With the few clickes to unlock full potential of %s', 'wpazure' ), wpazure_get_theme_name() );  ?></h3>

    <p><?php printf(esc_html__( 'Simply complete the steps listed below it only takes a minute  and you will be able to enjoy all functionalities of %s Theme.', 'wpazure'), wpazure_get_theme_name() ); ?></p>
    <p><?php esc_html_e( 'So without a further ado let\'s begin!', 'wpazure' ); ?></p>

    <h4><?php printf( esc_html__( 'Install and Activate all recommended plugins to unlock %s custom features', 'wpazure'),wpazure_get_theme_name() ); ?></h4>
    <?php
    $wpazure_installer = TGM_Plugin_Activation::get_instance();
    if ( ! $wpazure_installer->is_tgmpa_complete() ) {
    ?>
    <p><a href="<?php echo esc_url( admin_url( 'themes.php?page=tgmpa-install-plugins' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Install and Activate Plugins Now', 'wpazure' ); ?></a><p>
    <?php
    } else {
      ?>
      <p><span class="dashicons dashicons-yes"></span><?php esc_html_e( 'Success: All plugins are installed and activated', 'wpazure' ); ?></a><p>
      <?php
    }
    ?>

    <p><?php printf(wp_kses_post( '<strong>IMPORTANT:</strong> you need to install all recommended plugins to be able to use all %s theme custom features.', 'wpazure'),wpazure_get_theme_name()); ?></p>
    <p><?php printf(wp_kses_post( '<strong>Need help?</strong> Here you can check how to install and import demo in %s theme <a href="' . esc_url( 'https://www.wpazure.com/how-to-import-premade-templates-of-wpazure/' ) . '" target="_blank" style="background: #0085ba;border-color: #0073aa #006799 #006799;box-shadow: 0 1px 0 #006799;color: #fff;text-decoration: none;text-shadow: 0 -1px 1px #006799, 1px 0 1px #006799, 0 1px 1px #006799, -1px 0 1px #006799;padding: 5px 8px;border-radius: 4px;">click here.</a>', 'wpazure'),wpazure_get_theme_name() ); ?></p>

   
    <h4><?php esc_html_e( 'Import one of the already created Demo sites', 'wpazure' ); ?></h4>
    <?php
    if ( ! $wpazure_installer->is_tgmpa_complete() ) {
    ?>
    <p><a href="#" class="button"><?php printf(esc_html__( 'Go to %s Demo Importer', 'wpazure'),wpazure_get_theme_name() ); ?></a><p>
    <?php
    } else {
    ?>
    <p><a href="<?php echo esc_url( admin_url( 'themes.php?page=wpazure-demo-import' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Go to Wpazure Site Library', 'wpazure' ); ?></a><p>
    <?php
    }
    ?>
	
	<h4><?php printf(esc_html__( 'Go to Wordpress Customizer to tweak many %s theme options and customize it just how you like!', 'wpazure'),wpazure_get_theme_name() ); ?></h4>
    <p><a href="<?php echo esc_url( admin_url( 'customize.php' ) ); ?>" class="button button-primary"><?php esc_html_e( 'Go To Customizer' , 'wpazure' ); ?></a><p>

    <h4><?php printf(esc_html__( 'Need help with %s Theme?', 'wpazure'),wpazure_get_theme_name() ); ?></h4>
    <p><a href="<?php echo esc_url( 'https://wordpress.org/support/theme/wpazure/' ); ?>" target="_blank" class="button button-primary"><?php esc_html_e( 'Post your query' , 'wpazure' ); ?></a><p>

</div>

	<?php
	}
	
	if('support' == $wpazure_active_tab){ ?>
	<div class="wpazure-support">
		<div class="column-wrapper">
			<div class="tab-column">
							<span class="dashicons dashicons-sos"></span>
							<h3><?php esc_html_e('Visit our forums','wpazure');?></h3>
							<p><?php esc_html_e("Need help? Go ahead and visit our support forums and we'll be happy to assist you with any theme related questions","wpazure");?></p>
							
							<?php if ( !is_plugin_active( 'wpazure-pro/wpazure-pro.php' ) ) {?>
							
							<a href="https://wordpress.org/support/theme/wpazure/" target="_blank"><?php esc_html_e('Visit the forums','wpazure');?>
								</a>	
							<?php } else {?>
								<a href="https://www.wpazure.com/forums/forum/wpazure-pro/" target="_blank"><?php esc_html_e('Visit the forums','wpazure');
							}?>
														
			</div>
			<div class="tab-column">
				<span class="dashicons dashicons-book-alt"></span>
				<h3><?php esc_html_e('Documentation','wpazure');?></h3>
					<p><?php esc_html_e('Our documentation can help you learn how to use the theme','wpazure');?></p>
					<a href="https://www.wpazure.com/docs/" target="_blank"><?php esc_html_e('See the Documentation','wpazure');?></a>
			</div>
		</div>
	</div><?php
	}
	
	
	
	/* Wpazure pro feaures section table*/
	 if ('freevspro' == $wpazure_active_tab ){ ?>
		<div id="table" class="wpazure-tab table">
				<table class="widefat fixed featuresList"> 
				   <thead> 
					<tr> 
					 <td><strong><h3><?php esc_html_e( 'Feature', 'wpazure' ); ?></h3></strong></td>
					 <td style="width:20%;"><strong><h3><?php esc_html_e( 'Wpazure', 'wpazure' ); ?></h3></strong></td>
					 <td style="width:20%;"><strong><h3><?php esc_html_e( 'Wpazure Pro', 'wpazure' ); ?></h3></strong></td>
					</tr> 
				   </thead> 
				   <tbody> 
				   <tr> 
					 <td><?php esc_html_e( 'Elementor support', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Access to all Google Fonts', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Responsive', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>  
					<tr> 
					 <td><?php esc_html_e( 'Translation ready', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Color options', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Blog options', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Widgetized footer', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 	
					<td><?php esc_html_e( 'WooCommerce compatible', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Footer Credits option', 'wpazure' ); ?></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Growing collection of premium demos', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Scroll to top', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Infinite scroll & ajax posts loading', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Header top section', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Theme layout', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Extended Typography', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Footer background image', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'More header layout ', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Extra blog layouts (list, masonry,left sidebar,blog column layout)', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Extended WooCommerce options', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( '9 More footer layouts', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'More color options(header, blog, footer)', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
					<tr> 
					 <td><?php esc_html_e( 'Extended footer bar', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'White list', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr>
					<tr> 
					 <td><?php esc_html_e( 'Priority support', 'wpazure' ); ?></td>
					 <td class="redFeature"><span class="dashicons dashicons-no-alt dash-red"></span></td>
					 <td class="greenFeature"><span class="dashicons dashicons-yes dash-green"></span></td>
					</tr> 
				   </tbody> 
				  </table>
				  <p style="text-align: right;"><a class="button button-primary button-large" href="https://www.wpazure.com/pricing/"><?php esc_html_e('Buy Wpazure Pro ', 'wpazure'); ?></a></p>
				</div>
	 <?php }
}
