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

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

goog.require('org.apache.royale.collections.ArrayList');
goog.require('org.apache.royale.core.ClassFactory');
goog.require('org.apache.royale.core.IBeadModel');
goog.require('org.apache.royale.core.IBeadView');
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.beads.GroupView');
goog.require('org.apache.royale.jewel.Button');
goog.require('org.apache.royale.jewel.beads.models.DateChooserModel');
goog.require('org.apache.royale.jewel.beads.views.TableView');
goog.require('org.apache.royale.jewel.itemRenderers.DateItemRenderer');
goog.require('org.apache.royale.jewel.supportClasses.datechooser.DateChooserTable');
goog.require('org.apache.royale.jewel.supportClasses.table.TableColumn');
goog.require('org.apache.royale.jewel.supportClasses.table.TableHeaderCell');
goog.require('org.apache.royale.jewel.supportClasses.table.TableRow');
goog.require('org.apache.royale.utils.loadBeadFromValuesManager');
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.html.beads.GroupView}
 * @implements {org.apache.royale.core.IBeadView}
 */
org.apache.royale.jewel.beads.views.DateChooserView = function() {
  org.apache.royale.jewel.beads.views.DateChooserView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.views.DateChooserView, org.apache.royale.html.beads.GroupView);


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


/**
 * @private
 * @type {org.apache.royale.jewel.beads.models.DateChooserModel}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_model;


/**
 * @royaleignorecoercion org.apache.royale.core.UIBase
 * @private
 * @return {Object}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_getHost = function() {
  return this._strand;
};


/**
 * @private
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView__monthLabel;


/**
 * @private
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView__prevMonthButton;


/**
 * @private
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView__nextMonthButton;


/**
 * @private
 * @type {org.apache.royale.jewel.supportClasses.datechooser.DateChooserTable}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView__daysTable;


/**
 * @asprivate
 * @private
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_createChildren = function() {
  this.org_apache_royale_jewel_beads_views_DateChooserView__monthLabel = new org.apache.royale.jewel.Button();
  this.org_apache_royale_jewel_beads_views_DateChooserView__monthLabel.className = "monthLabel";
  this.org_apache_royale_jewel_beads_views_DateChooserView__prevMonthButton = new org.apache.royale.jewel.Button();
  this.org_apache_royale_jewel_beads_views_DateChooserView__prevMonthButton.text = "<";
  this.org_apache_royale_jewel_beads_views_DateChooserView__prevMonthButton.className = "prevMonthButton";
  this.org_apache_royale_jewel_beads_views_DateChooserView__nextMonthButton = new org.apache.royale.jewel.Button();
  this.org_apache_royale_jewel_beads_views_DateChooserView__nextMonthButton.text = ">";
  this.org_apache_royale_jewel_beads_views_DateChooserView__nextMonthButton.className = "nextMonthButton";
  this.createColumns();
  this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable = new org.apache.royale.jewel.supportClasses.datechooser.DateChooserTable();
  
  this.org_apache_royale_jewel_beads_views_DateChooserView_getHost().addElement(this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable, false);
  org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(new org.apache.royale.events.Event("itemsCreated"));
  this.org_apache_royale_jewel_beads_views_DateChooserView_model.addEventListener("selectedDateChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_DateChooserView_selectionChangeHandler, this, 'selectionChangeHandler'));
  this.org_apache_royale_jewel_beads_views_DateChooserView_createButtonsRow();
};


/**
 * @private
 * @type {org.apache.royale.jewel.supportClasses.table.TableRow}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_buttonsRow;


/**
 * @private
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_createButtonsRow = function() {
  var /** @type {org.apache.royale.jewel.beads.views.TableView} */ view = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable.getBeadByType(org.apache.royale.core.IBeadView), org.apache.royale.jewel.beads.views.TableView);
  this.org_apache_royale_jewel_beads_views_DateChooserView_buttonsRow = new org.apache.royale.jewel.supportClasses.table.TableRow();
  var /** @type {org.apache.royale.jewel.supportClasses.table.TableHeaderCell} */ tableHeader = new org.apache.royale.jewel.supportClasses.table.TableHeaderCell();
  tableHeader.className = "buttonsRow";
  tableHeader.addElement(this.org_apache_royale_jewel_beads_views_DateChooserView__monthLabel);
  tableHeader.expandColumns = 5;
  this.org_apache_royale_jewel_beads_views_DateChooserView_buttonsRow.addElement(tableHeader);
  tableHeader = new org.apache.royale.jewel.supportClasses.table.TableHeaderCell();
  tableHeader.className = "buttonsRow";
  tableHeader.addElement(this.org_apache_royale_jewel_beads_views_DateChooserView__prevMonthButton);
  this.org_apache_royale_jewel_beads_views_DateChooserView_buttonsRow.addElement(tableHeader);
  tableHeader = new org.apache.royale.jewel.supportClasses.table.TableHeaderCell();
  tableHeader.className = "buttonsRow";
  tableHeader.addElement(this.org_apache_royale_jewel_beads_views_DateChooserView__nextMonthButton);
  this.org_apache_royale_jewel_beads_views_DateChooserView_buttonsRow.addElement(tableHeader);
};


