import{g as ne,p as le,ai as oe,F as y,r as x,aq as ue,aX as ie,o as re,w as f,e as se,u as ce,ar as de,c as k,x as r,R as S,O as N,Z as G,c2 as fe,b as ve,a2 as B,aS as me,aT as xe,bc as ge}from"./index-C5GbdPxY.js";import{b as he,d as D,g as E,h as we,i as Ve,j as ye,c as Ce}from"./VTextField-DxEUpn3-.js";import{f as Fe}from"./forwardRefs-CB8NoG9r.js";import{I as U}from"./VImg-BlqLjeEy.js";const Pe=le({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,...Ce(),...ye()},"VTextarea"),Se=ne()({name:"VTextarea",directives:{vIntersect:U},inheritAttrs:!1,props:Pe(),emits:{"click:control":e=>!0,"mousedown:control":e=>!0,"update:focused":e=>!0,"update:modelValue":e=>!0,"update:rows":e=>!0},setup(e,O){let{attrs:C,emit:F,slots:l}=O;const a=oe(e,"modelValue"),{isFocused:v,focus:j,blur:$}=he(e),{onIntersect:p}=Ve(e),q=y(()=>typeof e.counterValue=="function"?e.counterValue(a.value):(a.value||"").toString().length),X=y(()=>{if(C.maxlength)return C.maxlength;if(!(!e.counter||typeof e.counter!="number"&&typeof e.counter!="string"))return e.counter}),M=x(),g=x(),z=ue(""),h=x(),Z=y(()=>e.persistentPlaceholder||v.value||e.active);function P(){var t;h.value!==document.activeElement&&((t=h.value)==null||t.focus()),v.value||j()}function J(t){P(),F("click:control",t)}function K(t){F("mousedown:control",t)}function L(t){t.stopPropagation(),P(),B(()=>{a.value="",ge(e["onClick:clear"],t)})}function Q(t){var u;const n=t.target;if(a.value=n.value,(u=e.modelModifiers)!=null&&u.trim){const d=[n.selectionStart,n.selectionEnd];B(()=>{n.selectionStart=d[0],n.selectionEnd=d[1]})}}const s=x(),m=x(Number(e.rows)),b=y(()=>["plain","underlined"].includes(e.variant));ie(()=>{e.autoGrow||(m.value=Number(e.rows))});function c(){e.autoGrow&&B(()=>{if(!s.value||!g.value)return;const t=getComputedStyle(s.value),n=getComputedStyle(g.value.$el),u=parseFloat(t.getPropertyValue("--v-field-padding-top"))+parseFloat(t.getPropertyValue("--v-input-padding-top"))+parseFloat(t.getPropertyValue("--v-field-padding-bottom")),d=s.value.scrollHeight,w=parseFloat(t.lineHeight),I=Math.max(parseFloat(e.rows)*w+u,parseFloat(n.getPropertyValue("--v-input-control-height"))),R=parseFloat(e.maxRows)*w+u||1/0,i=xe(d??0,I,R);m.value=Math.floor((i-u)/w),z.value=me(i)})}re(c),f(a,c),f(()=>e.rows,c),f(()=>e.maxRows,c),f(()=>e.density,c),f(m,t=>{F("update:rows",t)});let o;return f(s,t=>{t?(o=new ResizeObserver(c),o.observe(s.value)):o==null||o.disconnect()}),se(()=>{o==null||o.disconnect()}),ce(()=>{const t=!!(l.counter||e.counter||e.counterValue),n=!!(t||l.details),[u,d]=de(C),{modelValue:w,...I}=D.filterProps(e),R=E.filterProps(e);return k(D,N({ref:M,modelValue:a.value,"onUpdate:modelValue":i=>a.value=i,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":b.value},e.class],style:e.style},u,I,{centerAffix:m.value===1&&!b.value,focused:v.value}),{...l,default:i=>{let{id:V,isDisabled:A,isDirty:H,isReadonly:W,isValid:Y,hasDetails:ee}=i;return k(E,N({ref:g,style:{"--v-textarea-control-height":z.value},onClick:J,onMousedown:K,"onClick:clear":L,"onClick:prependInner":e["onClick:prependInner"],"onClick:appendInner":e["onClick:appendInner"]},R,{id:V.value,active:Z.value||H.value,centerAffix:m.value===1&&!b.value,dirty:H.value||e.dirty,disabled:A.value,focused:v.value,details:ee.value,error:Y.value===!1}),{...l,default:te=>{let{props:{class:T,..._}}=te;return r(S,null,[e.prefix&&r("span",{class:"v-text-field__prefix"},[e.prefix]),G(r("textarea",N({ref:h,class:T,value:a.value,onInput:Q,autofocus:e.autofocus,readonly:W.value,disabled:A.value,placeholder:e.placeholder,rows:e.rows,name:e.name,onFocus:P,onBlur:$},_,d),null),[[U,{handler:p},null,{once:!0}]]),e.autoGrow&&G(r("textarea",{class:ve([T,"v-textarea__sizer"]),id:`${_.id}-sizer`,"onUpdate:modelValue":ae=>a.value=ae,ref:s,readonly:!0,"aria-hidden":"true"},null),[[fe,a.value]]),e.suffix&&r("span",{class:"v-text-field__suffix"},[e.suffix])])}})},details:n?i=>{var V;return r(S,null,[(V=l.details)==null?void 0:V.call(l,i),t&&r(S,null,[r("span",null,null),k(we,{active:e.persistentCounter||v.value,value:q.value,max:X.value,disabled:e.disabled},l.counter)])])}:void 0})}),Fe({},M,g,h)}});export{Se as V};
