<?php
namespace App\Utils\Views;

abstract class AbstractHtmlComponent
{
	/**
	 * The list of internal options
	 * @var array
	 */
	private $options = [];

	/**
	 * Render the html output of this component
	 * @return string
	 */
	abstract function renderHtml();

	/**
	 * Generate the JS initializer scripts needed for this component. It might use the JS loader class to inject needed scripts
	 * The component is supposed to return only the script content, without surrounding tags (no <script> tags)
	 * @param \JSLoader_complex $JSLoader
	 * @return string
	 */
	abstract function renderJs(\JSLoader_complex $JSLoader);

	/**
	 * Preload needed CSS's for this component. It might use the CSS loader class to inject needed scripts
	 * The component is supposed to return only the script content, without surrounding tags (no <style> tags)
	 * @param \Engine\Theme\CSSLoader\Complex $CSSLoader
	 * @return string
	 */
	abstract function preloadCss(\Engine\Theme\CSSLoader\Complex $CSSLoader);

	/**
	 * Preload needed JS's for this component. It might use the JS loader class to inject needed scripts
	 * The component is supposed to return only the script content, without surrounding tags (no <script> tags)
	 * @param \JSLoader_complex $JSLoader
	 * @return string
	 */
	abstract function preloadJs(\JSLoader_complex $JSLoader);

	/**
	 * Set a general option
	 * @param string $key
	 * @param mixed $value
	 */
	public function setOption($key, $value)
	{
		$this->options[$key] = $value;
		return $this;
	}

	/**
	 * Set multiple options at a time
	 * @param array $values
	 */
	public function mergeOptions($values)
	{
		foreach ($values as $k=>$v) {
			$this->options[$k] = $v;
		}

		return $this;
	}

	/**
	 * Get a specific option value
	 * @param string $key
	 * @return mixed
	 */
	public function getOption($key)
	{
		return $this->options[$key];
	}
}
