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

use Prodigy\Includes\Content\Prodigy_Order_Parser;
use Prodigy\Includes\Content\Prodigy_Request_Maker;
use Prodigy\Includes\Helpers\Prodigy_Platform_Settings;

/**
 * Prodigy thank you page data mapper
 *
 * @version    2.7.0
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Thank_Page_Data_Mapper extends Prodigy_Main_Data_Mapper {


	const TEST_MESSAGE       = 'Test';
	const TEST_ORDER_MESSAGE = 'Thank you for your order.';

	/**
	 * @param array $options
	 *
	 * @return array
	 */
	public function get_default_parameters( array $options ): array {
		if ( isset( $options['order_token'] ) ) {
			$order_data          = Prodigy_Request_Maker::get_instance()->do_order_request( $options['order_token'] );
			$order_info          = new Prodigy_Order_Parser( $order_data );
			$attrs               = $order_info->get_attributes();
			$up_sell_product_ids = $order_info->get_cross_sell_products();
			$products            = get_format_related_products( $up_sell_product_ids );
		}

		return array(
			'up_sell_product_ids' => $products ?? array(),
			'list_ids'            => '',
			'test_preview'        => empty( $options['order_token'] ) && ( isset( $options['is_elementor'] ) && $options['is_elementor'] ),
			'order_info'          => $order_info ?? '',
			'order_remote'        => $attrs['number'] ?? self::TEST_MESSAGE,
			'message'             => Prodigy_Platform_Settings::get_thank_you_page_title_from_api() ?: ( $options['heading_text'] ?? 'Thank you for your order' ),
			'body_text'           => Prodigy_Platform_Settings::get_thank_you_page_body(),
			'show_back_button'    => Prodigy_Platform_Settings::is_thank_you_page_back_btn_enabled(),
			'button_text'         => Prodigy_Platform_Settings::get_thank_you_page_button_text(),
			'divi_editor'         => $options['divi_editor'] ?? false,
			'is_approval'         => isset( $options['approval_needed'] ) && ! empty( $options['approval_needed'] ),
		);
	}
}
