import{switch_styles_default as t}from"./chunk.OBB4I6GS.js";import{defaultValue as e}from"./chunk.GI7VDIWX.js";import{FormControlController as i}from"./chunk.GZKNJ77J.js";import{watch as s}from"./chunk.C7FWPEOY.js";import{ShoelaceElement as l}from"./chunk.Z7XDKKOD.js";import{__decorateClass as r}from"./chunk.6M63UXML.js";import{classMap as h}from"../../../../lit/directives/class-map.js";import{html as o}from"../../../../lit/index.js";import{ifDefined as a}from"../../../../lit/directives/if-defined.js";import{live as c}from"../../../../lit/directives/live.js";import{property as d,query as n,state as p}from"../../../../lit/decorators.js";var u=class extends l{constructor(){super(...arguments),this.formControlController=new i(this,{value:t=>t.checked?t.value||"on":void 0,defaultValue:t=>t.defaultChecked,setValue:(t,e)=>t.checked=e}),this.hasFocus=!1,this.title="",this.name="",this.size="medium",this.disabled=!1,this.checked=!1,this.defaultChecked=!1,this.form="",this.required=!1}get validity(){return this.input.validity}get validationMessage(){return this.input.validationMessage}firstUpdated(){this.formControlController.updateValidity()}handleBlur(){this.hasFocus=!1,this.emit("sl-blur")}handleInput(){this.emit("sl-input")}handleInvalid(t){this.formControlController.setValidity(!1),this.formControlController.emitInvalidEvent(t)}handleClick(){this.checked=!this.checked,this.emit("sl-change")}handleFocus(){this.hasFocus=!0,this.emit("sl-focus")}handleKeyDown(t){"ArrowLeft"===t.key&&(t.preventDefault(),this.checked=!1,this.emit("sl-change"),this.emit("sl-input")),"ArrowRight"===t.key&&(t.preventDefault(),this.checked=!0,this.emit("sl-change"),this.emit("sl-input"))}handleCheckedChange(){this.input.checked=this.checked,this.formControlController.updateValidity()}handleDisabledChange(){this.formControlController.setValidity(!0)}click(){this.input.click()}focus(t){this.input.focus(t)}blur(){this.input.blur()}checkValidity(){return this.input.checkValidity()}getForm(){return this.formControlController.getForm()}reportValidity(){return this.input.reportValidity()}setCustomValidity(t){this.input.setCustomValidity(t),this.formControlController.updateValidity()}render(){return o`
      <label
        part="base"
        class=${h({switch:!0,"switch--checked":this.checked,"switch--disabled":this.disabled,"switch--focused":this.hasFocus,"switch--small":"small"===this.size,"switch--medium":"medium"===this.size,"switch--large":"large"===this.size})}
      >
        <input
          class="switch__input"
          type="checkbox"
          title=${this.title}
          name=${this.name}
          value=${a(this.value)}
          .checked=${c(this.checked)}
          .disabled=${this.disabled}
          .required=${this.required}
          role="switch"
          aria-checked=${this.checked?"true":"false"}
          @click=${this.handleClick}
          @input=${this.handleInput}
          @invalid=${this.handleInvalid}
          @blur=${this.handleBlur}
          @focus=${this.handleFocus}
          @keydown=${this.handleKeyDown}
        />

        <span part="control" class="switch__control">
          <span part="thumb" class="switch__thumb"></span>
        </span>

        <slot part="label" class="switch__label"></slot>
      </label>
    `}};u.styles=t,r([n('input[type="checkbox"]')],u.prototype,"input",2),r([p()],u.prototype,"hasFocus",2),r([d()],u.prototype,"title",2),r([d()],u.prototype,"name",2),r([d()],u.prototype,"value",2),r([d({reflect:!0})],u.prototype,"size",2),r([d({type:Boolean,reflect:!0})],u.prototype,"disabled",2),r([d({type:Boolean,reflect:!0})],u.prototype,"checked",2),r([e("checked")],u.prototype,"defaultChecked",2),r([d({reflect:!0})],u.prototype,"form",2),r([d({type:Boolean,reflect:!0})],u.prototype,"required",2),r([s("checked",{waitUntilFirstUpdate:!0})],u.prototype,"handleCheckedChange",1),r([s("disabled",{waitUntilFirstUpdate:!0})],u.prototype,"handleDisabledChange",1);export{u as SlSwitch};