var UIElem = require('libresignage/ui/controller/UIElem');
var Assert = require('assert');

/**
* UIStatic settings object.
*
* Other settings are documented at
* {@link module:libresignage/ui/controller.UIElem#UIElemSettings}
*
* @typedef {object} module:libresignage/ui/controller.UIStatic#UIStaticSettings
*
* @property
*	{module:libresignage/ui/controller.UIStatic~default_getter}
*	getter
*	A function for getting the element HTML.
* @property
*	{module:libresignage/ui/controller.UIStatic~default_setter}
*	setter
*	A function for setting the element HTML.
*
* @memberof module:libresignage/ui/controller
*/

/**
* UI class for static DOM elements.
*
* @memberof module:libresignage/ui/controller
*/
class UIStatic extends UIElem {
	/**
	* Construct a new UIStatic element.
	*
	* @param
	*	{module:libresignage/ui/controller.UIStatic#UIStaticSettings}
	*	settings
	*	Element configuration values.
	*
	* @throws {AssertionError} if the settings object is invalid.
	*/
	constructor(settings) {
		Assert.ok('getter' in settings);
		Assert.ok('setter' in settings);

		super(settings);
		this.type = "static";

		this.getter = settings.getter;
		this.setter = settings.setter;

		if (!this.getter) { this.getter = this.default_getter; }
		if (!this.setter) { this.setter = this.default_setter; }
	}

	/**
	* Getter function for getting an element's innerHTML.
	*
	* @callback module:libresignage/ui/controller.UIStatic~default_getter
	*
	* @param {HTMLElement} e The HTML element to access.
	*
	* @return {string} The innerHTML of the element.
	*
	*/
	default_getter(e) { return e.innerHTML; }

	/**
	* Setter function for setting an element's innerHTML.
	*
	* @callback module:libresignage/ui/controller.UIStatic~default_setter
	*
	* @param {HTMLElement} e    The HTML element to access.
	* @param {string}      html The HTML to set as the element's innerHTML.
	*/
	default_setter(e, html) { e.innerHTML = html; }
	
	get() { return this.getter(this.get_elem()); }
	set(html) { this.setter(this.get_elem(), html); }
}
module.exports = UIStatic;

