import { CalendarPeriod } from './calendar-period.abstract';
import { CalendarDate } from '../calendar-date';
import { DateDirection, getClosestWorkday } from '../../../components/vega-calendar/utils';
/**
 * Period of day.
 */
export class DayPeriod extends CalendarPeriod {
  constructor(current, showWeekends, timezone) {
    super(DayPeriod.DISPLAY_DATE_COUNT, current, timezone);
    this._type = 'day';
    this._showWeekends = true;
    this._showWeekends = showWeekends === false ? false : true;
  }
  /**
   * @inheritDoc
   */
  next() {
    const nextDate = this.current.toDate();
    nextDate.setDate(nextDate.getDate() + 1);
    let calendarDate = CalendarDate.from(nextDate);
    if (this._showWeekends === false) {
      calendarDate = getClosestWorkday(calendarDate);
    }
    return this.createBy(calendarDate);
  }
  /**
   * @inheritDoc
   */
  previous() {
    const previousDate = this.current.toDate();
    previousDate.setDate(previousDate.getDate() - 1);
    let calendarDate = CalendarDate.from(previousDate);
    if (this._showWeekends === false) {
      calendarDate = getClosestWorkday(calendarDate, DateDirection.PREVIOUS);
    }
    return this.createBy(calendarDate);
  }
  /**
   * Go to now.
   *
   * @returns {this} - The current period.
   */
  now() {
    let calendarDate = CalendarDate.from(new Date(), this.timezone);
    if (this._showWeekends === false) {
      calendarDate = getClosestWorkday(calendarDate);
    }
    return this.createBy(calendarDate);
  }
  /**
   * @inheritDoc
   */
  createBy(current) {
    return new DayPeriod(current, this._showWeekends, this.timezone);
  }
}
DayPeriod.DISPLAY_DATE_COUNT = 1;
