import{ad as ae,bi as ne,al as ue,cL as ie,z as r,cW as N,r as I,ao as oe,ap as se,M as re,ae as ce,au as de,af as fe,cX as ve,cq as me,aJ as x,cm as pe,cn as T,cY as $,i,F as b,cZ as ge,D as C,as as he,c_ as ye}from"./index-N7CMQwFv.js";import{V as Ie}from"./VChip-iaVLrPY0.js";const be=fe({chips:Boolean,counter:Boolean,counterSizeString:{type:String,default:"$vuetify.fileInput.counterSize"},counterString:{type:String,default:"$vuetify.fileInput.counter"},hideInput:Boolean,multiple:Boolean,showSize:{type:[Boolean,Number,String],default:!1,validator:e=>typeof e=="boolean"||[1e3,1024].includes(Number(e))},...me({prependIcon:"$file"}),modelValue:{type:[Array,Object],default:e=>e.multiple?[]:null,validator:e=>x(e).every(d=>d!=null&&typeof d=="object")},...ve({clearable:!0})},"VFileInput"),Ve=ae()({name:"VFileInput",inheritAttrs:!1,props:be(),emits:{"click:control":e=>!0,"mousedown:control":e=>!0,"update:focused":e=>!0,"update:modelValue":e=>!0},setup(e,d){let{attrs:E,emit:k,slots:n}=d;const{t:V}=ne(),u=ue(e,"modelValue",e.modelValue,t=>x(t),t=>!e.multiple&&Array.isArray(t)?t[0]:t),{isFocused:f,focus:j,blur:L}=ie(e),D=r(()=>typeof e.showSize!="boolean"?e.showSize:void 0),P=r(()=>(u.value??[]).reduce((t,l)=>{let{size:o=0}=l;return t+o},0)),S=r(()=>N(P.value,D.value)),g=r(()=>(u.value??[]).map(t=>{const{name:l="",size:o=0}=t;return e.showSize?`${l} (${N(o,D.value)})`:l})),O=r(()=>{var l;const t=((l=u.value)==null?void 0:l.length)??0;return e.showSize?V(e.counterSizeString,t,S.value):V(e.counterString,t)}),F=I(),w=I(),a=I(),_=oe(()=>f.value||e.active),z=r(()=>["plain","underlined"].includes(e.variant)),v=se(!1);function h(){var t;a.value!==document.activeElement&&((t=a.value)==null||t.focus()),f.value||j()}function q(t){var l;(l=a.value)==null||l.click()}function J(t){k("mousedown:control",t)}function U(t){var l;(l=a.value)==null||l.click(),k("click:control",t)}function W(t){t.stopPropagation(),h(),he(()=>{u.value=[],ye(e["onClick:clear"],t)})}function X(t){t.preventDefault(),t.stopImmediatePropagation(),v.value=!0}function Y(t){t.preventDefault(),v.value=!1}function Z(t){var o,m;if(t.preventDefault(),t.stopImmediatePropagation(),v.value=!1,!((m=(o=t.dataTransfer)==null?void 0:o.files)!=null&&m.length)||!a.value)return;const l=new DataTransfer;for(const R of t.dataTransfer.files)l.items.add(R);a.value.files=l.files,a.value.dispatchEvent(new Event("change",{bubbles:!0}))}return re(u,t=>{(!Array.isArray(t)||!t.length)&&a.value&&(a.value.value="")}),ce(()=>{const t=!!(n.counter||e.counter),l=!!(t||n.details),[o,m]=pe(E),{modelValue:R,...G}=T.filterProps(e),H=$.filterProps(e);return i(T,C({ref:F,modelValue:e.multiple?u.value:u.value[0],class:["v-file-input",{"v-file-input--chips":!!e.chips,"v-file-input--dragging":v.value,"v-file-input--hide":e.hideInput,"v-input--plain-underlined":z.value},e.class],style:e.style,"onClick:prepend":q},o,G,{centerAffix:!z.value,focused:f.value}),{...n,default:y=>{let{id:p,isDisabled:c,isDirty:A,isReadonly:B,isValid:K}=y;return i($,C({ref:w,"prepend-icon":e.prependIcon,onMousedown:J,onClick:U,"onClick:clear":W,"onClick:prependInner":e["onClick:prependInner"],"onClick:appendInner":e["onClick:appendInner"]},H,{id:p.value,active:_.value||A.value,dirty:A.value||e.dirty,disabled:c.value,focused:f.value,error:K.value===!1,onDragover:X,onDrop:Z}),{...n,default:Q=>{var M;let{props:{class:ee,...te}}=Q;return i(b,null,[i("input",C({ref:a,type:"file",readonly:B.value,disabled:c.value,multiple:e.multiple,name:e.name,onClick:s=>{s.stopPropagation(),B.value&&s.preventDefault(),h()},onChange:s=>{if(!s.target)return;const le=s.target;u.value=[...le.files??[]]},onDragleave:Y,onFocus:h,onBlur:L},te,m),null),i("div",{class:ee},[!!((M=u.value)!=null&&M.length)&&!e.hideInput&&(n.selection?n.selection({fileNames:g.value,totalBytes:P.value,totalBytesReadable:S.value}):e.chips?g.value.map(s=>i(Ie,{key:s,size:"small",text:s},null)):g.value.join(", "))])])}})},details:l?y=>{var p,c;return i(b,null,[(p=n.details)==null?void 0:p.call(n,y),t&&i(b,null,[i("span",null,null),i(ge,{active:!!((c=u.value)!=null&&c.length),value:O.value,disabled:e.disabled},n.counter)])])}:void 0})}),de({},F,w,a)}});export{Ve as V};