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

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

goog.require('org.apache.royale.core.BeadViewBase');
goog.require('org.apache.royale.core.IBeadModel');
goog.require('org.apache.royale.core.IDateChooserModel');
goog.require('org.apache.royale.core.IFormatBead');
goog.require('org.apache.royale.core.IPopUpHost');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.ValuesManager');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.geom.Point');
goog.require('org.apache.royale.html.TextButton');
goog.require('org.apache.royale.html.TextInput');
goog.require('org.apache.royale.html.supportClasses.IDateChooser');
goog.require('org.apache.royale.utils.PointUtils');
goog.require('org.apache.royale.utils.UIUtils');
goog.require('org.apache.royale.core.IBeadView');
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.core.BeadViewBase}
 * @implements {org.apache.royale.core.IBeadView}
 */
org.apache.royale.html.beads.DateFieldView = function() {
  org.apache.royale.html.beads.DateFieldView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.html.beads.DateFieldView, org.apache.royale.core.BeadViewBase);


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


/**
 * @private
 * @type {org.apache.royale.html.TextInput}
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView__textInput;


/**
 * @private
 * @type {org.apache.royale.html.TextButton}
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView__button;


/**
 * @royaleignorecoercion org.apache.royale.core.UIBase
 * @protected
 * @return {Object}
 */
org.apache.royale.html.beads.DateFieldView.prototype.getHost = function() {
  return this._strand;
};


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView_handleInitComplete = function(event) {
  var /** @type {org.apache.royale.core.IFormatBead} */ formatter = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IFormatBead), org.apache.royale.core.IFormatBead);
  formatter.addEventListener("formatChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_DateFieldView_handleFormatChanged, this, 'handleFormatChanged'));
  this.org_apache_royale_html_beads_DateFieldView__textInput.height = this.org_apache_royale_html_beads_DateFieldView__button.height;
  var /** @type {org.apache.royale.core.IBeadModel} */ model = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IBeadModel), org.apache.royale.core.IBeadModel);
  org.apache.royale.utils.Language.as(model, org.apache.royale.events.IEventDispatcher, true).addEventListener("selectedDateChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_DateFieldView_selectionChangeHandler, this, 'selectionChangeHandler'));
};


/**
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView_handleFormatChanged = function(event) {
  var /** @type {org.apache.royale.core.IFormatBead} */ formatter = org.apache.royale.utils.Language.as(event.target, org.apache.royale.core.IFormatBead);
  this.org_apache_royale_html_beads_DateFieldView__textInput.text = formatter.formattedString;
};


