import { n as i, C as v } from "./lib-cortex-element.CVMmyPMC.js";
import { c as g } from "./component.styles.CRO4Odto.js";
import { c as C } from "./custom-element.L4WJXn1j.js";
import { F as x, v as w } from "./form.Ch1cwYzO.js";
import { L as $ } from "./i18n.BABe9hN4.js";
import { H as S, g as O } from "./slot.j5oheLJC.js";
import { w as m } from "./watch.BCJD77bD.js";
import { r as u } from "./state.CSDxrqLd.js";
import { e as L } from "./query.BBf1UFkC.js";
import { e as D } from "./class-map.BiVq-cVR.js";
import { o } from "./if-defined.BRoBj_Rp.js";
import { n as f } from "./when.Dr1es41R.js";
import { u as h, i as b } from "./static.UA3G1Deq.js";
import B from "../components/icon.js";
import F from "../components/spinner.js";
import { b as _ } from "./button.styles.Cz4EELcL.js";
var y = /* @__PURE__ */ ((t) => (t.Adaptive = "adaptive", t.Fill = "fill", t.Hug = "hug", t))(y || {}), l = /* @__PURE__ */ ((t) => (t.Custom = "custom", t.Large = "large", t.Medium = "medium", t.Small = "small", t.XLarge = "x-large", t))(l || {}), k = Object.defineProperty, V = Object.getOwnPropertyDescriptor, r = (t, s, p, n) => {
  for (var a = n > 1 ? void 0 : n ? V(s, p) : s, d = t.length - 1, c; d >= 0; d--)
    (c = t[d]) && (a = (n ? c(s, p, a) : c(a)) || a);
  return n && a && k(s, p, a), a;
};
let e = class extends v {
  constructor() {
    super(...arguments), this.formControlController = new x(this, {
      assumeInteractionOn: ["click"]
    }), this.hasSlotController = new S(
      this,
      "[default]",
      "prefix",
      "suffix"
    ), this.localize = new $(this), this.forceButtonNavigation = !1, this.hasFocus = !1, this.invalid = !1, this.isParentDropdownOpened = !1, this.title = "", this.variant = "default", this.size = l.Medium, this.caret = !1, this.caretDirection = "down", this.disabled = !1, this.loading = !1, this.outline = !1, this.pill = !1, this.circle = !1, this.type = "button", this.name = "", this.value = "", this.href = "", this.link = "", this.rel = "noreferrer noopener", this.form = void 0, this.widthType = y.Hug, this.label = "", this.mappedLabel = "", this.styleObserver = null, this.parentDropdownObserver = null;
  }
  /** Gets the validity state object */
  get validity() {
    return this.isButton() ? this.button.validity : w;
  }
  /** Gets the validation message */
  get validationMessage() {
    return this.isButton() ? this.button.validationMessage : "";
  }
  get hasPrefix() {
    return this.hasSlotController.test("prefix");
  }
  get hasSuffix() {
    return this.hasSlotController.test("suffix");
  }
  get hasLabel() {
    return this.hasSlotController.test("[default]");
  }
  runFirstUpdated() {
    this.isButton() && this.formControlController.updateValidity();
  }
  connectedUpdatedCallback() {
    this.syncStyles(), this.styleObserver = new MutationObserver(() => this.syncStyles()), this.styleObserver.observe(this, {
      attributeFilter: ["class", "style"],
      attributes: !0
    });
    const t = this.closest("cx-dropdown");
    t && (this.parentDropdownObserver = new MutationObserver(() => {
      this.slot === "trigger" && (this.isParentDropdownOpened = t.open);
    }), this.parentDropdownObserver.observe(t, {
      attributeFilter: ["open"],
      attributes: !0
    }));
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.styleObserver && this.styleObserver.disconnect(), this.parentDropdownObserver && this.parentDropdownObserver.disconnect();
  }
  syncStyles() {
    const t = this.style.fontSize;
    t && this.button && (this.button.style.fontSize = t, this.style.fontSize = "");
  }
  handleBlur() {
    this.hasFocus = !1, this.emit("cx-blur");
  }
  handleFocus() {
    this.hasFocus = !0, this.emit("cx-focus");
  }
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  handleClick(t) {
    this.type === "submit" && this.formControlController.submit(this), this.type === "reset" && this.formControlController.reset(this);
  }
  handleInvalid(t) {
    this.formControlController.setValidity(!1), this.formControlController.emitInvalidEvent(t);
  }
  isButton() {
    return !(this.link || this.href);
  }
  isLink() {
    return this.link || this.href;
  }
  handleLabelSlotChange() {
    this.mappedLabel = O(
      this.shadowRoot?.querySelector('slot[part="label"]')
    ).trim() || this.label || "";
  }
  handleDisabledChange() {
    this.isButton() && this.formControlController.setValidity(this.disabled);
  }
  /** Simulates a click on the button. */
  click() {
    this.button.click();
  }
  /** Sets focus on the button. */
  focus(t) {
    this.button.focus(t);
  }
  /** Removes focus from the button. */
  blur() {
    this.button.blur();
  }
  /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */
  checkValidity() {
    return this.isButton() ? this.button.checkValidity() : !0;
  }
  /** Gets the associated form, if one exists. */
  getForm() {
    return this.formControlController.getForm();
  }
  /** Checks for validity and shows the browser's validation message if the control is invalid. */
  reportValidity() {
    return this.isButton() ? this.button.reportValidity() : !0;
  }
  /** Sets a custom validation message. Pass an empty string to restore validity. */
  setCustomValidity(t) {
    this.isButton() && (this.button.setCustomValidity(t), this.formControlController.updateValidity());
  }
  renderLabel() {
    return h`<slot part="label" class="button__label" @slotchange=${this.handleLabelSlotChange}></slot>`;
  }
  render() {
    const t = this.isLink() && !this.forceButtonNavigation, s = t ? b`a` : b`button`;
    return h`<${s} part="base" class=${D({
      button: !0,
      "button--caret": this.caret,
      "button--circle": this.circle,
      "button--custom": this.variant === "custom",
      "button--custom-size": this.size === l.Custom,
      "button--danger": this.variant === "danger",
      "button--default": this.variant === "default" || this.variant === "neutral",
      "button--disabled": this.disabled,
      "button--focused": this.hasFocus || this.isParentDropdownOpened,
      "button--has-label": this.hasLabel,
      "button--has-prefix": this.hasPrefix,
      "button--has-suffix": this.hasSuffix,
      "button--large": this.size === l.Large,
      "button--loading": this.loading,
      "button--medium": this.size === l.Medium,
      "button--outline": this.outline,
      "button--pill": this.pill,
      "button--primary": this.variant === "primary",
      "button--rtl": this.localize.dir() === "rtl",
      "button--small": this.size === l.Small,
      "button--standard": !this.outline,
      "button--success": this.variant === "success",
      "button--tertiary": this.variant === "tertiary",
      "button--text": this.variant === "text",
      "button--warning": this.variant === "warning",
      "button--x-large": this.size === l.XLarge
    })} ?disabled=${o(t ? void 0 : this.disabled)} type=${o(t ? void 0 : this.type)} title=${o(this.title || void 0)} name=${o(t ? void 0 : this.name)} value=${o(t ? void 0 : this.value)} href=${o(t ? this.link || this.href : void 0)} target=${o(t ? this.target : void 0)} download=${o(t ? this.download : void 0)} rel=${o(t ? this.rel : void 0)} role=${o(t ? void 0 : "button")} aria-disabled=${this.disabled ? "true" : "false"} aria-label=${o(this.mappedLabel || void 0)} tabindex=${this.disabled ? "-1" : "0"} @blur=${this.handleBlur} @focus=${this.handleFocus} @invalid=${this.isButton() ? this.handleInvalid : null} @click=${this.handleClick}><slot name="prefix" part="prefix" class="button__prefix"></slot>${this.renderLabel()}<slot name="suffix" part="suffix" class="button__suffix"></slot>${f(
      this.caret,
      () => h`<cx-icon part="caret" class="button__caret" name=${`keyboard_arrow_${this.caretDirection}`}></cx-icon>`
    )}
        ${f(this.loading, () => h`<cx-spinner part="spinner"></cx-spinner>`)}</${s}>`;
  }
};
e.styles = [g, _];
e.dependencies = {
  "cx-icon": B,
  "cx-spinner": F
};
r([
  L(".button")
], e.prototype, "button", 2);
r([
  u()
], e.prototype, "hasFocus", 2);
r([
  u()
], e.prototype, "invalid", 2);
r([
  u()
], e.prototype, "isParentDropdownOpened", 2);
r([
  i()
], e.prototype, "title", 2);
r([
  i({ reflect: !0 })
], e.prototype, "variant", 2);
r([
  i({ reflect: !0 })
], e.prototype, "size", 2);
r([
  i({ reflect: !0, type: Boolean })
], e.prototype, "caret", 2);
r([
  i({ attribute: "caret-direction", reflect: !0, type: String })
], e.prototype, "caretDirection", 2);
r([
  i({ reflect: !0, type: Boolean })
], e.prototype, "disabled", 2);
r([
  i({ reflect: !0, type: Boolean })
], e.prototype, "loading", 2);
r([
  i({ reflect: !0, type: Boolean })
], e.prototype, "outline", 2);
r([
  i({ reflect: !0, type: Boolean })
], e.prototype, "pill", 2);
r([
  i({ reflect: !0, type: Boolean })
], e.prototype, "circle", 2);
r([
  i()
], e.prototype, "type", 2);
r([
  i()
], e.prototype, "name", 2);
r([
  i()
], e.prototype, "value", 2);
r([
  i()
], e.prototype, "href", 2);
r([
  i()
], e.prototype, "link", 2);
r([
  i()
], e.prototype, "target", 2);
r([
  i()
], e.prototype, "rel", 2);
r([
  i()
], e.prototype, "download", 2);
r([
  i({ reflect: !1 })
], e.prototype, "form", 2);
r([
  i({ attribute: "formaction" })
], e.prototype, "formAction", 2);
r([
  i({ attribute: "formenctype" })
], e.prototype, "formEnctype", 2);
r([
  i({ attribute: "formmethod" })
], e.prototype, "formMethod", 2);
r([
  i({ attribute: "formnovalidate", type: Boolean })
], e.prototype, "formNoValidate", 2);
r([
  i({ attribute: "formtarget" })
], e.prototype, "formTarget", 2);
r([
  i({ attribute: "width-type", reflect: !0, type: String })
], e.prototype, "widthType", 2);
r([
  i({ reflect: !0, type: String })
], e.prototype, "label", 2);
r([
  u()
], e.prototype, "mappedLabel", 2);
r([
  m("label")
], e.prototype, "handleLabelSlotChange", 1);
r([
  m("disabled", { waitUntilFirstUpdate: !0 })
], e.prototype, "handleDisabledChange", 1);
e = r([
  C("cx-button")
], e);
export {
  l as B,
  e as C,
  y as a
};
