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 { Fragment, h } from '@stencil/core';
import { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { VegaCalendarEventItemRenderer } from '../../../common/renderers/vega-calendar-event-item-renderer';
/** renders all-day events in a calendar view, with options to display a limited number of events and show a "more" button for additional events. */
export class VegaCalendarFullDayEventRenderer extends VegaSlimmer {
  /**
   * render current preiod all day events
   *
   * @returns {HTMLElement} event element
   */
  render() {
    const viewSource = this.calendarView.dateItems[0];
    const events = viewSource.map((calendarDate) => {
      return this.calendarEventController
        .getCurrentDateEvents(calendarDate)
        .filter((eventItem) => eventItem.isAllDayEvent || eventItem.isGroupEvent());
    });
    const orderEvents = this.fullDayEventLayoutRenderer.sortLongEvents(events);
    const displayEvents = this.filterDisplayEvents(orderEvents);
    return (h("div", { class: "calendar-view-event-all" }, viewSource.map((item, index) => (h("div", { class: "event-all-col border-divider-left", key: item.date }, this.renderCurrentFullDayEvents(displayEvents[index], index, orderEvents[index], item))))));
  }
  /**
   * render current date all day events
   *
   * @param {Nullable<CalendarEvent>[]} events displayed calendar events
   * @param {number} currentViewIndex the current date index of the array
   * @param {Nullable<CalendarEvent>[]} allEvents all calendar events
   * @returns {HTMLVegaCalendarEventElement[]} event component array
   */
  renderCurrentFullDayEvents(events, currentViewIndex, allEvents, targetCalendarViewDate) {
    const height = events.length * VegaCalendarEventItemRenderer.backgroundColorModeEventHeight - 2;
    const hideEventsLength = allEvents.slice(events.length).filter(Boolean).length;
    return (h(Fragment, null,
      h("div", { class: "placeholder-block", style: { height: height + 'px' } },
        h("span", null,
          events.length,
          " events")),
      this.fullDayEventLayoutRenderer.render(events, currentViewIndex, targetCalendarViewDate),
      hideEventsLength > 0 && this.dayViewFullDayEventMoreButtonRenderer.render(hideEventsLength)));
  }
  /**
   * Get the display events base on the show all events flag
   *
   * @param {Nullable<CalendarEvent>[][]} rowEvents row events array
   * @returns {Nullable<CalendarEvent>[][]} the part of the events or the whole events
   */
  filterDisplayEvents(rowEvents) {
    if (!this.showAllEventsInDayOrWeekView) {
      const result = [];
      const maxLength = VegaCalendarFullDayEventRenderer.maxDisplayEventLength;
      rowEvents.forEach((events) => {
        const displayEvents = events.length > maxLength ? events.slice(0, maxLength) : events;
        result.push(displayEvents);
      });
      return result;
    }
    else {
      return rowEvents;
    }
  }
}
VegaCalendarFullDayEventRenderer.maxDisplayEventLength = 2;
__decorate([
  MapToComponentField()
], VegaCalendarFullDayEventRenderer.prototype, "calendarView", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarFullDayEventRenderer.prototype, "calendarEventController", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarFullDayEventRenderer.prototype, "eventItemRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarFullDayEventRenderer.prototype, "fullDayEventLayoutRenderer", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarFullDayEventRenderer.prototype, "showAllEventsInDayOrWeekView", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarFullDayEventRenderer.prototype, "dayViewFullDayEventMoreButtonRenderer", void 0);
