<?php
namespace SabaiApps\Directories\Component\User\FieldFilter;

use SabaiApps\Directories\Component\Field;
use SabaiApps\Directories\Component\View\FieldFilter\GlossaryFieldFilter;
use SabaiApps\Directories\Component\Field\IField;

class NameFieldFilter extends GlossaryFieldFilter {

	protected function _fieldFilterInfo() {
		$info                               = parent::_fieldFilterInfo();
		$info['field_types']                = array( 'user_name' );
		$info['default_settings']['column'] = 'display_name';

		return $info;
	}

	public function fieldFilterSettingsForm( Field\IField $field, array $settings, array $parents = array() ) {
		$form           = parent::fieldFilterSettingsForm( $field, $settings, $parents );
		$form['column'] = array(
			'#type'          => 'select',
			'#title'         => __( 'Filter by', 'directories-pro' ),
			'#options'       => array(
				'display_name' => __( 'Display name', 'directories-pro' ),
				'first_name'   => __( 'First name', 'directories-pro' ),
				'middle_name'  => __( 'Middle name', 'directories-pro' ),
				'last_name'    => __( 'Last name', 'directories-pro' ),
			),
			'#default_value' => $settings['column'],
		);

		return $form;
	}

	protected function _getFacetColumn( IField $field, array $settings ) {
		return $settings['column'];
	}
}
