import { CalendarViewGenerator } from './calendar-view-generator.abstract';
import { CalendarDate } from '../calendar-date';
import { CalendarView } from '../calendar-view';
/**
 * Calendar month view generator
 */
export class MonthViewGenerator extends CalendarViewGenerator {
  /**
   * @inheritDoc
   */
  generate(period) {
    const showWeekends = period.showWeekends;
    let calendarDates = [];
    let week = [];
    const dates = this.generateDates(period);
    dates.forEach((date, i) => {
      if (!(i % 7)) {
        calendarDates[i / 7] = week = [];
      }
      const item = CalendarDate.from(date);
      week.push(item);
    });
    let weekDays = this.generateWeekHead();
    if (showWeekends === false) {
      weekDays = weekDays.slice(1, 6);
      calendarDates = calendarDates.map((items) => items.slice(1, 6));
    }
    return new CalendarView(weekDays, calendarDates);
  }
}
