<?php
declare( strict_types=1 );

namespace FiboFilters\Integrations\Plugins;

use FiboFilters\Config\AssetsLoader;
use FiboFilters\Filtering\Front;
use FiboFilters\Index\Sources;
use FiboFilters\Integrations\Multilingual;
use FiboFilters\Settings\Settings;
use FiboFilters\WooCommerce\Helper as WooCommerceHelper;

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

/**
 * Class AbstractPlugin
 */
abstract class AbstractPlugin {
	/** @var AssetsLoader */
	protected $assets_loader;

	/** @var Multilingual */
	protected $multilingual;

	/** @var Front */
	protected $front;

	/** @var Settings */
	protected $settings;

	/** @var Sources */
	protected $sources;

	/** @var WooCommerceHelper */
	protected $wc_helper;

	public function __construct( Front $front, Settings $settings, WooCommerceHelper $wc_helper, Sources $sources, Multilingual $multilingual, AssetsLoader $assets_loader ) {
		$this->front         = $front;
		$this->settings      = $settings;
		$this->wc_helper     = $wc_helper;
		$this->sources       = $sources;
		$this->multilingual  = $multilingual;
		$this->assets_loader = $assets_loader;
	}

	abstract public function init(): void;

	/**
	 * Allow use \FiboFilters\Filtering\Front::config in partials.
	 *
	 * WARNING!
	 * This method could be used, but it has to be fired later than 'template_redirect' with priority 5.
	 *
	 * @param string $key Key.
	 * @param mixed  $default_value Default value.
	 *
	 * @return mixed
	 */
	public function get_config_value( string $key, $default_value = null ) {
		return $this->front->get_config_value( $key, $default_value );
	}

	/**
	 * Enqueue inline script
	 *
	 * @param string     $js JavaScript code.
	 * @param array      $deps Dependencies.
	 * @param string     $handle_suffix Handle suffix.
	 * @param bool|array $args Arguments.
	 * @param int        $priority Priority.
	 *
	 * @see AssetsLoader::enqueue_inline_script()
	 */
	public function enqueue_inline_script( string $js, array $deps = [], string $handle_suffix = '', $args = true, int $priority = 15 ) {
		$this->assets_loader->enqueue_inline_script( $js, $deps, $handle_suffix, $args, $priority );
	}

	/**
	 * Enqueue inline style
	 *
	 * @param string $css CSS.
	 */
	public function enqueue_inline_style( string $css ) {
		$this->assets_loader->enqueue_inline_style( $css );
	}
}
