import{defineComponent as H,computed as f,ref as r,onMounted as g,nextTick as B,onBeforeUnmount as T,watchEffect as L,toRef as k,createVNode as h}from"vue";import N from"../../_util/classNames.mjs";import D from"../../vc-util/Dom/addEventListener.mjs";import E from"../ColGroup.mjs";import{useInjectTable as F}from"../context/TableContext.mjs";function R(t,m){return f(()=>{const u=[],d=t.value,n=m.value;for(let l=0;l<n;l+=1){const a=d[l];if(a!==void 0)u[l]=a;else return null}return u})}const I=H({name:"FixedHolder",inheritAttrs:!1,props:["columns","flattenColumns","stickyOffsets","customHeaderRow","noData","maxContentScroll","colWidths","columCount","direction","fixHeader","stickyTopOffset","stickyBottomOffset","stickyClassName"],emits:["scroll"],setup(t,{attrs:m,slots:u,emit:d}){const n=F(),l=f(()=>n.isSticky&&!t.fixHeader?0:n.scrollbarSize),a=r(),S=e=>{const{currentTarget:o,deltaX:s}=e;s&&(d("scroll",{currentTarget:o,scrollLeft:o.scrollLeft+s}),e.preventDefault())},y=r();g(()=>{B(()=>{y.value=D(a.value,"wheel",S)})}),T(()=>{y.value?.remove()});const b=f(()=>t.flattenColumns.every(e=>e.width&&e.width!==0&&e.width!=="0px")),x=r([]),v=r([]);L(()=>{const e=t.flattenColumns[t.flattenColumns.length-1],o={fixed:e?e.fixed:null,scrollbar:!0,customHeaderCell:()=>({class:`${n.prefixCls}-cell-scrollbar`})};x.value=l.value?[...t.columns,o]:t.columns,v.value=l.value?[...t.flattenColumns,o]:t.flattenColumns});const W=f(()=>{const{stickyOffsets:e,direction:o}=t,{right:s,left:i}=e;return{...e,left:o==="rtl"?[...i.map(c=>c+l.value),0]:i,right:o==="rtl"?s:[...s.map(c=>c+l.value),0],isSticky:n.isSticky}}),C=R(k(t,"colWidths"),k(t,"columCount"));return()=>{const{noData:e,columCount:o,stickyTopOffset:s,stickyBottomOffset:i,stickyClassName:c,maxContentScroll:w}=t,{isSticky:O}=n;return h("div",{style:{overflow:"hidden",...O?{top:`${s}px`,bottom:`${i}px`}:{}},ref:a,class:N(m.class,{[c]:!!c})},[h("table",{style:{tableLayout:"fixed",visibility:e||C.value?null:"hidden"}},[(!e||!w||b.value)&&h(E,{colWidths:C.value?[...C.value,l.value]:[],columCount:o+1,columns:v.value},null),u.default?.({...t,stickyOffsets:W.value,columns:x.value,flattenColumns:v.value})])])}}});export{I as default};
