import { Component, EventEmitter, HostBinding, Input, Output, Type } from '@angular/core';
import { RCalendarYearModelService } from '../calendar-kit/services/calendar-year-model.service';
import { RCalendarSize, RCalendarViewMode, } from '../calendar-kit/model';
import { RDateService } from '../calendar-kit';
/**
 * The basis for calendar and range calendar components.
 * Encapsulates common behavior - store calendar state and perform navigation
 * between pickers.
 * */
export class RBaseCalendarComponent {
    constructor(dateService, yearModelService) {
        this.dateService = dateService;
        this.yearModelService = yearModelService;
        /**
         * Defines if we should render previous and next months
         * in the current month view.
         * */
        this.boundingMonth = true;
        /**
         * Defines active view for calendar.
         * */
        this.activeViewMode = RCalendarViewMode.DATE;
        /**
         * Size of the calendar and entire components.
         * Can be 'medium' which is default or 'large'.
         * */
        this.size = RCalendarSize.MEDIUM;
        /**
         * Determines whether we should show calendar navigation or not.
         * */
        this.showNavigation = true;
        this._showWeekNumber = false;
        /**
         * Emits date when selected.
         * */
        this.dateChange = new EventEmitter();
        this.ViewMode = RCalendarViewMode;
    }
    /**
     * Determines should we show week numbers column.
     * False by default.
     * */
    get showWeekNumber() {
        return this._showWeekNumber;
    }
    set showWeekNumber(value) {
        this._showWeekNumber = !!value;
    }
    ngOnInit() {
        if (!this.visibleDate) {
            this.visibleDate = this.dateService.today();
        }
    }
    get large() {
        return this.size === RCalendarSize.LARGE;
    }
    setViewMode(viewMode) {
        this.activeViewMode = viewMode;
    }
    setVisibleDate(visibleDate) {
        this.visibleDate = visibleDate;
    }
    prevMonth() {
        this.changeVisibleMonth(-1);
    }
    nextMonth() {
        this.changeVisibleMonth(1);
    }
    prevYear() {
        this.changeVisibleYear(-1);
    }
    nextYear() {
        this.changeVisibleYear(1);
    }
    prevYears() {
        this.changeVisibleYears(-1);
    }
    nextYears() {
        this.changeVisibleYears(1);
    }
    navigatePrev() {
        switch (this.activeViewMode) {
            case RCalendarViewMode.DATE:
                return this.prevMonth();
            case RCalendarViewMode.MONTH:
                return this.prevYear();
            case RCalendarViewMode.YEAR:
                return this.prevYears();
        }
    }
    navigateNext() {
        switch (this.activeViewMode) {
            case RCalendarViewMode.DATE:
                return this.nextMonth();
            case RCalendarViewMode.MONTH:
                return this.nextYear();
            case RCalendarViewMode.YEAR:
                return this.nextYears();
        }
    }
    onChangeViewMode() {
        if (this.activeViewMode === RCalendarViewMode.DATE) {
            return this.setViewMode(RCalendarViewMode.YEAR);
        }
        this.setViewMode(RCalendarViewMode.DATE);
    }
    changeVisibleMonth(direction) {
        this.visibleDate = this.dateService.addMonth(this.visibleDate, direction);
    }
    changeVisibleYear(direction) {
        this.visibleDate = this.dateService.addYear(this.visibleDate, direction);
    }
    changeVisibleYears(direction) {
        this.visibleDate = this.dateService.addYear(this.visibleDate, direction * this.yearModelService.getYearsInView());
    }
}
RBaseCalendarComponent.decorators = [
    { type: Component, args: [{
                selector: 'r-base-calendar',
                template: "<r-card>\r\n  <r-card-header *ngIf=\"showNavigation\" class=\"calendar-navigation\">\r\n    <r-calendar-view-mode [date]=\"visibleDate\" [viewMode]=\"activeViewMode\" (changeMode)=\"onChangeViewMode()\">\r\n    </r-calendar-view-mode>\r\n\r\n    <r-calendar-pageable-navigation (prev)=\"navigatePrev()\" (next)=\"navigateNext()\">\r\n    </r-calendar-pageable-navigation>\r\n  </r-card-header>\r\n\r\n  <r-card-body [ngSwitch]=\"activeViewMode\">\r\n    <r-calendar-day-picker *ngSwitchCase=\"ViewMode.DATE\" [boundingMonths]=\"boundingMonth\"\r\n      [cellComponent]=\"dayCellComponent\" [min]=\"min\" [max]=\"max\" [filter]=\"filter\" [visibleDate]=\"visibleDate\"\r\n      [size]=\"size\" [date]=\"date\" [showWeekNumber]=\"showWeekNumber\" (dateChange)=\"dateChange.emit($any($event))\"\r\n      [weekNumberSymbol]=\"weekNumberSymbol\">\r\n    </r-calendar-day-picker>\r\n\r\n    <r-calendar-year-picker *ngSwitchCase=\"ViewMode.YEAR\" [cellComponent]=\"yearCellComponent\" [date]=\"$any(date)\"\r\n      [min]=\"min\" [max]=\"max\" [filter]=\"filter\" [size]=\"size\" [year]=\"visibleDate\"\r\n      (yearChange)=\"setVisibleDate($event); setViewMode(ViewMode.MONTH)\">\r\n    </r-calendar-year-picker>\r\n\r\n    <r-calendar-month-picker *ngSwitchCase=\"ViewMode.MONTH\" [cellComponent]=\"monthCellComponent\" [min]=\"min\" [max]=\"max\"\r\n      [filter]=\"filter\" [size]=\"size\" [month]=\"visibleDate\" [date]=\"$any(date)\"\r\n      (monthChange)=\"setVisibleDate($event); setViewMode(ViewMode.DATE)\">\r\n    </r-calendar-month-picker>\r\n\r\n  </r-card-body>\r\n\r\n</r-card>"
            },] }
];
RBaseCalendarComponent.ctorParameters = () => [
    { type: RDateService },
    { type: RCalendarYearModelService }
];
RBaseCalendarComponent.propDecorators = {
    boundingMonth: [{ type: Input }],
    activeViewMode: [{ type: Input, args: ['startView',] }],
    min: [{ type: Input }],
    max: [{ type: Input }],
    filter: [{ type: Input }],
    dayCellComponent: [{ type: Input }],
    monthCellComponent: [{ type: Input }],
    yearCellComponent: [{ type: Input }],
    size: [{ type: Input }],
    visibleDate: [{ type: Input }],
    showNavigation: [{ type: Input }, { type: HostBinding, args: ['class.has-navigation',] }],
    date: [{ type: Input }],
    showWeekNumber: [{ type: Input }, { type: HostBinding, args: ['class.has-week-number',] }],
    weekNumberSymbol: [{ type: Input }],
    dateChange: [{ type: Output }],
    large: [{ type: HostBinding, args: ['class.size-large',] }]
};
//# sourceMappingURL=base-calendar.component.js.map