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