/**
 * @private
 * @type {org.apache.royale.html.supportClasses.IDateChooser}
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView__popUp;


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView__popUpVisible;


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView__showingPopup;


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.html.beads.DateFieldView.prototype.org_apache_royale_html_beads_DateFieldView_selectionChangeHandler = function(event) {
  this.getHost().dispatchEvent(new org.apache.royale.events.Event("selectedDateChanged"));
};


org.apache.royale.html.beads.DateFieldView.prototype.get__menuButton = function() {
  return this.org_apache_royale_html_beads_DateFieldView__button;
};


org.apache.royale.html.beads.DateFieldView.prototype.get__textInput = function() {
  return this.org_apache_royale_html_beads_DateFieldView__textInput;
};


org.apache.royale.html.beads.DateFieldView.prototype.set__strand = function(value) {
  org.apache.royale.html.beads.DateFieldView.superClass_.set__strand.apply(this, [ value] );
  this.org_apache_royale_html_beads_DateFieldView__textInput = new org.apache.royale.html.TextInput();
  this.getHost().addElement(this.org_apache_royale_html_beads_DateFieldView__textInput);
  this.org_apache_royale_html_beads_DateFieldView__textInput.width = 100;
  this.org_apache_royale_html_beads_DateFieldView__textInput.height = 18;
  this.org_apache_royale_html_beads_DateFieldView__button = new org.apache.royale.html.TextButton();
  this.org_apache_royale_html_beads_DateFieldView__button.text = "⬇︎";
  this.getHost().addElement(this.org_apache_royale_html_beads_DateFieldView__button);
  
  this.org_apache_royale_html_beads_DateFieldView__textInput.element.setAttribute('readonly', 'true');
  this.getHost().addEventListener("initComplete", org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_DateFieldView_handleInitComplete, this, 'handleInitComplete'));
};


org.apache.royale.html.beads.DateFieldView.prototype.get__popUp = function() {
  return this.org_apache_royale_html_beads_DateFieldView__popUp;
};


org.apache.royale.html.beads.DateFieldView.prototype.get__popUpVisible = function() {
  return this.org_apache_royale_html_beads_DateFieldView__popUpVisible;
};


org.apache.royale.html.beads.DateFieldView.prototype.set__popUpVisible = function(value) {
  if (this.org_apache_royale_html_beads_DateFieldView__showingPopup)
    return;
  if (value != this.org_apache_royale_html_beads_DateFieldView__popUpVisible) {
    this.org_apache_royale_html_beads_DateFieldView__showingPopup = true;
    this.org_apache_royale_html_beads_DateFieldView__popUpVisible = value;
    if (value) {
      if (!this.org_apache_royale_html_beads_DateFieldView__popUp) {
        this.org_apache_royale_html_beads_DateFieldView__popUp = org.apache.royale.utils.Language.as(org.apache.royale.core.ValuesManager["valuesImpl"].newInstance(this._strand, "iPopUp"), org.apache.royale.html.supportClasses.IDateChooser);
      }
      var /** @type {org.apache.royale.core.IDateChooserModel} */ model = org.apache.royale.utils.Language.as(this._strand.getBeadByType(org.apache.royale.core.IDateChooserModel), org.apache.royale.core.IDateChooserModel);
      this.org_apache_royale_html_beads_DateFieldView__popUp.selectedDate = model.selectedDate;
      var /** @type {org.apache.royale.core.IPopUpHost} */ host = org.apache.royale.utils.UIUtils.findPopUpHost(this.getHost());
      var /** @type {org.apache.royale.geom.Point} */ point = new org.apache.royale.geom.Point(this.org_apache_royale_html_beads_DateFieldView__textInput.width, this.org_apache_royale_html_beads_DateFieldView__button.height);
      var /** @type {org.apache.royale.geom.Point} */ p2 = org.apache.royale.utils.PointUtils.localToGlobal(point, this._strand);
      var /** @type {org.apache.royale.geom.Point} */ p3 = org.apache.royale.utils.PointUtils.globalToLocal(p2, host);
      this.org_apache_royale_html_beads_DateFieldView__popUp.x = p3.x;
      this.org_apache_royale_html_beads_DateFieldView__popUp.y = p3.y;
      this.org_apache_royale_html_beads_DateFieldView__popUp.element.style.position = "absolute";
      host.popUpParent.addElement(this.org_apache_royale_html_beads_DateFieldView__popUp);
    } else {
      org.apache.royale.utils.UIUtils.removePopUp(this.org_apache_royale_html_beads_DateFieldView__popUp);
    }
  }
  this.org_apache_royale_html_beads_DateFieldView__showingPopup = false;
};


Object.defineProperties(org.apache.royale.html.beads.DateFieldView.prototype, /** @lends {org.apache.royale.html.beads.DateFieldView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.html.TextButton} */
menuButton: {
get: org.apache.royale.html.beads.DateFieldView.prototype.get__menuButton},
/**
  * @export
  * @type {org.apache.royale.html.TextInput} */
textInput: {
get: org.apache.royale.html.beads.DateFieldView.prototype.get__textInput},
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.beads.DateFieldView.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.html.supportClasses.IDateChooser} */
popUp: {
get: org.apache.royale.html.beads.DateFieldView.prototype.get__popUp},
/**
  * @export
  * @type {boolean} */
popUpVisible: {
get: org.apache.royale.html.beads.DateFieldView.prototype.get__popUpVisible,
set: org.apache.royale.html.beads.DateFieldView.prototype.set__popUpVisible}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.DateFieldView.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'menuButton': { type: 'org.apache.royale.html.TextButton', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.DateFieldView'},
        'textInput': { type: 'org.apache.royale.html.TextInput', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.DateFieldView'},
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.html.beads.DateFieldView'},
        'popUp': { type: 'org.apache.royale.html.supportClasses.IDateChooser', access: 'readonly', declaredBy: 'org.apache.royale.html.beads.DateFieldView'},
        'popUpVisible': { type: 'Boolean', access: 'readwrite', declaredBy: 'org.apache.royale.html.beads.DateFieldView'}
      };
    },
    methods: function () {
      return {
        'DateFieldView': { type: '', declaredBy: 'org.apache.royale.html.beads.DateFieldView'}
      };
    }
  };
};