<?php

use Jet\Form;
use Jet\SysConf_URI;
use Jet\Tr;
use Jet\MVC_View;
use Jet\MVC_Layout;

/**
 * @var MVC_View $this
 * @var Form[] $forms
 */

$forms = $this->getRaw( 'forms' );

MVC_Layout::getCurrentLayout()->requireJavascriptFile( SysConf_URI::getJs() . 'JetAjaxForm.js?v=1' );

?>
<script type="text/javascript">
	const testSendForm = {
		submit: function (id) {
			JetAjaxForm.submit(id, {
				showProgressIndicator: function (form) {
					$('#__progress__').show();
					$('#__progress_prc__').html('');
				},

				hideProgressIndicator: function (form) {
					$('#__progress__').hide();
				},

				onProgress: function (form, percent) {
					$('#__progress_prc__').html(percent + '%');
				},

				onSuccess: function (form, response_data) {
				},

				onFormError: function (form, response_data) {
				},

				onAccessDenied: function (form) {
					alert('Access denied!');
				},

				onError: function (form) {
					alert('Unknown error ...');
				}
			});
		}
	};

</script>

<style>
    #__progress__ {
        z-index: 9999999999;
        position: fixed;
        display: none;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: #000000;
        opacity: 0.5
    }

    #__progress__ .loading {
        margin-top: 20%;
        margin-left: 40%;
        width: 20%;
        opacity: 1;
        background-color: #ffffff;
        padding: 20px;
        border-radius: 10px;
        color: #000000;
        font-size: 18px;
    }
</style>

<h2><?= Tr::_( 'Form test' ) ?></h2>

<?php foreach($forms as $form_name => $d):
	/**
	 * @var Form $form
	 */
	$form = $d['form'];
	//$form->setIsReadonly();
	$this->setVar( 'form', $form );
	?>
	<fieldset style="margin-bottom: 40px">
		<legend><?= $d['title'] ?></legend>

		<div id="form_message_area_<?= $form->getId() ?>">
			<?= $this->render( 'test-forms/message' ); ?>
		</div>

		<div id="form_area_<?= $form->getId() ?>">
			<?= $this->render( 'test-forms/form' ); ?>
		</div>

		<div id="form_sent_area_<?= $form->getId() ?>">
			<?= $this->render( 'test-forms/sent' ); ?>
		</div>

	</fieldset>
<?php endforeach; ?>



<div id="__progress__">

	<div class="loading text-center">
		<div id="__progress_prc__"></div>
		<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i>
		<span class="sr-only"><?= Tr::_( 'Loading ...' ); ?></span>
	</div>
</div>
