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 clockThree from '../../../icons/clock-three';
import { VegaInternalIconManager } from '../../../../../helpers/icon/internal-icon-manager';
import { getEventStatusBgColorStyle } from '../../../utils';
import { vegaNonceManager } from '../../../../../helpers/csp/vega-nonce-manager';
/** The `VegaCalendarEventRenderer` class is a TypeScript React component used for rendering calendar events with different display modes and custom styling. */
export class VegaCalendarEventRenderer extends VegaSlimmer {
  /*
   * The below method is e2e-test covered in
   * @see{module:vega-calendar-event-title-max-height-e2e}
   */
  /* istanbul ignore next */
  /**
   * This function returns the event title container as a nullable HTMLDivElement.
   *
   * @returns {Nullable<HTMLDivElement>} The method `getEventTitleContainer` is returning a nullable HTMLDivElement.
   */
  getEventTitleContainerRef() {
    return this.eventTitleContainerRef;
  }
  /**
   * Get the calendar event slot container element
   *
   * @returns {Nullable<HTMLDivElement>} a div element
   */
  getSlotContainerRef() {
    return this.slotContainerRef;
  }
  /**
   * The function conditionally renders either a group event or a normal event based on a boolean flag.
   *
   * @returns {HTMLElement} the event element
   */
  render() {
    return (h(Fragment, null,
      this.injectBackgroundColorStyle(),
      this.calendarEventRender()));
  }
  /**
   * The vega calendar event default render
   *
   * @returns {HTMLElement} calendar event element
   */
  calendarEventRender() {
    return this.calendarEvent.isAllDayEvent || this.calendarEvent.isGroupEvent()
      ? this.renderBackgroundModeEvent()
      : this.renderNormalEvent();
  }
  /**
   * render background mode event element
   *
   * @returns {HTMLDivElement} div element
   */
  renderBackgroundModeEvent() {
    const disabled = this.calendarEvent.disabled;
    return (h("div", { class: {
        'slot-container': this.slotMode,
        'background-color-mode': true,
        'event-bg-color': !disabled,
        'bg-disabled': disabled,
      }, ref: (node) => (this.slotContainerRef = node) }, this.slotMode ? this.getSlotElement() : this.calendarEvent.title));
  }
  /**
   * render event element
   *
   * @returns {HTMLAnchorElement} event element
   */
  renderNormalEvent() {
    const { variant, disabled } = this.calendarEvent;
    const variantText = variant || 'primary';
    const isMonthEvent = !this.host.classList.contains('day-event');
    const classMap = {
      'slot-container': this.slotMode,
      'event-container': true,
      'disabled': disabled,
      [variantText]: true,
    };
    if (isMonthEvent) {
      return (h("div", { class: classMap, ref: (node) => (this.slotContainerRef = node) },
        !this.slotMode && this.renderEventStatus(),
        this.slotMode ? this.getSlotElement() : this.defaultNormalMonthEventContentRender()));
    }
    else {
      const eventDuration = this.calendarEvent.getEventMinutes();
      return (h("div", { part: "event-container", class: Object.assign(Object.assign({}, classMap), { 'vertical': eventDuration > 30, 'duration-half-an-hour': eventDuration === 30, 'event-bg-color': !disabled, 'bg-disabled': disabled }), ref: (node) => (this.slotContainerRef = node) },
        !this.slotMode && this.renderEventStatus(),
        h("div", { class: "cover-block" }),
        this.slotMode
          ? this.getSlotElement()
          : this.defaultNormalTimedEventContentRender(eventDuration)));
    }
  }
  /**
   * render event status element, a color badge or a color bar element
   *
   * @returns {Nullable<HTMLDivElement>} div element
   */
  renderEventStatus() {
    if (this.showColorBar) {
      const disabled = this.calendarEvent.disabled;
      return (h("div", { class: {
          'event-status': true,
          'event-bg-color': !disabled,
          'bg-disabled': disabled,
        } },
        h("span", { class: {
            stripe: this.calendarEvent.variant === 'secondary',
          } })));
    }
  }
  /**
   * Render the month view timed event.
   *
   * @returns {HTMLElement} a div element
   */
  defaultNormalMonthEventContentRender() {
    const { startTime, title } = this.calendarEvent;
    return h("div", { class: "event-title" }, `${startTime.toString(this.timeFormat)} ${title}`);
  }
  /**
   * Render the day view timed event.
   *
   * @param {number} eventDuration the event duration
   * @returns {HTMLElement} a div element
   */
  defaultNormalTimedEventContentRender(eventDuration) {
    const { startTime, endTime, title } = this.calendarEvent;
    return (h("div", { class: "event-content" },
      h("div", { class: {
          'event-title': true,
          'title-word-wrap': eventDuration > 30,
        }, ref: (node) => (this.eventTitleContainerRef = node) }, title),
      h("div", { class: "event-time" },
        h("vega-icon", { size: "size-12", "aria-hidden": "true", icon: VegaInternalIconManager.getIconKey('clock-three') }),
        h("span", null, `${startTime.toString(this.timeFormat)} - ${endTime.toString(this.timeFormat)}`))));
  }
  /**
   * Return a slot element if the calendar is not a repeat event
   *
   * @returns {Nullable<HTMLElement>} slot element or null
   */
  getSlotElement() {
    if (!this.calendarEvent.isRepeatEvent) {
      return h("slot", null);
    }
  }
  /**
   * render the custom color style tag element
   *
   * @returns {HTMLStyleElement} style element
   */
  injectBackgroundColorStyle() {
    return (h("style", { nonce: vegaNonceManager.nonce }, getEventStatusBgColorStyle(this.calendarEvent.color)));
  }
}
(() => {
  VegaInternalIconManager.register({
    'clock-three': clockThree,
  });
})();
__decorate([
  MapToComponentField()
], VegaCalendarEventRenderer.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarEventRenderer.prototype, "timeFormat", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarEventRenderer.prototype, "calendarEvent", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarEventRenderer.prototype, "slotMode", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarEventRenderer.prototype, "showColorBar", void 0);
