var B=Object.defineProperty,H=Object.defineProperties;var L=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var x=(t,e,r)=>e in t?B(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,y=(t,e)=>{for(var r in e||(e={}))O.call(e,r)&&x(t,r,e[r]);if(S)for(var r of S(e))P.call(e,r)&&x(t,r,e[r]);return t},A=(t,e)=>H(t,L(e));var T=(t,e,r)=>new Promise((u,f)=>{var c=s=>{try{a(r.next(s))}catch(i){f(i)}},h=s=>{try{a(r.throw(s))}catch(i){f(i)}},a=s=>s.done?u(s.value):Promise.resolve(s.value).then(c,h);a((r=r.apply(t,e)).next())});import{jsx as l,jsxs as N}from"react/jsx-runtime";import{router as v}from"@inertiajs/react";import _ from"nprogress";import{c as C,H as R,J as Y,K as w,e as F,M as G,N as J}from"./ui-components-B24mpb8o.js";import{Move as K}from"lucide-react";import{useRef as V,useState as k}from"react";const z=()=>{v.on("start",()=>_.remove()),v.on("finish",()=>_.remove())},Q=({items:t,onOrderChange:e,updateRoute:r,renderItem:u,containerClassName:f,itemClassName:c,iconClassName:h})=>{const a=V(null),s=n=>{n.currentTarget.classList.add("dragging")},i=n=>T(null,null,function*(){n.currentTarget.classList.remove("dragging");const o=a.current;if(o){const d=[],g=Array.from(o.querySelectorAll("[data-item_id]")),m=t[0].sort;g.forEach((b,D)=>{const E=parseInt(b.getAttribute("data-item_id")||"");if(E){const I=t.find(j=>j.id===E);I&&d.push(A(y({},I),{sort:m+D}))}}),e==null||e(d),r&&(z(),v.put(r,{items:d}))}}),p=n=>{var g,m;n.preventDefault();const o=q(a.current,n.clientY),d=document.querySelector(".dragging");o==null?(g=a.current)==null||g.appendChild(d):(m=a.current)==null||m.insertBefore(d,o)},q=(n,o)=>[...n.querySelectorAll(".draggable:not(.dragging)")].reduce((g,m)=>{const b=m.getBoundingClientRect(),D=o-b.top-b.height/2;return D<0&&D>g.offset?{offset:D,element:m}:g},{offset:Number.NEGATIVE_INFINITY,element:null}).element,M=[...t].sort((n,o)=>n.sort-o.sort);return l("div",{ref:a,className:f,onDragOver:p,children:M.map((n,o)=>N("div",{draggable:!0,"data-item_id":n.id,className:C("draggable flex items-center",c),onDragStart:s,onDragEnd:i,children:[l(K,{className:C("mr-4 h-5 w-5 cursor-grab",h)}),u(n,o)]},n.id))})},te=({title:t,data:e,handler:r,renderContent:u,onOrderChange:f,translate:c})=>{var i;const[h,a]=k(!1),s=p=>{f(p,a)};return N(R,{open:h,onOpenChange:a,children:[l(Y,{asChild:!0,children:r}),l(w,{className:"p-0",children:N(F,{className:"max-h-[90vh] p-6",children:[l(G,{className:"mb-6",children:l(J,{children:t})}),e.length>0?l(Q,{items:e,onOrderChange:s,containerClassName:"space-y-2",renderItem:p=>u(p)}):l("div",{className:"px-4 py-3 text-center",children:l("p",{children:((i=c==null?void 0:c.frontend)==null?void 0:i.no_element_available)||"No element available"})})]})})]})};export{te as D};
