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

goog.provide('org.apache.royale.html.beads.AccordionCollapseBead');

goog.require('org.apache.royale.core.IItemRendererParent');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.html.Accordion');
goog.require('org.apache.royale.html.beads.IListView');
goog.require('org.apache.royale.html.beads.layouts.IOneFlexibleChildLayout');
goog.require('org.apache.royale.html.supportClasses.ICollapsible');
goog.require('org.apache.royale.utils.loadBeadFromValuesManager');
goog.require('org.apache.royale.html.beads.IAccordionCollapseBead');
goog.require('org.apache.royale.utils.Language');



/**
 * @constructor
 * @implements {org.apache.royale.html.beads.IAccordionCollapseBead}
 */
org.apache.royale.html.beads.AccordionCollapseBead = function() {
};


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


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.AccordionCollapseBead.prototype.org_apache_royale_html_beads_AccordionCollapseBead__strand;


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.AccordionCollapseBead.prototype.org_apache_royale_html_beads_AccordionCollapseBead_lastSelectedIndex = -1;


/**
 * @private
 * @type {org.apache.royale.html.beads.layouts.IOneFlexibleChildLayout}
 */
org.apache.royale.html.beads.AccordionCollapseBead.prototype.org_apache_royale_html_beads_AccordionCollapseBead__layout;


/**
 * @protected
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.AccordionCollapseBead.prototype.selectedIndexChangedHandler = function(event) {
  var /** @type {org.apache.royale.html.beads.IListView} */ view = org.apache.royale.utils.Language.as(this.host.view, org.apache.royale.html.beads.IListView);
  var /** @type {org.apache.royale.core.UIBase} */ newChild = org.apache.royale.utils.Language.as(view.dataGroup.getItemRendererAt(this.host.selectedIndex), org.apache.royale.core.UIBase);
  if (!newChild) {
    return;
  }
  var /** @type {org.apache.royale.html.supportClasses.ICollapsible} */ lastElement = org.apache.royale.utils.Language.as(view.dataGroup.getItemRendererForIndex(this.org_apache_royale_html_beads_AccordionCollapseBead_lastSelectedIndex), org.apache.royale.html.supportClasses.ICollapsible);
  if (lastElement)
    lastElement.collapse();
  this.org_apache_royale_html_beads_AccordionCollapseBead_lastSelectedIndex = this.host.selectedIndex;
  this.layout.flexibleChild = String(this.host.selectedIndex);
  org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_AccordionCollapseBead__strand, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(new org.apache.royale.events.Event("layoutNeeded"));
};


org.apache.royale.html.beads.AccordionCollapseBead.prototype.set__strand = function(value) {
  this.org_apache_royale_html_beads_AccordionCollapseBead__strand = value;
  this.host.model.addEventListener("selectedIndexChanged", org.apache.royale.utils.Language.closure(this.selectedIndexChangedHandler, this, 'selectedIndexChangedHandler'));
  var /** @type {number} */ idx = this.host.selectedIndex;
  if (idx < 0)
    idx = 0;
  var /** @type {org.apache.royale.core.IItemRendererParent} */ dg = org.apache.royale.utils.Language.as(org.apache.royale.utils.Language.as(this.host.view, org.apache.royale.html.beads.IListView, true).dataGroup, org.apache.royale.core.IItemRendererParent);
  var /** @type {number} */ numElems = dg.numItemRenderers;
  for (var /** @type {number} */ i = 0; i < numElems; i++) {
    if (i == idx)
      continue;
    var /** @type {org.apache.royale.html.supportClasses.ICollapsible} */ elem = org.apache.royale.utils.Language.as(dg.getItemRendererForIndex(i), org.apache.royale.html.supportClasses.ICollapsible);
    elem.collapse();
  }
};


org.apache.royale.html.beads.AccordionCollapseBead.prototype.get__host = function() {
  return org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_AccordionCollapseBead__strand, org.apache.royale.html.Accordion);
};


org.apache.royale.html.beads.AccordionCollapseBead.prototype.get__layout = function() {
  if (!this.org_apache_royale_html_beads_AccordionCollapseBead__layout) {
    this.org_apache_royale_html_beads_AccordionCollapseBead__layout = org.apache.royale.utils.Language.as(org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.html.beads.layouts.IOneFlexibleChildLayout, "iBeadLayout", this.org_apache_royale_html_beads_AccordionCollapseBead__strand), org.apache.royale.html.beads.layouts.IOneFlexibleChildLayout);
  }
  return this.org_apache_royale_html_beads_AccordionCollapseBead__layout;
};


Object.defineProperties(org.apache.royale.html.beads.AccordionCollapseBead.prototype, /** @lends {org.apache.royale.html.beads.AccordionCollapseBead.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.beads.AccordionCollapseBead.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.html.Accordion} */
host: {
get: org.apache.royale.html.beads.AccordionCollapseBead.prototype.get__host},
/**
  * @export
  * @type {org.apache.royale.html.beads.layouts.IOneFlexibleChildLayout} */
layout: {
get: org.apache.royale.html.beads.AccordionCollapseBead.prototype.get__layout}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.AccordionCollapseBead.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.html.beads.AccordionCollapseBead'}
      };
    },
    methods: function () {
      return {
        'AccordionCollapseBead': { type: '', declaredBy: 'org.apache.royale.html.beads.AccordionCollapseBead'}
      };
    }
  };
};