import{g as ee,p as te,a1 as ae,f as y,r as v,s as ne,w as le,a7 as oe,a3 as m,aZ as ue,j as ie,at as re,k as l,H as I,S as R,ap as _,aB as se,be as ce,av as de,a8 as S,l as fe,b6 as ve,aw as me}from"./index-g0hxAASb.js";import{u as xe,b as G,c as D,d as ge,e as he,m as we}from"./VTextField-CThd_nQC.js";import{I as Ve}from"./VRow-BC7GmtAs.js";const ye=te({autoGrow:Boolean,autofocus:Boolean,counter:[Boolean,Number,String],counterValue:Function,prefix:String,placeholder:String,persistentPlaceholder:Boolean,persistentCounter:Boolean,noResize:Boolean,rows:{type:[Number,String],default:5,validator:e=>!isNaN(parseFloat(e))},maxRows:{type:[Number,String],validator:e=>!isNaN(parseFloat(e))},suffix:String,modelModifiers:Object,...we(),...he()},"VTextarea"),be=ee()({name:"VTextarea",directives:{Intersect:Ve},inheritAttrs:!1,props:ye(),emits:{"click:control":e=>!0,"mousedown:control":e=>!0,"update:focused":e=>!0,"update:modelValue":e=>!0},setup(e,E){let{attrs:C,emit:N,slots:i}=E;const o=ae(e,"modelValue"),{isFocused:f,focus:U,blur:O}=xe(e),j=y(()=>typeof e.counterValue=="function"?e.counterValue(o.value):(o.value||"").toString().length),$=y(()=>{if(C.maxlength)return C.maxlength;if(!(!e.counter||typeof e.counter!="number"&&typeof e.counter!="string"))return e.counter});function Z(t,n){var a,u;!e.autofocus||!t||(u=(a=n[0].target)==null?void 0:a.focus)==null||u.call(a)}const B=v(),x=v(),H=ne(""),g=v(),q=y(()=>e.persistentPlaceholder||f.value||e.active);function F(){var t;g.value!==document.activeElement&&((t=g.value)==null||t.focus()),f.value||U()}function J(t){F(),N("click:control",t)}function K(t){N("mousedown:control",t)}function L(t){t.stopPropagation(),F(),S(()=>{o.value="",me(e["onClick:clear"],t)})}function Q(t){var a;const n=t.target;if(o.value=n.value,(a=e.modelModifiers)!=null&&a.trim){const u=[n.selectionStart,n.selectionEnd];S(()=>{n.selectionStart=u[0],n.selectionEnd=u[1]})}}const c=v(),h=v(Number(e.rows)),P=y(()=>["plain","underlined"].includes(e.variant));le(()=>{e.autoGrow||(h.value=Number(e.rows))});function d(){e.autoGrow&&S(()=>{if(!c.value||!x.value)return;const t=getComputedStyle(c.value),n=getComputedStyle(x.value.$el),a=parseFloat(t.getPropertyValue("--v-field-padding-top"))+parseFloat(t.getPropertyValue("--v-input-padding-top"))+parseFloat(t.getPropertyValue("--v-field-padding-bottom")),u=c.value.scrollHeight,w=parseFloat(t.lineHeight),b=Math.max(parseFloat(e.rows)*w+a,parseFloat(n.getPropertyValue("--v-input-control-height"))),k=parseFloat(e.maxRows)*w+a||1/0,s=ve(u??0,b,k);h.value=Math.floor((s-a)/w),H.value=fe(s)})}oe(d),m(o,d),m(()=>e.rows,d),m(()=>e.maxRows,d),m(()=>e.density,d);let r;return m(c,t=>{t?(r=new ResizeObserver(d),r.observe(c.value)):r==null||r.disconnect()}),ue(()=>{r==null||r.disconnect()}),ie(()=>{const t=!!(i.counter||e.counter||e.counterValue),n=!!(t||i.details),[a,u]=re(C),{modelValue:w,...b}=G.filterProps(e),k=D.filterProps(e);return l(G,R({ref:B,modelValue:o.value,"onUpdate:modelValue":s=>o.value=s,class:["v-textarea v-text-field",{"v-textarea--prefixed":e.prefix,"v-textarea--suffixed":e.suffix,"v-text-field--prefixed":e.prefix,"v-text-field--suffixed":e.suffix,"v-textarea--auto-grow":e.autoGrow,"v-textarea--no-resize":e.noResize||e.autoGrow,"v-input--plain-underlined":P.value},e.class],style:e.style},a,b,{centerAffix:h.value===1&&!P.value,focused:f.value}),{...i,default:s=>{let{id:V,isDisabled:M,isDirty:z,isReadonly:W,isValid:X}=s;return l(D,R({ref:x,style:{"--v-textarea-control-height":H.value},onClick:J,onMousedown:K,"onClick:clear":L,"onClick:prependInner":e["onClick:prependInner"],"onClick:appendInner":e["onClick:appendInner"]},k,{id:V.value,active:q.value||z.value,centerAffix:h.value===1&&!P.value,dirty:z.value||e.dirty,disabled:M.value,focused:f.value,error:X.value===!1}),{...i,default:Y=>{let{props:{class:A,...T}}=Y;return l(I,null,[e.prefix&&l("span",{class:"v-text-field__prefix"},[e.prefix]),_(l("textarea",R({ref:g,class:A,value:o.value,onInput:Q,autofocus:e.autofocus,readonly:W.value,disabled:M.value,placeholder:e.placeholder,rows:e.rows,name:e.name,onFocus:F,onBlur:O},T,u),null),[[se("intersect"),{handler:Z},null,{once:!0}]]),e.autoGrow&&_(l("textarea",{class:[A,"v-textarea__sizer"],id:`${T.id}-sizer`,"onUpdate:modelValue":p=>o.value=p,ref:c,readonly:!0,"aria-hidden":"true"},null),[[ce,o.value]]),e.suffix&&l("span",{class:"v-text-field__suffix"},[e.suffix])])}})},details:n?s=>{var V;return l(I,null,[(V=i.details)==null?void 0:V.call(i,s),t&&l(I,null,[l("span",null,null),l(ge,{active:e.persistentCounter||f.value,value:j.value,max:$.value,disabled:e.disabled},i.counter)])])}:void 0})}),de({},B,x,g)}});export{be as V};
