<?php
/**
 * @package    VP Advanced User
 * @author     Abhishek Das <info@virtueplanet.com>
 * @copyright  Copyright (C) 2012-2019 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @link       https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

JFormHelper::loadFieldClass('text');

class JFormFieldTexttotag extends JFormFieldText
{
	protected $type = 'Texttotag';

	function getInput()
	{
		JHtml::_('jquery.framework');
		JHtml::_('script', 'system/html5fallback.js', false, true);
		
		$doc  = JFactory::getDocument();
		$root = JUri::root(true);
		
		$doc->addStyleSheet($root . '/media/com_vpadvanceduser/css/bootstrap-tagsinput.css');
		
		// Load angular before bootstrap
		$doc->addScript($root . '/media/com_vpadvanceduser/js/angular.min.js');
		
		JHtml::_('bootstrap.framework');
		
		$doc->addScript($root . '/media/com_vpadvanceduser/js/bootstrap-tagsinput.js');
		$doc->addScript($root . '/media/com_vpadvanceduser/js/bootstrap-tagsinput-angular.js');
		
		$doc->addScriptDeclaration("
		jQuery(function($) {
			$('#{$this->id}').tagsinput({
					trimValue: true,
					allowDuplicates: false,
					tagClass: 'label'
			});
		});
		");
		
		$html  = parent::getInput();
		$html .= '<div class="clearfix"></div>';

		if(!empty($this->element['hinttext']))
		{
				$html .= '<div class="muted small">' . JText::_($this->element['hinttext']) . '</div>';
		}

		return $html;
	}
}