import { __extends } from "tslib";
import ModulDate, { DatePrecision } from './../../../../utils/modul-date/modul-date';
import AbstractCalendarState from './abstract-calendar-state';
import { CalendarType } from './calendar-state';
var CalendarSingleDateState = /** @class */ (function (_super) {
    __extends(CalendarSingleDateState, _super);
    function CalendarSingleDateState() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    CalendarSingleDateState.prototype.updateState = function (value, minDate, maxDate) {
        this.initDates(value, minDate, maxDate);
    };
    CalendarSingleDateState.prototype.assembleValue = function () {
        return this.currentDate ? this.currentDate.toString() : '';
    };
    CalendarSingleDateState.prototype.selectYearMonth = function (year, month) {
        this.currentDate = new ModulDate(year.year, month.month, 1);
        this.emitUpdate(this.assembleValue());
        _super.prototype.selectYearMonth.call(this, year, month);
    };
    CalendarSingleDateState.prototype.selectDay = function (selectedDay) {
        _super.prototype.selectDay.call(this, selectedDay);
        if (!selectedDay.isDisabled) {
            var newDate = this.selectedDayToDate(selectedDay);
            this.currentDate = newDate;
            this.updateCurrentlyDisplayedDate(newDate.fullYear(), newDate.month(), newDate.day());
            this.emitUpdate(this.assembleValue());
        }
    };
    CalendarSingleDateState.prototype.initCurrentValue = function (value) {
        if (value) {
            this.currentDate = new ModulDate(value);
        }
        else {
            this.currentDate = undefined;
        }
    };
    CalendarSingleDateState.prototype.initCurrentlyDisplayedDate = function () {
        if (this.currentDate) {
            this.updateCurrentlyDisplayedDate(this.currentDate.fullYear(), this.currentDate.month(), this.currentDate.day());
        }
        else {
            this.updateCurrentlyDisplayedDate(this.now.fullYear(), this.now.month(), this.now.day());
        }
    };
    CalendarSingleDateState.prototype.isDaySelected = function (date) {
        return !!this.currentDate && date.isSame(this.currentDate, DatePrecision.DAY);
    };
    CalendarSingleDateState.prototype.isSelectionStart = function (date) {
        return this.isDaySelected(date);
    };
    CalendarSingleDateState.prototype.isSelectionEnd = function (date) {
        return this.isDaySelected(date);
    };
    CalendarSingleDateState.prototype.calendarType = function () {
        return CalendarType.SINGLE_DATE;
    };
    return CalendarSingleDateState;
}(AbstractCalendarState));
export default CalendarSingleDateState;
//# sourceMappingURL=calendar-single-date-state.js.map