import{SlSpinner as t}from"./chunk.JPV2F5NK.js";import{FormControlController as o,validValidityState as i}from"./chunk.GZKNJ77J.js";import{button_styles_default as e}from"./chunk.VXRBGRCD.js";import{LocalizeController as r}from"./chunk.2A3352EO.js";import{HasSlotController as s}from"./chunk.NYIIDP5N.js";import{SlIcon as l}from"./chunk.M4HIRIJ5.js";import{watch as n}from"./chunk.C7FWPEOY.js";import{ShoelaceElement as a}from"./chunk.Z7XDKKOD.js";import{__decorateClass as h}from"./chunk.6M63UXML.js";import{classMap as u}from"../../../../lit/directives/class-map.js";import{html as p,literal as d}from"../../../../lit/static-html.js";import{ifDefined as c}from"../../../../lit/directives/if-defined.js";import{property as f,query as m,state as b}from"../../../../lit/decorators.js";var y=class extends a{constructor(){super(...arguments),this.formControlController=new o(this,{form:t=>{if(t.hasAttribute("form")){const o=t.getRootNode(),i=t.getAttribute("form");return o.getElementById(i)}return t.closest("form")},assumeInteractionOn:["click"]}),this.hasSlotController=new s(this,"[default]","prefix","suffix"),this.localize=new r(this),this.hasFocus=!1,this.invalid=!1,this.title="",this.variant="default",this.size="medium",this.caret=!1,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.rel="noreferrer noopener"}get validity(){return this.isButton()?this.button.validity:i}get validationMessage(){return this.isButton()?this.button.validationMessage:""}firstUpdated(){this.isButton()&&this.formControlController.updateValidity()}handleBlur(){this.hasFocus=!1,this.emit("sl-blur")}handleFocus(){this.hasFocus=!0,this.emit("sl-focus")}handleClick(){"submit"===this.type&&this.formControlController.submit(this),"reset"===this.type&&this.formControlController.reset(this)}handleInvalid(t){this.formControlController.setValidity(!1),this.formControlController.emitInvalidEvent(t)}isButton(){return!this.href}isLink(){return!!this.href}handleDisabledChange(){this.isButton()&&this.formControlController.setValidity(this.disabled)}click(){this.button.click()}focus(t){this.button.focus(t)}blur(){this.button.blur()}checkValidity(){return!this.isButton()||this.button.checkValidity()}getForm(){return this.formControlController.getForm()}reportValidity(){return!this.isButton()||this.button.reportValidity()}setCustomValidity(t){this.isButton()&&(this.button.setCustomValidity(t),this.formControlController.updateValidity())}render(){const t=this.isLink(),o=t?d`a`:d`button`;return p`
      <${o}
        part="base"
        class=${u({button:!0,"button--default":"default"===this.variant,"button--primary":"primary"===this.variant,"button--success":"success"===this.variant,"button--neutral":"neutral"===this.variant,"button--warning":"warning"===this.variant,"button--danger":"danger"===this.variant,"button--text":"text"===this.variant,"button--small":"small"===this.size,"button--medium":"medium"===this.size,"button--large":"large"===this.size,"button--caret":this.caret,"button--circle":this.circle,"button--disabled":this.disabled,"button--focused":this.hasFocus,"button--loading":this.loading,"button--standard":!this.outline,"button--outline":this.outline,"button--pill":this.pill,"button--rtl":"rtl"===this.localize.dir(),"button--has-label":this.hasSlotController.test("[default]"),"button--has-prefix":this.hasSlotController.test("prefix"),"button--has-suffix":this.hasSlotController.test("suffix")})}
        ?disabled=${c(t?void 0:this.disabled)}
        type=${c(t?void 0:this.type)}
        title=${this.title}
        name=${c(t?void 0:this.name)}
        value=${c(t?void 0:this.value)}
        href=${c(t?this.href:void 0)}
        target=${c(t?this.target:void 0)}
        download=${c(t?this.download:void 0)}
        rel=${c(t?this.rel:void 0)}
        role=${c(t?void 0:"button")}
        aria-disabled=${this.disabled?"true":"false"}
        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>
        <slot part="label" class="button__label"></slot>
        <slot name="suffix" part="suffix" class="button__suffix"></slot>
        ${this.caret?p` <sl-icon part="caret" class="button__caret" library="system" name="caret"></sl-icon> `:""}
        ${this.loading?p`<sl-spinner part="spinner"></sl-spinner>`:""}
      </${o}>
    `}};y.styles=e,y.dependencies={"sl-icon":l,"sl-spinner":t},h([m(".button")],y.prototype,"button",2),h([b()],y.prototype,"hasFocus",2),h([b()],y.prototype,"invalid",2),h([f()],y.prototype,"title",2),h([f({reflect:!0})],y.prototype,"variant",2),h([f({reflect:!0})],y.prototype,"size",2),h([f({type:Boolean,reflect:!0})],y.prototype,"caret",2),h([f({type:Boolean,reflect:!0})],y.prototype,"disabled",2),h([f({type:Boolean,reflect:!0})],y.prototype,"loading",2),h([f({type:Boolean,reflect:!0})],y.prototype,"outline",2),h([f({type:Boolean,reflect:!0})],y.prototype,"pill",2),h([f({type:Boolean,reflect:!0})],y.prototype,"circle",2),h([f()],y.prototype,"type",2),h([f()],y.prototype,"name",2),h([f()],y.prototype,"value",2),h([f()],y.prototype,"href",2),h([f()],y.prototype,"target",2),h([f()],y.prototype,"rel",2),h([f()],y.prototype,"download",2),h([f()],y.prototype,"form",2),h([f({attribute:"formaction"})],y.prototype,"formAction",2),h([f({attribute:"formenctype"})],y.prototype,"formEnctype",2),h([f({attribute:"formmethod"})],y.prototype,"formMethod",2),h([f({attribute:"formnovalidate",type:Boolean})],y.prototype,"formNoValidate",2),h([f({attribute:"formtarget"})],y.prototype,"formTarget",2),h([n("disabled",{waitUntilFirstUpdate:!0})],y.prototype,"handleDisabledChange",1);export{y as SlButton};