'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-58ea899e.js');
const component = require('./component-1e352960.js');
const globalSlimmerRegistry = require('./global-slimmer-registry-b3bce7e0.js');
const componentUsageRuntimeMetrics = require('./component-usage-runtime-metrics-4572c5b7.js');
const eventEmitSlimmer = require('./event-emit-slimmer-8ba00d00.js');
const vegaEventId = require('./vega-event-id-d9994eb3.js');
const accessibility = require('./accessibility-a5ef2038.js');
require('./dynamic-slimmer-f31fdfd7.js');
require('./change-manager-a297e4d2.js');
require('./dom-node-subject-observer-factory-ba6a95f3.js');
require('./observer-f49483e8.js');
require('./ui-3727d685.js');
require('./internal-vega-event-manager-7e0d966d.js');
require('./try-get-document-c0ebd39a.js');

var __decorate$1 = (undefined && undefined.__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;
};
/** Render the suffix button in a field label component. */
class VegaFieldLabelSuffixElementRenderer extends globalSlimmerRegistry.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 (index.h("div", { class: "label-suffix-button", role: "button", tabIndex: 0, onClick: this.handleSuffixButtonClick, onKeyDown: accessibility.createEnterKeyHandlerToTriggerClick() }, text ? (index.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 (index.h("vega-button-circle", { size: "extra-small", variant: "icon-only", iconColor: "text-link", showTooltip: false, icon: icon }));
  }
}
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaFieldLabelSuffixElementRenderer.prototype, "suffixButtonProps", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaFieldLabelSuffixElementRenderer.prototype, "suffixButtonConfig", void 0);
__decorate$1([
  globalSlimmerRegistry.MapToComponentField()
], VegaFieldLabelSuffixElementRenderer.prototype, "suffixButtonClickEventEmitter", void 0);

const vegaFieldLabelCss = ":host{display:inline-block}:host(.disabled){pointer-events:none}:host(.hidden){display:none}label:first-of-type{color:rgba(var(--v-text-primary, 32, 54, 69, 1));font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px;word-break:break-word}@media screen and (min-width: 768px) and (max-width: 1023px){label:first-of-type{font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}}@media screen and (min-width: 1024px) and (max-width: 1439px){label:first-of-type{font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}}@media screen and (min-width: 1440px) and (max-width: 9999px){label:first-of-type{font-family:\"Inter\", sans-serif;font-size:16px;font-weight:500;line-height:22px;letter-spacing:0px}}:host(.disabled)>label>span.vega-field-label{color:rgba(var(--v-text-secondary, 107, 116, 125, 1))}.vega-field-label-required{color:rgba(var(--v-text-error, 189, 41, 71, 1));margin-left:4px}.vega-field-label-required.hidden{display:none}.label-suffix-button{display:inline-block;margin-left:4px;vertical-align:top}";

var __decorate = (undefined && undefined.__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;
};
const VegaFieldLabel = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.vegaClick = index.createEvent(this, "vegaClick", 7);
    this.vegaLabelButtonClick = index.createEvent(this, "vegaLabelButtonClick", 1);
    this.labelButtonClick = index.createEvent(this, "labelButtonClick", 1);
    this.globalSlimmers = {};
    this.clickEventEmitter = eventEmitSlimmer.createEventEmitSlimmer(VegaFieldLabel, vegaEventId.VegaClick);
    this.suffixButtonClickEventEmitter = eventEmitSlimmer.createEventEmitSlimmer(VegaFieldLabel, vegaEventId.VegaLabelButtonClick);
    this.vegaComponentUsageRuntimeMetricsSlimmer = new componentUsageRuntimeMetrics.VegaComponentUsageRuntimeMetricsSlimmer();
    this.suffixElementRenderer = new VegaFieldLabelSuffixElementRenderer();
    /**
     * @deprecated Please use `suffixButtonConfig` instead
     *
     * Specifies the properties for the suffix button associated with the input.
     *
     * It provides essential information and functionality related to
     *    the suffix button's role and behavior.
     *
     * @vegaVersion 2.25.0
     */
    this.suffixButtonProps = null;
    /**
     * Specifies the properties for the suffix button associated with the input.
     *
     * It provides essential information and functionality related to
     *    the suffix button's role and behavior.
     *
     * @vegaVersion 2.68.0
     */
    this.suffixButtonConfig = null;
    /**
     * Specifies the label or title for the field.
     *
     * It provides descriptive text that helps identify the
     *    purpose or content expected in the field.
     *
     * @vegaVersion 1.10.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.label = '';
    /**
     * Determines whether the input field is required.
     *
     * Specifies whether the field must be filled in to pass form validation.
     *
     * @vegaVersion 1.10.0
     */
    this.isFieldRequired = false;
    /**
     * Specifies whether the field is disabled.
     *
     * @vegaVersion 1.10.0
     */
    this.disabled = false;
    /*
     * The below method is e2e-test covered in
     * @see{module:vega-field-label-vegaClick-event}
     */
    /* istanbul ignore next */
    this.handleClick = (e) => {
      this.clickEventEmitter.emit(undefined, e);
    };
  }
  componentWillLoad() {
    if (this.label === '') {
      this.label = this.host.textContent;
      this.host.textContent = '';
    }
  }
  render() {
    return component.sanitizeVegaComponent(index.h(index.Host, { class: {
        hidden: this.label === '',
        disabled: this.disabled,
      }, onClick: this.handleClick }, index.h("label", null, index.h("span", { class: "vega-field-label" }, this.label), index.h("span", { class: {
        'vega-field-label-required': true,
        'hidden': !this.isFieldRequired,
      } }, "*")), this.suffixElementRenderer.render()), this.host);
  }
  get host() { return index.getElement(this); }
};
__decorate([
  componentUsageRuntimeMetrics.InjectVegaGlobalSlimmer()
], VegaFieldLabel.prototype, "globalSlimmers", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaFieldLabel.prototype, "clickEventEmitter", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaFieldLabel.prototype, "suffixButtonClickEventEmitter", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaFieldLabel.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
__decorate([
  globalSlimmerRegistry.InjectVegaSlimmer()
], VegaFieldLabel.prototype, "suffixElementRenderer", void 0);
VegaFieldLabel.style = vegaFieldLabelCss;

exports.vega_field_label = VegaFieldLabel;
