import{i as G,s as H,d as j,a as z,b as C,r as N,g as O}from"./i18n-eTakDDhg.js";import{R,aa as V,t as W,a as X,T as Y,X as F,W as J,V as K,M as Q,w as U,Y as Z,a5 as ee}from"./index-BkylzejB.js";import{G as te}from"./utils.svelte-DZ62NrTu.js";import{S as re}from"./index-C-r_2iGV.js";import"./StreamingBar.svelte_svelte_type_style_lang-CFNH9sqm.js";import"./clone-IGppQJ7B.js";import"./ScrollFade.svelte_svelte_type_style_lang-De9nUaYy.js";import"./snippet-CC9u6I34.js";import"./Clear-Daql2pLY.js";import"./html-DvOIMrhY.js";import"./index-B_pwUImq.js";var ae=J('<div role="region" aria-label="Draggable items container"><!> <!></div>');function pe(y,_){R(_,!0);const A=N(_,["$$slots","$$events","$$legacy"]),s=new te(A);let a,o=null,c=[],i=null;const p=[{event:"dragstart",handler:x},{event:"dragend",handler:M}],m=[{event:"dragover",handler:k},{event:"drop",handler:P},{event:"dragenter",handler:D}];function w(e){p.forEach(({event:r,handler:t})=>{e.addEventListener(r,t)})}function h(e){p.forEach(({event:r,handler:t})=>{e.removeEventListener(r,t)})}function S(e){m.forEach(({event:r,handler:t})=>{e.addEventListener(r,t)})}function v(e){m.forEach(({event:r,handler:t})=>{e.removeEventListener(r,t)})}function b(e,r){e.classList.add("draggable-item"),e.setAttribute("data-index",r.toString()),e.style.position="relative";const t=document.createElement("div");t.className="drag-handle",t.setAttribute("draggable","true"),t.setAttribute("aria-grabbed","false"),t.setAttribute("data-index",r.toString()),t.innerHTML="⋮⋮",e.appendChild(t),w(t),S(e)}function f(){if(!a)return;c.forEach(t=>{const n=t.querySelector(".drag-handle");n&&(h(n),n.remove()),v(t)}),c=[];const e=Array.from(a.children);let r=0;e.forEach(t=>{t.classList.contains("status-tracker")||(t.classList.contains("form")&&t.children.length>0?Array.from(t.children).forEach(l=>{c.push(l),b(l,r),r++}):(c.push(t),b(t,r),r++))})}function x(e){e.stopPropagation?.();const r=e.currentTarget,t=r.parentElement;o=t,parseInt(r.dataset.index||"-1"),r.setAttribute("aria-grabbed","true"),t.classList.add("dragging"),e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/html",t.outerHTML),e.dataTransfer.setDragImage(t,10,10))}function M(e){e.stopPropagation?.();const r=e.currentTarget;r.parentElement.classList.remove("dragging"),r.setAttribute("aria-grabbed","false"),i&&(i.classList.remove("drop-target"),i=null),o=null}function k(e){return e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="move"),!1}function D(e){e.stopPropagation?.();const r=e.currentTarget;if(r===o||!o||!a)return;const t=o.parentElement,n=r.parentElement,l=t?.classList.contains("form")&&t.parentElement===a,u=n?.classList.contains("form")&&n.parentElement===a;(l||t===a)&&(u||n===a)&&(i&&i!==r&&i.classList.remove("drop-target"),r.classList.add("drop-target"),i=r)}async function P(e){e.stopPropagation?.();const r=e.currentTarget;if(r.classList.remove("drop-target"),i&&(i.classList.remove("drop-target"),i=null),o&&o!==r&&a){const t=o.parentElement,n=r.parentElement,l=t?.classList.contains("form")&&t.parentElement===a,u=n?.classList.contains("form")&&n.parentElement===a;if(!((l||t===a)&&(u||n===a)))return!1;const g=document.createElement("div");g.style.display="none",t.insertBefore(g,o),n.insertBefore(o,r),t.insertBefore(r,g),g.remove(),o?.classList.remove("dragging");const T=o?.querySelector(".drag-handle");T&&T.setAttribute("aria-grabbed","false"),await Q(),f()}return!1}V(()=>{f();const e=new MutationObserver(f);return a&&e.observe(a,{childList:!0,subtree:!1}),()=>{e.disconnect(),c.forEach(r=>{const t=r.querySelector(".drag-handle");t&&h(t),v(r)})}});var d=ae();let E;var L=K(d);{var $=e=>{{let r=ee(()=>s.shared.loading_status?s.shared.loading_status.status=="pending"?"generating":s.shared.loading_status.status:null);re(e,O({get autoscroll(){return s.shared.autoscroll},get i18n(){return s.i18n}},()=>s.shared.loading_status,{get status(){return U(r)}}))}};G(L,e=>{s.shared.loading_status&&s.props.show_progress&&e($)})}var q=F(L,2);H(q,_,"default",{}),Z(d),j(d,e=>a=e,()=>a),W(e=>{z(d,"id",s.shared.elem_id),E=C(d,1,`draggable ${e??""}`,"svelte-1kr8imm",E,{hide:!s.shared.visible,horizontal:s.props.orientation==="row",vertical:s.props.orientation==="column"})},[()=>(s.shared.elem_classes||[]).join(" ")]),X(y,d),Y()}export{pe as default};
