<?php
namespace SabaiApps\Directories\Component\Entity\FieldWidget;

use SabaiApps\Directories\Component\Entity\Type\IEntity;
use SabaiApps\Directories\Component\Field;

class LevelFieldWidget extends Field\Widget\AbstractWidget {

	protected function _fieldWidgetInfo() {
		return array(
			'field_types' => array( $this->_name ),
		);
	}

	public function fieldWidgetForm( Field\IField $field, array $settings, $value = null, ?IEntity $entity = null, array $parents = array(), $language = null ) {
		if ( ! $this->_application->IsAdministrator()
			|| ( ! $bundle = $field->Bundle )
			|| ( ! $options = $this->_application->Entity_Levels_options( $bundle, true ) )
			|| count( $options ) === 1
		) {
			return;
		}

		return array(
			'#type'          => 'select',
			'#default_value' => $value,
			'#options'       => $options,
		);
	}
}
