"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("vue"),z=require("../_util/classNames.js"),w=require("../_util/getScrollBarSize.js"),S=require("../vc-util/Dom/addEventListener.js"),b=require("../vc-util/Dom/css.js"),T=require("./context/TableContext.js"),W=require("./hooks/useFrame.js"),k=l.defineComponent({name:"StickyScrollBar",inheritAttrs:!1,props:["offsetScroll","container","scrollBodyRef","scrollBodySizeInfo"],emits:["scroll"],setup(t,{emit:L,expose:x}){const g=T.useInjectTable(),c=l.shallowRef(0),s=l.shallowRef(0),u=l.shallowRef(0);l.watchEffect(()=>{c.value=t.scrollBodySizeInfo.scrollWidth||0,s.value=t.scrollBodySizeInfo.clientWidth||0,u.value=c.value&&s.value*(s.value/c.value)},{flush:"post"});const M=l.shallowRef(),[f,d]=W.useLayoutState({scrollLeft:0,isHiddenScrollBar:!0}),i=l.ref({delta:0,x:0}),a=l.shallowRef(!1),R=()=>{a.value=!1},H=e=>{i.value={delta:e.pageX-f.value.scrollLeft,x:0},a.value=!0,e.preventDefault()},$=e=>{const{buttons:n}=e||window?.event;if(!a.value||n===0){a.value&&(a.value=!1);return}let o=i.value.x+e.pageX-i.value.x-i.value.delta;o<=0&&(o=0),o+u.value>=s.value&&(o=s.value-u.value),L("scroll",{scrollLeft:o/s.value*(c.value+2)}),i.value.x=e.pageX},v=()=>{if(!t.scrollBodyRef.value)return;const e=b.getOffset(t.scrollBodyRef.value).top,n=e+t.scrollBodyRef.value.offsetHeight,o=t.container===window?document.documentElement.scrollTop+window.innerHeight:b.getOffset(t.container).top+t.container.clientHeight;n-w.default()<=o||e>=o-t.offsetScroll?d(r=>({...r,isHiddenScrollBar:!0})):d(r=>({...r,isHiddenScrollBar:!1}))};x({setScrollLeft:e=>{d(n=>({...n,scrollLeft:e/c.value*s.value||0}))}});let h=null,y=null,B=null,m=null;l.onMounted(()=>{h=S.default(document.body,"mouseup",R,!1),y=S.default(document.body,"mousemove",$,!1),B=S.default(window,"resize",v,!1)}),l.onActivated(()=>{l.nextTick(()=>{v()})}),l.onMounted(()=>{setTimeout(()=>{l.watch([u,a],()=>{v()},{immediate:!0,flush:"post"})})}),l.watch(()=>t.container,()=>{m?.remove(),m=S.default(t.container,"scroll",v,!1)},{immediate:!0,flush:"post"}),l.onBeforeUnmount(()=>{h?.remove(),y?.remove(),m?.remove(),B?.remove()}),l.watch(()=>({...f.value}),(e,n)=>{e.isHiddenScrollBar!==n?.isHiddenScrollBar&&!e.isHiddenScrollBar&&d(o=>{const r=t.scrollBodyRef.value;return r?{...o,scrollLeft:r.scrollLeft/r.scrollWidth*r.clientWidth}:o})},{immediate:!0});const q=w.default();return()=>{if(c.value<=s.value||!u.value||f.value.isHiddenScrollBar)return null;const{prefixCls:e}=g;return l.createVNode("div",{style:{height:`${q}px`,width:`${s.value}px`,bottom:`${t.offsetScroll}px`},class:`${e}-sticky-scroll`},[l.createVNode("div",{onMousedown:H,ref:M,class:z.default(`${e}-sticky-scroll-bar`,{[`${e}-sticky-scroll-bar-active`]:a.value}),style:{width:`${u.value}px`,transform:`translate3d(${f.value.scrollLeft}px, 0, 0)`}},null)])}}});exports.default=k;
