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

/**
 * Prodigy categories filter shortcode class
 *
 * @version   3.1.2
 * @package    Prodigy
 * @subpackage Prodigy/includes
 */
class Prodigy_Short_Code_Categories_Filter extends Prodigy_Main_Short_Code {

	/**
	 * Prodigy_Short_Code_Categories_Filter constructor.
	 */
	public function __construct() {
		parent::__construct();
		add_shortcode( 'prodigy_categories_filter', array( $this, 'output' ) );
	}

	/**
	 * @param array $params
	 *
	 * @return void
	 */
	public function render_view( array $params ) {
		do_action( 'prodigy_shortcode_template_categories_filter', $params );
	}


	public function set_script() {
		$cache_prefix = defined( 'WP_ROCKET_VERSION' ) ? '?ver=' . PRODIGY_VERSION . '&cb=' . time() : '';

		wp_enqueue_script(
			'prodigy-categories',
			plugin_dir_url( PRODIGY_PLUGIN_PATH . '/includes/frontend/shortcodes/js/prodigy-category.js' ) . 'prodigy-category.js' . $cache_prefix,
			array( 'jquery' ),
			PRODIGY_VERSION,
			false
		);
	}

	/**
	 * @param $attr
	 *
	 * @return string
	 */
	public function output( $attr ): string {
		$this->set_script();
		ob_start();
		$this->render_view( $attr );

		return ob_get_clean();
	}
}
