<?php
declare( strict_types=1 );

namespace FiboFilters\Filters\Types;

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

/**
 * Class Checkboxes
 */
class Checkboxes extends Filter {

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

	/**
	 * Allow ony selected values in this type of filter if source is "Stock status"
	 *
	 * @param array $values Filter values.
	 */
	protected function filter_values( array $values ): array {
		if ( count( $values ) <= 1 ) {
			return $values;
		}

		$source = $this->get_prop( 'source' );

		if ( $source === 'cf__stock_status' ) {
			$values = array_filter(
				$values,
				function ( array $value ): bool {
					return $value['value'] !== 'outofstock';
				}
			);
		}

		return $values;
	}
}
