import { Directive, HostBinding, Input } from '@angular/core';
import { DateAdapter } from '@ui/common';
import { UiCalendarComponent } from '../ui-calendar.component';

@Directive({ selector: '[uiCalendarCell]' })
export class UiCalendarCellDirective {
  @Input('uiCalendarCell')
  date: Date;

  @HostBinding('class.today')
  get isToday() {
    return this.date && this.dateAdapter.equals({ first: this.date, second: this.calendar.today, precision: 'day' });
  }

  @HostBinding('class.selected')
  get isSelected() {
    return this.date && this.dateAdapter.equals({ first: this.date, second: this.calendar.selected, precision: 'day' });
  }

  @HostBinding('class.faded')
  get isFaded() {
    if (this.date && this.calendar.mode === 'month') {
      const firstDateOfMonth = this.dateAdapter.getFirstDateOfMonth(this.calendar.displayed);
      const lastDateOfMonth = this.dateAdapter.getLastDateOfMonth(this.calendar.displayed);
      return firstDateOfMonth > this.date || this.date > lastDateOfMonth || this.date.getDay() === 0;
    }
    return false;
  }

  constructor(public calendar: UiCalendarComponent, private dateAdapter: DateAdapter) {}
}
