<?php
/**
 * Showcase Layout for Product Showcase (Free Version)
 *
 * @package Product_Display
 */

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

/**
 * Class PRODDISP_Showcase
 *
 * This class handles the rendering of the showcase layout for product showcase.
 * It extends the base layout class and provides methods to render products in a showcase format,
 * including category filtering and product actions.
 */

class PRODDISP_Showcase extends PRODDISP_Layout_Base {
	public function __construct( $settings = array() ) {
		parent::__construct($settings);
	}
	public function render( $products ) {
		// Enqueue showcase-specific assets
		PRODDISP_Assets::get_instance()->enqueue_showcase_style_assets();

		// Check if PRO is active and PRO showcase class is available
		if ( PRODDISP_Loader::is_pro_active() && $this->should_use_pro_layout() ) {
			return $this->render_pro_layout( $products );
		}

		// Handle pro layout modes using the base class method
		$pro_result = $this->handle_pro_layout_mode('showcase-2', 'PRODDISP_PRO_Showcase', 'showcase-locked-style-2.gif', $products);
		if ( $pro_result !== false ) {
			return $pro_result;
		}

		$pro_result = $this->handle_pro_layout_mode('showcase-3', 'PRODDISP_PRO_Showcase', 'showcase-locked-style-3.gif', $products);
		if ( $pro_result !== false ) {
			return $pro_result;
		}

		// Default showcase layout (style 1) is also pro - show locked layout
		return $this->render_locked_layout('showcase-locked.jpg.gif');
	}

	/**
	 * Check if we should use the PRO layout
	 *
	 * @return bool
	 */
	private function should_use_pro_layout() {
		return defined('PRODDISP_PRO_PLUGIN_DIR') && 
			   file_exists(PRODDISP_PRO_PLUGIN_DIR . 'inc/layouts/showcase/class-proddisp-pro-showcase.php');
	}

	/**
	 * Render using PRO layout class
	 *
	 * @param array $products
	 * @return string
	 */
	private function render_pro_layout( $products ) {
		// Include PRO showcase class if not already loaded
		if ( ! class_exists('PRODDISP_PRO_Showcase') ) {
			require_once PRODDISP_PRO_PLUGIN_DIR . 'inc/layouts/showcase/class-proddisp-pro-showcase.php';
		}

		if ( class_exists('PRODDISP_PRO_Showcase') ) {
			$pro_showcase = new PRODDISP_PRO_Showcase( $this->settings );
			return $pro_showcase->render( $products );
		}

		// Fallback to locked layout if PRO class fails to load
		return $this->render_locked_layout('showcase-locked.jpg.gif');
	}
}
