import { __decorate, __extends } from "tslib";
import { Component, Emit, Prop, Watch } from 'vue-property-decorator';
import { Enums } from '../../utils/enums/enums';
import uuid from '../../utils/uuid/uuid';
import { ModulVue } from '../../utils/vue/vue';
import { CALENDAR_NAME } from '../component-names';
import MBaseCalendar, { MBaseCalendarType, MBaseCalendarView } from './calendar-renderer/base-calendar/base-calendar';
import MCalendarStateMachine from './calendar-state/calendar-state-machine';
import WithRender from './calendar.html?style=./calendar.scss';
export var CalendarMode;
(function (CalendarMode) {
    CalendarMode["SINGLE_DATE"] = "single-date";
    CalendarMode["DATE_RANGE"] = "date-range";
})(CalendarMode || (CalendarMode = {}));
export var MCalendarType;
(function (MCalendarType) {
    MCalendarType["FullDate"] = "full-date";
    MCalendarType["YearsMonths"] = "years-months";
})(MCalendarType || (MCalendarType = {}));
var MCalendar = /** @class */ (function (_super) {
    __extends(MCalendar, _super);
    function MCalendar() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.innerValue = _this.value;
        _this.id = "m-calendar-" + uuid.generate();
        return _this;
    }
    MCalendar.prototype.refreshValue = function () {
        this.validateInputModel();
        this.innerValue = this.value;
    };
    MCalendar.prototype.created = function () {
        this.validateInputModel();
    };
    MCalendar.prototype.onInput = function () {
        return this.innerValue;
    };
    Object.defineProperty(MCalendar.prototype, "isSingleDate", {
        get: function () {
            return this.mode === CalendarMode.SINGLE_DATE;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MCalendar.prototype, "isDateRange", {
        get: function () {
            return this.mode === CalendarMode.DATE_RANGE;
        },
        enumerable: false,
        configurable: true
    });
    MCalendar.prototype.validateInputModel = function () {
        switch (this.mode) {
            case CalendarMode.SINGLE_DATE:
                if (typeof this.value !== 'string') {
                    throw new Error("In '" + CalendarMode.SINGLE_DATE + "' mode, the model type should be a 'string'");
                }
                break;
            case CalendarMode.DATE_RANGE:
                if (typeof this.value !== 'object') {
                    throw new Error("In '" + CalendarMode.DATE_RANGE + "' mode, the model type should be an 'object'");
                }
                break;
        }
    };
    __decorate([
        Prop({ default: '' })
    ], MCalendar.prototype, "value", void 0);
    __decorate([
        Prop({ default: CalendarMode.SINGLE_DATE })
    ], MCalendar.prototype, "mode", void 0);
    __decorate([
        Prop({
            default: MBaseCalendarType.FULL_DATE,
            validator: function (value) { return Enums.toValueArray(MBaseCalendarType).includes(value); }
        })
    ], MCalendar.prototype, "type", void 0);
    __decorate([
        Prop()
    ], MCalendar.prototype, "minDate", void 0);
    __decorate([
        Prop()
    ], MCalendar.prototype, "maxDate", void 0);
    __decorate([
        Prop({ default: true })
    ], MCalendar.prototype, "showMonthBeforeAfter", void 0);
    __decorate([
        Prop({ default: true })
    ], MCalendar.prototype, "visible", void 0);
    __decorate([
        Prop({
            default: MBaseCalendarView.DAYS,
            validator: function (value) { return Enums.toValueArray(MBaseCalendarView).includes(value); }
        })
    ], MCalendar.prototype, "initialView", void 0);
    __decorate([
        Watch('value')
    ], MCalendar.prototype, "refreshValue", null);
    __decorate([
        Emit('input')
    ], MCalendar.prototype, "onInput", null);
    MCalendar = __decorate([
        WithRender,
        Component({
            components: {
                MCalendarStateMachine: MCalendarStateMachine,
                MBaseCalendar: MBaseCalendar
            }
        })
    ], MCalendar);
    return MCalendar;
}(ModulVue));
export { MCalendar };
var CalendarPlugin = {
    install: function (v, options) {
        v.component(CALENDAR_NAME, MCalendar);
    }
};
export default CalendarPlugin;
//# sourceMappingURL=calendar.js.map