import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { o as openWormhole } from './consumer.js';
import { i as isRtl } from './page-align.js';
import { d as defineCustomElement$1 } from './sc-tooltip2.js';

const scFormControlCss = ".form-control{font-family:var(--sc-font-sans);font-size:var(--sc-font-size-medium);font-weight:var(--sc-font-weight-normal);display:flex;flex-direction:column;gap:var(--sc-input-label-margin)}.form-control .form-control__label{display:none}.form-control .form-control__help-text{display:none}.form-control--has-label .form-control__label{display:inline-block;color:var(--sc-input-label-color);font-weight:var(--sc-input-label-font-weight);text-transform:var(--sc-input-label-text-transform, none);letter-spacing:var(--sc-input-label-letter-spacing, 0)}.form-control--has-label.form-control--small .form-control__label{font-size:var(--sc-input-label-font-size-small)}.form-control--has-label.form-control--medium .form-control__label{font-size:var(--sc-input-label-font-size-medium)}.form-control--has-label.form-control--large .form-control_label{font-size:var(--sc-input-label-font-size-large)}::slotted(.control--errors){margin-top:var(--sc-spacing-small);color:var(--sc-color-danger-500)}::slotted([slot=label-end]){float:right}.form-control--is-required slot[name=label]:after{content:\" *\";color:var(--sc-color-danger-500)}.form-control--has-help-text .form-control__help-text{display:block;color:var(--sc-input-help-text-color)}.form-control--has-help-text.form-control--small .form-control__help-text{font-size:var(--sc-input-help-text-font-size-small)}.form-control--has-help-text.form-control--medium .form-control__help-text{font-size:var(--sc-input-help-text-font-size-medium)}.form-control--has-help-text.form-control--large .form-control__help-text{font-size:var(--sc-input-help-text-font-size-large)}.form-control--has-error .form-control__error-text{display:block;color:var(--sc-input-error-text-color)}.form-control--has-error.form-control--small .form-control__error-text{font-size:var(--sc-input-error-text-font-size-small)}.form-control--has-error.form-control--medium .form-control__error-text{font-size:var(--sc-input-error-text-font-size-medium)}.form-control--has-error.form-control--large .form-control__error-text{font-size:var(--sc-input-error-text-font-size-large)}.form-control--has-error ::part(base){border-color:rgb(var(--sl-color-danger-500))}.form-control--is-rtl.form-control--has-label .form-control__label{text-align:right}";

const ScFormControl = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    /** Size of the label */
    this.size = 'medium';
    /** Show the label. */
    this.showLabel = true;
    /** Whether the input is required. */
    this.required = false;
  }
  handleErrors() {
    var _a;
    this.errorMessage = (_a = this === null || this === void 0 ? void 0 : this.errors) === null || _a === void 0 ? void 0 : _a[this === null || this === void 0 ? void 0 : this.name];
  }
  render() {
    return (h("div", { part: "form-control", class: {
        'form-control': true,
        'form-control--small': this.size === 'small',
        'form-control--medium': this.size === 'medium',
        'form-control--large': this.size === 'large',
        'form-control--has-label': !!this.label && this.showLabel,
        'form-control--has-help-text': !!this.help,
        'form-control--is-required': !!this.required,
        'form-control--is-rtl': isRtl()
      } }, h("label", { part: "label", id: this.labelId, class: "form-control__label", htmlFor: this.inputId, "aria-hidden": !!this.label ? 'false' : 'true' }, h("slot", { name: "label" }, this.label), h("slot", { name: "label-end" })), h("div", { part: "input", class: "form-control__input" }, !!this.errorMessage ? (h("sc-tooltip", { exportparts: "base:tooltip, text:tooltip-text", text: this.errorMessage, type: "danger", padding: 10, freeze: true, open: true, onClick: () => (this.errorMessage = '') }, h("slot", null))) : (h("slot", null))), this.help && (h("div", { part: "help-text", id: this.helpId, class: "form-control__help-text" }, h("slot", { name: "help-text" }, this.help)))));
  }
  get el() { return this; }
  static get watchers() { return {
    "errors": ["handleErrors"]
  }; }
  static get style() { return scFormControlCss; }
}, [1, "sc-form-control", {
    "size": [513],
    "name": [1],
    "errors": [8],
    "showLabel": [4, "show-label"],
    "label": [1],
    "labelId": [1, "label-id"],
    "inputId": [1, "input-id"],
    "required": [4],
    "help": [1],
    "helpId": [1, "help-id"],
    "errorMessage": [1025, "error-message"]
  }]);
openWormhole(ScFormControl, ['errors'], false);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-form-control", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-form-control":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScFormControl);
      }
      break;
    case "sc-tooltip":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}
defineCustomElement();

export { ScFormControl as S, defineCustomElement as d };
