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