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 { h } from '@stencil/core';
import { VegaSlimmer, MapToComponentField } from 'vega-slimmer/core';
import { createEnterKeyHandlerToTriggerClick } from '../../../../utils/accessibility';
/** Render the suffix button in a field label component. */
export class VegaFieldLabelSuffixElementRenderer extends VegaSlimmer {
  constructor() {
    super(...arguments);
    /**
     * Stop click event propagation and emit an event.
     *
     * @param {MouseEvent} e click event object
     */
    this.handleSuffixButtonClick = (e) => {
      e.stopPropagation();
      this.suffixButtonClickEventEmitter.emit();
    };
  }
  /**
   * Render a suffix button if the property is not empty.
   *
   * @returns {Nullable<HTMLElement>}
   */
  render() {
    if (this.suffixButtonConfig || this.suffixButtonProps) {
      const { icon, text, size, minWidth, maxWidth, placement = 'right', alignment = 'start', trigger = 'hover', } = this.suffixButtonConfig ||
        (this.suffixButtonProps && {
          icon: this.suffixButtonProps.icon,
          text: this.suffixButtonProps.tooltipText,
          trigger: this.suffixButtonProps.trigger,
        });
      return (h("div", { class: "label-suffix-button", role: "button", tabIndex: 0, onClick: this.handleSuffixButtonClick, onKeyDown: createEnterKeyHandlerToTriggerClick() }, text ? (h("vega-tooltip", { trigger: trigger, text: text, size: size, minWidth: minWidth, maxWidth: maxWidth, alignment: alignment, placement: placement }, this.renderSuffixButton(icon))) : (this.renderSuffixButton(icon))));
    }
  }
  /**
   * Render a vega button circle component.
   *
   * @param {string} icon the button icon name
   * @returns {HTMLVegaButtonCircleElement} vega button circle component
   */
  renderSuffixButton(icon) {
    return (h("vega-button-circle", { size: "extra-small", variant: "icon-only", iconColor: "text-link", showTooltip: false, icon: icon }));
  }
}
__decorate([
  MapToComponentField()
], VegaFieldLabelSuffixElementRenderer.prototype, "suffixButtonProps", void 0);
__decorate([
  MapToComponentField()
], VegaFieldLabelSuffixElementRenderer.prototype, "suffixButtonConfig", void 0);
__decorate([
  MapToComponentField()
], VegaFieldLabelSuffixElementRenderer.prototype, "suffixButtonClickEventEmitter", void 0);
