import { Pipe, PipeTransform } from '@angular/core';
import { DateAdapter } from '../components/calendar/providers';

@Pipe({
  name: 'headerName',
})
export class HeaderNamePipe implements PipeTransform {
  days = {
    0: 'Sonntag',
    1: 'Montag',
    2: 'Dienstag',
    3: 'Mittwoch',
    4: 'Donnerstag',
    5: 'Freitag',
    6: 'Samstag',
  };

  constructor(private dateAdapter: DateAdapter) {}

  transform(value: Date): string {
    const today = new Date();
    let result: string;

    if (this.dateAdapter.equals(value, today)) {
      result = 'Heute';
    }

    if (this.dateAdapter.isGreaterThan(value, today)) {
      result = 'Überfällig';
    }

    if (this.dateAdapter.isLessThan(value, today)) {
      result = this.days[new Date(value).getDay()];
    }

    return result;
  }
}
