<?php

namespace App\Form\Input;

/**
 * Corporate autocomplete field
 *
 */
class Autocomplete_CorporateOffice extends Autocomplete_GeneralAbstract
{

	protected $class = "autocompleteCorporate";

	public function __construct($label=null, $name=null, $value=null)
	{
		parent::__construct($label, $name, $value);

		$this->setStyle('minimumTextLength', 3);
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete::getUrl()
	 */
	public function getUrl()
	{
		return ($this->url?:\Engine\Mvc\Dispatcher::getInstance()->getAppUrl('Modules/RemoteData/AutocompleteFieldData', '', ['class'=>'CorporateOffice']));
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete::determineDisplayValue()
	 */
	public function determineDisplayValue($displayId) :string
	{
		if ($displayId) {
			list($idCorp, $idCorpOff) = explode('|', $displayId);
			return \Entity\Corporate::select($idCorp)->alias.' - '.\Entity\CorporateOffice::select($idCorpOff)->name;
		}
		return '';
	}

}
