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