<?php
  /**
   * @version     1.0.0
   * @package     Joomla 4
   * @subpackage  Formea
   * @author      Feseur Sdn Bhd
   * @copyright   Copyright (C) 2010 - 2020 Feseur Sdn Bhd
   * @license     GNU/GPL, see LICENSE.php
   */
  defined('_JEXEC') or die;

  use Joomla\CMS\HTML\HTMLHelper;
  use Joomla\CMS\Language\Text;
  use Joomla\CMS\Uri\Uri;
  use Joomla\Component\Formea\Site\Helper\FormeaGeneralHelper;
  use Joomla\Component\Formea\Site\View\Formea\HtmlView;
  use Joomla\Registry\Registry;

  /** @var HtmlView $this */

  $totalPages        = count($this->item->elementLayouts);
  $uniqueString      = $this->form->getUniqueString();
  $renderer_style_id = $this->item->params->get('renderer_style_id', 0);
  $rendererParams    = new Registry($this->renderexExtension->params);
  if ($renderer_style_id > 0)
  {
    $styleObject = FormeaGeneralHelper::getExtensionStyle($renderer_style_id);
    if (!empty($styleObject))
    {
      $rendererParams = new Registry($styleObject->params);
    }
  }
  $stepperHeaderClass = [];
  if ((int) $rendererParams->get('enable_steps', 1) != 1)
  {
    $stepperHeaderClass[] = 'd-none';
  }
  $app         = \Joomla\CMS\Factory::getApplication();
  $langTag     = $app->getLanguage()->getTag();
  $formeaToken = base64_encode($uniqueString);

?>
<?php if ((int) $this->item->allow_submission > 0){ ?>
<form action="<?php echo Uri::current() ?>" enctype="multipart/form-data"
      class="formea-form <?php echo $this->item->params->get('form_class', null); ?>"
      id="formea_form_<?php echo $uniqueString; ?>"
  <?php echo $this->item->params->get('form_attributes', null); ?> method="post">
  <?php }else{ ?>
  <div class="formea-form <?php echo $this->item->params->get('form_class', null); ?>"
       id="formea_form_<?php echo $uniqueString; ?>"
    <?php echo $this->item->params->get('form_attributes', null); ?>>
    <?php } ?>


    <?php if (!empty($this->item->details->get('form_heading'))): ?>
      <h5><?php echo $this->item->details->get('form_heading'); ?></h5>
    <?php endif; ?>
    <div class="bs-stepper bs-stepper-<?php echo $uniqueString; ?>">
      <div class="bs-stepper-header <?php echo implode(' ', $stepperHeaderClass); ?>" role="tablist">
        <?php for ($i = 0; $i < $totalPages; $i++) { ?>
          <div class="step" data-target=".multipage_<?php echo $uniqueString; ?>_<?php echo $i; ?>">
            <button type="button" class="step-trigger" role="tab"
                    aria-controls="multipage_<?php echo $uniqueString; ?>_<?php echo $i; ?>"
                    id="fm_pg_<?php echo $uniqueString; ?>_<?php echo $i; ?>_trigger">
              <?php if ((int) $rendererParams->get('enable_icon', 1) > 0):
                $number = $i + 1;
                if (!empty($this->item->elementLayouts[$i]->icon))
                {
                  $number = $this->item->elementLayouts[$i]->icon;
                }
                ?>
                <span class="bs-stepper-circle"><?php echo $number; ?></span>
              <?php endif; ?>
              <span class="bs-stepper-label"><?php echo $this->item->elementLayouts[$i]->title; ?></span>
            </button>
          </div>
          <?php if ($i !== ($totalPages - 1)): ?>
            <div class="line"></div>
          <?php endif; ?>
        <?php } ?>
      </div>
      <div class="bs-stepper-content">
        <?php echo $this->form->renderForm($this->item->elementLayouts, $this->item); ?>
      </div>
    </div>
    <?php if ((int) $rendererParams->get('nav_auto', 1) == 1) { ?>
      <div
        class="d-flex gap-2 pb-3 <?php echo $rendererParams->get('button_positioning', 'justify-content-between') ?>">
        <div>
          <button id="mp_prev_<?php echo $uniqueString ?>"
                  class="<?php echo $rendererParams->get('prev_btn_class', 'btn btn-secondary'); ?>" type="button"
                  data-formea-btn-prev>
            <?php echo Text::_($rendererParams->get('button_texts.' . $langTag . '.prev', 'JPREVIOUS')); ?>
          </button>
        </div>
        <div>
          <button class="<?php echo $rendererParams->get('submit_btn_class', 'btn btn-success'); ?>"
                  style="display:none"
                  type="submit" data-formea-btn-submit>
            <?php echo Text::_($rendererParams->get('button_texts.' . $langTag . '.submit', 'JSUBMIT')); ?>
          </button>
          <button class="<?php echo $rendererParams->get('next_btn_class', 'btn btn-primary'); ?>" type="button"
                  data-formea-btn-next>
            <?php echo Text::_($rendererParams->get('button_texts.' . $langTag . '.next', 'JNEXT')); ?>
          </button>
        </div>
      </div>

    <?php } ?>
    <?php echo $this->item->honeypot; ?>
   <input type="hidden" name="fom" value="<?php echo $this->item->id; ?>">

    <?php if ((int) $this->item->allow_submission > 0) { ?>
    <input type="hidden" name="return_url" value="<?php echo base64_encode(Uri::current()); ?>">

    <input type="hidden" name="fomToken" value="<?php echo $formeaToken; ?>">
    <input type="hidden" name="option" value="com_formea">
    <input type="hidden" name="task" value="formea.submit">
    <?php echo HTMLHelper::_('form.token'); ?>
</form>
    <?php } else { ?>
    </div>
    <?php } ?>



