<?php
declare( strict_types=1 );

namespace FiboFilters\Filters\Types;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Radio
 */
class Radio extends Filter {

	const ARTIFICIAL_VALUE_ANY_ID = - 1;

	/**
	 * This is the name of this filter type.
	 *
	 * @var string
	 */
	protected $filter_type = 'radio';

	protected function extend_data(): void {
		$this->data['any_label'] = '';
	}

	protected function before_set_values(): void {
		if ( ! empty( $this->get_prop( 'any_label' ) ) ) {
			$any_label = apply_filters( 'fibofilters/filter/radio/any_label', $this->get_prop( 'any_label' ) );
		} else {
			$any_label = _x( 'Any', '[front]', 'fibofilters' );
		}

		$this->values[] = [
			'value_id'    => self::ARTIFICIAL_VALUE_ANY_ID,
			'value'       => '',
			'label'       => $any_label,
			'label_url'   => '',
			'description' => '',
			'selected'    => true,
			'disabled'    => false,
			'counter'     => null, // When value is 'null' then counter will be hidden.
			'default'     => true,
		];
	}

	protected function after_set_values(): void {
		$this->maybe_overwrite_value_labels();
	}
}
