<?php
namespace Prodigy\Includes\Frontend\Shortcodes\Pages;

use Prodigy\Includes\Content\Prodigy_Order_Parser;
use Prodigy\includes\models\Prodigy_Order;
use Prodigy\Includes\Prodigy_Cache;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Prodigy cart page shortcode class
 *
 * @version    2.7.0
 */
class Prodigy_Short_Code_Cart_Page {

	/**
	 * Shortcode name
	 *
	 * @var string
	 */
	const NAME = 'prodigy_cart';

	/** @var Prodigy_Order_Parser  */
	protected Prodigy_Order_Parser $order;

	protected $order_token;

	/** @var Prodigy_Cache  */
	protected Prodigy_Cache $cache;

	/**
	 * Prodigy_Short_Code_Cart_Page constructor.
	 */
	public function __construct() {
		$this->order_token = ( new Prodigy_Order() )->get_order_token( $this->user_session ?? '' );
		$this->cache       = new Prodigy_Cache();
		add_shortcode( self::NAME, array( $this, 'output' ) );
	}

	/**
	 * @return string
	 */
	public function output(): string {
		if ( ! defined( 'DONOTCACHEPAGE' ) ) {
			define( 'DONOTCACHEPAGE', true );
		}
		ob_start();
		do_action( 'prodigy_get_template_cart_page', array( 'is_quantity_title' => false ) );

		wp_reset_postdata();
		$content = ob_get_contents();
		ob_end_clean();

		return $content;
	}
}
