@kelceyp/caw-server 0.0.85 → 0.0.87
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/public_html/main.js +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
|
`},Y28={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 z28(J){let{announcements:Z=Y28,container:Q,hiddenTextDescribedById:K,screenReaderInstructions:X=U28}=J,{announce:U,announcement:Y}=ZK6(),z=Pk("DndLiveRegion"),[G,W]=p6.useState(!1);if(p6.useEffect(()=>{W(!0)},[]),K28(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(e16,{id:K,value:X.draggable}),p6.default.createElement(JK6,{id:z,announcement:Y}));return Q?T3.createPortal(q,Q):q}var pQ;(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"})(pQ||(pQ={}));function ai(){}function MB0(J,Z){return p6.useMemo(()=>({sensor:J,options:Z!=null?Z:{}}),[J,Z])}function MK6(){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 az=Object.freeze({x:0,y:0});function G28(J,Z){let Q=Vk(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 W28(J,Z){let{data:{value:Q}}=J,{data:{value:K}}=Z;return K-Q}function q28(J,Z){if(!J||J.length===0)return null;let[Q]=J;return Z?Q[Z]:Q}function H28(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 B28=(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=H28(z,Z);if(G>0)X.push({id:Y,data:{droppableContainer:U,value:G}})}}return X.sort(W28)};function F28(J,Z,Q){return{...J,scaleX:Z&&Q?Z.width/Q.width:1,scaleY:Z&&Q?Z.height/Q.height:1}}function OK6(J,Z){return J&&Z?{x:J.left-Z.left,y:J.top-Z.top}:az}function M28(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 O28=M28(1);function LK6(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 L28(J,Z,Q){let K=LK6(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 A28={ignoreTransform:!1};function Ck(J,Z){if(Z===void 0)Z=A28;let Q=J.getBoundingClientRect();if(Z.ignoreTransform){let{transform:W,transformOrigin:q}=S1(J).getComputedStyle(J);if(W)Q=L28(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 QK6(J){return Ck(J,{ignoreTransform:!0})}function N28(J){let{innerWidth:Z,innerHeight:Q}=J;return{top:0,left:0,right:Z,bottom:Q,width:Z,height:Q}}function I28(J,Z){if(Z===void 0)Z=S1(J).getComputedStyle(J);return Z.position==="fixed"}function R28(J,Z){if(Z===void 0)Z=S1(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 OB0(J,Z){let Q=[];function K(X){if(Z!=null&&Q.length>=Z)return Q;if(!X)return Q;if(ri(X)&&X.scrollingElement!=null&&!Q.includes(X.scrollingElement))return Q.push(X.scrollingElement),Q;if(!cD(X)||zB0(X))return Q;if(Q.includes(X))return Q;let U=S1(J).getComputedStyle(X);if(X!==J){if(R28(X,U))Q.push(X)}if(I28(X,U))return Q;return K(X.parentNode)}if(!J)return Q;return K(J)}function AK6(J){let[Z]=OB0(J,1);return Z!=null?Z:null}function GB0(J){if(!Ik||!J)return null;if(P3(J))return J;if(!ii(J))return null;if(ri(J)||J===E3(J).scrollingElement)return window;if(cD(J))return J;return null}function NK6(J){if(P3(J))return J.scrollX;return J.scrollLeft}function IK6(J){if(P3(J))return J.scrollY;return J.scrollTop}function HB0(J){return{x:NK6(J),y:IK6(J)}}var M5;(function(J){J[J.Forward=1]="Forward",J[J.Backward=-1]="Backward"})(M5||(M5={}));function RK6(J){if(!Ik||!J)return!1;return J===document.scrollingElement}function wK6(J){let Z={x:0,y:0},Q=RK6(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 w28={x:0.2,y:0.2};function D28(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=w28;let{isTop:W,isBottom:q,isLeft:H,isRight:B}=wK6(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=M5.Backward,L.y=K*Math.abs((Z.top+A.height-U)/A.height);else if(!q&&G>=Z.bottom-A.height)M.y=M5.Forward,L.y=K*Math.abs((Z.bottom-A.height-G)/A.height);if(!B&&z>=Z.right-A.width)M.x=M5.Forward,L.x=K*Math.abs((Z.right-A.width-z)/A.width);else if(!H&&Y<=Z.left+A.width)M.x=M5.Backward,L.x=K*Math.abs((Z.left+A.width-Y)/A.width);return{direction:M,speed:L}}function P28(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 DK6(J){return J.reduce((Z,Q)=>{return V3(Z,HB0(Q))},az)}function E28(J){return J.reduce((Z,Q)=>{return Z+NK6(Q)},0)}function V28(J){return J.reduce((Z,Q)=>{return Z+IK6(Q)},0)}function PK6(J,Z){if(Z===void 0)Z=Ck;if(!J)return;let{top:Q,left:K,bottom:X,right:U}=Z(J);if(!AK6(J))return;if(X<=0||U<=0||Q>=window.innerHeight||K>=window.innerWidth)J.scrollIntoView({block:"center",inline:"center"})}var j28=[["x",["left","right"],E28],["y",["top","bottom"],V28]];class ti{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=OB0(Z),K=DK6(Q);this.rect={...J},this.width=J.width,this.height=J.height;for(let[X,U,Y]of j28)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 iD{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 T28(J){let{EventTarget:Z}=S1(J);return J instanceof Z?J:E3(J)}function WB0(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 SY;(function(J){J.Click="click",J.DragStart="dragstart",J.Keydown="keydown",J.ContextMenu="contextmenu",J.Resize="resize",J.SelectionChange="selectionchange",J.VisibilityChange="visibilitychange"})(SY||(SY={}));function KK6(J){J.preventDefault()}function C28(J){J.stopPropagation()}var G4;(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"})(G4||(G4={}));var EK6={start:[G4.Space,G4.Enter],cancel:[G4.Esc],end:[G4.Space,G4.Enter,G4.Tab]},S28=(J,Z)=>{let{currentCoordinates:Q}=Z;switch(J.code){case G4.Right:return{...Q,x:Q.x+25};case G4.Left:return{...Q,x:Q.x-25};case G4.Down:return{...Q,y:Q.y+25};case G4.Up:return{...Q,y:Q.y-25}}return};class Sk{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 iD(E3(Z)),this.windowListeners=new iD(S1(Z)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(SY.Resize,this.handleCancel),this.windowListeners.add(SY.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(SY.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:J,onStart:Z}=this.props,Q=J.node.current;if(Q)PK6(Q);Z(az)}handleKeyDown(J){if(ni(J)){let{active:Z,context:Q,options:K}=this.props,{keyboardCodes:X=EK6,coordinateGetter:U=S28,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}:az;if(!this.referenceCoordinates)this.referenceCoordinates=W;let q=U(J,{active:Z,context:Q.current,currentCoordinates:W});if(q){let H=Ek(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}=wK6(L),T=P28(L),C={x:Math.min(A===G4.Right?T.right-T.width/2:T.right,Math.max(A===G4.Right?T.left:T.left+T.width/2,q.x)),y:Math.min(A===G4.Down?T.bottom-T.height/2:T.bottom,Math.max(A===G4.Down?T.top:T.top+T.height/2,q.y))},S=A===G4.Right&&!I||A===G4.Left&&!R,_=A===G4.Down&&!D||A===G4.Up&&!N;if(S&&C.x!==q.x){let h=L.scrollLeft+H.x,v=A===G4.Right&&h<=V.x||A===G4.Left&&h>=P.x;if(v&&!H.y){L.scrollTo({left:h,behavior:Y});return}if(v)B.x=L.scrollLeft-h;else B.x=A===G4.Right?L.scrollLeft-V.x:L.scrollLeft-P.x;if(B.x)L.scrollBy({left:-B.x,behavior:Y});break}else if(_&&C.y!==q.y){let h=L.scrollTop+H.y,v=A===G4.Down&&h<=V.y||A===G4.Up&&h>=P.y;if(v&&!H.x){L.scrollTo({top:h,behavior:Y});return}if(v)B.y=L.scrollTop-h;else B.y=A===G4.Down?L.scrollTop-V.y:L.scrollTop-P.y;if(B.y)L.scrollBy({top:-B.y,behavior:Y});break}}this.handleMove(J,V3(Ek(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()}}Sk.activators=[{eventName:"onKeyDown",handler:(J,Z,Q)=>{let{keyboardCodes:K=EK6,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 XK6(J){return Boolean(J&&"distance"in J)}function UK6(J){return Boolean(J&&"delay"in J)}class ei{constructor(J,Z,Q){var K;if(Q===void 0)Q=T28(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=E3(U),this.documentListeners=new iD(this.document),this.listeners=new iD(Q),this.windowListeners=new iD(S1(U)),this.initialCoordinates=(K=Vk(X))!=null?K:az,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(SY.Resize,this.handleCancel),this.windowListeners.add(SY.DragStart,KK6),this.windowListeners.add(SY.VisibilityChange,this.handleCancel),this.windowListeners.add(SY.ContextMenu,KK6),this.documentListeners.add(SY.Keydown,this.handleKeydown),Z){if(Q!=null&&Q({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(UK6(Z)){this.timeoutId=setTimeout(this.handleStart,Z.delay),this.handlePending(Z);return}if(XK6(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(SY.Click,C28,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(SY.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=Vk(J))!=null?Z:az,G=Ek(K,z);if(!Q&&Y){if(XK6(Y)){if(Y.tolerance!=null&&WB0(G,Y.tolerance))return this.handleCancel();if(WB0(G,Y.distance))return this.handleStart()}if(UK6(Y)){if(WB0(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===G4.Esc)this.handleCancel()}removeTextSelection(){var J;(J=this.document.getSelection())==null||J.removeAllRanges()}}var $28={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class $k extends ei{constructor(J){let{event:Z}=J,Q=E3(Z.target);super(J,$28,Q)}}$k.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 k28={move:{name:"mousemove"},end:{name:"mouseup"}},BB0;(function(J){J[J.RightClick=2]="RightClick"})(BB0||(BB0={}));class VK6 extends ei{constructor(J){super(J,k28,E3(J.event.target))}}VK6.activators=[{eventName:"onMouseDown",handler:(J,Z)=>{let{nativeEvent:Q}=J,{onActivation:K}=Z;if(Q.button===BB0.RightClick)return!1;return K==null||K({event:Q}),!0}}];var qB0={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class jK6 extends ei{constructor(J){super(J,qB0)}static setup(){return window.addEventListener(qB0.move.name,J,{capture:!1,passive:!1}),function(){window.removeEventListener(qB0.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 jk;(function(J){J[J.Pointer=0]="Pointer",J[J.DraggableRect=1]="DraggableRect"})(jk||(jk={}));var oi;(function(J){J[J.TreeOrder=0]="TreeOrder",J[J.ReversedTreeOrder=1]="ReversedTreeOrder"})(oi||(oi={}));function v28(J){let{acceleration:Z,activator:Q=jk.Pointer,canScroll:K,draggingRect:X,enabled:U,interval:Y=5,order:z=oi.TreeOrder,pointerCoordinates:G,scrollableAncestors:W,scrollableAncestorRects:q,delta:H,threshold:B}=J,M=_28({delta:H,disabled:!U}),[L,A]=a16(),N=p6.useRef({x:0,y:0}),I=p6.useRef({x:0,y:0}),R=p6.useMemo(()=>{switch(Q){case jk.Pointer:return G?{top:G.y,bottom:G.y,left:G.x,right:G.x}:null;case jk.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===oi.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:_,speed:h}=D28(T,S,R,Z,B);for(let v of["x","y"])if(!M[v][_[v]])h[v]=0,_[v]=0;if(h.x>0||h.y>0){A(),D.current=T,L(V,Y),N.current=h,I.current=_;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 f28={x:{[M5.Backward]:!1,[M5.Forward]:!1},y:{[M5.Backward]:!1,[M5.Forward]:!1}};function _28(J){let{delta:Z,disabled:Q}=J,K=Dk(Z);return dD((X)=>{if(Q||!K||!X)return f28;let U={x:Math.sign(Z.x-K.x),y:Math.sign(Z.y-K.y)};return{x:{[M5.Backward]:X.x[M5.Backward]||U.x===-1,[M5.Forward]:X.x[M5.Forward]||U.x===1},y:{[M5.Backward]:X.y[M5.Backward]||U.y===-1,[M5.Forward]:X.y[M5.Forward]||U.y===1}}},[Q,Z,K])}function b28(J,Z){let Q=Z!=null?J.get(Z):void 0,K=Q?Q.node.current:null;return dD((X)=>{var U;if(Z==null)return null;return(U=K!=null?K:X)!=null?U:null},[K,Z])}function x28(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 Tk;(function(J){J[J.Always=0]="Always",J[J.BeforeDragging=1]="BeforeDragging",J[J.WhileDragging=2]="WhileDragging"})(Tk||(Tk={}));var FB0;(function(J){J.Optimized="optimized"})(FB0||(FB0={}));var YK6=new Map;function h28(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=lD(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=dD((I)=>{if(H&&!Q)return YK6;if(!I||I===YK6||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 ti(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 Tk.Always:return!1;case Tk.BeforeDragging:return Q;default:return!Q}}}function LB0(J,Z){return dD((Q)=>{if(!J)return null;if(Q)return Q;return typeof Z==="function"?Z(J):J},[Z,J])}function y28(J,Z){return LB0(J,Z)}function g28(J){let{callback:Z,disabled:Q}=J,K=Rk(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 Jr(J){let{callback:Z,disabled:Q}=J,K=Rk(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 m28(J){return new ti(Ck(J),J)}function zK6(J,Z,Q){if(Z===void 0)Z=m28;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=g28({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=Jr({callback:U});return iW(()=>{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 u28(J){let Z=LB0(J);return OK6(J,Z)}var GK6=[];function p28(J){let Z=p6.useRef(J),Q=dD((K)=>{if(!J)return GK6;if(K&&K!==GK6&&J&&Z.current&&J.parentNode===Z.current.parentNode)return K;return OB0(J)},[J]);return p6.useEffect(()=>{Z.current=J},[J]),Q}function c28(J){let[Z,Q]=p6.useState(null),K=p6.useRef(J),X=p6.useCallback((U)=>{let Y=GB0(U.target);if(!Y)return;Q((z)=>{if(!z)return null;return z.set(Y,HB0(Y)),new Map(z)})},[]);return p6.useEffect(()=>{let U=K.current;if(J!==U){Y(U);let z=J.map((G)=>{let W=GB0(G);if(W)return W.addEventListener("scroll",X,{passive:!0}),[W,HB0(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=GB0(G);W==null||W.removeEventListener("scroll",X)})}},[X,J]),p6.useMemo(()=>{if(J.length)return Z?Array.from(Z.values()).reduce((U,Y)=>V3(U,Y),az):DK6(J);return az},[J,Z])}function WK6(J,Z){if(Z===void 0)Z=[];let Q=p6.useRef(null);return p6.useEffect(()=>{Q.current=null},Z),p6.useEffect(()=>{let K=J!==az;if(K&&!Q.current)Q.current=J;if(!K&&Q.current)Q.current=null},[J]),Q.current?Ek(J,Q.current):az}function l28(J){p6.useEffect(()=>{if(!Ik)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 d28(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 TK6(J){return p6.useMemo(()=>J?N28(J):null,[J])}var qK6=[];function i28(J,Z){if(Z===void 0)Z=Ck;let[Q]=J,K=TK6(Q?S1(Q):null),[X,U]=p6.useState(qK6);function Y(){U(()=>{if(!J.length)return qK6;return J.map((G)=>RK6(G)?K:new ti(Z(G),G))})}let z=Jr({callback:Y});return iW(()=>{z==null||z.disconnect(),Y(),J.forEach((G)=>z==null?void 0:z.observe(G))},[J]),X}function CK6(J){if(!J)return null;if(J.children.length>1)return J;let Z=J.children[0];return cD(Z)?Z:J}function r28(J){let{measure:Z}=J,[Q,K]=p6.useState(null),X=p6.useCallback((W)=>{for(let{target:q}of W)if(cD(q)){K((H)=>{let B=Z(q);return H?{...H,width:B.width,height:B.height}:B});break}},[Z]),U=Jr({callback:X}),Y=p6.useCallback((W)=>{let q=CK6(W);if(U==null||U.disconnect(),q)U==null||U.observe(q);K(q?Z(q):null)},[Z,U]),[z,G]=wk(Y);return p6.useMemo(()=>({nodeRef:z,rect:Q,setRef:G}),[Q,z,G])}var n28=[{sensor:$k,options:{}},{sensor:Sk,options:{}}],s28={current:{}},si={draggable:{measure:QK6},droppable:{measure:QK6,strategy:Tk.WhileDragging,frequency:FB0.Optimized},dragOverlay:{measure:Ck}};class rD 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 a28={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new rD,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:ai},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:si,measureDroppableContainers:ai,windowRect:null,measuringScheduled:!1},SK6={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:ai,draggableNodes:new Map,over:null,measureDroppableContainers:ai},kk=p6.createContext(SK6),$K6=p6.createContext(a28);function o28(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new rD}}}function t28(J,Z){switch(Z.type){case pQ.DragStart:return{...J,draggable:{...J.draggable,initialCoordinates:Z.initialCoordinates,active:Z.active}};case pQ.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 pQ.DragEnd:case pQ.DragCancel:return{...J,draggable:{...J.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case pQ.RegisterDroppable:{let{element:Q}=Z,{id:K}=Q,X=new rD(J.droppable.containers);return X.set(K,Q),{...J,droppable:{...J.droppable,containers:X}}}case pQ.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 rD(J.droppable.containers);return Y.set(Q,{...U,disabled:X}),{...J,droppable:{...J.droppable,containers:Y}}}case pQ.UnregisterDroppable:{let{id:Q,key:K}=Z,X=J.droppable.containers.get(Q);if(!X||K!==X.key)return J;let U=new rD(J.droppable.containers);return U.delete(Q),{...J,droppable:{...J.droppable,containers:U}}}default:return J}}function e28(J){let{disabled:Z}=J,{active:Q,activatorEvent:K,draggableNodes:X}=p6.useContext(kk),U=Dk(K),Y=Dk(Q==null?void 0:Q.id);return p6.useEffect(()=>{if(Z)return;if(!K&&U&&Y!=null){if(!ni(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=t16(q);if(H){H.focus();break}}})}},[K,Z,X,Y,U]),null}function kK6(J,Z){let{transform:Q,...K}=Z;return J!=null&&J.length?J.reduce((X,U)=>{return U({transform:X,...K})},Q):Q}function JH8(J){return p6.useMemo(()=>({draggable:{...si.draggable,...J==null?void 0:J.draggable},droppable:{...si.droppable,...J==null?void 0:J.droppable},dragOverlay:{...si.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 ZH8(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;iW(()=>{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=OK6(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=AK6(W);if(B)B.scrollBy({top:H.y,left:H.x})}},[Z,Y,z,K,Q])}var Zr=p6.createContext({...az,scaleX:1,scaleY:1}),YM;(function(J){J[J.Uninitialized=0]="Uninitialized",J[J.Initializing=1]="Initializing",J[J.Initialized=2]="Initialized"})(YM||(YM={}));var vK6=p6.memo(function(Z){var Q,K,X,U;let{id:Y,accessibility:z,autoScroll:G=!0,children:W,sensors:q=n28,collisionDetection:H=B28,measuring:B,modifiers:M,...L}=Z,A=p6.useReducer(t28,void 0,o28),[N,I]=A,[R,D]=X28(),[V,P]=p6.useState(YM.Uninitialized),T=V===YM.Initialized,{draggable:{active:C,nodes:S,translate:_},droppable:{containers:h}}=N,v=C!=null?S.get(C):null,$=p6.useRef({initial:null,translated:null}),k=p6.useMemo(()=>{var A6;return C!=null?{id:C,data:(A6=v==null?void 0:v.data)!=null?A6:s28,rect:$}:null},[C,v]),f=p6.useRef(null),[b,y]=p6.useState(null),[g,m]=p6.useState(null),u=lD(L,Object.values(L)),d=Pk("DndDescribedBy",Y),l=p6.useMemo(()=>h.getEnabled(),[h]),r=JH8(B),{droppableRects:e,measureDroppableContainers:Y0,measuringScheduled:J0}=h28(l,{dragging:T,dependencies:[_.x,_.y],config:r.droppable}),B0=b28(S,C),o=p6.useMemo(()=>g?Vk(g):null,[g]),H0=B6(),K0=y28(B0,r.draggable.measure);ZH8({activeNode:C!=null?S.get(C):null,config:H0.layoutShiftCompensation,initialRect:K0,measure:r.draggable.measure});let q0=zK6(B0,r.draggable.measure,K0),Z0=zK6(B0?B0.parentElement:null),X0=p6.useRef({activatorEvent:null,active:null,activeNode:B0,collisionRect:null,collisions:null,droppableRects:e,draggableNodes:S,draggingNode:null,draggingNodeRect:null,droppableContainers:h,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),O0=h.getNodeFor((Q=X0.current.over)==null?void 0:Q.id),W0=r28({measure:r.dragOverlay.measure}),P0=(K=W0.nodeRef.current)!=null?K:B0,F0=T?(X=W0.rect)!=null?X:q0:null,y0=Boolean(W0.nodeRef.current&&W0.rect),Q0=u28(y0?null:q0),Q6=TK6(P0?S1(P0):null),G0=p28(T?O0!=null?O0:B0:null),V0=i28(G0),k0=kK6(M,{transform:{x:_.x-Q0.x,y:_.y-Q0.y,scaleX:1,scaleY:1},activatorEvent:g,active:k,activeNodeRect:q0,containerNodeRect:Z0,draggingNodeRect:F0,over:X0.current.over,overlayNodeRect:W0.rect,scrollableAncestors:G0,scrollableAncestorRects:V0,windowRect:Q6}),d0=o?V3(o,_):null,j0=c28(G0),T0=WK6(j0),g0=WK6(j0,[q0]),b0=V3(k0,T0),p0=F0?O28(F0,k0):null,E0=k&&p0?H({active:k,collisionRect:p0,droppableRects:e,droppableContainers:l,pointerCoordinates:d0}):null,x0=q28(E0,"id"),[t,D0]=p6.useState(null),i=y0?k0:V3(k0,g0),N0=F28(i,(U=t==null?void 0:t.rect)!=null?U:null,q0),I0=p6.useRef(null),u0=p6.useCallback((A6,y6)=>{let{sensor:J6,options:K6}=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:K6,context:X0,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,$0={activatorEvent:X6,active:{id:t6,data:S6.data,rect:$}};T3.unstable_batchedUpdates(()=>{C6==null||C6($0),P(YM.Initializing),I({type:pQ.DragStart,initialCoordinates:k6,active:t6}),R({type:"onDragStart",event:$0}),y(I0.current),m(X6)})},onMove(k6){I({type:pQ.DragMove,coordinates:k6})},onEnd:Z8(pQ.DragEnd),onCancel:Z8(pQ.DragCancel)});I0.current=f6;function Z8(k6){return async function(){let{active:S6,collisions:C6,over:$0,scrollAdjustedTranslate:e0}=X0.current,H6=null;if(S6&&e0){let{cancelDrop:w0}=u.current;if(H6={activatorEvent:X6,active:S6,collisions:C6,delta:e0,over:$0},k6===pQ.DragEnd&&typeof w0==="function"){if(await Promise.resolve(w0(H6)))k6=pQ.DragCancel}}f.current=null,T3.unstable_batchedUpdates(()=>{I({type:k6}),P(YM.Uninitialized),D0(null),y(null),m(null),I0.current=null;let w0=k6===pQ.DragEnd?"onDragEnd":"onDragCancel";if(H6){let z6=u.current[w0];z6==null||z6(H6),R({type:w0,event:H6})}})}}},[S]),_0=p6.useCallback((A6,y6)=>{return(J6,K6)=>{let L6=J6.nativeEvent,X6=S.get(K6);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=K6,u0(J6,y6)}},[S,u0]),v0=x28(q,_0);l28(q),iW(()=>{if(q0&&V===YM.Initializing)P(YM.Initialized)},[q0,V]),p6.useEffect(()=>{let{onDragMove:A6}=u.current,{active:y6,activatorEvent:J6,collisions:K6,over:L6}=X0.current;if(!y6||!J6)return;let X6={active:y6,activatorEvent:J6,collisions:K6,delta:{x:b0.x,y:b0.y},over:L6};T3.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:K6,scrollAdjustedTranslate:L6}=X0.current;if(!A6||f.current==null||!y6||!L6)return;let{onDragOver:X6}=u.current,f6=K6.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};T3.unstable_batchedUpdates(()=>{D0(Z8),X6==null||X6(k6),R({type:"onDragOver",event:k6})})},[x0]),iW(()=>{X0.current={activatorEvent:g,active:k,activeNode:B0,collisionRect:p0,collisions:E0,droppableRects:e,draggableNodes:S,draggingNode:P0,draggingNodeRect:F0,droppableContainers:h,over:t,scrollableAncestors:G0,scrollAdjustedTranslate:b0},$.current={initial:F0,translated:p0}},[k,B0,E0,p0,S,P0,F0,e,h,t,G0,b0]),v28({...H0,delta:_,draggingRect:p0,pointerCoordinates:d0,scrollableAncestors:G0,scrollableAncestorRects:V0});let n0=p6.useMemo(()=>{return{active:k,activeNode:B0,activeNodeRect:q0,activatorEvent:g,collisions:E0,containerNodeRect:Z0,dragOverlay:W0,draggableNodes:S,droppableContainers:h,droppableRects:e,over:t,measureDroppableContainers:Y0,scrollableAncestors:G0,scrollableAncestorRects:V0,measuringConfiguration:r,measuringScheduled:J0,windowRect:Q6}},[k,B0,q0,g,E0,Z0,W0,S,h,e,t,Y0,G0,V0,r,J0,Q6]),l0=p6.useMemo(()=>{return{activatorEvent:g,activators:v0,active:k,activeNodeRect:q0,ariaDescribedById:{draggable:d},dispatch:I,draggableNodes:S,over:t,measureDroppableContainers:Y0}},[g,v0,k,q0,I,d,S,t,Y0]);return p6.default.createElement(FK6.Provider,{value:D},p6.default.createElement(kk.Provider,{value:l0},p6.default.createElement($K6.Provider,{value:n0},p6.default.createElement(Zr.Provider,{value:N0},W)),p6.default.createElement(e28,{disabled:(z==null?void 0:z.restoreFocus)===!1})),p6.default.createElement(z28,{...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}}}),QH8=p6.createContext(null),HK6="button",KH8="Draggable";function fK6(J){let{id:Z,data:Q,disabled:K=!1,attributes:X}=J,U=Pk(KH8),{activators:Y,activatorEvent:z,active:G,activeNodeRect:W,ariaDescribedById:q,draggableNodes:H,over:B}=p6.useContext(kk),{role:M=HK6,roleDescription:L="draggable",tabIndex:A=0}=X!=null?X:{},N=(G==null?void 0:G.id)===Z,I=p6.useContext(N?Zr:QH8),[R,D]=wk(),[V,P]=wk(),T=d28(Y,Z),C=lD(Q);iW(()=>{return H.set(Z,{id:Z,key:U,node:R,activatorNode:V,data:C}),()=>{let _=H.get(Z);if(_&&_.key===U)H.delete(Z)}},[H,Z]);let S=p6.useMemo(()=>({role:M,tabIndex:A,"aria-disabled":K,"aria-pressed":N&&M===HK6?!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 XH8(){return p6.useContext($K6)}var UH8="Droppable",YH8={timeout:25};function _K6(J){let{data:Z,disabled:Q=!1,id:K,resizeObserverConfig:X}=J,U=Pk(UH8),{active:Y,dispatch:z,over:G,measureDroppableContainers:W}=p6.useContext(kk),q=p6.useRef({disabled:Q}),H=p6.useRef(!1),B=p6.useRef(null),M=p6.useRef(null),{disabled:L,updateMeasurementsFor:A,timeout:N}={...YH8,...X},I=lD(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=Jr({callback:R,disabled:L||!Y}),V=p6.useCallback((S,_)=>{if(!D)return;if(_)D.unobserve(_),H.current=!1;if(S)D.observe(S)},[D]),[P,T]=wk(V),C=lD(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:pQ.RegisterDroppable,element:{id:K,key:U,disabled:Q,node:P,rect:B,data:C}}),()=>z({type:pQ.UnregisterDroppable,key:U,id:K})},[K]),p6.useEffect(()=>{if(Q!==q.current.disabled)z({type:pQ.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 zH8(J){let{animation:Z,children:Q}=J,[K,X]=p6.useState(null),[U,Y]=p6.useState(null),z=Dk(Q);if(!Q&&!K&&z)X(z);return iW(()=>{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 GH8={x:0,y:0,scaleX:1,scaleY:1};function WH8(J){let{children:Z}=J;return p6.default.createElement(kk.Provider,{value:SK6},p6.default.createElement(Zr.Provider,{value:GH8},Z))}var qH8={position:"fixed",touchAction:"none"},HH8=(J)=>{return ni(J)?"transform 250ms ease":void 0},BH8=p6.forwardRef((J,Z)=>{let{as:Q,activatorEvent:K,adjustScale:X,children:U,className:Y,rect:z,style:G,transform:W,transition:q=HH8}=J;if(!z)return null;let H=X?W:{...W,scaleX:1,scaleY:1},B={...qH8,width:z.width,height:z.height,top:z.top,left:z.left,transform:pD.Transform.toString(H),transformOrigin:X&&K?G28(K,z):void 0,transition:typeof q==="function"?q(K):q,...G};return p6.default.createElement(Q,{className:Y,style:B,ref:Z},U)}),FH8=(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)}},MH8=(J)=>{let{transform:{initial:Z,final:Q}}=J;return[{transform:pD.Transform.toString(Z)},{transform:pD.Transform.toString(Q)}]},OH8={duration:250,easing:"ease",keyframes:MH8,sideEffects:FH8({styles:{active:{opacity:"0"}}})};function LH8(J){let{config:Z,draggableNodes:Q,droppableContainers:K,measuringConfiguration:X}=J;return Rk((U,Y)=>{if(Z===null)return;let z=Q.get(U);if(!z)return;let G=z.node.current;if(!G)return;let W=CK6(Y);if(!W)return;let{transform:q}=S1(Y).getComputedStyle(Y),H=LK6(q);if(!H)return;let B=typeof Z==="function"?Z:AH8(Z);return PK6(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 AH8(J){let{duration:Z,easing:Q,sideEffects:K,keyframes:X}={...OH8,...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 BK6=0;function NH8(J){return p6.useMemo(()=>{if(J==null)return;return BK6++,BK6},[J])}var bK6=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}=XH8(),T=p6.useContext(Zr),C=NH8(H==null?void 0:H.id),S=kK6(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}),_=LB0(B),h=LH8({config:K,draggableNodes:L,droppableContainers:A,measuringConfiguration:R}),v=_?N.setRef:void 0;return p6.default.createElement(WH8,null,p6.default.createElement(zH8,{animation:h},H&&C?p6.default.createElement(BH8,{key:C,id:H.id,ref:v,as:z,activatorEvent:q,adjustScale:Z,className:G,transition:U,rect:_,style:{zIndex:W,...X},transform:S},Q):null))});var IH8="",RH8=()=>({"Content-Type":"application/json","X-Session-Id":lJ()});async function xK6(J,Z,Q,{value:K,values:X}){let U=X?{values:X}:{value:K},Y=await fetch(`${IH8}/api/p/${J}/entities/${Z}/fields/${Q}`,{method:"PUT",headers:RH8(),body:JSON.stringify(U)});return P9(Y,"Failed to set field value")}function Qr(J){let Z=e9();return AJ({mutationFn:({entityId:Q,fieldName:K,value:X,values:U})=>xK6(J,Q,K,U?{values:U}:{value:X}),onSuccess:()=>{Z.invalidateQueries({queryKey:["folderContents",J]}),Z.invalidateQueries({queryKey:["stories",J]})}})}var wH8=f0(P6(),1);var C3=f0(z8(),1);function AB0({task:J,onClick:Z,onMoveTask:Q,states:K}){let{attributes:X,listeners:U,setNodeRef:Y,isDragging:z}=fK6({id:J.id,data:{state:J.fields?.state,task:J}});return C3.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:[C3.jsxDEV("div",{className:"text-sm truncate",children:J.name},void 0,!1,void 0,this),J.fields?.label&&C3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.label},void 0,!1,void 0,this),J.fields?.colour&&C3.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&&C3.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&&C3.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 DH8({state:J,children:Z}){let{setNodeRef:Q,isOver:K}=_K6({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 hK6({projectId:J,storyId:Z,onOpenDocument:Q}){let[K,X]=nD.useState(null),[U,Y]=nD.useState(!1),[z,G]=nD.useState(""),[W,q]=nD.useState(""),H=MB0($k,{activationConstraint:{distance:8}}),B=MB0(Sk),M=MK6(H,B),L=Qr(J),A=M3(J),N=e9(),{data:I,isLoading:R,isError:D}=bV(J,{folderId:Z,type:"d"}),V=I?.find((g)=>g.isFolder&&g.subtype==="tasks"),P=V?.fields?.states??[],{data:T,isLoading:C,isError:S}=bV(J,{folderId:V?.id,type:"d",enabled:!!V?.id}),_={};for(let g of P)_[g]=[];if(T){for(let g of T)if(!g.isFolder&&g.fields?.state&&_[g.fields.state])_[g.fields.state].push(g)}let h=V?["folderContents",J,"A",V.id,"d","default"]:null;function v(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;v(m.id,u.id)}function f(g,m){let u=T?.find((e)=>e.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;v(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(n6,{variant:"warning",size:"sm",onClick:()=>{G(""),q(P[0]||""),Y(!0)},children:[F7.jsxDEV(sQ,{className:"w-4 h-4"},void 0,!1,void 0,this),F7.jsxDEV(sY,{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(vK6,{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(DH8,{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):_[g]?.map((m)=>F7.jsxDEV(AB0,{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(bK6,{children:y?F7.jsxDEV(AB0,{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(lZ,{open:U,onOpenChange:(g)=>{if(Y(g),!g)G(""),q(P[0]||"")},children:F7.jsxDEV(EZ,{children:[F7.jsxDEV(VZ,{children:F7.jsxDEV(jZ,{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(J5,{value:W,onValueChange:q,children:[F7.jsxDEV(RQ,{children:F7.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV(wQ,{children:P.map((g)=>F7.jsxDEV(iJ,{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(dZ,{children:[F7.jsxDEV(n6,{variant:"outline",onClick:()=>{Y(!1),G(""),q(P[0]||"")},children:"Cancel"},void 0,!1,void 0,this),F7.jsxDEV(n6,{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="",fk=()=>({"Content-Type":"application/json","X-Session-Id":lJ()}),yK6=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:fk()});return P9(U,"Failed to list stories")};var gK6=async(J,{name:Z,store:Q,state:K})=>{let X=await fetch(`${vk}/api/p/${J}/stories`,{method:"POST",headers:fk(),body:JSON.stringify({name:Z,store:Q,state:K})});return P9(X,"Failed to create story")},mK6=async(J,Z,Q)=>{let K=await fetch(`${vk}/api/p/${J}/stories/${Z}/state`,{method:"PATCH",headers:fk(),body:JSON.stringify({state:Q})});return P9(K,"Failed to update story state")},uK6=async(J,Z,Q)=>{let K=await fetch(`${vk}/api/p/${J}/stories/${Z}/name`,{method:"PATCH",headers:fk(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename story")},pK6=async(J,Z)=>{let Q=await fetch(`${vk}/api/p/${J}/stories/${Z}`,{method:"DELETE",headers:fk()});return P9(Q,"Failed to delete story")};var cK6=(J,{store:Z}={})=>{return FQ({queryKey:["stories",J,Z??"demux"],queryFn:()=>yK6(J,{store:Z}),enabled:!!J,staleTime:30000})};var lK6=(J)=>{let Z=e9();return AJ({mutationFn:({name:Q,store:K,state:X})=>gK6(J,{name:Q,store:K,state:X}),onSuccess:(Q,{store:K})=>{Z.invalidateQueries({queryKey:["stories",J,K??"demux"]})}})},dK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,state:K})=>mK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},iK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,name:K})=>uK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},rK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q})=>pK6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})};var nK6=f0(P6(),1),sK6=(J)=>{let Z=KT0(J,{path:"",store:"A",type:"s"});return{states:nK6.useMemo(()=>Z.data?.fields?.states??[],[Z.data]),isLoading:Z.isLoading,error:Z.error,refetch:Z.refetch}};var Kr="prep";var v6=f0(z8(),1),PH8={useItem:d2,useCreate:M3,useSaveDraft:FD,usePublish:MD,useDiscard:OD,useVersions:LD,useDelete:AD,useUpdatePath:ND,getVersion:BD},NB0=[{key:"unsorted",icon:VG,label:"Not sorted"},{key:"name-asc",icon:wG,label:"Sorting by name ascending"},{key:"name-desc",icon:RG,label:"Sorting by name descending"},{key:"date-asc",icon:eM,label:"Sorting by date ascending"},{key:"date-desc",icon:tM,label:"Sorting by date descending"},{key:"state-asc",icon:$H,label:"Sorting by state ascending"},{key:"state-desc",icon:SH,label:"Sorting by state descending"}],aK6=[{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"}],EH8=({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=aK6[X%aK6.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(JO,{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(ZO,{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)},VH8=({projectId:J,storyId:Z})=>{let{data:Q,isLoading:K,error:X}=NZ6(J,"s"),[U,Y]=YZ.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(rY,{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(pi,{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)},jH8=({projectId:J,story:Z,onDeleted:Q})=>{let[K,X]=YZ.useState(Z.name),[U,Y]=YZ.useState(null),[z,G]=YZ.useState(!1),[W,q]=YZ.useState(null),H=iK6(J),B=rK6(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(ZQ,{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(n6,{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(n6,{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(lZ,{open:z,onOpenChange:G,children:v6.jsxDEV(EZ,{children:[v6.jsxDEV(VZ,{children:v6.jsxDEV(jZ,{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(dZ,{children:[v6.jsxDEV(n6,{variant:"outline",onClick:()=>G(!1),children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(n6,{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)},IB0=()=>{let{id:J,storeCode:Z}=j5(),[Q,K]=dM(),{data:X}=q1(J);H1(X?`${X.name} - Stories`:"CAW");let U=Z??"A";rH(J);let{data:Y=[],isLoading:z,error:G,refetch:W}=cK6(J,{store:U}),{states:q,isLoading:H,error:B,refetch:M}=sK6(J),L=lK6(J),A=dK6(J),N=Qr(J),[I,R]=YZ.useState(!1),[D,V]=YZ.useState(""),[P,T]=YZ.useState(Kr),[C,S]=YZ.useState(null),[_,h]=YZ.useState("documents"),[v,$]=YZ.useState("state-asc"),k=YZ.useRef(null),[f,b]=YZ.useState(null),y=YZ.useMemo(()=>f??new Set(q),[f,q]),g=(o)=>{let H0=f??new Set(q),K0=new Set(H0);if(K0.has(o))K0.delete(o);else K0.add(o);b(K0.size===q.length?null:K0)};YZ.useEffect(()=>{if(Q.has("id"))h("documents")},[Q]);let m=Q.get("expanded")??"",u=YZ.useRef({}),d=(o)=>{if(h("documents"),K((H0)=>{let K0=new URLSearchParams(H0);if(K0.delete("id"),K0.delete("edit"),o)K0.set("expanded",o);else K0.delete("expanded");return K0}),o)setTimeout(()=>{u.current[o]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},l=YZ.useMemo(()=>{if(!q.length)return[];let o=Y.filter((K0)=>K0.fields?.state&&y.has(K0.fields.state));if(v==="unsorted"){if(k.current){let K0=k.current,q0=[...o];return q0.sort((Z0,X0)=>{let O0=K0.indexOf(Z0.id),W0=K0.indexOf(X0.id);return(O0===-1?1/0:O0)-(W0===-1?1/0:W0)}),q0}return o}let H0=[...o];return H0.sort((K0,q0)=>{if(v==="name-asc")return K0.name.localeCompare(q0.name);if(v==="name-desc")return q0.name.localeCompare(K0.name);if(v==="date-asc"||v==="date-desc"){let Z0=(O0)=>O0.createdAt?new Date(O0.createdAt).getTime():parseInt(O0.id.replace(/\D/g,""),10)||0,X0=Z0(K0)-Z0(q0);return v==="date-asc"?X0:-X0}if(v==="state-asc")return q.indexOf(K0.fields.state)-q.indexOf(q0.fields.state);if(v==="state-desc")return q.indexOf(q0.fields.state)-q.indexOf(K0.fields.state);return 0}),H0},[Y,q,v,y]),r=()=>{if(!D.trim()){S("Story name is required");return}S(null),L.mutate({name:D.trim(),store:U,state:P},{onSuccess:(o)=>{R(!1),V(""),T(Kr),K((H0)=>{let K0=new URLSearchParams(H0);return K0.delete("id"),K0.delete("edit"),K0.set("expanded",o.id),K0})},onError:(o)=>{S(o.message)}})},e=()=>{R(!1),V(""),T(Kr),S(null)},Y0=z||H,J0=G||B,B0=G?W:M;if(Y0)return v6.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(J0)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:J0.message},void 0,!1,void 0,this),v6.jsxDEV(n6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>B0(),children:[v6.jsxDEV(XO,{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(n6,{size:"sm",variant:"warning",onClick:()=>R(!0),children:[v6.jsxDEV(sQ,{className:"w-4 h-4"},void 0,!1,void 0,this),v6.jsxDEV(kH,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(tx,{children:[v6.jsxDEV(Y7,{content:NB0.find((o)=>o.key===v)?.label,children:v6.jsxDEV(ex,{asChild:!0,children:v6.jsxDEV(n6,{size:"sm",variant:"outline",children:YZ.default.createElement(NB0.find((o)=>o.key===v)?.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(rV,{align:"start",children:NB0.map((o)=>v6.jsxDEV(nV,{onClick:()=>{if(o.key==="unsorted")k.current=l.map((H0)=>H0.id);else k.current=null;$(o.key)},className:v===o.key?"bg-accent":"",children:[v6.jsxDEV(o.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),o.label]},o.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(r16,{children:[v6.jsxDEV(Y7,{content:"Filter by state",children:v6.jsxDEV(n16,{asChild:!0,children:v6.jsxDEV(n6,{size:"sm",variant:"outline",children:v6.jsxDEV(hH,{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(UB0,{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((o)=>v6.jsxDEV("label",{className:"flex items-center gap-2",children:[v6.jsxDEV(Mk,{checked:y.has(o),onCheckedChange:()=>g(o)},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"text-sm capitalize",children:o},void 0,!1,void 0,this)]},o,!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),l.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(Xb,{type:"single",collapsible:!0,value:m,onValueChange:d,children:l.map((o)=>{let H0=q.indexOf(o.fields.state),K0=H0>0?q[H0-1]:null,q0=H0<q.length-1?q[H0+1]:null;return v6.jsxDEV(Ub,{value:o.id,className:"border-b",ref:(Z0)=>{u.current[o.id]=Z0},children:[v6.jsxDEV(Yb,{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(kH,{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:o.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 ${o.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:o.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(EH8,{state:o.fields.state,states:q,onPrev:K0?()=>A.mutate({id:o.id,state:K0}):null,onNext:q0?()=>A.mutate({id:o.id,state:q0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"flex justify-center",children:o.fields?.flag==="true"&&v6.jsxDEV(dE,{className:"w-4 h-4 flex-shrink-0 text-amber-500 cursor-pointer hover:text-amber-600 dark:text-amber-400 dark:hover:text-amber-300",fill:"currentColor",onClick:(Z0)=>{Z0.stopPropagation(),N.mutate({entityId:o.id,fieldName:"flag",value:"false"})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"flex justify-end",children:v6.jsxDEV(mK,{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(zb,{className:"border-t",children:v6.jsxDEV(S16,{value:_,onValueChange:h,children:[v6.jsxDEV(QB0,{variant:"line",className:"px-4",children:[v6.jsxDEV(gD,{value:"documents",children:[v6.jsxDEV(nQ,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Documents"]},void 0,!0,void 0,this),v6.jsxDEV(gD,{value:"tasks",children:[v6.jsxDEV(sY,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Tasks"]},void 0,!0,void 0,this),v6.jsxDEV(gD,{value:"prompts",children:[v6.jsxDEV(nE,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),v6.jsxDEV(gD,{value:"settings",children:[v6.jsxDEV(tY,{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(mD,{value:"documents",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(Xh,{projectId:J,rootFolderId:o.id,type:"d",DetailPanel:Nd,hooks:PH8},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(mD,{value:"tasks",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(hK6,{projectId:J,storyId:o.id,onOpenDocument:(Z0,X0)=>{K((O0)=>{let W0=new URLSearchParams(O0);if(W0.set("id",Z0),X0?.edit)W0.set("edit","true");return W0})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(mD,{value:"prompts",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(VH8,{projectId:J,storyId:o.id},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(mD,{value:"settings",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(jH8,{projectId:J,story:o,onDeleted:()=>{K((Z0)=>{let X0=new URLSearchParams(Z0);return X0.delete("expanded"),X0.delete("id"),X0.delete("edit"),X0})}},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)]},o.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(lZ,{open:I,onOpenChange:e,children:v6.jsxDEV(EZ,{children:[v6.jsxDEV(VZ,{children:v6.jsxDEV(jZ,{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(z4,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),v6.jsxDEV(ZQ,{id:"name",value:D,onChange:(o)=>V(o.target.value),placeholder:"Enter story name",onKeyDown:(o)=>o.key==="Enter"&&r()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV(z4,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),v6.jsxDEV(J5,{value:P,onValueChange:T,children:[v6.jsxDEV(RQ,{children:v6.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(wQ,{children:q.map((o)=>v6.jsxDEV(iJ,{value:o,children:o.charAt(0).toUpperCase()+o.slice(1)},o,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),C&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(dZ,{children:[v6.jsxDEV(n6,{variant:"outline",onClick:e,children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(n6,{onClick:r,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 Z1=f0(P6(),1);var TK=f0(P6(),1);var p9=f0(z8(),1),TH8=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],oK6=({open:J,onOpenChange:Z,projectId:Q,onSuccess:K,initialPrompt:X=""})=>{let[U,Y]=TK.useState(""),[z,G]=TK.useState("claude"),[W,q]=TK.useState(""),[H,B]=TK.useState({type:"main",path:null}),[M,L]=TK.useState(""),[A,N]=TK.useState(""),[I,R]=TK.useState(!1),[D,V]=TK.useState({}),[P,T]=TK.useState(!1),[C,S]=TK.useState(null),[_,h]=TK.useState(null);TK.useEffect(()=>{if(X)L(X)},[X]);let{data:v,isLoading:$,error:k}=mi(J?Q:null),f=v?.worktrees??[],b=v?.isGitProject??!0,y=gi(Q),g=Id(Q),m=ui(Q),{data:u}=ID(Q,A.trim()||null),d=u?.parameters??[],l=u?.detectedVariables??[],r=A.trim().length>0,e=()=>{Y(""),G("claude"),q(""),B({type:"main",path:null}),L(X||""),N(""),S(null),h(null),V({}),T(!1)},Y0=()=>{e(),Z(!1)},J0=()=>{if(H.type==="main")return;return H.path||void 0},B0=(W0)=>{y.mutate({name:U.trim()||void 0,agent:z,model:W.trim()||void 0,prompt:M.trim(),workingDirectory:W0},{onSuccess:(P0)=>{if(Y0(),K)K(P0)},onError:(P0)=>{S(P0.message)}})},o=()=>{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:(W0)=>{B0(W0.path)},onError:(W0)=>{h(W0.message)}});else B0(J0())},H0=()=>{R(!0)},K0=(W0)=>{V(W0),g.mutate({id:A.trim(),params:W0,target:"stdout"},{onSuccess:(P0)=>{if(P0.content)L(P0.content);N(""),R(!1)},onError:(P0)=>{S(`Template render failed: ${P0.message}`),R(!1)}})},q0=r?"render":"run",Z0=q0==="run"&&!M.trim(),X0=m.isPending,O0=y.isPending||g.isPending||X0;return p9.jsxDEV(p9.Fragment,{children:[p9.jsxDEV(lZ,{open:J,onOpenChange:Y0,children:p9.jsxDEV(EZ,{className:"max-w-lg",children:[p9.jsxDEV(VZ,{children:p9.jsxDEV(jZ,{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(z4,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),p9.jsxDEV(ZQ,{id:"job-name",value:U,onChange:(W0)=>Y(W0.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(z4,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),p9.jsxDEV(J5,{value:z,onValueChange:G,children:[p9.jsxDEV(RQ,{children:p9.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(wQ,{children:TH8.map((W0)=>p9.jsxDEV(iJ,{value:W0.value,children:W0.label},W0.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(z4,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),p9.jsxDEV(ZQ,{id:"job-model",value:W,onChange:(W0)=>q(W0.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(mK,{className:"w-4 h-4"},void 0,!1,void 0,this):p9.jsxDEV(VU,{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(yi,{value:H,onChange:B,worktrees:f,isLoadingWorktrees:$,isGitProject:b,error:k,createError:_,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(z4,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),p9.jsxDEV(lW,{id:"job-prompt",value:M,onChange:(W0)=>L(W0.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(z4,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),p9.jsxDEV(ZQ,{id:"job-template",value:A,onChange:(W0)=>N(W0.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(dZ,{children:[p9.jsxDEV(n6,{variant:"outline",onClick:Y0,children:"Cancel"},void 0,!1,void 0,this),q0==="render"?p9.jsxDEV(n6,{onClick:H0,disabled:O0,children:[p9.jsxDEV(nQ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),O0?"Rendering...":"Render"]},void 0,!0,void 0,this):p9.jsxDEV(n6,{onClick:o,disabled:Z0||O0,children:[p9.jsxDEV(mX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),X0?"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(lZ,{open:I,onOpenChange:R,children:p9.jsxDEV(EZ,{className:"max-w-lg",children:[p9.jsxDEV(VZ,{children:p9.jsxDEV(jZ,{className:"flex items-center gap-2",children:[p9.jsxDEV(nQ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",lU(u?.path)," (",A,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(hi,{fields:d,detectedVariables:l,initialValues:D,onSubmit:K0,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 l8=f0(z8(),1),CH8=86400000,SH8=({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 l8.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)},tK6=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},$H8=(J)=>{if(J===null||J===void 0)return"-";if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},eK6=async(J)=>{if(!J)return;try{await navigator.clipboard.writeText(J),F1.success("Copied")}catch(Z){console.error("Failed to copy:",Z)}},kH8=(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},wB0=({job:J,onClick:Z,projectPath:Q})=>{let K=kH8(J.fields?.workingDirectory,Q);return l8.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:[l8.jsxDEV(SH8,{status:J.fields?.status},void 0,!1,void 0,this),l8.jsxDEV(Y7,{content:"Click to copy",children:l8.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(X)=>{X.stopPropagation(),eK6(J.id)},children:J.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),l8.jsxDEV(Y7,{content:J.fields?.sessionId||"No session ID",children:l8.jsxDEV("span",{className:"w-24 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(X)=>{if(X.stopPropagation(),J.fields?.sessionId)eK6(J.fields?.sessionId)},children:J.fields?.sessionId?J.fields?.sessionId.slice(0,8)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),l8.jsxDEV("div",{className:"flex-1 min-w-0",children:[l8.jsxDEV("span",{className:"truncate text-sm font-medium block",children:J.name},void 0,!1,void 0,this),K&&l8.jsxDEV(Y7,{content:J.fields?.workingDirectory,children:l8.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),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.agent},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.pid||"-"},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:tK6(J.fields?.startedAt)},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:tK6(J.fields?.completedAt)},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:$H8(J.fields?.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},JX6=({title:J,count:Z})=>{return l8.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[l8.jsxDEV("h3",{className:"text-sm font-semibold text-foreground",children:J},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",Z,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},vH8=({column:J,sortColumn:Z,sortDirection:Q})=>{if(Z!==J)return l8.jsxDEV(aM,{className:"w-3 h-3 ml-1 opacity-50"},void 0,!1,void 0,this);return Q==="asc"?l8.jsxDEV(oM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this):l8.jsxDEV(sM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)},DB0=({onSort:J,sortColumn:Z,sortDirection:Q})=>{return l8.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 l8.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&&l8.jsxDEV(vH8,{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)},ZX6=["active","history"],RB0=(J,Z,Q="")=>{let K=Z?`/project/${J}/store/${Z}/jobs`:`/project/${J}/jobs`;return Q?`${K}/${Q}`:K},QX6=({active:J,onClick:Z,children:Q})=>l8.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),fH8=({activeJobs:J,completedJobs:Z,onJobClick:Q,onNewJob:K,projectPath:X,onActiveSort:U,activeSortColumn:Y,activeSortDirection:z,onCompletedSort:G,completedSortColumn:W,completedSortDirection:q})=>l8.jsxDEV("div",{className:"space-y-6",children:[l8.jsxDEV("div",{className:"flex justify-start",children:l8.jsxDEV(n6,{size:"sm",variant:"warning",onClick:K,children:[l8.jsxDEV(sQ,{className:"w-4 h-4"},void 0,!1,void 0,this),l8.jsxDEV(QO,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),l8.jsxDEV("div",{children:[l8.jsxDEV(JX6,{title:"Active Jobs",count:J.length},void 0,!1,void 0,this),J.length>0?l8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[l8.jsxDEV(DB0,{onSort:U,sortColumn:Y,sortDirection:z},void 0,!1,void 0,this),J.map((H)=>l8.jsxDEV(wB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):l8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[l8.jsxDEV(mX,{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),l8.jsxDEV("div",{children:[l8.jsxDEV(JX6,{title:"Recently Completed",count:Z.length},void 0,!1,void 0,this),Z.length>0?l8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[l8.jsxDEV(DB0,{onSort:G,sortColumn:W,sortDirection:q},void 0,!1,void 0,this),Z.map((H)=>l8.jsxDEV(wB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):l8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[l8.jsxDEV(vH,{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),_H8=({completedJobs:J,onJobClick:Z,projectPath:Q,onSort:K,sortColumn:X,sortDirection:U})=>l8.jsxDEV("div",{children:J.length>0?l8.jsxDEV(l8.Fragment,{children:[l8.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),l8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[l8.jsxDEV(DB0,{onSort:K,sortColumn:X,sortDirection:U},void 0,!1,void 0,this),J.map((Y)=>l8.jsxDEV(wB0,{job:Y,onClick:Z,projectPath:Q},Y.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):l8.jsxDEV("div",{className:"text-center py-8 text-muted-foreground",children:[l8.jsxDEV(vH,{className:"w-8 h-8 mx-auto mb-2 opacity-50"},void 0,!1,void 0,this),l8.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),_k=()=>{let{id:J,storeCode:Z,tab:Q}=j5(),K=qZ(),X=cJ(),{data:U}=q1(J),Y=Q&&!ZX6.includes(Q),z=ZX6.includes(Q)?Q:"active";H1(U?`${U.name} - Jobs`:"CAW");let[G,W]=Z1.useState(!1),[q,H]=Z1.useState(""),[B,M]=Z1.useState("startedAt"),[L,A]=Z1.useState("desc"),[N,I]=Z1.useState("completedAt"),[R,D]=Z1.useState("desc"),[V,P]=Z1.useState("completedAt"),[T,C]=Z1.useState("desc"),S=Z??"A";rH(J);let{data:_=[],isLoading:h,error:v,refetch:$}=J16(J,{store:S}),k=(e)=>{return["startedAt","completedAt","tokensUsed"].includes(e)?"desc":"asc"},f=(e)=>{if(B===e)A((Y0)=>Y0==="asc"?"desc":"asc");else M(e),A(k(e))},b=(e)=>{if(N===e)D((Y0)=>Y0==="asc"?"desc":"asc");else I(e),D(k(e))},y=(e)=>{if(V===e)C((Y0)=>Y0==="asc"?"desc":"asc");else P(e),C(k(e))},g=(e,Y0,J0)=>{return[...e].sort((B0,o)=>{let H0=0;switch(Y0){case"status":let K0={running:0,completed:1,error:2};H0=(K0[B0.fields?.status]??3)-(K0[o.fields?.status]??3);break;case"name":H0=(B0.name||"").localeCompare(o.name||"");break;case"agent":H0=(B0.fields?.agent||"").localeCompare(o.fields?.agent||"");break;case"startedAt":case"completedAt":let q0=(O0)=>{if(!O0)return 0;let W0=new Date(O0).getTime();return isNaN(W0)?0:W0},Z0=q0(B0.fields?.[Y0]),X0=q0(o.fields?.[Y0]);H0=Z0-X0;break;case"tokensUsed":H0=(B0.fields?.tokensUsed??0)-(o.fields?.tokensUsed??0);break;default:H0=0}return J0==="asc"?H0:-H0})},m=Z1.useMemo(()=>{let e=_.filter((Y0)=>Y0.fields?.status==="running");return g(e,B,L)},[_,B,L]),u=Z1.useMemo(()=>{let e=Date.now()-CH8,Y0=_.filter((J0)=>J0.fields?.status==="completed"||J0.fields?.status==="error").filter((J0)=>J0.fields?.completedAt&&new Date(J0.fields?.completedAt).getTime()>e);return g(Y0,N,R)},[_,N,R]),d=Z1.useMemo(()=>{let e=_.filter((Y0)=>Y0.fields?.status==="completed"||Y0.fields?.status==="error");return g(e,V,T)},[_,V,T]),l=(e)=>{let Y0=Z?`/project/${J}/store/${Z}/job/${e.id}`:`/project/${J}/job/${e.id}`;K(Y0,{state:{fromTab:z}})},r=(e)=>{if(e&&e.id){let Y0=Z?`/project/${J}/store/${Z}/job/${e.id}`:`/project/${J}/job/${e.id}`;K(Y0,{state:{fromTab:z}})}};if(Z1.useEffect(()=>{if(X.state?.openNewJobWithPrompt)H(X.state.openNewJobWithPrompt),W(!0),K(X.pathname,{replace:!0,state:{}})},[X.state,K,X.pathname]),Z1.useEffect(()=>{if(Y)K(RB0(J,Z,"active"),{replace:!0})},[Y,K,J,Z]),Y)return null;if(h)return l8.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(v)return l8.jsxDEV("div",{className:"p-6",children:[l8.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),l8.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:v.message},void 0,!1,void 0,this),l8.jsxDEV(n6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>$(),children:[l8.jsxDEV(XO,{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 l8.jsxDEV("div",{className:"h-full flex flex-col",children:[l8.jsxDEV("div",{className:"flex border-b overflow-x-auto bg-muted/50 px-2",role:"tablist","aria-label":"Jobs tabs",children:[l8.jsxDEV(QX6,{active:z==="active",onClick:()=>K(RB0(J,Z,"active")),children:"Active"},void 0,!1,void 0,this),l8.jsxDEV(QX6,{active:z==="history",onClick:()=>K(RB0(J,Z,"history")),children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l8.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:z==="active"?l8.jsxDEV(fH8,{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):l8.jsxDEV(_H8,{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),l8.jsxDEV(oK6,{open:G,onOpenChange:(e)=>{if(W(e),!e)H("")},projectId:J,onSuccess:r,initialPrompt:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var LU=f0(P6(),1);var PB0=f0(P6(),1);var bk=f0(z8(),1),KX6=({value:J,disabled:Z=!1,className:Q=""})=>{let[K,X]=PB0.useState(!1);return bk.jsxDEV(Y7,{content:"Copy to clipboard",children:bk.jsxDEV(n6,{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?bk.jsxDEV(p1,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):bk.jsxDEV(rQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var zM=f0(P6(),1);var $1=f0(z8(),1),XX6=({open:J,onOpenChange:Z,sessionId:Q,onContinue:K,isLoading:X})=>{let[U,Y]=zM.useState(""),z=zM.useRef(null);zM.useEffect(()=>{if(!J)Y("")},[J]),zM.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 $1.jsxDEV(lZ,{open:J,onOpenChange:W,children:$1.jsxDEV(EZ,{children:[$1.jsxDEV(VZ,{children:$1.jsxDEV(jZ,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$1.jsxDEV("form",{onSubmit:G,className:"space-y-4",children:[$1.jsxDEV("div",{className:"space-y-2",children:[$1.jsxDEV(z4,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),$1.jsxDEV(ZQ,{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),$1.jsxDEV("div",{className:"space-y-2",children:[$1.jsxDEV(z4,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),$1.jsxDEV(lW,{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),$1.jsxDEV(dZ,{children:[$1.jsxDEV(n6,{type:"button",variant:"outline",onClick:W,children:"Cancel"},void 0,!1,void 0,this),$1.jsxDEV(n6,{type:"submit",disabled:q,children:[X&&$1.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),bH8=({status:J})=>{let Z={running:{icon:NJ,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:DG,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:fH,class:"text-red-700 border-red-300 bg-red-50",animate:!1},pending:{icon:cE,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)},UX6=(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"})},xH8=(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()},YX6=(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},zX6=(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},GX6=({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(mK,{className:"w-4 h-4"},void 0,!1,void 0,this):E8.jsxDEV(VU,{className:"w-4 h-4"},void 0,!1,void 0,this),E8.jsxDEV(nQ,{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),WX6=({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(GX6,{title:"Output",docId:U,isOpen:G,onToggle:W,children:E8.jsxDEV(c2,{markdown:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(GX6,{title:"Prompt",docId:X,isOpen:Y,onToggle:z,children:E8.jsxDEV(c2,{markdown:Z||""},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},hH8=86400000,EB0=()=>{let{id:J,storeCode:Z,jobId:Q}=j5(),K=qZ(),X=cJ(),{data:U}=q1(J);H1(U?`${U.name} - Job: ${Q}`:"CAW"),rH(J);let{data:Y,isLoading:z,error:G}=Z16(J,Q),{data:W,isLoading:q}=Q16(J,Q),{promptDoc:H,outputDoc:B}=LU.useMemo(()=>{if(!W)return{promptDoc:null,outputDoc:null};let H0=W.documents||[],K0=H0.find((Z0)=>Z0.name==="prompt.md"),q0=H0.find((Z0)=>Z0.name==="output.md");return{promptDoc:K0,outputDoc:q0}},[W]),{data:M}=d2(J,H?.id),{data:L}=d2(J,B?.id),A=M?.draftContent??M?.publishedContent??"",N=L?.draftContent??L?.publishedContent??"",I=LU.useMemo(()=>zX6(A),[A]),R=LU.useMemo(()=>zX6(N),[N]),D=I.length>1||R.length>1,[V,P]=LU.useState({}),T=Math.max(I.length,R.length);LU.useEffect(()=>{P((H0)=>{let K0={...H0};for(let q0=0;q0<T;q0++)if(!(q0 in K0))K0[q0]={promptOpen:!0,outputOpen:!0};return K0})},[T]);let C=()=>{P((H0)=>{let K0={};for(let q0 of Object.keys(H0))K0[q0]={promptOpen:!1,outputOpen:!1};return K0})},S=()=>{P((H0)=>{let K0={};for(let q0 of Object.keys(H0))K0[q0]={promptOpen:!0,outputOpen:!0};return K0})},_=async()=>{try{await navigator.clipboard.writeText(Q),F1.success("ID copied")}catch(H0){console.error("Failed to copy ID:",H0)}},h=(H0)=>{if(!H0)return"active";if(H0.fields?.status==="running")return"active";if(H0.fields?.completedAt){let K0=new Date(H0.fields?.completedAt).getTime(),q0=Date.now()-hH8;if(K0>q0)return"active"}return"history"},v=()=>{let H0=X.state?.fromTab||h(Y),K0=Z?`/project/${J}/store/${Z}/jobs/${H0}`:`/project/${J}/jobs/${H0}`;K(K0)},[$,k]=LU.useState(!1),f=K16(J,Q),b=(Y?.status==="completed"||Y?.status==="error")&&Y?.sessionId,y=async(H0)=>{await f.mutateAsync({prompt:H0}),k(!1)},[g,m]=LU.useState(!1),[u,d]=LU.useState(""),[l,r]=LU.useState(null),e=X16(J),Y0=()=>{d(Y.name),r(null),m(!0)},J0=async()=>{let H0=u.trim();if(!H0||H0===Y.name){m(!1),r(null);return}try{await e.mutateAsync({id:Q,name:H0}),m(!1),r(null)}catch(K0){let q0=K0?.message||"Failed to rename job";r(q0)}},B0=(H0)=>{if(H0.key==="Enter")H0.preventDefault(),J0();if(H0.key==="Escape")m(!1),r(null)},o=(H0)=>{if(d(H0.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(n6,{variant:"outline",className:"mt-4",onClick:v,children:[E8.jsxDEV(yA,{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(n6,{variant:"ghost",size:"sm",onClick:v,children:E8.jsxDEV(yA,{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:o,onBlur:J0,onKeyDown:B0,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(n6,{variant:"ghost",size:"sm",onClick:Y0,children:E8.jsxDEV(G1,{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(bH8,{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),UX6(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),UX6(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),xH8(Y.tokensUsed)]},void 0,!0,void 0,this),YX6(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),YX6(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(KX6,{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(n6,{variant:"default",size:"sm",onClick:()=>k(!0),children:[E8.jsxDEV(sE,{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(n6,{variant:"outline",size:"sm",onClick:_,children:[E8.jsxDEV(rQ,{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(n6,{variant:"outline",size:"sm",onClick:C,children:"Collapse All"},void 0,!1,void 0,this),E8.jsxDEV(n6,{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((H0,K0,q0)=>{let Z0=q0.length-1-K0,X0=I[Z0],O0=R[Z0],W0=X0?.turnNumber??O0?.turnNumber??Z0+1;return E8.jsxDEV(WX6,{turnNumber:W0,promptContent:X0?.content,outputContent:O0?.content,showHeading:!0,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[Z0]?.promptOpen??!0,setIsPromptOpen:(P0)=>P((F0)=>({...F0,[Z0]:{...F0[Z0],promptOpen:P0}})),isOutputOpen:V[Z0]?.outputOpen??!0,setIsOutputOpen:(P0)=>P((F0)=>({...F0,[Z0]:{...F0[Z0],outputOpen:P0}}))},Z0,!1,void 0,this)}):E8.jsxDEV(WX6,{turnNumber:1,promptContent:I[0]?.content,outputContent:R[0]?.content,showHeading:!1,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[0]?.promptOpen??!0,setIsPromptOpen:(H0)=>P((K0)=>({...K0,[0]:{...K0[0],promptOpen:H0}})),isOutputOpen:V[0]?.outputOpen??!0,setIsOutputOpen:(H0)=>P((K0)=>({...K0,[0]:{...K0[0],outputOpen:H0}}))},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(XX6,{open:$,onOpenChange:k,sessionId:Y.sessionId,onContinue:y,isLoading:f.isPending},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var CK=f0(P6(),1);var S3=f0(P6(),1);var $3=f0(z8(),1),Xr=S3.default.forwardRef(({className:J,...Z},Q)=>$3.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));Xr.displayName="Card";var yH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("div",{ref:Q,className:k8("flex flex-col space-y-1.5 p-6",J),...Z},void 0,!1,void 0,this));yH8.displayName="CardHeader";var gH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("h3",{ref:Q,className:k8("text-2xl font-semibold leading-none tracking-tight",J),...Z},void 0,!1,void 0,this));gH8.displayName="CardTitle";var mH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("p",{ref:Q,className:k8("text-sm text-muted-foreground",J),...Z},void 0,!1,void 0,this));mH8.displayName="CardDescription";var Ur=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("div",{ref:Q,className:k8("p-6 pt-0",J),...Z},void 0,!1,void 0,this));Ur.displayName="CardContent";var uH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("div",{ref:Q,className:k8("flex items-center p-6 pt-0",J),...Z},void 0,!1,void 0,this));uH8.displayName="CardFooter";var Yr="",zr=()=>({"Content-Type":"application/json","X-Session-Id":lJ()}),qX6=async(J)=>{let Z=await fetch(`${Yr}/api/p/${J}/export/preview`,{headers:zr()});return P9(Z,"Failed to get export preview")},HX6=async(J)=>{let Z=await fetch(`${Yr}/api/p/${J}/exports`,{headers:zr()});return P9(Z,"Failed to get exports")},BX6=async(J)=>{let Z=await fetch(`${Yr}/api/p/${J}/export`,{method:"POST",headers:zr(),body:JSON.stringify({confirm:!0})});return P9(Z,"Failed to export documents")},FX6=async(J,Z)=>{let Q=await fetch(`${Yr}/api/p/${J}/import`,{method:"POST",headers:zr(),body:JSON.stringify({filename:Z})});return P9(Q,"Failed to import documents")};var l6=f0(z8(),1),MX6=()=>{let{id:J}=j5(),{data:Z,isLoading:Q}=q1(J),[K,X]=CK.useState(!1),[U,Y]=CK.useState(null),[z,G]=CK.useState(!1),[W,q]=CK.useState(null),[H,B]=CK.useState(!1),[M,L]=CK.useState(null),[A,N]=CK.useState(null),[I,R]=CK.useState(!1),[D,V]=CK.useState(!1),[P,T]=CK.useState(null),[C,S]=CK.useState(null),[_,h]=CK.useState([]),[v,$]=CK.useState("");H1(Z?`${Z.name} - Settings`:"CAW");let k=async(r,e)=>{if(Y(null),!navigator.clipboard?.writeText){Y("Clipboard not available");return}try{await navigator.clipboard.writeText(r),e(!0),setTimeout(()=>e(!1),2000)}catch(Y0){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 qX6(Z.objectId);q(r)}catch(r){L(r.message)}finally{B(!1)}},g=async()=>{B(!0),L(null);try{let r=await BX6(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 HX6(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(!v){T("Please select an export file");return}V(!0),T(null);try{let r=await FX6(Z.objectId,v);S(r)}catch(r){T(r.message)}finally{V(!1)}},l=()=>{R(!1),S(null),T(null)};if(Q)return l6.jsxDEV("div",{className:"p-6",children:l6.jsxDEV("p",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(!Z)return l6.jsxDEV("div",{className:"p-6",children:l6.jsxDEV("p",{className:"text-muted-foreground",children:"Project not found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return l6.jsxDEV("div",{className:"p-6",children:[l6.jsxDEV("h2",{className:"text-2xl font-bold text-foreground mb-6",children:"Project Settings"},void 0,!1,void 0,this),l6.jsxDEV("div",{className:"max-w-2xl space-y-6",children:[l6.jsxDEV(Xr,{children:l6.jsxDEV(Ur,{className:"pt-6 space-y-6",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Project Name"},void 0,!1,void 0,this),l6.jsxDEV("p",{className:"text-foreground mt-1",children:Z.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Path"},void 0,!1,void 0,this),l6.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),l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Add to Claude Code"},void 0,!1,void 0,this),l6.jsxDEV("div",{className:"flex items-start gap-2 mt-1",children:[l6.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),l6.jsxDEV(n6,{variant:"outline",size:"icon",onClick:b,className:"shrink-0",children:K?l6.jsxDEV(p1,{className:"w-4 h-4"},void 0,!1,void 0,this):l6.jsxDEV(rQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&l6.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),l6.jsxDEV(Xr,{children:l6.jsxDEV(Ur,{className:"pt-6",children:l6.jsxDEV("div",{className:"flex items-start justify-between",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"PROJECT STORE (A)"},void 0,!1,void 0,this),l6.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),l6.jsxDEV("div",{className:"flex gap-2",children:[l6.jsxDEV(n6,{onClick:y,size:"sm",children:[l6.jsxDEV(lE,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Export"]},void 0,!0,void 0,this),l6.jsxDEV(n6,{onClick:u,variant:"outline",size:"sm",children:[l6.jsxDEV(jG,{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),l6.jsxDEV(lZ,{open:z,onOpenChange:G,children:l6.jsxDEV(EZ,{children:[l6.jsxDEV(VZ,{children:[l6.jsxDEV(jZ,{children:A?"Export Complete":"Export Preview"},void 0,!1,void 0,this),l6.jsxDEV(lx,{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&&l6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:l6.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&&l6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[l6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),l6.jsxDEV("span",{className:"text-sm",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W?.toExport&&W?.draftOnly&&!A&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Will be exported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[l6.jsxDEV("li",{children:[W.toExport.documents.length," documents"]},void 0,!0,void 0,this),l6.jsxDEV("li",{children:[W.toExport.templates.length," templates"]},void 0,!0,void 0,this),l6.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)&&l6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:l6.jsxDEV("div",{className:"flex items-start gap-2",children:[l6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),l6.jsxDEV("div",{children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Draft-only items will NOT be exported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[W.draftOnly.documents.length>0&&l6.jsxDEV("li",{children:[W.draftOnly.documents.length," documents",W.draftOnly.documents.length<=3&&l6.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&&l6.jsxDEV("li",{children:[W.draftOnly.templates.length," templates",W.draftOnly.templates.length<=3&&l6.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&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Exported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[l6.jsxDEV("li",{children:[A.counts.documents," documents"]},void 0,!0,void 0,this),l6.jsxDEV("li",{children:[A.counts.templates," templates"]},void 0,!0,void 0,this),l6.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),l6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Saved to: ",l6.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),l6.jsxDEV(dZ,{children:!A?l6.jsxDEV(l6.Fragment,{children:[l6.jsxDEV(n6,{variant:"outline",onClick:m,children:"Cancel"},void 0,!1,void 0,this),l6.jsxDEV(n6,{onClick:g,disabled:H||!W,children:H?l6.jsxDEV(l6.Fragment,{children:[l6.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):l6.jsxDEV(n6,{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),l6.jsxDEV(lZ,{open:I,onOpenChange:R,children:l6.jsxDEV(EZ,{children:[l6.jsxDEV(VZ,{children:[l6.jsxDEV(jZ,{children:C?"Import Complete":"Import from .caw-exports/"},void 0,!1,void 0,this),l6.jsxDEV(lx,{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&&l6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[l6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),l6.jsxDEV("span",{className:"text-sm",children:P},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D&&_.length===0&&!P&&l6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:l6.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&&_.length===0&&!P&&l6.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&&_.length>0&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-foreground block mb-2",children:"Select export file:"},void 0,!1,void 0,this),l6.jsxDEV(J5,{value:v,onValueChange:$,children:[l6.jsxDEV(RQ,{children:l6.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),l6.jsxDEV(wQ,{children:_.map((r)=>l6.jsxDEV(iJ,{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),l6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:l6.jsxDEV("div",{className:"flex items-start gap-2",children:[l6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),l6.jsxDEV("div",{children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Important:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[l6.jsxDEV("li",{children:"The store must be empty before importing"},void 0,!1,void 0,this),l6.jsxDEV("li",{children:"Entity IDs will be remapped to new values"},void 0,!1,void 0,this),l6.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&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Imported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[l6.jsxDEV("li",{children:[C.counts.documents," documents"]},void 0,!0,void 0,this),l6.jsxDEV("li",{children:[C.counts.templates," templates"]},void 0,!0,void 0,this),l6.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&&l6.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),l6.jsxDEV(dZ,{children:!C?l6.jsxDEV(l6.Fragment,{children:[l6.jsxDEV(n6,{variant:"outline",onClick:l,children:"Cancel"},void 0,!1,void 0,this),l6.jsxDEV(n6,{onClick:d,disabled:D||!v,children:D?l6.jsxDEV(l6.Fragment,{children:[l6.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):l6.jsxDEV(n6,{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 pH8=f0(P6(),1);var GM=f0(z8(),1),Gr=()=>{let J=cJ(),Z=qZ();return GM.jsxDEV("div",{className:"flex items-center justify-center h-full",children:GM.jsxDEV("div",{className:"text-center max-w-md px-4",children:[GM.jsxDEV(S7,{className:"w-16 h-16 text-muted-foreground/50 mx-auto mb-4"},void 0,!1,void 0,this),GM.jsxDEV("h2",{className:"text-2xl font-semibold text-foreground mb-2",children:"Page Not Found"},void 0,!1,void 0,this),GM.jsxDEV("p",{className:"text-muted-foreground mb-4",children:["The path ",GM.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),GM.jsxDEV(n6,{onClick:()=>Z("/"),children:"Go Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var JH=f0(z8(),1),OX6=()=>{let{theme:J,toggleTheme:Z}=D_(),Q=J==="dark";return JH.jsxDEV("div",{className:"flex items-center justify-between",children:[JH.jsxDEV("div",{children:[JH.jsxDEV("div",{className:"font-medium text-foreground",children:"Theme"},void 0,!1,void 0,this),JH.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),JH.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:JH.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?JH.jsxDEV(aE,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this):JH.jsxDEV(oE,{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 oz=f0(z8(),1),LX6=()=>{return H1("CAW - Preferences"),oz.jsxDEV("div",{className:"flex-1 p-6",children:[oz.jsxDEV("div",{className:"mb-6",children:oz.jsxDEV("div",{className:"flex items-center gap-3",children:[oz.jsxDEV(tY,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this),oz.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),oz.jsxDEV("div",{className:"max-w-2xl",children:oz.jsxDEV("section",{className:"mb-8",children:[oz.jsxDEV("h2",{className:"text-lg font-medium text-foreground mb-4",children:"Appearance"},void 0,!1,void 0,this),oz.jsxDEV("div",{className:"bg-card border border-border rounded-lg p-4",children:oz.jsxDEV(OX6,{},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 NX6=f0(z8(),1),AX6=(J)=>NX6.jsxDEV(BT0,{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),lH8=()=>{return b9.jsxDEV(xo,{children:b9.jsxDEV(oo,{client:rA0,children:[b9.jsxDEV(fo,{children:b9.jsxDEV(B4,{element:b9.jsxDEV(Kw0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(B4,{index:!0,element:b9.jsxDEV(zw0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"preferences",element:b9.jsxDEV(LX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"project/:id",element:b9.jsxDEV(Yw0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(B4,{index:!0,element:b9.jsxDEV(ef,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"documents/*",element:b9.jsxDEV(hz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"templates/*",element:b9.jsxDEV(JB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"stories",element:b9.jsxDEV(IB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs/:tab",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"job/:jobId",element:b9.jsxDEV(EB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"settings",element:b9.jsxDEV(MX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"store/:storeCode",children:[b9.jsxDEV(B4,{index:!0,element:b9.jsxDEV(ef,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"documents/*",element:b9.jsxDEV(hz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"templates/*",element:b9.jsxDEV(JB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"stories",element:b9.jsxDEV(IB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs/:tab",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"job/:jobId",element:b9.jsxDEV(EB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"*",element:b9.jsxDEV(Gr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(B4,{path:"*",element:b9.jsxDEV(Gr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(B4,{path:"*",element:b9.jsxDEV(Gr,{},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(AX6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},IX6=lH8;var VB0=f0(z8(),1),DX6=document.getElementById("root");if(!DX6)throw Error("Root element not found");var dH8=wX6.createRoot(DX6);dH8.render(VB0.jsxDEV(RX6.default.StrictMode,{children:VB0.jsxDEV(IX6,{},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:[C3.jsxDEV("div",{className:"text-sm truncate",children:J.name},void 0,!1,void 0,this),J.fields?.label&&C3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.label},void 0,!1,void 0,this),J.fields?.colour&&C3.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&&C3.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&&C3.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 DH8({state:J,children:Z}){let{setNodeRef:Q,isOver:K}=_K6({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 hK6({projectId:J,storyId:Z,onOpenDocument:Q}){let[K,X]=nD.useState(null),[U,Y]=nD.useState(!1),[z,G]=nD.useState(""),[W,q]=nD.useState(""),H=MB0($k,{activationConstraint:{distance:8}}),B=MB0(Sk),M=MK6(H,B),L=Qr(J),A=M3(J),N=e9(),{data:I,isLoading:R,isError:D}=bV(J,{folderId:Z,type:"d"}),V=I?.find((g)=>g.isFolder&&g.subtype==="tasks"),P=V?.fields?.states??[],{data:T,isLoading:C,isError:S}=bV(J,{folderId:V?.id,type:"d",enabled:!!V?.id}),_={};for(let g of P)_[g]=[];if(T){for(let g of T)if(!g.isFolder&&g.fields?.state&&_[g.fields.state])_[g.fields.state].push(g)}let h=V?["folderContents",J,"A",V.id,"d","default"]:null;function v(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;v(m.id,u.id)}function f(g,m){let u=T?.find((e)=>e.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;v(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(n6,{variant:"warning",size:"sm",onClick:()=>{G(""),q(P[0]||""),Y(!0)},children:[F7.jsxDEV(sQ,{className:"w-4 h-4"},void 0,!1,void 0,this),F7.jsxDEV(sY,{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(vK6,{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(DH8,{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):_[g]?.map((m)=>F7.jsxDEV(AB0,{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(bK6,{children:y?F7.jsxDEV(AB0,{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(lZ,{open:U,onOpenChange:(g)=>{if(Y(g),!g)G(""),q(P[0]||"")},children:F7.jsxDEV(EZ,{children:[F7.jsxDEV(VZ,{children:F7.jsxDEV(jZ,{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(J5,{value:W,onValueChange:q,children:[F7.jsxDEV(RQ,{children:F7.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),F7.jsxDEV(wQ,{children:P.map((g)=>F7.jsxDEV(iJ,{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(dZ,{children:[F7.jsxDEV(n6,{variant:"outline",onClick:()=>{Y(!1),G(""),q(P[0]||"")},children:"Cancel"},void 0,!1,void 0,this),F7.jsxDEV(n6,{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="",fk=()=>({"Content-Type":"application/json","X-Session-Id":lJ()}),yK6=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:fk()});return P9(U,"Failed to list stories")};var gK6=async(J,{name:Z,store:Q,state:K})=>{let X=await fetch(`${vk}/api/p/${J}/stories`,{method:"POST",headers:fk(),body:JSON.stringify({name:Z,store:Q,state:K})});return P9(X,"Failed to create story")},mK6=async(J,Z,Q)=>{let K=await fetch(`${vk}/api/p/${J}/stories/${Z}/state`,{method:"PATCH",headers:fk(),body:JSON.stringify({state:Q})});return P9(K,"Failed to update story state")},uK6=async(J,Z,Q)=>{let K=await fetch(`${vk}/api/p/${J}/stories/${Z}/name`,{method:"PATCH",headers:fk(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename story")},pK6=async(J,Z)=>{let Q=await fetch(`${vk}/api/p/${J}/stories/${Z}`,{method:"DELETE",headers:fk()});return P9(Q,"Failed to delete story")};var cK6=(J,{store:Z}={})=>{return FQ({queryKey:["stories",J,Z??"demux"],queryFn:()=>yK6(J,{store:Z}),enabled:!!J,staleTime:30000})};var lK6=(J)=>{let Z=e9();return AJ({mutationFn:({name:Q,store:K,state:X})=>gK6(J,{name:Q,store:K,state:X}),onSuccess:(Q,{store:K})=>{Z.invalidateQueries({queryKey:["stories",J,K??"demux"]})}})},dK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,state:K})=>mK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},iK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q,name:K})=>uK6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},rK6=(J)=>{let Z=e9();return AJ({mutationFn:({id:Q})=>pK6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})};var nK6=f0(P6(),1),sK6=(J)=>{let Z=KT0(J,{path:"",store:"A",type:"s"});return{states:nK6.useMemo(()=>Z.data?.fields?.states??[],[Z.data]),isLoading:Z.isLoading,error:Z.error,refetch:Z.refetch}};var Kr="prep";var v6=f0(z8(),1),PH8={useItem:d2,useCreate:M3,useSaveDraft:FD,usePublish:MD,useDiscard:OD,useVersions:LD,useDelete:AD,useUpdatePath:ND,getVersion:BD},NB0=[{key:"unsorted",icon:VG,label:"Not sorted"},{key:"name-asc",icon:wG,label:"Sorting by name ascending"},{key:"name-desc",icon:RG,label:"Sorting by name descending"},{key:"date-asc",icon:eM,label:"Sorting by date ascending"},{key:"date-desc",icon:tM,label:"Sorting by date descending"},{key:"state-asc",icon:$H,label:"Sorting by state ascending"},{key:"state-desc",icon:SH,label:"Sorting by state descending"}],aK6=[{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"}],EH8=({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=aK6[X%aK6.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(JO,{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(ZO,{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)},VH8=({projectId:J,storyId:Z})=>{let{data:Q,isLoading:K,error:X}=NZ6(J,"s"),[U,Y]=YZ.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(rY,{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(pi,{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)},jH8=({projectId:J,story:Z,onDeleted:Q})=>{let[K,X]=YZ.useState(Z.name),[U,Y]=YZ.useState(null),[z,G]=YZ.useState(!1),[W,q]=YZ.useState(null),H=iK6(J),B=rK6(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(ZQ,{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(n6,{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(n6,{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(lZ,{open:z,onOpenChange:G,children:v6.jsxDEV(EZ,{children:[v6.jsxDEV(VZ,{children:v6.jsxDEV(jZ,{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(dZ,{children:[v6.jsxDEV(n6,{variant:"outline",onClick:()=>G(!1),children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(n6,{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)},IB0=()=>{let{id:J,storeCode:Z}=j5(),[Q,K]=dM(),{data:X}=q1(J);H1(X?`${X.name} - Stories`:"CAW");let U=Z??"A";rH(J);let{data:Y=[],isLoading:z,error:G,refetch:W}=cK6(J,{store:U}),{states:q,isLoading:H,error:B,refetch:M}=sK6(J),L=lK6(J),A=dK6(J),N=Qr(J),[I,R]=YZ.useState(!1),[D,V]=YZ.useState(""),[P,T]=YZ.useState(Kr),[C,S]=YZ.useState(null),[_,h]=YZ.useState("documents"),[v,$]=YZ.useState("state-asc"),k=YZ.useRef(null),[f,b]=YZ.useState(null),y=YZ.useMemo(()=>f??new Set(q),[f,q]),g=(o)=>{let H0=f??new Set(q),K0=new Set(H0);if(K0.has(o))K0.delete(o);else K0.add(o);b(K0.size===q.length?null:K0)};YZ.useEffect(()=>{if(Q.has("id"))h("documents")},[Q]);let m=Q.get("expanded")??"",u=YZ.useRef({}),d=(o)=>{if(h("documents"),K((H0)=>{let K0=new URLSearchParams(H0);if(K0.delete("id"),K0.delete("edit"),o)K0.set("expanded",o);else K0.delete("expanded");return K0}),o)setTimeout(()=>{u.current[o]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},l=YZ.useMemo(()=>{if(!q.length)return[];let o=Y.filter((K0)=>K0.fields?.state&&y.has(K0.fields.state));if(v==="unsorted"){if(k.current){let K0=k.current,q0=[...o];return q0.sort((Z0,X0)=>{let O0=K0.indexOf(Z0.id),W0=K0.indexOf(X0.id);return(O0===-1?1/0:O0)-(W0===-1?1/0:W0)}),q0}return o}let H0=[...o];return H0.sort((K0,q0)=>{if(v==="name-asc")return K0.name.localeCompare(q0.name);if(v==="name-desc")return q0.name.localeCompare(K0.name);if(v==="date-asc"||v==="date-desc"){let Z0=(O0)=>O0.createdAt?new Date(O0.createdAt).getTime():parseInt(O0.id.replace(/\D/g,""),10)||0,X0=Z0(K0)-Z0(q0);return v==="date-asc"?X0:-X0}if(v==="state-asc")return q.indexOf(K0.fields.state)-q.indexOf(q0.fields.state);if(v==="state-desc")return q.indexOf(q0.fields.state)-q.indexOf(K0.fields.state);return 0}),H0},[Y,q,v,y]),r=()=>{if(!D.trim()){S("Story name is required");return}S(null),L.mutate({name:D.trim(),store:U,state:P},{onSuccess:(o)=>{R(!1),V(""),T(Kr),K((H0)=>{let K0=new URLSearchParams(H0);return K0.delete("id"),K0.delete("edit"),K0.set("expanded",o.id),K0})},onError:(o)=>{S(o.message)}})},e=()=>{R(!1),V(""),T(Kr),S(null)},Y0=z||H,J0=G||B,B0=G?W:M;if(Y0)return v6.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(J0)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:J0.message},void 0,!1,void 0,this),v6.jsxDEV(n6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>B0(),children:[v6.jsxDEV(XO,{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(n6,{size:"sm",variant:"warning",onClick:()=>R(!0),children:[v6.jsxDEV(sQ,{className:"w-4 h-4"},void 0,!1,void 0,this),v6.jsxDEV(kH,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(tx,{children:[v6.jsxDEV(Y7,{content:NB0.find((o)=>o.key===v)?.label,children:v6.jsxDEV(ex,{asChild:!0,children:v6.jsxDEV(n6,{size:"sm",variant:"outline",children:YZ.default.createElement(NB0.find((o)=>o.key===v)?.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(rV,{align:"start",children:NB0.map((o)=>v6.jsxDEV(nV,{onClick:()=>{if(o.key==="unsorted")k.current=l.map((H0)=>H0.id);else k.current=null;$(o.key)},className:v===o.key?"bg-accent":"",children:[v6.jsxDEV(o.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),o.label]},o.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(r16,{children:[v6.jsxDEV(Y7,{content:"Filter by state",children:v6.jsxDEV(n16,{asChild:!0,children:v6.jsxDEV(n6,{size:"sm",variant:"outline",children:v6.jsxDEV(hH,{className:"w-4 h-4",...f&&{fill:"var(--primary)",stroke:"var(--primary)"}},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(UB0,{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((o)=>v6.jsxDEV("label",{className:"flex items-center gap-2",children:[v6.jsxDEV(Mk,{checked:y.has(o),onCheckedChange:()=>g(o)},void 0,!1,void 0,this),v6.jsxDEV("span",{className:"text-sm capitalize",children:o},void 0,!1,void 0,this)]},o,!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),l.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(Xb,{type:"single",collapsible:!0,value:m,onValueChange:d,children:l.map((o)=>{let H0=q.indexOf(o.fields.state),K0=H0>0?q[H0-1]:null,q0=H0<q.length-1?q[H0+1]:null;return v6.jsxDEV(Ub,{value:o.id,className:"border-b",ref:(Z0)=>{u.current[o.id]=Z0},children:[v6.jsxDEV(Yb,{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(kH,{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:o.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 ${o.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:o.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(EH8,{state:o.fields.state,states:q,onPrev:K0?()=>A.mutate({id:o.id,state:K0}):null,onNext:q0?()=>A.mutate({id:o.id,state:q0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV("div",{className:"flex justify-center",children:o.fields?.flag==="true"&&v6.jsxDEV(dE,{className:"w-4 h-4 flex-shrink-0 text-amber-500 cursor-pointer hover:text-amber-600 dark:text-amber-400 dark:hover:text-amber-300",fill:"currentColor",onClick:(Z0)=>{Z0.stopPropagation(),N.mutate({entityId:o.id,fieldName:"flag",value:"false"})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"flex justify-end",children:v6.jsxDEV(mK,{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(zb,{className:"border-t",children:v6.jsxDEV(S16,{value:_,onValueChange:h,children:[v6.jsxDEV(QB0,{variant:"line",className:"px-4",children:[v6.jsxDEV(gD,{value:"documents",children:[v6.jsxDEV(nQ,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Documents"]},void 0,!0,void 0,this),v6.jsxDEV(gD,{value:"tasks",children:[v6.jsxDEV(sY,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Tasks"]},void 0,!0,void 0,this),v6.jsxDEV(gD,{value:"prompts",children:[v6.jsxDEV(nE,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),v6.jsxDEV(gD,{value:"settings",children:[v6.jsxDEV(tY,{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(mD,{value:"documents",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(Xh,{projectId:J,rootFolderId:o.id,type:"d",DetailPanel:Nd,hooks:PH8},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(mD,{value:"tasks",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(hK6,{projectId:J,storyId:o.id,onOpenDocument:(Z0,X0)=>{K((O0)=>{let W0=new URLSearchParams(O0);if(W0.set("id",Z0),X0?.edit)W0.set("edit","true");return W0})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(mD,{value:"prompts",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(VH8,{projectId:J,storyId:o.id},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(mD,{value:"settings",children:v6.jsxDEV("div",{className:"h-[800px]",children:v6.jsxDEV(jH8,{projectId:J,story:o,onDeleted:()=>{K((Z0)=>{let X0=new URLSearchParams(Z0);return X0.delete("expanded"),X0.delete("id"),X0.delete("edit"),X0})}},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)]},o.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(lZ,{open:I,onOpenChange:e,children:v6.jsxDEV(EZ,{children:[v6.jsxDEV(VZ,{children:v6.jsxDEV(jZ,{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(z4,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),v6.jsxDEV(ZQ,{id:"name",value:D,onChange:(o)=>V(o.target.value),placeholder:"Enter story name",onKeyDown:(o)=>o.key==="Enter"&&r()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV("div",{className:"space-y-2",children:[v6.jsxDEV(z4,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),v6.jsxDEV(J5,{value:P,onValueChange:T,children:[v6.jsxDEV(RQ,{children:v6.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),v6.jsxDEV(wQ,{children:q.map((o)=>v6.jsxDEV(iJ,{value:o,children:o.charAt(0).toUpperCase()+o.slice(1)},o,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),C&&v6.jsxDEV("div",{className:"text-sm text-destructive",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v6.jsxDEV(dZ,{children:[v6.jsxDEV(n6,{variant:"outline",onClick:e,children:"Cancel"},void 0,!1,void 0,this),v6.jsxDEV(n6,{onClick:r,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 Z1=f0(P6(),1);var TK=f0(P6(),1);var p9=f0(z8(),1),TH8=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],oK6=({open:J,onOpenChange:Z,projectId:Q,onSuccess:K,initialPrompt:X=""})=>{let[U,Y]=TK.useState(""),[z,G]=TK.useState("claude"),[W,q]=TK.useState(""),[H,B]=TK.useState({type:"main",path:null}),[M,L]=TK.useState(""),[A,N]=TK.useState(""),[I,R]=TK.useState(!1),[D,V]=TK.useState({}),[P,T]=TK.useState(!1),[C,S]=TK.useState(null),[_,h]=TK.useState(null);TK.useEffect(()=>{if(X)L(X)},[X]);let{data:v,isLoading:$,error:k}=mi(J?Q:null),f=v?.worktrees??[],b=v?.isGitProject??!0,y=gi(Q),g=Id(Q),m=ui(Q),{data:u}=ID(Q,A.trim()||null),d=u?.parameters??[],l=u?.detectedVariables??[],r=A.trim().length>0,e=()=>{Y(""),G("claude"),q(""),B({type:"main",path:null}),L(X||""),N(""),S(null),h(null),V({}),T(!1)},Y0=()=>{e(),Z(!1)},J0=()=>{if(H.type==="main")return;return H.path||void 0},B0=(W0)=>{y.mutate({name:U.trim()||void 0,agent:z,model:W.trim()||void 0,prompt:M.trim(),workingDirectory:W0},{onSuccess:(P0)=>{if(Y0(),K)K(P0)},onError:(P0)=>{S(P0.message)}})},o=()=>{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:(W0)=>{B0(W0.path)},onError:(W0)=>{h(W0.message)}});else B0(J0())},H0=()=>{R(!0)},K0=(W0)=>{V(W0),g.mutate({id:A.trim(),params:W0,target:"stdout"},{onSuccess:(P0)=>{if(P0.content)L(P0.content);N(""),R(!1)},onError:(P0)=>{S(`Template render failed: ${P0.message}`),R(!1)}})},q0=r?"render":"run",Z0=q0==="run"&&!M.trim(),X0=m.isPending,O0=y.isPending||g.isPending||X0;return p9.jsxDEV(p9.Fragment,{children:[p9.jsxDEV(lZ,{open:J,onOpenChange:Y0,children:p9.jsxDEV(EZ,{className:"max-w-lg",children:[p9.jsxDEV(VZ,{children:p9.jsxDEV(jZ,{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(z4,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),p9.jsxDEV(ZQ,{id:"job-name",value:U,onChange:(W0)=>Y(W0.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(z4,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),p9.jsxDEV(J5,{value:z,onValueChange:G,children:[p9.jsxDEV(RQ,{children:p9.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(wQ,{children:TH8.map((W0)=>p9.jsxDEV(iJ,{value:W0.value,children:W0.label},W0.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(z4,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),p9.jsxDEV(ZQ,{id:"job-model",value:W,onChange:(W0)=>q(W0.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(mK,{className:"w-4 h-4"},void 0,!1,void 0,this):p9.jsxDEV(VU,{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(yi,{value:H,onChange:B,worktrees:f,isLoadingWorktrees:$,isGitProject:b,error:k,createError:_,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(z4,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),p9.jsxDEV(lW,{id:"job-prompt",value:M,onChange:(W0)=>L(W0.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(z4,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),p9.jsxDEV(ZQ,{id:"job-template",value:A,onChange:(W0)=>N(W0.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(dZ,{children:[p9.jsxDEV(n6,{variant:"outline",onClick:Y0,children:"Cancel"},void 0,!1,void 0,this),q0==="render"?p9.jsxDEV(n6,{onClick:H0,disabled:O0,children:[p9.jsxDEV(nQ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),O0?"Rendering...":"Render"]},void 0,!0,void 0,this):p9.jsxDEV(n6,{onClick:o,disabled:Z0||O0,children:[p9.jsxDEV(mX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),X0?"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(lZ,{open:I,onOpenChange:R,children:p9.jsxDEV(EZ,{className:"max-w-lg",children:[p9.jsxDEV(VZ,{children:p9.jsxDEV(jZ,{className:"flex items-center gap-2",children:[p9.jsxDEV(nQ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",lU(u?.path)," (",A,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),p9.jsxDEV(hi,{fields:d,detectedVariables:l,initialValues:D,onSubmit:K0,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 l8=f0(z8(),1),CH8=86400000,SH8=({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 l8.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)},tK6=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},$H8=(J)=>{if(J===null||J===void 0)return"-";if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},eK6=async(J)=>{if(!J)return;try{await navigator.clipboard.writeText(J),F1.success("Copied")}catch(Z){console.error("Failed to copy:",Z)}},kH8=(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},wB0=({job:J,onClick:Z,projectPath:Q})=>{let K=kH8(J.fields?.workingDirectory,Q);return l8.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:[l8.jsxDEV(SH8,{status:J.fields?.status},void 0,!1,void 0,this),l8.jsxDEV(Y7,{content:"Click to copy",children:l8.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(X)=>{X.stopPropagation(),eK6(J.id)},children:J.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),l8.jsxDEV(Y7,{content:J.fields?.sessionId||"No session ID",children:l8.jsxDEV("span",{className:"w-24 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(X)=>{if(X.stopPropagation(),J.fields?.sessionId)eK6(J.fields?.sessionId)},children:J.fields?.sessionId?J.fields?.sessionId.slice(0,8)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),l8.jsxDEV("div",{className:"flex-1 min-w-0",children:[l8.jsxDEV("span",{className:"truncate text-sm font-medium block",children:J.name},void 0,!1,void 0,this),K&&l8.jsxDEV(Y7,{content:J.fields?.workingDirectory,children:l8.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),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.agent},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.pid||"-"},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:tK6(J.fields?.startedAt)},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:tK6(J.fields?.completedAt)},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:$H8(J.fields?.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},JX6=({title:J,count:Z})=>{return l8.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[l8.jsxDEV("h3",{className:"text-sm font-semibold text-foreground",children:J},void 0,!1,void 0,this),l8.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",Z,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},vH8=({column:J,sortColumn:Z,sortDirection:Q})=>{if(Z!==J)return l8.jsxDEV(aM,{className:"w-3 h-3 ml-1 opacity-50"},void 0,!1,void 0,this);return Q==="asc"?l8.jsxDEV(oM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this):l8.jsxDEV(sM,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)},DB0=({onSort:J,sortColumn:Z,sortDirection:Q})=>{return l8.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 l8.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&&l8.jsxDEV(vH8,{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)},ZX6=["active","history"],RB0=(J,Z,Q="")=>{let K=Z?`/project/${J}/store/${Z}/jobs`:`/project/${J}/jobs`;return Q?`${K}/${Q}`:K},QX6=({active:J,onClick:Z,children:Q})=>l8.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),fH8=({activeJobs:J,completedJobs:Z,onJobClick:Q,onNewJob:K,projectPath:X,onActiveSort:U,activeSortColumn:Y,activeSortDirection:z,onCompletedSort:G,completedSortColumn:W,completedSortDirection:q})=>l8.jsxDEV("div",{className:"space-y-6",children:[l8.jsxDEV("div",{className:"flex justify-start",children:l8.jsxDEV(n6,{size:"sm",variant:"warning",onClick:K,children:[l8.jsxDEV(sQ,{className:"w-4 h-4"},void 0,!1,void 0,this),l8.jsxDEV(QO,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),l8.jsxDEV("div",{children:[l8.jsxDEV(JX6,{title:"Active Jobs",count:J.length},void 0,!1,void 0,this),J.length>0?l8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[l8.jsxDEV(DB0,{onSort:U,sortColumn:Y,sortDirection:z},void 0,!1,void 0,this),J.map((H)=>l8.jsxDEV(wB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):l8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[l8.jsxDEV(mX,{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),l8.jsxDEV("div",{children:[l8.jsxDEV(JX6,{title:"Recently Completed",count:Z.length},void 0,!1,void 0,this),Z.length>0?l8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[l8.jsxDEV(DB0,{onSort:G,sortColumn:W,sortDirection:q},void 0,!1,void 0,this),Z.map((H)=>l8.jsxDEV(wB0,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):l8.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[l8.jsxDEV(vH,{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),_H8=({completedJobs:J,onJobClick:Z,projectPath:Q,onSort:K,sortColumn:X,sortDirection:U})=>l8.jsxDEV("div",{children:J.length>0?l8.jsxDEV(l8.Fragment,{children:[l8.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),l8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[l8.jsxDEV(DB0,{onSort:K,sortColumn:X,sortDirection:U},void 0,!1,void 0,this),J.map((Y)=>l8.jsxDEV(wB0,{job:Y,onClick:Z,projectPath:Q},Y.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):l8.jsxDEV("div",{className:"text-center py-8 text-muted-foreground",children:[l8.jsxDEV(vH,{className:"w-8 h-8 mx-auto mb-2 opacity-50"},void 0,!1,void 0,this),l8.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),_k=()=>{let{id:J,storeCode:Z,tab:Q}=j5(),K=qZ(),X=cJ(),{data:U}=q1(J),Y=Q&&!ZX6.includes(Q),z=ZX6.includes(Q)?Q:"active";H1(U?`${U.name} - Jobs`:"CAW");let[G,W]=Z1.useState(!1),[q,H]=Z1.useState(""),[B,M]=Z1.useState("startedAt"),[L,A]=Z1.useState("desc"),[N,I]=Z1.useState("completedAt"),[R,D]=Z1.useState("desc"),[V,P]=Z1.useState("completedAt"),[T,C]=Z1.useState("desc"),S=Z??"A";rH(J);let{data:_=[],isLoading:h,error:v,refetch:$}=J16(J,{store:S}),k=(e)=>{return["startedAt","completedAt","tokensUsed"].includes(e)?"desc":"asc"},f=(e)=>{if(B===e)A((Y0)=>Y0==="asc"?"desc":"asc");else M(e),A(k(e))},b=(e)=>{if(N===e)D((Y0)=>Y0==="asc"?"desc":"asc");else I(e),D(k(e))},y=(e)=>{if(V===e)C((Y0)=>Y0==="asc"?"desc":"asc");else P(e),C(k(e))},g=(e,Y0,J0)=>{return[...e].sort((B0,o)=>{let H0=0;switch(Y0){case"status":let K0={running:0,completed:1,error:2};H0=(K0[B0.fields?.status]??3)-(K0[o.fields?.status]??3);break;case"name":H0=(B0.name||"").localeCompare(o.name||"");break;case"agent":H0=(B0.fields?.agent||"").localeCompare(o.fields?.agent||"");break;case"startedAt":case"completedAt":let q0=(O0)=>{if(!O0)return 0;let W0=new Date(O0).getTime();return isNaN(W0)?0:W0},Z0=q0(B0.fields?.[Y0]),X0=q0(o.fields?.[Y0]);H0=Z0-X0;break;case"tokensUsed":H0=(B0.fields?.tokensUsed??0)-(o.fields?.tokensUsed??0);break;default:H0=0}return J0==="asc"?H0:-H0})},m=Z1.useMemo(()=>{let e=_.filter((Y0)=>Y0.fields?.status==="running");return g(e,B,L)},[_,B,L]),u=Z1.useMemo(()=>{let e=Date.now()-CH8,Y0=_.filter((J0)=>J0.fields?.status==="completed"||J0.fields?.status==="error").filter((J0)=>J0.fields?.completedAt&&new Date(J0.fields?.completedAt).getTime()>e);return g(Y0,N,R)},[_,N,R]),d=Z1.useMemo(()=>{let e=_.filter((Y0)=>Y0.fields?.status==="completed"||Y0.fields?.status==="error");return g(e,V,T)},[_,V,T]),l=(e)=>{let Y0=Z?`/project/${J}/store/${Z}/job/${e.id}`:`/project/${J}/job/${e.id}`;K(Y0,{state:{fromTab:z}})},r=(e)=>{if(e&&e.id){let Y0=Z?`/project/${J}/store/${Z}/job/${e.id}`:`/project/${J}/job/${e.id}`;K(Y0,{state:{fromTab:z}})}};if(Z1.useEffect(()=>{if(X.state?.openNewJobWithPrompt)H(X.state.openNewJobWithPrompt),W(!0),K(X.pathname,{replace:!0,state:{}})},[X.state,K,X.pathname]),Z1.useEffect(()=>{if(Y)K(RB0(J,Z,"active"),{replace:!0})},[Y,K,J,Z]),Y)return null;if(h)return l8.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(v)return l8.jsxDEV("div",{className:"p-6",children:[l8.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),l8.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:v.message},void 0,!1,void 0,this),l8.jsxDEV(n6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>$(),children:[l8.jsxDEV(XO,{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 l8.jsxDEV("div",{className:"h-full flex flex-col",children:[l8.jsxDEV("div",{className:"flex border-b overflow-x-auto bg-muted/50 px-2",role:"tablist","aria-label":"Jobs tabs",children:[l8.jsxDEV(QX6,{active:z==="active",onClick:()=>K(RB0(J,Z,"active")),children:"Active"},void 0,!1,void 0,this),l8.jsxDEV(QX6,{active:z==="history",onClick:()=>K(RB0(J,Z,"history")),children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l8.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:z==="active"?l8.jsxDEV(fH8,{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):l8.jsxDEV(_H8,{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),l8.jsxDEV(oK6,{open:G,onOpenChange:(e)=>{if(W(e),!e)H("")},projectId:J,onSuccess:r,initialPrompt:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var LU=f0(P6(),1);var PB0=f0(P6(),1);var bk=f0(z8(),1),KX6=({value:J,disabled:Z=!1,className:Q=""})=>{let[K,X]=PB0.useState(!1);return bk.jsxDEV(Y7,{content:"Copy to clipboard",children:bk.jsxDEV(n6,{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?bk.jsxDEV(p1,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):bk.jsxDEV(rQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var zM=f0(P6(),1);var $1=f0(z8(),1),XX6=({open:J,onOpenChange:Z,sessionId:Q,onContinue:K,isLoading:X})=>{let[U,Y]=zM.useState(""),z=zM.useRef(null);zM.useEffect(()=>{if(!J)Y("")},[J]),zM.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 $1.jsxDEV(lZ,{open:J,onOpenChange:W,children:$1.jsxDEV(EZ,{children:[$1.jsxDEV(VZ,{children:$1.jsxDEV(jZ,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$1.jsxDEV("form",{onSubmit:G,className:"space-y-4",children:[$1.jsxDEV("div",{className:"space-y-2",children:[$1.jsxDEV(z4,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),$1.jsxDEV(ZQ,{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),$1.jsxDEV("div",{className:"space-y-2",children:[$1.jsxDEV(z4,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),$1.jsxDEV(lW,{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),$1.jsxDEV(dZ,{children:[$1.jsxDEV(n6,{type:"button",variant:"outline",onClick:W,children:"Cancel"},void 0,!1,void 0,this),$1.jsxDEV(n6,{type:"submit",disabled:q,children:[X&&$1.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),bH8=({status:J})=>{let Z={running:{icon:NJ,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:DG,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:fH,class:"text-red-700 border-red-300 bg-red-50",animate:!1},pending:{icon:cE,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)},UX6=(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"})},xH8=(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()},YX6=(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},zX6=(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},GX6=({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(mK,{className:"w-4 h-4"},void 0,!1,void 0,this):E8.jsxDEV(VU,{className:"w-4 h-4"},void 0,!1,void 0,this),E8.jsxDEV(nQ,{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),WX6=({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(GX6,{title:"Output",docId:U,isOpen:G,onToggle:W,children:E8.jsxDEV(c2,{markdown:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(GX6,{title:"Prompt",docId:X,isOpen:Y,onToggle:z,children:E8.jsxDEV(c2,{markdown:Z||""},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},hH8=86400000,EB0=()=>{let{id:J,storeCode:Z,jobId:Q}=j5(),K=qZ(),X=cJ(),{data:U}=q1(J);H1(U?`${U.name} - Job: ${Q}`:"CAW"),rH(J);let{data:Y,isLoading:z,error:G}=Z16(J,Q),{data:W,isLoading:q}=Q16(J,Q),{promptDoc:H,outputDoc:B}=LU.useMemo(()=>{if(!W)return{promptDoc:null,outputDoc:null};let H0=W.documents||[],K0=H0.find((Z0)=>Z0.name==="prompt.md"),q0=H0.find((Z0)=>Z0.name==="output.md");return{promptDoc:K0,outputDoc:q0}},[W]),{data:M}=d2(J,H?.id),{data:L}=d2(J,B?.id),A=M?.draftContent??M?.publishedContent??"",N=L?.draftContent??L?.publishedContent??"",I=LU.useMemo(()=>zX6(A),[A]),R=LU.useMemo(()=>zX6(N),[N]),D=I.length>1||R.length>1,[V,P]=LU.useState({}),T=Math.max(I.length,R.length);LU.useEffect(()=>{P((H0)=>{let K0={...H0};for(let q0=0;q0<T;q0++)if(!(q0 in K0))K0[q0]={promptOpen:!0,outputOpen:!0};return K0})},[T]);let C=()=>{P((H0)=>{let K0={};for(let q0 of Object.keys(H0))K0[q0]={promptOpen:!1,outputOpen:!1};return K0})},S=()=>{P((H0)=>{let K0={};for(let q0 of Object.keys(H0))K0[q0]={promptOpen:!0,outputOpen:!0};return K0})},_=async()=>{try{await navigator.clipboard.writeText(Q),F1.success("ID copied")}catch(H0){console.error("Failed to copy ID:",H0)}},h=(H0)=>{if(!H0)return"active";if(H0.fields?.status==="running")return"active";if(H0.fields?.completedAt){let K0=new Date(H0.fields?.completedAt).getTime(),q0=Date.now()-hH8;if(K0>q0)return"active"}return"history"},v=()=>{let H0=X.state?.fromTab||h(Y),K0=Z?`/project/${J}/store/${Z}/jobs/${H0}`:`/project/${J}/jobs/${H0}`;K(K0)},[$,k]=LU.useState(!1),f=K16(J,Q),b=(Y?.fields?.status==="completed"||Y?.fields?.status==="error")&&Y?.fields?.sessionId,y=async(H0)=>{await f.mutateAsync({prompt:H0}),k(!1)},[g,m]=LU.useState(!1),[u,d]=LU.useState(""),[l,r]=LU.useState(null),e=X16(J),Y0=()=>{d(Y.name),r(null),m(!0)},J0=async()=>{let H0=u.trim();if(!H0||H0===Y.name){m(!1),r(null);return}try{await e.mutateAsync({id:Q,name:H0}),m(!1),r(null)}catch(K0){let q0=K0?.message||"Failed to rename job";r(q0)}},B0=(H0)=>{if(H0.key==="Enter")H0.preventDefault(),J0();if(H0.key==="Escape")m(!1),r(null)},o=(H0)=>{if(d(H0.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(n6,{variant:"outline",className:"mt-4",onClick:v,children:[E8.jsxDEV(yA,{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(n6,{variant:"ghost",size:"sm",onClick:v,children:E8.jsxDEV(yA,{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:o,onBlur:J0,onKeyDown:B0,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(n6,{variant:"ghost",size:"sm",onClick:Y0,children:E8.jsxDEV(G1,{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(bH8,{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),UX6(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),UX6(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),xH8(Y.tokensUsed)]},void 0,!0,void 0,this),YX6(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),YX6(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.fields?.sessionId||"-"},void 0,!1,void 0,this),E8.jsxDEV(KX6,{value:Y.fields?.sessionId||"",disabled:!Y.fields?.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(n6,{variant:"default",size:"sm",onClick:()=>k(!0),children:[E8.jsxDEV(sE,{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(n6,{variant:"outline",size:"sm",onClick:_,children:[E8.jsxDEV(rQ,{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(n6,{variant:"outline",size:"sm",onClick:C,children:"Collapse All"},void 0,!1,void 0,this),E8.jsxDEV(n6,{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((H0,K0,q0)=>{let Z0=q0.length-1-K0,X0=I[Z0],O0=R[Z0],W0=X0?.turnNumber??O0?.turnNumber??Z0+1;return E8.jsxDEV(WX6,{turnNumber:W0,promptContent:X0?.content,outputContent:O0?.content,showHeading:!0,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[Z0]?.promptOpen??!0,setIsPromptOpen:(P0)=>P((F0)=>({...F0,[Z0]:{...F0[Z0],promptOpen:P0}})),isOutputOpen:V[Z0]?.outputOpen??!0,setIsOutputOpen:(P0)=>P((F0)=>({...F0,[Z0]:{...F0[Z0],outputOpen:P0}}))},Z0,!1,void 0,this)}):E8.jsxDEV(WX6,{turnNumber:1,promptContent:I[0]?.content,outputContent:R[0]?.content,showHeading:!1,promptDocId:H?.id,outputDocId:B?.id,isPromptOpen:V[0]?.promptOpen??!0,setIsPromptOpen:(H0)=>P((K0)=>({...K0,[0]:{...K0[0],promptOpen:H0}})),isOutputOpen:V[0]?.outputOpen??!0,setIsOutputOpen:(H0)=>P((K0)=>({...K0,[0]:{...K0[0],outputOpen:H0}}))},void 0,!1,void 0,this)},void 0,!1,void 0,this),E8.jsxDEV(XX6,{open:$,onOpenChange:k,sessionId:Y.fields?.sessionId,onContinue:y,isLoading:f.isPending},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var CK=f0(P6(),1);var S3=f0(P6(),1);var $3=f0(z8(),1),Xr=S3.default.forwardRef(({className:J,...Z},Q)=>$3.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));Xr.displayName="Card";var yH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("div",{ref:Q,className:k8("flex flex-col space-y-1.5 p-6",J),...Z},void 0,!1,void 0,this));yH8.displayName="CardHeader";var gH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("h3",{ref:Q,className:k8("text-2xl font-semibold leading-none tracking-tight",J),...Z},void 0,!1,void 0,this));gH8.displayName="CardTitle";var mH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("p",{ref:Q,className:k8("text-sm text-muted-foreground",J),...Z},void 0,!1,void 0,this));mH8.displayName="CardDescription";var Ur=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("div",{ref:Q,className:k8("p-6 pt-0",J),...Z},void 0,!1,void 0,this));Ur.displayName="CardContent";var uH8=S3.default.forwardRef(({className:J,...Z},Q)=>$3.jsxDEV("div",{ref:Q,className:k8("flex items-center p-6 pt-0",J),...Z},void 0,!1,void 0,this));uH8.displayName="CardFooter";var Yr="",zr=()=>({"Content-Type":"application/json","X-Session-Id":lJ()}),qX6=async(J)=>{let Z=await fetch(`${Yr}/api/p/${J}/export/preview`,{headers:zr()});return P9(Z,"Failed to get export preview")},HX6=async(J)=>{let Z=await fetch(`${Yr}/api/p/${J}/exports`,{headers:zr()});return P9(Z,"Failed to get exports")},BX6=async(J)=>{let Z=await fetch(`${Yr}/api/p/${J}/export`,{method:"POST",headers:zr(),body:JSON.stringify({confirm:!0})});return P9(Z,"Failed to export documents")},FX6=async(J,Z)=>{let Q=await fetch(`${Yr}/api/p/${J}/import`,{method:"POST",headers:zr(),body:JSON.stringify({filename:Z})});return P9(Q,"Failed to import documents")};var l6=f0(z8(),1),MX6=()=>{let{id:J}=j5(),{data:Z,isLoading:Q}=q1(J),[K,X]=CK.useState(!1),[U,Y]=CK.useState(null),[z,G]=CK.useState(!1),[W,q]=CK.useState(null),[H,B]=CK.useState(!1),[M,L]=CK.useState(null),[A,N]=CK.useState(null),[I,R]=CK.useState(!1),[D,V]=CK.useState(!1),[P,T]=CK.useState(null),[C,S]=CK.useState(null),[_,h]=CK.useState([]),[v,$]=CK.useState("");H1(Z?`${Z.name} - Settings`:"CAW");let k=async(r,e)=>{if(Y(null),!navigator.clipboard?.writeText){Y("Clipboard not available");return}try{await navigator.clipboard.writeText(r),e(!0),setTimeout(()=>e(!1),2000)}catch(Y0){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 qX6(Z.objectId);q(r)}catch(r){L(r.message)}finally{B(!1)}},g=async()=>{B(!0),L(null);try{let r=await BX6(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 HX6(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(!v){T("Please select an export file");return}V(!0),T(null);try{let r=await FX6(Z.objectId,v);S(r)}catch(r){T(r.message)}finally{V(!1)}},l=()=>{R(!1),S(null),T(null)};if(Q)return l6.jsxDEV("div",{className:"p-6",children:l6.jsxDEV("p",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(!Z)return l6.jsxDEV("div",{className:"p-6",children:l6.jsxDEV("p",{className:"text-muted-foreground",children:"Project not found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return l6.jsxDEV("div",{className:"p-6",children:[l6.jsxDEV("h2",{className:"text-2xl font-bold text-foreground mb-6",children:"Project Settings"},void 0,!1,void 0,this),l6.jsxDEV("div",{className:"max-w-2xl space-y-6",children:[l6.jsxDEV(Xr,{children:l6.jsxDEV(Ur,{className:"pt-6 space-y-6",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Project Name"},void 0,!1,void 0,this),l6.jsxDEV("p",{className:"text-foreground mt-1",children:Z.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Path"},void 0,!1,void 0,this),l6.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),l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Add to Claude Code"},void 0,!1,void 0,this),l6.jsxDEV("div",{className:"flex items-start gap-2 mt-1",children:[l6.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),l6.jsxDEV(n6,{variant:"outline",size:"icon",onClick:b,className:"shrink-0",children:K?l6.jsxDEV(p1,{className:"w-4 h-4"},void 0,!1,void 0,this):l6.jsxDEV(rQ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&l6.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),l6.jsxDEV(Xr,{children:l6.jsxDEV(Ur,{className:"pt-6",children:l6.jsxDEV("div",{className:"flex items-start justify-between",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"PROJECT STORE (A)"},void 0,!1,void 0,this),l6.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),l6.jsxDEV("div",{className:"flex gap-2",children:[l6.jsxDEV(n6,{onClick:y,size:"sm",children:[l6.jsxDEV(lE,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Export"]},void 0,!0,void 0,this),l6.jsxDEV(n6,{onClick:u,variant:"outline",size:"sm",children:[l6.jsxDEV(jG,{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),l6.jsxDEV(lZ,{open:z,onOpenChange:G,children:l6.jsxDEV(EZ,{children:[l6.jsxDEV(VZ,{children:[l6.jsxDEV(jZ,{children:A?"Export Complete":"Export Preview"},void 0,!1,void 0,this),l6.jsxDEV(lx,{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&&l6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:l6.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&&l6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[l6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),l6.jsxDEV("span",{className:"text-sm",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W?.toExport&&W?.draftOnly&&!A&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Will be exported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[l6.jsxDEV("li",{children:[W.toExport.documents.length," documents"]},void 0,!0,void 0,this),l6.jsxDEV("li",{children:[W.toExport.templates.length," templates"]},void 0,!0,void 0,this),l6.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)&&l6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:l6.jsxDEV("div",{className:"flex items-start gap-2",children:[l6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),l6.jsxDEV("div",{children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Draft-only items will NOT be exported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[W.draftOnly.documents.length>0&&l6.jsxDEV("li",{children:[W.draftOnly.documents.length," documents",W.draftOnly.documents.length<=3&&l6.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&&l6.jsxDEV("li",{children:[W.draftOnly.templates.length," templates",W.draftOnly.templates.length<=3&&l6.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&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Exported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[l6.jsxDEV("li",{children:[A.counts.documents," documents"]},void 0,!0,void 0,this),l6.jsxDEV("li",{children:[A.counts.templates," templates"]},void 0,!0,void 0,this),l6.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),l6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Saved to: ",l6.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),l6.jsxDEV(dZ,{children:!A?l6.jsxDEV(l6.Fragment,{children:[l6.jsxDEV(n6,{variant:"outline",onClick:m,children:"Cancel"},void 0,!1,void 0,this),l6.jsxDEV(n6,{onClick:g,disabled:H||!W,children:H?l6.jsxDEV(l6.Fragment,{children:[l6.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):l6.jsxDEV(n6,{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),l6.jsxDEV(lZ,{open:I,onOpenChange:R,children:l6.jsxDEV(EZ,{children:[l6.jsxDEV(VZ,{children:[l6.jsxDEV(jZ,{children:C?"Import Complete":"Import from .caw-exports/"},void 0,!1,void 0,this),l6.jsxDEV(lx,{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&&l6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[l6.jsxDEV(S7,{className:"w-4 h-4"},void 0,!1,void 0,this),l6.jsxDEV("span",{className:"text-sm",children:P},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D&&_.length===0&&!P&&l6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:l6.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&&_.length===0&&!P&&l6.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&&_.length>0&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{children:[l6.jsxDEV("label",{className:"text-sm font-medium text-foreground block mb-2",children:"Select export file:"},void 0,!1,void 0,this),l6.jsxDEV(J5,{value:v,onValueChange:$,children:[l6.jsxDEV(RQ,{children:l6.jsxDEV(Z5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),l6.jsxDEV(wQ,{children:_.map((r)=>l6.jsxDEV(iJ,{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),l6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:l6.jsxDEV("div",{className:"flex items-start gap-2",children:[l6.jsxDEV(S7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),l6.jsxDEV("div",{children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Important:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[l6.jsxDEV("li",{children:"The store must be empty before importing"},void 0,!1,void 0,this),l6.jsxDEV("li",{children:"Entity IDs will be remapped to new values"},void 0,!1,void 0,this),l6.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&&l6.jsxDEV("div",{className:"space-y-4",children:[l6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[l6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Imported:"},void 0,!1,void 0,this),l6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[l6.jsxDEV("li",{children:[C.counts.documents," documents"]},void 0,!0,void 0,this),l6.jsxDEV("li",{children:[C.counts.templates," templates"]},void 0,!0,void 0,this),l6.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&&l6.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),l6.jsxDEV(dZ,{children:!C?l6.jsxDEV(l6.Fragment,{children:[l6.jsxDEV(n6,{variant:"outline",onClick:l,children:"Cancel"},void 0,!1,void 0,this),l6.jsxDEV(n6,{onClick:d,disabled:D||!v,children:D?l6.jsxDEV(l6.Fragment,{children:[l6.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):l6.jsxDEV(n6,{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 pH8=f0(P6(),1);var GM=f0(z8(),1),Gr=()=>{let J=cJ(),Z=qZ();return GM.jsxDEV("div",{className:"flex items-center justify-center h-full",children:GM.jsxDEV("div",{className:"text-center max-w-md px-4",children:[GM.jsxDEV(S7,{className:"w-16 h-16 text-muted-foreground/50 mx-auto mb-4"},void 0,!1,void 0,this),GM.jsxDEV("h2",{className:"text-2xl font-semibold text-foreground mb-2",children:"Page Not Found"},void 0,!1,void 0,this),GM.jsxDEV("p",{className:"text-muted-foreground mb-4",children:["The path ",GM.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),GM.jsxDEV(n6,{onClick:()=>Z("/"),children:"Go Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var JH=f0(z8(),1),OX6=()=>{let{theme:J,toggleTheme:Z}=D_(),Q=J==="dark";return JH.jsxDEV("div",{className:"flex items-center justify-between",children:[JH.jsxDEV("div",{children:[JH.jsxDEV("div",{className:"font-medium text-foreground",children:"Theme"},void 0,!1,void 0,this),JH.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),JH.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:JH.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?JH.jsxDEV(aE,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this):JH.jsxDEV(oE,{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 oz=f0(z8(),1),LX6=()=>{return H1("CAW - Preferences"),oz.jsxDEV("div",{className:"flex-1 p-6",children:[oz.jsxDEV("div",{className:"mb-6",children:oz.jsxDEV("div",{className:"flex items-center gap-3",children:[oz.jsxDEV(tY,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this),oz.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),oz.jsxDEV("div",{className:"max-w-2xl",children:oz.jsxDEV("section",{className:"mb-8",children:[oz.jsxDEV("h2",{className:"text-lg font-medium text-foreground mb-4",children:"Appearance"},void 0,!1,void 0,this),oz.jsxDEV("div",{className:"bg-card border border-border rounded-lg p-4",children:oz.jsxDEV(OX6,{},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 NX6=f0(z8(),1),AX6=(J)=>NX6.jsxDEV(BT0,{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),lH8=()=>{return b9.jsxDEV(xo,{children:b9.jsxDEV(oo,{client:rA0,children:[b9.jsxDEV(fo,{children:b9.jsxDEV(B4,{element:b9.jsxDEV(Kw0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(B4,{index:!0,element:b9.jsxDEV(zw0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"preferences",element:b9.jsxDEV(LX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"project/:id",element:b9.jsxDEV(Yw0,{},void 0,!1,void 0,this),children:[b9.jsxDEV(B4,{index:!0,element:b9.jsxDEV(ef,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"documents/*",element:b9.jsxDEV(hz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"templates/*",element:b9.jsxDEV(JB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"stories",element:b9.jsxDEV(IB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs/:tab",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"job/:jobId",element:b9.jsxDEV(EB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"settings",element:b9.jsxDEV(MX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"store/:storeCode",children:[b9.jsxDEV(B4,{index:!0,element:b9.jsxDEV(ef,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"documents/*",element:b9.jsxDEV(hz0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"templates/*",element:b9.jsxDEV(JB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"stories",element:b9.jsxDEV(IB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"jobs/:tab",element:b9.jsxDEV(_k,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"job/:jobId",element:b9.jsxDEV(EB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(B4,{path:"*",element:b9.jsxDEV(Gr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(B4,{path:"*",element:b9.jsxDEV(Gr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(B4,{path:"*",element:b9.jsxDEV(Gr,{},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(AX6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},IX6=lH8;var VB0=f0(z8(),1),DX6=document.getElementById("root");if(!DX6)throw Error("Root element not found");var dH8=wX6.createRoot(DX6);dH8.render(VB0.jsxDEV(RX6.default.StrictMode,{children:VB0.jsxDEV(IX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this));
|