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

goog.provide('org.apache.royale.jewel.beads.views.SnackbarView');

goog.require('org.apache.royale.core.BeadViewBase');
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.jewel.Snackbar');
goog.require('org.apache.royale.jewel.beads.models.SnackbarModel');
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.BeadViewBase}
 */
org.apache.royale.jewel.beads.views.SnackbarView = function() {
  org.apache.royale.jewel.beads.views.SnackbarView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.views.SnackbarView, org.apache.royale.core.BeadViewBase);


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


/**
 * @protected
 * @type {org.apache.royale.jewel.Snackbar}
 */
org.apache.royale.jewel.beads.views.SnackbarView.prototype.host;


/**
 * @protected
 * @type {Element}
 */
org.apache.royale.jewel.beads.views.SnackbarView.prototype.actionElement;


/**
 * @private
 */
org.apache.royale.jewel.beads.views.SnackbarView.prototype.org_apache_royale_jewel_beads_views_SnackbarView_prepareForPopUp = function() {
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.UIBase, true).element.classList.add("open");
};


/**
 *  Update the text when message changed. 
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.SnackbarView.prototype.org_apache_royale_jewel_beads_views_SnackbarView_messageChangeHandler = function(event) {
  org.apache.royale.utils.Language.as(this.host.element.firstChild.firstChild, HTMLElement, true).innerHTML = org.apache.royale.utils.Language.as(this.host.model, org.apache.royale.jewel.beads.models.SnackbarModel, true).message;
};


/**
 *  Show the action element or remove it, based on action text.
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.SnackbarView.prototype.org_apache_royale_jewel_beads_views_SnackbarView_actionChangeHandler = function(event) {
  var /** @type {org.apache.royale.jewel.beads.models.SnackbarModel} */ model = org.apache.royale.utils.Language.as(this.host.model, org.apache.royale.jewel.beads.models.SnackbarModel);
  if (model.action) {
    if (!this.actionElement) {
      this.actionElement = document.createElement("div");
      this.actionElement.className = "jewel snackbar-action";
      this.actionElement.addEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_SnackbarView_actionClickHandler, this, 'actionClickHandler'));
      this.host.element.firstChild.appendChild(this.actionElement);
    }
    this.actionElement.innerText = model.action;
  } else {
    if (this.actionElement) {
      this.actionElement.removeEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_SnackbarView_actionClickHandler, this, 'actionClickHandler'));
      this.host.element.firstChild.removeChild(this.actionElement);
      this.actionElement = null;
    }
  }
};


/**
 *  Trigger event and dismiss the host when action clicked.
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.SnackbarView.prototype.org_apache_royale_jewel_beads_views_SnackbarView_actionClickHandler = function(event) {
  this.actionElement.removeEventListener("click", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_SnackbarView_actionClickHandler, this, 'actionClickHandler'));
  this.host.dispatchEvent(new org.apache.royale.events.Event(org.apache.royale.jewel.Snackbar.ACTION));
  org.apache.royale.utils.Language.as(this.host.model, org.apache.royale.jewel.beads.models.SnackbarModel, true).duration = -1;
};


org.apache.royale.jewel.beads.views.SnackbarView.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.views.SnackbarView.superClass_.set__strand.apply(this, [ value] );
  this.host = org.apache.royale.utils.Language.as(value, org.apache.royale.jewel.Snackbar);
  var /** @type {org.apache.royale.jewel.beads.models.SnackbarModel} */ model = org.apache.royale.utils.Language.as(this.host.model, org.apache.royale.jewel.beads.models.SnackbarModel);
  model.addEventListener("messageChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_SnackbarView_messageChangeHandler, this, 'messageChangeHandler'));
  model.addEventListener("actionChange", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_SnackbarView_actionChangeHandler, this, 'actionChangeHandler'));
  var /** @type {Element} */ messageElement = document.createElement("div");
  messageElement.className = "jewel snackbar-message";
  messageElement.innerHTML = model.message;
  var /** @type {Element} */ contentElement = document.createElement("div");
  contentElement.className = "jewel snackbar-content";
  contentElement.appendChild(messageElement);
  this.host.element.appendChild(contentElement);
  if (model.action)
    this.org_apache_royale_jewel_beads_views_SnackbarView_actionChangeHandler(null);
  setTimeout(org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_SnackbarView_prepareForPopUp, this, 'prepareForPopUp'), 300);
};


Object.defineProperties(org.apache.royale.jewel.beads.views.SnackbarView.prototype, /** @lends {org.apache.royale.jewel.beads.views.SnackbarView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.views.SnackbarView.prototype.set__strand}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.views.SnackbarView.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.jewel.beads.views.SnackbarView'}
      };
    },
    methods: function () {
      return {
        'SnackbarView': { type: '', declaredBy: 'org.apache.royale.jewel.beads.views.SnackbarView'}
      };
    }
  };
};