<?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_Formatting;
use Prodigy\Includes\Helpers\Prodigy_Widget_Options;

/**
 * Prodigy sku data mapper
 *
 * @version    3.0.4
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Product_Sku_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 {
		$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() );
		$params['main_sku']         = ! empty( $product ) ? $product->get_remote_main_sku() : '';
		$params['categories']       = ! empty( $product ) ? $product->get_remote_categories() : array();
		$params['tags']             = ! empty( $product ) ? $product->get_remote_tags() : array();
		$params['count_categories'] = count( ( is_countable( $params['categories'] ) ? $params['categories'] : array() ) );
		$params['count_tags']       = count( ( is_countable( $params['tags'] ) ? $params['tags'] : array() ) );

		$params['enable_product_sku'] = isset( $options['meta_show_sku'] )
			? ( Prodigy_Widget_Options::$bool_mapper[ $options['meta_show_sku'] ] )
			: ( $this->customizer_product_options['prodigy_product_sku'] ?? true );

		$params['enable_product_categories'] = isset( $options['meta_show_categories'] )
			? ( Prodigy_Widget_Options::$bool_mapper[ $options['meta_show_categories'] ] )
			: ( $this->customizer_product_options['prodigy_product_categories'] ?? true );

		$params['enable_product_tags'] = isset( $options['meta_show_tags'] )
			? ( Prodigy_Widget_Options::$bool_mapper[ $options['meta_show_tags'] ] )
			: ( $this->customizer_product_options['prodigy_product_tags'] ?? true );

		$params['charge_amount'] = Prodigy_Formatting::prodigy_price_format( $product->get_charge_amount() );

		return $params;
	}
}
