<?php

  /**
   * @package     Joomla.Administrator
   * @subpackage  com_formea
   *
   * @copyright   Copyright (C) 2010-2024 Feseur Sdn Bhd. All rights reserved.
   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   * @version     1.1.8
   */

  defined('_JEXEC') or die;

  use Joomla\CMS\HTML\HTMLHelper;
  use Joomla\CMS\Language\Text;
  use Joomla\CMS\Form\Form;
  use Joomla\Component\Formea\Site\Libraries\FormeaCore;

  /** @var FormeaCore $coreExtension */
  /** @var Form $htmlForm */

  Text::script('FORMEA_PDF_PAGE');

  if (!isset($htmlForm))
  {
    $htmlForm = null;
  }
  if (!empty($htmlForm))
  {
    ?>
    <div class="d-block ps-3">
      <?php echo $htmlForm->renderField('enabled', 'cores.'.$coreExtension->name); ?>
      <hr>

      <div class="d-block mb-2">
        <div class="row">
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('doc_author','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('doc_author','cores.'.$coreExtension->name); ?>
          </div>
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('doc_title','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('doc_title','cores.'.$coreExtension->name); ?>
          </div>
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('doc_subject','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('doc_subject','cores.'.$coreExtension->name); ?>
          </div>
        </div>
      </div>
      <div class="d-block mb-2">
        <div class="row">
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('doc_keywords','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('doc_keywords','cores.'.$coreExtension->name); ?>
          </div>
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('doc_font','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('doc_font','cores.'.$coreExtension->name); ?>
          </div>
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('doc_font_size','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('doc_font_size','cores.'.$coreExtension->name); ?>
          </div>

        </div>
      </div>
      <div class="d-block mb-2">
        <div class="row">
          <div class="col-md-4">
            <?php echo $htmlForm->getLabel('file_name','cores.'.$coreExtension->name); ?>
            <?php echo $htmlForm->getInput('file_name','cores.'.$coreExtension->name); ?>
          </div>
          <div class="col-md-4">
            <?php echo $htmlForm->renderField('upload_path','cores.'.$coreExtension->name); ?>
          </div>
          <div class="col-md-4">

          </div>

        </div>
      </div>
      <div class="d-block position-relative">
        <?php echo $htmlForm->getInput('pdf_pages', 'cores.'.$coreExtension->name);; ?>
      </div>
      <div class="d-block">
        <?php echo $htmlForm->getInput('pdf_preview','cores.'.$coreExtension->name); ?>
      </div>
    </div>
  <?php }
?>

<script>
  const pdfSubForm = document.querySelector('joomla-field-subform[name="jform[cores][Pdf][pdf_pages]"]');
  if(pdfSubForm !== undefined && pdfSubForm !== null){
    const btnGroups = pdfSubForm.querySelectorAll('.btn-group');
    if(btnGroups.length > 0){
      const addPageSpan = document.createElement('span');
      addPageSpan.style.marginTop = "5px";
      addPageSpan.style.marginRight = "5px";
      addPageSpan.style.fontWeight = "Bold";
      addPageSpan.textContent= Joomla.Text._('FORMEA_PDF_PAGE');
      btnGroups[0].before(addPageSpan);
    }
   // console.log('btnGroups',btnGroups);
  }
 // console.log('pdfSubForm',pdfSubForm);
</script>
