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, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import { DomNodeSubjectObserverFactory } from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaInternalCalendarPreviewActionClick } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
import { PreviewActionButtonType } from '../../../vega-calendar-event-preview/slimmers/renderers/vega-calendar-event-preview-detail-renderer';
/**
 * Controller for managing the visibility of event action buttons in the calendar component.
 */
export class EventPreviewActionsController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * Handles the click event for preview action buttons.
     *
     * @param {NotifyObserverPayload} payload The payload containing information about the clicked action button.
     */
    this.handlePreviewActionButtonClick = (payload) => {
      if (payload && payload.detail) {
        const { event, date, actionType } = payload.detail;
        if (actionType === PreviewActionButtonType.Edit) {
          this.eventEditEmitter.emit({
            rawEvent: event.event,
            date: {
              year: date.year,
              month: date.month,
              date: date.date,
            },
          });
        }
      }
    };
  }
  /**
   * Checks the visibility of event action buttons based on the calendar's eventEditable state and the presence of a getEventPreviewActions callback.
   *
   * @param {CalendarEvent} calendarEvent - The calendar event for which to check the action buttons visibility.
   * @param {CalendarDate} calendarDate - The date associated with the event.
   * @returns {CalendarEventActions} An object indicating which event action buttons should be visible.
   */
  retrieveActionsVisibility(calendarEvent, calendarDate) {
    let result = {};
    if (this.eventEditable && typeof this.getEventPreviewActions === 'function') {
      const { date, month, year } = calendarDate;
      result = this.getEventPreviewActions(calendarEvent.event, { date, month, year });
    }
    return result;
  }
  /**
   * Registers event listeners for preview action buttons when the component is connected to the DOM.
   */
  registerPreviewActionButtonEvent() {
    DomNodeSubjectObserverFactory.addUniqueObserverToNode(this.host, VegaInternalCalendarPreviewActionClick, this.handlePreviewActionButtonClick);
  }
  /**
   * Unregisters event listeners for preview action buttons when the component is disconnected from the DOM.
   */
  unregisterPreviewActionButtonEvent() {
    DomNodeSubjectObserverFactory.removeUniqueObserverFromNode(this.host, VegaInternalCalendarPreviewActionClick);
  }
}
__decorate([
  MapToComponentField()
], EventPreviewActionsController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], EventPreviewActionsController.prototype, "eventEditable", void 0);
__decorate([
  MapToComponentField()
], EventPreviewActionsController.prototype, "getEventPreviewActions", void 0);
__decorate([
  MapToComponentField()
], EventPreviewActionsController.prototype, "eventEditEmitter", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], EventPreviewActionsController.prototype, "registerPreviewActionButtonEvent", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], EventPreviewActionsController.prototype, "unregisterPreviewActionButtonEvent", null);
