import{textarea_styles_default as t}from"./chunk.HZD5FWDJ.js";import{defaultValue as e}from"./chunk.GI7VDIWX.js";import{FormControlController as i}from"./chunk.GZKNJ77J.js";import{HasSlotController as s}from"./chunk.NYIIDP5N.js";import{watch as l}from"./chunk.C7FWPEOY.js";import{ShoelaceElement as o}from"./chunk.Z7XDKKOD.js";import{__decorateClass as r}from"./chunk.6M63UXML.js";import{classMap as a}from"../../../../lit/directives/class-map.js";import{html as h}from"../../../../lit/index.js";import{ifDefined as n}from"../../../../lit/directives/if-defined.js";import{live as p}from"../../../../lit/directives/live.js";import{property as u,query as d,state as c}from"../../../../lit/decorators.js";var m=class extends o{constructor(){super(...arguments),this.formControlController=new i(this,{assumeInteractionOn:["sl-blur","sl-input"]}),this.hasSlotController=new s(this,"help-text","label"),this.hasFocus=!1,this.title="",this.name="",this.value="",this.size="medium",this.filled=!1,this.label="",this.helpText="",this.placeholder="",this.rows=4,this.resize="vertical",this.disabled=!1,this.readonly=!1,this.form="",this.required=!1,this.spellcheck=!0,this.defaultValue=""}get validity(){return this.input.validity}get validationMessage(){return this.input.validationMessage}connectedCallback(){super.connectedCallback(),this.resizeObserver=new ResizeObserver((()=>this.setTextareaHeight())),this.updateComplete.then((()=>{this.setTextareaHeight(),this.resizeObserver.observe(this.input)}))}firstUpdated(){this.formControlController.updateValidity()}disconnectedCallback(){super.disconnectedCallback(),this.resizeObserver.unobserve(this.input)}handleBlur(){this.hasFocus=!1,this.emit("sl-blur")}handleChange(){this.value=this.input.value,this.setTextareaHeight(),this.emit("sl-change")}handleFocus(){this.hasFocus=!0,this.emit("sl-focus")}handleInput(){this.value=this.input.value,this.emit("sl-input")}handleInvalid(t){this.formControlController.setValidity(!1),this.formControlController.emitInvalidEvent(t)}setTextareaHeight(){"auto"===this.resize?(this.input.style.height="auto",this.input.style.height=`${this.input.scrollHeight}px`):this.input.style.height=void 0}handleDisabledChange(){this.formControlController.setValidity(this.disabled)}handleRowsChange(){this.setTextareaHeight()}async handleValueChange(){await this.updateComplete,this.formControlController.updateValidity(),this.setTextareaHeight()}focus(t){this.input.focus(t)}blur(){this.input.blur()}select(){this.input.select()}scrollPosition(t){return t?("number"==typeof t.top&&(this.input.scrollTop=t.top),void("number"==typeof t.left&&(this.input.scrollLeft=t.left))):{top:this.input.scrollTop,left:this.input.scrollTop}}setSelectionRange(t,e,i="none"){this.input.setSelectionRange(t,e,i)}setRangeText(t,e,i,s){this.input.setRangeText(t,e,i,s),this.value!==this.input.value&&(this.value=this.input.value),this.value!==this.input.value&&(this.value=this.input.value,this.setTextareaHeight())}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(){const t=this.hasSlotController.test("label"),e=this.hasSlotController.test("help-text"),i=!!this.label||!!t,s=!!this.helpText||!!e;return h`
      <div
        part="form-control"
        class=${a({"form-control":!0,"form-control--small":"small"===this.size,"form-control--medium":"medium"===this.size,"form-control--large":"large"===this.size,"form-control--has-label":i,"form-control--has-help-text":s})}
      >
        <label
          part="form-control-label"
          class="form-control__label"
          for="input"
          aria-hidden=${i?"false":"true"}
        >
          <slot name="label">${this.label}</slot>
        </label>

        <div part="form-control-input" class="form-control-input">
          <div
            part="base"
            class=${a({textarea:!0,"textarea--small":"small"===this.size,"textarea--medium":"medium"===this.size,"textarea--large":"large"===this.size,"textarea--standard":!this.filled,"textarea--filled":this.filled,"textarea--disabled":this.disabled,"textarea--focused":this.hasFocus,"textarea--empty":!this.value,"textarea--resize-none":"none"===this.resize,"textarea--resize-vertical":"vertical"===this.resize,"textarea--resize-auto":"auto"===this.resize})}
          >
            <textarea
              part="textarea"
              id="input"
              class="textarea__control"
              title=${this.title}
              name=${n(this.name)}
              .value=${p(this.value)}
              ?disabled=${this.disabled}
              ?readonly=${this.readonly}
              ?required=${this.required}
              placeholder=${n(this.placeholder)}
              rows=${n(this.rows)}
              minlength=${n(this.minlength)}
              maxlength=${n(this.maxlength)}
              autocapitalize=${n(this.autocapitalize)}
              autocorrect=${n(this.autocorrect)}
              ?autofocus=${this.autofocus}
              spellcheck=${n(this.spellcheck)}
              enterkeyhint=${n(this.enterkeyhint)}
              inputmode=${n(this.inputmode)}
              aria-describedby="help-text"
              @change=${this.handleChange}
              @input=${this.handleInput}
              @invalid=${this.handleInvalid}
              @focus=${this.handleFocus}
              @blur=${this.handleBlur}
            ></textarea>
          </div>
        </div>

        <div
          part="form-control-help-text"
          id="help-text"
          class="form-control__help-text"
          aria-hidden=${s?"false":"true"}
        >
          <slot name="help-text">${this.helpText}</slot>
        </div>
      </div>
    `}};m.styles=t,r([d(".textarea__control")],m.prototype,"input",2),r([c()],m.prototype,"hasFocus",2),r([u()],m.prototype,"title",2),r([u()],m.prototype,"name",2),r([u()],m.prototype,"value",2),r([u({reflect:!0})],m.prototype,"size",2),r([u({type:Boolean,reflect:!0})],m.prototype,"filled",2),r([u()],m.prototype,"label",2),r([u({attribute:"help-text"})],m.prototype,"helpText",2),r([u()],m.prototype,"placeholder",2),r([u({type:Number})],m.prototype,"rows",2),r([u()],m.prototype,"resize",2),r([u({type:Boolean,reflect:!0})],m.prototype,"disabled",2),r([u({type:Boolean,reflect:!0})],m.prototype,"readonly",2),r([u({reflect:!0})],m.prototype,"form",2),r([u({type:Boolean,reflect:!0})],m.prototype,"required",2),r([u({type:Number})],m.prototype,"minlength",2),r([u({type:Number})],m.prototype,"maxlength",2),r([u()],m.prototype,"autocapitalize",2),r([u()],m.prototype,"autocorrect",2),r([u()],m.prototype,"autocomplete",2),r([u({type:Boolean})],m.prototype,"autofocus",2),r([u()],m.prototype,"enterkeyhint",2),r([u({type:Boolean,converter:{fromAttribute:t=>!(!t||"false"===t),toAttribute:t=>t?"true":"false"}})],m.prototype,"spellcheck",2),r([u()],m.prototype,"inputmode",2),r([e()],m.prototype,"defaultValue",2),r([l("disabled",{waitUntilFirstUpdate:!0})],m.prototype,"handleDisabledChange",1),r([l("rows",{waitUntilFirstUpdate:!0})],m.prototype,"handleRowsChange",1),r([l("value",{waitUntilFirstUpdate:!0})],m.prototype,"handleValueChange",1);export{m as SlTextarea};