/**
 * @private
 * @type {Array}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_columns;


/**
 * @private
 * @type {boolean}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_dayNamesInit;


/**
 * @export
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.createColumns = function() {
  if (!this.org_apache_royale_jewel_beads_views_DateChooserView_dayNamesInit) {
    this.org_apache_royale_jewel_beads_views_DateChooserView_columns = [];
    var /** @type {org.apache.royale.core.ClassFactory} */ dateItemRenderer = new org.apache.royale.core.ClassFactory(org.apache.royale.jewel.itemRenderers.DateItemRenderer);
    for (var /** @type {number} */ i = 0; i < 7; i++) {
      var /** @type {org.apache.royale.jewel.supportClasses.table.TableColumn} */ column = new org.apache.royale.jewel.supportClasses.table.TableColumn();
      column.dataField = "d" + i;
      column.align = "center";
      column.itemRenderer = dateItemRenderer;
      this.org_apache_royale_jewel_beads_views_DateChooserView_columns.push(column);
    }
    this.org_apache_royale_jewel_beads_views_DateChooserView_dayNamesInit = true;
  }
};


/**
 * @private
 * @param {Array} array
 * @param {number} index
 * @param {number} n
 * @return {number}
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_cycleArray = function(array, index, n) {
  return ((index + n) % array.length + array.length) % array.length;
};


/**
 * @asprivate
 * @private
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_updateDisplay = function() {
  this.org_apache_royale_jewel_beads_views_DateChooserView__monthLabel.text = this.org_apache_royale_jewel_beads_views_DateChooserView_model.monthNames[this.org_apache_royale_jewel_beads_views_DateChooserView_model.displayedMonth] + " " + String(this.org_apache_royale_jewel_beads_views_DateChooserView_model.displayedYear);
  var /** @type {number} */ len = this.org_apache_royale_jewel_beads_views_DateChooserView_columns.length;
  for (var /** @type {number} */ index = 0; index < len; index++) {
    var /** @type {org.apache.royale.jewel.supportClasses.table.TableColumn} */ column = this.org_apache_royale_jewel_beads_views_DateChooserView_columns[index];
    column.columnLabelAlign = "center";
    column.label = org.apache.royale.utils.Language.string(this.org_apache_royale_jewel_beads_views_DateChooserView_model.dayNames[this.org_apache_royale_jewel_beads_views_DateChooserView_cycleArray(this.org_apache_royale_jewel_beads_views_DateChooserView_model.dayNames, index, this.org_apache_royale_jewel_beads_views_DateChooserView_model.firstDayOfWeek)]);
  }
  this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable.columns = this.org_apache_royale_jewel_beads_views_DateChooserView_columns;
  var /** @type {Array} */ currrentMonth = [];
  var /** @type {number} */ dayIndex = 0;
  for (var /** @type {number} */ i = 0; i < this.org_apache_royale_jewel_beads_views_DateChooserView_model.days.length / 7; i++) {
    currrentMonth[i] = {};
    for (var /** @type {number} */ j = 0; j < this.org_apache_royale_jewel_beads_views_DateChooserView_columns.length; j++) {
      currrentMonth[i]["d" + j] = this.org_apache_royale_jewel_beads_views_DateChooserView_model.days[dayIndex];
      dayIndex++;
    }
  }
  this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable.dataProvider = new org.apache.royale.collections.ArrayList(currrentMonth);
  var /** @type {org.apache.royale.jewel.beads.views.TableView} */ view = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable.getBeadByType(org.apache.royale.core.IBeadView), org.apache.royale.jewel.beads.views.TableView);
  view.thead.addElementAt(this.org_apache_royale_jewel_beads_views_DateChooserView_buttonsRow, 0, false);
  this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable.selectedIndex = this.org_apache_royale_jewel_beads_views_DateChooserView_model.getIndexForSelectedDate();
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_selectionChangeHandler = function(event) {
  this.org_apache_royale_jewel_beads_views_DateChooserView_updateDisplay();
  this.org_apache_royale_jewel_beads_views_DateChooserView_getHost().dispatchEvent(new org.apache.royale.events.Event("selectedDateChanged"));
  this.org_apache_royale_jewel_beads_views_DateChooserView_getHost().dispatchEvent(new org.apache.royale.events.Event(org.apache.royale.events.Event.CHANGE));
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.Event} event
 */
