<?php
namespace SabaiApps\Directories\Component\Field\Type;

use SabaiApps\Directories\Component\Field\IField;
use SabaiApps\Directories\Component\Entity\Type\IEntity;
use SabaiApps\Directories\Component\Entity\Model\Bundle;

class StringType extends AbstractStringType implements ILabellable {

	protected function _fieldTypeInfo() {
		return array(
			'label'            => __( 'Single Line Text', 'directories-pro' ),
			'default_widget'   => 'textfield',
			'default_settings' => array(
				'min_length'      => null,
				'max_length'      => null,
				'char_validation' => 'none',
				'regex'           => null,
				'prefix'          => null,
				'suffix'          => null,
			),
			'icon'             => 'fas fa-minus',
		);
	}

	public function fieldTypeSettingsForm( $fieldType, Bundle $bundle, array $settings, array $parents = array(), array $rootParents = array() ) {
		return parent::fieldTypeSettingsForm( $fieldType, $bundle, $settings, $parents, $rootParents ) + array(
			'prefix' => array(
				'#type'          => 'textfield',
				'#title'         => __( 'Field prefix', 'directories-pro' ),
				'#description'   => __( 'Example: $, #, -', 'directories-pro' ),
				'#size'          => 20,
				'#default_value' => $settings['prefix'],
				'#no_trim'       => true,
			),
			'suffix' => array(
				'#type'          => 'textfield',
				'#title'         => __( 'Field suffix', 'directories-pro' ),
				'#description'   => __( 'Example: km, %, g', 'directories-pro' ),
				'#size'          => 20,
				'#default_value' => $settings['suffix'],
				'#no_trim'       => true,
			),
		);
	}

	public function fieldLabellableLabels( IField $field, IEntity $entity ) {
		return $entity->getFieldValue( $field->getFieldName() );
	}
}
