import {
  FormControlController,
  validValidityState
} from "./chunk.C3WIBDGG.js";
import {
  HasSlotController
} from "./chunk.IVMQWO2L.js";
import {
  watch
} from "./chunk.X2OQMWGY.js";
import {
  SolidElement,
  customElement
} from "./chunk.H53WQBDK.js";
import {
  __decorateClass
} from "./chunk.S3NI7NKU.js";

// src/components/button/button.ts
import { css } from "lit";
import { html, literal } from "lit/static-html.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { property, query, queryAssignedElements, state } from "lit/decorators.js";
import cx from "classix";
var SdButton = class extends SolidElement {
  constructor() {
    super(...arguments);
    this.formControlController = new FormControlController(this, {
      form: (input) => {
        if (input.hasAttribute("form")) {
          const doc = input.getRootNode();
          const formId = input.getAttribute("form");
          return doc.getElementById(formId);
        }
        return input.closest("form");
      }
    });
    this.hasSlotController = new HasSlotController(this, "[default]", "icon-left", "icon-right");
    this.invalid = false;
    this.title = "";
    this.variant = "primary";
    this.inverted = false;
    this.size = "lg";
    this.disabled = false;
    this.visuallyDisabled = false;
    this.loading = false;
    this.type = "button";
    this.name = "";
    this.value = "";
    this.href = "";
  }
  /** Gets the validity state object */
  get validity() {
    if (this.isButton()) {
      return this.button.validity;
    }
    return validValidityState;
  }
  /** Gets the validation message */
  get validationMessage() {
    if (this.isButton()) {
      return this.button.validationMessage;
    }
    return "";
  }
  firstUpdated() {
    if (this.isButton()) {
      this.formControlController.updateValidity();
    }
  }
  handleBlur() {
    this.emit("sd-blur");
  }
  handleFocus() {
    this.emit("sd-focus");
  }
  handleClick(event) {
    if (this.disabled || this.loading || this.visuallyDisabled) {
      event.preventDefault();
      event.stopPropagation();
      return;
    }
    if (this.type === "submit") {
      this.formControlController.submit(this);
    }
    if (this.type === "reset") {
      this.formControlController.reset(this);
    }
  }
  handleInvalid(event) {
    this.formControlController.setValidity(false);
    this.formControlController.emitInvalidEvent(event);
  }
  isButton() {
    return this.href ? false : true;
  }
  isLink() {
    return this.href ? true : false;
  }
  handleDisabledChange() {
    if (this.isButton()) {
      this.formControlController.setValidity(this.disabled);
    }
  }
  /** Simulates a click on the button. */
  click() {
    this.button.click();
  }
  /** Sets focus on the button. */
  focus(options) {
    this.button.focus(options);
  }
  /** Removes focus from the button. */
  blur() {
    this.button.blur();
  }
  /** Checks for validity but does not show the browser's validation message. Returns `true` when valid and `false` when invalid. */
  checkValidity() {
    if (this.isButton()) {
      return this.button.checkValidity();
    }
    return true;
  }
  /** 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() {
    if (this.isButton()) {
      return this.button.reportValidity();
    }
    return true;
  }
  /** Sets a custom validation message. Pass an empty string to restore validity. */
  setCustomValidity(message) {
    if (this.isButton()) {
      this.button.setCustomValidity(message);
      this.formControlController.updateValidity();
    }
  }
  render() {
    const isLink = this.isLink();
    const tag = isLink ? literal`a` : literal`button`;
    const slots = {
      label: this.hasSlotController.test("[default]"),
      "icon-left": this.hasSlotController.test("icon-left"),
      "icon-right": this.hasSlotController.test("icon-right"),
      "icon-only": this._iconsInDefaultSlot.length > 0
    };
    const hasBorder = this.variant === "secondary";
    return html`<${tag} part="base" class="${cx(
      `group relative z-10 font-md no-underline
        w-full align-middle inline-flex items-stretch justify-center
        transition-colors duration-fast ease-in-out
        select-none cursor-[inherit]`,
      !this.inverted ? "focus-visible:focus-outline" : "focus-visible:focus-outline-inverted",
      this.loading && "relative cursor-wait",
      (this.disabled || this.visuallyDisabled) && "cursor-not-allowed",
      {
        /* sizes, fonts */
        sm: `varspacing-8 min-h-8 sd-6-22-0-button--size-sm-font-size sd-6-22-0-button-font-weight sd-6-22-0-button--secondary--size-sm-padding-block sd-6-22-0-button--size-sm-border-radius`,
        md: `varspacing-10 sd-6-22-0-button--size-md-height sd-6-22-0-button--size-md-font-size sd-6-22-0-button--secondary--size-md-padding-block sd-6-22-0-button-font-weight sd-6-22-0-button--size-md-border-radius`,
        lg: `varspacing-12 sd-6-22-0-button--size-lg-height sd-6-22-0-button--size-lg-font-size sd-6-22-0-button--secondary--size-lg-padding-block sd-6-22-0-button-font-weight sd-6-22-0-button--size-lg-border-radius`
      }[this.size],
      !slots["icon-only"] && {
        /* sizes, fonts */
        sm: `${hasBorder ? "sd-6-22-0-button--secondary-padding-inline" : "sd-6-22-0-button--size-sm-padding-block sd-6-22-0-button-padding-inline"}`,
        md: `${hasBorder ? "sd-6-22-0-button--secondary-padding-inline" : "sd-6-22-0-button--size-md-padding-block sd-6-22-0-button-padding-inline"}`,
        lg: `${hasBorder ? "sd-6-22-0-button--secondary-padding-inline" : "sd-6-22-0-button--size-lg-padding-block sd-6-22-0-button-padding-inline"}`
      }[this.size],
      /**
       * Anatomy
       * */
      slots["icon-only"] && {
        sm: "px-1 aspect-square",
        md: "sd-6-22-0-button--size-md--icon-only-padding-inline aspect-square",
        lg: "px-[12px] aspect-square"
      }[this.size],
      {
        /* variants */
        primary: !this.inverted ? `${this.visuallyDisabled ? "sd-6-22-0-button--primary--disabled-color-background border-neutral-500 text-white" : "sd-6-22-0-button--primary--default-color-background border-transparent sd-6-22-0-button--primary--default-color-text hover:sd-6-22-0-button--primary--hover-color-text active:sd-6-22-0-button--primary--active-color-text active:sd-6-22-0-button--primary--active-color-background"}
          disabled:sd-6-22-0-button--primary--disabled-color-background disabled:text-white` : `${this.visuallyDisabled ? "sd-6-22-0-button--inverted--disabled-color-background text-white border-neutral-500" : "sd-6-22-0-button--primary--inverted--default-color-text sd-6-22-0-button--primary--inverted--default-color-background border-white hover:sd-6-22-0-button--primary--inverted--hover-color-text active:sd-6-22-0-button--primary--inverted--active-color-text active:sd-6-22-0-button--primary--inverted--active-color-background"}
          disabled:sd-6-22-0-button--inverted--disabled-color-background disabled:text-white`,
        secondary: !this.inverted ? `border sd-6-22-0-button-border-width ${this.visuallyDisabled ? "sd-6-22-0-button--secondary--disabled-color-text sd-6-22-0-button--secondary--disabled-color-border" : "sd-6-22-0-button--secondary--default-color-text sd-6-22-0-button--secondary--default-color-border hover:sd-6-22-0-button--secondary--hover-color-text hover:sd-6-22-0-button--secondary--hover-color-border active:sd-6-22-0-button--secondary--active-color-text active:sd-6-22-0-button--secondary--active-color-border"}
          disabled:sd-6-22-0-button--secondary--disabled-color-text disabled:sd-6-22-0-button--secondary--disabled-color-border` : `border sd-6-22-0-button-border-width ${this.visuallyDisabled ? "text-neutral-600 border-neutral-600" : "sd-6-22-0-button--secondary--inverted-color-text sd-6-22-0-button--secondary--inverted-color-border hover:sd-6-22-0-button--secondary--inverted-color-border hover:sd-6-22-0-button--secondary--inverted--hover-color-text hover:sd-6-22-0-button--secondary--inverted--hover-color-background active:sd-6-22-0-button--secondary--inverted--active-color-text active:border-primary-200 active:sd-6-22-0-button--secondary--inverted--active-color-background"}
          disabled:sd-6-22-0-button--inverted--disabled-color-border disabled:sd-6-22-0-button--inverted--disabled-color-text`,
        tertiary: !this.inverted ? `border-transparent ${this.visuallyDisabled ? "sd-6-22-0-button--tertiary--disabled-color-text" : "sd-6-22-0-button--tertiary--default-color-text hover:sd-6-22-0-button--tertiary--hover-color-text active:sd-6-22-0-button--tertiary--active-color-text"}
          disabled:sd-6-22-0-button--tertiary--disabled-color-text` : `border-transparent  ${this.visuallyDisabled ? "text-neutral-600" : "sd-6-22-0-button--tertiary--inverted-color-text hover:sd-6-22-0-button--tertiary--inverted--hover-color-text hover:sd-6-22-0-button--tertiary--inverted--hover-color-background active:sd-6-22-0-button--tertiary--inverted--active-color-background active:sd-6-22-0-button--tertiary--inverted--active-color-text"}
          disabled:sd-6-22-0-button--inverted--disabled-color-text`,
        cta: `${this.visuallyDisabled ? "sd-6-22-0-button--primary--disabled-color-background border-neutral-500" : "bg-accent border-transparent hover:bg-accent-500"}
          ${!this.inverted ? "text-white bg-accent disabled:sd-6-22-0-button--primary--disabled-color-background hover:bg-accent-500 disabled:border-neutral-500 disabled:text-white" : "sd-6-22-0-button--cta--inverted--default-color-background sd-6-22-0-button--cta--inverted--default-color-text hover:sd-6-22-0-button--cta--inverted--hover-color-text active:sd-6-22-0-button--cta--inverted--active-color-text disabled:sd-6-22-0-button--inverted--disabled-color-background disabled:text-white"}`
      }[this.variant]
    )}" ?disabled="${ifDefined(isLink ? void 0 : this.disabled)}" type="${ifDefined(isLink ? void 0 : this.type)}" title="${this.title}" name="${ifDefined(isLink ? void 0 : this.name)}" value="${ifDefined(isLink ? void 0 : this.value)}" href="${ifDefined(isLink ? this.href : void 0)}" target="${ifDefined(isLink ? this.target : void 0)}" download="${ifDefined(isLink ? this.download : void 0)}" rel="${ifDefined(isLink && this.target ? "noreferrer noopener" : void 0)}" role="${ifDefined(isLink ? void 0 : "button")}" aria-disabled="${this.disabled || this.visuallyDisabled ? "true" : "false"}" aria-labelledby="content" tabindex="${this.disabled ? "-1" : "0"}" @blur="${this.handleBlur}" @focus="${this.handleFocus}" @invalid="${this.isButton() ? this.handleInvalid : null}" @click="${this.handleClick}"><div part="motion-wrapper" class="${cx(
      "absolute inset-0 -z-10 overflow-hidden pointer-events-none ",
      (this.disabled || this.visuallyDisabled) && "hidden",
      {
        /* sizes, fonts */
        sm: `sd-6-22-0-button-border-radius`,
        md: `sd-6-22-0-button-border-radius`,
        lg: `sd-6-22-0-button-border-radius`
      }[this.size]
    )}"><div class="absolute inset-0 w-full h-full transition-all duration-fast translate-y-full group-hover:translate-y-0 group-hover:mt-[-22%] mt-[11%]"><div class="${cx(
      "absolute right-0 min-w-full min-h-full aspect-square skew-y-[-11deg] mt-[11%]",
      {
        primary: !this.inverted ? "sd-6-22-0-button--primary--hover-color-background group-active:sd-6-22-0-button--primary--active-color-background" : "sd-6-22-0-button--primary--inverted--hover-color-background group-active:sd-6-22-0-button--primary--inverted--active-color-background",
        secondary: !this.inverted ? "sd-6-22-0-button--secondary--hover-color-background group-active:sd-6-22-0-button--secondary--active-color-background" : "sd-6-22-0-button--secondary--inverted--hover-color-background group-active:sd-6-22-0-button--secondary--inverted--active-color-background group-active:sd-6-22-0-button--secondary--inverted--active-color-text",
        tertiary: !this.inverted ? "sd-6-22-0-button--tertiary--hover-color-background group-active:sd-6-22-0-button--tertiary--active-color-background" : "sd-6-22-0-button--tertiary--inverted--hover-color-background group-active:sd-6-22-0-button--tertiary--inverted--active-color-background group-active:sd-6-22-0-button--tertiary--inverted--active-color-text",
        cta: !this.inverted ? "bg-accent-500 group-active:bg-accent-700" : "sd-6-22-0-button--cta--inverted--hover-color-background group-active:sd-6-22-0-button--cta--inverted--active-color-background"
      }[this.variant]
    )}"></div><div class="${cx(
      "absolute w-full h-full mt-[22%]",
      {
        primary: !this.inverted ? "sd-6-22-0-button--primary--hover-color-background group-active:sd-6-22-0-button--primary--active-color-background" : "sd-6-22-0-button--primary--inverted--hover-color-background group-active:sd-6-22-0-button--primary--inverted--active-color-background",
        secondary: !this.inverted ? "sd-6-22-0-button--secondary--hover-color-background group-active:sd-6-22-0-button--secondary--active-color-background" : "sd-6-22-0-button--secondary--inverted--hover-color-background group-active:sd-6-22-0-button--secondary--inverted--active-color-background group-active:sd-6-22-0-button--secondary--inverted--active-color-text group-active:sd-6-22-0-button--secondary--active-color-border",
        tertiary: !this.inverted ? "sd-6-22-0-button--tertiary--hover-color-background group-active:sd-6-22-0-button--tertiary--active-color-background" : "sd-6-22-0-button--tertiary--inverted--hover-color-background group-active:sd-6-22-0-button--tertiary--inverted--active-color-background group-active:sd-6-22-0-button--tertiary--inverted--active-color-text",
        cta: !this.inverted ? "bg-accent-500 group-active:bg-accent-700" : "sd-6-22-0-button--cta--inverted--hover-color-background group-active:sd-6-22-0-button--cta--inverted--active-color-background"
      }[this.variant]
    )}"></div></div></div><slot name="icon-left" part="icon-left" class="${cx(
      "flex flex-auto items-center justify-end pointer-events-none",
      slots["icon-only"] && "hidden",
      this.loading && "invisible",
      slots["icon-left"] && {
        sm: "mr-1",
        md: "mr-2",
        lg: "mr-2"
      }[this.size]
    )}"></slot><slot part="label" id="content" class="${cx(
      "inline-flex items-center justify-center",
      {
        sm: "leading-5",
        md: "leading-6",
        lg: "leading-6"
      }[this.size],
      slots["icon-only"] && "pointer-events-none",
      this.loading && "invisible"
    )}"></slot><slot name="icon-right" part="icon-right" class="${cx(
      "flex flex-auto items-center pointer-events-none",
      this.loading && "invisible",
      slots["icon-only"] && "hidden",
      slots["icon-right"] && {
        sm: "ml-1",
        md: "ml-2",
        lg: "ml-2"
      }[this.size]
    )}"></slot>${this.loading ? html`<sd-6-22-0-loader class="${cx("absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2")}"></sd-6-22-0-loader>` : ""}</${tag}>`;
  }
};
/**
 * Inherits global stylesheet including TailwindCSS
 */
