"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('../../assets/index24.css');const y=require("react/jsx-runtime"),T=require("../../classix-5H4IWnMA.cjs"),o=require("react"),A=require("../../icons-o8Z5npPW.cjs"),H=require("../list/index.cjs"),M="_sortable_c1ptl_5",V="_dragging_c1ptl_35",z="_dropping_c1ptl_50",B="_columns_c1ptl_63",N="_pseudo_c1ptl_73",c={sortable:M,dragging:V,dropping:z,columns:B,pseudo:N,"target-above":"_target-above_c1ptl_88","target-below":"_target-below_c1ptl_89"};function k({children:h,className:I,columns:g=1,isRearranging:d=!1,onChangeOrder:f,...b}){const x=Number.isFinite(g)?Math.max(1,Math.floor(g)):1,v=o.useMemo(()=>o.Children.toArray(h),[h]),n=o.useRef(-1),[p,q]=o.useState({height:0,width:0}),[a,m]=o.useState(null),[E,S]=o.useState(null),$={...b.style,"--icon-svg":A.iconSVG("sort",!0),"--height":`calc(${p.height}px - var(--scale-16))`,"--width":x>1?`calc(${p.width}px - var(--scale-16))`:`${p.width}px`},w=()=>{n.current=-1,m(null)};return o.useEffect(()=>{d||S(null)},[d]),y.jsx(H.List,{className:T.t(I,c.sortable,x>1&&c.columns),columns:g,ordered:!0,style:$,...b,"data-component":"sortable",children:v.map((_,t)=>{const j=o.isValidElement(_)?_.key:null;return y.jsx("li",{className:T.t(a!==null&&a>t-10&&a<t+10&&c.pseudo,a===t&&n.current<t&&c["target-below"],a===t&&n.current>t&&c["target-above"],n.current===t&&c.dragging,E===t&&d&&c.dropping),draggable:!d,onDragEnd:()=>w(),onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move";const r=n.current;if(r<0||r===t)return;const s=e.currentTarget.getBoundingClientRect(),l=t===r+1?p.height:s.height,u=e.clientY>s.top+l/2?t+1:t,i=u>r?u-1:u;m(i)},onDragStart:e=>{n.current=t,q({height:e.currentTarget.offsetHeight,width:e.currentTarget.offsetWidth}),e.dataTransfer.setData("text/plain",""),e.dataTransfer.effectAllowed="move",m(t)},onDrop:e=>{e.preventDefault();const r=n.current,s=a;if(r<0||s===null||r===s)return;S(s);const l=v.slice(),[D]=l.splice(r,1);l.splice(s,0,D),f==null||f(l.map((u,i)=>({id:String(o.isValidElement(u)?u.props["data-id"]??`idx-${i}`:`idx-${i}`),weight:l.length-1-i}))),w()},"data-component":"sortable",children:_},j??t)})})}exports.Sortable=k;
//# sourceMappingURL=index.cjs.map
