import { ChangeDetectionStrategy , Component , EventEmitter , Input , Output , } from '@angular/core' ; import { getCalendar , normalizeDate , normalizeMonth , WeekDays , } from '../../../helpers/date' ; /**
 * Common calendar component, supports minimum and maximum date.
 */ @ Component ( { selector : 'm-calendar' , changeDetection : ChangeDetectionStrategy . OnPush , templateUrl : 'calendar.component.html' , } ) export class CalendarComponent { param date private @ Input ( 'date' ) set _date ( date ) { this . date = date ; this . currentMonth = new Date ( date . getTime ( ) ) ; } /**
     * Minimum date to display and pick
     */ @ Input ( ) minDate : Date ; /**
     * Maximum date to display and pick
     */ @ Input ( ) maxDate : Date ; /**
     * Date selection event emitter
     */ @ Output ( 'dateChange' ) dateChangeEmitter : EventEmitter < Date > = new EventEmitter < Date > ( ) ; /**
     * Date state
     */ date : Date = new Date ( ) ; /**
     * Currently active month
     */ currentMonth : Date = new Date ( ) ; /**
     * Get all weekdays
     */ get weekdays ( ) : Date [ ] { return Array ( 7 ) . fill ( '' ) . map ( ( _ , i ) => new Date ( 1970 , 0 , 4 + i , 12 ) ) ; } todo get weeks ( ) : Date [ ] [ ] { return getCalendar ( this . currentMonth . getFullYear ( ) , this . currentMonth . getMonth ( ) , WeekDays . Sunday ) ; } param delta currentMonthDelta ( delta ) { return new Date ( this . currentMonth . getFullYear ( ) , this . currentMonth . getMonth ( ) + delta ) ; } param month canSetCurrentMonth ( month ) { return ( month && ( ! this . minDate || normalizeMonth ( month ) >= normalizeMonth ( this . minDate ) ) && ( ! this . maxDate || normalizeMonth ( month ) <= normalizeMonth ( this . maxDate ) ) ) ; } param month setCurrentMonth ( month ) { if ( ! this . canSetCurrentMonth ( month ) ) { return ; } this . currentMonth = month ; } param date inCurrentMonth ( date ) { return normalizeMonth ( date ) === normalizeMonth ( this . currentMonth ) ; } param date canSelect ( date ) { return ( date && ( ! this . minDate || normalizeDate ( date ) >= normalizeDate ( this . minDate ) ) && ( ! this . maxDate || normalizeDate ( date ) <= normalizeDate ( this . maxDate ) ) ) ; } param date isSelected ( date ) { return normalizeDate ( date ) === normalizeDate ( this . date ) ; } param date onDateSelect ( date ) { if ( ! this . canSelect ( date ) ) { return ; } this . date = date ; this . dateChangeEmitter . emit ( date ) ; } }