<?php
/**
 * Variant engine resolver functions.
 *
 * @package The Studio Player
 */

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

if ( ! function_exists( 'thespl_get_variant_engine_class' ) ) {
	/**
	 * Get the active variant engine class name.
	 *
	 * @return string
	 */
	function thespl_get_variant_engine_class() {
		$class_name = 'THESPL_Variant_Engine';

		if ( defined( 'THESPL_HAS_PRO_ASSETS' ) && THESPL_HAS_PRO_ASSETS && class_exists( 'THESPL_Variant_Engine_Pro' ) ) {
			$class_name = 'THESPL_Variant_Engine_Pro';
		}

		return is_string( $class_name ) && '' !== $class_name ? $class_name : 'THESPL_Variant_Engine';
	}
}

if ( ! function_exists( 'thespl_get_variant_engine' ) ) {
	/**
	 * Get the active variant engine instance.
	 *
	 * @return THESPL_Variant_Engine
	 */
	function thespl_get_variant_engine() {
		static $instance       = null;
		static $instance_class = '';

		$class_name = thespl_get_variant_engine_class();
		if ( null !== $instance && $instance_class === $class_name ) {
			return $instance;
		}

		if ( ! class_exists( $class_name ) ) {
			$class_name = 'THESPL_Variant_Engine';
		}

		$instance       = new $class_name();
		$instance_class = $class_name;

		return $instance;
	}
}
