import{defineComponent as P,onUnmounted as T,watchEffect as I,computed as p,getCurrentInstance as z,shallowRef as R,createVNode as f}from"vue";import v from"../../_util/raf.mjs";import _ from"../../_util/supportsPassive.mjs";import{useInjectTableContext as S}from"../../table/context.mjs";import g from"../../vc-util/Dom/addEventListener.mjs";import $ from"../../vc-util/devWarning.mjs";const W={mouse:{move:"mousemove",stop:"mouseup"},touch:{move:"touchmove",stop:"touchend"}},w=50,B=P({compatConfig:{MODE:3},name:"DragHandle",props:{prefixCls:String,width:{type:Number,required:!0},minWidth:{type:Number,default:w},maxWidth:{type:Number,default:1/0},column:{type:Object,default:void 0}},setup(t){let u=0,r={remove:()=>{}},m={remove:()=>{}};const o=()=>{r.remove(),m.remove()};T(()=>{o()}),I(()=>{$(!isNaN(t.width),"Table","width must be a number when use resizable")});const{onResizeColumn:b}=S(),C=p(()=>typeof t.minWidth=="number"&&!isNaN(t.minWidth)?t.minWidth:w),N=p(()=>typeof t.maxWidth=="number"&&!isNaN(t.maxWidth)?t.maxWidth:1/0),x=z();let l=0;const a=R(!1);let c;const d=e=>{let n=0;e.touches?e.touches.length?n=e.touches[0].pageX:n=e.changedTouches[0].pageX:n=e.pageX;const i=u-n;let s=Math.max(l-i,C.value);s=Math.min(s,N.value),v.cancel(c),c=v(()=>{b(s,t.column.__originColumn__)})},E=e=>{d(e)},D=e=>{a.value=!1,d(e),o()},h=(e,n)=>{a.value=!0,o(),l=x.vnode.el.parentNode.getBoundingClientRect().width,!(e instanceof MouseEvent&&e.which!==1)&&(e.stopPropagation&&e.stopPropagation(),u=e.touches?e.touches[0].pageX:e.pageX,r=g(document.documentElement,n.move,E),m=g(document.documentElement,n.stop,D))},y=e=>{e.stopPropagation(),e.preventDefault(),h(e,W.mouse)},X=e=>{e.stopPropagation(),e.preventDefault(),h(e,W.touch)},M=e=>{e.stopPropagation(),e.preventDefault()};return()=>{const{prefixCls:e}=t,n={[_?"onTouchstartPassive":"onTouchstart"]:i=>X(i)};return f("div",{class:`${e}-resize-handle ${a.value?"dragging":""}`,onMousedown:y,...n,onClick:M},[f("div",{class:`${e}-resize-handle-line`},null)])}}});export{B as default};
