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