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

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

goog.require('org.apache.royale.core.StyledUIBase');
goog.require('org.apache.royale.core.WrappedHTMLElement');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.html.util.addElementToWrapper');
goog.require('org.apache.royale.utils.Language');



/**
 *  Constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @constructor
 * @extends {org.apache.royale.core.StyledUIBase}
 */
org.apache.royale.jewel.RadioButton = function() {
  org.apache.royale.jewel.RadioButton.base(this, 'constructor');
  this.typeNames = "jewel radiobutton";
};
goog.inherits(org.apache.royale.jewel.RadioButton, org.apache.royale.core.StyledUIBase);


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


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


/**
 * @private
 * @type {HTMLSpanElement}
 */
org.apache.royale.jewel.RadioButton.prototype.org_apache_royale_jewel_RadioButton_radio;


/**
 * @private
 * @type {HTMLInputElement}
 */
org.apache.royale.jewel.RadioButton.prototype.org_apache_royale_jewel_RadioButton_icon;


/**
 * @private
 * @type {HTMLLabelElement}
 */
org.apache.royale.jewel.RadioButton.prototype.org_apache_royale_jewel_RadioButton_label;


/**
 * @private
 * @type {Text}
 */
org.apache.royale.jewel.RadioButton.prototype.org_apache_royale_jewel_RadioButton_textNode;


/**
 * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
 * @royaleignorecoercion HTMLLabelElement
 * @royaleignorecoercion HTMLInputElement
 * @royaleignorecoercion HTMLSpanElement
 * @royaleignorecoercion Text
 * @protected
 * @override
 */
org.apache.royale.jewel.RadioButton.prototype.createElement = function() {
  this.org_apache_royale_jewel_RadioButton_label = document.createElement('label');
  this.org_apache_royale_jewel_RadioButton_icon = org.apache.royale.html.util.addElementToWrapper(this, 'input');
  this.org_apache_royale_jewel_RadioButton_icon.type = 'radio';
  this.org_apache_royale_jewel_RadioButton_icon.id = '_radio_' + Math.random();
  this.org_apache_royale_jewel_RadioButton_icon.value = String(this.value);
  this.org_apache_royale_jewel_RadioButton_label.appendChild(this.org_apache_royale_jewel_RadioButton_icon);
  this.org_apache_royale_jewel_RadioButton_textNode = document.createTextNode('');
  this.org_apache_royale_jewel_RadioButton_radio = document.createElement('span');
  this.org_apache_royale_jewel_RadioButton_radio.appendChild(this.org_apache_royale_jewel_RadioButton_textNode);
  this.org_apache_royale_jewel_RadioButton_label.appendChild(this.org_apache_royale_jewel_RadioButton_radio);
  this.positioner = this.org_apache_royale_jewel_RadioButton_label;
  this.positioner.royale_wrapper = this;
  return this.element;
};


/**
 * @export
 * @override
 */
org.apache.royale.jewel.RadioButton.prototype.addEventListener = function(type, handler, opt_capture, opt_handlerScope) {
  opt_capture = typeof opt_capture !== 'undefined' ? opt_capture : false;
  opt_handlerScope = typeof opt_handlerScope !== 'undefined' ? opt_handlerScope : null;
  if (type == org.apache.royale.events.MouseEvent.CLICK) {
    this.org_apache_royale_jewel_RadioButton_icon.addEventListener(type, handler, opt_capture);
  } else {
    org.apache.royale.jewel.RadioButton.superClass_.addEventListener.apply(this, [ type, handler, opt_capture, opt_handlerScope] );
  }
};


/**
 * @export
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.RadioButton.prototype.clickHandler = function(event) {
  this.selected = !this.selected;
};


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


org.apache.royale.jewel.RadioButton.prototype.set__groupName = function(value) {
  this.org_apache_royale_jewel_RadioButton_icon.name = value;
};


org.apache.royale.jewel.RadioButton.prototype.get__text = function() {
  return this.org_apache_royale_jewel_RadioButton_textNode.nodeValue;
};


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


org.apache.royale.jewel.RadioButton.prototype.get__selected = function() {
  return this.org_apache_royale_jewel_RadioButton_icon.checked;
};


org.apache.royale.jewel.RadioButton.prototype.set__selected = function(value) {
  if (this.org_apache_royale_jewel_RadioButton_icon.checked == value)
    return;
  this.org_apache_royale_jewel_RadioButton_icon.checked = value;
  this.dispatchEvent(new org.apache.royale.events.Event(org.apache.royale.events.Event.CHANGE));
};


org.apache.royale.jewel.RadioButton.prototype.get__value = function() {
  return this.org_apache_royale_jewel_RadioButton_icon.value;
};


org.apache.royale.jewel.RadioButton.prototype.set__value = function(value) {
  this.org_apache_royale_jewel_RadioButton_icon.value = String(value);
};


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


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


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


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.RadioButton.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'groupName': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.RadioButton'},
        'text': { type: 'String', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.RadioButton'},
        'selected': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.RadioButton'},
        'value': { type: 'Object', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.RadioButton'},
        'selectedValue': { type: 'Object', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.RadioButton'}
      };
    },
    methods: function () {
      return {
        'RadioButton': { type: '', declaredBy: 'org.apache.royale.jewel.RadioButton'},
        'addEventListener': { type: 'void', declaredBy: 'org.apache.royale.jewel.RadioButton', parameters: function () { return [  { index: 1, type: 'String', optional: false },{ index: 2, type: 'Function', optional: false },{ index: 3, type: 'Boolean', optional: true },{ index: 4, type: 'Object', optional: true } ]; }},
        'clickHandler': { type: 'void', declaredBy: 'org.apache.royale.jewel.RadioButton', parameters: function () { return [  { index: 1, type: 'org.apache.royale.events.Event', optional: false } ]; }}
      };
    },
    metadata: function () { return [  ]; }
  };
};