<?php
use Easymailing\App\Core\Provider\Woocommerce\Model\BatchSynchronizationStatus;
use Easymailing\App\Core\Provider\Woocommerce\Service\MetadataHelper;

$current_page_index = $current_page;

$no_active_class = "em-menuitem";
$active_class = "em-selected-menuitem";

$selected_link0 = ($current_page_index == 0) ? $active_class : $no_active_class;
$selected_link1 = ($current_page_index == 1) ? $active_class : $no_active_class;
$selected_link2 = ($current_page_index == 2) ? $active_class : $no_active_class;
$selected_link3 = ($current_page_index == 3) ? $active_class : $no_active_class;
$selected_link4 = ($current_page_index == 4) ? $active_class : $no_active_class;

$batchSynchronizationStatus = get_option(MetadataHelper::getBatchSynchronizationStatus());

?>

<div class="em-synchronization-header">
  <div class="em-py-3 em-d-flex em-align-items-center em-justify-content-between em-mb-4">
      <div class="em-d-flex em-d-flex em-align-items-center">
          <img alt="Logo" src="<?php $this->asset('plugin/img/logo.svg') ?>" class="em-mr-3" />
            <span class="em-fs-4 em-fw-bold"><?php echo __('Sincronización', 'easymailing') ?></span>
      </div>
	  <?php if (!is_null($synchronizationConfig) && $synchronizationConfig->getShopId() && $synchronizationConfig->getAudience()) { ?>
        <?php if (in_array($batchSynchronizationStatus, [BatchSynchronizationStatus::ERROR, BatchSynchronizationStatus::SUCCESS, BatchSynchronizationStatus::CANCELED])) { ?>
            <button id="em-start-sync-button" class="em-submit-button ms-auto"><?php echo __('Sincronizar', 'easymailing') ?></button>
        <?php }else{ ?>
			  <?php if (in_array($batchSynchronizationStatus, [BatchSynchronizationStatus::SCHEDULED, BatchSynchronizationStatus::IN_PROGRESS])) { ?>
                <button id="em-cancel-sync-button" class="em-btn em-btn-danger ms-auto"><?php echo __('Cancelar sincronización', 'easymailing') ?></button>
            <?php } ?>
        <?php } ?>
	  <?php } ?>
  </div>


<?php if (!is_null($synchronizationConfig) && $synchronizationConfig->getShopId()){   ?>
  <div class="em-d-flex w-100 em-synchronization-nav">
    <div class="em-py-2 em-px-4 em-fs-6 <?php echo $selected_link0; ?>">
      <a href="<?php $this->adminUrl('easymailing_synchronization') ?>"><?php echo __('Resumen', 'easymailing') ?></a>
    </div>
    <div class="em-py-2 em-px-4 em-fs-6 <?php echo $selected_link1; ?>">
      <a href="<?php $this->adminUrl('easymailing_synchronization_configuration') ?>"><?php echo __('Configuración', 'easymailing') ?></a>
    </div>
    <div class="em-py-2 em-px-4 em-fs-6 <?php echo $selected_link2; ?>">
      <a href="<?php $this->adminUrl('easymailing_synchronization_settings') ?>"><?php echo __('Ajustes formularios', 'easymailing') ?></a>
    </div>
      <div class="em-py-2 em-px-4 em-fs-6 <?php echo $selected_link4; ?>">
          <a href="<?php $this->adminUrl('easymailing_synchronization_logs') ?>"><?php echo __('Logs', 'easymailing') ?></a>
      </div>
    <div class="em-py-2 em-px-4 em-fs-6 <?php echo $selected_link3; ?>">
      <a href="<?php $this->adminUrl('easymailing_synchronization_reset') ?>"><?php echo __('Restablecer integración', 'easymailing') ?></a>
    </div>

    <div class="em-menuitem em-menuitem-no-hover em-flex-grow-1"></div>
  </div>
<?php } ?>
</div>
