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

goog.provide('org.apache.royale.jewel.beads.models.DateChooserModel');

goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.events.Event');
goog.require('org.apache.royale.events.EventDispatcher');
goog.require('org.apache.royale.core.IDateChooserModel');
goog.require('org.apache.royale.utils.Language');



/**
 * @constructor
 * @extends {org.apache.royale.events.EventDispatcher}
 * @implements {org.apache.royale.core.IDateChooserModel}
 */
org.apache.royale.jewel.beads.models.DateChooserModel = function() {
  org.apache.royale.jewel.beads.models.DateChooserModel.base(this, 'constructor');

this.org_apache_royale_jewel_beads_models_DateChooserModel__dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
this.org_apache_royale_jewel_beads_models_DateChooserModel__monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
};
goog.inherits(org.apache.royale.jewel.beads.models.DateChooserModel, org.apache.royale.events.EventDispatcher);


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


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__strand;


/**
 * @private
 * @type {Array}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__dayNames;


/**
 * @private
 * @type {Array}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__monthNames;


/**
 * @private
 * @type {Array}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__days;


/**
 * @private
 * @type {number}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__displayedYear;


/**
 * @private
 * @type {number}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__displayedMonth;


/**
 * @private
 * @type {number}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__firstDayOfWeek = 0;


/**
 * @private
 * @type {Date}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel__selectedDate;


/**
 * @asprivate
 * @private
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel_updateCalendar = function() {
  var /** @type {Date} */ firstDay = new Date(this.displayedYear, this.displayedMonth, 1);
  this.org_apache_royale_jewel_beads_models_DateChooserModel__days = new Array(42);
  var /** @type {number} */ i = firstDay.getDay() - this.firstDayOfWeek;
  var /** @type {number} */ dayNumber = 1;
  var /** @type {number} */ numDays = this.org_apache_royale_jewel_beads_models_DateChooserModel_numberOfDaysInMonth(this.displayedMonth, this.displayedYear);
  while (dayNumber <= numDays) {
    this.org_apache_royale_jewel_beads_models_DateChooserModel__days[i++] = new Date(this.displayedYear, this.displayedMonth, dayNumber++);
  }
};


/**
 * @asprivate
 * @private
 * @param {number} month
 * @param {number} year
 * @return {number}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.org_apache_royale_jewel_beads_models_DateChooserModel_numberOfDaysInMonth = function(month, year) {
  var /** @type {number} */ n = 0;
  if (month == 1) {
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
      n = 29;
    else
      n = 28;
  }
  else if (month == 3 || month == 5 || month == 8 || month == 10)
    n = 30;
  else
    n = 31;
  return n;
};


