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 { ElementAppenderSlimmer } from '../../../../helpers/slimmers/element-appender/element-appender-slimmer';
import { MapToComponentField, MapToComponentMethod } from 'vega-slimmer/core';
/**
 * The class is responsible for managing the visibility and behavior of the tooltip content box.
 */
export class VegaTooltipElementAppenderController extends ElementAppenderSlimmer {
  /**
   * This constructor of the tooltip element appender controller.
   */
  constructor() {
    super(() => this.getShowConfig(), () => this.trigger, 'isTooltipShow', () => this.disableInteractive);
    /**
     * Generate the element appender show config object.
     *
     * @returns {ElementAppenderShowConfig} - Show config object.
     */
    this.getShowConfig = () => {
      return {
        target: this.host,
        appendableElement: this.vegaTooltipContentBoxRenderer.getTooltipContentBoxRef(),
        positionRelativeTo: this.positionRelativeTo,
        isScreenPosition: true,
        matchTargetWidth: false,
        size: this.size,
        minWidth: this.minWidth,
        maxWidth: this.maxWidth,
        placement: this.placement,
        alignment: this.alignment,
      };
    };
  }
  /**
   * The `watchTrigger` function hides an element if the trigger is set to 'none'.
   */
  watchTrigger() {
    if (this.trigger === 'none') {
      this.hide();
    }
  }
  /**
   * The function `watchToShowTooltip` checks if the tooltip should be shown and then displays it if necessary.
   */
  watchToShowTooltip() {
    if (this.isTooltipShow) {
      this.show();
    }
  }
  /**
   * Hide the tooltip if the content change to empty.
   *
   * @param {string} newText - The property text or content new value.
   * @param {string} oldText - The property text or content old value.
   */
  watchTextChange(newText, oldText) {
    if (!newText && oldText && this.isTooltipShow) {
      this.hide();
    }
  }
  /**
   * Override the parent class `ElementAppenderSlimmer` show method to control the tooltip show according to the tooltip content.
   */
  show() {
    const text = this.deprecatedPropertySlimmer.getValue();
    if (text) {
      super.show();
    }
  }
}
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "positionRelativeTo", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "size", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "minWidth", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "maxWidth", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "placement", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "alignment", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "trigger", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "disableInteractive", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "deprecatedPropertySlimmer", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaTooltipElementAppenderController.prototype, "isTooltipShow", void 0);
__decorate([
  MapToComponentField()
], VegaTooltipElementAppenderController.prototype, "vegaTooltipContentBoxRenderer", void 0);
__decorate([
  MapToComponentMethod('watchTrigger')
], VegaTooltipElementAppenderController.prototype, "watchTrigger", null);
__decorate([
  MapToComponentMethod('watchToShowTooltip')
], VegaTooltipElementAppenderController.prototype, "watchToShowTooltip", null);
__decorate([
  MapToComponentMethod('watchTextChange')
], VegaTooltipElementAppenderController.prototype, "watchTextChange", null);
