<?php
/**
 * FW Food menu 5.1.1
 * @copyright C 2019 Fastw3b
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @link http://www.fastw3b.net/ Official website
 **/

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.html.html');
jimport('joomla.form.formfield');

class JFormFieldFwFmPromo extends JFormField {
	var	$type = 'fwfmpromo';

	function getInput() {
		if (!defined('FWFM_COMPONENT_SITE')) {
			define('FWFM_COMPONENT_SITE', JPATH_SITE.'/components/com_fwfoodmenu');
		}
		require_once(FWFM_COMPONENT_SITE.'/helpers/helper.php');

		fwFoodMenuHelper::loadAdminStyles();

		$options = array();
		JFactory::getApplication()->triggerEvent('onGetFoodMenuPromoOptions', array('com_fwfoodmenu', &$options));

		ob_start();
		if ($options) {
//			$name = str_replace(array('[', ']'), array('_', ''), $this->name);
			echo JHTML::_('select.genericlist', $options, $this->name, 'class="uk-select"', 'id', 'name', $this->value);
		} else {
?>
<div id="fwfmpromo"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
	(function($) {
	$('#fwfmpromo').closest('.control-group').hide();
	})(jQuery);
});
</script>
<?php
		}
		return ob_get_clean();
	}
}