/**
 * @asprivate
 * @export
 * @return {number}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.prototype.getIndexForSelectedDate = function() {
  if (!this.org_apache_royale_jewel_beads_models_DateChooserModel__selectedDate)
    return -1;
  var /** @type {string} */ str = this.org_apache_royale_jewel_beads_models_DateChooserModel__selectedDate.toDateString();
  for (var /** @type {number} */ i = 0; i < this.org_apache_royale_jewel_beads_models_DateChooserModel__days.length; i++) {
    var /** @type {Date} */ test = org.apache.royale.utils.Language.as(this.org_apache_royale_jewel_beads_models_DateChooserModel__days[i], Date);
    if (test && test.toDateString() == str) {
      return i;
    }
  }
  return -1;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__strand = function(value) {
  this.org_apache_royale_jewel_beads_models_DateChooserModel__strand = value;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__dayNames = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__dayNames;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__dayNames = function(value) {
  this.org_apache_royale_jewel_beads_models_DateChooserModel__dayNames = value;
  this.dispatchEvent(new org.apache.royale.events.Event("dayNamesChanged"));
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__monthNames = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__monthNames;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__monthNames = function(value) {
  this.org_apache_royale_jewel_beads_models_DateChooserModel__monthNames = value;
  this.dispatchEvent(new org.apache.royale.events.Event("monthNames"));
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__displayedYear = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedYear;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__displayedYear = function(value) {
  if (value != this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedYear) {
    this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedYear = value;
    this.org_apache_royale_jewel_beads_models_DateChooserModel_updateCalendar();
    this.dispatchEvent(new org.apache.royale.events.Event("displayedYearChanged"));
  }
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__displayedMonth = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedMonth;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__displayedMonth = function(value) {
  if (this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedMonth != value) {
    this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedMonth = value;
    this.org_apache_royale_jewel_beads_models_DateChooserModel_updateCalendar();
    this.dispatchEvent(new org.apache.royale.events.Event("displayedMonthChanged"));
  }
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__firstDayOfWeek = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__firstDayOfWeek;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__firstDayOfWeek = function(value) {
  if (value != this.org_apache_royale_jewel_beads_models_DateChooserModel__firstDayOfWeek) {
    this.org_apache_royale_jewel_beads_models_DateChooserModel__firstDayOfWeek = value;
    this.org_apache_royale_jewel_beads_models_DateChooserModel_updateCalendar();
    this.dispatchEvent(new org.apache.royale.events.Event("firstDayOfWeekChanged"));
  }
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__days = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__days;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__days = function(value) {
  if (value != this.org_apache_royale_jewel_beads_models_DateChooserModel__days) {
    this.org_apache_royale_jewel_beads_models_DateChooserModel__days = value;
    this.dispatchEvent(new org.apache.royale.events.Event("daysChanged"));
  }
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__selectedDate = function() {
  return this.org_apache_royale_jewel_beads_models_DateChooserModel__selectedDate;
};


org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__selectedDate = function(value) {
  if (value != this.org_apache_royale_jewel_beads_models_DateChooserModel__selectedDate) {
    this.org_apache_royale_jewel_beads_models_DateChooserModel__selectedDate = value;
    if (value != null) {
      var /** @type {boolean} */ needsUpdate = false;
      if (value.getMonth() != this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedMonth) {
        needsUpdate = true;
        this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedMonth = value.getMonth();
      }
      if (value.getFullYear() != this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedYear) {
        needsUpdate = true;
        this.org_apache_royale_jewel_beads_models_DateChooserModel__displayedYear = value.getFullYear();
      }
      if (needsUpdate)
        this.org_apache_royale_jewel_beads_models_DateChooserModel_updateCalendar();
    }
    this.dispatchEvent(new org.apache.royale.events.Event("selectedDateChanged"));
  }
};


Object.defineProperties(org.apache.royale.jewel.beads.models.DateChooserModel.prototype, /** @lends {org.apache.royale.jewel.beads.models.DateChooserModel.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__strand},
/**
  * @export
  * @type {Array} */
dayNames: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__dayNames,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__dayNames},
/**
  * @export
  * @type {Array} */
monthNames: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__monthNames,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__monthNames},
/**
  * @export
  * @type {number} */
displayedYear: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__displayedYear,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__displayedYear},
/**
  * @export
  * @type {number} */
displayedMonth: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__displayedMonth,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__displayedMonth},
/**
  * @export
  * @type {number} */
firstDayOfWeek: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__firstDayOfWeek,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__firstDayOfWeek},
/**
  * @export
  * @type {Array} */
days: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__days,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__days},
/**
  * @export
  * @type {Date} */
selectedDate: {
get: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.get__selectedDate,
set: org.apache.royale.jewel.beads.models.DateChooserModel.prototype.set__selectedDate}}
);


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



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.models.DateChooserModel.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.models.DateChooserModel'},
        'dayNames': { type: 'Array', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'monthNames': { type: 'Array', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'displayedYear': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'displayedMonth': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'firstDayOfWeek': { type: 'Number', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'days': { type: 'Array', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'selectedDate': { type: 'Date', access: 'readwrite', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'}
      };
    },
    methods: function () {
      return {
        'DateChooserModel': { type: '', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'},
        'getIndexForSelectedDate': { type: 'Number', declaredBy: 'org.apache.royale.jewel.beads.models.DateChooserModel'}
      };
    }
  };
};