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

use Prodigy\Includes\Content\Prodigy_Product_Parser;
use Prodigy\Includes\Frontend\Prodigy_Product_Template_Builder;
use Prodigy\Includes\Frontend\Prodigy_Product_Template_Item;
use Prodigy\Includes\Helpers\Prodigy_Platform_Settings;

/**
 * Prodigy product price data mapper
 *
 * @version    3.0.4
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Product_Price_Data_Mapper extends Prodigy_Main_Data_Mapper {

	/**
	 * Prepare data and variables to inject in template
	 *
	 * @param array $options
	 *
	 * @return array
	 */
	public function get_default_parameters( array $options = array() ): array {
		$product_template                     = new Prodigy_Product_Template_Builder( new Prodigy_Product_Template_Item() );
		$product                              = $GLOBALS['prodigy_product'] ?? $product_template->set_product( (int) Prodigy_Product_Template_Builder::get_random_product_id() );
		$options['main_price']                = ! empty( $product ) ? $product->get_remote_main_price() : 0;
		$options['tiered_price_range']        = $product->get_tiered_price_range();
		$options['is_tiered_prices']          = ! empty( $options['tiered_price_range']['min_price'] ) && ! empty( $options['tiered_price_range']['max_price'] ) && ! empty( $options['tiered_price_range']['min_quantity'] );
		$options['product']                   = ! empty( $product ) ? $product : array();
		$options['show_min_price']            = ! Prodigy_Platform_Settings::is_product_page_price_range_settings();
		$options['price_range_show_sale']     = $options['price_range_show_sale'] ?? '';
		$options['is_show_price_sale_format'] = (int) ! empty( $options['price_range_show_sale'] );
		$options['is_variants']               = ! empty( $product->get_variant_options() );
		$options['is_single_variants_option'] = Prodigy_Product_Parser::is_single_variant( $product->get_variant_options() );

		return $options;
	}
}
