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

use Prodigy\Includes\Frontend\Prodigy_Product_Template_Builder;
use Prodigy\Includes\Frontend\Prodigy_Product_Template_Item;
use Prodigy\Includes\Helpers\Prodigy_Widget_Options;

/**
 * Prodigy product description data mapper
 *
 * @version    3.0.4
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Product_Short_Description_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['content'] = ! empty( $product ) ? $product->get_remote_description() :
			'description description description description description description description description description description
         description description description description description description description description description description
          description description description description description description description description description';
		$options['product'] = ! empty( $product ) ? $product : array();

		$options['show_description'] = $this->customizer_product_options['prodigy_product_description'] ?? true;
		if ( isset( $options['idwidget'] ) ) {
			$options['settings']                 = $options;
			$options['content_truncate_chars']   = $options['prg_content_description_truncate_chars']['size'] ?? 0;
			$options['style_anchor_type']        = $options['prg_style_anchor_type'];
			$options['show_description']         = true;
			$options['content_description_show'] = isset( $options['prg_content_description_show'] ) && Prodigy_Widget_Options::$bool_mapper[ $options['prg_content_description_show'] ];
			$options['is_huge_description']      = ( strlen( $options['content'] ) > $options['content_truncate_chars'] && $options['content_description_show'] );
		}

		return $options;
	}
}
