<?php
declare( strict_types=1 );

namespace FiboFilters\Filters\SourceTypes;

/**
 * Class Price
 */
class Price extends SourceType {
	public function validate_user_input( string $user_input, string $filter_type = '' ): array {
		$values = explode( '-', $user_input );

		if ( count( $values ) === 2 ) {
			$from = is_numeric( $values[0] ) ? $this->format_price( $values[0] ) : self::ARTIFICIAL_NO_VALUE;
			$to   = is_numeric( $values[1] ) ? $this->format_price( $values[1] ) : self::ARTIFICIAL_NO_VALUE;

			if ( $to >= 0 && $from > $to ) {
				$from = $to;
			}

			return [
				$from,
				$to,
			];
		}

		return [ self::ARTIFICIAL_NO_VALUE, self::ARTIFICIAL_NO_VALUE ];
	}

	public function get_calculate_percentage_share(): float {
		$total_products_count = $this->woocommerce_helper->get_total_products_count();
		$count                = $this->woocommerce_helper->get_product_count_with_price();

		return $this->get_percentage( $count, $total_products_count );
	}
}
