import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{c as t,d as n,m as r,o as i,s as a,u as o}from"./vendor-dnd-C1cICjTT.js";import{s}from"./vendor-markdown-Db1-9wH7.js";import{l as c}from"./issueStore-B3ra7txM.js";var l=e(r(),1),u=s(),d=`col::`,f=`card::`,p=`sidebar-project::`,m=e=>e.startsWith(d),h=e=>e.startsWith(f),g=e=>e.startsWith(p),_=e=>e.slice(5),v=e=>e.slice(6),y=e=>e.slice(17);function b(e){return e?!!(e.tagName&&[`input`,`textarea`,`select`,`option`].includes(e.tagName.toLowerCase())||e.closest?.(`input, textarea, select, [data-no-drag="true"]`)):!1}var x=class extends t{static activators=[{eventName:`onPointerDown`,handler:({nativeEvent:e})=>!(!e.isPrimary||e.button!==0||b(e.target))}]},S=(0,l.createContext)(null);function C(){return(0,l.useContext)(S)||{activeId:null,registerDragStart:()=>()=>{},registerDragEnd:()=>()=>{},setOverlayNode:()=>{}}}function w({children:e}){let t=n(o(x,{activationConstraint:{distance:5}})),r=(0,l.useRef)(new Set),s=(0,l.useRef)(new Set),[d,f]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),_=(0,l.useCallback)(e=>{f(String(e.active.id)),r.current.forEach(t=>t(e))},[]),b=(0,l.useCallback)(async e=>{f(null),m(null);let t=e.over?String(e.over.id):null,n=String(e.active.id);if(t&&g(t)&&h(n)){let e=y(t),r=v(n),i=c.getState().issues.get(r);if(!i||i.project_path===e)return;let a=c.getState().upsertIssue;a({...i,project_path:e,updated_at:new Date().toISOString()});try{let t=await fetch(`/api/issues/${r}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({project_path:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();n?.issue&&a(n.issue)}catch(e){console.error(`Failed to move issue to project`,e),a(i)}return}s.current.forEach(t=>t(e))},[]),C=(0,l.useCallback)(e=>(r.current.add(e),()=>{r.current.delete(e)}),[]),w=(0,l.useCallback)(e=>(s.current.add(e),()=>{s.current.delete(e)}),[]),T=(0,l.useMemo)(()=>({activeId:d,registerDragStart:C,registerDragEnd:w,setOverlayNode:m}),[d,C,w]);return(0,u.jsx)(S.Provider,{value:T,children:(0,u.jsxs)(i,{sensors:t,onDragStart:_,onDragEnd:b,onDragCancel:()=>{f(null),m(null)},children:[e,(0,u.jsx)(a,{dropAnimation:null,children:p})]})})}function T({onDragStart:e,onDragEnd:t}){let{registerDragStart:n,registerDragEnd:r}=C(),i=(0,l.useRef)(e),a=(0,l.useRef)(t);(0,l.useEffect)(()=>{i.current=e},[e]),(0,l.useEffect)(()=>{a.current=t},[t]),(0,l.useEffect)(()=>{let e=[];return i.current&&e.push(n(e=>i.current?.(e))),a.current&&e.push(r(e=>a.current?.(e))),()=>{e.forEach(e=>e())}},[n,r])}export{f as CARD_PREFIX,d as COL_PREFIX,w as KanbanDnDShell,h as isCardId,m as isColId,v as stripCard,_ as stripCol,C as useKanbanDnD,T as useRegisterDragHandlers};