SdButton.styles = [
  ...SolidElement.styles,
  css`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */@layer properties;@layer theme,base,components,utilities;
:host{position:relative;z-index:0;display:inline-block;width:auto;cursor:pointer}::slotted(sd-6-22-0-badge){pointer-events:none;position:absolute;top:calc(var(--sd-spacing-1) * 0);right:calc(var(--sd-spacing-1) * 0);--tw-translate-x:calc(1 / 2 * 100%)!important;--tw-translate-y:calc(calc(1 / 2 * 100%) * -1)!important;translate:var(--tw-translate-x) var(--tw-translate-y)!important}::slotted(sd-6-22-0-icon),sd-6-22-0-loader{font-size:calc(var(--tw-varspacing)/ 2)}:host([size=lg]) ::slotted(sd-6-22-0-icon){font-size:var(--sd-button--size-lg-icon-height,var(--sd-spacing-6))}:host([size=sm]) .sd-6-22-0-button--size-sm-border-radius{border-radius:var(--sd-button--size-sm-border-radius,var(--sd-button-border-radius))}:host([size=md]) .sd-6-22-0-button--size-md-border-radius{border-radius:var(--sd-button--size-md-border-radius,var(--sd-button-border-radius))}:host([size=lg]) .sd-6-22-0-button--size-lg-border-radius{border-radius:var(--sd-button--size-lg-border-radius,var(--sd-button-border-radius))}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}`
];
__decorateClass([
  query("a, button")
], SdButton.prototype, "button", 2);
__decorateClass([
  queryAssignedElements({ selector: "sd-6-22-0-icon" })
], SdButton.prototype, "_iconsInDefaultSlot", 2);
__decorateClass([
  state()
], SdButton.prototype, "invalid", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "title", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "variant", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], SdButton.prototype, "inverted", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "size", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], SdButton.prototype, "disabled", 2);
__decorateClass([
  property({ type: Boolean, reflect: true, attribute: "visually-disabled" })
], SdButton.prototype, "visuallyDisabled", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], SdButton.prototype, "loading", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "type", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "name", 2);
__decorateClass([
  property()
], SdButton.prototype, "value", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "href", 2);
__decorateClass([
  property({ type: String, reflect: true })
], SdButton.prototype, "target", 2);
__decorateClass([
  property({ reflect: true })
], SdButton.prototype, "download", 2);
__decorateClass([
  property({ reflect: true })
], SdButton.prototype, "form", 2);
__decorateClass([
  property({ attribute: "formaction" })
], SdButton.prototype, "formAction", 2);
__decorateClass([
  property({ attribute: "formenctype" })
], SdButton.prototype, "formEnctype", 2);
__decorateClass([
  property({ attribute: "formmethod" })
], SdButton.prototype, "formMethod", 2);
__decorateClass([
  property({ attribute: "formnovalidate", type: Boolean })
], SdButton.prototype, "formNoValidate", 2);
__decorateClass([
  property({ attribute: "formtarget" })
], SdButton.prototype, "formTarget", 2);
__decorateClass([
  watch("disabled", { waitUntilFirstUpdate: true })
], SdButton.prototype, "handleDisabledChange", 1);
SdButton = __decorateClass([
  customElement("sd-6-22-0-button")
], SdButton);

export {
  SdButton
};
