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 { MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../../utils/accessibility';
/**
 * Provides an abstract base class for rendering date blocks in a calendar component.
 * This class handles click and double-click events on date blocks and emits the appropriate events.
 */
export class VegaCalendarDateBlockRenderer extends VegaSlimmer {
  /**
   * Handles the date click or double-click event and emits the appropriate event based on the `enableDateClick` property.
   *
   * @param {MouseEvent} event - The mouse event triggered by the user.
   * @param {VegaCalendarDateClickInfo} eventInfo - Information about the clicked calendar date.
   */
  emit(event, eventInfo) {
    if (this.shouldHandleClickEvent(event)) {
      this.dateClickEmitter.emit(eventInfo);
    }
    else if (this.shouldHandleDblClickEvent(event)) {
      this.dateDblClickEmitter.emit(eventInfo);
    }
  }
  /**
   * Checks if the click event should be handled based on the `enableDateClick` property and the event type.
   *
   * @param {MouseEvent} event - The mouse event to check.
   * @returns {boolean} - True if the event should be handled, false otherwise.
   */
  shouldHandleClickEvent(event) {
    return this.enableDateClick === true && event.type === 'click';
  }
  /**
   * Checks if the double-click event should be handled based on the `enableDateClick` property and the event type.
   *
   * @param {MouseEvent} event - The mouse event to check.
   * @returns {boolean} - True if the event should be handled, false otherwise.
   */
  shouldHandleDblClickEvent(event) {
    return this.enableDateClick !== true && event.type === 'dblclick';
  }
  /**
   * Generate the properties for rendering a date block based on its disabled state and calendar date.
   *
   * @param {boolean} isDisabled - Indicates if the date block is disabled.
   * @param {CalendarDate} calendarDate - The calendar date object.
   * @param {number} index - The index of the date block.
   * @returns {DateBlockRenderProps} - The properties for rendering the date block.
   */
  generateDateBlockRenderProps(isDisabled, calendarDate, index) {
    const result = {};
    if (!isDisabled) {
      if (this.enableDateClick) {
        result.tabIndex = 0;
        result.role = 'button';
        result.onClick = (e) => {
          this.handleDateBlockClick(e, calendarDate, index);
        };
        result.onKeyDown = createEnterKeyHandlerToTriggerClick();
      }
      else {
        result.onDblClick = (e) => {
          this.handleDateBlockClick(e, calendarDate, index);
        };
      }
    }
    return result;
  }
}
__decorate([
  MapToComponentField()
], VegaCalendarDateBlockRenderer.prototype, "enableDateClick", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarDateBlockRenderer.prototype, "dateClickEmitter", void 0);
__decorate([
  MapToComponentField()
], VegaCalendarDateBlockRenderer.prototype, "dateDblClickEmitter", void 0);
