var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
/** The `VegaCalendarDayViewEventLayoutRenderer` class in TypeScript React renders event layouts for a day view calendar. */
export class VegaCalendarDayViewEventLayoutRenderer extends VegaSlimmer {
  /**
   * The `render` function in TypeScript React renders a layout of calendar events for a day view.
   *
   * @param {VegaCalendarDayViewTimedEventLayout} layout - The `layout` parameter in the `render` function is
   * of type `VegaCalendarDayViewTimedEventLayout`, which contains information about the layout of events for
   * a day view in a calendar. It has properties like `eventLayoutColumns`, which is an array of `VegaCalendarDayViewEvent
   * @returns {HTMLElement[]} An array of HTMLElements representing the rendered event nodes based on the provided layout and event data.
   */
  render(layout, targetCalendarViewDate) {
    const layoutColumns = layout.eventLayoutCells;
    const eventNodes = [];
    layoutColumns.forEach((columns, index) => {
      let renderEvent = columns.getEventBySlotIndex(0);
      let start = 0;
      for (let i = 0; i <= VegaCalendarDayViewEventLayoutRenderer.TOTAL_NUMBER_OF_CELLS; i++) {
        const currentEvent = columns.getEventBySlotIndex(i);
        if (currentEvent !== renderEvent) {
          if (renderEvent) {
            eventNodes.push(h("div", { key: index, class: "time-event-block", style: this.getTimeEventStyle(start, i, index, layout.getEventColumnsSpannedCount(renderEvent)) }, this.eventPreviewPopoverRenderer.render(renderEvent, targetCalendarViewDate, {
              'day-event': true,
              'bg-shadow': index > 0,
            })));
          }
          renderEvent = currentEvent;
          start = i;
        }
      }
    });
    return eventNodes;
  }
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-calendar-render-timed-event-correct}
   */
  /* istanbul ignore next */
  /**
   * This function calculates and returns the style properties for positioning and sizing a calendar event within a grid layout.
   *
   * @param {number} startIndex - The `startIndex` parameter represents the index of the starting cell for the time event in the calendar grid.
   * @param {number} endIndex - The `endIndex` parameter represents the index of the end position of the time event within a column. It indicates where the time event ends vertically within the column layout.
   * @param {number} columnIndex - The `columnIndex` parameter represents the index of the column in which the event is being displayed. It is used to calculate the `left` position of the event element within the container based on the total number of columns spanned by the event.
   * @param {number} columnsSpannedCount - The `columnsSpannedCount` parameter represents the number of columns spanned by the event in a calendar layout. It is used to calculate the left position of the event within the calendar grid.
   * @returns {VegaCalendarEventStyle} The function `getTimeEventStyle` returns an object of type `VegaCalendarEventStyle` with properties for position, left, top, width, height, and zIndex.
   */
  getTimeEventStyle(startIndex, endIndex, columnIndex, columnsSpannedCount) {
    const left = columnIndex * (1 / columnsSpannedCount);
    return {
      position: 'absolute',
      left: `${left * 100}%`,
      top: `${(100 / VegaCalendarDayViewEventLayoutRenderer.TOTAL_NUMBER_OF_CELLS) * startIndex}%`,
      width: `calc(100% - ${left * 100}%)`,
      height: `${(100 / VegaCalendarDayViewEventLayoutRenderer.TOTAL_NUMBER_OF_CELLS) * (endIndex - startIndex)}%`,
      zIndex: columnIndex > 0 ? `${columnIndex}` : undefined,
    };
  }
}
VegaCalendarDayViewEventLayoutRenderer.TOTAL_NUMBER_OF_CELLS = 24 * 4;
__decorate([
  MapToComponentField()
], VegaCalendarDayViewEventLayoutRenderer.prototype, "eventItemRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarDayViewEventLayoutRenderer.prototype, "eventPreviewPopoverRenderer", void 0);
