<?php
namespace Prodigy\Includes\Frontend\Mappers;

use Prodigy\Includes\Content\Prodigy_Catalog_Filters_Parser;
use Prodigy\Includes\Helpers\Prodigy_Page;
use Prodigy\Includes\Helpers\Prodigy_Url_Helper;
use Prodigy\Includes\Prodigy;

defined( 'ABSPATH' ) || exit;

/**
 * Prodigy price filter data mapper
 *
 * @version    2.9.1
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Price_Filter_Data_Mapper extends Prodigy_Main_Data_Mapper {

	/**
	 * @param array $options
	 *
	 * @return array
	 */
	public function get_default_parameters( array $options = array() ): array {
		$prepared_params = $this->clear_catalog_params( $_GET );
		$query           = $this->build_query_params( $prepared_params, $options );
		$content         = Prodigy_Page::prodigy_is_frontend()
			? $this->request_maker->do_catalog_filters_request( $query )
			: $this->request_maker->do_admin_catalog_filters_request( $query );
		$catalog_info    = Prodigy_Catalog_Filters_Parser::get_catalog_info( $content );
		$catalog_info    = json_decode( wp_json_encode( $catalog_info['attributes'] ?? array() ), true );
		$max_price       = (int) ( $catalog_info['price-range']['max_price'] ?? 0 );
		$min_price       = (int) ( $catalog_info['price-range']['min_price'] ?? 0 );

		return array(
			'filter_nonce'          => $this->filter_nonce,
			'min'                   => $min_price,
			'max'                   => $max_price,
			'query_min_price'       => $min_price,
			'query_max_price'       => $max_price,
			'taxonomy'              => Prodigy::get_prodigy_category_type(),
			'current_type_category' => Prodigy::get_prodigy_category_type(),
			'attr_shortcode'        => $options,
			'shop_page'             => Prodigy_Url_Helper::prodigy_get_shop_url(),
			'is_shop_page'          => ( is_prodigy_product_taxonomy() || is_page( Prodigy_Page::prodigy_get_page_id( 'shop' ) ) ) ? 'true' : 'false',
			'heading_price_filter'  => $options['attr_shortcode']['price_style_heading_text'] ?? 'Price Filter',
		);
	}
}
