<?php
namespace ONLINE_ADAv4;
use ONLINE_ADAv4\Helper;
if ( !isset($this_scan) ) exit;

global $post;
list( $step_key, $number_step, $number_total ) = get_step_details( $this_scan );

// Is this screen the current scan's edit screen?
$screen = get_current_screen();
$is_scan_screen = false;
if (isset($screen->id) && $screen->id == 'wcag_scan') {
	$is_scan_screen = true;
}

if (isset($_REQUEST['is_scan_screen'])) {
	if ($_REQUEST['is_scan_screen'] === 'wcag_scan') {
		$is_scan_screen = true;
	}
}


// Get the scan description and details
list( $task_description, $task_details ) = get_task_details( $step_key );

// The edit URL for the scan
$edit_link = get_edit_post_link($this_scan->ID);

// Classes used on the widget
$classes = array( 'wcag-scan-progress-indicator' );
$classes[] = 'wcag-scan-step-' . $step_key;

$classes[] = 'wcag-scan-step-progress-' . $number_step;

if ( !$is_scan_screen ) {
	$classes[] = 'wcag-scan-progress-with-controls';
}else{
	$classes[] = 'wcag-scan-progress-no-controls';
}

if ($step_key == 'scan_finished') {
	$classes[] = 'stop-ajax';
}


?>
<div class="<?php echo esc_attr(implode( ' ', $classes )); ?>">
	<div class="col col-overall">
		<div class="header">Overall Progress</div>
		<div class="content">
			<div class="progress-indicator">
				<?php
				for( $i = 0; $i < $number_total; $i++ ) {
					$classes = array( 'indicator' );
					$classes[] = 'indicator-' . $i;

					if ( $number_step > $i ) $classes[] = 'indicator-complete';
					if ( $number_step == $i ) $classes[] = 'indicator-current';
					if ( $number_step < $i ) $classes[] = 'indicator-waiting';
					?>
					<div class="<?php echo esc_attr(implode(' ', $classes)); ?>">
						<span class="indicator-index"><?php echo esc_attr($i+1); ?></span>
						<span class="indicator-circle"></span>
					</div>
					<?php
				}
				?>
			</div>
			<div class="progress-display">
				<div class="label">Step</div>
				<strong><?php echo wp_kses($number_step + 1,wp_kses_allowed_html()); ?> of <?php echo esc_html($number_total); ?></strong>
			</div>
		</div>
	</div>


	<div class="col col-description">
		<div class="header">Current Task</div>
		<div class="content">
			<div class="content-top">
				<strong><?php echo wp_kses($task_description,wp_kses_allowed_html()); ?></strong>
			</div>

			<div class="content-bottom">
				<?php if ( $is_scan_screen ): ?>
					<?php $sitemap = Helper::get_sitemap(); ?>
					<?php if( !empty($sitemap) ): ?>
					<?php $include_cbr = get_post_meta($this_scan->ID, "_oadaas_include_cbr", true); ?>
					<?php $time_to_complete = get_computed_time($sitemap, $include_cbr); ?>
					<p>Estimated audit completion: <?php echo esc_html($time_to_complete) ?></p>
					<?php endif; ?>
				<?php endif; ?>
			</div>
		</div>
	</div>

	<div class="col col-current">
			<div class="header">Step <?php echo esc_html($number_step + 1); ?> Details</div>
			<div class="content">

				<div>
					<?php
					echo wp_kses($task_details,wp_kses_allowed_html());

					if ( $is_scan_screen ) {
						//echo '<p><em>When you are done, click "Update" to continue.</em></p>';
					}else{
						//echo '<hr>';
						//echo '<p><em><a href="'. esc_attr($edit_link) .'">Go to the scan</a> to follow these instructions.</em></p>';
					}
					?>
				</div>

			</div>
	</div>


	<?php
	// Only show buttons when not looking at the scan
	if ( !$is_scan_screen ) { ?>
		<div class="col col-buttons">
			<div class="header">Controls</div>
			<div class="content">
				<div class="button-row button-row-goto">
					<a href="<?php echo esc_attr($edit_link); ?>"><span class="icon dashicons dashicons-controls-play"></span> <span class="button-text">Go to audit</span></a>
				</div>

				<div class="button-row button-row-dismiss">
					<a href="#" class="dismiss-message"><span class="icon dashicons dashicons-no-alt"></span> <span class="button-text">Dismiss Message</span></a>
				</div>
			</div>
		</div>
	<?php } ?>
</div>
<div class="scan-note">
	<strong>Note:</strong>
	<p class="description">You may leave this page and return later. The audit will continue to run in the background so long as you're logged into WordPress and have the website open in a browser tab. Auditing halts when you log out or close your browser.</p>
	<p>An email will be sent to <?php echo wp_kses(get_option("admin_email"),wp_kses_allowed_html()); ?> when the audit is complete</p>
</div>
