<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template files receive local context variables from their controller.
namespace SPAATG;

use SPAATG\Helper\UiHelper as UiHelper;

if ( ! defined( 'ABSPATH' ) ) {
 exit; // Exit if accessed directly.
}



?>

<section class='dashboard panel active' data-panel="dashboard" style='display: block'  >
  <div class="panel-container">

    <div class='bulk-wrapper'>

      <?php 
	      $link = (false !== $view->dashboard_link) ? sprintf('title="%s" href="%s" target="_blank" rel="noopener noreferrer"', esc_attr($view->dashboard_message), esc_url($view->dashboard_link)) : '';
	      ?>
	      <a class='top-circle' <?php echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Built above from escaped attributes. ?>>
	          <div class='the-circle' style='background-image: url("<?php echo esc_url($view->dashboard_icon); ?>");'>&nbsp;</div>
	      </a>
	      <?php //if (false !== $view->dashboard_title): ?>
	       <h3 class='title-offer'><?php echo esc_html((false !== $view->dashboard_title) ? $view->dashboard_title : __('Ready to start generating AI SEO data?', 'shortpixel-ai-alt-text-generator')); ?></h3>
      <?php //endif; ?>



	        <button type="button" class="button-primary button start" id="start-optimize" data-action="open-panel" data-panel="selection" <?php disabled((bool) $this->view->error); ?>  >
            <?php esc_html_e('Start AI SEO Generation','shortpixel-ai-alt-text-generator'); ?>
        </button>

			<div class='dashboard-text'>
	         <a class='button button-primary' type="button" href="<?php echo esc_url(admin_url('options-general.php?page=spaatg-settings&part=help')); ?>" target="_blank" rel="noopener noreferrer">
	         <span class='icon white'><?php echo wp_kses(UIHelper::getIcon('res/images/icon/help-circle.svg', ['width' => '16']), array('img' => array('src' => array(), 'class' => array(), 'width' => array(), 'height' => array(), 'alt' => array()))); ?></span>
	         <span><?php esc_html_e('Help','shortpixel-ai-alt-text-generator'); ?></span>
	         </a>
      </div>


   <?php if ($this->view->error): ?>
     <div class='bulk error'>
        <h3><?php echo esc_html($this->view->errorTitle); ?></h3>
	        <p><?php echo wp_kses_post($this->view->errorContent); ?></p>
        <?php if (property_exists($this->view, 'errorText')): ?>
            <p class='text'><?php echo esc_html($this->view->errorText) ?></p>
        <?php endif; ?>
     </div>
   <?php endif; ?>

   </div> <!-- bulk-wrappeur -->


   <?php if (count($this->view->logs) > 0): ?>

	 <div id="LogModal" class="shortpixel-modal shortpixel-hide dashboard-modal">
		 <span class="close" data-action="CloseModal" data-id="LogModal">x</span>
	 	  <div class='title'></div>
			<div class="content sptw-modal-spinner"><div class='table-wrapper'></div></div>
	 </div>
	 <div id="LogModal-Shade" class='sp-modal-shade'></div>
   
    <div class='wrap-collap log-wrapper'> 

    <input type="checkbox" id="bulk-history" class='collap-checkbox'>       

    <label for="bulk-history">     
        <h3>
	        <span class='icon white'><?php echo wp_kses(UIHelper::getIcon('res/images/icon/history.svg'), array('img' => array('src' => array(), 'class' => array(), 'width' => array(), 'height' => array(), 'alt' => array()))); ?></span>
	          <?php esc_html_e('Bulk History', 'shortpixel-ai-alt-text-generator'); ?>
	          <span class='collap-arrow'><?php echo wp_kses(UIHelper::getIcon('res/images/icon/chevron.svg'), array('img' => array('src' => array(), 'class' => array(), 'width' => array(), 'height' => array(), 'alt' => array()))); ?></span>
        </h3>
    </label>

   <div class='collap-content'>
    <div class='dashboard-log'>
        <?php
          echo "<div class='head'>";
          foreach($this->view->logHeaders as $header)
          {
            echo "<span>" . esc_attr($header) . "</span>";
          }
          echo "</div>";
          foreach ($this->view->logs as $logItem):
          {
              echo "<div class='data " . esc_attr($logItem['type']) . "'>";

              echo "<span>" . esc_html($logItem['images'])  . '</span>';
	              echo "<span>" . esc_html($logItem['errors']) . '</span>';

                /* translators: 1: opening status markup, 2: closing status markup, 3: completion date. */
                echo '<span class="checkmark_green date">' . sprintf(esc_html__('%1$sCompleted%2$s on %3$s','shortpixel-ai-alt-text-generator'), '','', esc_html($logItem['date'])) . '</span>';

              echo "<span>" . esc_html($logItem['bulkName']) . '</span>';

            echo "</div>";
          }
          ?>


        <?php endforeach; ?>

    </div> <!-- dashboardlog table --> 
    </div> <!-- content -->
        </div> <!-- wrap-collap -->
  <?php endif; ?>


  <?php if (! $this->view->error): ?>
     <div class='spaatg-bulk-loader' id="bulk-loading" data-status='loading'>
       <div class='loader'>
				 	 <span class="svg-spinner"><?php $this->loadView('snippets/part-svgloader', false); ?></span>

           <span>
           <h2><?php esc_html_e('Please wait, ShortPixel is loading', 'shortpixel-ai-alt-text-generator'); ?></h2>

         </span>

       </div>
     </div>
  <?php endif; ?>
 </div> <!-- panel-container -->
</section> <!-- section -->
