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

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

goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.WrappedHTMLElement');
goog.require('org.apache.royale.html.supportClasses.RadioButtonIcon');
goog.require('org.apache.royale.html.util.addElementToWrapper');
goog.require('org.apache.royale.core.ISelectable');
goog.require('org.apache.royale.utils.Language');



/**
 * @constructor
 * @extends {org.apache.royale.core.UIBase}
 * @implements {org.apache.royale.core.ISelectable}
 */
org.apache.royale.html.RadioButton = function() {
  org.apache.royale.html.RadioButton.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.RadioButton, org.apache.royale.core.UIBase);


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


/**
 * @export
 * @type {number}
 */
org.apache.royale.html.RadioButton.radioCounter = 0;


/**
 * @private
 * @type {HTMLLabelElement}
 */
org.apache.royale.html.RadioButton.prototype.org_apache_royale_html_RadioButton_labelFor;


/**
 * @private
 * @type {Text}
 */
org.apache.royale.html.RadioButton.prototype.org_apache_royale_html_RadioButton_textNode;


/**
 * @private
 * @type {org.apache.royale.html.supportClasses.RadioButtonIcon}
 */
org.apache.royale.html.RadioButton.prototype.org_apache_royale_html_RadioButton_icon;


/**
 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
 * @royaleignorecoercion HTMLInputElement
 * @royaleignorecoercion HTMLLabelElement
 * @royaleignorecoercion Text
 * @protected
 * @override
 */
org.apache.royale.html.RadioButton.prototype.createElement = function() {
  this.org_apache_royale_html_RadioButton_icon = new org.apache.royale.html.supportClasses.RadioButtonIcon();
  this.org_apache_royale_html_RadioButton_icon.id = '_radio_' + org.apache.royale.html.RadioButton.radioCounter++;
  this.org_apache_royale_html_RadioButton_textNode = document.createTextNode('');
  this.org_apache_royale_html_RadioButton_labelFor = org.apache.royale.html.util.addElementToWrapper(this, 'label');
  this.org_apache_royale_html_RadioButton_labelFor.appendChild(this.org_apache_royale_html_RadioButton_icon.element);
  this.org_apache_royale_html_RadioButton_labelFor.appendChild(this.org_apache_royale_html_RadioButton_textNode);
  this.org_apache_royale_html_RadioButton_textNode.royale_wrapper = this;
  this.org_apache_royale_html_RadioButton_icon.element.royale_wrapper = this;
  this.typeNames = 'RadioButton';
  return this.element;
};


org.apache.royale.html.RadioButton.prototype.set__id = function(value) {
  org.apache.royale.html.RadioButton.superClass_.set__id.apply(this, [ value] );
  this.org_apache_royale_html_RadioButton_labelFor.id = value;
  this.org_apache_royale_html_RadioButton_icon.element.id = value;
};


org.apache.royale.html.RadioButton.prototype.get__groupName = function() {
  return org.apache.royale.utils.Language.as(this.org_apache_royale_html_RadioButton_icon.element.name, String);
};


org.apache.royale.html.RadioButton.prototype.set__groupName = function(value) {
  this.org_apache_royale_html_RadioButton_icon.element.name = value;
};


org.apache.royale.html.RadioButton.prototype.get__text = function() {
  return org.apache.royale.utils.Language.as(this.org_apache_royale_html_RadioButton_textNode.nodeValue, String);
};


org.apache.royale.html.RadioButton.prototype.set__text = function(value) {
  this.org_apache_royale_html_RadioButton_textNode.nodeValue = value;
};


org.apache.royale.html.RadioButton.prototype.get__selected = function() {
  return this.org_apache_royale_html_RadioButton_icon.element.checked;
};


org.apache.royale.html.RadioButton.prototype.set__selected = function(value) {
  this.org_apache_royale_html_RadioButton_icon.element.checked = value;
};


org.apache.royale.html.RadioButton.prototype.get__value = function() {
  return this.org_apache_royale_html_RadioButton_icon.element.value;
};


org.apache.royale.html.RadioButton.prototype.set__value = function(v) {
  this.org_apache_royale_html_RadioButton_icon.element.value = "" + v;
};


org.apache.royale.html.RadioButton.prototype.get__selectedValue = function() {
  var /** @type {NodeList} */ buttons;
  var /** @type {string} */ groupName;
  var /** @type {number} */ i = 0;
  var /** @type {number} */ n = 0;
  groupName = this.org_apache_royale_html_RadioButton_icon.element.name;
  buttons = document.getElementsByName(groupName);
  n = buttons.length;
  for (i = 0; i < n; i++) {
    if (buttons[i].checked) {
      return buttons[i].value;
    }
  }
  return null;
};


org.apache.royale.html.RadioButton.prototype.set__selectedValue = function(value) {
  var /** @type {NodeList} */ buttons;
  var /** @type {string} */ groupName;
  var /** @type {number} */ i = 0;
  var /** @type {number} */ n = 0;
  groupName = this.org_apache_royale_html_RadioButton_icon.element.name;
  buttons = document.getElementsByName(groupName);
  n = buttons.length;
  for (i = 0; i < n; i++) {
    if (buttons[i].value === value) {
      buttons[i].checked = true;
      break;
    }
  }
};


Object.defineProperties(org.apache.royale.html.RadioButton.prototype, /** @lends {org.apache.royale.html.RadioButton.prototype} */ {
/**
  * @export
  * @type {string} */
id: {
get: org.apache.royale.core.UIBase.prototype.get__id,
set: org.apache.royale.html.RadioButton.prototype.set__id},
/**
  * @export
  * @type {string} */
groupName: {
get: org.apache.royale.html.RadioButton.prototype.get__groupName,
set: org.apache.royale.html.RadioButton.prototype.set__groupName},
/**
  * @export
  * @type {string} */
text: {
get: org.apache.royale.html.RadioButton.prototype.get__text,
set: org.apache.royale.html.RadioButton.prototype.set__text},
/**
  * @export
  * @type {boolean} */
selected: {
get: org.apache.royale.html.RadioButton.prototype.get__selected,
set: org.apache.royale.html.RadioButton.prototype.set__selected},
/**
  * @export
  * @type {string} */
value: {
get: org.apache.royale.html.RadioButton.prototype.get__value,
set: org.apache.royale.html.RadioButton.prototype.set__value},
/**
  * @export
  * @type {Object} */
selectedValue: {
get: org.apache.royale.html.RadioButton.prototype.get__selectedValue,
set: org.apache.royale.html.RadioButton.prototype.set__selectedValue}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.RadioButton.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {
      return {
        '|radioCounter': { type: 'int'}
      };
    },
    accessors: function () {
      return {
        'id': { type: 'String', access: 'writeonly', declaredBy: 'org.apache.royale.html.RadioButton'},
        'groupName': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.html.RadioButton'},
        'text': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.html.RadioButton'},
        'selected': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.html.RadioButton'},
        'value': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.html.RadioButton'},
        'selectedValue': { type: 'Object', access: 'readwrite', declaredBy: 'org.apache.royale.html.RadioButton'}
      };
    },
    methods: function () {return {};},
    metadata: function () { return [  ]; }
  };
};