<?php

namespace JetApplicationModule\Admin\Content\Images;

use Jet\MVC_Layout;
use Jet\UI;
use Jet\SysConf_URI;

use Jet\Form;
use Jet\MVC_View;
use JetApplication\Content_Gallery;


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

/**
 * @var MVC_View $this
 * @var Form $upload_form
 * @var Content_Gallery $gallery
 */
$upload_form = $this->getRaw( 'upload_form' );
$gallery = $this->getRaw( 'gallery' );

if( !$upload_form || $upload_form->getIsReadonly() ) {
	return;
}

$router = $this->getController()->getControllerRouter();

$upload_form->setAction( $router->action( 'image_upload' )->URI( $gallery->getId() ) );

$file_field = $upload_form->field( 'file' );

$file_field->input()
	->addJsAction( 'onchange', 'imageGallery.uploadImage(this.form.id)' )
	->addCustomCssStyle( ' position: absolute;top: 0;right: 0;margin: 0;padding: 0;font-size: 20px;cursor: pointer;opacity: 0;filter: alpha(opacity=0);' )
?>


<?= $upload_form->start() ?>

	<div class="btn btn-primary" style=" position: relative;overflow: hidden;margin: 0;">
		<?= UI::icon( 'upload' ) ?>&nbsp;<span><?= $file_field->getLabel() ?></span>
		<?= $file_field->input() ?>
	</div>

<?= $upload_form->end() ?>

<?= $upload_form->getCommonMessage(); ?>