<?php
namespace common\components;

use Yii;
use kartik\widgets\Typeahead;
use yii\helpers\Url;
use yii\web\JsExpression;


class CityNameTypeahead extends Typeahead{
	
	public $item_template = '<div><p class="">{{fullname}}</p></div>';
	
	public $options = ['placeholder' => 'Válassz várost'];
	
	public $pluginOptions = ['highlight'=>true];
	
	public $scrollable = true;
	
	public $display = 'name';
	
	public $pluginEvents = [	"typeahead:select" => "function(a,b) {   }",];
			 
	
	
	public function init(){
		parent::init();
		$this->dataset = $this->createDefaultDataset();
	}
	
	protected function createDefaultDataset(){
		return [
    				[
    					'limit' => 20,
    					'remote' => [
    							'ttl' => 1,
    							'url' => Url::to(['city/name-list']) . '&search=%QUERY&' . rand(0, 100000000),
    							'wildcard' => '%QUERY'
    						],
    						'limit' => 10,
    						'display' => $this->display,
    						'templates' => [
	    						'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>',
	    						'suggestion' => new JsExpression("Handlebars.compile('{$this->item_template}')")
    						]
    			]
		];
	}
	
}