const e=require("../_util/classNames.js"),t=require("../vc-resize-observer/index.js"),n=require("../_util/vue-types/index.js"),r=require("./Item.js"),i=require("./context.js"),a=require("./RawItem.js");let o=require("vue");var s=`responsive`,c=`invalidate`;function l(e){return`+ ${e.length} ...`}var u=(0,o.defineComponent)({name:`Overflow`,inheritAttrs:!1,props:{id:String,prefixCls:String,data:Array,itemKey:[String,Number,Function],itemWidth:{type:Number,default:10},renderItem:Function,renderRawItem:Function,maxCount:[Number,String],renderRest:Function,renderRawRest:Function,suffix:n.default.any,component:String,itemComponent:n.default.any,onVisibleChange:Function,ssr:String,onMousedown:Function,role:String},emits:[`visibleChange`],setup(n,{attrs:a,emit:u,slots:d}){let f=(0,o.computed)(()=>n.ssr===`full`),p=(0,o.shallowRef)(null),m=(0,o.computed)(()=>p.value||0),h=(0,o.shallowRef)(new Map),g=(0,o.shallowRef)(0),_=(0,o.shallowRef)(0),v=(0,o.shallowRef)(0),y=(0,o.shallowRef)(null),b=(0,o.shallowRef)(null),x=(0,o.computed)(()=>b.value===null&&f.value?2**53-1:b.value||0),S=(0,o.shallowRef)(!1),C=(0,o.computed)(()=>`${n.prefixCls}-item`),w=(0,o.computed)(()=>Math.max(g.value,_.value)),T=(0,o.computed)(()=>!!(n.data.length&&n.maxCount===s)),E=(0,o.computed)(()=>n.maxCount===c),D=(0,o.computed)(()=>T.value||typeof n.maxCount==`number`&&n.data.length>n.maxCount),O=(0,o.computed)(()=>{let e=n.data;return T.value?e=p.value===null&&f.value?n.data:n.data.slice(0,Math.min(n.data.length,m.value/n.itemWidth)):typeof n.maxCount==`number`&&(e=n.data.slice(0,n.maxCount)),e}),k=(0,o.computed)(()=>T.value?n.data.slice(x.value+1):n.data.slice(O.value.length)),A=(e,t)=>typeof n.itemKey==`function`?n.itemKey(e):(n.itemKey&&e?.[n.itemKey])??t,j=(0,o.computed)(()=>n.renderItem||(e=>e)),M=(e,t)=>{b.value=e,t||(S.value=e<n.data.length-1,u(`visibleChange`,e))},N=(e,t)=>{p.value=t.clientWidth},P=(e,t)=>{let n=new Map(h.value);t===null?n.delete(e):n.set(e,t),h.value=n},F=(e,t)=>{g.value=_.value,_.value=t},I=(e,t)=>{v.value=t},L=e=>h.value.get(A(O.value[e],e));return(0,o.watch)([m,h,_,v,()=>n.itemKey,O],()=>{if(m.value&&w.value&&O.value){let e=v.value,t=O.value.length,r=t-1;if(!t){M(0),y.value=null;return}for(let n=0;n<t;n+=1){let t=L(n);if(t===void 0){M(n-1,!0);break}if(e+=t,r===0&&e<=m.value||n===r-1&&e+L(r)<=m.value){M(r),y.value=null;break}else if(e+w.value>m.value){M(n-1),y.value=e-t-v.value+_.value;break}}n.suffix&&L(0)+v.value>m.value&&(y.value=null)}}),()=>{let s=S.value&&!!k.value.length,{itemComponent:c,renderRawItem:u,renderRawRest:f,renderRest:p,prefixCls:m=`rc-overflow`,suffix:h,component:g=`div`,id:_,onMousedown:v}=n,{class:b,style:w,...M}=a,L={};y.value!==null&&T.value&&(L={position:`absolute`,left:`${y.value}px`,top:0});let R={prefixCls:C.value,responsive:T.value,component:c,invalidate:E.value},z=u?(e,t)=>{let n=A(e,t);return(0,o.createVNode)(i.OverflowContextProvider,{key:n,value:{...R,order:t,item:e,itemKey:n,registerSize:P,display:t<=x.value}},{default:()=>[u(e,t)]})}:(e,t)=>{let n=A(e,t);return(0,o.createVNode)(r.default,{...R,order:t,key:n,item:e,renderItem:j.value,itemKey:n,registerSize:P,display:t<=x.value},null)},B=()=>null,V={order:s?x.value:2**53-1,className:`${C.value} ${C.value}-rest`,registerSize:F,display:s};if(f)f&&(B=()=>(0,o.createVNode)(i.OverflowContextProvider,{value:{...R,...V}},{default:()=>[f(k.value)]}));else{let e=p||l;B=()=>(0,o.createVNode)(r.default,{...R,...V},{default:()=>typeof e==`function`?e(k.value):e})}return(0,o.createVNode)(t.default,{disabled:!T.value,onResize:N},{default:()=>(0,o.createVNode)(g,{id:_,class:e.default(!E.value&&m,b),style:w,onMousedown:v,role:n.role,...M},{default:()=>[O.value.map(z),D.value?B():null,h&&(0,o.createVNode)(r.default,{...R,order:x.value,class:`${C.value}-suffix`,registerSize:I,display:!0,style:L},{default:()=>h}),d.default?.()]})})}}});u.Item=a.default,u.RESPONSIVE=s,u.INVALIDATE=c,exports.default=u;