<?php
defined('_JEXEC') or die;

use Joomla\CMS\Router\Route;
use Joomla\CMS\HTML\HTMLHelper;

$wa = $this->document->getWebAssetManager();
$wa->useScript('keepalive');
$wa->useScript('form.validate');
$wa->useScript('core');

?>
<form action="<?php echo Route::_('index.php?option=com_grafik_keuangan&layout=edit&id=' . (int) $this->item->id); ?>"
	method="post" name="adminForm" id="adminForm" class="form-validate">

	<div class="row">
		<div class="col-md-9">
			<?php echo $this->form->renderFieldset('detail'); ?>
		</div>
	</div>

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

	<script>
		Joomla.submitbutton = function (task) {
			if (task) {
				const form = document.getElementById('adminForm');
				if (form) {
					// Validate if the task is a save task
					if (task !== 'item.cancel' && document.formvalidator && !document.formvalidator.isValid(form)) {
						return false;
					}

					// Find task input
					let taskInput = form.querySelector('input[name="task"]');
					if (!taskInput) {
						taskInput = document.createElement('input');
						taskInput.type = 'hidden';
						taskInput.name = 'task';
						form.appendChild(taskInput);
					}
					taskInput.value = task;
					form.submit();
				}
			}
		}
	</script>
</form>