org.apache.royale.jewel.beads.views.DateChooserView.prototype.org_apache_royale_jewel_beads_views_DateChooserView_handleModelChange = function(event) {
  this.org_apache_royale_jewel_beads_views_DateChooserView_updateDisplay();
};


org.apache.royale.jewel.beads.views.DateChooserView.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.views.DateChooserView.superClass_.set__strand.apply(this, [ value] );
  this.org_apache_royale_jewel_beads_views_DateChooserView_model = org.apache.royale.utils.Language.as(org.apache.royale.utils.loadBeadFromValuesManager(org.apache.royale.core.IBeadModel, "iBeadModel", this._strand), org.apache.royale.jewel.beads.models.DateChooserModel);
  this.org_apache_royale_jewel_beads_views_DateChooserView_model.addEventListener("firstDayOfWeekChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_DateChooserView_handleModelChange, this, 'handleModelChange'));
  this.org_apache_royale_jewel_beads_views_DateChooserView_model.addEventListener("dayNamesChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_DateChooserView_handleModelChange, this, 'handleModelChange'));
  this.org_apache_royale_jewel_beads_views_DateChooserView_model.addEventListener("displayedMonthChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_DateChooserView_handleModelChange, this, 'handleModelChange'));
  this.org_apache_royale_jewel_beads_views_DateChooserView_model.addEventListener("displayedYearChanged", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_DateChooserView_handleModelChange, this, 'handleModelChange'));
  this.org_apache_royale_jewel_beads_views_DateChooserView_createChildren();
  this.org_apache_royale_jewel_beads_views_DateChooserView_updateDisplay();
};


org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__monthLabel = function() {
  return this.org_apache_royale_jewel_beads_views_DateChooserView__monthLabel;
};


org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__prevMonthButton = function() {
  return this.org_apache_royale_jewel_beads_views_DateChooserView__prevMonthButton;
};


org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__nextMonthButton = function() {
  return this.org_apache_royale_jewel_beads_views_DateChooserView__nextMonthButton;
};


org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__daysTable = function() {
  return this.org_apache_royale_jewel_beads_views_DateChooserView__daysTable;
};


Object.defineProperties(org.apache.royale.jewel.beads.views.DateChooserView.prototype, /** @lends {org.apache.royale.jewel.beads.views.DateChooserView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.views.DateChooserView.prototype.set__strand},
/**
  * @export
  * @type {org.apache.royale.jewel.Button} */
monthLabel: {
get: org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__monthLabel},
/**
  * @export
  * @type {org.apache.royale.jewel.Button} */
prevMonthButton: {
get: org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__prevMonthButton},
/**
  * @export
  * @type {org.apache.royale.jewel.Button} */
nextMonthButton: {
get: org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__nextMonthButton},
/**
  * @export
  * @type {org.apache.royale.jewel.supportClasses.datechooser.DateChooserTable} */
daysTable: {
get: org.apache.royale.jewel.beads.views.DateChooserView.prototype.get__daysTable}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.views.DateChooserView.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.DateChooserView'},
        'monthLabel': { type: 'org.apache.royale.jewel.Button', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.DateChooserView'},
        'prevMonthButton': { type: 'org.apache.royale.jewel.Button', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.DateChooserView'},
        'nextMonthButton': { type: 'org.apache.royale.jewel.Button', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.DateChooserView'},
        'daysTable': { type: 'org.apache.royale.jewel.supportClasses.datechooser.DateChooserTable', access: 'readonly', declaredBy: 'org.apache.royale.jewel.beads.views.DateChooserView'}
      };
    },
    methods: function () {
      return {
        'DateChooserView': { type: '', declaredBy: 'org.apache.royale.jewel.beads.views.DateChooserView'},
        'createColumns': { type: 'void', declaredBy: 'org.apache.royale.jewel.beads.views.DateChooserView'}
      };
    }
  };
};