import { VegaCalendarBaseEventLayout } from '../../../../common/layout/base-event-layout';
/** This TypeScript class, VegaCalendarDayViewTimedEventLayout, manages the layout of events in a day view calendar. */
export class VegaCalendarDayViewTimedEventLayout extends VegaCalendarBaseEventLayout {
  /**
   * The constructor function initializes the columns property with the provided array of VegaCalendarDayViewTimedEventLayoutColumn objects.
   *
   * @param {VegaCalendarDayViewTimedEventLayoutColumn[]} columns - An array of VegaCalendarDayViewTimedEventLayoutColumn objects.
   */
  constructor(columns) {
    super();
    this.cells = columns;
  }
  /**
   * The function `getEventColumnsSpannedCount` calculates the number of columns spanned by a given calendar event in a day view layout.
   *
   * @param {CalendarEvent} eventItem - The `getEventColumnsSpannedCount` function takes a `CalendarEvent` object as the `eventItem` parameter. This function calculates the number of columns spanned by the given event within the calendar view.
   * @returns {number} The function `getEventColumnsSpannedCount` returns the number of columns spanned by the given `eventItem` in the `VegaCalendarDayViewTimedEventLayoutColumn` array `columns`.
   */
  getEventColumnsSpannedCount(eventItem) {
    const eventColumnIndex = this.cells.findIndex((column) => {
      return column.getEventStartIndex(eventItem) >= 0;
    });
    let count = eventColumnIndex + 1;
    if (eventColumnIndex < this.cells.length - 1) {
      this.cells
        .slice(eventColumnIndex + 1)
        .forEach((column) => {
        if (column.hasOverlapEvent(eventItem)) {
          count++;
        }
      });
    }
    return count;
  }
}
