/**
 * Generated by Apache Royale Compiler from org\apache\royale\html\ToggleTextButton.as
 * org.apache.royale.html.ToggleTextButton
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.html.ToggleTextButton');

goog.require('org.apache.royale.core.WrappedHTMLElement');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.html.TextButton');
goog.require('org.apache.royale.core.ISelectable');
goog.require('org.apache.royale.utils.Language');



/**
 *  Constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.0
 * @constructor
 * @extends {org.apache.royale.html.TextButton}
 * @implements {org.apache.royale.core.ISelectable}
 */
org.apache.royale.html.ToggleTextButton = function() {
  org.apache.royale.html.ToggleTextButton.base(this, 'constructor');
  
  this.typeNames = 'ToggleTextButton';
};
goog.inherits(org.apache.royale.html.ToggleTextButton, org.apache.royale.html.TextButton);


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.html.ToggleTextButton', org.apache.royale.html.ToggleTextButton);


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.html.ToggleTextButton.prototype.org_apache_royale_html_ToggleTextButton__selected = false;


/**
 * @protected
 * @override
 */
org.apache.royale.html.ToggleTextButton.prototype.createElement = function() {
  org.apache.royale.html.ToggleTextButton.superClass_.createElement.apply(this);
  this.element.addEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_ToggleTextButton_clickHandler, this, 'clickHandler'), false);
  this.org_apache_royale_html_ToggleTextButton_internalSelected();
  return this.element;
};


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.ToggleTextButton.prototype.org_apache_royale_html_ToggleTextButton_clickHandler = function(event) {
  this.selected = !this.selected;
};


/**
 * @private
 */
org.apache.royale.html.ToggleTextButton.prototype.org_apache_royale_html_ToggleTextButton_internalSelected = function() {
  
  var /** @type {boolean} */ isToggleTextButtonSelected = this.element.classList.contains("selected");
  if (isToggleTextButtonSelected != this.org_apache_royale_html_ToggleTextButton__selected)
    this.element.classList.toggle("selected");
};


org.apache.royale.html.ToggleTextButton.prototype.get__selected = function() {
  
  return this.org_apache_royale_html_ToggleTextButton__selected;
};


org.apache.royale.html.ToggleTextButton.prototype.set__selected = function(value) {
  
  if (this.org_apache_royale_html_ToggleTextButton__selected != value) {
    this.org_apache_royale_html_ToggleTextButton__selected = value;
    this.org_apache_royale_html_ToggleTextButton_internalSelected();
    this.dispatchEvent(new org.apache.royale.events.Event("change"));
  }
};


Object.defineProperties(org.apache.royale.html.ToggleTextButton.prototype, /** @lends {org.apache.royale.html.ToggleTextButton.prototype} */ {
/**
  * @export
  * @type {boolean} */
selected: {
get: org.apache.royale.html.ToggleTextButton.prototype.get__selected,
set: org.apache.royale.html.ToggleTextButton.prototype.set__selected}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.html.ToggleTextButton.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'ToggleTextButton', qName: 'org.apache.royale.html.ToggleTextButton', kind: 'class' }], interfaces: [org.apache.royale.core.ISelectable] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.ToggleTextButton.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'selected': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.html.ToggleTextButton', metadata: function () { return [ { name: 'Bindable', args: [ { key: '', value: 'change' } ] } ]; }}
      };
    },
    methods: function () {
      return {
        'ToggleTextButton': { type: '', declaredBy: 'org.apache.royale.html.ToggleTextButton'}
      };
    },
    metadata: function () { return [  ]; }
  };
};