<?php

namespace JetApplicationModule\Admin\Content\Images;

use Jet\Form_Field;
use Jet\MVC_View;
use Jet\UI;
use Jet\Tr;
use Jet\UI_button;
use JetApplication\Content_Gallery_Image;

/**
 * @var MVC_View $this
 * @var Form_Field $form_field
 */

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

$image_id = $form_field->getValue();

$image = null;
$image_thb_url = '';
if($image_id) {
	$image = Content_Gallery_Image::get( $image_id );
	
	if($image) {
		$image_thb_url = $image->getThumbnail(200, 200)->getURI();
	}
}
?>
<div class="select-image-widget"  id="select_image_<?=$form_field->getId()?>" style="<?php if($image_thb_url):?>background-image: url(<?=$image_thb_url?>);<?php endif; ?>">
	<div class="select-image-widget-input">
		<?=$form_field->input()?>
	</div>
	<div class="select-image-widget-no-image fa fa-image" id="select_image_no_image_<?=$form_field->getId()?>" style="display: <?=$image?'none':''?>">
	</div>

	<?=UI::button(Tr::_('Select image'))
		->setClass(UI_button::CLASS_SECONDARY)
		->addCustomCssClass('select-image-widget-button-select')
		->setOnClick("selectImage.select('{$form_field->getId()}');")?>
	<?=UI::button(' ')
		->setIcon('square-xmark')
		->setClass(UI_button::CLASS_INFO)
		->addCustomCssClass('select-image-widget-button-unselect')
		->setOnClick("selectImage.unselect('{$form_field->getId()}')")
		->setId('select_image_unselect_btn_'.$form_field->getId())
		->addCustomCssStyle('display:'.($image?'':'none'))?>

</div>


