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