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 { createDynamicSlimmer, InjectVegaSlimmer, MapToComponentField, MapToComponentMethod, methodPlaceholder, } from 'vega-slimmer/core';
import { ElementAppenderSlimmer } from '../../../../helpers/slimmers/element-appender/element-appender-slimmer';
import remoteInvocationRegistry from '../../../../helpers/remote-invocation/remote-invocation-registry';
import domNodeSubjectFactory from '../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalPopoverUpdateTarget } from '../../../../helpers/event-manager/event-id/vega-internal-event-id';
import { AriaDialogFocusableTrapSlimmer } from '../../../../helpers/slimmers/aria-dialog-focusable-trap-slimmer';
/** The `VegaPopoverAppenderController` class extends `ElementAppenderSlimmer` and defines properties and methods for appending a popover element to a target element based on specified configurations. */
export class VegaPopoverAppenderController extends ElementAppenderSlimmer {
  /**
   * The constructor initializes a popover with specific configuration options.
   */
  constructor() {
    super(() => this.generateShowConfigFactory(), () => this.trigger, 'isPopoverShow');
    this.ariaDialogFocusableTrapSlimmer = createDynamicSlimmer(VegaPopoverAppenderController, AriaDialogFocusableTrapSlimmer, [], [
      { mapFrom: 'show', mapTo: 'show' },
      { mapFrom: 'hide', mapTo: 'hide' },
    ], [
      {
        // eslint-disable-next-line jsdoc/require-jsdoc
        triggerEl: () => this.host,
        // eslint-disable-next-line jsdoc/require-jsdoc
        dialogEl: () => this.appenderRenderer.getPopoverContentBox(),
      },
    ]);
  }
  /**
   * Component lifecycle - [componentDidLoad]{@link VegaPopover.connectedCallback}
   */
  connectedCallback() {
    this.registerRemoteMethod();
  }
  /**
   * Component lifecycle - [componentDidLoad]{@link VegaPopover.disconnectedCallback}
   */
  disconnectedCallback() {
    remoteInvocationRegistry.unRegister(domNodeSubjectFactory.getSubject(this.host, VegaInternalPopoverUpdateTarget));
  }
  /**
   * Component lifecycle - [componentDidRender]{@link VegaPopover.componentDidRender}
   */
  componentDidRender() {
    methodPlaceholder();
  }
  /**
   * Generate the show configuration for the popover.
   *
   * @returns {ElementAppenderShowConfig} The show configuration for the popover.
   */
  generateShowConfigFactory() {
    return {
      target: this.target || this.host,
      appendableElement: this.appenderRenderer.getPopoverContentBox(),
      positionRelativeTo: this.positionRelativeTo,
      matchTargetWidth: false,
      size: this.size,
      placement: this.placement,
      alignment: this.alignment,
      isScreenPosition: this.isScreenPosition,
    };
  }
  /**
   * Register a remote method to update the target element of the popover.
   * TODO: refactor to using Change Manager
   */
  registerRemoteMethod() {
    remoteInvocationRegistry.register(domNodeSubjectFactory.getSubject(this.host, VegaInternalPopoverUpdateTarget), (target) => {
      this.target = target;
      super.updateShowConfigFactory(this.generateShowConfigFactory.bind(this));
    });
  }
}
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "trigger", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "positionRelativeTo", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "placement", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "alignment", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "size", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "isScreenPosition", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaPopoverAppenderController.prototype, "isPopoverShow", void 0);
__decorate([
  MapToComponentField()
], VegaPopoverAppenderController.prototype, "appenderRenderer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaPopoverAppenderController.prototype, "ariaDialogFocusableTrapSlimmer", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaPopoverAppenderController.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaPopoverAppenderController.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentDidRender')
], VegaPopoverAppenderController.prototype, "componentDidRender", null);
