<?php
/**
 * @package     CMGiftCard
 * @subpackage  com_cmgiftcard
 * @copyright   Copyright (C) 2016-2024 CMExension
 * @license     GNU General Public License version 2 or later
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;

HTMLHelper::_('behavior.formvalidator');

if (version_compare(JVERSION, '4.0.0-alpha1', '<'))
{
	HTMLHelper::_('formbehavior.chosen', 'select');
}

Factory::getDocument()->addScriptDeclaration('
	Joomla.submitbutton = function(task) {
		if (task == "order.cancel" || document.formvalidator.isValid(document.getElementById("order-form"))) {
			Joomla.submitform(task, document.getElementById("order-form"));
		}
	};
');

$fieldsets = $this->form->getFieldsets();
?>

<form action="<?php echo Route::_('index.php?option=com_cmgiftcard&layout=edit&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="order-form" class="form-validate form-horizontal">
	<?php echo HTMLHelper::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>

	<?php foreach ($fieldsets as $fieldset) : ?>
		<?php echo HTMLHelper::_('bootstrap.addTab', 'myTab', $fieldset->name, Text::_($fieldset->label, true)); ?>
		<?php foreach ($this->form->getFieldset($fieldset->name) as $field) : ?>
			<?php if ($field->type == 'CMMMItems') : ?>
				<?php echo $field->input; ?>
			<?php elseif ($field->type == 'Editor') : ?>
				<div style="display: none">
					<?php echo $field->input; ?>
				</div>
			<?php elseif ($field->hidden) : ?>
				<div class="control-group form-group">
					<div class="controls"><?php echo $field->input; ?></div>
				</div>
			<?php else: ?>
				<div class="control-group form-group">
					<div class="control-label"><?php echo $field->label; ?></div>
					<div class="controls"><?php echo $field->input; ?></div>
				</div>
			<?php endif; ?>
		<?php endforeach; ?>
		<?php echo HTMLHelper::_('bootstrap.endTab'); ?>
	<?php endforeach; ?>

	<?php echo HTMLHelper::_('bootstrap.endTabSet'); ?>

	<input type="hidden" name="task" value="" />
	<?php echo HTMLHelper::_('form.token'); ?>
</form>
