@kelceyp/caw-server 0.0.79 → 0.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +156 -156
- package/dist/public_html/main.js +1 -1
- package/dist/public_html/styles.css +1 -1
- package/package.json +1 -1
package/dist/public_html/main.js
CHANGED
|
@@ -3110,4 +3110,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
3110
3110
|
While dragging, use the arrow keys to move the item.
|
|
3111
3111
|
Press space again to drop the item in its new position, or press escape to cancel.
|
|
3112
3112
|
`},aq8={onDragStart(J){let{active:Z}=J;return"Picked up draggable item "+Z.id+"."},onDragOver(J){let{active:Z,over:Q}=J;if(Q)return"Draggable item "+Z.id+" was moved over droppable area "+Q.id+".";return"Draggable item "+Z.id+" is no longer over a droppable area."},onDragEnd(J){let{active:Z,over:Q}=J;if(Q)return"Draggable item "+Z.id+" was dropped over droppable area "+Q.id;return"Draggable item "+Z.id+" was dropped."},onDragCancel(J){let{active:Z}=J;return"Dragging was cancelled. Draggable item "+Z.id+" was dropped."}};function oq8(J){let{announcements:Z=aq8,container:Q,hiddenTextDescribedById:K,screenReaderInstructions:X=sq8}=J,{announce:U,announcement:Y}=S16(),z=Lk("DndLiveRegion"),[G,W]=p6.useState(!1);if(p6.useEffect(()=>{W(!0)},[]),rq8(p6.useMemo(()=>({onDragStart(H){let{active:B}=H;U(Z.onDragStart({active:B}))},onDragMove(H){let{active:B,over:M}=H;if(Z.onDragMove)U(Z.onDragMove({active:B,over:M}))},onDragOver(H){let{active:B,over:M}=H;U(Z.onDragOver({active:B,over:M}))},onDragEnd(H){let{active:B,over:M}=H;U(Z.onDragEnd({active:B,over:M}))},onDragCancel(H){let{active:B,over:M}=H;U(Z.onDragCancel({active:B,over:M}))}}),[U,Z])),!G)return null;let q=p6.default.createElement(p6.default.Fragment,null,p6.default.createElement(T16,{id:K,value:X.draggable}),p6.default.createElement(C16,{id:z,announcement:Y}));return Q?P3.createPortal(q,Q):q}var xQ;(function(J){J.DragStart="dragStart",J.DragMove="dragMove",J.DragEnd="dragEnd",J.DragCancel="dragCancel",J.DragOver="dragOver",J.RegisterDroppable="registerDroppable",J.SetDroppableDisabled="setDroppableDisabled",J.UnregisterDroppable="unregisterDroppable"})(xQ||(xQ={}));function ui(){}function XB0(J,Z){return p6.useMemo(()=>({sensor:J,options:Z!=null?Z:{}}),[J,Z])}function p16(){for(var J=arguments.length,Z=Array(J),Q=0;Q<J;Q++)Z[Q]=arguments[Q];return p6.useMemo(()=>[...Z].filter((K)=>K!=null),[...Z])}var rz=Object.freeze({x:0,y:0});function tq8(J,Z){let Q=Nk(J);if(!Q)return"0 0";let K={x:(Q.x-Z.left)/Z.width*100,y:(Q.y-Z.top)/Z.height*100};return K.x+"% "+K.y+"%"}function eq8(J,Z){let{data:{value:Q}}=J,{data:{value:K}}=Z;return K-Q}function J28(J,Z){if(!J||J.length===0)return null;let[Q]=J;return Z?Q[Z]:Q}function Z28(J,Z){let Q=Math.max(Z.top,J.top),K=Math.max(Z.left,J.left),X=Math.min(Z.left+Z.width,J.left+J.width),U=Math.min(Z.top+Z.height,J.top+J.height),Y=X-K,z=U-Q;if(K<X&&Q<U){let G=Z.width*Z.height,W=J.width*J.height,q=Y*z,H=q/(G+W-q);return Number(H.toFixed(4))}return 0}var Q28=(J)=>{let{collisionRect:Z,droppableRects:Q,droppableContainers:K}=J,X=[];for(let U of K){let{id:Y}=U,z=Q.get(Y);if(z){let G=Z28(z,Z);if(G>0)X.push({id:Y,data:{droppableContainer:U,value:G}})}}return X.sort(eq8)};function K28(J,Z,Q){return{...J,scaleX:Z&&Q?Z.width/Q.width:1,scaleY:Z&&Q?Z.height/Q.height:1}}function c16(J,Z){return J&&Z?{x:J.left-Z.left,y:J.top-Z.top}:rz}function X28(J){return function(Q){for(var K=arguments.length,X=Array(K>1?K-1:0),U=1;U<K;U++)X[U-1]=arguments[U];return X.reduce((Y,z)=>({...Y,top:Y.top+J*z.y,bottom:Y.bottom+J*z.y,left:Y.left+J*z.x,right:Y.right+J*z.x}),{...Q})}}var U28=X28(1);function l16(J){if(J.startsWith("matrix3d(")){let Z=J.slice(9,-1).split(/, /);return{x:+Z[12],y:+Z[13],scaleX:+Z[0],scaleY:+Z[5]}}else if(J.startsWith("matrix(")){let Z=J.slice(7,-1).split(/, /);return{x:+Z[4],y:+Z[5],scaleX:+Z[0],scaleY:+Z[3]}}return null}function Y28(J,Z,Q){let K=l16(Z);if(!K)return J;let{scaleX:X,scaleY:U,x:Y,y:z}=K,G=J.left-Y-(1-X)*parseFloat(Q),W=J.top-z-(1-U)*parseFloat(Q.slice(Q.indexOf(" ")+1)),q=X?J.width/X:J.width,H=U?J.height/U:J.height;return{width:q,height:H,top:W,right:G+q,bottom:W+H,left:G}}var z28={ignoreTransform:!1};function wk(J,Z){if(Z===void 0)Z=z28;let Q=J.getBoundingClientRect();if(Z.ignoreTransform){let{transform:W,transformOrigin:q}=T1(J).getComputedStyle(J);if(W)Q=Y28(Q,W,q)}let{top:K,left:X,width:U,height:Y,bottom:z,right:G}=Q;return{top:K,left:X,width:U,height:Y,bottom:z,right:G}}function $16(J){return wk(J,{ignoreTransform:!0})}function G28(J){let{innerWidth:Z,innerHeight:Q}=J;return{top:0,left:0,right:Z,bottom:Q,width:Z,height:Q}}function W28(J,Z){if(Z===void 0)Z=T1(J).getComputedStyle(J);return Z.position==="fixed"}function q28(J,Z){if(Z===void 0)Z=T1(J).getComputedStyle(J);let Q=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some((X)=>{let U=Z[X];return typeof U==="string"?Q.test(U):!1})}function UB0(J,Z){let Q=[];function K(X){if(Z!=null&&Q.length>=Z)return Q;if(!X)return Q;if(yi(X)&&X.scrollingElement!=null&&!Q.includes(X.scrollingElement))return Q.push(X.scrollingElement),Q;if(!gD(X)||oH0(X))return Q;if(Q.includes(X))return Q;let U=T1(J).getComputedStyle(X);if(X!==J){if(q28(X,U))Q.push(X)}if(W28(X,U))return Q;return K(X.parentNode)}if(!J)return Q;return K(J)}function d16(J){let[Z]=UB0(J,1);return Z!=null?Z:null}function tH0(J){if(!Bk||!J)return null;if(I3(J))return J;if(!hi(J))return null;if(yi(J)||J===R3(J).scrollingElement)return window;if(gD(J))return J;return null}function i16(J){if(I3(J))return J.scrollX;return J.scrollLeft}function r16(J){if(I3(J))return J.scrollY;return J.scrollTop}function ZB0(J){return{x:i16(J),y:r16(J)}}var z5;(function(J){J[J.Forward=1]="Forward",J[J.Backward=-1]="Backward"})(z5||(z5={}));function n16(J){if(!Bk||!J)return!1;return J===document.scrollingElement}function s16(J){let Z={x:0,y:0},Q=n16(J)?{height:window.innerHeight,width:window.innerWidth}:{height:J.clientHeight,width:J.clientWidth},K={x:J.scrollWidth-Q.width,y:J.scrollHeight-Q.height},X=J.scrollTop<=Z.y,U=J.scrollLeft<=Z.x,Y=J.scrollTop>=K.y,z=J.scrollLeft>=K.x;return{isTop:X,isLeft:U,isBottom:Y,isRight:z,maxScroll:K,minScroll:Z}}var H28={x:0.2,y:0.2};function B28(J,Z,Q,K,X){let{top:U,left:Y,right:z,bottom:G}=Q;if(K===void 0)K=10;if(X===void 0)X=H28;let{isTop:W,isBottom:q,isLeft:H,isRight:B}=s16(J),M={x:0,y:0},L={x:0,y:0},A={height:Z.height*X.y,width:Z.width*X.x};if(!W&&U<=Z.top+A.height)M.y=z5.Backward,L.y=K*Math.abs((Z.top+A.height-U)/A.height);else if(!q&&G>=Z.bottom-A.height)M.y=z5.Forward,L.y=K*Math.abs((Z.bottom-A.height-G)/A.height);if(!B&&z>=Z.right-A.width)M.x=z5.Forward,L.x=K*Math.abs((Z.right-A.width-z)/A.width);else if(!H&&Y<=Z.left+A.width)M.x=z5.Backward,L.x=K*Math.abs((Z.left+A.width-Y)/A.width);return{direction:M,speed:L}}function F28(J){if(J===document.scrollingElement){let{innerWidth:U,innerHeight:Y}=window;return{top:0,left:0,right:U,bottom:Y,width:U,height:Y}}let{top:Z,left:Q,right:K,bottom:X}=J.getBoundingClientRect();return{top:Z,left:Q,right:K,bottom:X,width:J.clientWidth,height:J.clientHeight}}function a16(J){return J.reduce((Z,Q)=>{return w3(Z,ZB0(Q))},rz)}function M28(J){return J.reduce((Z,Q)=>{return Z+i16(Q)},0)}function O28(J){return J.reduce((Z,Q)=>{return Z+r16(Q)},0)}function o16(J,Z){if(Z===void 0)Z=wk;if(!J)return;let{top:Q,left:K,bottom:X,right:U}=Z(J);if(!d16(J))return;if(X<=0||U<=0||Q>=window.innerHeight||K>=window.innerWidth)J.scrollIntoView({block:"center",inline:"center"})}var L28=[["x",["left","right"],M28],["y",["top","bottom"],O28]];class ci{constructor(J,Z){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let Q=UB0(Z),K=a16(Q);this.rect={...J},this.width=J.width,this.height=J.height;for(let[X,U,Y]of L28)for(let z of U)Object.defineProperty(this,z,{get:()=>{let G=Y(Q),W=K[X]-G;return this.rect[z]+W},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class pD{constructor(J){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach((Z)=>{var Q;return(Q=this.target)==null?void 0:Q.removeEventListener(...Z)})},this.target=J}add(J,Z,Q){var K;(K=this.target)==null||K.addEventListener(J,Z,Q),this.listeners.push([J,Z,Q])}}function A28(J){let{EventTarget:Z}=T1(J);return J instanceof Z?J:R3(J)}function eH0(J,Z){let Q=Math.abs(J.x),K=Math.abs(J.y);if(typeof Z==="number")return Math.sqrt(Q**2+K**2)>Z;if("x"in Z&&"y"in Z)return Q>Z.x&&K>Z.y;if("x"in Z)return Q>Z.x;if("y"in Z)return K>Z.y;return!1}var VY;(function(J){J.Click="click",J.DragStart="dragstart",J.Keydown="keydown",J.ContextMenu="contextmenu",J.Resize="resize",J.SelectionChange="selectionchange",J.VisibilityChange="visibilitychange"})(VY||(VY={}));function k16(J){J.preventDefault()}function N28(J){J.stopPropagation()}var U4;(function(J){J.Space="Space",J.Down="ArrowDown",J.Right="ArrowRight",J.Left="ArrowLeft",J.Up="ArrowUp",J.Esc="Escape",J.Enter="Enter",J.Tab="Tab"})(U4||(U4={}));var t16={start:[U4.Space,U4.Enter],cancel:[U4.Esc],end:[U4.Space,U4.Enter,U4.Tab]},I28=(J,Z)=>{let{currentCoordinates:Q}=Z;switch(J.code){case U4.Right:return{...Q,x:Q.x+25};case U4.Left:return{...Q,x:Q.x-25};case U4.Down:return{...Q,y:Q.y+25};case U4.Up:return{...Q,y:Q.y-25}}return};class Dk{constructor(J){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=J;let{event:{target:Z}}=J;this.props=J,this.listeners=new pD(R3(Z)),this.windowListeners=new pD(T1(Z)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(VY.Resize,this.handleCancel),this.windowListeners.add(VY.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(VY.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:J,onStart:Z}=this.props,Q=J.node.current;if(Q)o16(Q);Z(rz)}handleKeyDown(J){if(gi(J)){let{active:Z,context:Q,options:K}=this.props,{keyboardCodes:X=t16,coordinateGetter:U=I28,scrollBehavior:Y="smooth"}=K,{code:z}=J;if(X.end.includes(z)){this.handleEnd(J);return}if(X.cancel.includes(z)){this.handleCancel(J);return}let{collisionRect:G}=Q.current,W=G?{x:G.left,y:G.top}:rz;if(!this.referenceCoordinates)this.referenceCoordinates=W;let q=U(J,{active:Z,context:Q.current,currentCoordinates:W});if(q){let H=Ak(q,W),B={x:0,y:0},{scrollableAncestors:M}=Q.current;for(let L of M){let A=J.code,{isTop:N,isRight:I,isLeft:R,isBottom:D,maxScroll:V,minScroll:P}=s16(L),T=F28(L),C={x:Math.min(A===U4.Right?T.right-T.width/2:T.right,Math.max(A===U4.Right?T.left:T.left+T.width/2,q.x)),y:Math.min(A===U4.Down?T.bottom-T.height/2:T.bottom,Math.max(A===U4.Down?T.top:T.top+T.height/2,q.y))},S=A===U4.Right&&!I||A===U4.Left&&!R,v=A===U4.Down&&!D||A===U4.Up&&!N;if(S&&C.x!==q.x){let h=L.scrollLeft+H.x,_=A===U4.Right&&h<=V.x||A===U4.Left&&h>=P.x;if(_&&!H.y){L.scrollTo({left:h,behavior:Y});return}if(_)B.x=L.scrollLeft-h;else B.x=A===U4.Right?L.scrollLeft-V.x:L.scrollLeft-P.x;if(B.x)L.scrollBy({left:-B.x,behavior:Y});break}else if(v&&C.y!==q.y){let h=L.scrollTop+H.y,_=A===U4.Down&&h<=V.y||A===U4.Up&&h>=P.y;if(_&&!H.x){L.scrollTo({top:h,behavior:Y});return}if(_)B.y=L.scrollTop-h;else B.y=A===U4.Down?L.scrollTop-V.y:L.scrollTop-P.y;if(B.y)L.scrollBy({top:-B.y,behavior:Y});break}}this.handleMove(J,w3(Ak(q,this.referenceCoordinates),B))}}}handleMove(J,Z){let{onMove:Q}=this.props;J.preventDefault(),Q(Z)}handleEnd(J){let{onEnd:Z}=this.props;J.preventDefault(),this.detach(),Z()}handleCancel(J){let{onCancel:Z}=this.props;J.preventDefault(),this.detach(),Z()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Dk.activators=[{eventName:"onKeyDown",handler:(J,Z,Q)=>{let{keyboardCodes:K=t16,onActivation:X}=Z,{active:U}=Q,{code:Y}=J.nativeEvent;if(K.start.includes(Y)){let z=U.activatorNode.current;if(z&&J.target!==z)return!1;return J.preventDefault(),X==null||X({event:J.nativeEvent}),!0}return!1}}];function v16(J){return Boolean(J&&"distance"in J)}function f16(J){return Boolean(J&&"delay"in J)}class li{constructor(J,Z,Q){var K;if(Q===void 0)Q=A28(J.event.target);this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=J,this.events=Z;let{event:X}=J,{target:U}=X;this.props=J,this.events=Z,this.document=R3(U),this.documentListeners=new pD(this.document),this.listeners=new pD(Q),this.windowListeners=new pD(T1(U)),this.initialCoordinates=(K=Nk(X))!=null?K:rz,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:J,props:{options:{activationConstraint:Z,bypassActivationConstraint:Q}}}=this;if(this.listeners.add(J.move.name,this.handleMove,{passive:!1}),this.listeners.add(J.end.name,this.handleEnd),J.cancel)this.listeners.add(J.cancel.name,this.handleCancel);if(this.windowListeners.add(VY.Resize,this.handleCancel),this.windowListeners.add(VY.DragStart,k16),this.windowListeners.add(VY.VisibilityChange,this.handleCancel),this.windowListeners.add(VY.ContextMenu,k16),this.documentListeners.add(VY.Keydown,this.handleKeydown),Z){if(Q!=null&&Q({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(f16(Z)){this.timeoutId=setTimeout(this.handleStart,Z.delay),this.handlePending(Z);return}if(v16(Z)){this.handlePending(Z);return}}this.handleStart()}detach(){if(this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null)clearTimeout(this.timeoutId),this.timeoutId=null}handlePending(J,Z){let{active:Q,onPending:K}=this.props;K(Q,J,this.initialCoordinates,Z)}handleStart(){let{initialCoordinates:J}=this,{onStart:Z}=this.props;if(J)this.activated=!0,this.documentListeners.add(VY.Click,N28,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(VY.SelectionChange,this.removeTextSelection),Z(J)}handleMove(J){var Z;let{activated:Q,initialCoordinates:K,props:X}=this,{onMove:U,options:{activationConstraint:Y}}=X;if(!K)return;let z=(Z=Nk(J))!=null?Z:rz,G=Ak(K,z);if(!Q&&Y){if(v16(Y)){if(Y.tolerance!=null&&eH0(G,Y.tolerance))return this.handleCancel();if(eH0(G,Y.distance))return this.handleStart()}if(f16(Y)){if(eH0(G,Y.tolerance))return this.handleCancel()}this.handlePending(Y,G);return}if(J.cancelable)J.preventDefault();U(z)}handleEnd(){let{onAbort:J,onEnd:Z}=this.props;if(this.detach(),!this.activated)J(this.props.active);Z()}handleCancel(){let{onAbort:J,onCancel:Z}=this.props;if(this.detach(),!this.activated)J(this.props.active);Z()}handleKeydown(J){if(J.code===U4.Esc)this.handleCancel()}removeTextSelection(){var J;(J=this.document.getSelection())==null||J.removeAllRanges()}}var R28={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Pk extends li{constructor(J){let{event:Z}=J,Q=R3(Z.target);super(J,R28,Q)}}Pk.activators=[{eventName:"onPointerDown",handler:(J,Z)=>{let{nativeEvent:Q}=J,{onActivation:K}=Z;if(!Q.isPrimary||Q.button!==0)return!1;return K==null||K({event:Q}),!0}}];var w28={move:{name:"mousemove"},end:{name:"mouseup"}},QB0;(function(J){J[J.RightClick=2]="RightClick"})(QB0||(QB0={}));class e16 extends li{constructor(J){super(J,w28,R3(J.event.target))}}e16.activators=[{eventName:"onMouseDown",handler:(J,Z)=>{let{nativeEvent:Q}=J,{onActivation:K}=Z;if(Q.button===QB0.RightClick)return!1;return K==null||K({event:Q}),!0}}];var JB0={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class JK6 extends li{constructor(J){super(J,JB0)}static setup(){return window.addEventListener(JB0.move.name,J,{capture:!1,passive:!1}),function(){window.removeEventListener(JB0.move.name,J)};function J(){}}}JK6.activators=[{eventName:"onTouchStart",handler:(J,Z)=>{let{nativeEvent:Q}=J,{onActivation:K}=Z,{touches:X}=Q;if(X.length>1)return!1;return K==null||K({event:Q}),!0}}];var Ik;(function(J){J[J.Pointer=0]="Pointer",J[J.DraggableRect=1]="DraggableRect"})(Ik||(Ik={}));var pi;(function(J){J[J.TreeOrder=0]="TreeOrder",J[J.ReversedTreeOrder=1]="ReversedTreeOrder"})(pi||(pi={}));function D28(J){let{acceleration:Z,activator:Q=Ik.Pointer,canScroll:K,draggingRect:X,enabled:U,interval:Y=5,order:z=pi.TreeOrder,pointerCoordinates:G,scrollableAncestors:W,scrollableAncestorRects:q,delta:H,threshold:B}=J,M=E28({delta:H,disabled:!U}),[L,A]=E16(),N=p6.useRef({x:0,y:0}),I=p6.useRef({x:0,y:0}),R=p6.useMemo(()=>{switch(Q){case Ik.Pointer:return G?{top:G.y,bottom:G.y,left:G.x,right:G.x}:null;case Ik.DraggableRect:return X}},[Q,X,G]),D=p6.useRef(null),V=p6.useCallback(()=>{let T=D.current;if(!T)return;let C=N.current.x*I.current.x,S=N.current.y*I.current.y;T.scrollBy(C,S)},[]),P=p6.useMemo(()=>z===pi.TreeOrder?[...W].reverse():W,[z,W]);p6.useEffect(()=>{if(!U||!W.length||!R){A();return}for(let T of P){if((K==null?void 0:K(T))===!1)continue;let C=W.indexOf(T),S=q[C];if(!S)continue;let{direction:v,speed:h}=B28(T,S,R,Z,B);for(let _ of["x","y"])if(!M[_][v[_]])h[_]=0,v[_]=0;if(h.x>0||h.y>0){A(),D.current=T,L(V,Y),N.current=h,I.current=v;return}}N.current={x:0,y:0},I.current={x:0,y:0},A()},[Z,V,K,A,U,Y,JSON.stringify(R),JSON.stringify(M),L,W,P,q,JSON.stringify(B)])}var P28={x:{[z5.Backward]:!1,[z5.Forward]:!1},y:{[z5.Backward]:!1,[z5.Forward]:!1}};function E28(J){let{delta:Z,disabled:Q}=J,K=Ok(Z);return uD((X)=>{if(Q||!K||!X)return P28;let U={x:Math.sign(Z.x-K.x),y:Math.sign(Z.y-K.y)};return{x:{[z5.Backward]:X.x[z5.Backward]||U.x===-1,[z5.Forward]:X.x[z5.Forward]||U.x===1},y:{[z5.Backward]:X.y[z5.Backward]||U.y===-1,[z5.Forward]:X.y[z5.Forward]||U.y===1}}},[Q,Z,K])}function V28(J,Z){let Q=Z!=null?J.get(Z):void 0,K=Q?Q.node.current:null;return uD((X)=>{var U;if(Z==null)return null;return(U=K!=null?K:X)!=null?U:null},[K,Z])}function j28(J,Z){return p6.useMemo(()=>J.reduce((Q,K)=>{let{sensor:X}=K,U=X.activators.map((Y)=>({eventName:Y.eventName,handler:Z(Y.handler,K)}));return[...Q,...U]},[]),[J,Z])}var Rk;(function(J){J[J.Always=0]="Always",J[J.BeforeDragging=1]="BeforeDragging",J[J.WhileDragging=2]="WhileDragging"})(Rk||(Rk={}));var KB0;(function(J){J.Optimized="optimized"})(KB0||(KB0={}));var _16=new Map;function T28(J,Z){let{dragging:Q,dependencies:K,config:X}=Z,[U,Y]=p6.useState(null),{frequency:z,measure:G,strategy:W}=X,q=p6.useRef(J),H=N(),B=mD(H),M=p6.useCallback(function(I){if(I===void 0)I=[];if(B.current)return;Y((R)=>{if(R===null)return I;return R.concat(I.filter((D)=>!R.includes(D)))})},[B]),L=p6.useRef(null),A=uD((I)=>{if(H&&!Q)return _16;if(!I||I===_16||q.current!==J||U!=null){let R=new Map;for(let D of J){if(!D)continue;if(U&&U.length>0&&!U.includes(D.id)&&D.rect.current){R.set(D.id,D.rect.current);continue}let V=D.node.current,P=V?new ci(G(V),V):null;if(D.rect.current=P,P)R.set(D.id,P)}return R}return I},[J,U,Q,H,G]);return p6.useEffect(()=>{q.current=J},[J]),p6.useEffect(()=>{if(H)return;M()},[Q,H]),p6.useEffect(()=>{if(U&&U.length>0)Y(null)},[JSON.stringify(U)]),p6.useEffect(()=>{if(H||typeof z!=="number"||L.current!==null)return;L.current=setTimeout(()=>{M(),L.current=null},z)},[z,H,M,...K]),{droppableRects:A,measureDroppableContainers:M,measuringScheduled:U!=null};function N(){switch(W){case Rk.Always:return!1;case Rk.BeforeDragging:return Q;default:return!Q}}}function YB0(J,Z){return uD((Q)=>{if(!J)return null;if(Q)return Q;return typeof Z==="function"?Z(J):J},[Z,J])}function C28(J,Z){return YB0(J,Z)}function S28(J){let{callback:Z,disabled:Q}=J,K=Fk(Z),X=p6.useMemo(()=>{if(Q||typeof window>"u"||typeof window.MutationObserver>"u")return;let{MutationObserver:U}=window;return new U(K)},[K,Q]);return p6.useEffect(()=>{return()=>X==null?void 0:X.disconnect()},[X]),X}function di(J){let{callback:Z,disabled:Q}=J,K=Fk(Z),X=p6.useMemo(()=>{if(Q||typeof window>"u"||typeof window.ResizeObserver>"u")return;let{ResizeObserver:U}=window;return new U(K)},[Q]);return p6.useEffect(()=>{return()=>X==null?void 0:X.disconnect()},[X]),X}function $28(J){return new ci(wk(J),J)}function b16(J,Z,Q){if(Z===void 0)Z=$28;let[K,X]=p6.useState(null);function U(){X((G)=>{if(!J)return null;if(J.isConnected===!1){var W;return(W=G!=null?G:Q)!=null?W:null}let q=Z(J);if(JSON.stringify(G)===JSON.stringify(q))return G;return q})}let Y=S28({callback(G){if(!J)return;for(let W of G){let{type:q,target:H}=W;if(q==="childList"&&H instanceof HTMLElement&&H.contains(J)){U();break}}}}),z=di({callback:U});return uW(()=>{if(U(),J)z==null||z.observe(J),Y==null||Y.observe(document.body,{childList:!0,subtree:!0});else z==null||z.disconnect(),Y==null||Y.disconnect()},[J]),K}function k28(J){let Z=YB0(J);return c16(J,Z)}var x16=[];function v28(J){let Z=p6.useRef(J),Q=uD((K)=>{if(!J)return x16;if(K&&K!==x16&&J&&Z.current&&J.parentNode===Z.current.parentNode)return K;return UB0(J)},[J]);return p6.useEffect(()=>{Z.current=J},[J]),Q}function f28(J){let[Z,Q]=p6.useState(null),K=p6.useRef(J),X=p6.useCallback((U)=>{let Y=tH0(U.target);if(!Y)return;Q((z)=>{if(!z)return null;return z.set(Y,ZB0(Y)),new Map(z)})},[]);return p6.useEffect(()=>{let U=K.current;if(J!==U){Y(U);let z=J.map((G)=>{let W=tH0(G);if(W)return W.addEventListener("scroll",X,{passive:!0}),[W,ZB0(W)];return null}).filter((G)=>G!=null);Q(z.length?new Map(z):null),K.current=J}return()=>{Y(J),Y(U)};function Y(z){z.forEach((G)=>{let W=tH0(G);W==null||W.removeEventListener("scroll",X)})}},[X,J]),p6.useMemo(()=>{if(J.length)return Z?Array.from(Z.values()).reduce((U,Y)=>w3(U,Y),rz):a16(J);return rz},[J,Z])}function h16(J,Z){if(Z===void 0)Z=[];let Q=p6.useRef(null);return p6.useEffect(()=>{Q.current=null},Z),p6.useEffect(()=>{let K=J!==rz;if(K&&!Q.current)Q.current=J;if(!K&&Q.current)Q.current=null},[J]),Q.current?Ak(J,Q.current):rz}function _28(J){p6.useEffect(()=>{if(!Bk)return;let Z=J.map((Q)=>{let{sensor:K}=Q;return K.setup==null?void 0:K.setup()});return()=>{for(let Q of Z)Q==null||Q()}},J.map((Z)=>{let{sensor:Q}=Z;return Q}))}function b28(J,Z){return p6.useMemo(()=>{return J.reduce((Q,K)=>{let{eventName:X,handler:U}=K;return Q[X]=(Y)=>{U(Y,Z)},Q},{})},[J,Z])}function ZK6(J){return p6.useMemo(()=>J?G28(J):null,[J])}var y16=[];function x28(J,Z){if(Z===void 0)Z=wk;let[Q]=J,K=ZK6(Q?T1(Q):null),[X,U]=p6.useState(y16);function Y(){U(()=>{if(!J.length)return y16;return J.map((G)=>n16(G)?K:new ci(Z(G),G))})}let z=di({callback:Y});return uW(()=>{z==null||z.disconnect(),Y(),J.forEach((G)=>z==null?void 0:z.observe(G))},[J]),X}function QK6(J){if(!J)return null;if(J.children.length>1)return J;let Z=J.children[0];return gD(Z)?Z:J}function h28(J){let{measure:Z}=J,[Q,K]=p6.useState(null),X=p6.useCallback((W)=>{for(let{target:q}of W)if(gD(q)){K((H)=>{let B=Z(q);return H?{...H,width:B.width,height:B.height}:B});break}},[Z]),U=di({callback:X}),Y=p6.useCallback((W)=>{let q=QK6(W);if(U==null||U.disconnect(),q)U==null||U.observe(q);K(q?Z(q):null)},[Z,U]),[z,G]=Mk(Y);return p6.useMemo(()=>({nodeRef:z,rect:Q,setRef:G}),[Q,z,G])}var y28=[{sensor:Pk,options:{}},{sensor:Dk,options:{}}],g28={current:{}},mi={draggable:{measure:$16},droppable:{measure:$16,strategy:Rk.WhileDragging,frequency:KB0.Optimized},dragOverlay:{measure:wk}};class cD extends Map{get(J){var Z;return J!=null?(Z=super.get(J))!=null?Z:void 0:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter((J)=>{let{disabled:Z}=J;return!Z})}getNodeFor(J){var Z,Q;return(Z=(Q=this.get(J))==null?void 0:Q.node.current)!=null?Z:void 0}}var m28={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new cD,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:ui},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:mi,measureDroppableContainers:ui,windowRect:null,measuringScheduled:!1},KK6={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:ui,draggableNodes:new Map,over:null,measureDroppableContainers:ui},Ek=p6.createContext(KK6),XK6=p6.createContext(m28);function u28(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new cD}}}function p28(J,Z){switch(Z.type){case xQ.DragStart:return{...J,draggable:{...J.draggable,initialCoordinates:Z.initialCoordinates,active:Z.active}};case xQ.DragMove:if(J.draggable.active==null)return J;return{...J,draggable:{...J.draggable,translate:{x:Z.coordinates.x-J.draggable.initialCoordinates.x,y:Z.coordinates.y-J.draggable.initialCoordinates.y}}};case xQ.DragEnd:case xQ.DragCancel:return{...J,draggable:{...J.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case xQ.RegisterDroppable:{let{element:Q}=Z,{id:K}=Q,X=new cD(J.droppable.containers);return X.set(K,Q),{...J,droppable:{...J.droppable,containers:X}}}case xQ.SetDroppableDisabled:{let{id:Q,key:K,disabled:X}=Z,U=J.droppable.containers.get(Q);if(!U||K!==U.key)return J;let Y=new cD(J.droppable.containers);return Y.set(Q,{...U,disabled:X}),{...J,droppable:{...J.droppable,containers:Y}}}case xQ.UnregisterDroppable:{let{id:Q,key:K}=Z,X=J.droppable.containers.get(Q);if(!X||K!==X.key)return J;let U=new cD(J.droppable.containers);return U.delete(Q),{...J,droppable:{...J.droppable,containers:U}}}default:return J}}function c28(J){let{disabled:Z}=J,{active:Q,activatorEvent:K,draggableNodes:X}=p6.useContext(Ek),U=Ok(K),Y=Ok(Q==null?void 0:Q.id);return p6.useEffect(()=>{if(Z)return;if(!K&&U&&Y!=null){if(!gi(U))return;if(document.activeElement===U.target)return;let z=X.get(Y);if(!z)return;let{activatorNode:G,node:W}=z;if(!G.current&&!W.current)return;requestAnimationFrame(()=>{for(let q of[G.current,W.current]){if(!q)continue;let H=j16(q);if(H){H.focus();break}}})}},[K,Z,X,Y,U]),null}function UK6(J,Z){let{transform:Q,...K}=Z;return J!=null&&J.length?J.reduce((X,U)=>{return U({transform:X,...K})},Q):Q}function l28(J){return p6.useMemo(()=>({draggable:{...mi.draggable,...J==null?void 0:J.draggable},droppable:{...mi.droppable,...J==null?void 0:J.droppable},dragOverlay:{...mi.dragOverlay,...J==null?void 0:J.dragOverlay}}),[J==null?void 0:J.draggable,J==null?void 0:J.droppable,J==null?void 0:J.dragOverlay])}function d28(J){let{activeNode:Z,measure:Q,initialRect:K,config:X=!0}=J,U=p6.useRef(!1),{x:Y,y:z}=typeof X==="boolean"?{x:X,y:X}:X;uW(()=>{if(!Y&&!z||!Z){U.current=!1;return}if(U.current||!K)return;let W=Z==null?void 0:Z.node.current;if(!W||W.isConnected===!1)return;let q=Q(W),H=c16(q,K);if(!Y)H.x=0;if(!z)H.y=0;if(U.current=!0,Math.abs(H.x)>0||Math.abs(H.y)>0){let B=d16(W);if(B)B.scrollBy({top:H.y,left:H.x})}},[Z,Y,z,K,Q])}var ii=p6.createContext({...rz,scaleX:1,scaleY:1}),QM;(function(J){J[J.Uninitialized=0]="Uninitialized",J[J.Initializing=1]="Initializing",J[J.Initialized=2]="Initialized"})(QM||(QM={}));var YK6=p6.memo(function(Z){var Q,K,X,U;let{id:Y,accessibility:z,autoScroll:G=!0,children:W,sensors:q=y28,collisionDetection:H=Q28,measuring:B,modifiers:M,...L}=Z,A=p6.useReducer(p28,void 0,u28),[N,I]=A,[R,D]=nq8(),[V,P]=p6.useState(QM.Uninitialized),T=V===QM.Initialized,{draggable:{active:C,nodes:S,translate:v},droppable:{containers:h}}=N,_=C!=null?S.get(C):null,$=p6.useRef({initial:null,translated:null}),k=p6.useMemo(()=>{var A6;return C!=null?{id:C,data:(A6=_==null?void 0:_.data)!=null?A6:g28,rect:$}:null},[C,_]),f=p6.useRef(null),[b,y]=p6.useState(null),[g,m]=p6.useState(null),u=mD(L,Object.values(L)),d=Lk("DndDescribedBy",Y),l=p6.useMemo(()=>h.getEnabled(),[h]),r=l28(B),{droppableRects:t,measureDroppableContainers:z0,measuringScheduled:J0}=T28(l,{dragging:T,dependencies:[v.x,v.y],config:r.droppable}),H0=V28(S,C),e=p6.useMemo(()=>g?Nk(g):null,[g]),B0=B6(),U0=C28(H0,r.draggable.measure);d28({activeNode:C!=null?S.get(C):null,config:B0.layoutShiftCompensation,initialRect:U0,measure:r.draggable.measure});let X0=b16(H0,r.draggable.measure,U0),Z0=b16(H0?H0.parentElement:null),Q0=p6.useRef({activatorEvent:null,active:null,activeNode:H0,collisionRect:null,collisions:null,droppableRects:t,draggableNodes:S,draggingNode:null,draggingNodeRect:null,droppableContainers:h,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),F0=h.getNodeFor((Q=Q0.current.over)==null?void 0:Q.id),q0=h28({measure:r.dragOverlay.measure}),P0=(K=q0.nodeRef.current)!=null?K:H0,M0=T?(X=q0.rect)!=null?X:X0:null,y0=Boolean(q0.nodeRef.current&&q0.rect),K0=k28(y0?null:X0),K6=ZK6(P0?T1(P0):null),W0=v28(T?F0!=null?F0:H0:null),V0=x28(W0),_0=UK6(M,{transform:{x:v.x-K0.x,y:v.y-K0.y,scaleX:1,scaleY:1},activatorEvent:g,active:k,activeNodeRect:X0,containerNodeRect:Z0,draggingNodeRect:M0,over:Q0.current.over,overlayNodeRect:q0.rect,scrollableAncestors:W0,scrollableAncestorRects:V0,windowRect:K6}),i0=e?w3(e,v):null,T0=f28(W0),$0=h16(T0),m0=h16(T0,[X0]),b0=w3(_0,$0),p0=M0?U28(M0,_0):null,E0=k&&p0?H({active:k,collisionRect:p0,droppableRects:t,droppableContainers:l,pointerCoordinates:i0}):null,x0=J28(E0,"id"),[o,D0]=p6.useState(null),i=y0?_0:w3(_0,m0),N0=K28(i,(U=o==null?void 0:o.rect)!=null?U:null,X0),I0=p6.useRef(null),u0=p6.useCallback((A6,y6)=>{let{sensor:J6,options:Q6}=y6;if(f.current==null)return;let L6=S.get(f.current);if(!L6)return;let X6=A6.nativeEvent,f6=new J6({active:f.current,activeNode:L6,event:X6,options:Q6,context:Q0,onAbort(k6){if(!S.get(k6))return;let{onDragAbort:S6}=u.current,C6={id:k6};S6==null||S6(C6),R({type:"onDragAbort",event:C6})},onPending(k6,t6,S6,C6){if(!S.get(k6))return;let{onDragPending:e0}=u.current,H6={id:k6,constraint:t6,initialCoordinates:S6,offset:C6};e0==null||e0(H6),R({type:"onDragPending",event:H6})},onStart(k6){let t6=f.current;if(t6==null)return;let S6=S.get(t6);if(!S6)return;let{onDragStart:C6}=u.current,S0={activatorEvent:X6,active:{id:t6,data:S6.data,rect:$}};P3.unstable_batchedUpdates(()=>{C6==null||C6(S0),P(QM.Initializing),I({type:xQ.DragStart,initialCoordinates:k6,active:t6}),R({type:"onDragStart",event:S0}),y(I0.current),m(X6)})},onMove(k6){I({type:xQ.DragMove,coordinates:k6})},onEnd:Z8(xQ.DragEnd),onCancel:Z8(xQ.DragCancel)});I0.current=f6;function Z8(k6){return async function(){let{active:S6,collisions:C6,over:S0,scrollAdjustedTranslate:e0}=Q0.current,H6=null;if(S6&&e0){let{cancelDrop:w0}=u.current;if(H6={activatorEvent:X6,active:S6,collisions:C6,delta:e0,over:S0},k6===xQ.DragEnd&&typeof w0==="function"){if(await Promise.resolve(w0(H6)))k6=xQ.DragCancel}}f.current=null,P3.unstable_batchedUpdates(()=>{I({type:k6}),P(QM.Uninitialized),D0(null),y(null),m(null),I0.current=null;let w0=k6===xQ.DragEnd?"onDragEnd":"onDragCancel";if(H6){let z6=u.current[w0];z6==null||z6(H6),R({type:w0,event:H6})}})}}},[S]),v0=p6.useCallback((A6,y6)=>{return(J6,Q6)=>{let L6=J6.nativeEvent,X6=S.get(Q6);if(f.current!==null||!X6||L6.dndKit||L6.defaultPrevented)return;let f6={active:X6};if(A6(J6,y6.options,f6)===!0)L6.dndKit={capturedBy:y6.sensor},f.current=Q6,u0(J6,y6)}},[S,u0]),k0=j28(q,v0);_28(q),uW(()=>{if(X0&&V===QM.Initializing)P(QM.Initialized)},[X0,V]),p6.useEffect(()=>{let{onDragMove:A6}=u.current,{active:y6,activatorEvent:J6,collisions:Q6,over:L6}=Q0.current;if(!y6||!J6)return;let X6={active:y6,activatorEvent:J6,collisions:Q6,delta:{x:b0.x,y:b0.y},over:L6};P3.unstable_batchedUpdates(()=>{A6==null||A6(X6),R({type:"onDragMove",event:X6})})},[b0.x,b0.y]),p6.useEffect(()=>{let{active:A6,activatorEvent:y6,collisions:J6,droppableContainers:Q6,scrollAdjustedTranslate:L6}=Q0.current;if(!A6||f.current==null||!y6||!L6)return;let{onDragOver:X6}=u.current,f6=Q6.get(x0),Z8=f6&&f6.rect.current?{id:f6.id,rect:f6.rect.current,data:f6.data,disabled:f6.disabled}:null,k6={active:A6,activatorEvent:y6,collisions:J6,delta:{x:L6.x,y:L6.y},over:Z8};P3.unstable_batchedUpdates(()=>{D0(Z8),X6==null||X6(k6),R({type:"onDragOver",event:k6})})},[x0]),uW(()=>{Q0.current={activatorEvent:g,active:k,activeNode:H0,collisionRect:p0,collisions:E0,droppableRects:t,draggableNodes:S,draggingNode:P0,draggingNodeRect:M0,droppableContainers:h,over:o,scrollableAncestors:W0,scrollAdjustedTranslate:b0},$.current={initial:M0,translated:p0}},[k,H0,E0,p0,S,P0,M0,t,h,o,W0,b0]),D28({...B0,delta:v,draggingRect:p0,pointerCoordinates:i0,scrollableAncestors:W0,scrollableAncestorRects:V0});let n0=p6.useMemo(()=>{return{active:k,activeNode:H0,activeNodeRect:X0,activatorEvent:g,collisions:E0,containerNodeRect:Z0,dragOverlay:q0,draggableNodes:S,droppableContainers:h,droppableRects:t,over:o,measureDroppableContainers:z0,scrollableAncestors:W0,scrollableAncestorRects:V0,measuringConfiguration:r,measuringScheduled:J0,windowRect:K6}},[k,H0,X0,g,E0,Z0,q0,S,h,t,o,z0,W0,V0,r,J0,K6]),l0=p6.useMemo(()=>{return{activatorEvent:g,activators:k0,active:k,activeNodeRect:X0,ariaDescribedById:{draggable:d},dispatch:I,draggableNodes:S,over:o,measureDroppableContainers:z0}},[g,k0,k,X0,I,d,S,o,z0]);return p6.default.createElement(u16.Provider,{value:D},p6.default.createElement(Ek.Provider,{value:l0},p6.default.createElement(XK6.Provider,{value:n0},p6.default.createElement(ii.Provider,{value:N0},W)),p6.default.createElement(c28,{disabled:(z==null?void 0:z.restoreFocus)===!1})),p6.default.createElement(oq8,{...z,hiddenTextDescribedById:d}));function B6(){let A6=(b==null?void 0:b.autoScrollEnabled)===!1,y6=typeof G==="object"?G.enabled===!1:G===!1,J6=T&&!A6&&!y6;if(typeof G==="object")return{...G,enabled:J6};return{enabled:J6}}}),i28=p6.createContext(null),g16="button",r28="Draggable";function zK6(J){let{id:Z,data:Q,disabled:K=!1,attributes:X}=J,U=Lk(r28),{activators:Y,activatorEvent:z,active:G,activeNodeRect:W,ariaDescribedById:q,draggableNodes:H,over:B}=p6.useContext(Ek),{role:M=g16,roleDescription:L="draggable",tabIndex:A=0}=X!=null?X:{},N=(G==null?void 0:G.id)===Z,I=p6.useContext(N?ii:i28),[R,D]=Mk(),[V,P]=Mk(),T=b28(Y,Z),C=mD(Q);uW(()=>{return H.set(Z,{id:Z,key:U,node:R,activatorNode:V,data:C}),()=>{let v=H.get(Z);if(v&&v.key===U)H.delete(Z)}},[H,Z]);let S=p6.useMemo(()=>({role:M,tabIndex:A,"aria-disabled":K,"aria-pressed":N&&M===g16?!0:void 0,"aria-roledescription":L,"aria-describedby":q.draggable}),[K,M,A,N,L,q.draggable]);return{active:G,activatorEvent:z,activeNodeRect:W,attributes:S,isDragging:N,listeners:K?void 0:T,node:R,over:B,setNodeRef:D,setActivatorNodeRef:P,transform:I}}function n28(){return p6.useContext(XK6)}var s28="Droppable",a28={timeout:25};function GK6(J){let{data:Z,disabled:Q=!1,id:K,resizeObserverConfig:X}=J,U=Lk(s28),{active:Y,dispatch:z,over:G,measureDroppableContainers:W}=p6.useContext(Ek),q=p6.useRef({disabled:Q}),H=p6.useRef(!1),B=p6.useRef(null),M=p6.useRef(null),{disabled:L,updateMeasurementsFor:A,timeout:N}={...a28,...X},I=mD(A!=null?A:K),R=p6.useCallback(()=>{if(!H.current){H.current=!0;return}if(M.current!=null)clearTimeout(M.current);M.current=setTimeout(()=>{W(Array.isArray(I.current)?I.current:[I.current]),M.current=null},N)},[N]),D=di({callback:R,disabled:L||!Y}),V=p6.useCallback((S,v)=>{if(!D)return;if(v)D.unobserve(v),H.current=!1;if(S)D.observe(S)},[D]),[P,T]=Mk(V),C=mD(Z);return p6.useEffect(()=>{if(!D||!P.current)return;D.disconnect(),H.current=!1,D.observe(P.current)},[P,D]),p6.useEffect(()=>{return z({type:xQ.RegisterDroppable,element:{id:K,key:U,disabled:Q,node:P,rect:B,data:C}}),()=>z({type:xQ.UnregisterDroppable,key:U,id:K})},[K]),p6.useEffect(()=>{if(Q!==q.current.disabled)z({type:xQ.SetDroppableDisabled,id:K,key:U,disabled:Q}),q.current.disabled=Q},[K,U,Q,z]),{active:Y,rect:B,isOver:(G==null?void 0:G.id)===K,node:P,over:G,setNodeRef:T}}function o28(J){let{animation:Z,children:Q}=J,[K,X]=p6.useState(null),[U,Y]=p6.useState(null),z=Ok(Q);if(!Q&&!K&&z)X(z);return uW(()=>{if(!U)return;let G=K==null?void 0:K.key,W=K==null?void 0:K.props.id;if(G==null||W==null){X(null);return}Promise.resolve(Z(W,U)).then(()=>{X(null)})},[Z,K,U]),p6.default.createElement(p6.default.Fragment,null,Q,K?p6.cloneElement(K,{ref:Y}):null)}var t28={x:0,y:0,scaleX:1,scaleY:1};function e28(J){let{children:Z}=J;return p6.default.createElement(Ek.Provider,{value:KK6},p6.default.createElement(ii.Provider,{value:t28},Z))}var JH8={position:"fixed",touchAction:"none"},ZH8=(J)=>{return gi(J)?"transform 250ms ease":void 0},QH8=p6.forwardRef((J,Z)=>{let{as:Q,activatorEvent:K,adjustScale:X,children:U,className:Y,rect:z,style:G,transform:W,transition:q=ZH8}=J;if(!z)return null;let H=X?W:{...W,scaleX:1,scaleY:1},B={...JH8,width:z.width,height:z.height,top:z.top,left:z.left,transform:yD.Transform.toString(H),transformOrigin:X&&K?tq8(K,z):void 0,transition:typeof q==="function"?q(K):q,...G};return p6.default.createElement(Q,{className:Y,style:B,ref:Z},U)}),KH8=(J)=>(Z)=>{let{active:Q,dragOverlay:K}=Z,X={},{styles:U,className:Y}=J;if(U!=null&&U.active)for(let[z,G]of Object.entries(U.active)){if(G===void 0)continue;X[z]=Q.node.style.getPropertyValue(z),Q.node.style.setProperty(z,G)}if(U!=null&&U.dragOverlay)for(let[z,G]of Object.entries(U.dragOverlay)){if(G===void 0)continue;K.node.style.setProperty(z,G)}if(Y!=null&&Y.active)Q.node.classList.add(Y.active);if(Y!=null&&Y.dragOverlay)K.node.classList.add(Y.dragOverlay);return function(){for(let[G,W]of Object.entries(X))Q.node.style.setProperty(G,W);if(Y!=null&&Y.active)Q.node.classList.remove(Y.active)}},XH8=(J)=>{let{transform:{initial:Z,final:Q}}=J;return[{transform:yD.Transform.toString(Z)},{transform:yD.Transform.toString(Q)}]},UH8={duration:250,easing:"ease",keyframes:XH8,sideEffects:KH8({styles:{active:{opacity:"0"}}})};function YH8(J){let{config:Z,draggableNodes:Q,droppableContainers:K,measuringConfiguration:X}=J;return Fk((U,Y)=>{if(Z===null)return;let z=Q.get(U);if(!z)return;let G=z.node.current;if(!G)return;let W=QK6(Y);if(!W)return;let{transform:q}=T1(Y).getComputedStyle(Y),H=l16(q);if(!H)return;let B=typeof Z==="function"?Z:zH8(Z);return o16(G,X.draggable.measure),B({active:{id:U,data:z.data,node:G,rect:X.draggable.measure(G)},draggableNodes:Q,dragOverlay:{node:Y,rect:X.dragOverlay.measure(W)},droppableContainers:K,measuringConfiguration:X,transform:H})})}function zH8(J){let{duration:Z,easing:Q,sideEffects:K,keyframes:X}={...UH8,...J};return(U)=>{let{active:Y,dragOverlay:z,transform:G,...W}=U;if(!Z)return;let q={x:z.rect.left-Y.rect.left,y:z.rect.top-Y.rect.top},H={scaleX:G.scaleX!==1?Y.rect.width*G.scaleX/z.rect.width:1,scaleY:G.scaleY!==1?Y.rect.height*G.scaleY/z.rect.height:1},B={x:G.x-q.x,y:G.y-q.y,...H},M=X({...W,active:Y,dragOverlay:z,transform:{initial:G,final:B}}),[L]=M,A=M[M.length-1];if(JSON.stringify(L)===JSON.stringify(A))return;let N=K==null?void 0:K({active:Y,dragOverlay:z,...W}),I=z.node.animate(M,{duration:Z,easing:Q,fill:"forwards"});return new Promise((R)=>{I.onfinish=()=>{N==null||N(),R()}})}}var m16=0;function GH8(J){return p6.useMemo(()=>{if(J==null)return;return m16++,m16},[J])}var WK6=p6.default.memo((J)=>{let{adjustScale:Z=!1,children:Q,dropAnimation:K,style:X,transition:U,modifiers:Y,wrapperElement:z="div",className:G,zIndex:W=999}=J,{activatorEvent:q,active:H,activeNodeRect:B,containerNodeRect:M,draggableNodes:L,droppableContainers:A,dragOverlay:N,over:I,measuringConfiguration:R,scrollableAncestors:D,scrollableAncestorRects:V,windowRect:P}=n28(),T=p6.useContext(ii),C=GH8(H==null?void 0:H.id),S=UK6(Y,{activatorEvent:q,active:H,activeNodeRect:B,containerNodeRect:M,draggingNodeRect:N.rect,over:I,overlayNodeRect:N.rect,scrollableAncestors:D,scrollableAncestorRects:V,transform:T,windowRect:P}),v=YB0(B),h=YH8({config:K,draggableNodes:L,droppableContainers:A,measuringConfiguration:R}),_=v?N.setRef:void 0;return p6.default.createElement(e28,null,p6.default.createElement(o28,{animation:h},H&&C?p6.default.createElement(QH8,{key:C,id:H.id,ref:_,as:z,activatorEvent:q,adjustScale:Z,className:G,transition:U,rect:v,style:{zIndex:W,...X},transform:S},Q):null))});var WH8="",qH8=()=>({"Content-Type":"application/json","X-Session-Id":cJ()});async function qK6(J,Z,Q,{value:K,values:X}){let U=X?{values:X}:{value:K},Y=await fetch(`${WH8}/api/p/${J}/entities/${Z}/fields/${Q}`,{method:"PUT",headers:qH8(),body:JSON.stringify(U)});return P9(Y,"Failed to set field value")}function HK6(J){let Z=e9();return AJ({mutationFn:({entityId:Q,fieldName:K,value:X,values:U})=>qK6(J,Q,K,U?{values:U}:{value:X}),onSuccess:()=>{Z.invalidateQueries({queryKey:["folderContents",J]})}})}var HH8=f0(j6(),1);var E3=f0(z8(),1);function zB0({task:J,onClick:Z,onMoveTask:Q,states:K}){let{attributes:X,listeners:U,setNodeRef:Y,isDragging:z}=zK6({id:J.id,data:{state:J.fields?.state,task:J}});return E3.jsxDEV("div",{ref:Y,...U,...X,role:"button",tabIndex:0,className:`px-3 py-2 bg-background border border-border rounded-md
|
|
3113
|
-
cursor-pointer hover:border-foreground/30 transition-colors${z?" opacity-50":""}`,onClick:()=>Z(J),onKeyDown:(W)=>{if(W.key==="Enter"||W.key===" ")W.preventDefault(),Z(J);if(W.key==="ArrowLeft"){if(W.stopPropagation(),Q&&K){if(K.indexOf(J.fields?.state)>0)Q(J.id,-1)}}if(W.key==="ArrowRight"){if(W.stopPropagation(),Q&&K){let q=K.indexOf(J.fields?.state);if(q>=0&&q<K.length-1)Q(J.id,1)}}},children:[E3.jsxDEV("div",{className:"text-sm truncate",children:J.name},void 0,!1,void 0,this),J.fields?.label&&E3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.label},void 0,!1,void 0,this),J.fields?.colour&&E3.jsxDEV("div",{className:"mt-1 w-3 h-3 rounded-full",style:{backgroundColor:J.fields.colour}},void 0,!1,void 0,this),J.fields?.worker&&E3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.worker},void 0,!1,void 0,this),Array.isArray(J.fields?.dependsOn)&&J.fields.dependsOn.length>0&&E3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:[J.fields.dependsOn.length," dep",J.fields.dependsOn.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var F7=f0(z8(),1);function BH8({state:J,children:Z}){let{setNodeRef:Q,isOver:K}=GK6({id:J});return F7.jsxDEV("div",{className:"flex-1 min-w-[160px] flex flex-col",children:[F7.jsxDEV("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground",children:J},void 0,!1,void 0,this),F7.jsxDEV("div",{ref:Q,className:`flex-1 min-h-[200px] rounded-md p-2 space-y-2 transition-colors ${K?"bg-muted":"bg-muted/50"}`,children:Z},void 0,!1,void 0,this)]},J,!0,void 0,this)}function BK6({projectId:J,storyId:Z,onOpenDocument:Q}){let[K,X]=lD.useState(null),[U,Y]=lD.useState(!1),[z,G]=lD.useState(""),[W,q]=lD.useState(""),H=XB0(Pk,{activationConstraint:{distance:8}}),B=XB0(Dk),M=p16(H,B),L=HK6(J),A=q3(J),N=e9(),{data:I,isLoading:R,isError:D}=$V(J,{folderId:Z,type:"d"}),V=I?.find((g)=>g.isFolder&&g.subtype==="tasks"),P=V?.fields?.states??[],{data:T,isLoading:C,isError:S}=$V(J,{folderId:V?.id,type:"d",enabled:!!V?.id}),v={};for(let g of P)v[g]=[];if(T){for(let g of T)if(!g.isFolder&&g.fields?.state&&v[g.fields.state])v[g.fields.state].push(g)}let h=V?["folderContents",J,"A",V.id,"d","default"]:null;function _(g,m){if(!h)return;L.mutate({entityId:g,fieldName:"state",value:m},{onMutate:()=>{let u=N.getQueryData(h);return N.setQueryData(h,(d)=>d?.map((l)=>l.id===g?{...l,fields:{...l.fields,state:m}}:l)),{previous:u,queryKey:h}},onError:(u,d,l)=>{if(l?.queryKey&&l?.previous)N.setQueryData(l.queryKey,l.previous)}})}function $(g){X(g.active.id)}function k(g){let{active:m,over:u}=g;if(X(null),!u)return;if(m.data.current?.state===u.id)return;_(m.id,u.id)}function f(g,m){let u=T?.find((t)=>t.id===g);if(!u)return;let d=u.fields?.state,l=P.indexOf(d);if(l===-1)return;let r=l+m;if(r<0||r>=P.length)return;_(g,P[r])}function b(){if(!z.trim())return;if(A.isPending)return;A.mutate({parentId:V.id,name:z.trim(),subtype:"task",fields:{state:W}},{onSuccess:(g)=>{Y(!1),G(""),q(P[0]||""),Q(g.id,{edit:!0})}})}let y=K?T?.find((g)=>g.id===K):null;if(R)return F7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this);if(D)return F7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Failed to load tasks folder."},void 0,!1,void 0,this);if(!V)return F7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"No tasks folder found for this story."},void 0,!1,void 0,this);return F7.jsxDEV(F7.Fragment,{children:[P.length>0&&F7.jsxDEV("div",{className:"px-4 pt-4 flex items-center",children:F7.jsxDEV(a6,{variant:"warning",size:"sm",onClick:()=>{G(""),q(P[0]||""),Y(!0)},children:[F7.jsxDEV(cQ,{className:"w-4 h-4"},void 0,!1,void 0,this),F7.jsxDEV(dY,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV(YK6,{sensors:M,onDragStart:$,onDragEnd:k,children:[F7.jsxDEV("div",{className:"flex gap-3 pb-4 px-4 overflow-x-auto",children:P.map((g)=>F7.jsxDEV(BH8,{state:g,children:C?F7.jsxDEV("div",{className:"text-xs text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this):S?F7.jsxDEV("div",{className:"text-xs text-destructive",children:"Failed to load tasks"},void 0,!1,void 0,this):v[g]?.map((m)=>F7.jsxDEV(zB0,{task:m,onClick:(u)=>Q(u.id),states:P,onMoveTask:f},m.id,!1,void 0,this))},g,!1,void 0,this))},void 0,!1,void 0,this),F7.jsxDEV(WK6,{children:y?F7.jsxDEV(zB0,{task:y,onClick:void 0,onMoveTask:void 0,states:void 0},void 0,!1,void 0,this):null},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F7.jsxDEV(cZ,{open:U,onOpenChange:(g)=>{if(Y(g),!g)G(""),q(P[0]||"")},children:F7.jsxDEV(PZ,{children:[F7.jsxDEV(EZ,{children:F7.jsxDEV(VZ,{children:"New Task"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV("div",{className:"py-4 space-y-4",children:[F7.jsxDEV("div",{children:[F7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Name"},void 0,!1,void 0,this),F7.jsxDEV("input",{type:"text",value:z,onChange:(g)=>G(g.target.value.replace(/\//g,"")),placeholder:"example.md",className:"w-full px-3 py-2 border border-input rounded-md bg-background text-foreground text-sm focus:outline-none focus:ring-2 focus:ring-ring",onKeyDown:(g)=>g.key==="Enter"&&b(),autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F7.jsxDEV("div",{children:[F7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"State"},void 0,!1,void 0,this),F7.jsxDEV(H1,{value:W,onValueChange:q,children:[F7.jsxDEV(V5,{children:F7.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV(j5,{children:P.map((g)=>F7.jsxDEV(F4,{value:g,children:g},g,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F7.jsxDEV(nQ,{children:[F7.jsxDEV(a6,{variant:"outline",onClick:()=>{Y(!1),G(""),q(P[0]||"")},children:"Cancel"},void 0,!1,void 0,this),F7.jsxDEV(a6,{onClick:b,disabled:A.isPending||!z.trim(),children:A.isPending?"Creating...":"Create"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Vk="",jk=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),FK6=async(J,{store:Z}={})=>{let Q=new URLSearchParams;if(Z)Q.set("store",Z);let K=Q.toString(),X=`${Vk}/api/p/${J}/stories${K?`?${K}`:""}`,U=await fetch(X,{headers:jk()});return P9(U,"Failed to list stories")};var MK6=async(J,{name:Z,store:Q,state:K})=>{let X=await fetch(`${Vk}/api/p/${J}/stories`,{method:"POST",headers:jk(),body:JSON.stringify({name:Z,store:Q,state:K})});return P9(X,"Failed to create story")},OK6=async(J,Z,Q)=>{let K=await fetch(`${Vk}/api/p/${J}/stories/${Z}/state`,{method:"PATCH",headers:jk(),body:JSON.stringify({state:Q})});return P9(K,"Failed to update story state")},LK6=async(J,Z,Q)=>{let K=await fetch(`${Vk}/api/p/${J}/stories/${Z}/name`,{method:"PATCH",headers:jk(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename story")},AK6=async(J,Z)=>{let Q=await fetch(`${Vk}/api/p/${J}/stories/${Z}`,{method:"DELETE",headers:jk()});return P9(Q,"Failed to delete story")};var NK6=(J,{store:Z}={})=>{return qQ({queryKey:["stories",J,Z??"demux"],queryFn:()=>FK6(J,{store:Z}),enabled:!!J,staleTime:30000})};var IK6=(J)=>{let Z=e9();return AJ({mutationFn:({name:Q,store:K,state:X})=>MK6(J,{name:Q,store:K,state:X}),onSuccess:(Q,{store:K})=>{Z.invalidateQueries({queryKey:["stories",J,K??"demux"]})}})},RK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,state:K})=>OK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},wK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,name:K})=>LK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},DK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q})=>AK6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})};var PK6=f0(j6(),1),EK6=(J)=>{let Z=rj0(J,{path:"",store:"A",type:"s"});return{states:PK6.useMemo(()=>Z.data?.fields?.states??[],[Z.data]),isLoading:Z.isLoading,error:Z.error,refetch:Z.refetch}};var ri="prep";var v6=f0(z8(),1),FH8={useItem:m2,useCreate:q3,useSaveDraft:qD,usePublish:HD,useDiscard:BD,useVersions:FD,useDelete:MD,useUpdatePath:OD,getVersion:WD},GB0=[{key:"unsorted",icon:DG,label:"Not sorted"},{key:"name-asc",icon:NG,label:"Sorting by name ascending"},{key:"name-desc",icon:AG,label:"Sorting by name descending"},{key:"date-asc",icon:sM,label:"Sorting by date ascending"},{key:"date-desc",icon:nM,label:"Sorting by date descending"},{key:"state-asc",icon:VH,label:"Sorting by state ascending"},{key:"state-desc",icon:EH,label:"Sorting by state descending"}],VK6=[{bg:"linear-gradient(to bottom, #ef4444, #dc2626)",text:"white",border:"#b91c1c"},{bg:"linear-gradient(to bottom, #f97316, #ea580c)",text:"white",border:"#c2410c"},{bg:"linear-gradient(to bottom, #eab308, #ca8a04)",text:"#422006",border:"#a16207"},{bg:"linear-gradient(to bottom, #22c55e, #16a34a)",text:"white",border:"#15803d"},{bg:"linear-gradient(to bottom, #3b82f6, #2563eb)",text:"white",border:"#1d4ed8"},{bg:"linear-gradient(to bottom, #6366f1, #4f46e5)",text:"white",border:"#4338ca"},{bg:"linear-gradient(to bottom, #8b5cf6, #7c3aed)",text:"white",border:"#6d28d9"}],MH8=({state:J,states:Z,onPrev:Q,onNext:K})=>{let X=Z.indexOf(J),U=Z.length;if(X<0||U===0)return null;let Y=X/U*100,z=1/U*100,G=J.charAt(0).toUpperCase()+J.slice(1),W=VK6[X%VK6.length];return v6.jsxDEV("div",{className:"relative h-8 flex-1 min-w-0 bg-black/[0.03] dark:bg-white/[0.03] shadow-sm border border-border/50 rounded overflow-hidden",children:v6.jsxDEV("div",{className:"absolute rounded text-xs flex items-center justify-between px-1 shadow-sm",style:{left:`${Y}%`,width:`${z}%`,top:"2px",bottom:"2px",background:W.bg,color:W.text,borderWidth:"1px",borderStyle:"solid",borderColor:W.border},children:[Q?v6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(q)=>{q.stopPropagation(),Q()},onKeyDown:(q)=>{if(q.key==="Enter"||q.key===" ")q.preventDefault(),q.stopPropagation(),Q()},children:v6.jsxDEV(aM,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):v6.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"flex-1 text-center",children:G},void 0,!1,void 0,this),K?v6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(q)=>{q.stopPropagation(),K()},onKeyDown:(q)=>{if(q.key==="Enter"||q.key===" ")q.preventDefault(),q.stopPropagation(),K()},children:v6.jsxDEV(oM,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):v6.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},OH8=({projectId:J,storyId:Z})=>{let{data:Q,isLoading:K,error:X}=GZ6(J,"s"),[U,Y]=XZ.useState(null),z=Q?.templates??[],G=(H)=>{Y(H)},W=()=>{Y(null)};if(K)return v6.jsxDEV("div",{className:"flex items-center gap-2 p-4 text-muted-foreground",children:[v6.jsxDEV(NJ,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading templates..."]},void 0,!0,void 0,this);if(X)return v6.jsxDEV("div",{className:"p-4 text-sm text-destructive",children:["Failed to load templates: ",X.message]},void 0,!0,void 0,this);if(z.length===0)return v6.jsxDEV("div",{className:"p-4 text-sm text-muted-foreground",children:"No associated templates"},void 0,!1,void 0,this);let q=z.find((H)=>H.id===U);return v6.jsxDEV("div",{className:"p-4",children:[v6.jsxDEV("ul",{className:"space-y-1",children:z.map((H)=>v6.jsxDEV("li",{children:v6.jsxDEV("button",{type:"button",onClick:()=>G(H.id),className:"flex items-center gap-2 w-full text-left px-3 py-2 rounded hover:bg-muted text-sm",children:[v6.jsxDEV(cY,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"truncate",children:H.name},void 0,!1,void 0,this),H.path&&v6.jsxDEV("span",{className:"text-xs text-muted-foreground truncate ml-auto",children:H.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},H.id,!1,void 0,this))},void 0,!1,void 0,this),v6.jsxDEV(fi,{open:!!U,onOpenChange:(H)=>{if(!H)W()},projectId:J,templateId:U,templatePath:q?.path||q?.name,mode:"story",storyId:Z,rootFolderId:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},LH8=({projectId:J,story:Z,onDeleted:Q})=>{let[K,X]=XZ.useState(Z.name),[U,Y]=XZ.useState(null),[z,G]=XZ.useState(!1),[W,q]=XZ.useState(null),H=wK6(J),B=DK6(J),M=!K.trim()||K.trim()===Z.name||H.isPending,L=()=>{Y(null),H.mutate({id:Z.id,name:K.trim()},{onError:(N)=>Y(N.message)})},A=()=>{q(null),B.mutate({id:Z.id},{onSuccess:()=>{G(!1),Q()},onError:(N)=>q(N.message)})};return v6.jsxDEV("div",{className:"p-4 space-y-8",children:[v6.jsxDEV("div",{className:"space-y-3",children:[v6.jsxDEV("h3",{className:"text-sm font-medium",children:"Rename"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"flex items-center gap-2",children:[v6.jsxDEV(a5,{value:K,onChange:(N)=>X(N.target.value),onKeyDown:(N)=>N.key==="Enter"&&!M&&L(),className:"max-w-sm"},void 0,!1,void 0,this),v6.jsxDEV(a6,{size:"sm",onClick:L,disabled:M,children:H.isPending?"Saving...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"space-y-3",children:[v6.jsxDEV("h3",{className:"text-sm font-medium",children:"Danger Zone"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"border border-destructive/30 rounded-md p-4",children:v6.jsxDEV("div",{className:"flex items-center justify-between",children:[v6.jsxDEV("div",{children:[v6.jsxDEV("div",{className:"text-sm font-medium",children:"Delete this story"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"text-xs text-muted-foreground",children:"This will soft-delete the story and all its contents."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(a6,{variant:"destructive",size:"sm",onClick:()=>G(!0),children:"Delete Story"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(cZ,{open:z,onOpenChange:G,children:v6.jsxDEV(PZ,{children:[v6.jsxDEV(EZ,{children:v6.jsxDEV(VZ,{className:"flex items-center gap-2 text-destructive",children:[v6.jsxDEV(S7,{className:"w-5 h-5"},void 0,!1,void 0,this),"Delete Story"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete ",v6.jsxDEV("strong",{children:Z.name},void 0,!1,void 0,this),"? This will remove the story and all its contents."]},void 0,!0,void 0,this),W&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:W},void 0,!1,void 0,this),v6.jsxDEV(nQ,{children:[v6.jsxDEV(a6,{variant:"outline",onClick:()=>G(!1),children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(a6,{variant:"destructive",onClick:A,disabled:B.isPending,children:B.isPending?"Deleting...":"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},WB0=()=>{let{id:J,storeCode:Z}=I5(),[Q,K]=uM(),{data:X}=Y1(J);z1(X?`${X.name} - Stories`:"CAW");let U=Z??"A";pH(J);let{data:Y=[],isLoading:z,error:G,refetch:W}=NK6(J,{store:U}),{states:q,isLoading:H,error:B,refetch:M}=EK6(J),L=IK6(J),A=RK6(J),[N,I]=XZ.useState(!1),[R,D]=XZ.useState(""),[V,P]=XZ.useState(ri),[T,C]=XZ.useState(null),[S,v]=XZ.useState("documents"),[h,_]=XZ.useState("state-asc"),$=XZ.useRef(null),[k,f]=XZ.useState(null),b=XZ.useMemo(()=>k??new Set(q),[k,q]),y=(H0)=>{let e=k??new Set(q),B0=new Set(e);if(B0.has(H0))B0.delete(H0);else B0.add(H0);f(B0.size===q.length?null:B0)};XZ.useEffect(()=>{if(Q.has("id"))v("documents")},[Q]);let g=Q.get("expanded")??"",m=XZ.useRef({}),u=(H0)=>{if(v("documents"),K((e)=>{let B0=new URLSearchParams(e);if(B0.delete("id"),B0.delete("edit"),H0)B0.set("expanded",H0);else B0.delete("expanded");return B0}),H0)setTimeout(()=>{m.current[H0]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},d=XZ.useMemo(()=>{if(!q.length)return[];let H0=Y.filter((B0)=>B0.fields?.state&&b.has(B0.fields.state));if(h==="unsorted"){if($.current){let B0=$.current,U0=[...H0];return U0.sort((X0,Z0)=>{let Q0=B0.indexOf(X0.id),F0=B0.indexOf(Z0.id);return(Q0===-1?1/0:Q0)-(F0===-1?1/0:F0)}),U0}return H0}let e=[...H0];return e.sort((B0,U0)=>{if(h==="name-asc")return B0.name.localeCompare(U0.name);if(h==="name-desc")return U0.name.localeCompare(B0.name);if(h==="date-asc"||h==="date-desc"){let X0=(Q0)=>Q0.createdAt?new Date(Q0.createdAt).getTime():parseInt(Q0.id.replace(/\D/g,""),10)||0,Z0=X0(B0)-X0(U0);return h==="date-asc"?Z0:-Z0}if(h==="state-asc")return q.indexOf(B0.fields.state)-q.indexOf(U0.fields.state);if(h==="state-desc")return q.indexOf(U0.fields.state)-q.indexOf(B0.fields.state);return 0}),e},[Y,q,h,b]),l=()=>{if(!R.trim()){C("Story name is required");return}C(null),L.mutate({name:R.trim(),store:U,state:V},{onSuccess:(H0)=>{I(!1),D(""),P(ri),K((e)=>{let B0=new URLSearchParams(e);return B0.delete("id"),B0.delete("edit"),B0.set("expanded",H0.id),B0})},onError:(H0)=>{C(H0.message)}})},r=()=>{I(!1),D(""),P(ri),C(null)},t=z||H,z0=G||B,J0=G?W:M;if(t)return v6.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(z0)return v6.jsxDEV("div",{className:"p-6",children:[v6.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading stories"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:z0.message},void 0,!1,void 0,this),v6.jsxDEV(a6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>J0(),children:[v6.jsxDEV(JO,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Retry"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return v6.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[v6.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:v6.jsxDEV("div",{className:"flex items-center gap-2",children:[v6.jsxDEV(a6,{size:"sm",variant:"warning",onClick:()=>I(!0),children:[v6.jsxDEV(cQ,{className:"w-4 h-4"},void 0,!1,void 0,this),v6.jsxDEV(jH,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(rx,{children:[v6.jsxDEV(Y7,{content:GB0.find((H0)=>H0.key===h)?.label,children:v6.jsxDEV(nx,{asChild:!0,children:v6.jsxDEV(a6,{size:"sm",variant:"outline",children:XZ.default.createElement(GB0.find((H0)=>H0.key===h)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(pV,{align:"start",children:GB0.map((H0)=>v6.jsxDEV(cV,{onClick:()=>{if(H0.key==="unsorted")$.current=d.map((e)=>e.id);else $.current=null;_(H0.key)},className:h===H0.key?"bg-accent":"",children:[v6.jsxDEV(H0.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),H0.label]},H0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(w16,{children:[v6.jsxDEV(Y7,{content:"Filter by state",children:v6.jsxDEV(D16,{asChild:!0,children:v6.jsxDEV(a6,{size:"sm",variant:"outline",children:v6.jsxDEV(vH,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(sH0,{align:"center",children:v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV("div",{className:"text-sm font-medium",children:"Show by state:"},void 0,!1,void 0,this),q.map((H0)=>v6.jsxDEV("label",{className:"flex items-center gap-2",children:[v6.jsxDEV(Wk,{checked:b.has(H0),onCheckedChange:()=>y(H0)},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"text-sm capitalize",children:H0},void 0,!1,void 0,this)]},H0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),d.length===0?v6.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories yet"},void 0,!1,void 0,this):v6.jsxDEV("div",{className:"flex-1 overflow-auto",children:v6.jsxDEV(e_,{type:"single",collapsible:!0,value:g,onValueChange:u,children:d.map((H0)=>{let e=q.indexOf(H0.fields.state),B0=e>0?q[e-1]:null,U0=e<q.length-1?q[e+1]:null;return v6.jsxDEV(Jb,{value:H0.id,className:"border-b",ref:(X0)=>{m.current[H0.id]=X0},children:[v6.jsxDEV(Zb,{className:"grid grid-cols-[25%_50%_25%] items-center px-3 py-2 w-full bg-black/[0.03] dark:bg-white/[0.03] hover:bg-muted text-left [&[data-state=open]_.chevron]:rotate-180",children:[v6.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[v6.jsxDEV(jH,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"truncate text-sm",children:H0.name},void 0,!1,void 0,this),v6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${H0.storeCode==="B"?"text-green-700 border-green-300 bg-green-50 dark:text-green-300 dark:border-green-700 dark:bg-green-900/30":"text-blue-700 border-blue-300 bg-blue-50 dark:text-blue-300 dark:border-blue-700 dark:bg-blue-900/30"}`,children:H0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"grid grid-cols-9 items-center",children:[v6.jsxDEV("span",{className:"text-xs text-muted-foreground text-right pr-1",children:"Status:"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"col-span-7",children:v6.jsxDEV(MH8,{state:H0.fields.state,states:q,onPrev:B0?()=>A.mutate({id:H0.id,state:B0}):null,onNext:U0?()=>A.mutate({id:H0.id,state:U0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"flex justify-end",children:v6.jsxDEV(DU,{className:"chevron w-4 h-4 flex-shrink-0 transition-transform"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(Qb,{className:"border-t",children:v6.jsxDEV(K16,{value:S,onValueChange:v,children:[v6.jsxDEV(iH0,{variant:"line",className:"px-4",children:[v6.jsxDEV(bD,{value:"documents",children:[v6.jsxDEV(pQ,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Documents"]},void 0,!0,void 0,this),v6.jsxDEV(bD,{value:"tasks",children:[v6.jsxDEV(dY,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Tasks"]},void 0,!0,void 0,this),v6.jsxDEV(bD,{value:"prompts",children:[v6.jsxDEV(cE,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),v6.jsxDEV(bD,{value:"settings",children:[v6.jsxDEV(sY,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Settings"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(xD,{value:"documents",children:v6.jsxDEV("div",{className:"h-[600px]",children:v6.jsxDEV(ex,{projectId:J,rootFolderId:H0.id,type:"d",DetailPanel:Fd,hooks:FH8},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(xD,{value:"tasks",children:v6.jsxDEV("div",{className:"h-[600px]",children:v6.jsxDEV(BK6,{projectId:J,storyId:H0.id,onOpenDocument:(X0,Z0)=>{K((Q0)=>{let F0=new URLSearchParams(Q0);if(F0.set("id",X0),Z0?.edit)F0.set("edit","true");return F0})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(xD,{value:"prompts",children:v6.jsxDEV("div",{className:"h-[600px]",children:v6.jsxDEV(OH8,{projectId:J,storyId:H0.id},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(xD,{value:"settings",children:v6.jsxDEV("div",{className:"h-[600px]",children:v6.jsxDEV(LH8,{projectId:J,story:H0,onDeleted:()=>{K((X0)=>{let Z0=new URLSearchParams(X0);return Z0.delete("expanded"),Z0.delete("id"),Z0.delete("edit"),Z0})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},H0.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(cZ,{open:N,onOpenChange:r,children:v6.jsxDEV(PZ,{children:[v6.jsxDEV(EZ,{children:v6.jsxDEV(VZ,{children:"Create Story"},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"space-y-4 py-4",children:[v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV(NZ,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),v6.jsxDEV(a5,{id:"name",value:R,onChange:(H0)=>D(H0.target.value),placeholder:"Enter story name",onKeyDown:(H0)=>H0.key==="Enter"&&l()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV(NZ,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),v6.jsxDEV(H1,{value:V,onValueChange:P,children:[v6.jsxDEV(V5,{children:v6.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(j5,{children:q.map((H0)=>v6.jsxDEV(F4,{value:H0,children:H0.charAt(0).toUpperCase()+H0.slice(1)},H0,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(nQ,{children:[v6.jsxDEV(a6,{variant:"outline",onClick:r,children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(a6,{onClick:l,disabled:L.isPending,children:L.isPending?"Creating...":"Create"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var o5=f0(j6(),1);var Tk="",Ck=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),jK6=async(J,{store:Z,status:Q}={})=>{let K=new URLSearchParams;if(Z)K.set("store",Z);if(Q)K.set("status",Q);let X=K.toString(),U=`${Tk}/api/p/${J}/jobs${X?`?${X}`:""}`,Y=await fetch(U,{headers:Ck()});return P9(Y,"Failed to list jobs")},TK6=async(J,Z)=>{let Q=await fetch(`${Tk}/api/p/${J}/jobs/${Z}`,{headers:Ck()});return P9(Q,"Failed to fetch job")},CK6=async(J,{name:Z,agent:Q,model:K,prompt:X,templateId:U,workingDirectory:Y})=>{let z=await fetch(`${Tk}/api/p/${J}/jobs`,{method:"POST",headers:Ck(),body:JSON.stringify({name:Z,agent:Q,model:K,prompt:X,templateId:U,workingDirectory:Y})});return P9(z,"Failed to create job")},SK6=async(J,Z,{prompt:Q})=>{let K=await fetch(`${Tk}/api/p/${J}/jobs/${Z}/continue`,{method:"POST",headers:Ck(),body:JSON.stringify({prompt:Q})});return P9(K,"Failed to continue job")},$K6=async(J,Z,Q)=>{let K=await fetch(`${Tk}/api/p/${J}/jobs/${Z}`,{method:"PATCH",headers:Ck(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename job")};var kK6=(J,{store:Z,status:Q}={})=>{return qQ({queryKey:["jobs",J,Z??"demux",Q??"all"],queryFn:()=>jK6(J,{store:Z,status:Q}),enabled:!!J,staleTime:30000})},vK6=(J,Z)=>{return qQ({queryKey:["job",Z],queryFn:()=>TK6(J,Z),enabled:!!J&&!!Z})},fK6=(J)=>{let Z=e9();return AJ({mutationFn:({name:Q,agent:K,model:X,prompt:U,templateId:Y,workingDirectory:z})=>CK6(J,{name:Q,agent:K,model:X,prompt:U,templateId:Y,workingDirectory:z}),onSuccess:()=>{Z.invalidateQueries({queryKey:["jobs",J]})}})},_K6=(J,Z)=>{return qQ({queryKey:["jobContents",Z],queryFn:async()=>{let Q=Z?Z[0]:"A",K=await fetch(`/api/p/${J}/folders/${Z}/contents?type=d&store=${Q}`);if(!K.ok)throw Error("Failed to fetch job contents");return K.json()},enabled:!!J&&!!Z})},bK6=(J,Z)=>{let Q=e9();return AJ({mutationFn:({prompt:K})=>SK6(J,Z,{prompt:K}),onSuccess:()=>{Q.invalidateQueries({queryKey:["job",Z]}),Q.invalidateQueries({queryKey:["jobs",J]})}})},xK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,name:K})=>$K6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["job",K]}),Z.invalidateQueries({queryKey:["jobs",J]})}})};var jK=f0(j6(),1);var AH8=f0(j6(),1);var t9=f0(z8(),1),hK6=({value:J,onChange:Z,worktrees:Q=[],isLoadingWorktrees:K=!1,isGitProject:X=!0,error:U=null,createError:Y=null,onCreateErrorClear:z=null})=>{let G=(L)=>{if(L==="main")Z({type:"main",path:null});else if(L==="worktree"){let A=Q[0];Z({type:"worktree",path:A?A.path:null})}else if(L==="new")Z({type:"new",branch:"",baseBranch:"main"})},W=(L)=>{Z({type:"worktree",path:L})},q=(L)=>{if(z)z();Z({...J,branch:L.target.value})},H=(L)=>{Z({...J,baseBranch:L.target.value})},B=(L)=>{Z({type:"new",path:L.target.value})};if(!X)return t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV(NZ,{htmlFor:"run-location-path",children:"Working Directory"},void 0,!1,void 0,this),t9.jsxDEV(a5,{id:"run-location-path",value:J.path||"",onChange:(L)=>Z({type:"new",path:L.target.value}),placeholder:"Optional - uses project root if empty"},void 0,!1,void 0,this),t9.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Specify a custom working directory (not a git repository)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(K)return t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV(NZ,{children:"Run Location"},void 0,!1,void 0,this),t9.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-2",children:[t9.jsxDEV(NJ,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading worktrees..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(U)return t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV(NZ,{children:"Run Location"},void 0,!1,void 0,this),t9.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-destructive py-2",children:[t9.jsxDEV(Mq,{className:"w-4 h-4"},void 0,!1,void 0,this),"Failed to load worktrees: ",U.message||"Unknown error"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);let M=Q.length>0;return t9.jsxDEV("div",{className:"space-y-3",children:[t9.jsxDEV(NZ,{children:"Run Location"},void 0,!1,void 0,this),t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV("label",{className:"flex items-center gap-2 cursor-pointer",children:[t9.jsxDEV("input",{type:"radio",name:"run-location",checked:J.type==="main",onChange:()=>G("main"),className:"w-4 h-4 text-primary border-input focus:ring-primary"},void 0,!1,void 0,this),t9.jsxDEV(Lq,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),t9.jsxDEV("span",{className:"text-sm",children:"Main project"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t9.jsxDEV("label",{className:"flex items-center gap-2 cursor-pointer",children:[t9.jsxDEV("input",{type:"radio",name:"run-location",checked:J.type==="worktree",onChange:()=>G("worktree"),disabled:!M,className:"w-4 h-4 text-primary border-input focus:ring-primary disabled:opacity-50"},void 0,!1,void 0,this),t9.jsxDEV(pE,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),t9.jsxDEV("span",{className:`text-sm ${!M?"text-muted-foreground":""}`,children:"Existing worktree"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.type==="worktree"&&M&&t9.jsxDEV("div",{className:"ml-6",children:[t9.jsxDEV(H1,{value:J.path||Q[0]?.path||"",onValueChange:W,children:[t9.jsxDEV(V5,{children:t9.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),t9.jsxDEV(j5,{children:Q.map((L)=>t9.jsxDEV(F4,{value:L.path,children:[L.branch,L.isLocked&&" (locked)"]},L.path,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.path&&t9.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1 truncate",children:J.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!M&&t9.jsxDEV("p",{className:"text-xs text-muted-foreground ml-6",children:"No existing worktrees found."},void 0,!1,void 0,this),t9.jsxDEV("label",{className:"flex items-center gap-2 cursor-pointer",children:[t9.jsxDEV("input",{type:"radio",name:"run-location",checked:J.type==="new",onChange:()=>G("new"),className:"w-4 h-4 text-primary border-input focus:ring-primary"},void 0,!1,void 0,this),t9.jsxDEV(cQ,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),t9.jsxDEV("span",{className:"text-sm",children:"Create new worktree"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.type==="new"&&t9.jsxDEV("div",{className:"ml-6 space-y-3",children:[t9.jsxDEV("div",{className:"space-y-1",children:[t9.jsxDEV(NZ,{htmlFor:"new-branch-name",className:"text-xs",children:"Branch name"},void 0,!1,void 0,this),t9.jsxDEV(a5,{id:"new-branch-name",value:J.branch||"",onChange:q,placeholder:"feature/my-branch",className:"h-8 text-sm"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t9.jsxDEV("div",{className:"space-y-1",children:[t9.jsxDEV(NZ,{htmlFor:"base-branch",className:"text-xs",children:"Base branch"},void 0,!1,void 0,this),t9.jsxDEV(a5,{id:"base-branch",value:J.baseBranch||"",onChange:H,placeholder:"main",className:"h-8 text-sm"},void 0,!1,void 0,this),t9.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Branch to create from (defaults to main)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&t9.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[t9.jsxDEV(Mq,{className:"w-4 h-4"},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var yK6="",gK6=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),mK6=async(J)=>{let Z=await fetch(`${yK6}/api/p/${J}/worktrees`,{headers:gK6()});return P9(Z,"Failed to fetch worktrees")},uK6=async(J,{branch:Z,baseBranch:Q})=>{let K=await fetch(`${yK6}/api/p/${J}/worktrees`,{method:"POST",headers:gK6(),body:JSON.stringify({branch:Z,baseBranch:Q})});return P9(K,"Failed to create worktree")};var pK6=(J)=>{return qQ({queryKey:["worktrees",J],queryFn:()=>mK6(J),enabled:!!J,staleTime:30000})},cK6=(J)=>{let Z=e9();return AJ({mutationFn:({branch:Q,baseBranch:K})=>uK6(J,{branch:Q,baseBranch:K}),onSuccess:()=>{Z.invalidateQueries({queryKey:["worktrees",J]})}})};var p9=f0(z8(),1),NH8=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],lK6=({open:J,onOpenChange:Z,projectId:Q,onSuccess:K,initialPrompt:X=""})=>{let[U,Y]=jK.useState(""),[z,G]=jK.useState("claude"),[W,q]=jK.useState(""),[H,B]=jK.useState({type:"main",path:null}),[M,L]=jK.useState(""),[A,N]=jK.useState(""),[I,R]=jK.useState(!1),[D,V]=jK.useState({}),[P,T]=jK.useState(!1),[C,S]=jK.useState(null),[v,h]=jK.useState(null);jK.useEffect(()=>{if(X)L(X)},[X]);let{data:_,isLoading:$,error:k}=pK6(J?Q:null),f=_?.worktrees??[],b=_?.isGitProject??!0,y=fK6(Q),g=Md(Q),m=cK6(Q),{data:u}=LD(Q,A.trim()||null),d=u?.parameters??[],l=u?.detectedVariables??[],r=A.trim().length>0,t=()=>{Y(""),G("claude"),q(""),B({type:"main",path:null}),L(X||""),N(""),S(null),h(null),V({}),T(!1)},z0=()=>{t(),Z(!1)},J0=()=>{if(H.type==="main")return;return H.path||void 0},H0=(q0)=>{y.mutate({name:U.trim()||void 0,agent:z,model:W.trim()||void 0,prompt:M.trim(),workingDirectory:q0},{onSuccess:(P0)=>{if(z0(),K)K(P0)},onError:(P0)=>{S(P0.message)}})},e=()=>{if(!M.trim()){S("Prompt is required");return}if(H.type==="new"&&b){if(!H.branch||!H.branch.trim()){h("Branch name is required");return}}if(S(null),h(null),H.type==="new"&&b&&H.branch)m.mutate({branch:H.branch.trim(),baseBranch:H.baseBranch?.trim()||void 0},{onSuccess:(q0)=>{H0(q0.path)},onError:(q0)=>{h(q0.message)}});else H0(J0())},B0=()=>{R(!0)},U0=(q0)=>{V(q0),g.mutate({id:A.trim(),params:q0,target:"stdout"},{onSuccess:(P0)=>{if(P0.content)L(P0.content);N(""),R(!1)},onError:(P0)=>{S(`Template render failed: ${P0.message}`),R(!1)}})},X0=r?"render":"run",Z0=X0==="run"&&!M.trim(),Q0=m.isPending,F0=y.isPending||g.isPending||Q0;return p9.jsxDEV(p9.Fragment,{children:[p9.jsxDEV(cZ,{open:J,onOpenChange:z0,children:p9.jsxDEV(PZ,{className:"max-w-lg",children:[p9.jsxDEV(EZ,{children:p9.jsxDEV(VZ,{children:"New Job"},void 0,!1,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV("div",{className:"space-y-4 py-4",children:[p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),p9.jsxDEV(a5,{id:"job-name",value:U,onChange:(q0)=>Y(q0.target.value),placeholder:"Auto-generated if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),p9.jsxDEV(H1,{value:z,onValueChange:G,children:[p9.jsxDEV(V5,{children:p9.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(j5,{children:NH8.map((q0)=>p9.jsxDEV(F4,{value:q0.value,children:q0.label},q0.value,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),p9.jsxDEV(a5,{id:"job-model",value:W,onChange:(q0)=>q(q0.target.value),placeholder:"Optional - uses default if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV("button",{type:"button",onClick:()=>T(!P),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[P?p9.jsxDEV(DU,{className:"w-4 h-4"},void 0,!1,void 0,this):p9.jsxDEV(IG,{className:"w-4 h-4"},void 0,!1,void 0,this),p9.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&p9.jsxDEV(hK6,{value:H,onChange:B,worktrees:f,isLoadingWorktrees:$,isGitProject:b,error:k,createError:v,onCreateErrorClear:()=>h(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),p9.jsxDEV(tF,{id:"job-prompt",value:M,onChange:(q0)=>L(q0.target.value),placeholder:"Enter the prompt for the agent...",rows:6},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),p9.jsxDEV(a5,{id:"job-template",value:A,onChange:(q0)=>N(q0.target.value),placeholder:"Template ID (optional)"},void 0,!1,void 0,this),r&&p9.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Click Render to populate prompt from template"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&p9.jsxDEV("div",{className:"text-sm text-destructive",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV(nQ,{children:[p9.jsxDEV(a6,{variant:"outline",onClick:z0,children:"Cancel"},void 0,!1,void 0,this),X0==="render"?p9.jsxDEV(a6,{onClick:B0,disabled:F0,children:[p9.jsxDEV(pQ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),F0?"Rendering...":"Render"]},void 0,!0,void 0,this):p9.jsxDEV(a6,{onClick:e,disabled:Z0||F0,children:[p9.jsxDEV(nY,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),Q0?"Creating worktree...":y.isPending?"Running...":"Run"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(cZ,{open:I,onOpenChange:R,children:p9.jsxDEV(PZ,{className:"max-w-lg",children:[p9.jsxDEV(EZ,{children:p9.jsxDEV(VZ,{className:"flex items-center gap-2",children:[p9.jsxDEV(pQ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",uU(u?.path)," (",A,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(ki,{fields:d,detectedVariables:l,initialValues:D,onSubmit:U0,onCancel:()=>R(!1),isSubmitting:g.isPending},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var c8=f0(z8(),1),IH8=86400000,RH8=({status:J})=>{let Z={running:"text-blue-700 border-blue-300 bg-blue-50 dark:text-blue-300 dark:border-blue-700 dark:bg-blue-900/30",completed:"text-green-700 border-green-300 bg-green-50 dark:text-green-300 dark:border-green-700 dark:bg-green-900/30",error:"text-red-700 border-red-300 bg-red-50 dark:text-red-300 dark:border-red-700 dark:bg-red-900/30",pending:"text-gray-700 border-gray-300 bg-gray-50 dark:text-gray-300 dark:border-gray-700 dark:bg-gray-900/30"};return c8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase ${Z[J]||Z.pending}`,children:J},void 0,!1,void 0,this)},dK6=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},wH8=(J)=>{if(J===null||J===void 0)return"-";if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},iK6=async(J)=>{if(!J)return;try{await navigator.clipboard.writeText(J),W1.success("Copied")}catch(Z){console.error("Failed to copy:",Z)}},DH8=(J,Z)=>{if(!J||!Z)return null;let Q=`${Z}/worktree/`;if(J.startsWith(Q)){let K=J.slice(Q.length),X=K.endsWith("/")?K.slice(0,-1):K,U=X.indexOf("/");return U===-1?X:X.slice(0,U)}if(J.startsWith(Z)){let K=J.slice(Z.length);return K.startsWith("/")?K.slice(1):K}return J},HB0=({job:J,onClick:Z,projectPath:Q})=>{let K=DH8(J.workingDirectory,Q);return c8.jsxDEV("div",{onClick:()=>Z(J),className:"p-3 rounded cursor-pointer flex items-center gap-3 hover:bg-muted border-b border-border last:border-b-0",children:[c8.jsxDEV(RH8,{status:J.fields?.status},void 0,!1,void 0,this),c8.jsxDEV(Y7,{content:"Click to copy",children:c8.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(X)=>{X.stopPropagation(),iK6(J.id)},children:J.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV(Y7,{content:J.sessionId||"No session ID",children:c8.jsxDEV("span",{className:"w-24 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(X)=>{if(X.stopPropagation(),J.sessionId)iK6(J.sessionId)},children:J.sessionId?J.sessionId.slice(0,8)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV("div",{className:"flex-1 min-w-0",children:[c8.jsxDEV("span",{className:"truncate text-sm font-medium block",children:J.name},void 0,!1,void 0,this),K&&c8.jsxDEV(Y7,{content:J.workingDirectory,children:c8.jsxDEV("span",{className:"text-xs text-muted-foreground truncate block",children:K},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.agent},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.status==="running"?J.fields?.pid||"-":"-"},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:dK6(J.fields?.startedAt)},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:dK6(J.fields?.completedAt)},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:wH8(J.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},rK6=({title:J,count:Z})=>{return c8.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[c8.jsxDEV("h3",{className:"text-sm font-semibold text-foreground",children:J},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",Z,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},PH8=({column:J,sortColumn:Z,sortDirection:Q})=>{if(Z!==J)return c8.jsxDEV(iM,{className:"w-3 h-3 ml-1 opacity-50"},void 0,!1,void 0,this);return Q==="asc"?c8.jsxDEV(rM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this):c8.jsxDEV(dM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)},BB0=({onSort:J,sortColumn:Z,sortDirection:Q})=>{return c8.jsxDEV("div",{className:"flex items-center gap-3 px-3 py-2 text-xs text-muted-foreground border-b border-border bg-muted/30",children:[{key:"status",label:"Status",width:"w-20"},{key:"id",label:"Job ID",width:"w-16",sortable:!1},{key:"sessionId",label:"Session",width:"w-24",sortable:!1},{key:"name",label:"Name",width:"flex-1"},{key:"agent",label:"Agent",width:"w-16"},{key:"pid",label:"PID",width:"w-16",sortable:!1},{key:"startedAt",label:"Started",width:"w-28"},{key:"completedAt",label:"Completed",width:"w-28"},{key:"tokensUsed",label:"Tokens",width:"w-16 text-right"}].map((X)=>{let U=X.sortable!==!1;return c8.jsxDEV("span",{className:`${X.width} select-none flex items-center ${U?"cursor-pointer hover:text-foreground":""}`,onClick:U?()=>J(X.key):void 0,children:[X.label,U&&c8.jsxDEV(PH8,{column:X.key,sortColumn:Z,sortDirection:Q},void 0,!1,void 0,this)]},X.key,!0,void 0,this)})},void 0,!1,void 0,this)},nK6=["active","history"],qB0=(J,Z,Q="")=>{let K=Z?`/project/${J}/store/${Z}/jobs`:`/project/${J}/jobs`;return Q?`${K}/${Q}`:K},sK6=({active:J,onClick:Z,children:Q})=>c8.jsxDEV("button",{onClick:Z,role:"tab","aria-selected":J,tabIndex:J?0:-1,className:`px-4 py-2 text-sm font-medium whitespace-nowrap ${J?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"}`,children:Q},void 0,!1,void 0,this),EH8=({activeJobs:J,completedJobs:Z,onJobClick:Q,onNewJob:K,projectPath:X,onActiveSort:U,activeSortColumn:Y,activeSortDirection:z,onCompletedSort:G,completedSortColumn:W,completedSortDirection:q})=>c8.jsxDEV("div",{className:"space-y-6",children:[c8.jsxDEV("div",{className:"flex justify-start",children:c8.jsxDEV(a6,{size:"sm",variant:"warning",onClick:K,children:[c8.jsxDEV(cQ,{className:"w-4 h-4"},void 0,!1,void 0,this),c8.jsxDEV(tM,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV("div",{children:[c8.jsxDEV(rK6,{title:"Active Jobs",count:J.length},void 0,!1,void 0,this),J.length>0?c8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[c8.jsxDEV(BB0,{onSort:U,sortColumn:Y,sortDirection:z},void 0,!1,void 0,this),J.map((H)=>c8.jsxDEV(HB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):c8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[c8.jsxDEV(nY,{className:"w-4 h-4 opacity-50"},void 0,!1,void 0,this),"No active jobs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c8.jsxDEV("div",{children:[c8.jsxDEV(rK6,{title:"Recently Completed",count:Z.length},void 0,!1,void 0,this),Z.length>0?c8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[c8.jsxDEV(BB0,{onSort:G,sortColumn:W,sortDirection:q},void 0,!1,void 0,this),Z.map((H)=>c8.jsxDEV(HB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):c8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[c8.jsxDEV(bA,{className:"w-4 h-4 opacity-50"},void 0,!1,void 0,this),"No jobs completed in the last 24 hours"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),VH8=({completedJobs:J,onJobClick:Z,projectPath:Q,onSort:K,sortColumn:X,sortDirection:U})=>c8.jsxDEV("div",{children:J.length>0?c8.jsxDEV(c8.Fragment,{children:[c8.jsxDEV("div",{className:"text-sm text-muted-foreground mb-2",children:[J.length," completed job",J.length!==1?"s":""]},void 0,!0,void 0,this),c8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[c8.jsxDEV(BB0,{onSort:K,sortColumn:X,sortDirection:U},void 0,!1,void 0,this),J.map((Y)=>c8.jsxDEV(HB0,{job:Y,onClick:Z,projectPath:Q},Y.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):c8.jsxDEV("div",{className:"text-center py-8 text-muted-foreground",children:[c8.jsxDEV(bA,{className:"w-8 h-8 mx-auto mb-2 opacity-50"},void 0,!1,void 0,this),c8.jsxDEV("p",{className:"text-sm",children:"No completed jobs yet"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Sk=()=>{let{id:J,storeCode:Z,tab:Q}=I5(),K=GZ(),X=pJ(),{data:U}=Y1(J),Y=Q&&!nK6.includes(Q),z=nK6.includes(Q)?Q:"active";z1(U?`${U.name} - Jobs`:"CAW");let[G,W]=o5.useState(!1),[q,H]=o5.useState(""),[B,M]=o5.useState("startedAt"),[L,A]=o5.useState("desc"),[N,I]=o5.useState("completedAt"),[R,D]=o5.useState("desc"),[V,P]=o5.useState("completedAt"),[T,C]=o5.useState("desc"),S=Z??"A";pH(J);let{data:v=[],isLoading:h,error:_,refetch:$}=kK6(J,{store:S}),k=(t)=>{return["startedAt","completedAt","tokensUsed"].includes(t)?"desc":"asc"},f=(t)=>{if(B===t)A((z0)=>z0==="asc"?"desc":"asc");else M(t),A(k(t))},b=(t)=>{if(N===t)D((z0)=>z0==="asc"?"desc":"asc");else I(t),D(k(t))},y=(t)=>{if(V===t)C((z0)=>z0==="asc"?"desc":"asc");else P(t),C(k(t))},g=(t,z0,J0)=>{return[...t].sort((H0,e)=>{let B0=0;switch(z0){case"status":let U0={running:0,completed:1,error:2};B0=(U0[H0.status]??3)-(U0[e.status]??3);break;case"name":B0=(H0.name||"").localeCompare(e.name||"");break;case"agent":B0=(H0.agent||"").localeCompare(e.agent||"");break;case"startedAt":case"completedAt":let X0=(F0)=>{if(!F0)return 0;let q0=new Date(F0).getTime();return isNaN(q0)?0:q0},Z0=X0(H0[z0]),Q0=X0(e[z0]);B0=Z0-Q0;break;case"tokensUsed":B0=(H0.tokensUsed??0)-(e.tokensUsed??0);break;default:B0=0}return J0==="asc"?B0:-B0})},m=o5.useMemo(()=>{let t=v.filter((z0)=>z0.fields?.status==="running");return g(t,B,L)},[v,B,L]),u=o5.useMemo(()=>{let t=Date.now()-IH8,z0=v.filter((J0)=>J0.fields?.status==="completed"||J0.fields?.status==="error").filter((J0)=>J0.fields?.completedAt&&new Date(J0.fields?.completedAt).getTime()>t);return g(z0,N,R)},[v,N,R]),d=o5.useMemo(()=>{let t=v.filter((z0)=>z0.fields?.status==="completed"||z0.fields?.status==="error");return g(t,V,T)},[v,V,T]),l=(t)=>{let z0=Z?`/project/${J}/store/${Z}/job/${t.id}`:`/project/${J}/job/${t.id}`;K(z0,{state:{fromTab:z}})},r=(t)=>{if(t&&t.id){let z0=Z?`/project/${J}/store/${Z}/job/${t.id}`:`/project/${J}/job/${t.id}`;K(z0,{state:{fromTab:z}})}};if(o5.useEffect(()=>{if(X.state?.openNewJobWithPrompt)H(X.state.openNewJobWithPrompt),W(!0),K(X.pathname,{replace:!0,state:{}})},[X.state,K,X.pathname]),o5.useEffect(()=>{if(Y)K(qB0(J,Z,"active"),{replace:!0})},[Y,K,J,Z]),Y)return null;if(h)return c8.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(_)return c8.jsxDEV("div",{className:"p-6",children:[c8.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),c8.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:_.message},void 0,!1,void 0,this),c8.jsxDEV(a6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>$(),children:[c8.jsxDEV(JO,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Retry"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return c8.jsxDEV("div",{className:"h-full flex flex-col",children:[c8.jsxDEV("div",{className:"flex border-b overflow-x-auto bg-muted/50 px-2",role:"tablist","aria-label":"Jobs tabs",children:[c8.jsxDEV(sK6,{active:z==="active",onClick:()=>K(qB0(J,Z,"active")),children:"Active"},void 0,!1,void 0,this),c8.jsxDEV(sK6,{active:z==="history",onClick:()=>K(qB0(J,Z,"history")),children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c8.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:z==="active"?c8.jsxDEV(EH8,{activeJobs:m,completedJobs:u,onJobClick:l,onNewJob:()=>W(!0),projectPath:U?.path,onActiveSort:f,activeSortColumn:B,activeSortDirection:L,onCompletedSort:b,completedSortColumn:N,completedSortDirection:R},void 0,!1,void 0,this):c8.jsxDEV(VH8,{completedJobs:d,onJobClick:l,projectPath:U?.path,onSort:y,sortColumn:V,sortDirection:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV(lK6,{open:G,onOpenChange:(t)=>{if(W(t),!t)H("")},projectId:J,onSuccess:r,initialPrompt:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var FU=f0(j6(),1);var FB0=f0(j6(),1);var $k=f0(z8(),1),aK6=({value:J,disabled:Z=!1,className:Q=""})=>{let[K,X]=FB0.useState(!1);return $k.jsxDEV(Y7,{content:"Copy to clipboard",children:$k.jsxDEV(a6,{variant:"ghost",size:"sm",onClick:async()=>{if(Z)return;await navigator.clipboard.writeText(J),X(!0),setTimeout(()=>X(!1),2000)},disabled:Z,className:Q,children:K?$k.jsxDEV(m1,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):$k.jsxDEV(uQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var KM=f0(j6(),1);var C1=f0(z8(),1),oK6=({open:J,onOpenChange:Z,sessionId:Q,onContinue:K,isLoading:X})=>{let[U,Y]=KM.useState(""),z=KM.useRef(null);KM.useEffect(()=>{if(!J)Y("")},[J]),KM.useEffect(()=>{if(J&&z.current){let H=setTimeout(()=>{z.current?.focus()},50);return()=>clearTimeout(H)}},[J]);let G=(H)=>{H.preventDefault();let B=U.trim();if(B)K(B)},W=()=>{Y(""),Z(!1)},q=!U.trim()||X;return C1.jsxDEV(cZ,{open:J,onOpenChange:W,children:C1.jsxDEV(PZ,{children:[C1.jsxDEV(EZ,{children:C1.jsxDEV(VZ,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),C1.jsxDEV("form",{onSubmit:G,className:"space-y-4",children:[C1.jsxDEV("div",{className:"space-y-2",children:[C1.jsxDEV(NZ,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),C1.jsxDEV(a5,{id:"session-id",value:Q||"",readOnly:!0,className:"font-mono text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C1.jsxDEV("div",{className:"space-y-2",children:[C1.jsxDEV(NZ,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),C1.jsxDEV(tF,{ref:z,id:"continue-prompt",value:U,onChange:(H)=>Y(H.target.value),placeholder:"Enter your follow-up prompt...",rows:6,autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C1.jsxDEV(nQ,{children:[C1.jsxDEV(a6,{type:"button",variant:"outline",onClick:W,children:"Cancel"},void 0,!1,void 0,this),C1.jsxDEV(a6,{type:"submit",disabled:q,children:[X&&C1.jsxDEV(NJ,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this),"Continue"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var E8=f0(z8(),1),jH8=({status:J})=>{let Z={running:{icon:NJ,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:TH,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:CH,class:"text-red-700 border-red-300 bg-red-50",animate:!1},pending:{icon:gE,class:"text-gray-700 border-gray-300 bg-gray-50",animate:!1}},{icon:Q,class:K,animate:X}=Z[J]||Z.pending;return E8.jsxDEV("span",{className:`inline-flex items-center gap-1.5 rounded border px-2 py-1 text-sm font-medium ${K}`,children:[E8.jsxDEV(Q,{className:`w-4 h-4 ${X?"animate-spin":""}`},void 0,!1,void 0,this),J]},void 0,!0,void 0,this)},tK6=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})},TH8=(J)=>{if(J===null||J===void 0)return"-";let Z=parseInt(J,10);if(isNaN(Z))return J;if(Z>=1000)return`${(Z/1000).toFixed(1)}k`;return Z.toString()},eK6=(J,Z)=>{if(!J||!Z)return null;let Q=`${Z}/worktree/`;if(J.startsWith(Q)){let K=J.slice(Q.length),X=K.endsWith("/")?K.slice(0,-1):K,U=X.indexOf("/");return U===-1?X:X.slice(0,U)}if(J.startsWith(Z)){let K=J.slice(Z.length);return K.startsWith("/")?K.slice(1):K}return J},JX6=(J)=>{if(!J)return[];let Z=/---\n## Turn (\d+)\n/g,Q=[...J.matchAll(Z)];if(Q.length===0)return[{turnNumber:1,content:J.trim()}];let K=[],X=Q[0].index,U=J.slice(0,X).trim();if(U)K.push({turnNumber:1,content:U});for(let Y=0;Y<Q.length;Y++){let z=Q[Y],G=parseInt(z[1],10),W=z.index+z[0].length,q=Q[Y+1]?.index??J.length,H=J.slice(W,q).trim();K.push({turnNumber:G,content:H})}return K},ZX6=({title:J,docId:Z,isOpen:Q,onToggle:K,children:X})=>E8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[E8.jsxDEV("button",{onClick:()=>K(!Q),className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[Q?E8.jsxDEV(DU,{className:"w-4 h-4"},void 0,!1,void 0,this):E8.jsxDEV(IG,{className:"w-4 h-4"},void 0,!1,void 0,this),E8.jsxDEV(pQ,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),E8.jsxDEV("span",{className:"font-medium",children:J},void 0,!1,void 0,this),Z&&E8.jsxDEV("span",{className:"text-xs text-muted-foreground ml-auto font-mono",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&E8.jsxDEV("div",{className:"p-4",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this),QX6=({turnNumber:J,promptContent:Z,outputContent:Q,showHeading:K,promptDocId:X,outputDocId:U,isPromptOpen:Y,setIsPromptOpen:z,isOutputOpen:G,setIsOutputOpen:W})=>{return E8.jsxDEV("div",{className:"space-y-4",children:[K&&E8.jsxDEV("h3",{className:"text-lg font-semibold text-muted-foreground",children:["Turn ",J]},void 0,!0,void 0,this),Q&&E8.jsxDEV(ZX6,{title:"Output",docId:U,isOpen:G,onToggle:W,children:E8.jsxDEV(y2,{markdown:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(ZX6,{title:"Prompt",docId:X,isOpen:Y,onToggle:z,children:E8.jsxDEV(y2,{markdown:Z||""},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},CH8=86400000,MB0=()=>{let{id:J,storeCode:Z,jobId:Q}=I5(),K=GZ(),X=pJ(),{data:U}=Y1(J);z1(U?`${U.name} - Job: ${Q}`:"CAW"),pH(J);let{data:Y,isLoading:z,error:G}=vK6(J,Q),{data:W,isLoading:q}=_K6(J,Q),{promptDoc:H,outputDoc:B}=FU.useMemo(()=>{if(!W)return{promptDoc:null,outputDoc:null};let B0=W.documents||[],U0=B0.find((Z0)=>Z0.name==="prompt.md"),X0=B0.find((Z0)=>Z0.name==="output.md");return{promptDoc:U0,outputDoc:X0}},[W]),{data:M}=m2(J,H?.id),{data:L}=m2(J,B?.id),A=M?.draftContent??M?.publishedContent??"",N=L?.draftContent??L?.publishedContent??"",I=FU.useMemo(()=>JX6(A),[A]),R=FU.useMemo(()=>JX6(N),[N]),D=I.length>1||R.length>1,[V,P]=FU.useState({}),T=Math.max(I.length,R.length);FU.useEffect(()=>{P((B0)=>{let U0={...B0};for(let X0=0;X0<T;X0++)if(!(X0 in U0))U0[X0]={promptOpen:!0,outputOpen:!0};return U0})},[T]);let C=()=>{P((B0)=>{let U0={};for(let X0 of Object.keys(B0))U0[X0]={promptOpen:!1,outputOpen:!1};return U0})},S=()=>{P((B0)=>{let U0={};for(let X0 of Object.keys(B0))U0[X0]={promptOpen:!0,outputOpen:!0};return U0})},v=async()=>{try{await navigator.clipboard.writeText(Q),W1.success("ID copied")}catch(B0){console.error("Failed to copy ID:",B0)}},h=(B0)=>{if(!B0)return"active";if(B0.fields?.status==="running")return"active";if(B0.fields?.completedAt){let U0=new Date(B0.fields?.completedAt).getTime(),X0=Date.now()-CH8;if(U0>X0)return"active"}return"history"},_=()=>{let B0=X.state?.fromTab||h(Y),U0=Z?`/project/${J}/store/${Z}/jobs/${B0}`:`/project/${J}/jobs/${B0}`;K(U0)},[$,k]=FU.useState(!1),f=bK6(J,Q),b=(Y?.status==="completed"||Y?.status==="error")&&Y?.sessionId,y=async(B0)=>{await f.mutateAsync({prompt:B0}),k(!1)},[g,m]=FU.useState(!1),[u,d]=FU.useState(""),[l,r]=FU.useState(null),t=xK6(J),z0=()=>{d(Y.name),r(null),m(!0)},J0=async()=>{let B0=u.trim();if(!B0||B0===Y.name){m(!1),r(null);return}try{await t.mutateAsync({id:Q,name:B0}),m(!1),r(null)}catch(U0){let X0=U0?.message||"Failed to rename job";r(X0)}},H0=(B0)=>{if(B0.key==="Enter")B0.preventDefault(),J0();if(B0.key==="Escape")m(!1),r(null)},e=(B0)=>{if(d(B0.target.value),l)r(null)};if(z)return E8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:E8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground",children:[E8.jsxDEV(NJ,{className:"w-5 h-5 animate-spin"},void 0,!1,void 0,this),"Loading job..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(G||!Y)return E8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:E8.jsxDEV("div",{className:"text-center",children:[E8.jsxDEV(S7,{className:"w-8 h-8 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),E8.jsxDEV("p",{className:"text-destructive font-medium",children:"Failed to load job"},void 0,!1,void 0,this),E8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-1",children:G?.message||"Job not found"},void 0,!1,void 0,this),E8.jsxDEV(a6,{variant:"outline",className:"mt-4",onClick:_,children:[E8.jsxDEV(_A,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Back to Jobs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return E8.jsxDEV("div",{className:"h-full flex flex-col p-6 overflow-auto",children:[E8.jsxDEV("div",{className:"flex items-start gap-4 mb-6",children:[E8.jsxDEV(a6,{variant:"ghost",size:"sm",onClick:_,children:E8.jsxDEV(_A,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV("div",{className:"flex-1",children:[E8.jsxDEV("div",{className:"flex items-center gap-3 mb-2",children:[g?E8.jsxDEV("input",{type:"text",value:u,onChange:e,onBlur:J0,onKeyDown:H0,autoFocus:!0,className:"text-xl font-semibold px-2 py-1 border border-input rounded bg-background"},void 0,!1,void 0,this):E8.jsxDEV(E8.Fragment,{children:[E8.jsxDEV("h1",{className:"text-xl font-semibold",children:Y.name},void 0,!1,void 0,this),E8.jsxDEV(Y7,{content:"Rename job",children:E8.jsxDEV(a6,{variant:"ghost",size:"sm",onClick:z0,children:E8.jsxDEV(X1,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV(jH8,{status:Y.fields?.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l&&E8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center gap-2 text-destructive",children:[E8.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),E8.jsxDEV("span",{className:"text-sm",children:l},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Agent:"},void 0,!1,void 0,this),E8.jsxDEV("span",{className:"capitalize",children:Y.agent},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y.model&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Model:"},void 0,!1,void 0,this),Y.model]},void 0,!0,void 0,this),E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Started:"},void 0,!1,void 0,this),tK6(Y.fields?.startedAt)]},void 0,!0,void 0,this),Y.fields?.completedAt&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Completed:"},void 0,!1,void 0,this),tK6(Y.fields?.completedAt)]},void 0,!0,void 0,this),Y.tokensUsed&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Tokens:"},void 0,!1,void 0,this),TH8(Y.tokensUsed)]},void 0,!0,void 0,this),eK6(Y.workingDirectory,U?.path)&&E8.jsxDEV(Y7,{content:Y.workingDirectory,children:E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Location:"},void 0,!1,void 0,this),eK6(Y.workingDirectory,U?.path)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y.fields?.status==="completed"&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Session:"},void 0,!1,void 0,this),E8.jsxDEV("span",{children:Y.sessionId||"-"},void 0,!1,void 0,this),E8.jsxDEV(aK6,{value:Y.sessionId||"",disabled:!Y.sessionId},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y.errorMessage&&E8.jsxDEV("div",{className:"mt-3 p-3 bg-destructive/10 border border-destructive/30 rounded-md",children:[E8.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error"},void 0,!1,void 0,this),E8.jsxDEV("p",{className:"text-sm text-destructive/80 mt-1",children:Y.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV("div",{className:"flex items-center gap-2",children:[b&&E8.jsxDEV(a6,{variant:"default",size:"sm",onClick:()=>k(!0),children:[E8.jsxDEV(lE,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Continue Conversation"]},void 0,!0,void 0,this),E8.jsxDEV(Y7,{content:"Copy job ID",children:E8.jsxDEV(a6,{variant:"outline",size:"sm",onClick:v,children:[E8.jsxDEV(uQ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I.length>=3&&E8.jsxDEV("div",{className:"flex gap-2 mb-4",children:[E8.jsxDEV(a6,{variant:"outline",size:"sm",onClick:C,children:"Collapse All"},void 0,!1,void 0,this),E8.jsxDEV(a6,{variant:"outline",size:"sm",onClick:S,children:"Expand All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV("div",{className:"flex-1 space-y-6",children:q?E8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-8",children:[E8.jsxDEV(NJ,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading documents..."]},void 0,!0,void 0,this):D?[...Array(Math.max(I.length,R.length))].map((B0,U0,X0)=>{let Z0=X0.length-1-U0,Q0=I[Z0],F0=R[Z0],q0=Q0?.turnNumber??F0?.turnNumber??Z0+1;return E8.jsxDEV(QX6,{turnNumber:q0,promptContent:Q0?.content,outputContent:F0?.content,showHeading:!0,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[Z0]?.promptOpen??!0,setIsPromptOpen:(P0)=>P((M0)=>({...M0,[Z0]:{...M0[Z0],promptOpen:P0}})),isOutputOpen:V[Z0]?.outputOpen??!0,setIsOutputOpen:(P0)=>P((M0)=>({...M0,[Z0]:{...M0[Z0],outputOpen:P0}}))},Z0,!1,void 0,this)}):E8.jsxDEV(QX6,{turnNumber:1,promptContent:I[0]?.content,outputContent:R[0]?.content,showHeading:!1,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[0]?.promptOpen??!0,setIsPromptOpen:(B0)=>P((U0)=>({...U0,[0]:{...U0[0],promptOpen:B0}})),isOutputOpen:V[0]?.outputOpen??!0,setIsOutputOpen:(B0)=>P((U0)=>({...U0,[0]:{...U0[0],outputOpen:B0}}))},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(oK6,{open:$,onOpenChange:k,sessionId:Y.sessionId,onContinue:y,isLoading:f.isPending},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var TK=f0(j6(),1);var V3=f0(j6(),1);var j3=f0(z8(),1),ni=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("rounded-lg border border-border bg-card text-card-foreground shadow-sm",J),...Z},void 0,!1,void 0,this));ni.displayName="Card";var SH8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("flex flex-col space-y-1.5 p-6",J),...Z},void 0,!1,void 0,this));SH8.displayName="CardHeader";var $H8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("h3",{ref:Q,className:k8("text-2xl font-semibold leading-none tracking-tight",J),...Z},void 0,!1,void 0,this));$H8.displayName="CardTitle";var kH8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("p",{ref:Q,className:k8("text-sm text-muted-foreground",J),...Z},void 0,!1,void 0,this));kH8.displayName="CardDescription";var si=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("p-6 pt-0",J),...Z},void 0,!1,void 0,this));si.displayName="CardContent";var vH8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("flex items-center p-6 pt-0",J),...Z},void 0,!1,void 0,this));vH8.displayName="CardFooter";var ai="",oi=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),KX6=async(J)=>{let Z=await fetch(`${ai}/api/p/${J}/export/preview`,{headers:oi()});return P9(Z,"Failed to get export preview")},XX6=async(J)=>{let Z=await fetch(`${ai}/api/p/${J}/exports`,{headers:oi()});return P9(Z,"Failed to get exports")},UX6=async(J)=>{let Z=await fetch(`${ai}/api/p/${J}/export`,{method:"POST",headers:oi(),body:JSON.stringify({confirm:!0})});return P9(Z,"Failed to export documents")},YX6=async(J,Z)=>{let Q=await fetch(`${ai}/api/p/${J}/import`,{method:"POST",headers:oi(),body:JSON.stringify({filename:Z})});return P9(Q,"Failed to import documents")};var c6=f0(z8(),1),zX6=()=>{let{id:J}=I5(),{data:Z,isLoading:Q}=Y1(J),[K,X]=TK.useState(!1),[U,Y]=TK.useState(null),[z,G]=TK.useState(!1),[W,q]=TK.useState(null),[H,B]=TK.useState(!1),[M,L]=TK.useState(null),[A,N]=TK.useState(null),[I,R]=TK.useState(!1),[D,V]=TK.useState(!1),[P,T]=TK.useState(null),[C,S]=TK.useState(null),[v,h]=TK.useState([]),[_,$]=TK.useState("");z1(Z?`${Z.name} - Settings`:"CAW");let k=async(r,t)=>{if(Y(null),!navigator.clipboard?.writeText){Y("Clipboard not available");return}try{await navigator.clipboard.writeText(r),t(!0),setTimeout(()=>t(!1),2000)}catch(z0){Y("Failed to copy")}},f=()=>{if(!Z?.objectId)return"";return`claude mcp add caw-${Z.objectId.toLowerCase()} https://caw.localhost/mcp/p/${Z.objectId} --transport http`},b=()=>k(f(),X),y=async()=>{L(null),N(null),q(null),B(!0),G(!0);try{let r=await KX6(Z.objectId);q(r)}catch(r){L(r.message)}finally{B(!1)}},g=async()=>{B(!0),L(null);try{let r=await UX6(Z.objectId);N(r)}catch(r){L(r.message)}finally{B(!1)}},m=()=>{G(!1),q(null),N(null),L(null)},u=async()=>{T(null),S(null),h([]),$(""),R(!0),V(!0);try{let r=await XX6(Z.objectId);if(h(r.exports),r.exports?.length>0)$(r.exports[0].filename)}catch(r){T(r.message)}finally{V(!1)}},d=async()=>{if(!_){T("Please select an export file");return}V(!0),T(null);try{let r=await YX6(Z.objectId,_);S(r)}catch(r){T(r.message)}finally{V(!1)}},l=()=>{R(!1),S(null),T(null)};if(Q)return c6.jsxDEV("div",{className:"p-6",children:c6.jsxDEV("p",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(!Z)return c6.jsxDEV("div",{className:"p-6",children:c6.jsxDEV("p",{className:"text-muted-foreground",children:"Project not found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return c6.jsxDEV("div",{className:"p-6",children:[c6.jsxDEV("h2",{className:"text-2xl font-bold text-foreground mb-6",children:"Project Settings"},void 0,!1,void 0,this),c6.jsxDEV("div",{className:"max-w-2xl space-y-6",children:[c6.jsxDEV(ni,{children:c6.jsxDEV(si,{className:"pt-6 space-y-6",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Project Name"},void 0,!1,void 0,this),c6.jsxDEV("p",{className:"text-foreground mt-1",children:Z.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Path"},void 0,!1,void 0,this),c6.jsxDEV("p",{className:"text-foreground font-mono text-sm mt-1",children:Z.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Add to Claude Code"},void 0,!1,void 0,this),c6.jsxDEV("div",{className:"flex items-start gap-2 mt-1",children:[c6.jsxDEV("pre",{className:"flex-1 bg-muted px-3 py-2 rounded font-mono text-sm text-foreground overflow-x-auto whitespace-pre-wrap",children:f()},void 0,!1,void 0,this),c6.jsxDEV(a6,{variant:"outline",size:"icon",onClick:b,className:"shrink-0",children:K?c6.jsxDEV(m1,{className:"w-4 h-4"},void 0,!1,void 0,this):c6.jsxDEV(uQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&c6.jsxDEV("p",{className:"text-xs text-destructive mt-1",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),c6.jsxDEV(ni,{children:c6.jsxDEV(si,{className:"pt-6",children:c6.jsxDEV("div",{className:"flex items-start justify-between",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"PROJECT STORE (A)"},void 0,!1,void 0,this),c6.jsxDEV("p",{className:"text-foreground text-sm mt-1",children:"Export and import documents, templates, and folders"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{className:"flex gap-2",children:[c6.jsxDEV(a6,{onClick:y,size:"sm",children:[c6.jsxDEV(mE,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Export"]},void 0,!0,void 0,this),c6.jsxDEV(a6,{onClick:u,variant:"outline",size:"sm",children:[c6.jsxDEV(PG,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Import"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV(cZ,{open:z,onOpenChange:G,children:c6.jsxDEV(PZ,{children:[c6.jsxDEV(EZ,{children:[c6.jsxDEV(VZ,{children:A?"Export Complete":"Export Preview"},void 0,!1,void 0,this),c6.jsxDEV(gx,{children:A?"Your content has been exported successfully.":"Review what will be exported to .caw-exports/"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H&&!W&&c6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:c6.jsxDEV(NJ,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M&&c6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[c6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),c6.jsxDEV("span",{className:"text-sm",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W?.toExport&&W?.draftOnly&&!A&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Will be exported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[c6.jsxDEV("li",{children:[W.toExport.documents.length," documents"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[W.toExport.templates.length," templates"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[W.toExport.folders.length," folders"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(W.draftOnly.documents.length>0||W.draftOnly.templates.length>0)&&c6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:c6.jsxDEV("div",{className:"flex items-start gap-2",children:[c6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Draft-only items will NOT be exported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[W.draftOnly.documents.length>0&&c6.jsxDEV("li",{children:[W.draftOnly.documents.length," documents",W.draftOnly.documents.length<=3&&c6.jsxDEV("span",{className:"text-xs ml-1",children:["(",W.draftOnly.documents.map((r)=>r.path).join(", "),")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W.draftOnly.templates.length>0&&c6.jsxDEV("li",{children:[W.draftOnly.templates.length," templates",W.draftOnly.templates.length<=3&&c6.jsxDEV("span",{className:"text-xs ml-1",children:["(",W.draftOnly.templates.map((r)=>r.path).join(", "),")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Exported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[c6.jsxDEV("li",{children:[A.counts.documents," documents"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[A.counts.templates," templates"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[A.counts.folders," folders"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Saved to: ",c6.jsxDEV("code",{className:"bg-muted px-1 rounded",children:".caw-exports/"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV(nQ,{children:!A?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(a6,{variant:"outline",onClick:m,children:"Cancel"},void 0,!1,void 0,this),c6.jsxDEV(a6,{onClick:g,disabled:H||!W,children:H?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(NJ,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this),"Exporting..."]},void 0,!0,void 0,this):"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c6.jsxDEV(a6,{onClick:m,children:"Done"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),c6.jsxDEV(cZ,{open:I,onOpenChange:R,children:c6.jsxDEV(PZ,{children:[c6.jsxDEV(EZ,{children:[c6.jsxDEV(VZ,{children:C?"Import Complete":"Import from .caw-exports/"},void 0,!1,void 0,this),c6.jsxDEV(gx,{children:C?"Your content has been imported successfully.":"Import documents, templates, and folders from a previous export."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&c6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[c6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),c6.jsxDEV("span",{className:"text-sm",children:P},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D&&v.length===0&&!P&&c6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:c6.jsxDEV(NJ,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),!C&&!D&&v.length===0&&!P&&c6.jsxDEV("div",{className:"text-center py-4 text-muted-foreground",children:"No exports found. Export your data first."},void 0,!1,void 0,this),!C&&v.length>0&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-foreground block mb-2",children:"Select export file:"},void 0,!1,void 0,this),c6.jsxDEV(H1,{value:_,onValueChange:$,children:[c6.jsxDEV(V5,{children:c6.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),c6.jsxDEV(j5,{children:v.map((r)=>c6.jsxDEV(F4,{value:r.filename,children:[r.filename," (",Math.round(r.size/1024)," KB)"]},r.filename,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:c6.jsxDEV("div",{className:"flex items-start gap-2",children:[c6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Important:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[c6.jsxDEV("li",{children:"The store must be empty before importing"},void 0,!1,void 0,this),c6.jsxDEV("li",{children:"Entity IDs will be remapped to new values"},void 0,!1,void 0,this),c6.jsxDEV("li",{children:"References in content will be updated automatically"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Imported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[c6.jsxDEV("li",{children:[C.counts.documents," documents"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[C.counts.templates," templates"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[C.counts.folders," folders"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Object.keys(C.remapped).length>0&&c6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:[Object.keys(C.remapped).length," entity IDs were remapped."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV(nQ,{children:!C?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(a6,{variant:"outline",onClick:l,children:"Cancel"},void 0,!1,void 0,this),c6.jsxDEV(a6,{onClick:d,disabled:D||!_,children:D?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(NJ,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this),"Importing..."]},void 0,!0,void 0,this):"Import"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c6.jsxDEV(a6,{onClick:l,children:"Done"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var fH8=f0(j6(),1);var XM=f0(z8(),1),ti=()=>{let J=pJ(),Z=GZ();return XM.jsxDEV("div",{className:"flex items-center justify-center h-full",children:XM.jsxDEV("div",{className:"text-center max-w-md px-4",children:[XM.jsxDEV(S7,{className:"w-16 h-16 text-muted-foreground/50 mx-auto mb-4"},void 0,!1,void 0,this),XM.jsxDEV("h2",{className:"text-2xl font-semibold text-foreground mb-2",children:"Page Not Found"},void 0,!1,void 0,this),XM.jsxDEV("p",{className:"text-muted-foreground mb-4",children:["The path ",XM.jsxDEV("code",{className:"bg-muted px-2 py-1 rounded text-sm",children:J.pathname},void 0,!1,void 0,this)," could not be found."]},void 0,!0,void 0,this),XM.jsxDEV(a6,{onClick:()=>Z("/"),children:"Go Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var s2=f0(z8(),1),GX6=()=>{let{theme:J,toggleTheme:Z}=A_(),Q=J==="dark";return s2.jsxDEV("div",{className:"flex items-center justify-between",children:[s2.jsxDEV("div",{children:[s2.jsxDEV("div",{className:"font-medium text-foreground",children:"Theme"},void 0,!1,void 0,this),s2.jsxDEV("div",{className:"text-sm text-muted-foreground",children:Q?"Dark mode":"Light mode"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s2.jsxDEV("button",{onClick:Z,className:"relative w-14 h-8 bg-muted rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",role:"switch","aria-checked":Q,"aria-label":"Toggle dark mode",children:s2.jsxDEV("span",{className:`absolute top-1 left-1 w-6 h-6 bg-background rounded-full shadow transition-transform flex items-center justify-center ${Q?"translate-x-6":"translate-x-0"}`,children:Q?s2.jsxDEV(dE,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this):s2.jsxDEV(iE,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var nz=f0(z8(),1),WX6=()=>{return z1("CAW - Preferences"),nz.jsxDEV("div",{className:"flex-1 p-6",children:[nz.jsxDEV("div",{className:"mb-6",children:nz.jsxDEV("div",{className:"flex items-center gap-3",children:[nz.jsxDEV(sY,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this),nz.jsxDEV("h1",{className:"text-xl font-semibold text-foreground",children:"Preferences"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),nz.jsxDEV("div",{className:"max-w-2xl",children:nz.jsxDEV("section",{className:"mb-8",children:[nz.jsxDEV("h2",{className:"text-lg font-medium text-foreground mb-4",children:"Appearance"},void 0,!1,void 0,this),nz.jsxDEV("div",{className:"bg-card border border-border rounded-lg p-4",children:nz.jsxDEV(GX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var HX6=f0(z8(),1),qX6=(J)=>HX6.jsxDEV(QT0,{className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...J},void 0,!1,void 0,this);var b9=f0(z8(),1),bH8=()=>{return b9.jsxDEV(jo,{children:b9.jsxDEV(mo,{client:hA0,children:[b9.jsxDEV(Po,{children:b9.jsxDEV(W4,{element:b9.jsxDEV(rR0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(W4,{index:!0,element:b9.jsxDEV(oR0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"preferences",element:b9.jsxDEV(WX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"project/:id",element:b9.jsxDEV(aR0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(W4,{index:!0,element:b9.jsxDEV(nf,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"documents/*",element:b9.jsxDEV(Tz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"templates/*",element:b9.jsxDEV(lH0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"stories",element:b9.jsxDEV(WB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs/:tab",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"job/:jobId",element:b9.jsxDEV(MB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"settings",element:b9.jsxDEV(zX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"store/:storeCode",children:[b9.jsxDEV(W4,{index:!0,element:b9.jsxDEV(nf,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"documents/*",element:b9.jsxDEV(Tz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"templates/*",element:b9.jsxDEV(lH0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"stories",element:b9.jsxDEV(WB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs/:tab",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"job/:jobId",element:b9.jsxDEV(MB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"*",element:b9.jsxDEV(ti,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(W4,{path:"*",element:b9.jsxDEV(ti,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(W4,{path:"*",element:b9.jsxDEV(ti,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(qX6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},BX6=bH8;var OB0=f0(z8(),1),OX6=document.getElementById("root");if(!OX6)throw Error("Root element not found");var xH8=MX6.createRoot(OX6);xH8.render(OB0.jsxDEV(FX6.default.StrictMode,{children:OB0.jsxDEV(BX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this));
|
|
3113
|
+
cursor-pointer hover:border-foreground/30 transition-colors${z?" opacity-50":""}`,onClick:()=>Z(J),onKeyDown:(W)=>{if(W.key==="Enter"||W.key===" ")W.preventDefault(),Z(J);if(W.key==="ArrowLeft"){if(W.stopPropagation(),Q&&K){if(K.indexOf(J.fields?.state)>0)Q(J.id,-1)}}if(W.key==="ArrowRight"){if(W.stopPropagation(),Q&&K){let q=K.indexOf(J.fields?.state);if(q>=0&&q<K.length-1)Q(J.id,1)}}},children:[E3.jsxDEV("div",{className:"text-sm truncate",children:J.name},void 0,!1,void 0,this),J.fields?.label&&E3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.label},void 0,!1,void 0,this),J.fields?.colour&&E3.jsxDEV("div",{className:"mt-1 w-3 h-3 rounded-full",style:{backgroundColor:J.fields.colour}},void 0,!1,void 0,this),J.fields?.worker&&E3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.worker},void 0,!1,void 0,this),Array.isArray(J.fields?.dependsOn)&&J.fields.dependsOn.length>0&&E3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:[J.fields.dependsOn.length," dep",J.fields.dependsOn.length!==1?"s":""]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var F7=f0(z8(),1);function BH8({state:J,children:Z}){let{setNodeRef:Q,isOver:K}=GK6({id:J});return F7.jsxDEV("div",{className:"flex-1 min-w-[160px] flex flex-col",children:[F7.jsxDEV("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground",children:J},void 0,!1,void 0,this),F7.jsxDEV("div",{ref:Q,className:`flex-1 min-h-[200px] rounded-md p-2 space-y-2 transition-colors ${K?"bg-muted":"bg-muted/50"}`,children:Z},void 0,!1,void 0,this)]},J,!0,void 0,this)}function BK6({projectId:J,storyId:Z,onOpenDocument:Q}){let[K,X]=lD.useState(null),[U,Y]=lD.useState(!1),[z,G]=lD.useState(""),[W,q]=lD.useState(""),H=XB0(Pk,{activationConstraint:{distance:8}}),B=XB0(Dk),M=p16(H,B),L=HK6(J),A=q3(J),N=e9(),{data:I,isLoading:R,isError:D}=$V(J,{folderId:Z,type:"d"}),V=I?.find((g)=>g.isFolder&&g.subtype==="tasks"),P=V?.fields?.states??[],{data:T,isLoading:C,isError:S}=$V(J,{folderId:V?.id,type:"d",enabled:!!V?.id}),v={};for(let g of P)v[g]=[];if(T){for(let g of T)if(!g.isFolder&&g.fields?.state&&v[g.fields.state])v[g.fields.state].push(g)}let h=V?["folderContents",J,"A",V.id,"d","default"]:null;function _(g,m){if(!h)return;L.mutate({entityId:g,fieldName:"state",value:m},{onMutate:()=>{let u=N.getQueryData(h);return N.setQueryData(h,(d)=>d?.map((l)=>l.id===g?{...l,fields:{...l.fields,state:m}}:l)),{previous:u,queryKey:h}},onError:(u,d,l)=>{if(l?.queryKey&&l?.previous)N.setQueryData(l.queryKey,l.previous)}})}function $(g){X(g.active.id)}function k(g){let{active:m,over:u}=g;if(X(null),!u)return;if(m.data.current?.state===u.id)return;_(m.id,u.id)}function f(g,m){let u=T?.find((t)=>t.id===g);if(!u)return;let d=u.fields?.state,l=P.indexOf(d);if(l===-1)return;let r=l+m;if(r<0||r>=P.length)return;_(g,P[r])}function b(){if(!z.trim())return;if(A.isPending)return;A.mutate({parentId:V.id,name:z.trim(),subtype:"task",fields:{state:W}},{onSuccess:(g)=>{Y(!1),G(""),q(P[0]||""),Q(g.id,{edit:!0})}})}let y=K?T?.find((g)=>g.id===K):null;if(R)return F7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this);if(D)return F7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Failed to load tasks folder."},void 0,!1,void 0,this);if(!V)return F7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"No tasks folder found for this story."},void 0,!1,void 0,this);return F7.jsxDEV(F7.Fragment,{children:[P.length>0&&F7.jsxDEV("div",{className:"px-4 pt-4 flex items-center",children:F7.jsxDEV(a6,{variant:"warning",size:"sm",onClick:()=>{G(""),q(P[0]||""),Y(!0)},children:[F7.jsxDEV(cQ,{className:"w-4 h-4"},void 0,!1,void 0,this),F7.jsxDEV(dY,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV(YK6,{sensors:M,onDragStart:$,onDragEnd:k,children:[F7.jsxDEV("div",{className:"flex gap-3 pb-4 px-4 overflow-x-auto",children:P.map((g)=>F7.jsxDEV(BH8,{state:g,children:C?F7.jsxDEV("div",{className:"text-xs text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this):S?F7.jsxDEV("div",{className:"text-xs text-destructive",children:"Failed to load tasks"},void 0,!1,void 0,this):v[g]?.map((m)=>F7.jsxDEV(zB0,{task:m,onClick:(u)=>Q(u.id),states:P,onMoveTask:f},m.id,!1,void 0,this))},g,!1,void 0,this))},void 0,!1,void 0,this),F7.jsxDEV(WK6,{children:y?F7.jsxDEV(zB0,{task:y,onClick:void 0,onMoveTask:void 0,states:void 0},void 0,!1,void 0,this):null},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F7.jsxDEV(cZ,{open:U,onOpenChange:(g)=>{if(Y(g),!g)G(""),q(P[0]||"")},children:F7.jsxDEV(PZ,{children:[F7.jsxDEV(EZ,{children:F7.jsxDEV(VZ,{children:"New Task"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV("div",{className:"py-4 space-y-4",children:[F7.jsxDEV("div",{children:[F7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Name"},void 0,!1,void 0,this),F7.jsxDEV("input",{type:"text",value:z,onChange:(g)=>G(g.target.value.replace(/\//g,"")),placeholder:"example.md",className:"w-full px-3 py-2 border border-input rounded-md bg-background text-foreground text-sm focus:outline-none focus:ring-2 focus:ring-ring",onKeyDown:(g)=>g.key==="Enter"&&b(),autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F7.jsxDEV("div",{children:[F7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"State"},void 0,!1,void 0,this),F7.jsxDEV(H1,{value:W,onValueChange:q,children:[F7.jsxDEV(V5,{children:F7.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV(j5,{children:P.map((g)=>F7.jsxDEV(F4,{value:g,children:g},g,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F7.jsxDEV(nQ,{children:[F7.jsxDEV(a6,{variant:"outline",onClick:()=>{Y(!1),G(""),q(P[0]||"")},children:"Cancel"},void 0,!1,void 0,this),F7.jsxDEV(a6,{onClick:b,disabled:A.isPending||!z.trim(),children:A.isPending?"Creating...":"Create"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var Vk="",jk=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),FK6=async(J,{store:Z}={})=>{let Q=new URLSearchParams;if(Z)Q.set("store",Z);let K=Q.toString(),X=`${Vk}/api/p/${J}/stories${K?`?${K}`:""}`,U=await fetch(X,{headers:jk()});return P9(U,"Failed to list stories")};var MK6=async(J,{name:Z,store:Q,state:K})=>{let X=await fetch(`${Vk}/api/p/${J}/stories`,{method:"POST",headers:jk(),body:JSON.stringify({name:Z,store:Q,state:K})});return P9(X,"Failed to create story")},OK6=async(J,Z,Q)=>{let K=await fetch(`${Vk}/api/p/${J}/stories/${Z}/state`,{method:"PATCH",headers:jk(),body:JSON.stringify({state:Q})});return P9(K,"Failed to update story state")},LK6=async(J,Z,Q)=>{let K=await fetch(`${Vk}/api/p/${J}/stories/${Z}/name`,{method:"PATCH",headers:jk(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename story")},AK6=async(J,Z)=>{let Q=await fetch(`${Vk}/api/p/${J}/stories/${Z}`,{method:"DELETE",headers:jk()});return P9(Q,"Failed to delete story")};var NK6=(J,{store:Z}={})=>{return qQ({queryKey:["stories",J,Z??"demux"],queryFn:()=>FK6(J,{store:Z}),enabled:!!J,staleTime:30000})};var IK6=(J)=>{let Z=e9();return AJ({mutationFn:({name:Q,store:K,state:X})=>MK6(J,{name:Q,store:K,state:X}),onSuccess:(Q,{store:K})=>{Z.invalidateQueries({queryKey:["stories",J,K??"demux"]})}})},RK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,state:K})=>OK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},wK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,name:K})=>LK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},DK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q})=>AK6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})};var PK6=f0(j6(),1),EK6=(J)=>{let Z=rj0(J,{path:"",store:"A",type:"s"});return{states:PK6.useMemo(()=>Z.data?.fields?.states??[],[Z.data]),isLoading:Z.isLoading,error:Z.error,refetch:Z.refetch}};var ri="prep";var v6=f0(z8(),1),FH8={useItem:m2,useCreate:q3,useSaveDraft:qD,usePublish:HD,useDiscard:BD,useVersions:FD,useDelete:MD,useUpdatePath:OD,getVersion:WD},GB0=[{key:"unsorted",icon:DG,label:"Not sorted"},{key:"name-asc",icon:NG,label:"Sorting by name ascending"},{key:"name-desc",icon:AG,label:"Sorting by name descending"},{key:"date-asc",icon:sM,label:"Sorting by date ascending"},{key:"date-desc",icon:nM,label:"Sorting by date descending"},{key:"state-asc",icon:VH,label:"Sorting by state ascending"},{key:"state-desc",icon:EH,label:"Sorting by state descending"}],VK6=[{bg:"linear-gradient(to bottom, #ef4444, #dc2626)",text:"white",border:"#b91c1c"},{bg:"linear-gradient(to bottom, #f97316, #ea580c)",text:"white",border:"#c2410c"},{bg:"linear-gradient(to bottom, #eab308, #ca8a04)",text:"#422006",border:"#a16207"},{bg:"linear-gradient(to bottom, #22c55e, #16a34a)",text:"white",border:"#15803d"},{bg:"linear-gradient(to bottom, #3b82f6, #2563eb)",text:"white",border:"#1d4ed8"},{bg:"linear-gradient(to bottom, #6366f1, #4f46e5)",text:"white",border:"#4338ca"},{bg:"linear-gradient(to bottom, #8b5cf6, #7c3aed)",text:"white",border:"#6d28d9"}],MH8=({state:J,states:Z,onPrev:Q,onNext:K})=>{let X=Z.indexOf(J),U=Z.length;if(X<0||U===0)return null;let Y=X/U*100,z=1/U*100,G=J.charAt(0).toUpperCase()+J.slice(1),W=VK6[X%VK6.length];return v6.jsxDEV("div",{className:"relative h-8 flex-1 min-w-0 bg-black/[0.03] dark:bg-white/[0.03] shadow-sm border border-border/50 rounded overflow-hidden",children:v6.jsxDEV("div",{className:"absolute rounded text-xs flex items-center justify-between px-1 shadow-sm",style:{left:`${Y}%`,width:`${z}%`,top:"2px",bottom:"2px",background:W.bg,color:W.text,borderWidth:"1px",borderStyle:"solid",borderColor:W.border},children:[Q?v6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(q)=>{q.stopPropagation(),Q()},onKeyDown:(q)=>{if(q.key==="Enter"||q.key===" ")q.preventDefault(),q.stopPropagation(),Q()},children:v6.jsxDEV(aM,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):v6.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"flex-1 text-center",children:G},void 0,!1,void 0,this),K?v6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(q)=>{q.stopPropagation(),K()},onKeyDown:(q)=>{if(q.key==="Enter"||q.key===" ")q.preventDefault(),q.stopPropagation(),K()},children:v6.jsxDEV(oM,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):v6.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},OH8=({projectId:J,storyId:Z})=>{let{data:Q,isLoading:K,error:X}=GZ6(J,"s"),[U,Y]=XZ.useState(null),z=Q?.templates??[],G=(H)=>{Y(H)},W=()=>{Y(null)};if(K)return v6.jsxDEV("div",{className:"flex items-center gap-2 p-4 text-muted-foreground",children:[v6.jsxDEV(NJ,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading templates..."]},void 0,!0,void 0,this);if(X)return v6.jsxDEV("div",{className:"p-4 text-sm text-destructive",children:["Failed to load templates: ",X.message]},void 0,!0,void 0,this);if(z.length===0)return v6.jsxDEV("div",{className:"p-4 text-sm text-muted-foreground",children:"No associated templates"},void 0,!1,void 0,this);let q=z.find((H)=>H.id===U);return v6.jsxDEV("div",{className:"p-4",children:[v6.jsxDEV("ul",{className:"space-y-1",children:z.map((H)=>v6.jsxDEV("li",{children:v6.jsxDEV("button",{type:"button",onClick:()=>G(H.id),className:"flex items-center gap-2 w-full text-left px-3 py-2 rounded hover:bg-muted text-sm",children:[v6.jsxDEV(cY,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"truncate",children:H.name},void 0,!1,void 0,this),H.path&&v6.jsxDEV("span",{className:"text-xs text-muted-foreground truncate ml-auto",children:H.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},H.id,!1,void 0,this))},void 0,!1,void 0,this),v6.jsxDEV(fi,{open:!!U,onOpenChange:(H)=>{if(!H)W()},projectId:J,templateId:U,templatePath:q?.path||q?.name,mode:"story",storyId:Z,rootFolderId:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},LH8=({projectId:J,story:Z,onDeleted:Q})=>{let[K,X]=XZ.useState(Z.name),[U,Y]=XZ.useState(null),[z,G]=XZ.useState(!1),[W,q]=XZ.useState(null),H=wK6(J),B=DK6(J),M=!K.trim()||K.trim()===Z.name||H.isPending,L=()=>{Y(null),H.mutate({id:Z.id,name:K.trim()},{onError:(N)=>Y(N.message)})},A=()=>{q(null),B.mutate({id:Z.id},{onSuccess:()=>{G(!1),Q()},onError:(N)=>q(N.message)})};return v6.jsxDEV("div",{className:"p-4 space-y-8",children:[v6.jsxDEV("div",{className:"space-y-3",children:[v6.jsxDEV("h3",{className:"text-sm font-medium",children:"Rename"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"flex items-center gap-2",children:[v6.jsxDEV(a5,{value:K,onChange:(N)=>X(N.target.value),onKeyDown:(N)=>N.key==="Enter"&&!M&&L(),className:"max-w-sm"},void 0,!1,void 0,this),v6.jsxDEV(a6,{size:"sm",onClick:L,disabled:M,children:H.isPending?"Saving...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"space-y-3",children:[v6.jsxDEV("h3",{className:"text-sm font-medium",children:"Danger Zone"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"border border-destructive/30 rounded-md p-4",children:v6.jsxDEV("div",{className:"flex items-center justify-between",children:[v6.jsxDEV("div",{children:[v6.jsxDEV("div",{className:"text-sm font-medium",children:"Delete this story"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"text-xs text-muted-foreground",children:"This will soft-delete the story and all its contents."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(a6,{variant:"destructive",size:"sm",onClick:()=>G(!0),children:"Delete Story"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(cZ,{open:z,onOpenChange:G,children:v6.jsxDEV(PZ,{children:[v6.jsxDEV(EZ,{children:v6.jsxDEV(VZ,{className:"flex items-center gap-2 text-destructive",children:[v6.jsxDEV(S7,{className:"w-5 h-5"},void 0,!1,void 0,this),"Delete Story"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete ",v6.jsxDEV("strong",{children:Z.name},void 0,!1,void 0,this),"? This will remove the story and all its contents."]},void 0,!0,void 0,this),W&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:W},void 0,!1,void 0,this),v6.jsxDEV(nQ,{children:[v6.jsxDEV(a6,{variant:"outline",onClick:()=>G(!1),children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(a6,{variant:"destructive",onClick:A,disabled:B.isPending,children:B.isPending?"Deleting...":"Delete"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},WB0=()=>{let{id:J,storeCode:Z}=I5(),[Q,K]=uM(),{data:X}=Y1(J);z1(X?`${X.name} - Stories`:"CAW");let U=Z??"A";pH(J);let{data:Y=[],isLoading:z,error:G,refetch:W}=NK6(J,{store:U}),{states:q,isLoading:H,error:B,refetch:M}=EK6(J),L=IK6(J),A=RK6(J),[N,I]=XZ.useState(!1),[R,D]=XZ.useState(""),[V,P]=XZ.useState(ri),[T,C]=XZ.useState(null),[S,v]=XZ.useState("documents"),[h,_]=XZ.useState("state-asc"),$=XZ.useRef(null),[k,f]=XZ.useState(null),b=XZ.useMemo(()=>k??new Set(q),[k,q]),y=(H0)=>{let e=k??new Set(q),B0=new Set(e);if(B0.has(H0))B0.delete(H0);else B0.add(H0);f(B0.size===q.length?null:B0)};XZ.useEffect(()=>{if(Q.has("id"))v("documents")},[Q]);let g=Q.get("expanded")??"",m=XZ.useRef({}),u=(H0)=>{if(v("documents"),K((e)=>{let B0=new URLSearchParams(e);if(B0.delete("id"),B0.delete("edit"),H0)B0.set("expanded",H0);else B0.delete("expanded");return B0}),H0)setTimeout(()=>{m.current[H0]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},d=XZ.useMemo(()=>{if(!q.length)return[];let H0=Y.filter((B0)=>B0.fields?.state&&b.has(B0.fields.state));if(h==="unsorted"){if($.current){let B0=$.current,U0=[...H0];return U0.sort((X0,Z0)=>{let Q0=B0.indexOf(X0.id),F0=B0.indexOf(Z0.id);return(Q0===-1?1/0:Q0)-(F0===-1?1/0:F0)}),U0}return H0}let e=[...H0];return e.sort((B0,U0)=>{if(h==="name-asc")return B0.name.localeCompare(U0.name);if(h==="name-desc")return U0.name.localeCompare(B0.name);if(h==="date-asc"||h==="date-desc"){let X0=(Q0)=>Q0.createdAt?new Date(Q0.createdAt).getTime():parseInt(Q0.id.replace(/\D/g,""),10)||0,Z0=X0(B0)-X0(U0);return h==="date-asc"?Z0:-Z0}if(h==="state-asc")return q.indexOf(B0.fields.state)-q.indexOf(U0.fields.state);if(h==="state-desc")return q.indexOf(U0.fields.state)-q.indexOf(B0.fields.state);return 0}),e},[Y,q,h,b]),l=()=>{if(!R.trim()){C("Story name is required");return}C(null),L.mutate({name:R.trim(),store:U,state:V},{onSuccess:(H0)=>{I(!1),D(""),P(ri),K((e)=>{let B0=new URLSearchParams(e);return B0.delete("id"),B0.delete("edit"),B0.set("expanded",H0.id),B0})},onError:(H0)=>{C(H0.message)}})},r=()=>{I(!1),D(""),P(ri),C(null)},t=z||H,z0=G||B,J0=G?W:M;if(t)return v6.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(z0)return v6.jsxDEV("div",{className:"p-6",children:[v6.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading stories"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:z0.message},void 0,!1,void 0,this),v6.jsxDEV(a6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>J0(),children:[v6.jsxDEV(JO,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Retry"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return v6.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[v6.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:v6.jsxDEV("div",{className:"flex items-center gap-2",children:[v6.jsxDEV(a6,{size:"sm",variant:"warning",onClick:()=>I(!0),children:[v6.jsxDEV(cQ,{className:"w-4 h-4"},void 0,!1,void 0,this),v6.jsxDEV(jH,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(rx,{children:[v6.jsxDEV(Y7,{content:GB0.find((H0)=>H0.key===h)?.label,children:v6.jsxDEV(nx,{asChild:!0,children:v6.jsxDEV(a6,{size:"sm",variant:"outline",children:XZ.default.createElement(GB0.find((H0)=>H0.key===h)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(pV,{align:"start",children:GB0.map((H0)=>v6.jsxDEV(cV,{onClick:()=>{if(H0.key==="unsorted")$.current=d.map((e)=>e.id);else $.current=null;_(H0.key)},className:h===H0.key?"bg-accent":"",children:[v6.jsxDEV(H0.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),H0.label]},H0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(w16,{children:[v6.jsxDEV(Y7,{content:"Filter by state",children:v6.jsxDEV(D16,{asChild:!0,children:v6.jsxDEV(a6,{size:"sm",variant:"outline",children:v6.jsxDEV(vH,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(sH0,{align:"center",children:v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV("div",{className:"text-sm font-medium",children:"Show by state:"},void 0,!1,void 0,this),q.map((H0)=>v6.jsxDEV("label",{className:"flex items-center gap-2",children:[v6.jsxDEV(Wk,{checked:b.has(H0),onCheckedChange:()=>y(H0)},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"text-sm capitalize",children:H0},void 0,!1,void 0,this)]},H0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),d.length===0?v6.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories yet"},void 0,!1,void 0,this):v6.jsxDEV("div",{className:"flex-1 overflow-auto",children:v6.jsxDEV(e_,{type:"single",collapsible:!0,value:g,onValueChange:u,children:d.map((H0)=>{let e=q.indexOf(H0.fields.state),B0=e>0?q[e-1]:null,U0=e<q.length-1?q[e+1]:null;return v6.jsxDEV(Jb,{value:H0.id,className:"border-b",ref:(X0)=>{m.current[H0.id]=X0},children:[v6.jsxDEV(Zb,{className:"grid grid-cols-[25%_50%_25%] items-center px-3 py-2 w-full bg-black/[0.03] dark:bg-white/[0.03] hover:bg-muted text-left [&[data-state=open]_.chevron]:rotate-180",children:[v6.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[v6.jsxDEV(jH,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"truncate text-sm",children:H0.name},void 0,!1,void 0,this),v6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${H0.storeCode==="B"?"text-green-700 border-green-300 bg-green-50 dark:text-green-300 dark:border-green-700 dark:bg-green-900/30":"text-blue-700 border-blue-300 bg-blue-50 dark:text-blue-300 dark:border-blue-700 dark:bg-blue-900/30"}`,children:H0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"grid grid-cols-9 items-center",children:[v6.jsxDEV("span",{className:"text-xs text-muted-foreground text-right pr-1",children:"Status:"},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"col-span-7",children:v6.jsxDEV(MH8,{state:H0.fields.state,states:q,onPrev:B0?()=>A.mutate({id:H0.id,state:B0}):null,onNext:U0?()=>A.mutate({id:H0.id,state:U0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"flex justify-end",children:v6.jsxDEV(DU,{className:"chevron w-4 h-4 flex-shrink-0 transition-transform"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(Qb,{className:"border-t",children:v6.jsxDEV(K16,{value:S,onValueChange:v,children:[v6.jsxDEV(iH0,{variant:"line",className:"px-4",children:[v6.jsxDEV(bD,{value:"documents",children:[v6.jsxDEV(pQ,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Documents"]},void 0,!0,void 0,this),v6.jsxDEV(bD,{value:"tasks",children:[v6.jsxDEV(dY,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Tasks"]},void 0,!0,void 0,this),v6.jsxDEV(bD,{value:"prompts",children:[v6.jsxDEV(cE,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),v6.jsxDEV(bD,{value:"settings",children:[v6.jsxDEV(sY,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Settings"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(xD,{value:"documents",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(ex,{projectId:J,rootFolderId:H0.id,type:"d",DetailPanel:Fd,hooks:FH8},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(xD,{value:"tasks",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(BK6,{projectId:J,storyId:H0.id,onOpenDocument:(X0,Z0)=>{K((Q0)=>{let F0=new URLSearchParams(Q0);if(F0.set("id",X0),Z0?.edit)F0.set("edit","true");return F0})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(xD,{value:"prompts",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(OH8,{projectId:J,storyId:H0.id},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(xD,{value:"settings",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(LH8,{projectId:J,story:H0,onDeleted:()=>{K((X0)=>{let Z0=new URLSearchParams(X0);return Z0.delete("expanded"),Z0.delete("id"),Z0.delete("edit"),Z0})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},H0.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(cZ,{open:N,onOpenChange:r,children:v6.jsxDEV(PZ,{children:[v6.jsxDEV(EZ,{children:v6.jsxDEV(VZ,{children:"Create Story"},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"space-y-4 py-4",children:[v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV(NZ,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),v6.jsxDEV(a5,{id:"name",value:R,onChange:(H0)=>D(H0.target.value),placeholder:"Enter story name",onKeyDown:(H0)=>H0.key==="Enter"&&l()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV(NZ,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),v6.jsxDEV(H1,{value:V,onValueChange:P,children:[v6.jsxDEV(V5,{children:v6.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(j5,{children:q.map((H0)=>v6.jsxDEV(F4,{value:H0,children:H0.charAt(0).toUpperCase()+H0.slice(1)},H0,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(nQ,{children:[v6.jsxDEV(a6,{variant:"outline",onClick:r,children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(a6,{onClick:l,disabled:L.isPending,children:L.isPending?"Creating...":"Create"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var o5=f0(j6(),1);var Tk="",Ck=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),jK6=async(J,{store:Z,status:Q}={})=>{let K=new URLSearchParams;if(Z)K.set("store",Z);if(Q)K.set("status",Q);let X=K.toString(),U=`${Tk}/api/p/${J}/jobs${X?`?${X}`:""}`,Y=await fetch(U,{headers:Ck()});return P9(Y,"Failed to list jobs")},TK6=async(J,Z)=>{let Q=await fetch(`${Tk}/api/p/${J}/jobs/${Z}`,{headers:Ck()});return P9(Q,"Failed to fetch job")},CK6=async(J,{name:Z,agent:Q,model:K,prompt:X,templateId:U,workingDirectory:Y})=>{let z=await fetch(`${Tk}/api/p/${J}/jobs`,{method:"POST",headers:Ck(),body:JSON.stringify({name:Z,agent:Q,model:K,prompt:X,templateId:U,workingDirectory:Y})});return P9(z,"Failed to create job")},SK6=async(J,Z,{prompt:Q})=>{let K=await fetch(`${Tk}/api/p/${J}/jobs/${Z}/continue`,{method:"POST",headers:Ck(),body:JSON.stringify({prompt:Q})});return P9(K,"Failed to continue job")},$K6=async(J,Z,Q)=>{let K=await fetch(`${Tk}/api/p/${J}/jobs/${Z}`,{method:"PATCH",headers:Ck(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename job")};var kK6=(J,{store:Z,status:Q}={})=>{return qQ({queryKey:["jobs",J,Z??"demux",Q??"all"],queryFn:()=>jK6(J,{store:Z,status:Q}),enabled:!!J,staleTime:30000})},vK6=(J,Z)=>{return qQ({queryKey:["job",Z],queryFn:()=>TK6(J,Z),enabled:!!J&&!!Z})},fK6=(J)=>{let Z=e9();return AJ({mutationFn:({name:Q,agent:K,model:X,prompt:U,templateId:Y,workingDirectory:z})=>CK6(J,{name:Q,agent:K,model:X,prompt:U,templateId:Y,workingDirectory:z}),onSuccess:()=>{Z.invalidateQueries({queryKey:["jobs",J]})}})},_K6=(J,Z)=>{return qQ({queryKey:["jobContents",Z],queryFn:async()=>{let Q=Z?Z[0]:"A",K=await fetch(`/api/p/${J}/folders/${Z}/contents?type=d&store=${Q}`);if(!K.ok)throw Error("Failed to fetch job contents");return K.json()},enabled:!!J&&!!Z})},bK6=(J,Z)=>{let Q=e9();return AJ({mutationFn:({prompt:K})=>SK6(J,Z,{prompt:K}),onSuccess:()=>{Q.invalidateQueries({queryKey:["job",Z]}),Q.invalidateQueries({queryKey:["jobs",J]})}})},xK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,name:K})=>$K6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["job",K]}),Z.invalidateQueries({queryKey:["jobs",J]})}})};var jK=f0(j6(),1);var AH8=f0(j6(),1);var t9=f0(z8(),1),hK6=({value:J,onChange:Z,worktrees:Q=[],isLoadingWorktrees:K=!1,isGitProject:X=!0,error:U=null,createError:Y=null,onCreateErrorClear:z=null})=>{let G=(L)=>{if(L==="main")Z({type:"main",path:null});else if(L==="worktree"){let A=Q[0];Z({type:"worktree",path:A?A.path:null})}else if(L==="new")Z({type:"new",branch:"",baseBranch:"main"})},W=(L)=>{Z({type:"worktree",path:L})},q=(L)=>{if(z)z();Z({...J,branch:L.target.value})},H=(L)=>{Z({...J,baseBranch:L.target.value})},B=(L)=>{Z({type:"new",path:L.target.value})};if(!X)return t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV(NZ,{htmlFor:"run-location-path",children:"Working Directory"},void 0,!1,void 0,this),t9.jsxDEV(a5,{id:"run-location-path",value:J.path||"",onChange:(L)=>Z({type:"new",path:L.target.value}),placeholder:"Optional - uses project root if empty"},void 0,!1,void 0,this),t9.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Specify a custom working directory (not a git repository)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(K)return t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV(NZ,{children:"Run Location"},void 0,!1,void 0,this),t9.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-2",children:[t9.jsxDEV(NJ,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading worktrees..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(U)return t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV(NZ,{children:"Run Location"},void 0,!1,void 0,this),t9.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-destructive py-2",children:[t9.jsxDEV(Mq,{className:"w-4 h-4"},void 0,!1,void 0,this),"Failed to load worktrees: ",U.message||"Unknown error"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);let M=Q.length>0;return t9.jsxDEV("div",{className:"space-y-3",children:[t9.jsxDEV(NZ,{children:"Run Location"},void 0,!1,void 0,this),t9.jsxDEV("div",{className:"space-y-2",children:[t9.jsxDEV("label",{className:"flex items-center gap-2 cursor-pointer",children:[t9.jsxDEV("input",{type:"radio",name:"run-location",checked:J.type==="main",onChange:()=>G("main"),className:"w-4 h-4 text-primary border-input focus:ring-primary"},void 0,!1,void 0,this),t9.jsxDEV(Lq,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),t9.jsxDEV("span",{className:"text-sm",children:"Main project"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t9.jsxDEV("label",{className:"flex items-center gap-2 cursor-pointer",children:[t9.jsxDEV("input",{type:"radio",name:"run-location",checked:J.type==="worktree",onChange:()=>G("worktree"),disabled:!M,className:"w-4 h-4 text-primary border-input focus:ring-primary disabled:opacity-50"},void 0,!1,void 0,this),t9.jsxDEV(pE,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),t9.jsxDEV("span",{className:`text-sm ${!M?"text-muted-foreground":""}`,children:"Existing worktree"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.type==="worktree"&&M&&t9.jsxDEV("div",{className:"ml-6",children:[t9.jsxDEV(H1,{value:J.path||Q[0]?.path||"",onValueChange:W,children:[t9.jsxDEV(V5,{children:t9.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),t9.jsxDEV(j5,{children:Q.map((L)=>t9.jsxDEV(F4,{value:L.path,children:[L.branch,L.isLocked&&" (locked)"]},L.path,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.path&&t9.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1 truncate",children:J.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!M&&t9.jsxDEV("p",{className:"text-xs text-muted-foreground ml-6",children:"No existing worktrees found."},void 0,!1,void 0,this),t9.jsxDEV("label",{className:"flex items-center gap-2 cursor-pointer",children:[t9.jsxDEV("input",{type:"radio",name:"run-location",checked:J.type==="new",onChange:()=>G("new"),className:"w-4 h-4 text-primary border-input focus:ring-primary"},void 0,!1,void 0,this),t9.jsxDEV(cQ,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),t9.jsxDEV("span",{className:"text-sm",children:"Create new worktree"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.type==="new"&&t9.jsxDEV("div",{className:"ml-6 space-y-3",children:[t9.jsxDEV("div",{className:"space-y-1",children:[t9.jsxDEV(NZ,{htmlFor:"new-branch-name",className:"text-xs",children:"Branch name"},void 0,!1,void 0,this),t9.jsxDEV(a5,{id:"new-branch-name",value:J.branch||"",onChange:q,placeholder:"feature/my-branch",className:"h-8 text-sm"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t9.jsxDEV("div",{className:"space-y-1",children:[t9.jsxDEV(NZ,{htmlFor:"base-branch",className:"text-xs",children:"Base branch"},void 0,!1,void 0,this),t9.jsxDEV(a5,{id:"base-branch",value:J.baseBranch||"",onChange:H,placeholder:"main",className:"h-8 text-sm"},void 0,!1,void 0,this),t9.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Branch to create from (defaults to main)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&t9.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[t9.jsxDEV(Mq,{className:"w-4 h-4"},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var yK6="",gK6=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),mK6=async(J)=>{let Z=await fetch(`${yK6}/api/p/${J}/worktrees`,{headers:gK6()});return P9(Z,"Failed to fetch worktrees")},uK6=async(J,{branch:Z,baseBranch:Q})=>{let K=await fetch(`${yK6}/api/p/${J}/worktrees`,{method:"POST",headers:gK6(),body:JSON.stringify({branch:Z,baseBranch:Q})});return P9(K,"Failed to create worktree")};var pK6=(J)=>{return qQ({queryKey:["worktrees",J],queryFn:()=>mK6(J),enabled:!!J,staleTime:30000})},cK6=(J)=>{let Z=e9();return AJ({mutationFn:({branch:Q,baseBranch:K})=>uK6(J,{branch:Q,baseBranch:K}),onSuccess:()=>{Z.invalidateQueries({queryKey:["worktrees",J]})}})};var p9=f0(z8(),1),NH8=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],lK6=({open:J,onOpenChange:Z,projectId:Q,onSuccess:K,initialPrompt:X=""})=>{let[U,Y]=jK.useState(""),[z,G]=jK.useState("claude"),[W,q]=jK.useState(""),[H,B]=jK.useState({type:"main",path:null}),[M,L]=jK.useState(""),[A,N]=jK.useState(""),[I,R]=jK.useState(!1),[D,V]=jK.useState({}),[P,T]=jK.useState(!1),[C,S]=jK.useState(null),[v,h]=jK.useState(null);jK.useEffect(()=>{if(X)L(X)},[X]);let{data:_,isLoading:$,error:k}=pK6(J?Q:null),f=_?.worktrees??[],b=_?.isGitProject??!0,y=fK6(Q),g=Md(Q),m=cK6(Q),{data:u}=LD(Q,A.trim()||null),d=u?.parameters??[],l=u?.detectedVariables??[],r=A.trim().length>0,t=()=>{Y(""),G("claude"),q(""),B({type:"main",path:null}),L(X||""),N(""),S(null),h(null),V({}),T(!1)},z0=()=>{t(),Z(!1)},J0=()=>{if(H.type==="main")return;return H.path||void 0},H0=(q0)=>{y.mutate({name:U.trim()||void 0,agent:z,model:W.trim()||void 0,prompt:M.trim(),workingDirectory:q0},{onSuccess:(P0)=>{if(z0(),K)K(P0)},onError:(P0)=>{S(P0.message)}})},e=()=>{if(!M.trim()){S("Prompt is required");return}if(H.type==="new"&&b){if(!H.branch||!H.branch.trim()){h("Branch name is required");return}}if(S(null),h(null),H.type==="new"&&b&&H.branch)m.mutate({branch:H.branch.trim(),baseBranch:H.baseBranch?.trim()||void 0},{onSuccess:(q0)=>{H0(q0.path)},onError:(q0)=>{h(q0.message)}});else H0(J0())},B0=()=>{R(!0)},U0=(q0)=>{V(q0),g.mutate({id:A.trim(),params:q0,target:"stdout"},{onSuccess:(P0)=>{if(P0.content)L(P0.content);N(""),R(!1)},onError:(P0)=>{S(`Template render failed: ${P0.message}`),R(!1)}})},X0=r?"render":"run",Z0=X0==="run"&&!M.trim(),Q0=m.isPending,F0=y.isPending||g.isPending||Q0;return p9.jsxDEV(p9.Fragment,{children:[p9.jsxDEV(cZ,{open:J,onOpenChange:z0,children:p9.jsxDEV(PZ,{className:"max-w-lg",children:[p9.jsxDEV(EZ,{children:p9.jsxDEV(VZ,{children:"New Job"},void 0,!1,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV("div",{className:"space-y-4 py-4",children:[p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),p9.jsxDEV(a5,{id:"job-name",value:U,onChange:(q0)=>Y(q0.target.value),placeholder:"Auto-generated if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),p9.jsxDEV(H1,{value:z,onValueChange:G,children:[p9.jsxDEV(V5,{children:p9.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(j5,{children:NH8.map((q0)=>p9.jsxDEV(F4,{value:q0.value,children:q0.label},q0.value,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),p9.jsxDEV(a5,{id:"job-model",value:W,onChange:(q0)=>q(q0.target.value),placeholder:"Optional - uses default if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV("button",{type:"button",onClick:()=>T(!P),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[P?p9.jsxDEV(DU,{className:"w-4 h-4"},void 0,!1,void 0,this):p9.jsxDEV(IG,{className:"w-4 h-4"},void 0,!1,void 0,this),p9.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&p9.jsxDEV(hK6,{value:H,onChange:B,worktrees:f,isLoadingWorktrees:$,isGitProject:b,error:k,createError:v,onCreateErrorClear:()=>h(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),p9.jsxDEV(tF,{id:"job-prompt",value:M,onChange:(q0)=>L(q0.target.value),placeholder:"Enter the prompt for the agent...",rows:6},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV("div",{className:"space-y-2",children:[p9.jsxDEV(NZ,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),p9.jsxDEV(a5,{id:"job-template",value:A,onChange:(q0)=>N(q0.target.value),placeholder:"Template ID (optional)"},void 0,!1,void 0,this),r&&p9.jsxDEV("p",{className:"text-xs text-muted-foreground",children:"Click Render to populate prompt from template"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&p9.jsxDEV("div",{className:"text-sm text-destructive",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p9.jsxDEV(nQ,{children:[p9.jsxDEV(a6,{variant:"outline",onClick:z0,children:"Cancel"},void 0,!1,void 0,this),X0==="render"?p9.jsxDEV(a6,{onClick:B0,disabled:F0,children:[p9.jsxDEV(pQ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),F0?"Rendering...":"Render"]},void 0,!0,void 0,this):p9.jsxDEV(a6,{onClick:e,disabled:Z0||F0,children:[p9.jsxDEV(nY,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),Q0?"Creating worktree...":y.isPending?"Running...":"Run"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(cZ,{open:I,onOpenChange:R,children:p9.jsxDEV(PZ,{className:"max-w-lg",children:[p9.jsxDEV(EZ,{children:p9.jsxDEV(VZ,{className:"flex items-center gap-2",children:[p9.jsxDEV(pQ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",uU(u?.path)," (",A,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(ki,{fields:d,detectedVariables:l,initialValues:D,onSubmit:U0,onCancel:()=>R(!1),isSubmitting:g.isPending},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var c8=f0(z8(),1),IH8=86400000,RH8=({status:J})=>{let Z={running:"text-blue-700 border-blue-300 bg-blue-50 dark:text-blue-300 dark:border-blue-700 dark:bg-blue-900/30",completed:"text-green-700 border-green-300 bg-green-50 dark:text-green-300 dark:border-green-700 dark:bg-green-900/30",error:"text-red-700 border-red-300 bg-red-50 dark:text-red-300 dark:border-red-700 dark:bg-red-900/30",pending:"text-gray-700 border-gray-300 bg-gray-50 dark:text-gray-300 dark:border-gray-700 dark:bg-gray-900/30"};return c8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase ${Z[J]||Z.pending}`,children:J},void 0,!1,void 0,this)},dK6=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},wH8=(J)=>{if(J===null||J===void 0)return"-";if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},iK6=async(J)=>{if(!J)return;try{await navigator.clipboard.writeText(J),W1.success("Copied")}catch(Z){console.error("Failed to copy:",Z)}},DH8=(J,Z)=>{if(!J||!Z)return null;let Q=`${Z}/worktree/`;if(J.startsWith(Q)){let K=J.slice(Q.length),X=K.endsWith("/")?K.slice(0,-1):K,U=X.indexOf("/");return U===-1?X:X.slice(0,U)}if(J.startsWith(Z)){let K=J.slice(Z.length);return K.startsWith("/")?K.slice(1):K}return J},HB0=({job:J,onClick:Z,projectPath:Q})=>{let K=DH8(J.workingDirectory,Q);return c8.jsxDEV("div",{onClick:()=>Z(J),className:"p-3 rounded cursor-pointer flex items-center gap-3 hover:bg-muted border-b border-border last:border-b-0",children:[c8.jsxDEV(RH8,{status:J.fields?.status},void 0,!1,void 0,this),c8.jsxDEV(Y7,{content:"Click to copy",children:c8.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(X)=>{X.stopPropagation(),iK6(J.id)},children:J.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV(Y7,{content:J.sessionId||"No session ID",children:c8.jsxDEV("span",{className:"w-24 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(X)=>{if(X.stopPropagation(),J.sessionId)iK6(J.sessionId)},children:J.sessionId?J.sessionId.slice(0,8)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV("div",{className:"flex-1 min-w-0",children:[c8.jsxDEV("span",{className:"truncate text-sm font-medium block",children:J.name},void 0,!1,void 0,this),K&&c8.jsxDEV(Y7,{content:J.workingDirectory,children:c8.jsxDEV("span",{className:"text-xs text-muted-foreground truncate block",children:K},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.agent},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.status==="running"?J.fields?.pid||"-":"-"},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:dK6(J.fields?.startedAt)},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:dK6(J.fields?.completedAt)},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:wH8(J.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},rK6=({title:J,count:Z})=>{return c8.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[c8.jsxDEV("h3",{className:"text-sm font-semibold text-foreground",children:J},void 0,!1,void 0,this),c8.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",Z,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},PH8=({column:J,sortColumn:Z,sortDirection:Q})=>{if(Z!==J)return c8.jsxDEV(iM,{className:"w-3 h-3 ml-1 opacity-50"},void 0,!1,void 0,this);return Q==="asc"?c8.jsxDEV(rM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this):c8.jsxDEV(dM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)},BB0=({onSort:J,sortColumn:Z,sortDirection:Q})=>{return c8.jsxDEV("div",{className:"flex items-center gap-3 px-3 py-2 text-xs text-muted-foreground border-b border-border bg-muted/30",children:[{key:"status",label:"Status",width:"w-20"},{key:"id",label:"Job ID",width:"w-16",sortable:!1},{key:"sessionId",label:"Session",width:"w-24",sortable:!1},{key:"name",label:"Name",width:"flex-1"},{key:"agent",label:"Agent",width:"w-16"},{key:"pid",label:"PID",width:"w-16",sortable:!1},{key:"startedAt",label:"Started",width:"w-28"},{key:"completedAt",label:"Completed",width:"w-28"},{key:"tokensUsed",label:"Tokens",width:"w-16 text-right"}].map((X)=>{let U=X.sortable!==!1;return c8.jsxDEV("span",{className:`${X.width} select-none flex items-center ${U?"cursor-pointer hover:text-foreground":""}`,onClick:U?()=>J(X.key):void 0,children:[X.label,U&&c8.jsxDEV(PH8,{column:X.key,sortColumn:Z,sortDirection:Q},void 0,!1,void 0,this)]},X.key,!0,void 0,this)})},void 0,!1,void 0,this)},nK6=["active","history"],qB0=(J,Z,Q="")=>{let K=Z?`/project/${J}/store/${Z}/jobs`:`/project/${J}/jobs`;return Q?`${K}/${Q}`:K},sK6=({active:J,onClick:Z,children:Q})=>c8.jsxDEV("button",{onClick:Z,role:"tab","aria-selected":J,tabIndex:J?0:-1,className:`px-4 py-2 text-sm font-medium whitespace-nowrap ${J?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"}`,children:Q},void 0,!1,void 0,this),EH8=({activeJobs:J,completedJobs:Z,onJobClick:Q,onNewJob:K,projectPath:X,onActiveSort:U,activeSortColumn:Y,activeSortDirection:z,onCompletedSort:G,completedSortColumn:W,completedSortDirection:q})=>c8.jsxDEV("div",{className:"space-y-6",children:[c8.jsxDEV("div",{className:"flex justify-start",children:c8.jsxDEV(a6,{size:"sm",variant:"warning",onClick:K,children:[c8.jsxDEV(cQ,{className:"w-4 h-4"},void 0,!1,void 0,this),c8.jsxDEV(tM,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV("div",{children:[c8.jsxDEV(rK6,{title:"Active Jobs",count:J.length},void 0,!1,void 0,this),J.length>0?c8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[c8.jsxDEV(BB0,{onSort:U,sortColumn:Y,sortDirection:z},void 0,!1,void 0,this),J.map((H)=>c8.jsxDEV(HB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):c8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[c8.jsxDEV(nY,{className:"w-4 h-4 opacity-50"},void 0,!1,void 0,this),"No active jobs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c8.jsxDEV("div",{children:[c8.jsxDEV(rK6,{title:"Recently Completed",count:Z.length},void 0,!1,void 0,this),Z.length>0?c8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[c8.jsxDEV(BB0,{onSort:G,sortColumn:W,sortDirection:q},void 0,!1,void 0,this),Z.map((H)=>c8.jsxDEV(HB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):c8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[c8.jsxDEV(bA,{className:"w-4 h-4 opacity-50"},void 0,!1,void 0,this),"No jobs completed in the last 24 hours"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),VH8=({completedJobs:J,onJobClick:Z,projectPath:Q,onSort:K,sortColumn:X,sortDirection:U})=>c8.jsxDEV("div",{children:J.length>0?c8.jsxDEV(c8.Fragment,{children:[c8.jsxDEV("div",{className:"text-sm text-muted-foreground mb-2",children:[J.length," completed job",J.length!==1?"s":""]},void 0,!0,void 0,this),c8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[c8.jsxDEV(BB0,{onSort:K,sortColumn:X,sortDirection:U},void 0,!1,void 0,this),J.map((Y)=>c8.jsxDEV(HB0,{job:Y,onClick:Z,projectPath:Q},Y.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):c8.jsxDEV("div",{className:"text-center py-8 text-muted-foreground",children:[c8.jsxDEV(bA,{className:"w-8 h-8 mx-auto mb-2 opacity-50"},void 0,!1,void 0,this),c8.jsxDEV("p",{className:"text-sm",children:"No completed jobs yet"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Sk=()=>{let{id:J,storeCode:Z,tab:Q}=I5(),K=GZ(),X=pJ(),{data:U}=Y1(J),Y=Q&&!nK6.includes(Q),z=nK6.includes(Q)?Q:"active";z1(U?`${U.name} - Jobs`:"CAW");let[G,W]=o5.useState(!1),[q,H]=o5.useState(""),[B,M]=o5.useState("startedAt"),[L,A]=o5.useState("desc"),[N,I]=o5.useState("completedAt"),[R,D]=o5.useState("desc"),[V,P]=o5.useState("completedAt"),[T,C]=o5.useState("desc"),S=Z??"A";pH(J);let{data:v=[],isLoading:h,error:_,refetch:$}=kK6(J,{store:S}),k=(t)=>{return["startedAt","completedAt","tokensUsed"].includes(t)?"desc":"asc"},f=(t)=>{if(B===t)A((z0)=>z0==="asc"?"desc":"asc");else M(t),A(k(t))},b=(t)=>{if(N===t)D((z0)=>z0==="asc"?"desc":"asc");else I(t),D(k(t))},y=(t)=>{if(V===t)C((z0)=>z0==="asc"?"desc":"asc");else P(t),C(k(t))},g=(t,z0,J0)=>{return[...t].sort((H0,e)=>{let B0=0;switch(z0){case"status":let U0={running:0,completed:1,error:2};B0=(U0[H0.status]??3)-(U0[e.status]??3);break;case"name":B0=(H0.name||"").localeCompare(e.name||"");break;case"agent":B0=(H0.agent||"").localeCompare(e.agent||"");break;case"startedAt":case"completedAt":let X0=(F0)=>{if(!F0)return 0;let q0=new Date(F0).getTime();return isNaN(q0)?0:q0},Z0=X0(H0[z0]),Q0=X0(e[z0]);B0=Z0-Q0;break;case"tokensUsed":B0=(H0.tokensUsed??0)-(e.tokensUsed??0);break;default:B0=0}return J0==="asc"?B0:-B0})},m=o5.useMemo(()=>{let t=v.filter((z0)=>z0.fields?.status==="running");return g(t,B,L)},[v,B,L]),u=o5.useMemo(()=>{let t=Date.now()-IH8,z0=v.filter((J0)=>J0.fields?.status==="completed"||J0.fields?.status==="error").filter((J0)=>J0.fields?.completedAt&&new Date(J0.fields?.completedAt).getTime()>t);return g(z0,N,R)},[v,N,R]),d=o5.useMemo(()=>{let t=v.filter((z0)=>z0.fields?.status==="completed"||z0.fields?.status==="error");return g(t,V,T)},[v,V,T]),l=(t)=>{let z0=Z?`/project/${J}/store/${Z}/job/${t.id}`:`/project/${J}/job/${t.id}`;K(z0,{state:{fromTab:z}})},r=(t)=>{if(t&&t.id){let z0=Z?`/project/${J}/store/${Z}/job/${t.id}`:`/project/${J}/job/${t.id}`;K(z0,{state:{fromTab:z}})}};if(o5.useEffect(()=>{if(X.state?.openNewJobWithPrompt)H(X.state.openNewJobWithPrompt),W(!0),K(X.pathname,{replace:!0,state:{}})},[X.state,K,X.pathname]),o5.useEffect(()=>{if(Y)K(qB0(J,Z,"active"),{replace:!0})},[Y,K,J,Z]),Y)return null;if(h)return c8.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(_)return c8.jsxDEV("div",{className:"p-6",children:[c8.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),c8.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:_.message},void 0,!1,void 0,this),c8.jsxDEV(a6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>$(),children:[c8.jsxDEV(JO,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Retry"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return c8.jsxDEV("div",{className:"h-full flex flex-col",children:[c8.jsxDEV("div",{className:"flex border-b overflow-x-auto bg-muted/50 px-2",role:"tablist","aria-label":"Jobs tabs",children:[c8.jsxDEV(sK6,{active:z==="active",onClick:()=>K(qB0(J,Z,"active")),children:"Active"},void 0,!1,void 0,this),c8.jsxDEV(sK6,{active:z==="history",onClick:()=>K(qB0(J,Z,"history")),children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c8.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:z==="active"?c8.jsxDEV(EH8,{activeJobs:m,completedJobs:u,onJobClick:l,onNewJob:()=>W(!0),projectPath:U?.path,onActiveSort:f,activeSortColumn:B,activeSortDirection:L,onCompletedSort:b,completedSortColumn:N,completedSortDirection:R},void 0,!1,void 0,this):c8.jsxDEV(VH8,{completedJobs:d,onJobClick:l,projectPath:U?.path,onSort:y,sortColumn:V,sortDirection:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),c8.jsxDEV(lK6,{open:G,onOpenChange:(t)=>{if(W(t),!t)H("")},projectId:J,onSuccess:r,initialPrompt:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var FU=f0(j6(),1);var FB0=f0(j6(),1);var $k=f0(z8(),1),aK6=({value:J,disabled:Z=!1,className:Q=""})=>{let[K,X]=FB0.useState(!1);return $k.jsxDEV(Y7,{content:"Copy to clipboard",children:$k.jsxDEV(a6,{variant:"ghost",size:"sm",onClick:async()=>{if(Z)return;await navigator.clipboard.writeText(J),X(!0),setTimeout(()=>X(!1),2000)},disabled:Z,className:Q,children:K?$k.jsxDEV(m1,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):$k.jsxDEV(uQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var KM=f0(j6(),1);var C1=f0(z8(),1),oK6=({open:J,onOpenChange:Z,sessionId:Q,onContinue:K,isLoading:X})=>{let[U,Y]=KM.useState(""),z=KM.useRef(null);KM.useEffect(()=>{if(!J)Y("")},[J]),KM.useEffect(()=>{if(J&&z.current){let H=setTimeout(()=>{z.current?.focus()},50);return()=>clearTimeout(H)}},[J]);let G=(H)=>{H.preventDefault();let B=U.trim();if(B)K(B)},W=()=>{Y(""),Z(!1)},q=!U.trim()||X;return C1.jsxDEV(cZ,{open:J,onOpenChange:W,children:C1.jsxDEV(PZ,{children:[C1.jsxDEV(EZ,{children:C1.jsxDEV(VZ,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),C1.jsxDEV("form",{onSubmit:G,className:"space-y-4",children:[C1.jsxDEV("div",{className:"space-y-2",children:[C1.jsxDEV(NZ,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),C1.jsxDEV(a5,{id:"session-id",value:Q||"",readOnly:!0,className:"font-mono text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C1.jsxDEV("div",{className:"space-y-2",children:[C1.jsxDEV(NZ,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),C1.jsxDEV(tF,{ref:z,id:"continue-prompt",value:U,onChange:(H)=>Y(H.target.value),placeholder:"Enter your follow-up prompt...",rows:6,autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C1.jsxDEV(nQ,{children:[C1.jsxDEV(a6,{type:"button",variant:"outline",onClick:W,children:"Cancel"},void 0,!1,void 0,this),C1.jsxDEV(a6,{type:"submit",disabled:q,children:[X&&C1.jsxDEV(NJ,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this),"Continue"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var E8=f0(z8(),1),jH8=({status:J})=>{let Z={running:{icon:NJ,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:TH,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:CH,class:"text-red-700 border-red-300 bg-red-50",animate:!1},pending:{icon:gE,class:"text-gray-700 border-gray-300 bg-gray-50",animate:!1}},{icon:Q,class:K,animate:X}=Z[J]||Z.pending;return E8.jsxDEV("span",{className:`inline-flex items-center gap-1.5 rounded border px-2 py-1 text-sm font-medium ${K}`,children:[E8.jsxDEV(Q,{className:`w-4 h-4 ${X?"animate-spin":""}`},void 0,!1,void 0,this),J]},void 0,!0,void 0,this)},tK6=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})},TH8=(J)=>{if(J===null||J===void 0)return"-";let Z=parseInt(J,10);if(isNaN(Z))return J;if(Z>=1000)return`${(Z/1000).toFixed(1)}k`;return Z.toString()},eK6=(J,Z)=>{if(!J||!Z)return null;let Q=`${Z}/worktree/`;if(J.startsWith(Q)){let K=J.slice(Q.length),X=K.endsWith("/")?K.slice(0,-1):K,U=X.indexOf("/");return U===-1?X:X.slice(0,U)}if(J.startsWith(Z)){let K=J.slice(Z.length);return K.startsWith("/")?K.slice(1):K}return J},JX6=(J)=>{if(!J)return[];let Z=/---\n## Turn (\d+)\n/g,Q=[...J.matchAll(Z)];if(Q.length===0)return[{turnNumber:1,content:J.trim()}];let K=[],X=Q[0].index,U=J.slice(0,X).trim();if(U)K.push({turnNumber:1,content:U});for(let Y=0;Y<Q.length;Y++){let z=Q[Y],G=parseInt(z[1],10),W=z.index+z[0].length,q=Q[Y+1]?.index??J.length,H=J.slice(W,q).trim();K.push({turnNumber:G,content:H})}return K},ZX6=({title:J,docId:Z,isOpen:Q,onToggle:K,children:X})=>E8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[E8.jsxDEV("button",{onClick:()=>K(!Q),className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[Q?E8.jsxDEV(DU,{className:"w-4 h-4"},void 0,!1,void 0,this):E8.jsxDEV(IG,{className:"w-4 h-4"},void 0,!1,void 0,this),E8.jsxDEV(pQ,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),E8.jsxDEV("span",{className:"font-medium",children:J},void 0,!1,void 0,this),Z&&E8.jsxDEV("span",{className:"text-xs text-muted-foreground ml-auto font-mono",children:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&E8.jsxDEV("div",{className:"p-4",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this),QX6=({turnNumber:J,promptContent:Z,outputContent:Q,showHeading:K,promptDocId:X,outputDocId:U,isPromptOpen:Y,setIsPromptOpen:z,isOutputOpen:G,setIsOutputOpen:W})=>{return E8.jsxDEV("div",{className:"space-y-4",children:[K&&E8.jsxDEV("h3",{className:"text-lg font-semibold text-muted-foreground",children:["Turn ",J]},void 0,!0,void 0,this),Q&&E8.jsxDEV(ZX6,{title:"Output",docId:U,isOpen:G,onToggle:W,children:E8.jsxDEV(y2,{markdown:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(ZX6,{title:"Prompt",docId:X,isOpen:Y,onToggle:z,children:E8.jsxDEV(y2,{markdown:Z||""},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},CH8=86400000,MB0=()=>{let{id:J,storeCode:Z,jobId:Q}=I5(),K=GZ(),X=pJ(),{data:U}=Y1(J);z1(U?`${U.name} - Job: ${Q}`:"CAW"),pH(J);let{data:Y,isLoading:z,error:G}=vK6(J,Q),{data:W,isLoading:q}=_K6(J,Q),{promptDoc:H,outputDoc:B}=FU.useMemo(()=>{if(!W)return{promptDoc:null,outputDoc:null};let B0=W.documents||[],U0=B0.find((Z0)=>Z0.name==="prompt.md"),X0=B0.find((Z0)=>Z0.name==="output.md");return{promptDoc:U0,outputDoc:X0}},[W]),{data:M}=m2(J,H?.id),{data:L}=m2(J,B?.id),A=M?.draftContent??M?.publishedContent??"",N=L?.draftContent??L?.publishedContent??"",I=FU.useMemo(()=>JX6(A),[A]),R=FU.useMemo(()=>JX6(N),[N]),D=I.length>1||R.length>1,[V,P]=FU.useState({}),T=Math.max(I.length,R.length);FU.useEffect(()=>{P((B0)=>{let U0={...B0};for(let X0=0;X0<T;X0++)if(!(X0 in U0))U0[X0]={promptOpen:!0,outputOpen:!0};return U0})},[T]);let C=()=>{P((B0)=>{let U0={};for(let X0 of Object.keys(B0))U0[X0]={promptOpen:!1,outputOpen:!1};return U0})},S=()=>{P((B0)=>{let U0={};for(let X0 of Object.keys(B0))U0[X0]={promptOpen:!0,outputOpen:!0};return U0})},v=async()=>{try{await navigator.clipboard.writeText(Q),W1.success("ID copied")}catch(B0){console.error("Failed to copy ID:",B0)}},h=(B0)=>{if(!B0)return"active";if(B0.fields?.status==="running")return"active";if(B0.fields?.completedAt){let U0=new Date(B0.fields?.completedAt).getTime(),X0=Date.now()-CH8;if(U0>X0)return"active"}return"history"},_=()=>{let B0=X.state?.fromTab||h(Y),U0=Z?`/project/${J}/store/${Z}/jobs/${B0}`:`/project/${J}/jobs/${B0}`;K(U0)},[$,k]=FU.useState(!1),f=bK6(J,Q),b=(Y?.status==="completed"||Y?.status==="error")&&Y?.sessionId,y=async(B0)=>{await f.mutateAsync({prompt:B0}),k(!1)},[g,m]=FU.useState(!1),[u,d]=FU.useState(""),[l,r]=FU.useState(null),t=xK6(J),z0=()=>{d(Y.name),r(null),m(!0)},J0=async()=>{let B0=u.trim();if(!B0||B0===Y.name){m(!1),r(null);return}try{await t.mutateAsync({id:Q,name:B0}),m(!1),r(null)}catch(U0){let X0=U0?.message||"Failed to rename job";r(X0)}},H0=(B0)=>{if(B0.key==="Enter")B0.preventDefault(),J0();if(B0.key==="Escape")m(!1),r(null)},e=(B0)=>{if(d(B0.target.value),l)r(null)};if(z)return E8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:E8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground",children:[E8.jsxDEV(NJ,{className:"w-5 h-5 animate-spin"},void 0,!1,void 0,this),"Loading job..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(G||!Y)return E8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:E8.jsxDEV("div",{className:"text-center",children:[E8.jsxDEV(S7,{className:"w-8 h-8 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),E8.jsxDEV("p",{className:"text-destructive font-medium",children:"Failed to load job"},void 0,!1,void 0,this),E8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-1",children:G?.message||"Job not found"},void 0,!1,void 0,this),E8.jsxDEV(a6,{variant:"outline",className:"mt-4",onClick:_,children:[E8.jsxDEV(_A,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Back to Jobs"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return E8.jsxDEV("div",{className:"h-full flex flex-col p-6 overflow-auto",children:[E8.jsxDEV("div",{className:"flex items-start gap-4 mb-6",children:[E8.jsxDEV(a6,{variant:"ghost",size:"sm",onClick:_,children:E8.jsxDEV(_A,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV("div",{className:"flex-1",children:[E8.jsxDEV("div",{className:"flex items-center gap-3 mb-2",children:[g?E8.jsxDEV("input",{type:"text",value:u,onChange:e,onBlur:J0,onKeyDown:H0,autoFocus:!0,className:"text-xl font-semibold px-2 py-1 border border-input rounded bg-background"},void 0,!1,void 0,this):E8.jsxDEV(E8.Fragment,{children:[E8.jsxDEV("h1",{className:"text-xl font-semibold",children:Y.name},void 0,!1,void 0,this),E8.jsxDEV(Y7,{content:"Rename job",children:E8.jsxDEV(a6,{variant:"ghost",size:"sm",onClick:z0,children:E8.jsxDEV(X1,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV(jH8,{status:Y.fields?.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l&&E8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center gap-2 text-destructive",children:[E8.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),E8.jsxDEV("span",{className:"text-sm",children:l},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Agent:"},void 0,!1,void 0,this),E8.jsxDEV("span",{className:"capitalize",children:Y.agent},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y.model&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Model:"},void 0,!1,void 0,this),Y.model]},void 0,!0,void 0,this),E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Started:"},void 0,!1,void 0,this),tK6(Y.fields?.startedAt)]},void 0,!0,void 0,this),Y.fields?.completedAt&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Completed:"},void 0,!1,void 0,this),tK6(Y.fields?.completedAt)]},void 0,!0,void 0,this),Y.tokensUsed&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Tokens:"},void 0,!1,void 0,this),TH8(Y.tokensUsed)]},void 0,!0,void 0,this),eK6(Y.workingDirectory,U?.path)&&E8.jsxDEV(Y7,{content:Y.workingDirectory,children:E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Location:"},void 0,!1,void 0,this),eK6(Y.workingDirectory,U?.path)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Y.fields?.status==="completed"&&E8.jsxDEV("span",{className:"flex items-center gap-1",children:[E8.jsxDEV("span",{className:"font-medium",children:"Session:"},void 0,!1,void 0,this),E8.jsxDEV("span",{children:Y.sessionId||"-"},void 0,!1,void 0,this),E8.jsxDEV(aK6,{value:Y.sessionId||"",disabled:!Y.sessionId},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y.errorMessage&&E8.jsxDEV("div",{className:"mt-3 p-3 bg-destructive/10 border border-destructive/30 rounded-md",children:[E8.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error"},void 0,!1,void 0,this),E8.jsxDEV("p",{className:"text-sm text-destructive/80 mt-1",children:Y.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV("div",{className:"flex items-center gap-2",children:[b&&E8.jsxDEV(a6,{variant:"default",size:"sm",onClick:()=>k(!0),children:[E8.jsxDEV(lE,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Continue Conversation"]},void 0,!0,void 0,this),E8.jsxDEV(Y7,{content:"Copy job ID",children:E8.jsxDEV(a6,{variant:"outline",size:"sm",onClick:v,children:[E8.jsxDEV(uQ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I.length>=3&&E8.jsxDEV("div",{className:"flex gap-2 mb-4",children:[E8.jsxDEV(a6,{variant:"outline",size:"sm",onClick:C,children:"Collapse All"},void 0,!1,void 0,this),E8.jsxDEV(a6,{variant:"outline",size:"sm",onClick:S,children:"Expand All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E8.jsxDEV("div",{className:"flex-1 space-y-6",children:q?E8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-8",children:[E8.jsxDEV(NJ,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading documents..."]},void 0,!0,void 0,this):D?[...Array(Math.max(I.length,R.length))].map((B0,U0,X0)=>{let Z0=X0.length-1-U0,Q0=I[Z0],F0=R[Z0],q0=Q0?.turnNumber??F0?.turnNumber??Z0+1;return E8.jsxDEV(QX6,{turnNumber:q0,promptContent:Q0?.content,outputContent:F0?.content,showHeading:!0,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[Z0]?.promptOpen??!0,setIsPromptOpen:(P0)=>P((M0)=>({...M0,[Z0]:{...M0[Z0],promptOpen:P0}})),isOutputOpen:V[Z0]?.outputOpen??!0,setIsOutputOpen:(P0)=>P((M0)=>({...M0,[Z0]:{...M0[Z0],outputOpen:P0}}))},Z0,!1,void 0,this)}):E8.jsxDEV(QX6,{turnNumber:1,promptContent:I[0]?.content,outputContent:R[0]?.content,showHeading:!1,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[0]?.promptOpen??!0,setIsPromptOpen:(B0)=>P((U0)=>({...U0,[0]:{...U0[0],promptOpen:B0}})),isOutputOpen:V[0]?.outputOpen??!0,setIsOutputOpen:(B0)=>P((U0)=>({...U0,[0]:{...U0[0],outputOpen:B0}}))},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(oK6,{open:$,onOpenChange:k,sessionId:Y.sessionId,onContinue:y,isLoading:f.isPending},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var TK=f0(j6(),1);var V3=f0(j6(),1);var j3=f0(z8(),1),ni=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("rounded-lg border border-border bg-card text-card-foreground shadow-sm",J),...Z},void 0,!1,void 0,this));ni.displayName="Card";var SH8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("flex flex-col space-y-1.5 p-6",J),...Z},void 0,!1,void 0,this));SH8.displayName="CardHeader";var $H8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("h3",{ref:Q,className:k8("text-2xl font-semibold leading-none tracking-tight",J),...Z},void 0,!1,void 0,this));$H8.displayName="CardTitle";var kH8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("p",{ref:Q,className:k8("text-sm text-muted-foreground",J),...Z},void 0,!1,void 0,this));kH8.displayName="CardDescription";var si=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("p-6 pt-0",J),...Z},void 0,!1,void 0,this));si.displayName="CardContent";var vH8=V3.default.forwardRef(({className:J,...Z},Q)=>j3.jsxDEV("div",{ref:Q,className:k8("flex items-center p-6 pt-0",J),...Z},void 0,!1,void 0,this));vH8.displayName="CardFooter";var ai="",oi=()=>({"Content-Type":"application/json","X-Session-Id":cJ()}),KX6=async(J)=>{let Z=await fetch(`${ai}/api/p/${J}/export/preview`,{headers:oi()});return P9(Z,"Failed to get export preview")},XX6=async(J)=>{let Z=await fetch(`${ai}/api/p/${J}/exports`,{headers:oi()});return P9(Z,"Failed to get exports")},UX6=async(J)=>{let Z=await fetch(`${ai}/api/p/${J}/export`,{method:"POST",headers:oi(),body:JSON.stringify({confirm:!0})});return P9(Z,"Failed to export documents")},YX6=async(J,Z)=>{let Q=await fetch(`${ai}/api/p/${J}/import`,{method:"POST",headers:oi(),body:JSON.stringify({filename:Z})});return P9(Q,"Failed to import documents")};var c6=f0(z8(),1),zX6=()=>{let{id:J}=I5(),{data:Z,isLoading:Q}=Y1(J),[K,X]=TK.useState(!1),[U,Y]=TK.useState(null),[z,G]=TK.useState(!1),[W,q]=TK.useState(null),[H,B]=TK.useState(!1),[M,L]=TK.useState(null),[A,N]=TK.useState(null),[I,R]=TK.useState(!1),[D,V]=TK.useState(!1),[P,T]=TK.useState(null),[C,S]=TK.useState(null),[v,h]=TK.useState([]),[_,$]=TK.useState("");z1(Z?`${Z.name} - Settings`:"CAW");let k=async(r,t)=>{if(Y(null),!navigator.clipboard?.writeText){Y("Clipboard not available");return}try{await navigator.clipboard.writeText(r),t(!0),setTimeout(()=>t(!1),2000)}catch(z0){Y("Failed to copy")}},f=()=>{if(!Z?.objectId)return"";return`claude mcp add caw-${Z.objectId.toLowerCase()} https://caw.localhost/mcp/p/${Z.objectId} --transport http`},b=()=>k(f(),X),y=async()=>{L(null),N(null),q(null),B(!0),G(!0);try{let r=await KX6(Z.objectId);q(r)}catch(r){L(r.message)}finally{B(!1)}},g=async()=>{B(!0),L(null);try{let r=await UX6(Z.objectId);N(r)}catch(r){L(r.message)}finally{B(!1)}},m=()=>{G(!1),q(null),N(null),L(null)},u=async()=>{T(null),S(null),h([]),$(""),R(!0),V(!0);try{let r=await XX6(Z.objectId);if(h(r.exports),r.exports?.length>0)$(r.exports[0].filename)}catch(r){T(r.message)}finally{V(!1)}},d=async()=>{if(!_){T("Please select an export file");return}V(!0),T(null);try{let r=await YX6(Z.objectId,_);S(r)}catch(r){T(r.message)}finally{V(!1)}},l=()=>{R(!1),S(null),T(null)};if(Q)return c6.jsxDEV("div",{className:"p-6",children:c6.jsxDEV("p",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(!Z)return c6.jsxDEV("div",{className:"p-6",children:c6.jsxDEV("p",{className:"text-muted-foreground",children:"Project not found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return c6.jsxDEV("div",{className:"p-6",children:[c6.jsxDEV("h2",{className:"text-2xl font-bold text-foreground mb-6",children:"Project Settings"},void 0,!1,void 0,this),c6.jsxDEV("div",{className:"max-w-2xl space-y-6",children:[c6.jsxDEV(ni,{children:c6.jsxDEV(si,{className:"pt-6 space-y-6",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Project Name"},void 0,!1,void 0,this),c6.jsxDEV("p",{className:"text-foreground mt-1",children:Z.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Path"},void 0,!1,void 0,this),c6.jsxDEV("p",{className:"text-foreground font-mono text-sm mt-1",children:Z.path},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Add to Claude Code"},void 0,!1,void 0,this),c6.jsxDEV("div",{className:"flex items-start gap-2 mt-1",children:[c6.jsxDEV("pre",{className:"flex-1 bg-muted px-3 py-2 rounded font-mono text-sm text-foreground overflow-x-auto whitespace-pre-wrap",children:f()},void 0,!1,void 0,this),c6.jsxDEV(a6,{variant:"outline",size:"icon",onClick:b,className:"shrink-0",children:K?c6.jsxDEV(m1,{className:"w-4 h-4"},void 0,!1,void 0,this):c6.jsxDEV(uQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&c6.jsxDEV("p",{className:"text-xs text-destructive mt-1",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),c6.jsxDEV(ni,{children:c6.jsxDEV(si,{className:"pt-6",children:c6.jsxDEV("div",{className:"flex items-start justify-between",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"PROJECT STORE (A)"},void 0,!1,void 0,this),c6.jsxDEV("p",{className:"text-foreground text-sm mt-1",children:"Export and import documents, templates, and folders"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{className:"flex gap-2",children:[c6.jsxDEV(a6,{onClick:y,size:"sm",children:[c6.jsxDEV(mE,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Export"]},void 0,!0,void 0,this),c6.jsxDEV(a6,{onClick:u,variant:"outline",size:"sm",children:[c6.jsxDEV(PG,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Import"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV(cZ,{open:z,onOpenChange:G,children:c6.jsxDEV(PZ,{children:[c6.jsxDEV(EZ,{children:[c6.jsxDEV(VZ,{children:A?"Export Complete":"Export Preview"},void 0,!1,void 0,this),c6.jsxDEV(gx,{children:A?"Your content has been exported successfully.":"Review what will be exported to .caw-exports/"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H&&!W&&c6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:c6.jsxDEV(NJ,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M&&c6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[c6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),c6.jsxDEV("span",{className:"text-sm",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W?.toExport&&W?.draftOnly&&!A&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Will be exported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[c6.jsxDEV("li",{children:[W.toExport.documents.length," documents"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[W.toExport.templates.length," templates"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[W.toExport.folders.length," folders"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),(W.draftOnly.documents.length>0||W.draftOnly.templates.length>0)&&c6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:c6.jsxDEV("div",{className:"flex items-start gap-2",children:[c6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Draft-only items will NOT be exported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[W.draftOnly.documents.length>0&&c6.jsxDEV("li",{children:[W.draftOnly.documents.length," documents",W.draftOnly.documents.length<=3&&c6.jsxDEV("span",{className:"text-xs ml-1",children:["(",W.draftOnly.documents.map((r)=>r.path).join(", "),")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),W.draftOnly.templates.length>0&&c6.jsxDEV("li",{children:[W.draftOnly.templates.length," templates",W.draftOnly.templates.length<=3&&c6.jsxDEV("span",{className:"text-xs ml-1",children:["(",W.draftOnly.templates.map((r)=>r.path).join(", "),")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Exported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[c6.jsxDEV("li",{children:[A.counts.documents," documents"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[A.counts.templates," templates"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[A.counts.folders," folders"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Saved to: ",c6.jsxDEV("code",{className:"bg-muted px-1 rounded",children:".caw-exports/"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV(nQ,{children:!A?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(a6,{variant:"outline",onClick:m,children:"Cancel"},void 0,!1,void 0,this),c6.jsxDEV(a6,{onClick:g,disabled:H||!W,children:H?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(NJ,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this),"Exporting..."]},void 0,!0,void 0,this):"Export"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c6.jsxDEV(a6,{onClick:m,children:"Done"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),c6.jsxDEV(cZ,{open:I,onOpenChange:R,children:c6.jsxDEV(PZ,{children:[c6.jsxDEV(EZ,{children:[c6.jsxDEV(VZ,{children:C?"Import Complete":"Import from .caw-exports/"},void 0,!1,void 0,this),c6.jsxDEV(gx,{children:C?"Your content has been imported successfully.":"Import documents, templates, and folders from a previous export."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&c6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[c6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),c6.jsxDEV("span",{className:"text-sm",children:P},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D&&v.length===0&&!P&&c6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:c6.jsxDEV(NJ,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),!C&&!D&&v.length===0&&!P&&c6.jsxDEV("div",{className:"text-center py-4 text-muted-foreground",children:"No exports found. Export your data first."},void 0,!1,void 0,this),!C&&v.length>0&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{children:[c6.jsxDEV("label",{className:"text-sm font-medium text-foreground block mb-2",children:"Select export file:"},void 0,!1,void 0,this),c6.jsxDEV(H1,{value:_,onValueChange:$,children:[c6.jsxDEV(V5,{children:c6.jsxDEV(B1,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),c6.jsxDEV(j5,{children:v.map((r)=>c6.jsxDEV(F4,{value:r.filename,children:[r.filename," (",Math.round(r.size/1024)," KB)"]},r.filename,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:c6.jsxDEV("div",{className:"flex items-start gap-2",children:[c6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),c6.jsxDEV("div",{children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Important:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[c6.jsxDEV("li",{children:"The store must be empty before importing"},void 0,!1,void 0,this),c6.jsxDEV("li",{children:"Entity IDs will be remapped to new values"},void 0,!1,void 0,this),c6.jsxDEV("li",{children:"References in content will be updated automatically"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&c6.jsxDEV("div",{className:"space-y-4",children:[c6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[c6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Imported:"},void 0,!1,void 0,this),c6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[c6.jsxDEV("li",{children:[C.counts.documents," documents"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[C.counts.templates," templates"]},void 0,!0,void 0,this),c6.jsxDEV("li",{children:[C.counts.folders," folders"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Object.keys(C.remapped).length>0&&c6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:[Object.keys(C.remapped).length," entity IDs were remapped."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c6.jsxDEV(nQ,{children:!C?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(a6,{variant:"outline",onClick:l,children:"Cancel"},void 0,!1,void 0,this),c6.jsxDEV(a6,{onClick:d,disabled:D||!_,children:D?c6.jsxDEV(c6.Fragment,{children:[c6.jsxDEV(NJ,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this),"Importing..."]},void 0,!0,void 0,this):"Import"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c6.jsxDEV(a6,{onClick:l,children:"Done"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var fH8=f0(j6(),1);var XM=f0(z8(),1),ti=()=>{let J=pJ(),Z=GZ();return XM.jsxDEV("div",{className:"flex items-center justify-center h-full",children:XM.jsxDEV("div",{className:"text-center max-w-md px-4",children:[XM.jsxDEV(S7,{className:"w-16 h-16 text-muted-foreground/50 mx-auto mb-4"},void 0,!1,void 0,this),XM.jsxDEV("h2",{className:"text-2xl font-semibold text-foreground mb-2",children:"Page Not Found"},void 0,!1,void 0,this),XM.jsxDEV("p",{className:"text-muted-foreground mb-4",children:["The path ",XM.jsxDEV("code",{className:"bg-muted px-2 py-1 rounded text-sm",children:J.pathname},void 0,!1,void 0,this)," could not be found."]},void 0,!0,void 0,this),XM.jsxDEV(a6,{onClick:()=>Z("/"),children:"Go Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var s2=f0(z8(),1),GX6=()=>{let{theme:J,toggleTheme:Z}=A_(),Q=J==="dark";return s2.jsxDEV("div",{className:"flex items-center justify-between",children:[s2.jsxDEV("div",{children:[s2.jsxDEV("div",{className:"font-medium text-foreground",children:"Theme"},void 0,!1,void 0,this),s2.jsxDEV("div",{className:"text-sm text-muted-foreground",children:Q?"Dark mode":"Light mode"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s2.jsxDEV("button",{onClick:Z,className:"relative w-14 h-8 bg-muted rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",role:"switch","aria-checked":Q,"aria-label":"Toggle dark mode",children:s2.jsxDEV("span",{className:`absolute top-1 left-1 w-6 h-6 bg-background rounded-full shadow transition-transform flex items-center justify-center ${Q?"translate-x-6":"translate-x-0"}`,children:Q?s2.jsxDEV(dE,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this):s2.jsxDEV(iE,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var nz=f0(z8(),1),WX6=()=>{return z1("CAW - Preferences"),nz.jsxDEV("div",{className:"flex-1 p-6",children:[nz.jsxDEV("div",{className:"mb-6",children:nz.jsxDEV("div",{className:"flex items-center gap-3",children:[nz.jsxDEV(sY,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this),nz.jsxDEV("h1",{className:"text-xl font-semibold text-foreground",children:"Preferences"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),nz.jsxDEV("div",{className:"max-w-2xl",children:nz.jsxDEV("section",{className:"mb-8",children:[nz.jsxDEV("h2",{className:"text-lg font-medium text-foreground mb-4",children:"Appearance"},void 0,!1,void 0,this),nz.jsxDEV("div",{className:"bg-card border border-border rounded-lg p-4",children:nz.jsxDEV(GX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var HX6=f0(z8(),1),qX6=(J)=>HX6.jsxDEV(QT0,{className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...J},void 0,!1,void 0,this);var b9=f0(z8(),1),bH8=()=>{return b9.jsxDEV(jo,{children:b9.jsxDEV(mo,{client:hA0,children:[b9.jsxDEV(Po,{children:b9.jsxDEV(W4,{element:b9.jsxDEV(rR0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(W4,{index:!0,element:b9.jsxDEV(oR0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"preferences",element:b9.jsxDEV(WX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"project/:id",element:b9.jsxDEV(aR0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(W4,{index:!0,element:b9.jsxDEV(nf,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"documents/*",element:b9.jsxDEV(Tz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"templates/*",element:b9.jsxDEV(lH0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"stories",element:b9.jsxDEV(WB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs/:tab",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"job/:jobId",element:b9.jsxDEV(MB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"settings",element:b9.jsxDEV(zX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"store/:storeCode",children:[b9.jsxDEV(W4,{index:!0,element:b9.jsxDEV(nf,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"documents/*",element:b9.jsxDEV(Tz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"templates/*",element:b9.jsxDEV(lH0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"stories",element:b9.jsxDEV(WB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"jobs/:tab",element:b9.jsxDEV(Sk,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"job/:jobId",element:b9.jsxDEV(MB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(W4,{path:"*",element:b9.jsxDEV(ti,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(W4,{path:"*",element:b9.jsxDEV(ti,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(W4,{path:"*",element:b9.jsxDEV(ti,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(qX6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},BX6=bH8;var OB0=f0(z8(),1),OX6=document.getElementById("root");if(!OX6)throw Error("Root element not found");var xH8=MX6.createRoot(OX6);xH8.render(OB0.jsxDEV(FX6.default.StrictMode,{children:OB0.jsxDEV(BX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this));
|