<?php

namespace App\Form\Input;

class Autocomplete_BankAndOffice extends Autocomplete_GeneralAbstract
{

	protected $class = "autocompleteBankAndOffice";

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

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete::getValue()
	 */
	public function getValue()
	{
		$v = parent::getValue();
		if ($v==='|') {
			$v = '';
		}
		return $v;
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete::determineDisplayValue()
	 */
	public function determineDisplayValue($displayId) :string
	{
		if ($displayId) {
			$bankDet = explode('|', $displayId);

			$displayValue = '';
			if ($bankDet[0]) $displayValue = \Entity\Bank::select($bankDet[0])->name;
			if ($bankDet[1]) $displayValue.=' '.\Entity\BankOffice::select($bankDet[1])->name;
			return $displayValue;
		}
		return '';
	}

}
