"use strict";

/**
 * Check box input element.
 * 
 * @class CheckBox
 * @extends {Element}
 * @param {Element} parent Parent element.
 */
function CheckBox(parent)
{
	Element.call(this, parent, "div");

	var self = this;

	this.element.style.display = "block";
	this.element.style.boxSizing = "border-box";
	this.element.style.cursor = "pointer";
	this.element.style.backgroundColor = Editor.theme.boxColor;
	this.element.style.borderRadius = "4px";
	this.element.onclick = function()
	{
		self.setValue(!self.value);
		
		if(self.onChange !== null)
		{
			self.onChange(self.value);
		}
	};

	this.check = document.createElement("img");
	this.check.style.visibility = "hidden";
	this.check.style.pointerEvents = "none";
	this.check.style.position = "absolute";
	this.check.style.top = "20%";
	this.check.style.left = "20%";
	this.check.style.width = "60%";
	this.check.style.height = "60%";
	this.check.src = Editor.FILE_PATH + "icons/misc/check.png";
	this.element.appendChild(this.check);

	/**
	 * Value stored in the checkbox.
	 *
	 * @property value
	 * @type {Boolean}
	 */
	this.value = false;

	/**
	 * On change callback function.
	 *
	 * @property onChange
	 * @type {Function}
	 */
	this.onChange = null;
};

CheckBox.prototype = Object.create(Element.prototype);

/**
 * Set if element is disabled.
 *
 * @method setDisabled
 */
CheckBox.prototype.setDisabled = function(value)
{
	this.element.disabled = value;
};

/**
 * Set checkbox value.
 * 
 * @method setValue
 * @param {Boolean} value
 */
CheckBox.prototype.setValue = function(value)
{
	this.value = value;
	this.check.style.visibility = this.value ? "visible" : "hidden";
};

/**
 * Get checkbox value.
 * 
 * @method getValue
 * @return {Boolean} Value from the element.
 */
CheckBox.prototype.getValue = function()
{
	return this.value;
};

/**
 * Set onchange callback.
 * 
 * @method setOnChange
 * @param {Function} callback
 */
CheckBox.prototype.setOnChange = function(callback)
{
	this.onChange = callback;
};

CheckBox.prototype.updateVisibility = function()
{
	this.element.style.visibility = this.visible ? "visible" : "hidden";
};

CheckBox.prototype.updateSize = function()
{
	this.element.style.width = this.size.y + "px";
	this.element.style.height = this.size.y + "px";
};

@@ -1266,16 +1266,168 @@
 = null;%0D
+%0A%0D%0A%09/** %0D%0A%09 * If the checkbox is disabled the value cannot be edited.%0D%0A%09 *%0D%0A%09 * @attribute disabled%0D%0A%09 * @type %7BBoolean%7D%0D%0A%09 */%0D%0A%09this.disabled = false;%0D
 %0A%7D;%0D%0A%0D%0AC
@@ -1524,16 +1524,75 @@
 d.%0D%0A *%0D%0A
+ * When disabled the checkbox value cannot be edited.%0D%0A *%0D%0A
  * @meth
@@ -1671,24 +1671,16 @@
 %0D%0A%09this.
-element.
 disabled
@@ -1684,24 +1684,255 @@
 led = value;
+%0D%0A%09%0D%0A%09if(this.disabled === true)%0D%0A%09%7B%0D%0A%09%09this.element.style.cursor = %22initial%22;%0D%0A%09%09this.element.style.pointerEvents = %22none%22;%0D%0A%09%7D%0D%0A%09else%0D%0A%09%7B%0D%0A%09%09this.element.style.cursor = %22pointer%22;%0D%0A%09%09this.element.style.pointerEvents = %22auto%22;%0D%0A%09%7D
 %0D%0A%7D;%0D%0A%0D%0A/**%0D

Disable checkbox