import { TranslationWidth } from '@angular/common';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { RCalendarViewMode } from '../../model';
import { RCalendarYearModelService } from '../../services/calendar-year-model.service';
import { RDateService } from '../../services/date.service';
export class RCalendarViewModeComponent {
    constructor(dateService, yearModelService) {
        this.dateService = dateService;
        this.yearModelService = yearModelService;
        this.viewMode = RCalendarViewMode.DATE;
        this.changeMode = new EventEmitter(true);
    }
    getText() {
        if (!this.date) {
            return '';
        }
        switch (this.viewMode) {
            case RCalendarViewMode.DATE: {
                const month = this.dateService.getMonthName(this.date, TranslationWidth.Wide);
                const year = this.dateService.getYear(this.date);
                return `${month} ${year}`;
            }
            case RCalendarViewMode.MONTH:
                return `${this.dateService.getYear(this.date)}`;
            case RCalendarViewMode.YEAR:
                return `${this.getFirstYear()} - ${this.getLastYear()}`;
        }
    }
    getIcon() {
        if (this.viewMode === RCalendarViewMode.DATE) {
            return 'chevron-down-outline';
        }
        return 'chevron-up-outline';
    }
    getFirstYear() {
        const years = this.yearModelService.getViewYears(this.date);
        return this.dateService.getYear(years[0][0]).toString();
    }
    getLastYear() {
        const years = this.yearModelService.getViewYears(this.date);
        const lastRow = years[years.length - 1];
        const lastYear = lastRow[lastRow.length - 1];
        return this.dateService.getYear(lastYear).toString();
    }
}
RCalendarViewModeComponent.decorators = [
    { type: Component, args: [{
                selector: 'r-calendar-view-mode',
                template: `
    <button r-button (click)="changeMode.emit()" appearance="ghost" status="basic">
      {{ getText() }}
      <r-icon [icon]="getIcon()" pack="r-components-essentials"></r-icon>
    </button>
  `,
                changeDetection: ChangeDetectionStrategy.OnPush
            },] }
];
RCalendarViewModeComponent.ctorParameters = () => [
    { type: RDateService },
    { type: RCalendarYearModelService }
];
RCalendarViewModeComponent.propDecorators = {
    date: [{ type: Input }],
    viewMode: [{ type: Input }],
    changeMode: [{ type: Output }]
};
//# sourceMappingURL=calendar-view-mode.component.js.map