@kelceyp/caw-server 1.0.16 → 1.0.17

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.
@@ -3080,7 +3080,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
3080
3080
  monaco.config({ paths: { vs: '...' } })
3081
3081
 
3082
3082
  For more please check the link https://github.com/suren-atoyan/monaco-loader#config
3083
- `},Ck0=jk0(xk6)(Sk0),$k0={config:_k6};var kk0=function(){for(var Z=arguments.length,Q=Array(Z),K=0;K<Z;K++)Q[K]=arguments[K];return function(X){return Q.reduceRight(function(U,Y){return Y(U)},X)}};function w60(J,Z){return Object.keys(Z).forEach(function(Q){if(Z[Q]instanceof Object){if(J[Q])Object.assign(Z[Q],w60(J[Q],Z[Q]))}}),R60(R60({},J),Z)}var hk6={type:"cancelation",msg:"operation is manually canceled"};function Th(J){var Z=!1,Q=new Promise(function(K,X){J.then(function(U){return Z?X(hk6):K(U)}),J.catch(X)});return Q.cancel=function(){return Z=!0},Q}var yk6=["monaco"],gk6=Ek0.create({config:Vk0,isInitialized:!1,resolve:null,reject:null,monaco:null}),vk0=Ik0(gk6,2),Rj=vk0[0],Ch=vk0[1];function mk6(J){var Z=$k0.config(J),Q=Z.monaco,K=wk0(Z,yk6);Ch(function(X){return{config:w60(X.config,K),monaco:Q}})}function uk6(){var J=Rj(function(Z){var{monaco:Q,isInitialized:K,resolve:X}=Z;return{monaco:Q,isInitialized:K,resolve:X}});if(!J.isInitialized){if(Ch({isInitialized:!0}),J.monaco)return J.resolve(J.monaco),Th(I60);if(window.monaco&&window.monaco.editor)return fk0(window.monaco),J.resolve(window.monaco),Th(I60);kk0(pk6,lk6)(dk6)}return Th(I60)}function pk6(J){return document.body.appendChild(J)}function ck6(J){var Z=document.createElement("script");return J&&(Z.src=J),Z}function lk6(J){var Z=Rj(function(K){var{config:X,reject:U}=K;return{config:X,reject:U}}),Q=ck6("".concat(Z.config.paths.vs,"/loader.js"));return Q.onload=function(){return J()},Q.onerror=Z.reject,Q}function dk6(){var J=Rj(function(Q){var{config:K,resolve:X,reject:U}=Q;return{config:K,resolve:X,reject:U}}),Z=window.require;Z.config(J.config),Z(["vs/editor/editor.main"],function(Q){var K=Q.m||Q;fk0(K),J.resolve(K)},function(Q){J.reject(Q)})}function fk0(J){if(!Rj().monaco)Ch({monaco:J})}function ik6(){return Rj(function(J){var Z=J.monaco;return Z})}var I60=new Promise(function(J,Z){return Ch({resolve:J,reject:Z})}),eO={config:mk6,init:uk6,__getMonacoInstance:ik6};var _k0=f0(D6(),1),H5=f0(D6(),1);var bk0=f0(D6(),1),$h=f0(D6(),1),xk0=f0(D6(),1),yk0=f0(D6(),1),kh=f0(D6(),1),zv6=f0(D6(),1);var uk0=f0(D6(),1),EZ=f0(D6(),1);var vh=f0(D6(),1),rk6={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},P60=rk6,nk6={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},sk6=nk6;function ak6({children:J}){return xk0.default.createElement("div",{style:sk6.container},J)}var ok6=ak6,tk6=ok6;function ek6({width:J,height:Z,isEditorReady:Q,loading:K,_ref:X,className:U,wrapperProps:Y}){return $h.default.createElement("section",{style:{...P60.wrapper,width:J,height:Z},...Y},!Q&&$h.default.createElement(tk6,null,K),$h.default.createElement("div",{ref:X,style:{...P60.fullWidth,...!Q&&P60.hide},className:U}))}var Jv6=ek6,hk0=bk0.memo(Jv6);function Zv6(J){yk0.useEffect(J,[])}var gk0=Zv6;function Qv6(J,Z,Q=!0){let K=kh.useRef(!0);kh.useEffect(K.current||!Q?()=>{K.current=!1}:J,Z)}var QU=Qv6;function wj(){}function YR(J,Z,Q,K){return Kv6(J,K)||Xv6(J,Z,Q,K)}function Kv6(J,Z){return J.editor.getModel(mk0(J,Z))}function Xv6(J,Z,Q,K){return J.editor.createModel(Z,Q,K?mk0(J,K):void 0)}function mk0(J,Z){return J.Uri.parse(Z)}function Uv6({original:J,modified:Z,language:Q,originalLanguage:K,modifiedLanguage:X,originalModelPath:U,modifiedModelPath:Y,keepCurrentOriginalModel:z=!1,keepCurrentModifiedModel:G=!1,theme:W="light",loading:q="Loading...",options:H={},height:B="100%",width:M="100%",className:O,wrapperProps:A={},beforeMount:N=wj,onMount:R=wj}){let[w,P]=H5.useState(!1),[V,D]=H5.useState(!0),T=H5.useRef(null),C=H5.useRef(null),S=H5.useRef(null),f=H5.useRef(R),h=H5.useRef(N),k=H5.useRef(!1);gk0(()=>{let b=eO.init();return b.then((x)=>(C.current=x)&&D(!1)).catch((x)=>x?.type!=="cancelation"&&console.error("Monaco initialization: error:",x)),()=>T.current?_():b.cancel()}),QU(()=>{if(T.current&&C.current){let b=T.current.getOriginalEditor(),x=YR(C.current,J||"",K||Q||"text",U||"");x!==b.getModel()&&b.setModel(x)}},[U],w),QU(()=>{if(T.current&&C.current){let b=T.current.getModifiedEditor(),x=YR(C.current,Z||"",X||Q||"text",Y||"");x!==b.getModel()&&b.setModel(x)}},[Y],w),QU(()=>{let b=T.current.getModifiedEditor();b.getOption(C.current.editor.EditorOption.readOnly)?b.setValue(Z||""):Z!==b.getValue()&&(b.executeEdits("",[{range:b.getModel().getFullModelRange(),text:Z||"",forceMoveMarkers:!0}]),b.pushUndoStop())},[Z],w),QU(()=>{T.current?.getModel()?.original.setValue(J||"")},[J],w),QU(()=>{let{original:b,modified:x}=T.current.getModel();C.current.editor.setModelLanguage(b,K||Q||"text"),C.current.editor.setModelLanguage(x,X||Q||"text")},[Q,K,X],w),QU(()=>{C.current?.editor.setTheme(W)},[W],w),QU(()=>{T.current?.updateOptions(H)},[H],w);let $=H5.useCallback(()=>{if(!C.current)return;h.current(C.current);let b=YR(C.current,J||"",K||Q||"text",U||""),x=YR(C.current,Z||"",X||Q||"text",Y||"");T.current?.setModel({original:b,modified:x})},[Q,Z,X,J,K,U,Y]),v=H5.useCallback(()=>{!k.current&&S.current&&(T.current=C.current.editor.createDiffEditor(S.current,{automaticLayout:!0,...H}),$(),C.current?.editor.setTheme(W),P(!0),k.current=!0)},[H,W,$]);H5.useEffect(()=>{w&&f.current(T.current,C.current)},[w]),H5.useEffect(()=>{!V&&!w&&v()},[V,w,v]);function _(){let b=T.current?.getModel();z||b?.original?.dispose(),G||b?.modified?.dispose(),T.current?.dispose()}return H5.default.createElement(hk0,{width:M,height:B,isEditorReady:w,loading:q,_ref:S,className:O,wrapperProps:A})}var Yv6=Uv6,gd8=_k0.memo(Yv6);function Gv6(J){let Z=vh.useRef();return vh.useEffect(()=>{Z.current=J},[J]),Z.current}var Wv6=Gv6,Sh=new Map;function qv6({defaultValue:J,defaultLanguage:Z,defaultPath:Q,value:K,language:X,path:U,theme:Y="light",line:z,loading:G="Loading...",options:W={},overrideServices:q={},saveViewState:H=!0,keepCurrentModel:B=!1,width:M="100%",height:O="100%",className:A,wrapperProps:N={},beforeMount:R=wj,onMount:w=wj,onChange:P,onValidate:V=wj}){let[D,T]=EZ.useState(!1),[C,S]=EZ.useState(!0),f=EZ.useRef(null),h=EZ.useRef(null),k=EZ.useRef(null),$=EZ.useRef(w),v=EZ.useRef(R),_=EZ.useRef(),b=EZ.useRef(K),x=Wv6(U),m=EZ.useRef(!1),g=EZ.useRef(!1);gk0(()=>{let l=eO.init();return l.then((r)=>(f.current=r)&&S(!1)).catch((r)=>r?.type!=="cancelation"&&console.error("Monaco initialization: error:",r)),()=>h.current?d():l.cancel()}),QU(()=>{let l=YR(f.current,J||K||"",Z||X||"",U||Q||"");l!==h.current?.getModel()&&(H&&Sh.set(x,h.current?.saveViewState()),h.current?.setModel(l),H&&h.current?.restoreViewState(Sh.get(U)))},[U],D),QU(()=>{h.current?.updateOptions(W)},[W],D),QU(()=>{!h.current||K===void 0||(h.current.getOption(f.current.editor.EditorOption.readOnly)?h.current.setValue(K):K!==h.current.getValue()&&(g.current=!0,h.current.executeEdits("",[{range:h.current.getModel().getFullModelRange(),text:K,forceMoveMarkers:!0}]),h.current.pushUndoStop(),g.current=!1))},[K],D),QU(()=>{let l=h.current?.getModel();l&&X&&f.current?.editor.setModelLanguage(l,X)},[X],D),QU(()=>{z!==void 0&&h.current?.revealLine(z)},[z],D),QU(()=>{f.current?.editor.setTheme(Y)},[Y],D);let u=EZ.useCallback(()=>{if(!(!k.current||!f.current)&&!m.current){v.current(f.current);let l=U||Q,r=YR(f.current,K||J||"",Z||X||"",l||"");h.current=f.current?.editor.create(k.current,{model:r,automaticLayout:!0,...W},q),H&&h.current.restoreViewState(Sh.get(l)),f.current.editor.setTheme(Y),z!==void 0&&h.current.revealLine(z),T(!0),m.current=!0}},[J,Z,Q,K,X,U,W,q,H,Y,z]);EZ.useEffect(()=>{D&&$.current(h.current,f.current)},[D]),EZ.useEffect(()=>{!C&&!D&&u()},[C,D,u]),b.current=K,EZ.useEffect(()=>{D&&P&&(_.current?.dispose(),_.current=h.current?.onDidChangeModelContent((l)=>{g.current||P(h.current.getValue(),l)}))},[D,P]),EZ.useEffect(()=>{if(D){let l=f.current.editor.onDidChangeMarkers((r)=>{let o=h.current.getModel()?.uri;if(o&&r.find((Y0)=>Y0.path===o.path)){let Y0=f.current.editor.getModelMarkers({resource:o});V?.(Y0)}});return()=>{l?.dispose()}}return()=>{}},[D,V]);function d(){_.current?.dispose(),B?H&&Sh.set(U,h.current.saveViewState()):h.current.getModel()?.dispose(),h.current.dispose()}return EZ.default.createElement(hk0,{width:M,height:O,isEditorReady:D,loading:G,_ref:k,className:A,wrapperProps:N})}var Hv6=qv6,Bv6=uk0.memo(Hv6),pk0=Bv6;var Fv6="",Mv6=["image/png","image/jpeg","image/gif","image/webp"],Ov6=10485760,ck0=async(J,Z,Q="A",K,X={})=>{let U=new FormData;if(U.append("file",Z),X.widthPx!==void 0)U.append("widthPx",X.widthPx);if(X.heightPx!==void 0)U.append("heightPx",X.heightPx);if(X.displayWidth!==void 0)U.append("displayWidth",X.displayWidth);if(X.displayHeight!==void 0)U.append("displayHeight",X.displayHeight);let Y=await fetch(`${Fv6}/api/p/${J}/assets?store=${Q}`,{method:"POST",headers:{"X-Session-Id":o4()},body:U,signal:K});return P9(Y,"Failed to upload asset")};var lk0=(J)=>{if(!Mv6.includes(J.type))return{valid:!1,error:`Unsupported image type: ${J.type}`};if(J.size>Ov6)return{valid:!1,error:`File too large: ${(J.size/1048576).toFixed(1)}MB. Maximum: 10MB`};return{valid:!0}};var D60=f0(e6(),1),Lv6=()=>crypto.randomUUID(),Av6=(J)=>{if(!J)return"markdown";let Z=J.toLowerCase();if(Z.endsWith(".md")||Z.endsWith(".markdown"))return"markdown";if(Z.endsWith(".json"))return"json";if(Z.endsWith(".ts"))return"typescript";if(Z.endsWith(".tsx"))return"typescript";if(Z.endsWith(".js"))return"javascript";if(Z.endsWith(".jsx"))return"javascript";if(Z.endsWith(".yml")||Z.endsWith(".yaml"))return"yaml";if(Z.endsWith(".html"))return"html";if(Z.endsWith(".css"))return"css";if(Z.endsWith(".mmd"))return"plaintext";if(Z.endsWith(".txt"))return"plaintext";return"markdown"},Ij=JJ.memo(({value:J,onChange:Z,onBlur:Q,path:K="",height:X="100%",className:U="",debounceMs:Y=0,autoFocus:z=!0,projectId:G,storeCode:W})=>{let q=JJ.useMemo(()=>Av6(K),[K]),H=JJ.useRef(null),{theme:B}=u_(),M=B==="dark"?"caw-dark":"caw-light",O=JJ.useRef(Z);O.current=Z;let A=JJ.useRef(Q);A.current=Q;let N=JJ.useRef(null),R=JJ.useRef(null),w=JJ.useRef(null),P=JJ.useRef(null),V=JJ.useRef(null),[D,T]=JJ.useState(!1),C=JJ.useRef(null),S=JJ.useRef(K);JJ.useEffect(()=>{return()=>{if(N.current)clearTimeout(N.current);if(H.current?._blurDisposable)H.current._blurDisposable.dispose()}},[]),JJ.useEffect(()=>{if(K!==S.current)C.current=null,S.current=K},[K]);let f=JJ.useCallback((m)=>{R.current=m,m.editor.defineTheme("caw-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#f9f8f6"}}),m.editor.defineTheme("caw-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#3c3c3e"}})},[]),h=JJ.useCallback((m)=>{if(H.current=m,T(!0),z)m.focus(),m.setPosition({lineNumber:1,column:1});let g=m.onDidBlurEditorWidget(()=>{if(A.current)A.current()});H.current._blurDisposable=g},[z]),k=JJ.useCallback((m)=>{let g=m??"";if(C.current=g,!Y||Y<=0){if(O.current)O.current(g);return}if(N.current)clearTimeout(N.current);N.current=setTimeout(()=>{if(O.current)O.current(g)},Y)},[Y]),$=JJ.useCallback(()=>{if(!H.current||!Z)return;let m=H.current.getModel();if(m)Z(m.getValue())},[Z]),v=JJ.useCallback(async(m)=>{if(!G||!R.current)return;let g=m.clipboardData?.items;if(!g)return;for(let u of g)if(u.type.startsWith("image/")){m.preventDefault();let d=u.getAsFile();if(!d)continue;let l=lk0(d);if(!l.valid){console.warn(`Image upload validation failed: ${l.error}`);let K0=H.current;if(K0){let O0=K0.getPosition(),J0=`<!-- Upload rejected: ${l.error} -->`;K0.executeEdits("paste-image-validation",[{range:new R.current.Range(O0.lineNumber,O0.column,O0.lineNumber,O0.column),text:J0}]),$()}continue}let r=H.current;if(!r)continue;let o=r.getPosition();P.current=o;let Y0,e,B0,Q0;try{let K0=await createImageBitmap(d);Y0=K0.width,e=K0.height,K0.close();let O0=window.devicePixelRatio||1;B0=Math.round(Y0/O0),Q0=Math.round(e/O0)}catch(K0){console.warn("[CAW Paste] Could not get image dimensions:",K0)}let W0=`![Uploading...](caw-upload:${Lv6()})`,H0=r.getPosition();r.executeEdits("paste-image",[{range:new R.current.Range(H0.lineNumber,H0.column,H0.lineNumber,H0.column),text:W0}]),$();let U0=new AbortController;w.current=U0;try{let K0=await ck0(G,d,W||"A",U0.signal,{widthPx:Y0,heightPx:e,displayWidth:B0,displayHeight:Q0});if(U0.signal.aborted)return;let O0=(K0.originalFilename||"image").replace(/"/g,"&quot;"),J0=K0.displayWidth&&K0.displayHeight?`<img src="/api/p/${G}/assets/${K0.id}/binary?h=${K0.hash}" alt="${O0}" width="${K0.displayWidth}" height="${K0.displayHeight}">`:`![${O0}](/api/p/${G}/assets/${K0.id}/binary?h=${K0.hash})`,j0=r.getModel();if(!j0)return;let v0=j0.getValue().indexOf(W0);if(v0>=0){let Z0=j0.getPositionAt(v0),e0=j0.getPositionAt(v0+W0.length);r.executeEdits("paste-image-complete",[{range:new R.current.Range(Z0.lineNumber,Z0.column,e0.lineNumber,e0.column),text:J0}])}else{let Z0=P.current||r.getPosition();r.executeEdits("paste-image-fallback",[{range:new R.current.Range(Z0.lineNumber,Z0.column,Z0.lineNumber,Z0.column),text:J0}])}$()}catch(K0){if(K0.name==="AbortError")return;let O0=r.getModel();if(!O0)return;let j0=O0.getValue().indexOf(W0),q0=`<!-- Upload failed: ${K0.message} -->`;if(j0>=0){let v0=O0.getPositionAt(j0),Z0=O0.getPositionAt(j0+W0.length);r.executeEdits("paste-image-error",[{range:new R.current.Range(v0.lineNumber,v0.column,Z0.lineNumber,Z0.column),text:q0}])}$(),console.error("Image upload failed:",K0)}finally{w.current=null,P.current=null}return}},[G,W,$]);V.current=v,JJ.useEffect(()=>{let m=H.current;if(!D||!m)return;let g=m.hasTextFocus(),u=m.onDidFocusEditorText(()=>{g=!0}),d=m.onDidBlurEditorText(()=>{g=!1}),l=(r)=>{if(!g)return;V.current?.(r)};return document.addEventListener("paste",l,!0),()=>{if(u.dispose(),d.dispose(),document.removeEventListener("paste",l,!0),w.current)w.current.abort()}},[D]);let _=J===C.current&&K===S.current,b=X==="100%"?void 0:{height:X},x=X==="100%"?`h-full rounded-md overflow-hidden border border-border ${U}`:`rounded-md overflow-hidden border border-border ${U}`;return D60.jsxDEV("div",{className:x,style:b,children:D60.jsxDEV(pk0,{height:"100%",language:q,path:K,value:_?void 0:J,defaultValue:J,onChange:k,beforeMount:f,onMount:h,theme:M,options:{fontSize:14,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",minimap:{enabled:!1},smoothScrolling:!0,scrollBeyondLastLine:!1,automaticLayout:!0,wordWrap:"on",lineNumbers:"on",padding:{top:12,bottom:12},cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",multiCursorModifier:"ctrlCmd",stickyScroll:{enabled:!0},overviewRulerLanes:0,hideCursorInOverviewRuler:!0,glyphMargin:!1,renderWhitespace:"boundary",lineDecorationsWidth:0,quickSuggestions:!1,wordBasedSuggestions:"off",suggestOnTriggerCharacters:!1,inlineSuggest:{enabled:!1},hover:{enabled:!1}}},void 0,!1,void 0,this)},void 0,!1,void 0,this)});Ij.displayName="MonacoEditor";var KG=f0(D6(),1),$Z6=f0(e6(),1),jZ6=!1,TZ6=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return"mmd-"+Math.random().toString(36).slice(2)+"-"+Date.now()},VP=(J)=>{return(J??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")},_d=(J)=>{return J.toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim()},u$=(J)=>J?.split("#")[0]??"",KG0=(J)=>{let Z=J?.indexOf("#")??-1;return Z>=0?J.slice(Z+1):null},XG0=(J)=>{let Z=u$(J);if(Z?.startsWith("?"))return new URLSearchParams(Z).get("id");return null},jP=/^A[dtfsj]\d+$/,CZ6=/^\/?documents\/.+/,SZ6=/^\/?templates\/.+/,jY8=(J)=>{if(!J)return!1;if(J.startsWith("#"))return!0;let Z=u$(J);if(jP.test(Z)||CZ6.test(Z)||SZ6.test(Z))return!0;let Q=XG0(J);return Q&&jP.test(Q)},TY8=(J)=>{if(J?.startsWith("#"))return"anchor";let Z=u$(J);if(jP.test(Z))return"id";if(CZ6.test(Z)||SZ6.test(Z))return"path";let Q=XG0(J);if(Q&&jP.test(Q))return"id";return null},yY=({markdown:J,className:Z="",onInternalLinkClick:Q,onRenderComplete:K})=>{let[X,U]=KG.useState(""),Y=KG.useRef(null),z=KG.useRef(0),G=KG.useRef(0),W=(q)=>{let H=q.target.closest("a.internal-link");if(!H)return;if(H.closest("code, pre"))return;let B=H.getAttribute("data-link-type");if(B==="anchor"){q.preventDefault();let M=KG0(H.getAttribute("href")),O=M?_d(M):null;Q?.({type:"anchor",id:null,path:null,anchor:O});return}if(B==="id"){let M=H.getAttribute("data-internal-id"),O=KG0(H.getAttribute("href")),A=O?_d(O):null;if(M&&jP.test(M))q.preventDefault(),Q?.({type:"id",id:M,path:null,anchor:A})}else if(B==="path"){let M=H.getAttribute("data-internal-path"),O=KG0(H.getAttribute("href")),A=O?_d(O):null;if(M&&/^\/(?:documents|templates)\/.+/.test(M))q.preventDefault(),Q?.({type:"path",id:null,path:M,anchor:A})}};return KG.useEffect(()=>{let q=!1,H=++z.current;return(async()=>{try{let[{marked:B},M]=await Promise.all([Promise.resolve().then(() => (qv0(),Wv0)),Promise.resolve().then(() => (ph(),Dv0))]),O=M.default||M,A=new B.Renderer;A.code=({text:V,lang:D})=>{let T=((D??"").trim().split(" ")[0]??"").toLowerCase(),C=VP(V);if(T==="mermaid")return`<pre class="mermaid" data-mermaid-id="${TZ6()}">${C}</pre>`;return`<pre><code class="language-${T}">${C}</code></pre>`},A.link=({href:V,title:D,text:T})=>{let C=VP(V??""),S=T??"",f=D?` title="${VP(D)}"`:"";if(jY8(V)){let h=TY8(V);if(h==="anchor")return`<a href="${C}" class="internal-link" data-link-type="anchor"${f}>${S}</a>`;let k=h==="path"&&V&&!V.startsWith("/")?"/"+V:V,$=VP(k??""),v=h==="id"?jP.test(u$(V))?u$(V):XG0(V):null,_=h==="id"?`data-internal-id="${VP(v)}"`:`data-internal-path="${$}"`;return`<a href="${$}" class="internal-link" data-link-type="${h}" ${_}${f}>${S}</a>`}return`<a href="${C}"${f}>${S}</a>`};let N=new Map,R=0;A.heading=({text:V,depth:D})=>{let T=V.replace(/<[^>]+>/g,""),C=_d(T);if(!C)R++,C=`heading-${R}`;if(N.has(C)){let f=N.get(C);N.set(C,f+1),C=`${C}-${f}`}else N.set(C,1);let S=`h${D}`;return`<${S} id="${VP(C)}">${V}</${S}>`};let w=await B.parse(J??"",{renderer:A}),P=O.sanitize(w,{ADD_TAGS:["pre"],ADD_ATTR:["class","data-mermaid-id","data-link-type","data-internal-id","data-internal-path","id","width","height"]});if(!q&&H===z.current)U(P)}catch(B){if(console.error("Markdown parse error:",B),!q&&H===z.current)U("")}})(),()=>{q=!0}},[J]),KG.useEffect(()=>{if(X)K?.()},[X,K]),KG.useEffect(()=>{if(!X)return;let q=!1,H=++G.current;return(async()=>{let B=Y.current;if(!B)return;let M=Array.from(B.querySelectorAll("pre.mermaid[data-mermaid-id]")),A=Array.from(B.querySelectorAll("pre > code.language-mermaid")).map((R)=>R.parentElement).filter(Boolean),N=[...M,...A];if(N.length===0)return;try{let R=await Promise.resolve().then(() => (VZ6(),EZ6)),w=R.default||R;if(!jZ6)w.initialize({startOnLoad:!1,theme:"default"}),jZ6=!0;let P=N.map(async(D)=>{let T=(D.textContent??"").trim();if(!T)return{el:D,svg:null,error:null};let C=D.getAttribute("data-mermaid-id")||TZ6();try{let{svg:S}=await w.render(`render-${C}`,T);return{el:D,svg:S,error:null}}catch(S){return{el:D,svg:null,error:S}}}),V=await Promise.all(P);if(q||H!==G.current)return;for(let{el:D,svg:T,error:C}of V){if(!D)continue;if(C||!T){console.warn("Mermaid render error:",C),D.classList.add("mermaid-error");continue}try{let S=document.createElement("div");S.className="mermaid-diagram",S.innerHTML=T,D.replaceWith(S)}catch(S){console.warn("Mermaid DOM replace error:",S),D.classList.add("mermaid-error")}}}catch(R){console.error("Mermaid initialization error:",R)}})(),()=>{q=!0}},[X]),$Z6.jsxDEV("div",{ref:Y,className:`prose prose-sm max-w-none ${Z}`,dangerouslySetInnerHTML:{__html:X},onClick:W},void 0,!1,void 0,this)};var p$=f0(D6(),1);var SK="",$K=()=>({"Content-Type":"application/json","X-Session-Id":o4()});var kZ6=async(J,{parentId:Z,name:Q,content:K,subtype:X,fields:U})=>{let Y=await fetch(`${SK}/api/p/${J}/documents`,{method:"POST",headers:$K(),body:JSON.stringify({parentId:Z,name:Q,content:K,subtype:X,fields:U})});return P9(Y,"Failed to create document")},vZ6=async(J,{parentId:Z,name:Q,content:K,subtype:X,fields:U})=>{let Y=await fetch(`${SK}/api/p/${J}/templates`,{method:"POST",headers:$K(),body:JSON.stringify({parentId:Z,name:Q,content:K,subtype:X,fields:U})});return P9(Y,"Failed to create template")},bd=async(J,Z,{includeDraft:Q}={})=>{let K=new URLSearchParams;if(Q)K.set("includeDraft","true");let X=K.toString(),U=`${SK}/api/p/${J}/documents/${Z}${X?`?${X}`:""}`,Y=await fetch(U,{headers:$K()});return P9(Y,"Failed to fetch document")},fZ6=async(J,Z,Q)=>{let K=await fetch(`${SK}/api/p/${J}/documents/${Z}/draft`,{method:"PUT",headers:$K(),body:JSON.stringify({content:Q})});return P9(K,"Failed to save draft")},_Z6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/publish`,{method:"POST",headers:$K()});return P9(Q,"Failed to publish document")},bZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/draft`,{method:"DELETE",headers:$K()});return P9(Q,"Failed to discard draft")},xZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/versions`,{headers:$K()});return P9(Q,"Failed to fetch versions")},TP=async(J,Z,Q)=>{let K=await fetch(`${SK}/api/p/${J}/documents/${Z}/versions/${Q}`,{headers:$K()});return P9(K,"Failed to fetch version")},hZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}`,{method:"DELETE",headers:$K()});return P9(Q,"Failed to delete document")},yZ6=async(J,Z,{path:Q,parentId:K})=>{let X=await fetch(`${SK}/api/p/${J}/documents/${Z}`,{method:"PATCH",headers:$K(),body:JSON.stringify({path:Q,parentId:K})});return P9(X,"Failed to update document path")},xd=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/edit-state`,{method:"POST",headers:$K()});if(Q.status===409)return Q.json();return P9(Q,"Failed to set edit state")},HM=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/edit-state`,{method:"DELETE",headers:$K()});return P9(Q,"Failed to clear edit state")},gZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/parameters`,{headers:$K()});return P9(Q,"Failed to fetch parameters")},mZ6=async(J,Z,{params:Q,target:K,targetOptions:X}={})=>{let U=await fetch(`${SK}/api/p/${J}/documents/${Z}/render`,{method:"POST",headers:$K(),body:JSON.stringify({params:Q,target:K,targetOptions:X})});return P9(U,"Failed to render template")},uZ6=async(J,Z,Q)=>{let K=new URLSearchParams;if(Q)K.set("store",Q);let X=K.toString(),U=`${SK}/api/p/${J}/templates/by-type/${Z}${X?`?${X}`:""}`,Y=await fetch(U,{headers:$K()});return P9(Y,"Failed to fetch templates by type")};var XG=(J,Z)=>{return iZ({queryKey:["document",Z],queryFn:()=>bd(J,Z),enabled:!!J&&!!Z})},CP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,content:K})=>fZ6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},SP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>_Z6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["versions",K]}),Z.invalidateQueries({queryKey:["folderContents"]}),Z.invalidateQueries({queryKey:["parameters",K]})}})},$P=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>bZ6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},kP=(J,Z)=>{return iZ({queryKey:["versions",Z],queryFn:()=>xZ6(J,Z),enabled:!!J&&!!Z})},vP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>hZ6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["versions",K]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},T3=(J)=>{let Z=r9();return I4({mutationFn:({parentId:Q,name:K,content:X,subtype:U,fields:Y})=>kZ6(J,{parentId:Q,name:K,content:X,subtype:U,fields:Y}),onSuccess:()=>{Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},pZ6=(J)=>{let Z=r9();return I4({mutationFn:({parentId:Q,name:K,content:X,subtype:U,fields:Y})=>vZ6(J,{parentId:Q,name:K,content:X,subtype:U,fields:Y}),onSuccess:()=>{Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},fP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,path:K,parentId:X})=>yZ6(J,Q,{path:K,parentId:X}),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},_P=(J,Z)=>{return iZ({queryKey:["parameters",Z],queryFn:()=>gZ6(J,Z),enabled:!!J&&!!Z,select:(Q)=>{let K=Q?.parameters?Object.entries(Q.parameters).map(([w,P])=>{let{label:V,type:D,required:T,description:C,...S}=P;return{name:w,label:V,primitive_type:D??"string",required:T??!1,description:C,config:Object.keys(S).length>0?S:void 0}}):[],X=Q?.detectedVariables??[],U=Q?.target==="stdout"?"clipboard":Q?.target||null,Y=Q?.targetPath||null,z=Q?.path||null,G=Q?.targetParentId||null,W=Q?.targetName||null,q=Q?.targetRoot||null,H=Q?.targetStore||null,B=Q?.targetJobName||null,M=Q?.targetJobAgent||null,O=Q?.targetJobModel||null,A=Q?.targetJobWorktree||null,N=Q?.targetJobSkipDialog??!1,R=Q?.skipDialog??!1;return{parameters:K,detectedVariables:X,target:U,targetPath:Y,path:z,targetParentId:G,targetName:W,targetRoot:q,targetStore:H,targetJobName:B,targetJobAgent:M,targetJobModel:O,targetJobWorktree:A,targetJobSkipDialog:N,skipDialog:R}}})},hd=(J)=>{return I4({mutationFn:({id:Z,params:Q,target:K,targetOptions:X})=>mZ6(J,Z,{params:Q,target:K,targetOptions:X})})},cZ6=(J,Z)=>{return iZ({queryKey:["templatesByType",J,Z],queryFn:()=>uZ6(J,Z),enabled:!!J&&!!Z})};var V4=f0(e6(),1),bP=({open:J,onOpenChange:Z,projectId:Q,documentId:K,anchor:X,onNavigate:U})=>{let{storeCode:Y}=EQ(),{data:z,isLoading:G,isError:W,refetch:q}=XG(Q,K),H=z?.name??"",B=z?.draftContent??z?.resolvedContent??z?.publishedContent??"",M=z?.ancestorFolderIds??[],O=z?.subtype,A=K?.startsWith("At"),N=A?null:M.find((x)=>x?.startsWith("As"))??null,R=A?null:M.find((x)=>x?.startsWith("Aj"))??null,w=!A&&O==="task",P=A?"Context: Templates":R?"Context: Jobs tab":N?"Context: Stories tab":"Context: Documents tab",V=z?.hasDraft??!1,D=A?V?nX:sX:O==="task"?V?hq:aX:O==="cartridge"?xq:O==="prompt"?zz:V?nX:rZ,T=()=>{if(O==="task"){let x=z?.fields?.state,m=JR(x,V);if(m)return{fill:m,stroke:"#000000"}}if(V)return{fill:"#fcd34d",stroke:"#000000"};return{}},C=K?cG(K):"A",S=Y?`/store/${Y}`:"",f=p$.useRef(null),h=p$.useCallback(()=>{if(X&&f.current)setTimeout(()=>{let x=f.current.querySelector(`#${CSS.escape(X)}`);if(x)x.scrollIntoView({behavior:"smooth",block:"start"})},0)},[X]),k=()=>{let x;if(A)x=`/project/${Q}${S}/templates?id=${K}`;else if(R)x=`/project/${Q}${S}/job/${R}`;else if(N)x=`/project/${Q}${S}/stories?expanded=${N}&id=${K}`;else x=`/project/${Q}${S}/documents?id=${K}`;Z(!1),U(x)},$=()=>{let x=`/project/${Q}${S}/stories?expanded=${N}&tab=tasks`;Z(!1),U(x)},v=async()=>{try{await navigator.clipboard.writeText(B),bZ.success("Contents copied")}catch(x){console.error("Failed to copy contents:",x),bZ.error("Failed to copy")}},_=async()=>{try{await navigator.clipboard.writeText(K),bZ.success("ID copied")}catch(x){console.error("Failed to copy ID:",x),bZ.error("Failed to copy")}},b=async({type:x,id:m,path:g,anchor:u})=>{if(x==="anchor")return;let d=u?`#${u}`:"";if(x==="id"){let l=m?.charAt(1)?.toLowerCase(),r;if(l==="j")r=`/project/${Q}${S}/job/${m}${d}`;else if(l==="s")r=`/project/${Q}${S}/stories?expanded=${m}${d}`;else if(l==="f")try{let o=await g5(Q,m),Y0=o?.path||"";if(Y0.startsWith("Templates/"))r=`/project/${Q}${S}/templates?id=${m}${d}`;else if(Y0.startsWith("Stories/")){let e=o?.parentId?.startsWith("As")?o.parentId:null;if(!e){let B0=o?.parentId?await g5(Q,o.parentId):null;while(B0&&!e)if(B0.parentId?.startsWith("As"))e=B0.parentId;else if(B0.id?.startsWith("As"))e=B0.id;else B0=B0.parentId?await g5(Q,B0.parentId):null}if(e)r=`/project/${Q}${S}/stories?expanded=${e}&id=${m}&tab=documents${d}`;else r=`/project/${Q}${S}/stories?id=${m}${d}`}else r=`/project/${Q}${S}/documents?id=${m}${d}`}catch{r=`/project/${Q}${S}/documents?id=${m}${d}`}else r=`/project/${Q}${S}/${l==="t"?"templates":"documents"}?id=${m}${d}`;Z(!1),U(r)}else if(x==="path"){let l=`/project/${Q}${S}${g}${d}`;Z(!1),U(l)}};return V4.jsxDEV(sJ,{open:J,onOpenChange:Z,children:V4.jsxDEV(vJ,{className:"max-w-6xl max-h-[85vh] flex flex-col",children:[V4.jsxDEV(fJ,{className:"flex-shrink-0",children:[V4.jsxDEV("div",{className:"relative flex items-center min-h-[28px]",children:[V4.jsxDEV("span",{className:"text-sm text-muted-foreground",children:P},void 0,!1,void 0,this),V4.jsxDEV(_J,{className:"absolute inset-0 flex items-center gap-2 justify-center pointer-events-none",children:[!G&&V4.jsxDEV(V4.Fragment,{children:[V4.jsxDEV(D,{className:"h-5 w-5 shrink-0",...T()},void 0,!1,void 0,this),V4.jsxDEV("span",{children:H||(A?"Template":"Document")},void 0,!1,void 0,this),V4.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${pq[C]||pq.A}`,children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&"Loading..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V4.jsxDEV("div",{className:"flex flex-wrap gap-2 pt-2",children:[V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:k,disabled:G,children:[V4.jsxDEV(qV,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"View in Context"]},void 0,!0,void 0,this),w&&N&&V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:$,disabled:G,children:[V4.jsxDEV(sH,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"View on Kanban"]},void 0,!0,void 0,this),V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:v,disabled:G||!B,children:[V4.jsxDEV(kZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Contents"]},void 0,!0,void 0,this),V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:_,children:[V4.jsxDEV(kZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy ID"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V4.jsxDEV("div",{ref:f,className:"flex-1 overflow-auto min-h-0 mt-4",children:G?V4.jsxDEV("div",{className:"flex items-center justify-center py-8",children:V4.jsxDEV(c7,{className:"w-6 h-6 animate-spin"},void 0,!1,void 0,this)},void 0,!1,void 0,this):W?V4.jsxDEV("div",{className:"text-center py-8",children:[V4.jsxDEV(B7,{className:"w-6 h-6 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),V4.jsxDEV("p",{className:"text-muted-foreground mb-2",children:"Failed to load document"},void 0,!1,void 0,this),V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>q(),children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):B?V4.jsxDEV(yY,{markdown:B,onInternalLinkClick:b,onRenderComplete:h},void 0,!1,void 0,this):V4.jsxDEV("p",{className:"text-muted-foreground text-center py-8",children:"No content"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var gY=f0(D6(),1);var BM=()=>{let[J,Z]=tE(),{"*":Q}=EQ(),K=Q||null,X=a4(),U=gY.useMemo(()=>{return X.hash?.slice(1)||null},[X.hash]),Y=J.get("id")||null,z=J.get("edit")==="true",G=gY.useMemo(()=>{let C=J.get("selected");return C?C.split(",").filter(Boolean):[]},[J]),W=J.get("tab")||null,q=J.get("expanded")||null,H=J.get("from")||null,B=K?"path":Y?"id":null,M=z,O=lq(Y),A=z&&Y&&!O;gY.useMemo(()=>{let C=!1,S=new URLSearchParams(J);if(Y&&G.length>0)S.delete("selected"),C=!0;if(K&&G.length>0)S.delete("selected"),C=!0;if(z&&!K&&(!Y||O))S.delete("edit"),C=!0;if(W&&!q)S.delete("tab"),C=!0;if(C)queueMicrotask(()=>{Z(S,{replace:!0})})},[J,Y,G,z,O,K,W,q,Z]);let N=gY.useCallback((C,S={})=>{let{history:f="push",preserveEdit:h=!1,edit:k}=S;Z(($)=>{let v=$.get("id")||null,_=$.get("edit")==="true";if(C===v&&k===_)return $;let b=new URLSearchParams($);if(C)b.set("id",C);else b.delete("id");if(k===!0&&C&&!lq(C))b.set("edit","true");else if(!h||!C||lq(C))b.delete("edit");return b.delete("selected"),b},{replace:f==="replace"})},[Z]),R=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;if(C===z)return;if(C&&!K&&(!Y||O))return;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("edit","true");else k.delete("edit");return k},{replace:f==="replace"})},[Z,z,Y,O,K]),w=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C.length>0){let $=C.slice(0,20);k.set("selected",$.join(",")),k.delete("id"),k.delete("edit")}else k.delete("selected");return k},{replace:f==="replace"})},[Z]),P=gY.useCallback((C={})=>{let{history:S="replace"}=C;Z((f)=>{let h=new URLSearchParams(f);return h.delete("id"),h.delete("edit"),h.delete("selected"),h},{replace:S==="replace"})},[Z]),V=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("tab",C);else k.delete("tab");return k},{replace:f==="replace"})},[Z]),D=gY.useCallback((C,S={})=>{let{history:f="push"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("expanded",C);else k.delete("expanded"),k.delete("tab");return k.delete("id"),k.delete("edit"),k},{replace:f==="replace"})},[Z]),T=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("from",C);else k.delete("from");return k},{replace:f==="replace"})},[Z]);return{selectedId:Y,isEditMode:A,collectedIds:G,documentPath:K,addressingScheme:B,isEditRequested:M,anchorFragment:U,activeTab:W,expandedId:q,fromContext:H,setSelectedId:N,setEditMode:R,setCollectedIds:w,clearSelection:P,setActiveTab:V,setExpandedId:D,setFromContext:T}};var T8=f0(e6(),1),yd=({projectId:J,rootFolderId:Z,selectedId:Q,selectedItemData:K,versions:X,draftContent:U,serverContent:Y,isDirty:z,hasDraft:G,isEditMode:W,setEditMode:q,viewingVersion:H,versionContent:B,showVersions:M,setShowVersions:O,showRename:A,setShowRename:N,renameFilename:R,setRenameFilename:w,actionError:P,setActionError:V,saveStatus:D,handleEditorChange:T,handleViewVersion:C,handleBackToEdit:S,handlePublish:f,handleDiscardDraft:h,handleRetry:k,handleOpenRename:$,handleRename:v,handleCopyContent:_,handleCopyIds:b,setShowDeleteConfirm:x,publishMutation:m,discardMutation:g,updatePathMutation:u,debouncedSave:d,collectedIds:l,typeName:r,triggerEditMode:o,setTriggerEditMode:Y0})=>{let e=r9(),{setSelectedId:B0,documentPath:Q0,anchorFragment:M0}=BM(),W0=dJ(),H0=a4(),U0=Z?.startsWith("As")?Z:null,K0=async({type:d0,id:R0,path:P0,anchor:s})=>{if(d0==="anchor"){W0(`${H0.pathname}${H0.search}#${s}`,{replace:!0});return}let A0=s?`#${s}`:"";if(d0==="id"){let i=R0?.charAt(1)?.toLowerCase();if(i==="t"){J0({id:R0,anchor:s||null});return}if(i==="d")try{let N0=await bd(J,R0),x0=N0?.ancestorFolderIds?.find((D0)=>D0?.startsWith("As")),$0=N0?.ancestorFolderIds?.some((D0)=>D0?.startsWith("Aj"));if(U0)if(x0===U0);else{J0({id:R0,anchor:s||null});return}else if(x0||$0){J0({id:R0,anchor:s||null});return}}catch{}let L0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?)/)?.[1];if(i==="s"){W0(`${L0}/stories?expanded=${R0}${A0}`);return}if(i==="j"){W0(`${L0}/job/${R0}${A0}`);return}if(i==="f"){try{let N0=await g5(J,R0),x0=N0?.path||"";if(x0.startsWith("Templates/"))W0(`${L0}/templates?id=${R0}${A0}`);else if(x0.startsWith("Stories/")){let $0=N0?.parentId?.startsWith("As")?N0.parentId:null;if(!$0){let D0=N0?.parentId?await g5(J,N0.parentId):null;while(D0&&!$0)if(D0.parentId?.startsWith("As"))$0=D0.parentId;else if(D0.id?.startsWith("As"))$0=D0.id;else D0=D0.parentId?await g5(J,D0.parentId):null}if($0)W0(`${L0}/stories?expanded=${$0}&id=${R0}&tab=documents${A0}`);else W0(`${L0}/stories?id=${R0}${A0}`)}else W0(`${L0}/documents?id=${R0}${A0}`)}catch{W0(`${L0}/documents?id=${R0}${A0}`)}return}if(Q0){let N0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?\/(?:documents|templates))/)?.[1];if(N0){W0(`${N0}?id=${R0}${A0}`);return}}if(s)W0(`${H0.pathname}?id=${R0}${A0}`);else B0(R0)}else if(d0==="path")W0(`/project/${J}${P0}${A0}`)},[O0,J0]=zQ.useState(null),[j0,q0]=zQ.useState(null),v0=j0===Q,[Z0,e0]=zQ.useState(!1),X0=zQ.useRef(Q),T0=zQ.useRef(!1),_0=zQ.useRef(null);zQ.useEffect(()=>{if(M0&&_0.current)setTimeout(()=>{let d0=_0.current.querySelector(`#${CSS.escape(M0)}`);if(d0)d0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[M0]);let l0=zQ.useCallback(()=>{if(M0&&_0.current)setTimeout(()=>{let d0=_0.current.querySelector(`#${CSS.escape(M0)}`);if(d0)d0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[M0]),b0=W&&v0,y0=zQ.useMemo(()=>{if(!K||!K.editState)return!1;let d0=o4();return K.editState.sessionId!==d0},[K]);zQ.useEffect(()=>{let d0=X0.current;if(X0.current=Q,v0&&d0&&d0!==Q)HM(J,d0).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",d0]})}).catch((R0)=>{console.error("Failed to clear edit state on selection change:",R0)}),q0(null);if(W&&Q&&!v0)xd(J,Q).then((R0)=>{if(R0.success)q0(Q),e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]});else q(!1),V(`Document is currently being edited. Try again in ${Math.ceil(R0.meta?.timeoutSeconds/60)} minutes.`)}).catch((R0)=>{q(!1),V(R0.message)});if(!W&&v0&&Q)HM(J,Q).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]})}).catch((R0)=>{console.error("Failed to clear edit state:",R0)}),q0(null)},[W,Q,v0,J,q,V,e]),zQ.useEffect(()=>{if(!K||!Q)return;let d0=K.editState,R0=o4();if(d0&&d0.sessionId===R0){let P0=new Date(d0.lastActivityAt),s=new Date(Date.now()-3600000);if(P0>=s){if(q0(Q),!W)q(!0)}}else if(j0===Q&&d0&&d0.sessionId!==R0){if(q0(null),W)e0(!0),q(!1)}},[K,Q]),zQ.useEffect(()=>{if(o)Y0(!1)},[o,Y0]),zQ.useEffect(()=>{console.log("[BUTTON] Visibility check:",{viewingVersion:H,isDirty:z,hasDraft:G,saveStatus:D,visible:!H&&(z||G||D==="saving")})},[H,z,G,D]),zQ.useEffect(()=>{return()=>{if(j0&&J)HM(J,j0).catch((d0)=>{console.error("Failed to clear edit state on unmount:",d0)})}},[j0,J]);let p0=async()=>{console.log("[BUTTON] Publish button clicked"),await f()},m0=async()=>{if(l&&l.length>0)try{let d0=await Promise.all(l.map(async(R0)=>{let s=await(await fetch(`/api/p/${J}/documents/${R0}`,{headers:{"Content-Type":"application/json"}})).json(),A0=s.draftContent??s.publishedContent??"";return`=== [${R0}] - ${s.path||R0} ===
3083
+ `},Ck0=jk0(xk6)(Sk0),$k0={config:_k6};var kk0=function(){for(var Z=arguments.length,Q=Array(Z),K=0;K<Z;K++)Q[K]=arguments[K];return function(X){return Q.reduceRight(function(U,Y){return Y(U)},X)}};function w60(J,Z){return Object.keys(Z).forEach(function(Q){if(Z[Q]instanceof Object){if(J[Q])Object.assign(Z[Q],w60(J[Q],Z[Q]))}}),R60(R60({},J),Z)}var hk6={type:"cancelation",msg:"operation is manually canceled"};function Th(J){var Z=!1,Q=new Promise(function(K,X){J.then(function(U){return Z?X(hk6):K(U)}),J.catch(X)});return Q.cancel=function(){return Z=!0},Q}var yk6=["monaco"],gk6=Ek0.create({config:Vk0,isInitialized:!1,resolve:null,reject:null,monaco:null}),vk0=Ik0(gk6,2),Rj=vk0[0],Ch=vk0[1];function mk6(J){var Z=$k0.config(J),Q=Z.monaco,K=wk0(Z,yk6);Ch(function(X){return{config:w60(X.config,K),monaco:Q}})}function uk6(){var J=Rj(function(Z){var{monaco:Q,isInitialized:K,resolve:X}=Z;return{monaco:Q,isInitialized:K,resolve:X}});if(!J.isInitialized){if(Ch({isInitialized:!0}),J.monaco)return J.resolve(J.monaco),Th(I60);if(window.monaco&&window.monaco.editor)return fk0(window.monaco),J.resolve(window.monaco),Th(I60);kk0(pk6,lk6)(dk6)}return Th(I60)}function pk6(J){return document.body.appendChild(J)}function ck6(J){var Z=document.createElement("script");return J&&(Z.src=J),Z}function lk6(J){var Z=Rj(function(K){var{config:X,reject:U}=K;return{config:X,reject:U}}),Q=ck6("".concat(Z.config.paths.vs,"/loader.js"));return Q.onload=function(){return J()},Q.onerror=Z.reject,Q}function dk6(){var J=Rj(function(Q){var{config:K,resolve:X,reject:U}=Q;return{config:K,resolve:X,reject:U}}),Z=window.require;Z.config(J.config),Z(["vs/editor/editor.main"],function(Q){var K=Q.m||Q;fk0(K),J.resolve(K)},function(Q){J.reject(Q)})}function fk0(J){if(!Rj().monaco)Ch({monaco:J})}function ik6(){return Rj(function(J){var Z=J.monaco;return Z})}var I60=new Promise(function(J,Z){return Ch({resolve:J,reject:Z})}),eO={config:mk6,init:uk6,__getMonacoInstance:ik6};var _k0=f0(D6(),1),H5=f0(D6(),1);var bk0=f0(D6(),1),$h=f0(D6(),1),xk0=f0(D6(),1),yk0=f0(D6(),1),kh=f0(D6(),1),zv6=f0(D6(),1);var uk0=f0(D6(),1),EZ=f0(D6(),1);var vh=f0(D6(),1),rk6={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},P60=rk6,nk6={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},sk6=nk6;function ak6({children:J}){return xk0.default.createElement("div",{style:sk6.container},J)}var ok6=ak6,tk6=ok6;function ek6({width:J,height:Z,isEditorReady:Q,loading:K,_ref:X,className:U,wrapperProps:Y}){return $h.default.createElement("section",{style:{...P60.wrapper,width:J,height:Z},...Y},!Q&&$h.default.createElement(tk6,null,K),$h.default.createElement("div",{ref:X,style:{...P60.fullWidth,...!Q&&P60.hide},className:U}))}var Jv6=ek6,hk0=bk0.memo(Jv6);function Zv6(J){yk0.useEffect(J,[])}var gk0=Zv6;function Qv6(J,Z,Q=!0){let K=kh.useRef(!0);kh.useEffect(K.current||!Q?()=>{K.current=!1}:J,Z)}var QU=Qv6;function wj(){}function YR(J,Z,Q,K){return Kv6(J,K)||Xv6(J,Z,Q,K)}function Kv6(J,Z){return J.editor.getModel(mk0(J,Z))}function Xv6(J,Z,Q,K){return J.editor.createModel(Z,Q,K?mk0(J,K):void 0)}function mk0(J,Z){return J.Uri.parse(Z)}function Uv6({original:J,modified:Z,language:Q,originalLanguage:K,modifiedLanguage:X,originalModelPath:U,modifiedModelPath:Y,keepCurrentOriginalModel:z=!1,keepCurrentModifiedModel:G=!1,theme:W="light",loading:q="Loading...",options:H={},height:B="100%",width:M="100%",className:O,wrapperProps:A={},beforeMount:N=wj,onMount:R=wj}){let[w,P]=H5.useState(!1),[V,D]=H5.useState(!0),T=H5.useRef(null),C=H5.useRef(null),S=H5.useRef(null),f=H5.useRef(R),h=H5.useRef(N),k=H5.useRef(!1);gk0(()=>{let b=eO.init();return b.then((x)=>(C.current=x)&&D(!1)).catch((x)=>x?.type!=="cancelation"&&console.error("Monaco initialization: error:",x)),()=>T.current?_():b.cancel()}),QU(()=>{if(T.current&&C.current){let b=T.current.getOriginalEditor(),x=YR(C.current,J||"",K||Q||"text",U||"");x!==b.getModel()&&b.setModel(x)}},[U],w),QU(()=>{if(T.current&&C.current){let b=T.current.getModifiedEditor(),x=YR(C.current,Z||"",X||Q||"text",Y||"");x!==b.getModel()&&b.setModel(x)}},[Y],w),QU(()=>{let b=T.current.getModifiedEditor();b.getOption(C.current.editor.EditorOption.readOnly)?b.setValue(Z||""):Z!==b.getValue()&&(b.executeEdits("",[{range:b.getModel().getFullModelRange(),text:Z||"",forceMoveMarkers:!0}]),b.pushUndoStop())},[Z],w),QU(()=>{T.current?.getModel()?.original.setValue(J||"")},[J],w),QU(()=>{let{original:b,modified:x}=T.current.getModel();C.current.editor.setModelLanguage(b,K||Q||"text"),C.current.editor.setModelLanguage(x,X||Q||"text")},[Q,K,X],w),QU(()=>{C.current?.editor.setTheme(W)},[W],w),QU(()=>{T.current?.updateOptions(H)},[H],w);let $=H5.useCallback(()=>{if(!C.current)return;h.current(C.current);let b=YR(C.current,J||"",K||Q||"text",U||""),x=YR(C.current,Z||"",X||Q||"text",Y||"");T.current?.setModel({original:b,modified:x})},[Q,Z,X,J,K,U,Y]),v=H5.useCallback(()=>{!k.current&&S.current&&(T.current=C.current.editor.createDiffEditor(S.current,{automaticLayout:!0,...H}),$(),C.current?.editor.setTheme(W),P(!0),k.current=!0)},[H,W,$]);H5.useEffect(()=>{w&&f.current(T.current,C.current)},[w]),H5.useEffect(()=>{!V&&!w&&v()},[V,w,v]);function _(){let b=T.current?.getModel();z||b?.original?.dispose(),G||b?.modified?.dispose(),T.current?.dispose()}return H5.default.createElement(hk0,{width:M,height:B,isEditorReady:w,loading:q,_ref:S,className:O,wrapperProps:A})}var Yv6=Uv6,gd8=_k0.memo(Yv6);function Gv6(J){let Z=vh.useRef();return vh.useEffect(()=>{Z.current=J},[J]),Z.current}var Wv6=Gv6,Sh=new Map;function qv6({defaultValue:J,defaultLanguage:Z,defaultPath:Q,value:K,language:X,path:U,theme:Y="light",line:z,loading:G="Loading...",options:W={},overrideServices:q={},saveViewState:H=!0,keepCurrentModel:B=!1,width:M="100%",height:O="100%",className:A,wrapperProps:N={},beforeMount:R=wj,onMount:w=wj,onChange:P,onValidate:V=wj}){let[D,T]=EZ.useState(!1),[C,S]=EZ.useState(!0),f=EZ.useRef(null),h=EZ.useRef(null),k=EZ.useRef(null),$=EZ.useRef(w),v=EZ.useRef(R),_=EZ.useRef(),b=EZ.useRef(K),x=Wv6(U),m=EZ.useRef(!1),g=EZ.useRef(!1);gk0(()=>{let l=eO.init();return l.then((r)=>(f.current=r)&&S(!1)).catch((r)=>r?.type!=="cancelation"&&console.error("Monaco initialization: error:",r)),()=>h.current?d():l.cancel()}),QU(()=>{let l=YR(f.current,J||K||"",Z||X||"",U||Q||"");l!==h.current?.getModel()&&(H&&Sh.set(x,h.current?.saveViewState()),h.current?.setModel(l),H&&h.current?.restoreViewState(Sh.get(U)))},[U],D),QU(()=>{h.current?.updateOptions(W)},[W],D),QU(()=>{!h.current||K===void 0||(h.current.getOption(f.current.editor.EditorOption.readOnly)?h.current.setValue(K):K!==h.current.getValue()&&(g.current=!0,h.current.executeEdits("",[{range:h.current.getModel().getFullModelRange(),text:K,forceMoveMarkers:!0}]),h.current.pushUndoStop(),g.current=!1))},[K],D),QU(()=>{let l=h.current?.getModel();l&&X&&f.current?.editor.setModelLanguage(l,X)},[X],D),QU(()=>{z!==void 0&&h.current?.revealLine(z)},[z],D),QU(()=>{f.current?.editor.setTheme(Y)},[Y],D);let u=EZ.useCallback(()=>{if(!(!k.current||!f.current)&&!m.current){v.current(f.current);let l=U||Q,r=YR(f.current,K||J||"",Z||X||"",l||"");h.current=f.current?.editor.create(k.current,{model:r,automaticLayout:!0,...W},q),H&&h.current.restoreViewState(Sh.get(l)),f.current.editor.setTheme(Y),z!==void 0&&h.current.revealLine(z),T(!0),m.current=!0}},[J,Z,Q,K,X,U,W,q,H,Y,z]);EZ.useEffect(()=>{D&&$.current(h.current,f.current)},[D]),EZ.useEffect(()=>{!C&&!D&&u()},[C,D,u]),b.current=K,EZ.useEffect(()=>{D&&P&&(_.current?.dispose(),_.current=h.current?.onDidChangeModelContent((l)=>{g.current||P(h.current.getValue(),l)}))},[D,P]),EZ.useEffect(()=>{if(D){let l=f.current.editor.onDidChangeMarkers((r)=>{let o=h.current.getModel()?.uri;if(o&&r.find((Y0)=>Y0.path===o.path)){let Y0=f.current.editor.getModelMarkers({resource:o});V?.(Y0)}});return()=>{l?.dispose()}}return()=>{}},[D,V]);function d(){_.current?.dispose(),B?H&&Sh.set(U,h.current.saveViewState()):h.current.getModel()?.dispose(),h.current.dispose()}return EZ.default.createElement(hk0,{width:M,height:O,isEditorReady:D,loading:G,_ref:k,className:A,wrapperProps:N})}var Hv6=qv6,Bv6=uk0.memo(Hv6),pk0=Bv6;var Fv6="",Mv6=["image/png","image/jpeg","image/gif","image/webp"],Ov6=10485760,ck0=async(J,Z,Q="A",K,X={})=>{let U=new FormData;if(U.append("file",Z),X.widthPx!==void 0)U.append("widthPx",X.widthPx);if(X.heightPx!==void 0)U.append("heightPx",X.heightPx);if(X.displayWidth!==void 0)U.append("displayWidth",X.displayWidth);if(X.displayHeight!==void 0)U.append("displayHeight",X.displayHeight);let Y=await fetch(`${Fv6}/api/p/${J}/assets?store=${Q}`,{method:"POST",headers:{"X-Session-Id":o4()},body:U,signal:K});return P9(Y,"Failed to upload asset")};var lk0=(J)=>{if(!Mv6.includes(J.type))return{valid:!1,error:`Unsupported image type: ${J.type}`};if(J.size>Ov6)return{valid:!1,error:`File too large: ${(J.size/1048576).toFixed(1)}MB. Maximum: 10MB`};return{valid:!0}};var D60=f0(e6(),1),Lv6=()=>crypto.randomUUID(),Av6=(J)=>{if(!J)return"markdown";let Z=J.toLowerCase();if(Z.endsWith(".md")||Z.endsWith(".markdown"))return"markdown";if(Z.endsWith(".json"))return"json";if(Z.endsWith(".ts"))return"typescript";if(Z.endsWith(".tsx"))return"typescript";if(Z.endsWith(".js"))return"javascript";if(Z.endsWith(".jsx"))return"javascript";if(Z.endsWith(".yml")||Z.endsWith(".yaml"))return"yaml";if(Z.endsWith(".html"))return"html";if(Z.endsWith(".css"))return"css";if(Z.endsWith(".mmd"))return"plaintext";if(Z.endsWith(".txt"))return"plaintext";return"markdown"},Ij=JJ.memo(({value:J,onChange:Z,onBlur:Q,path:K="",height:X="100%",className:U="",debounceMs:Y=0,autoFocus:z=!0,projectId:G,storeCode:W})=>{let q=JJ.useMemo(()=>Av6(K),[K]),H=JJ.useRef(null),{theme:B}=u_(),M=B==="dark"?"caw-dark":"caw-light",O=JJ.useRef(Z);O.current=Z;let A=JJ.useRef(Q);A.current=Q;let N=JJ.useRef(null),R=JJ.useRef(null),w=JJ.useRef(null),P=JJ.useRef(null),V=JJ.useRef(null),[D,T]=JJ.useState(!1),C=JJ.useRef(null),S=JJ.useRef(K);JJ.useEffect(()=>{return()=>{if(N.current)clearTimeout(N.current);if(H.current?._blurDisposable)H.current._blurDisposable.dispose()}},[]),JJ.useEffect(()=>{if(K!==S.current)C.current=null,S.current=K},[K]);let f=JJ.useCallback((m)=>{R.current=m,m.editor.defineTheme("caw-light",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#f9f8f6"}}),m.editor.defineTheme("caw-dark",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#3c3c3e"}})},[]),h=JJ.useCallback((m)=>{if(H.current=m,T(!0),z)m.focus(),m.setPosition({lineNumber:1,column:1});let g=m.onDidBlurEditorWidget(()=>{if(A.current)A.current()});H.current._blurDisposable=g},[z]),k=JJ.useCallback((m)=>{let g=m??"";if(C.current=g,!Y||Y<=0){if(O.current)O.current(g);return}if(N.current)clearTimeout(N.current);N.current=setTimeout(()=>{if(O.current)O.current(g)},Y)},[Y]),$=JJ.useCallback(()=>{if(!H.current||!Z)return;let m=H.current.getModel();if(m)Z(m.getValue())},[Z]),v=JJ.useCallback(async(m)=>{if(!G||!R.current)return;let g=m.clipboardData?.items;if(!g)return;for(let u of g)if(u.type.startsWith("image/")){m.preventDefault();let d=u.getAsFile();if(!d)continue;let l=lk0(d);if(!l.valid){console.warn(`Image upload validation failed: ${l.error}`);let K0=H.current;if(K0){let O0=K0.getPosition(),J0=`<!-- Upload rejected: ${l.error} -->`;K0.executeEdits("paste-image-validation",[{range:new R.current.Range(O0.lineNumber,O0.column,O0.lineNumber,O0.column),text:J0}]),$()}continue}let r=H.current;if(!r)continue;let o=r.getPosition();P.current=o;let Y0,e,B0,Q0;try{let K0=await createImageBitmap(d);Y0=K0.width,e=K0.height,K0.close();let O0=window.devicePixelRatio||1;B0=Math.round(Y0/O0),Q0=Math.round(e/O0)}catch(K0){console.warn("[CAW Paste] Could not get image dimensions:",K0)}let W0=`![Uploading...](caw-upload:${Lv6()})`,H0=r.getPosition();r.executeEdits("paste-image",[{range:new R.current.Range(H0.lineNumber,H0.column,H0.lineNumber,H0.column),text:W0}]),$();let U0=new AbortController;w.current=U0;try{let K0=await ck0(G,d,W||"A",U0.signal,{widthPx:Y0,heightPx:e,displayWidth:B0,displayHeight:Q0});if(U0.signal.aborted)return;let O0=(K0.originalFilename||"image").replace(/"/g,"&quot;"),J0=K0.displayWidth&&K0.displayHeight?`<img src="/api/p/${G}/assets/${K0.id}/binary?h=${K0.hash}" alt="${O0}" width="${K0.displayWidth}" height="${K0.displayHeight}">`:`![${O0}](/api/p/${G}/assets/${K0.id}/binary?h=${K0.hash})`,j0=r.getModel();if(!j0)return;let v0=j0.getValue().indexOf(W0);if(v0>=0){let Z0=j0.getPositionAt(v0),e0=j0.getPositionAt(v0+W0.length);r.executeEdits("paste-image-complete",[{range:new R.current.Range(Z0.lineNumber,Z0.column,e0.lineNumber,e0.column),text:J0}])}else{let Z0=P.current||r.getPosition();r.executeEdits("paste-image-fallback",[{range:new R.current.Range(Z0.lineNumber,Z0.column,Z0.lineNumber,Z0.column),text:J0}])}$()}catch(K0){if(K0.name==="AbortError")return;let O0=r.getModel();if(!O0)return;let j0=O0.getValue().indexOf(W0),q0=`<!-- Upload failed: ${K0.message} -->`;if(j0>=0){let v0=O0.getPositionAt(j0),Z0=O0.getPositionAt(j0+W0.length);r.executeEdits("paste-image-error",[{range:new R.current.Range(v0.lineNumber,v0.column,Z0.lineNumber,Z0.column),text:q0}])}$(),console.error("Image upload failed:",K0)}finally{w.current=null,P.current=null}return}},[G,W,$]);V.current=v,JJ.useEffect(()=>{let m=H.current;if(!D||!m)return;let g=m.hasTextFocus(),u=m.onDidFocusEditorText(()=>{g=!0}),d=m.onDidBlurEditorText(()=>{g=!1}),l=(r)=>{if(!g)return;V.current?.(r)};return document.addEventListener("paste",l,!0),()=>{if(u.dispose(),d.dispose(),document.removeEventListener("paste",l,!0),w.current)w.current.abort()}},[D]);let _=J===C.current&&K===S.current,b=X==="100%"?void 0:{height:X},x=X==="100%"?`h-full rounded-md overflow-hidden border border-border ${U}`:`rounded-md overflow-hidden border border-border ${U}`;return D60.jsxDEV("div",{className:x,style:b,children:D60.jsxDEV(pk0,{height:"100%",language:q,path:K,value:_?void 0:J,defaultValue:J,onChange:k,beforeMount:f,onMount:h,theme:M,options:{fontSize:14,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",minimap:{enabled:!1},smoothScrolling:!0,scrollBeyondLastLine:!1,automaticLayout:!0,wordWrap:"on",lineNumbers:"on",padding:{top:12,bottom:12},cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",multiCursorModifier:"ctrlCmd",stickyScroll:{enabled:!0},overviewRulerLanes:0,hideCursorInOverviewRuler:!0,glyphMargin:!1,renderWhitespace:"boundary",lineDecorationsWidth:0,quickSuggestions:!1,wordBasedSuggestions:"off",suggestOnTriggerCharacters:!1,inlineSuggest:{enabled:!1},hover:{enabled:!1}}},void 0,!1,void 0,this)},void 0,!1,void 0,this)});Ij.displayName="MonacoEditor";var KG=f0(D6(),1),$Z6=f0(e6(),1),jZ6=!1,TZ6=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID();return"mmd-"+Math.random().toString(36).slice(2)+"-"+Date.now()},VP=(J)=>{return(J??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")},_d=(J)=>{return J.toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim()},u$=(J)=>J?.split("#")[0]??"",KG0=(J)=>{let Z=J?.indexOf("#")??-1;return Z>=0?J.slice(Z+1):null},XG0=(J)=>{let Z=u$(J);if(Z?.startsWith("?"))return new URLSearchParams(Z).get("id");return null},jP=/^A[dtfsj]\d+$/,CZ6=/^\/?documents\/.+/,SZ6=/^\/?templates\/.+/,jY8=(J)=>{if(!J)return!1;if(J.startsWith("#"))return!0;let Z=u$(J);if(jP.test(Z)||CZ6.test(Z)||SZ6.test(Z))return!0;let Q=XG0(J);return Q&&jP.test(Q)},TY8=(J)=>{if(J?.startsWith("#"))return"anchor";let Z=u$(J);if(jP.test(Z))return"id";if(CZ6.test(Z)||SZ6.test(Z))return"path";let Q=XG0(J);if(Q&&jP.test(Q))return"id";return null},yY=({markdown:J,className:Z="",onInternalLinkClick:Q,onRenderComplete:K})=>{let[X,U]=KG.useState(""),Y=KG.useRef(null),z=KG.useRef(0),G=KG.useRef(0),W=(q)=>{let H=q.target.closest("a.internal-link");if(!H)return;if(H.closest("code, pre"))return;let B=H.getAttribute("data-link-type");if(B==="anchor"){q.preventDefault();let M=KG0(H.getAttribute("href")),O=M?_d(M):null;Q?.({type:"anchor",id:null,path:null,anchor:O});return}if(B==="id"){let M=H.getAttribute("data-internal-id"),O=KG0(H.getAttribute("href")),A=O?_d(O):null;if(M&&jP.test(M))q.preventDefault(),Q?.({type:"id",id:M,path:null,anchor:A})}else if(B==="path"){let M=H.getAttribute("data-internal-path"),O=KG0(H.getAttribute("href")),A=O?_d(O):null;if(M&&/^\/(?:documents|templates)\/.+/.test(M))q.preventDefault(),Q?.({type:"path",id:null,path:M,anchor:A})}};return KG.useEffect(()=>{let q=!1,H=++z.current;return(async()=>{try{let[{marked:B},M]=await Promise.all([Promise.resolve().then(() => (qv0(),Wv0)),Promise.resolve().then(() => (ph(),Dv0))]),O=M.default||M,A=new B.Renderer;A.code=({text:V,lang:D})=>{let T=((D??"").trim().split(" ")[0]??"").toLowerCase(),C=VP(V);if(T==="mermaid")return`<pre class="mermaid" data-mermaid-id="${TZ6()}">${C}</pre>`;return`<pre><code class="language-${T}">${C}</code></pre>`},A.link=({href:V,title:D,text:T})=>{let C=VP(V??""),S=T??"",f=D?` title="${VP(D)}"`:"";if(jY8(V)){let h=TY8(V);if(h==="anchor")return`<a href="${C}" class="internal-link" data-link-type="anchor"${f}>${S}</a>`;let k=h==="path"&&V&&!V.startsWith("/")?"/"+V:V,$=VP(k??""),v=h==="id"?jP.test(u$(V))?u$(V):XG0(V):null,_=h==="id"?`data-internal-id="${VP(v)}"`:`data-internal-path="${$}"`;return`<a href="${$}" class="internal-link" data-link-type="${h}" ${_}${f}>${S}</a>`}return`<a href="${C}"${f}>${S}</a>`};let N=new Map,R=0;A.heading=({text:V,depth:D})=>{let T=V.replace(/<[^>]+>/g,""),C=_d(T);if(!C)R++,C=`heading-${R}`;if(N.has(C)){let f=N.get(C);N.set(C,f+1),C=`${C}-${f}`}else N.set(C,1);let S=`h${D}`;return`<${S} id="${VP(C)}">${V}</${S}>`};let w=await B.parse(J??"",{renderer:A}),P=O.sanitize(w,{ADD_TAGS:["pre"],ADD_ATTR:["class","data-mermaid-id","data-link-type","data-internal-id","data-internal-path","id","width","height"]});if(!q&&H===z.current)U(P)}catch(B){if(console.error("Markdown parse error:",B),!q&&H===z.current)U("")}})(),()=>{q=!0}},[J]),KG.useEffect(()=>{if(X)K?.()},[X,K]),KG.useEffect(()=>{if(!X)return;let q=!1,H=++G.current;return(async()=>{let B=Y.current;if(!B)return;let M=Array.from(B.querySelectorAll("pre.mermaid[data-mermaid-id]")),A=Array.from(B.querySelectorAll("pre > code.language-mermaid")).map((R)=>R.parentElement).filter(Boolean),N=[...M,...A];if(N.length===0)return;try{let R=await Promise.resolve().then(() => (VZ6(),EZ6)),w=R.default||R;if(!jZ6)w.initialize({startOnLoad:!1,theme:"default"}),jZ6=!0;let P=N.map(async(D)=>{let T=(D.textContent??"").trim();if(!T)return{el:D,svg:null,error:null};let C=D.getAttribute("data-mermaid-id")||TZ6();try{let{svg:S}=await w.render(`render-${C}`,T);return{el:D,svg:S,error:null}}catch(S){return{el:D,svg:null,error:S}}}),V=await Promise.all(P);if(q||H!==G.current)return;for(let{el:D,svg:T,error:C}of V){if(!D)continue;if(C||!T){console.warn("Mermaid render error:",C),D.classList.add("mermaid-error");continue}try{let S=document.createElement("div");S.className="mermaid-diagram",S.innerHTML=T,D.replaceWith(S)}catch(S){console.warn("Mermaid DOM replace error:",S),D.classList.add("mermaid-error")}}}catch(R){console.error("Mermaid initialization error:",R)}})(),()=>{q=!0}},[X]),$Z6.jsxDEV("div",{ref:Y,className:`prose prose-sm max-w-none ${Z}`,dangerouslySetInnerHTML:{__html:X},onClick:W},void 0,!1,void 0,this)};var p$=f0(D6(),1);var SK="",$K=()=>({"Content-Type":"application/json","X-Session-Id":o4()});var kZ6=async(J,{parentId:Z,name:Q,content:K,subtype:X,fields:U})=>{let Y=await fetch(`${SK}/api/p/${J}/documents`,{method:"POST",headers:$K(),body:JSON.stringify({parentId:Z,name:Q,content:K,subtype:X,fields:U})});return P9(Y,"Failed to create document")},vZ6=async(J,{parentId:Z,name:Q,content:K,subtype:X,fields:U})=>{let Y=await fetch(`${SK}/api/p/${J}/templates`,{method:"POST",headers:$K(),body:JSON.stringify({parentId:Z,name:Q,content:K,subtype:X,fields:U})});return P9(Y,"Failed to create template")},bd=async(J,Z,{includeDraft:Q}={})=>{let K=new URLSearchParams;if(Q)K.set("includeDraft","true");let X=K.toString(),U=`${SK}/api/p/${J}/documents/${Z}${X?`?${X}`:""}`,Y=await fetch(U,{headers:$K()});return P9(Y,"Failed to fetch document")},fZ6=async(J,Z,Q)=>{let K=await fetch(`${SK}/api/p/${J}/documents/${Z}/draft`,{method:"PUT",headers:$K(),body:JSON.stringify({content:Q})});return P9(K,"Failed to save draft")},_Z6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/publish`,{method:"POST",headers:$K()});return P9(Q,"Failed to publish document")},bZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/draft`,{method:"DELETE",headers:$K()});return P9(Q,"Failed to discard draft")},xZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/versions`,{headers:$K()});return P9(Q,"Failed to fetch versions")},TP=async(J,Z,Q)=>{let K=await fetch(`${SK}/api/p/${J}/documents/${Z}/versions/${Q}`,{headers:$K()});return P9(K,"Failed to fetch version")},hZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}`,{method:"DELETE",headers:$K()});return P9(Q,"Failed to delete document")},yZ6=async(J,Z,{path:Q,parentId:K})=>{let X=await fetch(`${SK}/api/p/${J}/documents/${Z}`,{method:"PATCH",headers:$K(),body:JSON.stringify({path:Q,parentId:K})});return P9(X,"Failed to update document path")},xd=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/edit-state`,{method:"POST",headers:$K()});if(Q.status===409)return Q.json();return P9(Q,"Failed to set edit state")},HM=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/edit-state`,{method:"DELETE",headers:$K()});return P9(Q,"Failed to clear edit state")},gZ6=async(J,Z)=>{let Q=await fetch(`${SK}/api/p/${J}/documents/${Z}/parameters`,{headers:$K()});return P9(Q,"Failed to fetch parameters")},mZ6=async(J,Z,{params:Q,target:K,targetOptions:X}={})=>{let U=await fetch(`${SK}/api/p/${J}/documents/${Z}/render`,{method:"POST",headers:$K(),body:JSON.stringify({params:Q,target:K,targetOptions:X})});return P9(U,"Failed to render template")},uZ6=async(J,Z,Q)=>{let K=new URLSearchParams;if(Q)K.set("store",Q);let X=K.toString(),U=`${SK}/api/p/${J}/templates/by-type/${Z}${X?`?${X}`:""}`,Y=await fetch(U,{headers:$K()});return P9(Y,"Failed to fetch templates by type")};var XG=(J,Z)=>{return iZ({queryKey:["document",Z],queryFn:()=>bd(J,Z),enabled:!!J&&!!Z})},CP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,content:K})=>fZ6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},SP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>_Z6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["versions",K]}),Z.invalidateQueries({queryKey:["folderContents"]}),Z.invalidateQueries({queryKey:["parameters",K]})}})},$P=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>bZ6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},kP=(J,Z)=>{return iZ({queryKey:["versions",Z],queryFn:()=>xZ6(J,Z),enabled:!!J&&!!Z})},vP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>hZ6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["versions",K]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},T3=(J)=>{let Z=r9();return I4({mutationFn:({parentId:Q,name:K,content:X,subtype:U,fields:Y})=>kZ6(J,{parentId:Q,name:K,content:X,subtype:U,fields:Y}),onSuccess:()=>{Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},pZ6=(J)=>{let Z=r9();return I4({mutationFn:({parentId:Q,name:K,content:X,subtype:U,fields:Y})=>vZ6(J,{parentId:Q,name:K,content:X,subtype:U,fields:Y}),onSuccess:()=>{Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},fP=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,path:K,parentId:X})=>yZ6(J,Q,{path:K,parentId:X}),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["document",K]}),Z.invalidateQueries({queryKey:["documents"]}),Z.invalidateQueries({queryKey:["folderContents"]})}})},_P=(J,Z)=>{return iZ({queryKey:["parameters",Z],queryFn:()=>gZ6(J,Z),enabled:!!J&&!!Z,select:(Q)=>{let K=Q?.parameters?Object.entries(Q.parameters).map(([w,P])=>{let{label:V,type:D,required:T,description:C,...S}=P;return{name:w,label:V,primitive_type:D??"string",required:T??!1,description:C,config:Object.keys(S).length>0?S:void 0}}):[],X=Q?.detectedVariables??[],U=Q?.target==="stdout"?"clipboard":Q?.target||null,Y=Q?.targetPath||null,z=Q?.path||null,G=Q?.targetParentId||null,W=Q?.targetName||null,q=Q?.targetRoot||null,H=Q?.targetStore||null,B=Q?.targetJobName||null,M=Q?.targetJobAgent||null,O=Q?.targetJobModel||null,A=Q?.targetJobWorktree||null,N=Q?.targetJobSkipDialog??!1,R=Q?.skipDialog??!1;return{parameters:K,detectedVariables:X,target:U,targetPath:Y,path:z,targetParentId:G,targetName:W,targetRoot:q,targetStore:H,targetJobName:B,targetJobAgent:M,targetJobModel:O,targetJobWorktree:A,targetJobSkipDialog:N,skipDialog:R}}})},hd=(J)=>{return I4({mutationFn:({id:Z,params:Q,target:K,targetOptions:X})=>mZ6(J,Z,{params:Q,target:K,targetOptions:X})})},cZ6=(J,Z)=>{return iZ({queryKey:["templatesByType",J,Z],queryFn:()=>uZ6(J,Z),enabled:!!J&&!!Z})};var V4=f0(e6(),1),bP=({open:J,onOpenChange:Z,projectId:Q,documentId:K,anchor:X,onNavigate:U})=>{let{storeCode:Y}=EQ(),{data:z,isLoading:G,isError:W,refetch:q}=XG(Q,K),H=z?.name??"",B=z?.draftContent??z?.resolvedContent??z?.publishedContent??"",M=z?.ancestorFolderIds??[],O=z?.subtype,A=K?.startsWith("At"),N=A?null:M.find((x)=>x?.startsWith("As"))??null,R=A?null:M.find((x)=>x?.startsWith("Aj"))??null,w=!A&&O==="task",P=A?"Context: Templates":R?"Context: Jobs tab":N?"Context: Stories tab":"Context: Documents tab",V=z?.hasDraft??!1,D=A?V?nX:sX:O==="task"?V?hq:aX:O==="cartridge"?xq:O==="prompt"?zz:V?nX:rZ,T=()=>{if(O==="task"){let x=z?.fields?.state,m=JR(x,V);if(m)return{fill:m,stroke:"#000000"}}if(V)return{fill:"#fcd34d",stroke:"#000000"};return{}},C=K?cG(K):"A",S=Y?`/store/${Y}`:"",f=p$.useRef(null),h=p$.useCallback(()=>{if(X&&f.current)setTimeout(()=>{let x=f.current.querySelector(`#${CSS.escape(X)}`);if(x)x.scrollIntoView({behavior:"smooth",block:"start"})},0)},[X]),k=()=>{let x;if(A)x=`/project/${Q}${S}/templates?id=${K}`;else if(R)x=`/project/${Q}${S}/job/${R}`;else if(N)x=`/project/${Q}${S}/stories?expanded=${N}&id=${K}`;else x=`/project/${Q}${S}/documents?id=${K}`;Z(!1),U(x)},$=()=>{let x=`/project/${Q}${S}/stories?expanded=${N}&tab=tasks`;Z(!1),U(x)},v=async()=>{try{await navigator.clipboard.writeText(B),bZ.success("Contents copied")}catch(x){console.error("Failed to copy contents:",x),bZ.error("Failed to copy")}},_=async()=>{try{await navigator.clipboard.writeText(K),bZ.success("ID copied")}catch(x){console.error("Failed to copy ID:",x),bZ.error("Failed to copy")}},b=async({type:x,id:m,path:g,anchor:u})=>{if(x==="anchor")return;let d=u?`#${u}`:"";if(x==="id"){let l=m?.charAt(1)?.toLowerCase(),r;if(l==="j")r=`/project/${Q}${S}/job/${m}${d}`;else if(l==="s")r=`/project/${Q}${S}/stories?expanded=${m}${d}`;else if(l==="f")try{let o=await g5(Q,m),Y0=o?.path||"";if(Y0.startsWith("Templates/"))r=`/project/${Q}${S}/templates?id=${m}${d}`;else if(Y0.startsWith("Stories/")){let e=o?.parentId?.startsWith("As")?o.parentId:null;if(!e){let B0=o?.parentId?await g5(Q,o.parentId):null;while(B0&&!e)if(B0.parentId?.startsWith("As"))e=B0.parentId;else if(B0.id?.startsWith("As"))e=B0.id;else B0=B0.parentId?await g5(Q,B0.parentId):null}if(e)r=`/project/${Q}${S}/stories?expanded=${e}&id=${m}&tab=documents${d}`;else r=`/project/${Q}${S}/stories?id=${m}${d}`}else r=`/project/${Q}${S}/documents?id=${m}${d}`}catch{r=`/project/${Q}${S}/documents?id=${m}${d}`}else r=`/project/${Q}${S}/${l==="t"?"templates":"documents"}?id=${m}${d}`;Z(!1),U(r)}else if(x==="path"){let l=`/project/${Q}${S}${g}${d}`;Z(!1),U(l)}};return V4.jsxDEV(sJ,{open:J,onOpenChange:Z,children:V4.jsxDEV(vJ,{className:"max-w-6xl max-h-[85vh] flex flex-col",children:[V4.jsxDEV(fJ,{className:"flex-shrink-0",children:[V4.jsxDEV("div",{className:"relative flex items-center min-h-[28px]",children:[V4.jsxDEV("span",{className:"text-sm text-muted-foreground",children:P},void 0,!1,void 0,this),V4.jsxDEV(_J,{className:"absolute inset-0 flex items-center gap-2 justify-center pointer-events-none",children:[!G&&V4.jsxDEV(V4.Fragment,{children:[V4.jsxDEV(D,{className:"h-5 w-5 shrink-0",...T()},void 0,!1,void 0,this),V4.jsxDEV("span",{children:H||(A?"Template":"Document")},void 0,!1,void 0,this),V4.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${pq[C]||pq.A}`,children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&"Loading..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V4.jsxDEV("div",{className:"flex flex-wrap gap-2 pt-2",children:[V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:k,disabled:G,children:[V4.jsxDEV(qV,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"View in Context"]},void 0,!0,void 0,this),w&&N&&V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:$,disabled:G,children:[V4.jsxDEV(sH,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"View on Kanban"]},void 0,!0,void 0,this),V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:v,disabled:G||!B,children:[V4.jsxDEV(kZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Contents"]},void 0,!0,void 0,this),V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:_,children:[V4.jsxDEV(kZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy ID"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V4.jsxDEV("div",{ref:f,className:"flex-1 overflow-auto min-h-0 mt-4",children:G?V4.jsxDEV("div",{className:"flex items-center justify-center py-8",children:V4.jsxDEV(c7,{className:"w-6 h-6 animate-spin"},void 0,!1,void 0,this)},void 0,!1,void 0,this):W?V4.jsxDEV("div",{className:"text-center py-8",children:[V4.jsxDEV(B7,{className:"w-6 h-6 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),V4.jsxDEV("p",{className:"text-muted-foreground mb-2",children:"Failed to load document"},void 0,!1,void 0,this),V4.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>q(),children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):B?V4.jsxDEV(yY,{markdown:B,onInternalLinkClick:b,onRenderComplete:h},void 0,!1,void 0,this):V4.jsxDEV("p",{className:"text-muted-foreground text-center py-8",children:"No content"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var gY=f0(D6(),1);var BM=()=>{let[J,Z]=tE(),{"*":Q}=EQ(),K=Q||null,X=a4(),U=gY.useMemo(()=>{return X.hash?.slice(1)||null},[X.hash]),Y=J.get("id")||null,z=J.get("edit")==="true",G=gY.useMemo(()=>{let C=J.get("selected");return C?C.split(",").filter(Boolean):[]},[J]),W=J.get("tab")||null,q=J.get("expanded")||null,H=J.get("from")||null,B=K?"path":Y?"id":null,M=z,O=lq(Y),A=z&&Y&&!O;gY.useMemo(()=>{let C=!1,S=new URLSearchParams(J);if(Y&&G.length>0)S.delete("selected"),C=!0;if(K&&G.length>0)S.delete("selected"),C=!0;if(z&&!K&&(!Y||O))S.delete("edit"),C=!0;if(W&&!q)S.delete("tab"),C=!0;if(C)queueMicrotask(()=>{Z(S,{replace:!0})})},[J,Y,G,z,O,K,W,q,Z]);let N=gY.useCallback((C,S={})=>{let{history:f="push",preserveEdit:h=!1,edit:k}=S;Z(($)=>{let v=$.get("id")||null,_=$.get("edit")==="true";if(C===v&&k===_)return $;let b=new URLSearchParams($);if(C)b.set("id",C);else b.delete("id");if(k===!0&&C&&!lq(C))b.set("edit","true");else if(!h||!C||lq(C))b.delete("edit");return b.delete("selected"),b},{replace:f==="replace"})},[Z]),R=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;if(C===z)return;if(C&&!K&&(!Y||O))return;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("edit","true");else k.delete("edit");return k},{replace:f==="replace"})},[Z,z,Y,O,K]),w=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C.length>0){let $=C.slice(0,20);k.set("selected",$.join(",")),k.delete("id"),k.delete("edit")}else k.delete("selected");return k},{replace:f==="replace"})},[Z]),P=gY.useCallback((C={})=>{let{history:S="replace"}=C;Z((f)=>{let h=new URLSearchParams(f);return h.delete("id"),h.delete("edit"),h.delete("selected"),h},{replace:S==="replace"})},[Z]),V=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("tab",C);else k.delete("tab");return k},{replace:f==="replace"})},[Z]),D=gY.useCallback((C,S={})=>{let{history:f="push",withSelection:h}=S;Z((k)=>{let $=new URLSearchParams(k);if(C)if($.set("expanded",C),h)$.set("id",h);else $.delete("id");else $.delete("expanded"),$.delete("tab"),$.delete("id");return $.delete("edit"),$},{replace:f==="replace"})},[Z]),T=gY.useCallback((C,S={})=>{let{history:f="replace"}=S;Z((h)=>{let k=new URLSearchParams(h);if(C)k.set("from",C);else k.delete("from");return k},{replace:f==="replace"})},[Z]);return{selectedId:Y,isEditMode:A,collectedIds:G,documentPath:K,addressingScheme:B,isEditRequested:M,anchorFragment:U,activeTab:W,expandedId:q,fromContext:H,setSelectedId:N,setEditMode:R,setCollectedIds:w,clearSelection:P,setActiveTab:V,setExpandedId:D,setFromContext:T}};var T8=f0(e6(),1),yd=({projectId:J,rootFolderId:Z,selectedId:Q,selectedItemData:K,versions:X,draftContent:U,serverContent:Y,isDirty:z,hasDraft:G,isEditMode:W,setEditMode:q,viewingVersion:H,versionContent:B,showVersions:M,setShowVersions:O,showRename:A,setShowRename:N,renameFilename:R,setRenameFilename:w,actionError:P,setActionError:V,saveStatus:D,handleEditorChange:T,handleViewVersion:C,handleBackToEdit:S,handlePublish:f,handleDiscardDraft:h,handleRetry:k,handleOpenRename:$,handleRename:v,handleCopyContent:_,handleCopyIds:b,setShowDeleteConfirm:x,publishMutation:m,discardMutation:g,updatePathMutation:u,debouncedSave:d,collectedIds:l,typeName:r,triggerEditMode:o,setTriggerEditMode:Y0})=>{let e=r9(),{setSelectedId:B0,documentPath:Q0,anchorFragment:M0}=BM(),W0=dJ(),H0=a4(),U0=Z?.startsWith("As")?Z:null,K0=async({type:d0,id:R0,path:P0,anchor:s})=>{if(d0==="anchor"){W0(`${H0.pathname}${H0.search}#${s}`,{replace:!0});return}let A0=s?`#${s}`:"";if(d0==="id"){let i=R0?.charAt(1)?.toLowerCase();if(i==="t"){J0({id:R0,anchor:s||null});return}if(i==="d")try{let N0=await bd(J,R0),x0=N0?.ancestorFolderIds?.find((D0)=>D0?.startsWith("As")),$0=N0?.ancestorFolderIds?.some((D0)=>D0?.startsWith("Aj"));if(U0)if(x0===U0);else{J0({id:R0,anchor:s||null});return}else if(x0||$0){J0({id:R0,anchor:s||null});return}}catch{}let L0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?)/)?.[1];if(i==="s"){W0(`${L0}/stories?expanded=${R0}${A0}`);return}if(i==="j"){W0(`${L0}/job/${R0}${A0}`);return}if(i==="f"){try{let N0=await g5(J,R0),x0=N0?.path||"";if(x0.startsWith("Templates/"))W0(`${L0}/templates?id=${R0}${A0}`);else if(x0.startsWith("Stories/")){let $0=N0?.parentId?.startsWith("As")?N0.parentId:null;if(!$0){let D0=N0?.parentId?await g5(J,N0.parentId):null;while(D0&&!$0)if(D0.parentId?.startsWith("As"))$0=D0.parentId;else if(D0.id?.startsWith("As"))$0=D0.id;else D0=D0.parentId?await g5(J,D0.parentId):null}if($0)W0(`${L0}/stories?expanded=${$0}&id=${R0}&tab=documents${A0}`);else W0(`${L0}/stories?id=${R0}${A0}`)}else W0(`${L0}/documents?id=${R0}${A0}`)}catch{W0(`${L0}/documents?id=${R0}${A0}`)}return}if(Q0){let N0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?\/(?:documents|templates))/)?.[1];if(N0){W0(`${N0}?id=${R0}${A0}`);return}}if(s)W0(`${H0.pathname}?id=${R0}${A0}`);else B0(R0)}else if(d0==="path")W0(`/project/${J}${P0}${A0}`)},[O0,J0]=zQ.useState(null),[j0,q0]=zQ.useState(null),v0=j0===Q,[Z0,e0]=zQ.useState(!1),X0=zQ.useRef(Q),T0=zQ.useRef(!1),_0=zQ.useRef(null);zQ.useEffect(()=>{if(M0&&_0.current)setTimeout(()=>{let d0=_0.current.querySelector(`#${CSS.escape(M0)}`);if(d0)d0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[M0]);let l0=zQ.useCallback(()=>{if(M0&&_0.current)setTimeout(()=>{let d0=_0.current.querySelector(`#${CSS.escape(M0)}`);if(d0)d0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[M0]),b0=W&&v0,y0=zQ.useMemo(()=>{if(!K||!K.editState)return!1;let d0=o4();return K.editState.sessionId!==d0},[K]);zQ.useEffect(()=>{let d0=X0.current;if(X0.current=Q,v0&&d0&&d0!==Q)HM(J,d0).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",d0]})}).catch((R0)=>{console.error("Failed to clear edit state on selection change:",R0)}),q0(null);if(W&&Q&&!v0)xd(J,Q).then((R0)=>{if(R0.success)q0(Q),e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]});else q(!1),V(`Document is currently being edited. Try again in ${Math.ceil(R0.meta?.timeoutSeconds/60)} minutes.`)}).catch((R0)=>{q(!1),V(R0.message)});if(!W&&v0&&Q)HM(J,Q).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]})}).catch((R0)=>{console.error("Failed to clear edit state:",R0)}),q0(null)},[W,Q,v0,J,q,V,e]),zQ.useEffect(()=>{if(!K||!Q)return;let d0=K.editState,R0=o4();if(d0&&d0.sessionId===R0){let P0=new Date(d0.lastActivityAt),s=new Date(Date.now()-3600000);if(P0>=s){if(q0(Q),!W)q(!0)}}else if(j0===Q&&d0&&d0.sessionId!==R0){if(q0(null),W)e0(!0),q(!1)}},[K,Q]),zQ.useEffect(()=>{if(o)Y0(!1)},[o,Y0]),zQ.useEffect(()=>{console.log("[BUTTON] Visibility check:",{viewingVersion:H,isDirty:z,hasDraft:G,saveStatus:D,visible:!H&&(z||G||D==="saving")})},[H,z,G,D]),zQ.useEffect(()=>{return()=>{if(j0&&J)HM(J,j0).catch((d0)=>{console.error("Failed to clear edit state on unmount:",d0)})}},[j0,J]);let p0=async()=>{console.log("[BUTTON] Publish button clicked"),await f()},m0=async()=>{if(l&&l.length>0)try{let d0=await Promise.all(l.map(async(R0)=>{let s=await(await fetch(`/api/p/${J}/documents/${R0}`,{headers:{"Content-Type":"application/json"}})).json(),A0=s.draftContent??s.publishedContent??"";return`=== [${R0}] - ${s.path||R0} ===
3084
3084
  ${A0}`}));await navigator.clipboard.writeText(d0.join(`
3085
3085
 
3086
3086
  `)),bZ.success("Contents copied")}catch(d0){V("Failed to copy contents")}else _()};return T8.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0",children:[T8.jsxDEV("div",{className:"flex items-center gap-2 mb-3",children:[!H&&T8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>q(!W),disabled:y0,children:b0?T8.jsxDEV(T8.Fragment,{children:[T8.jsxDEV(oH,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"View"]},void 0,!0,void 0,this):y0?T8.jsxDEV(T8.Fragment,{children:[T8.jsxDEV(Yz,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Edit"]},void 0,!0,void 0,this):T8.jsxDEV(T8.Fragment,{children:[T8.jsxDEV(N1,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Edit"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!H&&T8.jsxDEV(g6,{onClick:$,variant:"outline",size:"sm",children:[T8.jsxDEV(Gz,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Rename"]},void 0,!0,void 0,this),!H&&(z||G||D==="saving")&&T8.jsxDEV(g6,{onMouseDown:()=>{T0.current=!0},onClick:p0,disabled:m.isPending,variant:"outline",size:"sm",children:[T8.jsxDEV(yG,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),m.isPending?"Publishing...":"Publish"]},void 0,!0,void 0,this),!H&&G&&T8.jsxDEV(g6,{onClick:h,disabled:g.isPending,variant:"outline",size:"sm",children:[T8.jsxDEV(gU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),g.isPending?"Discarding...":"Discard"]},void 0,!0,void 0,this),!H&&T8.jsxDEV(g6,{onClick:()=>x(!0),variant:"destructive",size:"sm",children:[T8.jsxDEV(gU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this),T8.jsxDEV(s9,{content:"Copy contents to clipboard",children:T8.jsxDEV(g6,{onClick:m0,variant:"outline",size:"sm",children:[T8.jsxDEV(kZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T8.jsxDEV(s9,{content:"Copy IDs to clipboard",children:T8.jsxDEV(g6,{onClick:b,variant:"outline",size:"sm",children:[T8.jsxDEV(bG,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"IDs"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"flex-1"},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"flex items-center gap-4",children:[b0&&!H&&T8.jsxDEV(Lj,{status:D,onRetry:k},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"text-right",children:[T8.jsxDEV(s9,{content:K.path,children:T8.jsxDEV("div",{className:"font-medium text-base text-foreground",children:KY(K.path)},void 0,!1,void 0,this)},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"flex gap-1 justify-end",children:[G&&T8.jsxDEV("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-100 text-amber-800",children:["v",X.length+1," draft"]},void 0,!0,void 0,this),K.hasPublished&&T8.jsxDEV("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-800",children:["v",X.length," published"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T8.jsxDEV(s9,{content:"Version History",children:T8.jsxDEV(g6,{variant:"ghost",size:"icon",onClick:()=>O(!M),children:T8.jsxDEV(JB,{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)]},void 0,!0,void 0,this),Z0&&T8.jsxDEV("div",{className:"mb-3 p-4 border border-red-300 rounded-md bg-red-50",children:T8.jsxDEV("div",{className:"flex items-start gap-3",children:[T8.jsxDEV(B7,{className:"w-5 h-5 text-red-600 shrink-0 mt-0.5"},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"flex-1",children:[T8.jsxDEV("p",{className:"text-sm font-medium text-red-800 mb-2",children:"Your edit session has expired"},void 0,!1,void 0,this),T8.jsxDEV("p",{className:"text-sm text-red-700 mb-3",children:"Another user may have taken over editing, or your session timed out after 1 hour of inactivity. Your changes are still visible below."},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"flex gap-2",children:[T8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(U),bZ.success("Copied to clipboard"),V(null)},children:[T8.jsxDEV(kZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy My Changes"]},void 0,!0,void 0,this),T8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>{e0(!1),q0(null),q(!1),window.location.reload()},children:[T8.jsxDEV(wO,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Reload Document"]},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),P&&T8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center justify-between",children:[T8.jsxDEV("div",{className:"flex items-center gap-2 text-destructive",children:[T8.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),T8.jsxDEV("span",{className:"text-sm",children:P},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T8.jsxDEV(g6,{variant:"ghost",size:"icon",onClick:()=>V(null),className:"h-6 w-6",children:T8.jsxDEV(R1,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A&&T8.jsxDEV("div",{className:"mb-3 p-3 border border-border rounded-md bg-muted",children:[T8.jsxDEV("div",{className:"flex items-center gap-2 text-foreground mb-2",children:[T8.jsxDEV(N1,{className:"w-4 h-4"},void 0,!1,void 0,this),T8.jsxDEV("span",{className:"font-medium",children:"Rename document"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T8.jsxDEV("input",{type:"text",value:R,onChange:(d0)=>w(d0.target.value),placeholder:"New filename",className:"w-full px-3 py-2 text-sm border border-border rounded bg-background text-foreground mb-3",autoFocus:!0,onKeyDown:(d0)=>{if(d0.key==="Enter")v();if(d0.key==="Escape")N(!1)}},void 0,!1,void 0,this),T8.jsxDEV("div",{className:"flex gap-2",children:[T8.jsxDEV(g6,{onClick:v,variant:"default",size:"sm",disabled:u.isPending||!R.trim(),children:u.isPending?"Renaming...":"Rename"},void 0,!1,void 0,this),T8.jsxDEV(g6,{onClick:()=>N(!1),variant:"outline",size:"sm",children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M&&T8.jsxDEV("div",{className:"mb-3 p-3 bg-muted rounded-md",children:[T8.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Version History"},void 0,!1,void 0,this),X.length===0?T8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"No published versions yet."},void 0,!1,void 0,this):T8.jsxDEV("div",{className:"space-y-1",children:X.map((d0)=>T8.jsxDEV("button",{onClick:()=>C(d0.versionNumber),className:`w-full text-left px-2 py-1 text-sm rounded hover:bg-accent ${H===d0.versionNumber?"bg-accent":""}`,children:["v",d0.versionNumber," - ",new Date(d0.publishedAt).toLocaleString()]},d0.versionNumber,!0,void 0,this))},void 0,!1,void 0,this),H&&T8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:S,className:"mt-2",children:"Back to Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H?T8.jsxDEV("div",{ref:_0,className:"flex-1 min-h-0 p-4 border border-border rounded-md bg-muted overflow-auto",children:[T8.jsxDEV("div",{className:"text-xs text-muted-foreground mb-3",children:["Viewing version ",H," (read-only)"]},void 0,!0,void 0,this),T8.jsxDEV(yY,{markdown:B??"",onInternalLinkClick:K0,onRenderComplete:l0},void 0,!1,void 0,this)]},void 0,!0,void 0,this):b0?T8.jsxDEV("div",{className:"flex-1 min-h-0",children:T8.jsxDEV(Ij,{value:U,onChange:T,onBlur:()=>{if(T0.current){console.log("[BLUR] Skipping flush - publish pending"),T0.current=!1;return}console.log("[BLUR] Monaco blur - calling flush"),d.flush()},path:K.path,height:"100%",projectId:J,storeCode:Q?Q[0]:"A"},void 0,!1,void 0,this)},void 0,!1,void 0,this):T8.jsxDEV("div",{ref:_0,className:"flex-1 min-h-0 p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:K.draftContent||K.resolvedContent||K.publishedContent?T8.jsxDEV(yY,{markdown:K.draftContent??K.resolvedContent??K.publishedContent,onInternalLinkClick:K0,onRenderComplete:l0},void 0,!1,void 0,this):T8.jsxDEV("p",{className:"text-muted-foreground italic",children:"No content yet. Click Edit to start."},void 0,!1,void 0,this)},void 0,!1,void 0,this),T8.jsxDEV(bP,{open:!!O0,onOpenChange:(d0)=>!d0&&J0(null),projectId:J,documentId:O0?.id,anchor:O0?.anchor,onNavigate:W0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var UG0=Eh({type:"d",typeName:"Document",typeNamePlural:"Documents",DetailPanel:yd,hooks:{useItem:XG,useCreate:T3,useSaveDraft:CP,usePublish:SP,useDiscard:$P,useVersions:kP,useDelete:vP,useUpdatePath:fP,getVersion:TP},enableCollectionMode:!0});var SZ=f0(D6(),1);var n4=f0(D6(),1);var Zr=f0(D6(),1);var q7=f0(D6(),1),i$=(J)=>J.type==="checkbox",C3=(J)=>J instanceof Date,kX=(J)=>J==null,ZQ6=(J)=>typeof J==="object",WQ=(J)=>!kX(J)&&!Array.isArray(J)&&ZQ6(J)&&!C3(J),QQ6=(J)=>WQ(J)&&J.target?i$(J.target)?J.target.checked:J.target.value:J,CY8=(J)=>J.substring(0,J.search(/\.\d+(\.|$)/))||J,KQ6=(J,Z)=>J.has(CY8(Z)),SY8=(J)=>{let Z=J.constructor&&J.constructor.prototype;return WQ(Z)&&Z.hasOwnProperty("isPrototypeOf")},qG0=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function sQ(J){let Z,Q=Array.isArray(J),K=typeof FileList<"u"?J instanceof FileList:!1;if(J instanceof Date)Z=new Date(J);else if(!(qG0&&(J instanceof Blob||K))&&(Q||WQ(J))){if(Z=Q?[]:Object.create(Object.getPrototypeOf(J)),!Q&&!SY8(J))Z=J;else for(let X in J)if(J.hasOwnProperty(X))Z[X]=sQ(J[X])}else return J;return Z}var pd=(J)=>/^\w*$/.test(J),CZ=(J)=>J===void 0,HG0=(J)=>Array.isArray(J)?J.filter(Boolean):[],BG0=(J)=>HG0(J.replace(/["|']|\]/g,"").split(/\.|\[/)),v8=(J,Z,Q)=>{if(!Z||!WQ(J))return Q;let K=(pd(Z)?[Z]:BG0(Z)).reduce((X,U)=>kX(X)?X:X[U],J);return CZ(K)||K===J?CZ(J[Z])?Q:J[Z]:K},PU=(J)=>typeof J==="boolean",h4=(J,Z,Q)=>{let K=-1,X=pd(Z)?[Z]:BG0(Z),U=X.length,Y=U-1;while(++K<U){let z=X[K],G=Q;if(K!==Y){let W=J[z];G=WQ(W)||Array.isArray(W)?W:!isNaN(+X[K+1])?[]:{}}if(z==="__proto__"||z==="constructor"||z==="prototype")return;J[z]=G,J=J[z]}},gd={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},UG={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},zH={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},FG0=q7.default.createContext(null);FG0.displayName="HookFormContext";var r$=()=>q7.default.useContext(FG0),XQ6=(J)=>{let{children:Z,...Q}=J;return q7.default.createElement(FG0.Provider,{value:Q},Z)},UQ6=(J,Z,Q,K=!0)=>{let X={defaultValues:Z._defaultValues};for(let U in J)Object.defineProperty(X,U,{get:()=>{let Y=U;if(Z._proxyFormState[Y]!==UG.all)Z._proxyFormState[Y]=!K||UG.all;return Q&&(Q[Y]=!0),J[Y]}});return X},MG0=typeof window<"u"?q7.default.useLayoutEffect:q7.default.useEffect;function $Y8(J){let Z=r$(),{control:Q=Z.control,disabled:K,name:X,exact:U}=J||{},[Y,z]=q7.default.useState(Q._formState),G=q7.default.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1});return MG0(()=>Q._subscribe({name:X,formState:G.current,exact:U,callback:(W)=>{!K&&z({...Q._formState,...W})}}),[X,K,U]),q7.default.useEffect(()=>{G.current.isValid&&Q._setValid(!0)},[Q]),q7.default.useMemo(()=>UQ6(Y,Q,G.current,!1),[Y,Q])}var DU=(J)=>typeof J==="string",zG0=(J,Z,Q,K,X)=>{if(DU(J))return K&&Z.watch.add(J),v8(Q,J,X);if(Array.isArray(J))return J.map((U)=>(K&&Z.watch.add(U),v8(Q,U)));return K&&(Z.watchAll=!0),Q},GG0=(J)=>kX(J)||!ZQ6(J);function YG(J,Z,Q=new WeakSet){if(GG0(J)||GG0(Z))return Object.is(J,Z);if(C3(J)&&C3(Z))return J.getTime()===Z.getTime();let K=Object.keys(J),X=Object.keys(Z);if(K.length!==X.length)return!1;if(Q.has(J)||Q.has(Z))return!0;Q.add(J),Q.add(Z);for(let U of K){let Y=J[U];if(!X.includes(U))return!1;if(U!=="ref"){let z=Z[U];if(C3(Y)&&C3(z)||WQ(Y)&&WQ(z)||Array.isArray(Y)&&Array.isArray(z)?!YG(Y,z,Q):!Object.is(Y,z))return!1}}return!0}function kY8(J){let Z=r$(),{control:Q=Z.control,name:K,defaultValue:X,disabled:U,exact:Y,compute:z}=J||{},G=q7.default.useRef(X),W=q7.default.useRef(z),q=q7.default.useRef(void 0),H=q7.default.useRef(Q),B=q7.default.useRef(K);W.current=z;let[M,O]=q7.default.useState(()=>{let V=Q._getWatch(K,G.current);return W.current?W.current(V):V}),A=q7.default.useCallback((V)=>{let D=zG0(K,Q._names,V||Q._formValues,!1,G.current);return W.current?W.current(D):D},[Q._formValues,Q._names,K]),N=q7.default.useCallback((V)=>{if(!U){let D=zG0(K,Q._names,V||Q._formValues,!1,G.current);if(W.current){let T=W.current(D);if(!YG(T,q.current))O(T),q.current=T}else O(D)}},[Q._formValues,Q._names,U,K]);MG0(()=>{if(H.current!==Q||!YG(B.current,K))H.current=Q,B.current=K,N();return Q._subscribe({name:K,formState:{values:!0},exact:Y,callback:(V)=>{N(V.values)}})},[Q,Y,K,N]),q7.default.useEffect(()=>Q._removeUnmounted());let R=H.current!==Q,w=B.current,P=q7.default.useMemo(()=>{if(U)return null;let V=!R&&!YG(w,K);return R||V?A():null},[U,R,K,w,A]);return P!==null?P:M}function vY8(J){let Z=r$(),{name:Q,disabled:K,control:X=Z.control,shouldUnregister:U,defaultValue:Y,exact:z=!0}=J,G=KQ6(X._names.array,Q),W=q7.default.useMemo(()=>v8(X._formValues,Q,v8(X._defaultValues,Q,Y)),[X,Q,Y]),q=kY8({control:X,name:Q,defaultValue:W,exact:z}),H=$Y8({control:X,name:Q,exact:z}),B=q7.default.useRef(J),M=q7.default.useRef(void 0),O=q7.default.useRef(X.register(Q,{...J.rules,value:q,...PU(J.disabled)?{disabled:J.disabled}:{}}));B.current=J;let A=q7.default.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!v8(H.errors,Q)},isDirty:{enumerable:!0,get:()=>!!v8(H.dirtyFields,Q)},isTouched:{enumerable:!0,get:()=>!!v8(H.touchedFields,Q)},isValidating:{enumerable:!0,get:()=>!!v8(H.validatingFields,Q)},error:{enumerable:!0,get:()=>v8(H.errors,Q)}}),[H,Q]),N=q7.default.useCallback((V)=>O.current.onChange({target:{value:QQ6(V),name:Q},type:gd.CHANGE}),[Q]),R=q7.default.useCallback(()=>O.current.onBlur({target:{value:v8(X._formValues,Q),name:Q},type:gd.BLUR}),[Q,X._formValues]),w=q7.default.useCallback((V)=>{let D=v8(X._fields,Q);if(D&&V)D._f.ref={focus:()=>V.focus&&V.focus(),select:()=>V.select&&V.select(),setCustomValidity:(T)=>V.setCustomValidity(T),reportValidity:()=>V.reportValidity()}},[X._fields,Q]),P=q7.default.useMemo(()=>({name:Q,value:q,...PU(K)||H.disabled?{disabled:H.disabled||K}:{},onChange:N,onBlur:R,ref:w}),[Q,K,H.disabled,N,R,w,q]);return q7.default.useEffect(()=>{let V=X._options.shouldUnregister||U,D=M.current;if(D&&D!==Q&&!G)X.unregister(D);X.register(Q,{...B.current.rules,...PU(B.current.disabled)?{disabled:B.current.disabled}:{}});let T=(C,S)=>{let f=v8(X._fields,C);if(f&&f._f)f._f.mount=S};if(T(Q,!0),V){let C=sQ(v8(X._options.defaultValues,Q,B.current.defaultValue));if(h4(X._defaultValues,Q,C),CZ(v8(X._formValues,Q)))h4(X._formValues,Q,C)}return!G&&X.register(Q),M.current=Q,()=>{(G?V&&!X._state.action:V)?X.unregister(Q):T(Q,!1)}},[Q,X,G,U]),q7.default.useEffect(()=>{X._setDisabledField({disabled:K,name:Q})},[K,Q,X]),q7.default.useMemo(()=>({field:P,formState:H,fieldState:A}),[P,H,A])}var YQ6=(J)=>J.render(vY8(J));var cd=(J,Z,Q,K,X)=>Z?{...Q[J],types:{...Q[J]&&Q[J].types?Q[J].types:{},[K]:X||!0}}:{},l$=(J)=>Array.isArray(J)?J:[J],lZ6=()=>{let J=[];return{get observers(){return J},next:(X)=>{for(let U of J)U.next&&U.next(X)},subscribe:(X)=>{return J.push(X),{unsubscribe:()=>{J=J.filter((U)=>U!==X)}}},unsubscribe:()=>{J=[]}}};function zQ6(J,Z){let Q={};for(let K in J)if(J.hasOwnProperty(K)){let X=J[K],U=Z[K];if(X&&WQ(X)&&U){let Y=zQ6(X,U);if(WQ(Y))Q[K]=Y}else if(J[K])Q[K]=U}return Q}var kK=(J)=>WQ(J)&&!Object.keys(J).length,OG0=(J)=>J.type==="file",zG=(J)=>typeof J==="function",md=(J)=>{if(!qG0)return!1;let Z=J?J.ownerDocument:0;return J instanceof(Z&&Z.defaultView?Z.defaultView.HTMLElement:HTMLElement)},GQ6=(J)=>J.type==="select-multiple",LG0=(J)=>J.type==="radio",fY8=(J)=>LG0(J)||i$(J),YG0=(J)=>md(J)&&J.isConnected;function _Y8(J,Z){let Q=Z.slice(0,-1).length,K=0;while(K<Q)J=CZ(J)?K++:J[Z[K++]];return J}function bY8(J){for(let Z in J)if(J.hasOwnProperty(Z)&&!CZ(J[Z]))return!1;return!0}function GQ(J,Z){let Q=Array.isArray(Z)?Z:pd(Z)?[Z]:BG0(Z),K=Q.length===1?J:_Y8(J,Q),X=Q.length-1,U=Q[X];if(K)delete K[U];if(X!==0&&(WQ(K)&&kK(K)||Array.isArray(K)&&bY8(K)))GQ(J,Q.slice(0,-1));return J}var xY8=(J)=>{for(let Z in J)if(zG(J[Z]))return!0;return!1};function WQ6(J){return Array.isArray(J)||WQ(J)&&!xY8(J)}function WG0(J,Z={}){for(let Q in J){let K=J[Q];if(WQ6(K))Z[Q]=Array.isArray(K)?[]:{},WG0(K,Z[Q]);else if(!CZ(K))Z[Q]=!0}return Z}function hP(J,Z,Q){if(!Q)Q=WG0(Z);for(let K in J){let X=J[K];if(WQ6(X))if(CZ(Z)||GG0(Q[K]))Q[K]=WG0(X,Array.isArray(X)?[]:{});else hP(X,kX(Z)?{}:Z[K],Q[K]);else{let U=Z[K];Q[K]=!YG(X,U)}}return Q}var dZ6={value:!1,isValid:!1},iZ6={value:!0,isValid:!0},qQ6=(J)=>{if(Array.isArray(J)){if(J.length>1){let Z=J.filter((Q)=>Q&&Q.checked&&!Q.disabled).map((Q)=>Q.value);return{value:Z,isValid:!!Z.length}}return J[0].checked&&!J[0].disabled?J[0].attributes&&!CZ(J[0].attributes.value)?CZ(J[0].value)||J[0].value===""?iZ6:{value:J[0].value,isValid:!0}:iZ6:dZ6}return dZ6},HQ6=(J,{valueAsNumber:Z,valueAsDate:Q,setValueAs:K})=>CZ(J)?J:Z?J===""?NaN:J?+J:J:Q&&DU(J)?new Date(J):K?K(J):J,rZ6={isValid:!1,value:null},BQ6=(J)=>Array.isArray(J)?J.reduce((Z,Q)=>Q&&Q.checked&&!Q.disabled?{isValid:!0,value:Q.value}:Z,rZ6):rZ6;function nZ6(J){let Z=J.ref;if(OG0(Z))return Z.files;if(LG0(Z))return BQ6(J.refs).value;if(GQ6(Z))return[...Z.selectedOptions].map(({value:Q})=>Q);if(i$(Z))return qQ6(J.refs).value;return HQ6(CZ(Z.value)?J.ref.value:Z.value,J)}var hY8=(J,Z,Q,K)=>{let X={};for(let U of J){let Y=v8(Z,U);Y&&h4(X,U,Y._f)}return{criteriaMode:Q,names:[...J],fields:X,shouldUseNativeValidation:K}},ud=(J)=>J instanceof RegExp,c$=(J)=>CZ(J)?J:ud(J)?J.source:WQ(J)?ud(J.value)?J.value.source:J.value:J,sZ6=(J)=>({isOnSubmit:!J||J===UG.onSubmit,isOnBlur:J===UG.onBlur,isOnChange:J===UG.onChange,isOnAll:J===UG.all,isOnTouch:J===UG.onTouched}),aZ6="AsyncFunction",yY8=(J)=>!!J&&!!J.validate&&!!(zG(J.validate)&&J.validate.constructor.name===aZ6||WQ(J.validate)&&Object.values(J.validate).find((Z)=>Z.constructor.name===aZ6)),gY8=(J)=>J.mount&&(J.required||J.min||J.max||J.maxLength||J.minLength||J.pattern||J.validate),oZ6=(J,Z,Q)=>!Q&&(Z.watchAll||Z.watch.has(J)||[...Z.watch].some((K)=>J.startsWith(K)&&/^\.\w+/.test(J.slice(K.length)))),d$=(J,Z,Q,K)=>{for(let X of Q||Object.keys(J)){let U=v8(J,X);if(U){let{_f:Y,...z}=U;if(Y){if(Y.refs&&Y.refs[0]&&Z(Y.refs[0],X)&&!K)return!0;else if(Y.ref&&Z(Y.ref,Y.name)&&!K)return!0;else if(d$(z,Z))break}else if(WQ(z)){if(d$(z,Z))break}}}return};function tZ6(J,Z,Q){let K=v8(J,Q);if(K||pd(Q))return{error:K,name:Q};let X=Q.split(".");while(X.length){let U=X.join("."),Y=v8(Z,U),z=v8(J,U);if(Y&&!Array.isArray(Y)&&Q!==U)return{name:Q};if(z&&z.type)return{name:U,error:z};if(z&&z.root&&z.root.type)return{name:`${U}.root`,error:z.root};X.pop()}return{name:Q}}var mY8=(J,Z,Q,K)=>{Q(J);let{name:X,...U}=J;return kK(U)||Object.keys(U).length>=Object.keys(Z).length||Object.keys(U).find((Y)=>Z[Y]===(!K||UG.all))},uY8=(J,Z,Q)=>!J||!Z||J===Z||l$(J).some((K)=>K&&(Q?K===Z:K.startsWith(Z)||Z.startsWith(K))),pY8=(J,Z,Q,K,X)=>{if(X.isOnAll)return!1;else if(!Q&&X.isOnTouch)return!(Z||J);else if(Q?K.isOnBlur:X.isOnBlur)return!J;else if(Q?K.isOnChange:X.isOnChange)return J;return!0},cY8=(J,Z)=>!HG0(v8(J,Z)).length&&GQ(J,Z),lY8=(J,Z,Q)=>{let K=l$(v8(J,Q));return h4(K,"root",Z[Q]),h4(J,Q,K),J};function eZ6(J,Z,Q="validate"){if(DU(J)||Array.isArray(J)&&J.every(DU)||PU(J)&&!J)return{type:Q,message:DU(J)?J:"",ref:Z}}var xP=(J)=>WQ(J)&&!ud(J)?J:{value:J,message:""},JQ6=async(J,Z,Q,K,X,U)=>{let{ref:Y,refs:z,required:G,maxLength:W,minLength:q,min:H,max:B,pattern:M,validate:O,name:A,valueAsNumber:N,mount:R}=J._f,w=v8(Q,A);if(!R||Z.has(A))return{};let P=z?z[0]:Y,V=($)=>{if(X&&P.reportValidity)P.setCustomValidity(PU($)?"":$||""),P.reportValidity()},D={},T=LG0(Y),C=i$(Y),S=T||C,f=(N||OG0(Y))&&CZ(Y.value)&&CZ(w)||md(Y)&&Y.value===""||w===""||Array.isArray(w)&&!w.length,h=cd.bind(null,A,K,D),k=($,v,_,b=zH.maxLength,x=zH.minLength)=>{let m=$?v:_;D[A]={type:$?b:x,message:m,ref:Y,...h($?b:x,m)}};if(U?!Array.isArray(w)||!w.length:G&&(!S&&(f||kX(w))||PU(w)&&!w||C&&!qQ6(z).isValid||T&&!BQ6(z).isValid)){let{value:$,message:v}=DU(G)?{value:!!G,message:G}:xP(G);if($){if(D[A]={type:zH.required,message:v,ref:P,...h(zH.required,v)},!K)return V(v),D}}if(!f&&(!kX(H)||!kX(B))){let $,v,_=xP(B),b=xP(H);if(!kX(w)&&!isNaN(w)){let x=Y.valueAsNumber||(w?+w:w);if(!kX(_.value))$=x>_.value;if(!kX(b.value))v=x<b.value}else{let x=Y.valueAsDate||new Date(w),m=(d)=>new Date(new Date().toDateString()+" "+d),g=Y.type=="time",u=Y.type=="week";if(DU(_.value)&&w)$=g?m(w)>m(_.value):u?w>_.value:x>new Date(_.value);if(DU(b.value)&&w)v=g?m(w)<m(b.value):u?w<b.value:x<new Date(b.value)}if($||v){if(k(!!$,_.message,b.message,zH.max,zH.min),!K)return V(D[A].message),D}}if((W||q)&&!f&&(DU(w)||U&&Array.isArray(w))){let $=xP(W),v=xP(q),_=!kX($.value)&&w.length>+$.value,b=!kX(v.value)&&w.length<+v.value;if(_||b){if(k(_,$.message,v.message),!K)return V(D[A].message),D}}if(M&&!f&&DU(w)){let{value:$,message:v}=xP(M);if(ud($)&&!w.match($)){if(D[A]={type:zH.pattern,message:v,ref:Y,...h(zH.pattern,v)},!K)return V(v),D}}if(O){if(zG(O)){let $=await O(w,Q),v=eZ6($,P);if(v){if(D[A]={...v,...h(zH.validate,v.message)},!K)return V(v.message),D}}else if(WQ(O)){let $={};for(let v in O){if(!kK($)&&!K)break;let _=eZ6(await O[v](w,Q),P,v);if(_){if($={..._,...h(v,_.message)},V(_.message),K)D[A]=$}}if(!kK($)){if(D[A]={ref:P,...$},!K)return D}}}return V(!0),D},dY8={mode:UG.onSubmit,reValidateMode:UG.onChange,shouldFocusError:!0};function iY8(J={}){let Z={...dY8,...J},Q={submitCount:0,isDirty:!1,isReady:!1,isLoading:zG(Z.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:Z.errors||{},disabled:Z.disabled||!1},K={},X=WQ(Z.defaultValues)||WQ(Z.values)?sQ(Z.defaultValues||Z.values)||{}:{},U=Z.shouldUnregister?{}:sQ(X),Y={action:!1,mount:!1,watch:!1},z={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},G,W=0,q={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},H={...q},B={array:lZ6(),state:lZ6()},M=Z.criteriaMode===UG.all,O=(X0)=>(T0)=>{clearTimeout(W),W=setTimeout(X0,T0)},A=async(X0)=>{if(!Z.disabled&&(q.isValid||H.isValid||X0)){let T0=Z.resolver?kK((await C()).errors):await f(K,!0);if(T0!==Q.isValid)B.state.next({isValid:T0})}},N=(X0,T0)=>{if(!Z.disabled&&(q.isValidating||q.validatingFields||H.isValidating||H.validatingFields))(X0||Array.from(z.mount)).forEach((_0)=>{if(_0)T0?h4(Q.validatingFields,_0,T0):GQ(Q.validatingFields,_0)}),B.state.next({validatingFields:Q.validatingFields,isValidating:!kK(Q.validatingFields)})},R=(X0,T0=[],_0,l0,b0=!0,y0=!0)=>{if(l0&&_0&&!Z.disabled){if(Y.action=!0,y0&&Array.isArray(v8(K,X0))){let p0=_0(v8(K,X0),l0.argA,l0.argB);b0&&h4(K,X0,p0)}if(y0&&Array.isArray(v8(Q.errors,X0))){let p0=_0(v8(Q.errors,X0),l0.argA,l0.argB);b0&&h4(Q.errors,X0,p0),cY8(Q.errors,X0)}if((q.touchedFields||H.touchedFields)&&y0&&Array.isArray(v8(Q.touchedFields,X0))){let p0=_0(v8(Q.touchedFields,X0),l0.argA,l0.argB);b0&&h4(Q.touchedFields,X0,p0)}if(q.dirtyFields||H.dirtyFields)Q.dirtyFields=hP(X,U);B.state.next({name:X0,isDirty:k(X0,T0),dirtyFields:Q.dirtyFields,errors:Q.errors,isValid:Q.isValid})}else h4(U,X0,T0)},w=(X0,T0)=>{h4(Q.errors,X0,T0),B.state.next({errors:Q.errors})},P=(X0)=>{Q.errors=X0,B.state.next({errors:Q.errors,isValid:!1})},V=(X0,T0,_0,l0)=>{let b0=v8(K,X0);if(b0){let y0=v8(U,X0,CZ(_0)?v8(X,X0):_0);CZ(y0)||l0&&l0.defaultChecked||T0?h4(U,X0,T0?y0:nZ6(b0._f)):_(X0,y0),Y.mount&&!Y.action&&A()}},D=(X0,T0,_0,l0,b0)=>{let y0=!1,p0=!1,m0={name:X0};if(!Z.disabled){if(!_0||l0){if(q.isDirty||H.isDirty)p0=Q.isDirty,Q.isDirty=m0.isDirty=k(),y0=p0!==m0.isDirty;let d0=YG(v8(X,X0),T0);p0=!!v8(Q.dirtyFields,X0),d0?GQ(Q.dirtyFields,X0):h4(Q.dirtyFields,X0,!0),m0.dirtyFields=Q.dirtyFields,y0=y0||(q.dirtyFields||H.dirtyFields)&&p0!==!d0}if(_0){let d0=v8(Q.touchedFields,X0);if(!d0)h4(Q.touchedFields,X0,_0),m0.touchedFields=Q.touchedFields,y0=y0||(q.touchedFields||H.touchedFields)&&d0!==_0}y0&&b0&&B.state.next(m0)}return y0?m0:{}},T=(X0,T0,_0,l0)=>{let b0=v8(Q.errors,X0),y0=(q.isValid||H.isValid)&&PU(T0)&&Q.isValid!==T0;if(Z.delayError&&_0)G=O(()=>w(X0,_0)),G(Z.delayError);else clearTimeout(W),G=null,_0?h4(Q.errors,X0,_0):GQ(Q.errors,X0);if((_0?!YG(b0,_0):b0)||!kK(l0)||y0){let p0={...l0,...y0&&PU(T0)?{isValid:T0}:{},errors:Q.errors,name:X0};Q={...Q,...p0},B.state.next(p0)}},C=async(X0)=>{N(X0,!0);let T0=await Z.resolver(U,Z.context,hY8(X0||z.mount,K,Z.criteriaMode,Z.shouldUseNativeValidation));return N(X0),T0},S=async(X0)=>{let{errors:T0}=await C(X0);if(X0)for(let _0 of X0){let l0=v8(T0,_0);l0?h4(Q.errors,_0,l0):GQ(Q.errors,_0)}else Q.errors=T0;return T0},f=async(X0,T0,_0={valid:!0})=>{for(let l0 in X0){let b0=X0[l0];if(b0){let{_f:y0,...p0}=b0;if(y0){let m0=z.array.has(y0.name),d0=b0._f&&yY8(b0._f);if(d0&&q.validatingFields)N([y0.name],!0);let R0=await JQ6(b0,z.disabled,U,M,Z.shouldUseNativeValidation&&!T0,m0);if(d0&&q.validatingFields)N([y0.name]);if(R0[y0.name]){if(_0.valid=!1,T0)break}!T0&&(v8(R0,y0.name)?m0?lY8(Q.errors,R0,y0.name):h4(Q.errors,y0.name,R0[y0.name]):GQ(Q.errors,y0.name))}!kK(p0)&&await f(p0,T0,_0)}}return _0.valid},h=()=>{for(let X0 of z.unMount){let T0=v8(K,X0);T0&&(T0._f.refs?T0._f.refs.every((_0)=>!YG0(_0)):!YG0(T0._f.ref))&&Q0(X0)}z.unMount=new Set},k=(X0,T0)=>!Z.disabled&&(X0&&T0&&h4(U,X0,T0),!YG(d(),X)),$=(X0,T0,_0)=>zG0(X0,z,{...Y.mount?U:CZ(T0)?X:DU(X0)?{[X0]:T0}:T0},_0,T0),v=(X0)=>HG0(v8(Y.mount?U:X,X0,Z.shouldUnregister?v8(X,X0,[]):[])),_=(X0,T0,_0={})=>{let l0=v8(K,X0),b0=T0;if(l0){let y0=l0._f;if(y0){if(!y0.disabled&&h4(U,X0,HQ6(T0,y0)),b0=md(y0.ref)&&kX(T0)?"":T0,GQ6(y0.ref))[...y0.ref.options].forEach((p0)=>p0.selected=b0.includes(p0.value));else if(y0.refs)if(i$(y0.ref))y0.refs.forEach((p0)=>{if(!p0.defaultChecked||!p0.disabled)if(Array.isArray(b0))p0.checked=!!b0.find((m0)=>m0===p0.value);else p0.checked=b0===p0.value||!!b0});else y0.refs.forEach((p0)=>p0.checked=p0.value===b0);else if(OG0(y0.ref))y0.ref.value="";else if(y0.ref.value=b0,!y0.ref.type)B.state.next({name:X0,values:sQ(U)})}}(_0.shouldDirty||_0.shouldTouch)&&D(X0,b0,_0.shouldTouch,_0.shouldDirty,!0),_0.shouldValidate&&u(X0)},b=(X0,T0,_0)=>{for(let l0 in T0){if(!T0.hasOwnProperty(l0))return;let b0=T0[l0],y0=X0+"."+l0,p0=v8(K,y0);(z.array.has(X0)||WQ(b0)||p0&&!p0._f)&&!C3(b0)?b(y0,b0,_0):_(y0,b0,_0)}},x=(X0,T0,_0={})=>{let l0=v8(K,X0),b0=z.array.has(X0),y0=sQ(T0);if(h4(U,X0,y0),b0){if(B.array.next({name:X0,values:sQ(U)}),(q.isDirty||q.dirtyFields||H.isDirty||H.dirtyFields)&&_0.shouldDirty)B.state.next({name:X0,dirtyFields:hP(X,U),isDirty:k(X0,y0)})}else l0&&!l0._f&&!kX(y0)?b(X0,y0,_0):_(X0,y0,_0);oZ6(X0,z)&&B.state.next({...Q,name:X0}),B.state.next({name:Y.mount?X0:void 0,values:sQ(U)})},m=async(X0)=>{Y.mount=!0;let T0=X0.target,_0=T0.name,l0=!0,b0=v8(K,_0),y0=(d0)=>{l0=Number.isNaN(d0)||C3(d0)&&isNaN(d0.getTime())||YG(d0,v8(U,_0,d0))},p0=sZ6(Z.mode),m0=sZ6(Z.reValidateMode);if(b0){let d0,R0,P0=T0.type?nZ6(b0._f):QQ6(X0),s=X0.type===gd.BLUR||X0.type===gd.FOCUS_OUT,A0=!gY8(b0._f)&&!Z.resolver&&!v8(Q.errors,_0)&&!b0._f.deps||pY8(s,v8(Q.touchedFields,_0),Q.isSubmitted,m0,p0),i=oZ6(_0,z,s);if(h4(U,_0,P0),s){if(!T0||!T0.readOnly)b0._f.onBlur&&b0._f.onBlur(X0),G&&G(0)}else if(b0._f.onChange)b0._f.onChange(X0);let L0=D(_0,P0,s),N0=!kK(L0)||i;if(!s&&B.state.next({name:_0,type:X0.type,values:sQ(U)}),A0){if(q.isValid||H.isValid){if(Z.mode==="onBlur"){if(s)A()}else if(!s)A()}return N0&&B.state.next({name:_0,...i?{}:L0})}if(!s&&i&&B.state.next({...Q}),Z.resolver){let{errors:x0}=await C([_0]);if(y0(P0),l0){let $0=tZ6(Q.errors,K,_0),D0=tZ6(x0,K,$0.name||_0);d0=D0.error,_0=D0.name,R0=kK(x0)}}else if(N([_0],!0),d0=(await JQ6(b0,z.disabled,U,M,Z.shouldUseNativeValidation))[_0],N([_0]),y0(P0),l0){if(d0)R0=!1;else if(q.isValid||H.isValid)R0=await f(K,!0)}if(l0)b0._f.deps&&(!Array.isArray(b0._f.deps)||b0._f.deps.length>0)&&u(b0._f.deps),T(_0,R0,d0,L0)}},g=(X0,T0)=>{if(v8(Q.errors,T0)&&X0.focus)return X0.focus(),1;return},u=async(X0,T0={})=>{let _0,l0,b0=l$(X0);if(Z.resolver){let y0=await S(CZ(X0)?X0:b0);_0=kK(y0),l0=X0?!b0.some((p0)=>v8(y0,p0)):_0}else if(X0)l0=(await Promise.all(b0.map(async(y0)=>{let p0=v8(K,y0);return await f(p0&&p0._f?{[y0]:p0}:p0)}))).every(Boolean),!(!l0&&!Q.isValid)&&A();else l0=_0=await f(K);return B.state.next({...!DU(X0)||(q.isValid||H.isValid)&&_0!==Q.isValid?{}:{name:X0},...Z.resolver||!X0?{isValid:_0}:{},errors:Q.errors}),T0.shouldFocus&&!l0&&d$(K,g,X0?b0:z.mount),l0},d=(X0,T0)=>{let _0={...Y.mount?U:X};if(T0)_0=zQ6(T0.dirtyFields?Q.dirtyFields:Q.touchedFields,_0);return CZ(X0)?_0:DU(X0)?v8(_0,X0):X0.map((l0)=>v8(_0,l0))},l=(X0,T0)=>({invalid:!!v8((T0||Q).errors,X0),isDirty:!!v8((T0||Q).dirtyFields,X0),error:v8((T0||Q).errors,X0),isValidating:!!v8(Q.validatingFields,X0),isTouched:!!v8((T0||Q).touchedFields,X0)}),r=(X0)=>{X0&&l$(X0).forEach((T0)=>GQ(Q.errors,T0)),B.state.next({errors:X0?Q.errors:{}})},o=(X0,T0,_0)=>{let l0=(v8(K,X0,{_f:{}})._f||{}).ref,b0=v8(Q.errors,X0)||{},{ref:y0,message:p0,type:m0,...d0}=b0;h4(Q.errors,X0,{...d0,...T0,ref:l0}),B.state.next({name:X0,errors:Q.errors,isValid:!1}),_0&&_0.shouldFocus&&l0&&l0.focus&&l0.focus()},Y0=(X0,T0)=>zG(X0)?B.state.subscribe({next:(_0)=>("values"in _0)&&X0($(void 0,T0),_0)}):$(X0,T0,!0),e=(X0)=>B.state.subscribe({next:(T0)=>{if(uY8(X0.name,T0.name,X0.exact)&&mY8(T0,X0.formState||q,v0,X0.reRenderRoot))X0.callback({values:{...U},...Q,...T0,defaultValues:X})}}).unsubscribe,B0=(X0)=>{return Y.mount=!0,H={...H,...X0.formState},e({...X0,formState:H})},Q0=(X0,T0={})=>{for(let _0 of X0?l$(X0):z.mount){if(z.mount.delete(_0),z.array.delete(_0),!T0.keepValue)GQ(K,_0),GQ(U,_0);!T0.keepError&&GQ(Q.errors,_0),!T0.keepDirty&&GQ(Q.dirtyFields,_0),!T0.keepTouched&&GQ(Q.touchedFields,_0),!T0.keepIsValidating&&GQ(Q.validatingFields,_0),!Z.shouldUnregister&&!T0.keepDefaultValue&&GQ(X,_0)}B.state.next({values:sQ(U)}),B.state.next({...Q,...!T0.keepDirty?{}:{isDirty:k()}}),!T0.keepIsValid&&A()},M0=({disabled:X0,name:T0})=>{if(PU(X0)&&Y.mount||!!X0||z.disabled.has(T0))X0?z.disabled.add(T0):z.disabled.delete(T0)},W0=(X0,T0={})=>{let _0=v8(K,X0),l0=PU(T0.disabled)||PU(Z.disabled);if(h4(K,X0,{..._0||{},_f:{..._0&&_0._f?_0._f:{ref:{name:X0}},name:X0,mount:!0,...T0}}),z.mount.add(X0),_0)M0({disabled:PU(T0.disabled)?T0.disabled:Z.disabled,name:X0});else V(X0,!0,T0.value);return{...l0?{disabled:T0.disabled||Z.disabled}:{},...Z.progressive?{required:!!T0.required,min:c$(T0.min),max:c$(T0.max),minLength:c$(T0.minLength),maxLength:c$(T0.maxLength),pattern:c$(T0.pattern)}:{},name:X0,onChange:m,onBlur:m,ref:(b0)=>{if(b0){W0(X0,T0),_0=v8(K,X0);let y0=CZ(b0.value)?b0.querySelectorAll?b0.querySelectorAll("input,select,textarea")[0]||b0:b0:b0,p0=fY8(y0),m0=_0._f.refs||[];if(p0?m0.find((d0)=>d0===y0):y0===_0._f.ref)return;h4(K,X0,{_f:{..._0._f,...p0?{refs:[...m0.filter(YG0),y0,...Array.isArray(v8(X,X0))?[{}]:[]],ref:{type:y0.type,name:X0}}:{ref:y0}}}),V(X0,!1,void 0,y0)}else{if(_0=v8(K,X0,{}),_0._f)_0._f.mount=!1;(Z.shouldUnregister||T0.shouldUnregister)&&!(KQ6(z.array,X0)&&Y.action)&&z.unMount.add(X0)}}}},H0=()=>Z.shouldFocusError&&d$(K,g,z.mount),U0=(X0)=>{if(PU(X0))B.state.next({disabled:X0}),d$(K,(T0,_0)=>{let l0=v8(K,_0);if(l0){if(T0.disabled=l0._f.disabled||X0,Array.isArray(l0._f.refs))l0._f.refs.forEach((b0)=>{b0.disabled=l0._f.disabled||X0})}},0,!1)},K0=(X0,T0)=>async(_0)=>{let l0=void 0;if(_0)_0.preventDefault&&_0.preventDefault(),_0.persist&&_0.persist();let b0=sQ(U);if(B.state.next({isSubmitting:!0}),Z.resolver){let{errors:y0,values:p0}=await C();Q.errors=y0,b0=sQ(p0)}else await f(K);if(z.disabled.size)for(let y0 of z.disabled)GQ(b0,y0);if(GQ(Q.errors,"root"),kK(Q.errors)){B.state.next({errors:{}});try{await X0(b0,_0)}catch(y0){l0=y0}}else{if(T0)await T0({...Q.errors},_0);H0(),setTimeout(H0)}if(B.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:kK(Q.errors)&&!l0,submitCount:Q.submitCount+1,errors:Q.errors}),l0)throw l0},O0=(X0,T0={})=>{if(v8(K,X0)){if(CZ(T0.defaultValue))x(X0,sQ(v8(X,X0)));else x(X0,T0.defaultValue),h4(X,X0,sQ(T0.defaultValue));if(!T0.keepTouched)GQ(Q.touchedFields,X0);if(!T0.keepDirty)GQ(Q.dirtyFields,X0),Q.isDirty=T0.defaultValue?k(X0,sQ(v8(X,X0))):k();if(!T0.keepError)GQ(Q.errors,X0),q.isValid&&A();B.state.next({...Q})}},J0=(X0,T0={})=>{let _0=X0?sQ(X0):X,l0=sQ(_0),b0=kK(X0),y0=b0?X:l0;if(!T0.keepDefaultValues)X=_0;if(!T0.keepValues){if(T0.keepDirtyValues){let p0=new Set([...z.mount,...Object.keys(hP(X,U))]);for(let m0 of Array.from(p0))v8(Q.dirtyFields,m0)?h4(y0,m0,v8(U,m0)):x(m0,v8(y0,m0))}else{if(qG0&&CZ(X0))for(let p0 of z.mount){let m0=v8(K,p0);if(m0&&m0._f){let d0=Array.isArray(m0._f.refs)?m0._f.refs[0]:m0._f.ref;if(md(d0)){let R0=d0.closest("form");if(R0){R0.reset();break}}}}if(T0.keepFieldsRef)for(let p0 of z.mount)x(p0,v8(y0,p0));else K={}}U=Z.shouldUnregister?T0.keepDefaultValues?sQ(X):{}:sQ(y0),B.array.next({values:{...y0}}),B.state.next({values:{...y0}})}z={mount:T0.keepDirtyValues?z.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},Y.mount=!q.isValid||!!T0.keepIsValid||!!T0.keepDirtyValues||!Z.shouldUnregister&&!kK(y0),Y.watch=!!Z.shouldUnregister,B.state.next({submitCount:T0.keepSubmitCount?Q.submitCount:0,isDirty:b0?!1:T0.keepDirty?Q.isDirty:!!(T0.keepDefaultValues&&!YG(X0,X)),isSubmitted:T0.keepIsSubmitted?Q.isSubmitted:!1,dirtyFields:b0?{}:T0.keepDirtyValues?T0.keepDefaultValues&&U?hP(X,U):Q.dirtyFields:T0.keepDefaultValues&&X0?hP(X,X0):T0.keepDirty?Q.dirtyFields:{},touchedFields:T0.keepTouched?Q.touchedFields:{},errors:T0.keepErrors?Q.errors:{},isSubmitSuccessful:T0.keepIsSubmitSuccessful?Q.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:X})},j0=(X0,T0)=>J0(zG(X0)?X0(U):X0,T0),q0=(X0,T0={})=>{let _0=v8(K,X0),l0=_0&&_0._f;if(l0){let b0=l0.refs?l0.refs[0]:l0.ref;if(b0.focus)b0.focus(),T0.shouldSelect&&zG(b0.select)&&b0.select()}},v0=(X0)=>{Q={...Q,...X0}},e0={control:{register:W0,unregister:Q0,getFieldState:l,handleSubmit:K0,setError:o,_subscribe:e,_runSchema:C,_focusError:H0,_getWatch:$,_getDirty:k,_setValid:A,_setFieldArray:R,_setDisabledField:M0,_setErrors:P,_getFieldArray:v,_reset:J0,_resetDefaultValues:()=>zG(Z.defaultValues)&&Z.defaultValues().then((X0)=>{j0(X0,Z.resetOptions),B.state.next({isLoading:!1})}),_removeUnmounted:h,_disableForm:U0,_subjects:B,_proxyFormState:q,get _fields(){return K},get _formValues(){return U},get _state(){return Y},set _state(X0){Y=X0},get _defaultValues(){return X},get _names(){return z},set _names(X0){z=X0},get _formState(){return Q},get _options(){return Z},set _options(X0){Z={...Z,...X0}}},subscribe:B0,trigger:u,register:W0,handleSubmit:K0,watch:Y0,setValue:x,getValues:d,reset:j0,resetField:O0,clearErrors:r,unregister:Q0,setError:o,setFocus:q0,getFieldState:l};return{...e0,formControl:e0}}function FQ6(J={}){let Z=q7.default.useRef(void 0),Q=q7.default.useRef(void 0),[K,X]=q7.default.useState({isDirty:!1,isValidating:!1,isLoading:zG(J.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:J.errors||{},disabled:J.disabled||!1,isReady:!1,defaultValues:zG(J.defaultValues)?void 0:J.defaultValues});if(!Z.current)if(J.formControl){if(Z.current={...J.formControl,formState:K},J.defaultValues&&!zG(J.defaultValues))J.formControl.reset(J.defaultValues,J.resetOptions)}else{let{formControl:Y,...z}=iY8(J);Z.current={...z,formState:K}}let U=Z.current.control;return U._options=J,MG0(()=>{let Y=U._subscribe({formState:U._proxyFormState,callback:()=>X({...U._formState}),reRenderRoot:!0});return X((z)=>({...z,isReady:!0})),U._formState.isReady=!0,Y},[U]),q7.default.useEffect(()=>U._disableForm(J.disabled),[U,J.disabled]),q7.default.useEffect(()=>{if(J.mode)U._options.mode=J.mode;if(J.reValidateMode)U._options.reValidateMode=J.reValidateMode},[U,J.mode,J.reValidateMode]),q7.default.useEffect(()=>{if(J.errors)U._setErrors(J.errors),U._focusError()},[U,J.errors]),q7.default.useEffect(()=>{J.shouldUnregister&&U._subjects.state.next({values:U._getWatch()})},[U,J.shouldUnregister]),q7.default.useEffect(()=>{if(U._proxyFormState.isDirty){let Y=U._getDirty();if(Y!==K.isDirty)U._subjects.state.next({isDirty:Y})}},[U,K.isDirty]),q7.default.useEffect(()=>{var Y;if(J.values&&!YG(J.values,Q.current)){if(U._reset(J.values,{keepFieldsRef:!0,...U._options.resetOptions}),!((Y=U._options.resetOptions)===null||Y===void 0?void 0:Y.keepIsValid))U._setValid();Q.current=J.values,X((z)=>({...z}))}else U._resetDefaultValues()},[U,J.values]),q7.default.useEffect(()=>{if(!U._state.mount)U._setValid(),U._state.mount=!0;if(U._state.watch)U._state.watch=!1,U._subjects.state.next({...U._formState});U._removeUnmounted()}),Z.current.formState=UQ6(K,U),Z.current}var HH={};I9(HH,{xid:()=>yW8,void:()=>Wq8,uuidv7:()=>$W8,uuidv6:()=>SW8,uuidv4:()=>CW8,uuid:()=>TW8,util:()=>A8,url:()=>kW8,uppercase:()=>Rk,unknown:()=>tP,union:()=>QB0,undefined:()=>zq8,ulid:()=>hW8,uint64:()=>Uq8,uint32:()=>Qq8,tuple:()=>H56,trim:()=>Vk,treeifyError:()=>CG0,transform:()=>UB0,toUpperCase:()=>Tk,toLowerCase:()=>jk,toJSONSchema:()=>AH0,templateLiteral:()=>jq8,symbol:()=>Yq8,superRefine:()=>x56,success:()=>Dq8,stringbool:()=>_q8,stringFormat:()=>sW8,string:()=>_H0,strictObject:()=>Fq8,startsWith:()=>Ik,slugify:()=>Ck,size:()=>Lk,setErrorMap:()=>yq8,set:()=>Nq8,safeParseAsync:()=>VH0,safeParse:()=>EH0,safeEncodeAsync:()=>vH0,safeEncode:()=>$H0,safeDecodeAsync:()=>fH0,safeDecode:()=>kH0,registry:()=>Fi,regexes:()=>uY,regex:()=>Ak,refine:()=>b56,record:()=>B56,readonly:()=>S56,property:()=>GH0,promise:()=>Tq8,prettifyError:()=>SG0,preprocess:()=>xq8,prefault:()=>P56,positive:()=>XH0,pipe:()=>li,partialRecord:()=>Lq8,parseAsync:()=>DH0,parse:()=>PH0,overwrite:()=>Zq,optional:()=>pi,object:()=>Bq8,number:()=>aQ6,nullish:()=>Pq8,nullable:()=>ci,null:()=>Z56,normalize:()=>Ek,nonpositive:()=>YH0,nonoptional:()=>D56,nonnegative:()=>zH0,never:()=>JB0,negative:()=>UH0,nativeEnum:()=>Rq8,nanoid:()=>_W8,nan:()=>Eq8,multipleOf:()=>_3,minSize:()=>b3,minLength:()=>NM,mime:()=>Dk,meta:()=>vq8,maxSize:()=>nP,maxLength:()=>sP,map:()=>Aq8,mac:()=>uW8,lte:()=>pY,lt:()=>GH,lowercase:()=>Nk,looseObject:()=>Mq8,locales:()=>Bk,literal:()=>wq8,length:()=>aP,lazy:()=>v56,ksuid:()=>gW8,keyof:()=>Hq8,jwt:()=>nW8,json:()=>bq8,iso:()=>mi,ipv6:()=>pW8,ipv4:()=>mW8,intersection:()=>W56,int64:()=>Xq8,int32:()=>Zq8,int:()=>bH0,instanceof:()=>fq8,includes:()=>wk,httpUrl:()=>vW8,hostname:()=>aW8,hex:()=>oW8,hash:()=>tW8,guid:()=>jW8,gte:()=>fX,gt:()=>WH,globalRegistry:()=>fK,getErrorMap:()=>gq8,function:()=>Cq8,formatError:()=>Qk,float64:()=>Jq8,float32:()=>eW8,flattenError:()=>Zk,file:()=>Iq8,enum:()=>XB0,endsWith:()=>Pk,encodeAsync:()=>CH0,encode:()=>jH0,emoji:()=>fW8,email:()=>VW8,e164:()=>rW8,discriminatedUnion:()=>Oq8,describe:()=>kq8,decodeAsync:()=>SH0,decode:()=>TH0,date:()=>qq8,custom:()=>$q8,cuid2:()=>xW8,cuid:()=>bW8,core:()=>Qq,config:()=>qQ,coerce:()=>HB0,codec:()=>Vq8,clone:()=>vK,cidrv6:()=>lW8,cidrv4:()=>cW8,check:()=>Sq8,catch:()=>j56,boolean:()=>oQ6,bigint:()=>Kq8,base64url:()=>iW8,base64:()=>dW8,array:()=>ri,any:()=>Gq8,_function:()=>Cq8,_default:()=>w56,_ZodString:()=>xH0,ZodXID:()=>cH0,ZodVoid:()=>U56,ZodUnknown:()=>K56,ZodUnion:()=>ZB0,ZodUndefined:()=>eQ6,ZodUUID:()=>qH,ZodURL:()=>di,ZodULID:()=>pH0,ZodType:()=>O7,ZodTuple:()=>q56,ZodTransform:()=>A56,ZodTemplateLiteral:()=>$56,ZodSymbol:()=>tQ6,ZodSuccess:()=>E56,ZodStringFormat:()=>BJ,ZodString:()=>$k,ZodSet:()=>M56,ZodRecord:()=>KB0,ZodRealError:()=>_X,ZodReadonly:()=>C56,ZodPromise:()=>f56,ZodPrefault:()=>I56,ZodPipe:()=>GB0,ZodOptional:()=>YB0,ZodObject:()=>ni,ZodNumberFormat:()=>eP,ZodNumber:()=>vk,ZodNullable:()=>N56,ZodNull:()=>J56,ZodNonOptional:()=>zB0,ZodNever:()=>X56,ZodNanoID:()=>gH0,ZodNaN:()=>T56,ZodMap:()=>F56,ZodMAC:()=>sQ6,ZodLiteral:()=>O56,ZodLazy:()=>k56,ZodKSUID:()=>lH0,ZodJWT:()=>tH0,ZodIssueCode:()=>hq8,ZodIntersection:()=>G56,ZodISOTime:()=>yi,ZodISODuration:()=>gi,ZodISODateTime:()=>xi,ZodISODate:()=>hi,ZodIPv6:()=>iH0,ZodIPv4:()=>dH0,ZodGUID:()=>ui,ZodFunction:()=>_56,ZodFirstPartyTypeKind:()=>qB0,ZodFile:()=>L56,ZodError:()=>DW8,ZodEnum:()=>Sk,ZodEmoji:()=>yH0,ZodEmail:()=>hH0,ZodE164:()=>oH0,ZodDiscriminatedUnion:()=>z56,ZodDefault:()=>R56,ZodDate:()=>ii,ZodCustomStringFormat:()=>kk,ZodCustom:()=>si,ZodCodec:()=>WB0,ZodCatch:()=>V56,ZodCUID2:()=>uH0,ZodCUID:()=>mH0,ZodCIDRv6:()=>nH0,ZodCIDRv4:()=>rH0,ZodBoolean:()=>fk,ZodBigIntFormat:()=>eH0,ZodBigInt:()=>_k,ZodBase64URL:()=>aH0,ZodBase64:()=>sH0,ZodArray:()=>Y56,ZodAny:()=>Q56,TimePrecision:()=>$20,NEVER:()=>AG0,$output:()=>V20,$input:()=>j20,$brand:()=>NG0});var Qq={};I9(Qq,{version:()=>VW0,util:()=>A8,treeifyError:()=>CG0,toJSONSchema:()=>AH0,toDotPath:()=>RQ6,safeParseAsync:()=>kG0,safeParse:()=>$G0,safeEncodeAsync:()=>Vz8,safeEncode:()=>Dz8,safeDecodeAsync:()=>jz8,safeDecode:()=>Ez8,registry:()=>Fi,regexes:()=>uY,prettifyError:()=>SG0,parseAsync:()=>lP,parse:()=>pP,meta:()=>OH0,locales:()=>Bk,isValidJWT:()=>hQ6,isValidBase64URL:()=>xQ6,isValidBase64:()=>rW0,globalRegistry:()=>fK,globalConfig:()=>n$,formatError:()=>Qk,flattenError:()=>Zk,encodeAsync:()=>Iz8,encode:()=>Rz8,describe:()=>MH0,decodeAsync:()=>Pz8,decode:()=>wz8,config:()=>qQ,clone:()=>vK,_xid:()=>Ei,_void:()=>JH0,_uuidv7:()=>Ni,_uuidv6:()=>Ai,_uuidv4:()=>Li,_uuid:()=>Oi,_url:()=>Ok,_uppercase:()=>Rk,_unknown:()=>t20,_union:()=>JW8,_undefined:()=>s20,_ulid:()=>Di,_uint64:()=>r20,_uint32:()=>u20,_tuple:()=>KW8,_trim:()=>Vk,_transform:()=>qW8,_toUpperCase:()=>Tk,_toLowerCase:()=>jk,_templateLiteral:()=>RW8,_symbol:()=>n20,_superRefine:()=>FH0,_success:()=>OW8,_stringbool:()=>LH0,_stringFormat:()=>oP,_string:()=>T20,_startsWith:()=>Ik,_slugify:()=>Ck,_size:()=>Lk,_set:()=>YW8,_safeParseAsync:()=>iP,_safeParse:()=>dP,_safeEncodeAsync:()=>td,_safeEncode:()=>ad,_safeDecodeAsync:()=>ed,_safeDecode:()=>od,_regex:()=>Ak,_refine:()=>BH0,_record:()=>XW8,_readonly:()=>NW8,_property:()=>GH0,_promise:()=>IW8,_positive:()=>XH0,_pipe:()=>AW8,_parseAsync:()=>cP,_parse:()=>uP,_overwrite:()=>Zq,_optional:()=>HW8,_number:()=>b20,_nullable:()=>BW8,_null:()=>a20,_normalize:()=>Ek,_nonpositive:()=>YH0,_nonoptional:()=>MW8,_nonnegative:()=>zH0,_never:()=>e20,_negative:()=>UH0,_nativeEnum:()=>GW8,_nanoid:()=>wi,_nan:()=>KH0,_multipleOf:()=>_3,_minSize:()=>b3,_minLength:()=>NM,_min:()=>fX,_mime:()=>Dk,_maxSize:()=>nP,_maxLength:()=>sP,_max:()=>pY,_map:()=>UW8,_mac:()=>S20,_lte:()=>pY,_lt:()=>GH,_lowercase:()=>Nk,_literal:()=>WW8,_length:()=>aP,_lazy:()=>wW8,_ksuid:()=>Vi,_jwt:()=>_i,_isoTime:()=>f20,_isoDuration:()=>_20,_isoDateTime:()=>k20,_isoDate:()=>v20,_ipv6:()=>Ti,_ipv4:()=>ji,_intersection:()=>QW8,_int64:()=>i20,_int32:()=>m20,_int:()=>h20,_includes:()=>wk,_guid:()=>Mk,_gte:()=>fX,_gt:()=>WH,_float64:()=>g20,_float32:()=>y20,_file:()=>qH0,_enum:()=>zW8,_endsWith:()=>Pk,_encodeAsync:()=>nd,_encode:()=>id,_emoji:()=>Ri,_email:()=>Mi,_e164:()=>fi,_discriminatedUnion:()=>ZW8,_default:()=>FW8,_decodeAsync:()=>sd,_decode:()=>rd,_date:()=>ZH0,_custom:()=>HH0,_cuid2:()=>Pi,_cuid:()=>Ii,_coercedString:()=>C20,_coercedNumber:()=>x20,_coercedDate:()=>QH0,_coercedBoolean:()=>c20,_coercedBigint:()=>d20,_cidrv6:()=>Si,_cidrv4:()=>Ci,_check:()=>dQ6,_catch:()=>LW8,_boolean:()=>p20,_bigint:()=>l20,_base64url:()=>ki,_base64:()=>$i,_array:()=>WH0,_any:()=>o20,TimePrecision:()=>$20,NEVER:()=>AG0,JSONSchemaGenerator:()=>bi,JSONSchema:()=>iQ6,Doc:()=>Ki,$output:()=>V20,$input:()=>j20,$constructor:()=>L6,$brand:()=>NG0,$ZodXID:()=>xW0,$ZodVoid:()=>zq0,$ZodUnknown:()=>Uq0,$ZodUnion:()=>Hi,$ZodUndefined:()=>Qq0,$ZodUUID:()=>CW0,$ZodURL:()=>$W0,$ZodULID:()=>bW0,$ZodType:()=>Z7,$ZodTuple:()=>Bi,$ZodTransform:()=>Rq0,$ZodTemplateLiteral:()=>$q0,$ZodSymbol:()=>Zq0,$ZodSuccess:()=>Vq0,$ZodStringFormat:()=>QJ,$ZodString:()=>f3,$ZodSet:()=>Oq0,$ZodRegistry:()=>Fk,$ZodRecord:()=>Fq0,$ZodRealError:()=>vX,$ZodReadonly:()=>Sq0,$ZodPromise:()=>vq0,$ZodPrefault:()=>Dq0,$ZodPipe:()=>Cq0,$ZodOptional:()=>wq0,$ZodObjectJIT:()=>qq0,$ZodObject:()=>mQ6,$ZodNumberFormat:()=>eW0,$ZodNumber:()=>Wi,$ZodNullable:()=>Iq0,$ZodNull:()=>Kq0,$ZodNonOptional:()=>Eq0,$ZodNever:()=>Yq0,$ZodNanoID:()=>vW0,$ZodNaN:()=>Tq0,$ZodMap:()=>Mq0,$ZodMAC:()=>lW0,$ZodLiteral:()=>Aq0,$ZodLazy:()=>fq0,$ZodKSUID:()=>hW0,$ZodJWT:()=>oW0,$ZodIntersection:()=>Bq0,$ZodISOTime:()=>mW0,$ZodISODuration:()=>uW0,$ZodISODateTime:()=>yW0,$ZodISODate:()=>gW0,$ZodIPv6:()=>cW0,$ZodIPv4:()=>pW0,$ZodGUID:()=>TW0,$ZodFunction:()=>kq0,$ZodFile:()=>Nq0,$ZodError:()=>k3,$ZodEnum:()=>Lq0,$ZodEncodeError:()=>S3,$ZodEmoji:()=>kW0,$ZodEmail:()=>SW0,$ZodE164:()=>aW0,$ZodDiscriminatedUnion:()=>Hq0,$ZodDefault:()=>Pq0,$ZodDate:()=>Gq0,$ZodCustomStringFormat:()=>tW0,$ZodCustom:()=>_q0,$ZodCodec:()=>Yk,$ZodCheckUpperCase:()=>NW0,$ZodCheckStringFormat:()=>rP,$ZodCheckStartsWith:()=>wW0,$ZodCheckSizeEquals:()=>BW0,$ZodCheckRegex:()=>LW0,$ZodCheckProperty:()=>PW0,$ZodCheckOverwrite:()=>EW0,$ZodCheckNumberFormat:()=>GW0,$ZodCheckMultipleOf:()=>zW0,$ZodCheckMinSize:()=>HW0,$ZodCheckMinLength:()=>MW0,$ZodCheckMimeType:()=>DW0,$ZodCheckMaxSize:()=>qW0,$ZodCheckMaxLength:()=>FW0,$ZodCheckLowerCase:()=>AW0,$ZodCheckLessThan:()=>Zi,$ZodCheckLengthEquals:()=>OW0,$ZodCheckIncludes:()=>RW0,$ZodCheckGreaterThan:()=>Qi,$ZodCheckEndsWith:()=>IW0,$ZodCheckBigIntFormat:()=>WW0,$ZodCheck:()=>HJ,$ZodCatch:()=>jq0,$ZodCUID2:()=>_W0,$ZodCUID:()=>fW0,$ZodCIDRv6:()=>iW0,$ZodCIDRv4:()=>dW0,$ZodBoolean:()=>Uk,$ZodBigIntFormat:()=>Jq0,$ZodBigInt:()=>qi,$ZodBase64URL:()=>sW0,$ZodBase64:()=>nW0,$ZodAsyncError:()=>Jq,$ZodArray:()=>Wq0,$ZodAny:()=>Xq0});var AG0=Object.freeze({status:"aborted"});function L6(J,Z,Q){function K(z,G){if(!z._zod)Object.defineProperty(z,"_zod",{value:{def:G,constr:Y,traits:new Set},enumerable:!1});if(z._zod.traits.has(J))return;z._zod.traits.add(J),Z(z,G);let W=Y.prototype,q=Object.keys(W);for(let H=0;H<q.length;H++){let B=q[H];if(!(B in z))z[B]=W[B].bind(z)}}let X=Q?.Parent??Object;class U extends X{}Object.defineProperty(U,"name",{value:J});function Y(z){var G;let W=Q?.Parent?new U:this;K(W,z),(G=W._zod).deferred??(G.deferred=[]);for(let q of W._zod.deferred)q();return W}return Object.defineProperty(Y,"init",{value:K}),Object.defineProperty(Y,Symbol.hasInstance,{value:(z)=>{if(Q?.Parent&&z instanceof Q.Parent)return!0;return z?._zod?.traits?.has(J)}}),Object.defineProperty(Y,"name",{value:J}),Y}var NG0=Symbol("zod_brand");class Jq extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class S3 extends Error{constructor(J){super(`Encountered unidirectional transform during encode: ${J}`);this.name="ZodEncodeError"}}var n$={};function qQ(J){if(J)Object.assign(n$,J);return n$}var A8={};I9(A8,{unwrapMessage:()=>s$,uint8ArrayToHex:()=>Az8,uint8ArrayToBase64url:()=>Oz8,uint8ArrayToBase64:()=>LQ6,stringifyPrimitive:()=>M8,slugify:()=>IG0,shallowClone:()=>DG0,safeExtend:()=>Wz8,required:()=>Bz8,randomString:()=>Qz8,propertyKeyTypes:()=>t$,promiseAllObject:()=>Zz8,primitiveTypes:()=>EG0,prefixIssues:()=>EU,pick:()=>Yz8,partial:()=>Hz8,optionalKeys:()=>VG0,omit:()=>zz8,objectClone:()=>tY8,numKeys:()=>Kz8,nullish:()=>FM,normalizeParams:()=>L8,mergeDefs:()=>OM,merge:()=>qz8,jsonStringifyReplacer:()=>yP,joinValues:()=>h6,issue:()=>mP,isPlainObject:()=>LM,isObject:()=>$3,hexToUint8Array:()=>Lz8,getSizableOrigin:()=>e$,getParsedType:()=>Xz8,getLengthableOrigin:()=>Jk,getEnumValues:()=>a$,getElementAtPath:()=>Jz8,floatSafeRemainder:()=>wG0,finalizeIssue:()=>VU,extend:()=>Gz8,escapeRegex:()=>mY,esc:()=>ld,defineLazy:()=>g7,createTransparentProxy:()=>Uz8,cloneDef:()=>eY8,clone:()=>vK,cleanRegex:()=>o$,cleanEnum:()=>Fz8,captureStackTrace:()=>dd,cached:()=>gP,base64urlToUint8Array:()=>Mz8,base64ToUint8Array:()=>OQ6,assignProp:()=>MM,assertNotEqual:()=>nY8,assertNever:()=>aY8,assertIs:()=>sY8,assertEqual:()=>rY8,assert:()=>oY8,allowsEval:()=>PG0,aborted:()=>AM,NUMBER_FORMAT_RANGES:()=>jG0,Class:()=>AQ6,BIGINT_FORMAT_RANGES:()=>TG0});function rY8(J){return J}function nY8(J){return J}function sY8(J){}function aY8(J){throw Error()}function oY8(J){}function a$(J){let Z=Object.values(J).filter((K)=>typeof K==="number");return Object.entries(J).filter(([K,X])=>Z.indexOf(+K)===-1).map(([K,X])=>X)}function h6(J,Z="|"){return J.map((Q)=>M8(Q)).join(Z)}function yP(J,Z){if(typeof Z==="bigint")return Z.toString();return Z}function gP(J){return{get value(){{let Q=J();return Object.defineProperty(this,"value",{value:Q}),Q}throw Error("cached value already set")}}}function FM(J){return J===null||J===void 0}function o$(J){let Z=J.startsWith("^")?1:0,Q=J.endsWith("$")?J.length-1:J.length;return J.slice(Z,Q)}function wG0(J,Z){let Q=(J.toString().split(".")[1]||"").length,K=Z.toString(),X=(K.split(".")[1]||"").length;if(X===0&&/\d?e-\d?/.test(K)){let G=K.match(/\d?e-(\d?)/);if(G?.[1])X=Number.parseInt(G[1])}let U=Q>X?Q:X,Y=Number.parseInt(J.toFixed(U).replace(".","")),z=Number.parseInt(Z.toFixed(U).replace(".",""));return Y%z/10**U}var MQ6=Symbol("evaluating");function g7(J,Z,Q){let K=void 0;Object.defineProperty(J,Z,{get(){if(K===MQ6)return;if(K===void 0)K=MQ6,K=Q();return K},set(X){Object.defineProperty(J,Z,{value:X})},configurable:!0})}function tY8(J){return Object.create(Object.getPrototypeOf(J),Object.getOwnPropertyDescriptors(J))}function MM(J,Z,Q){Object.defineProperty(J,Z,{value:Q,writable:!0,enumerable:!0,configurable:!0})}function OM(...J){let Z={};for(let Q of J){let K=Object.getOwnPropertyDescriptors(Q);Object.assign(Z,K)}return Object.defineProperties({},Z)}function eY8(J){return OM(J._zod.def)}function Jz8(J,Z){if(!Z)return J;return Z.reduce((Q,K)=>Q?.[K],J)}function Zz8(J){let Z=Object.keys(J),Q=Z.map((K)=>J[K]);return Promise.all(Q).then((K)=>{let X={};for(let U=0;U<Z.length;U++)X[Z[U]]=K[U];return X})}function Qz8(J=10){let Q="";for(let K=0;K<J;K++)Q+="abcdefghijklmnopqrstuvwxyz"[Math.floor(Math.random()*26)];return Q}function ld(J){return JSON.stringify(J)}function IG0(J){return J.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var dd="captureStackTrace"in Error?Error.captureStackTrace:(...J)=>{};function $3(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}var PG0=gP(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(J){return!1}});function LM(J){if($3(J)===!1)return!1;let Z=J.constructor;if(Z===void 0)return!0;if(typeof Z!=="function")return!0;let Q=Z.prototype;if($3(Q)===!1)return!1;if(Object.prototype.hasOwnProperty.call(Q,"isPrototypeOf")===!1)return!1;return!0}function DG0(J){if(LM(J))return{...J};if(Array.isArray(J))return[...J];return J}function Kz8(J){let Z=0;for(let Q in J)if(Object.prototype.hasOwnProperty.call(J,Q))Z++;return Z}var Xz8=(J)=>{let Z=typeof J;switch(Z){case"undefined":return"undefined";case"string":return"string";case"number":return Number.isNaN(J)?"nan":"number";case"boolean":return"boolean";case"function":return"function";case"bigint":return"bigint";case"symbol":return"symbol";case"object":if(Array.isArray(J))return"array";if(J===null)return"null";if(J.then&&typeof J.then==="function"&&J.catch&&typeof J.catch==="function")return"promise";if(typeof Map<"u"&&J instanceof Map)return"map";if(typeof Set<"u"&&J instanceof Set)return"set";if(typeof Date<"u"&&J instanceof Date)return"date";if(typeof File<"u"&&J instanceof File)return"file";return"object";default:throw Error(`Unknown data type: ${Z}`)}},t$=new Set(["string","number","symbol"]),EG0=new Set(["string","number","bigint","boolean","symbol","undefined"]);function mY(J){return J.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function vK(J,Z,Q){let K=new J._zod.constr(Z??J._zod.def);if(!Z||Q?.parent)K._zod.parent=J;return K}function L8(J){let Z=J;if(!Z)return{};if(typeof Z==="string")return{error:()=>Z};if(Z?.message!==void 0){if(Z?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");Z.error=Z.message}if(delete Z.message,typeof Z.error==="string")return{...Z,error:()=>Z.error};return Z}function Uz8(J){let Z;return new Proxy({},{get(Q,K,X){return Z??(Z=J()),Reflect.get(Z,K,X)},set(Q,K,X,U){return Z??(Z=J()),Reflect.set(Z,K,X,U)},has(Q,K){return Z??(Z=J()),Reflect.has(Z,K)},deleteProperty(Q,K){return Z??(Z=J()),Reflect.deleteProperty(Z,K)},ownKeys(Q){return Z??(Z=J()),Reflect.ownKeys(Z)},getOwnPropertyDescriptor(Q,K){return Z??(Z=J()),Reflect.getOwnPropertyDescriptor(Z,K)},defineProperty(Q,K,X){return Z??(Z=J()),Reflect.defineProperty(Z,K,X)}})}function M8(J){if(typeof J==="bigint")return J.toString()+"n";if(typeof J==="string")return`"${J}"`;return`${J}`}function VG0(J){return Object.keys(J).filter((Z)=>{return J[Z]._zod.optin==="optional"&&J[Z]._zod.optout==="optional"})}var jG0={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},TG0={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Yz8(J,Z){let Q=J._zod.def,K=OM(J._zod.def,{get shape(){let X={};for(let U in Z){if(!(U in Q.shape))throw Error(`Unrecognized key: "${U}"`);if(!Z[U])continue;X[U]=Q.shape[U]}return MM(this,"shape",X),X},checks:[]});return vK(J,K)}function zz8(J,Z){let Q=J._zod.def,K=OM(J._zod.def,{get shape(){let X={...J._zod.def.shape};for(let U in Z){if(!(U in Q.shape))throw Error(`Unrecognized key: "${U}"`);if(!Z[U])continue;delete X[U]}return MM(this,"shape",X),X},checks:[]});return vK(J,K)}function Gz8(J,Z){if(!LM(Z))throw Error("Invalid input to extend: expected a plain object");let Q=J._zod.def.checks;if(Q&&Q.length>0)throw Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");let X=OM(J._zod.def,{get shape(){let U={...J._zod.def.shape,...Z};return MM(this,"shape",U),U},checks:[]});return vK(J,X)}function Wz8(J,Z){if(!LM(Z))throw Error("Invalid input to safeExtend: expected a plain object");let Q={...J._zod.def,get shape(){let K={...J._zod.def.shape,...Z};return MM(this,"shape",K),K},checks:J._zod.def.checks};return vK(J,Q)}function qz8(J,Z){let Q=OM(J._zod.def,{get shape(){let K={...J._zod.def.shape,...Z._zod.def.shape};return MM(this,"shape",K),K},get catchall(){return Z._zod.def.catchall},checks:[]});return vK(J,Q)}function Hz8(J,Z,Q){let K=OM(Z._zod.def,{get shape(){let X=Z._zod.def.shape,U={...X};if(Q)for(let Y in Q){if(!(Y in X))throw Error(`Unrecognized key: "${Y}"`);if(!Q[Y])continue;U[Y]=J?new J({type:"optional",innerType:X[Y]}):X[Y]}else for(let Y in X)U[Y]=J?new J({type:"optional",innerType:X[Y]}):X[Y];return MM(this,"shape",U),U},checks:[]});return vK(Z,K)}function Bz8(J,Z,Q){let K=OM(Z._zod.def,{get shape(){let X=Z._zod.def.shape,U={...X};if(Q)for(let Y in Q){if(!(Y in U))throw Error(`Unrecognized key: "${Y}"`);if(!Q[Y])continue;U[Y]=new J({type:"nonoptional",innerType:X[Y]})}else for(let Y in X)U[Y]=new J({type:"nonoptional",innerType:X[Y]});return MM(this,"shape",U),U},checks:[]});return vK(Z,K)}function AM(J,Z=0){if(J.aborted===!0)return!0;for(let Q=Z;Q<J.issues.length;Q++)if(J.issues[Q]?.continue!==!0)return!0;return!1}function EU(J,Z){return Z.map((Q)=>{var K;return(K=Q).path??(K.path=[]),Q.path.unshift(J),Q})}function s$(J){return typeof J==="string"?J:J?.message}function VU(J,Z,Q){let K={...J,path:J.path??[]};if(!J.message){let X=s$(J.inst?._zod.def?.error?.(J))??s$(Z?.error?.(J))??s$(Q.customError?.(J))??s$(Q.localeError?.(J))??"Invalid input";K.message=X}if(delete K.inst,delete K.continue,!Z?.reportInput)delete K.input;return K}function e$(J){if(J instanceof Set)return"set";if(J instanceof Map)return"map";if(J instanceof File)return"file";return"unknown"}function Jk(J){if(Array.isArray(J))return"array";if(typeof J==="string")return"string";return"unknown"}function mP(...J){let[Z,Q,K]=J;if(typeof Z==="string")return{message:Z,code:"custom",input:Q,inst:K};return{...Z}}function Fz8(J){return Object.entries(J).filter(([Z,Q])=>{return Number.isNaN(Number.parseInt(Z,10))}).map((Z)=>Z[1])}function OQ6(J){let Z=atob(J),Q=new Uint8Array(Z.length);for(let K=0;K<Z.length;K++)Q[K]=Z.charCodeAt(K);return Q}function LQ6(J){let Z="";for(let Q=0;Q<J.length;Q++)Z+=String.fromCharCode(J[Q]);return btoa(Z)}function Mz8(J){let Z=J.replace(/-/g,"+").replace(/_/g,"/"),Q="=".repeat((4-Z.length%4)%4);return OQ6(Z+Q)}function Oz8(J){return LQ6(J).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Lz8(J){let Z=J.replace(/^0x/,"");if(Z.length%2!==0)throw Error("Invalid hex string length");let Q=new Uint8Array(Z.length/2);for(let K=0;K<Z.length;K+=2)Q[K/2]=Number.parseInt(Z.slice(K,K+2),16);return Q}function Az8(J){return Array.from(J).map((Z)=>Z.toString(16).padStart(2,"0")).join("")}class AQ6{constructor(...J){}}var NQ6=(J,Z)=>{J.name="$ZodError",Object.defineProperty(J,"_zod",{value:J._zod,enumerable:!1}),Object.defineProperty(J,"issues",{value:Z,enumerable:!1}),J.message=JSON.stringify(Z,yP,2),Object.defineProperty(J,"toString",{value:()=>J.message,enumerable:!1})},k3=L6("$ZodError",NQ6),vX=L6("$ZodError",NQ6,{Parent:Error});function Zk(J,Z=(Q)=>Q.message){let Q={},K=[];for(let X of J.issues)if(X.path.length>0)Q[X.path[0]]=Q[X.path[0]]||[],Q[X.path[0]].push(Z(X));else K.push(Z(X));return{formErrors:K,fieldErrors:Q}}function Qk(J,Z=(Q)=>Q.message){let Q={_errors:[]},K=(X)=>{for(let U of X.issues)if(U.code==="invalid_union"&&U.errors.length)U.errors.map((Y)=>K({issues:Y}));else if(U.code==="invalid_key")K({issues:U.issues});else if(U.code==="invalid_element")K({issues:U.issues});else if(U.path.length===0)Q._errors.push(Z(U));else{let Y=Q,z=0;while(z<U.path.length){let G=U.path[z];if(z!==U.path.length-1)Y[G]=Y[G]||{_errors:[]};else Y[G]=Y[G]||{_errors:[]},Y[G]._errors.push(Z(U));Y=Y[G],z++}}};return K(J),Q}function CG0(J,Z=(Q)=>Q.message){let Q={errors:[]},K=(X,U=[])=>{var Y,z;for(let G of X.issues)if(G.code==="invalid_union"&&G.errors.length)G.errors.map((W)=>K({issues:W},G.path));else if(G.code==="invalid_key")K({issues:G.issues},G.path);else if(G.code==="invalid_element")K({issues:G.issues},G.path);else{let W=[...U,...G.path];if(W.length===0){Q.errors.push(Z(G));continue}let q=Q,H=0;while(H<W.length){let B=W[H],M=H===W.length-1;if(typeof B==="string")q.properties??(q.properties={}),(Y=q.properties)[B]??(Y[B]={errors:[]}),q=q.properties[B];else q.items??(q.items=[]),(z=q.items)[B]??(z[B]={errors:[]}),q=q.items[B];if(M)q.errors.push(Z(G));H++}}};return K(J),Q}function RQ6(J){let Z=[],Q=J.map((K)=>typeof K==="object"?K.key:K);for(let K of Q)if(typeof K==="number")Z.push(`[${K}]`);else if(typeof K==="symbol")Z.push(`[${JSON.stringify(String(K))}]`);else if(/[^\w$]/.test(K))Z.push(`[${JSON.stringify(K)}]`);else{if(Z.length)Z.push(".");Z.push(K)}return Z.join("")}function SG0(J){let Z=[],Q=[...J.issues].sort((K,X)=>(K.path??[]).length-(X.path??[]).length);for(let K of Q)if(Z.push(`✖ ${K.message}`),K.path?.length)Z.push(` → at ${RQ6(K.path)}`);return Z.join(`
@@ -3112,4 +3112,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
3112
3112
  `},u28={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 p28(J){let{announcements:Z=u28,container:Q,hiddenTextDescribedById:K,screenReaderInstructions:X=m28}=J,{announce:U,announcement:Y}=SK6(),z=uk("DndLiveRegion"),[G,W]=l6.useState(!1);if(l6.useEffect(()=>{W(!0)},[]),y28(l6.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=l6.default.createElement(l6.default.Fragment,null,l6.default.createElement(TK6,{id:K,value:X.draggable}),l6.default.createElement(CK6,{id:z,announcement:Y}));return Q?c3.createPortal(q,Q):q}var oQ;(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"})(oQ||(oQ={}));function Ar(){}function xB0(J,Z){return l6.useMemo(()=>({sensor:J,options:Z!=null?Z:{}}),[J,Z])}function pK6(){for(var J=arguments.length,Z=Array(J),Q=0;Q<J;Q++)Z[Q]=arguments[Q];return l6.useMemo(()=>[...Z].filter((K)=>K!=null),[...Z])}var GG=Object.freeze({x:0,y:0});function c28(J,Z){let Q=ck(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 l28(J,Z){let{data:{value:Q}}=J,{data:{value:K}}=Z;return K-Q}function d28(J,Z){if(!J||J.length===0)return null;let[Q]=J;return Z?Q[Z]:Q}function i28(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 r28=(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=i28(z,Z);if(G>0)X.push({id:Y,data:{droppableContainer:U,value:G}})}}return X.sort(l28)};function n28(J,Z,Q){return{...J,scaleX:Z&&Q?Z.width/Q.width:1,scaleY:Z&&Q?Z.height/Q.height:1}}function cK6(J,Z){return J&&Z?{x:J.left-Z.left,y:J.top-Z.top}:GG}function s28(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 a28=s28(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 o28(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 t28={ignoreTransform:!1};function ik(J,Z){if(Z===void 0)Z=t28;let Q=J.getBoundingClientRect();if(Z.ignoreTransform){let{transform:W,transformOrigin:q}=y1(J).getComputedStyle(J);if(W)Q=o28(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 $K6(J){return ik(J,{ignoreTransform:!0})}function e28(J){let{innerWidth:Z,innerHeight:Q}=J;return{top:0,left:0,right:Z,bottom:Q,width:Z,height:Q}}function JH8(J,Z){if(Z===void 0)Z=y1(J).getComputedStyle(J);return Z.position==="fixed"}function ZH8(J,Z){if(Z===void 0)Z=y1(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 hB0(J,Z){let Q=[];function K(X){if(Z!=null&&Q.length>=Z)return Q;if(!X)return Q;if(Mr(X)&&X.scrollingElement!=null&&!Q.includes(X.scrollingElement))return Q.push(X.scrollingElement),Q;if(!UD(X)||SB0(X))return Q;if(Q.includes(X))return Q;let U=y1(J).getComputedStyle(X);if(X!==J){if(ZH8(X,U))Q.push(X)}if(JH8(X,U))return Q;return K(X.parentNode)}if(!J)return Q;return K(J)}function dK6(J){let[Z]=hB0(J,1);return Z!=null?Z:null}function $B0(J){if(!hk||!J)return null;if(g3(J))return J;if(!Fr(J))return null;if(Mr(J)||J===m3(J).scrollingElement)return window;if(UD(J))return J;return null}function iK6(J){if(g3(J))return J.scrollX;return J.scrollLeft}function rK6(J){if(g3(J))return J.scrollY;return J.scrollTop}function fB0(J){return{x:iK6(J),y:rK6(J)}}var I5;(function(J){J[J.Forward=1]="Forward",J[J.Backward=-1]="Backward"})(I5||(I5={}));function nK6(J){if(!hk||!J)return!1;return J===document.scrollingElement}function sK6(J){let Z={x:0,y:0},Q=nK6(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 QH8={x:0.2,y:0.2};function KH8(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=QH8;let{isTop:W,isBottom:q,isLeft:H,isRight:B}=sK6(J),M={x:0,y:0},O={x:0,y:0},A={height:Z.height*X.y,width:Z.width*X.x};if(!W&&U<=Z.top+A.height)M.y=I5.Backward,O.y=K*Math.abs((Z.top+A.height-U)/A.height);else if(!q&&G>=Z.bottom-A.height)M.y=I5.Forward,O.y=K*Math.abs((Z.bottom-A.height-G)/A.height);if(!B&&z>=Z.right-A.width)M.x=I5.Forward,O.x=K*Math.abs((Z.right-A.width-z)/A.width);else if(!H&&Y<=Z.left+A.width)M.x=I5.Backward,O.x=K*Math.abs((Z.left+A.width-Y)/A.width);return{direction:M,speed:O}}function XH8(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 aK6(J){return J.reduce((Z,Q)=>{return u3(Z,fB0(Q))},GG)}function UH8(J){return J.reduce((Z,Q)=>{return Z+iK6(Q)},0)}function YH8(J){return J.reduce((Z,Q)=>{return Z+rK6(Q)},0)}function oK6(J,Z){if(Z===void 0)Z=ik;if(!J)return;let{top:Q,left:K,bottom:X,right:U}=Z(J);if(!dK6(J))return;if(X<=0||U<=0||Q>=window.innerHeight||K>=window.innerWidth)J.scrollIntoView({block:"center",inline:"center"})}var zH8=[["x",["left","right"],UH8],["y",["top","bottom"],YH8]];class Rr{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=hB0(Z),K=aK6(Q);this.rect={...J},this.width=J.width,this.height=J.height;for(let[X,U,Y]of zH8)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 GD{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 GH8(J){let{EventTarget:Z}=y1(J);return J instanceof Z?J:m3(J)}function kB0(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 cY;(function(J){J.Click="click",J.DragStart="dragstart",J.Keydown="keydown",J.ContextMenu="contextmenu",J.Resize="resize",J.SelectionChange="selectionchange",J.VisibilityChange="visibilitychange"})(cY||(cY={}));function kK6(J){J.preventDefault()}function WH8(J){J.stopPropagation()}var FJ;(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"})(FJ||(FJ={}));var tK6={start:[FJ.Space,FJ.Enter],cancel:[FJ.Esc],end:[FJ.Space,FJ.Enter,FJ.Tab]},qH8=(J,Z)=>{let{currentCoordinates:Q}=Z;switch(J.code){case FJ.Right:return{...Q,x:Q.x+25};case FJ.Left:return{...Q,x:Q.x-25};case FJ.Down:return{...Q,y:Q.y+25};case FJ.Up:return{...Q,y:Q.y-25}}return};class rk{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 GD(m3(Z)),this.windowListeners=new GD(y1(Z)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(cY.Resize,this.handleCancel),this.windowListeners.add(cY.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(cY.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:J,onStart:Z}=this.props,Q=J.node.current;if(Q)oK6(Q);Z(GG)}handleKeyDown(J){if(Or(J)){let{active:Z,context:Q,options:K}=this.props,{keyboardCodes:X=tK6,coordinateGetter:U=qH8,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}:GG;if(!this.referenceCoordinates)this.referenceCoordinates=W;let q=U(J,{active:Z,context:Q.current,currentCoordinates:W});if(q){let H=pk(q,W),B={x:0,y:0},{scrollableAncestors:M}=Q.current;for(let O of M){let A=J.code,{isTop:N,isRight:R,isLeft:w,isBottom:P,maxScroll:V,minScroll:D}=sK6(O),T=XH8(O),C={x:Math.min(A===FJ.Right?T.right-T.width/2:T.right,Math.max(A===FJ.Right?T.left:T.left+T.width/2,q.x)),y:Math.min(A===FJ.Down?T.bottom-T.height/2:T.bottom,Math.max(A===FJ.Down?T.top:T.top+T.height/2,q.y))},S=A===FJ.Right&&!R||A===FJ.Left&&!w,f=A===FJ.Down&&!P||A===FJ.Up&&!N;if(S&&C.x!==q.x){let h=O.scrollLeft+H.x,k=A===FJ.Right&&h<=V.x||A===FJ.Left&&h>=D.x;if(k&&!H.y){O.scrollTo({left:h,behavior:Y});return}if(k)B.x=O.scrollLeft-h;else B.x=A===FJ.Right?O.scrollLeft-V.x:O.scrollLeft-D.x;if(B.x)O.scrollBy({left:-B.x,behavior:Y});break}else if(f&&C.y!==q.y){let h=O.scrollTop+H.y,k=A===FJ.Down&&h<=V.y||A===FJ.Up&&h>=D.y;if(k&&!H.x){O.scrollTo({top:h,behavior:Y});return}if(k)B.y=O.scrollTop-h;else B.y=A===FJ.Down?O.scrollTop-V.y:O.scrollTop-D.y;if(B.y)O.scrollBy({top:-B.y,behavior:Y});break}}this.handleMove(J,u3(pk(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()}}rk.activators=[{eventName:"onKeyDown",handler:(J,Z,Q)=>{let{keyboardCodes:K=tK6,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 vK6(J){return Boolean(J&&"distance"in J)}function fK6(J){return Boolean(J&&"delay"in J)}class wr{constructor(J,Z,Q){var K;if(Q===void 0)Q=GH8(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=m3(U),this.documentListeners=new GD(this.document),this.listeners=new GD(Q),this.windowListeners=new GD(y1(U)),this.initialCoordinates=(K=ck(X))!=null?K:GG,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(cY.Resize,this.handleCancel),this.windowListeners.add(cY.DragStart,kK6),this.windowListeners.add(cY.VisibilityChange,this.handleCancel),this.windowListeners.add(cY.ContextMenu,kK6),this.documentListeners.add(cY.Keydown,this.handleKeydown),Z){if(Q!=null&&Q({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(fK6(Z)){this.timeoutId=setTimeout(this.handleStart,Z.delay),this.handlePending(Z);return}if(vK6(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(cY.Click,WH8,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(cY.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=ck(J))!=null?Z:GG,G=pk(K,z);if(!Q&&Y){if(vK6(Y)){if(Y.tolerance!=null&&kB0(G,Y.tolerance))return this.handleCancel();if(kB0(G,Y.distance))return this.handleStart()}if(fK6(Y)){if(kB0(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===FJ.Esc)this.handleCancel()}removeTextSelection(){var J;(J=this.document.getSelection())==null||J.removeAllRanges()}}var HH8={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class nk extends wr{constructor(J){let{event:Z}=J,Q=m3(Z.target);super(J,HH8,Q)}}nk.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 BH8={move:{name:"mousemove"},end:{name:"mouseup"}},_B0;(function(J){J[J.RightClick=2]="RightClick"})(_B0||(_B0={}));class eK6 extends wr{constructor(J){super(J,BH8,m3(J.event.target))}}eK6.activators=[{eventName:"onMouseDown",handler:(J,Z)=>{let{nativeEvent:Q}=J,{onActivation:K}=Z;if(Q.button===_B0.RightClick)return!1;return K==null||K({event:Q}),!0}}];var vB0={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class JX6 extends wr{constructor(J){super(J,vB0)}static setup(){return window.addEventListener(vB0.move.name,J,{capture:!1,passive:!1}),function(){window.removeEventListener(vB0.move.name,J)};function J(){}}}JX6.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 lk;(function(J){J[J.Pointer=0]="Pointer",J[J.DraggableRect=1]="DraggableRect"})(lk||(lk={}));var Nr;(function(J){J[J.TreeOrder=0]="TreeOrder",J[J.ReversedTreeOrder=1]="ReversedTreeOrder"})(Nr||(Nr={}));function FH8(J){let{acceleration:Z,activator:Q=lk.Pointer,canScroll:K,draggingRect:X,enabled:U,interval:Y=5,order:z=Nr.TreeOrder,pointerCoordinates:G,scrollableAncestors:W,scrollableAncestorRects:q,delta:H,threshold:B}=J,M=OH8({delta:H,disabled:!U}),[O,A]=EK6(),N=l6.useRef({x:0,y:0}),R=l6.useRef({x:0,y:0}),w=l6.useMemo(()=>{switch(Q){case lk.Pointer:return G?{top:G.y,bottom:G.y,left:G.x,right:G.x}:null;case lk.DraggableRect:return X}},[Q,X,G]),P=l6.useRef(null),V=l6.useCallback(()=>{let T=P.current;if(!T)return;let C=N.current.x*R.current.x,S=N.current.y*R.current.y;T.scrollBy(C,S)},[]),D=l6.useMemo(()=>z===Nr.TreeOrder?[...W].reverse():W,[z,W]);l6.useEffect(()=>{if(!U||!W.length||!w){A();return}for(let T of D){if((K==null?void 0:K(T))===!1)continue;let C=W.indexOf(T),S=q[C];if(!S)continue;let{direction:f,speed:h}=KH8(T,S,w,Z,B);for(let k of["x","y"])if(!M[k][f[k]])h[k]=0,f[k]=0;if(h.x>0||h.y>0){A(),P.current=T,O(V,Y),N.current=h,R.current=f;return}}N.current={x:0,y:0},R.current={x:0,y:0},A()},[Z,V,K,A,U,Y,JSON.stringify(w),JSON.stringify(M),O,W,D,q,JSON.stringify(B)])}var MH8={x:{[I5.Backward]:!1,[I5.Forward]:!1},y:{[I5.Backward]:!1,[I5.Forward]:!1}};function OH8(J){let{delta:Z,disabled:Q}=J,K=mk(Z);return zD((X)=>{if(Q||!K||!X)return MH8;let U={x:Math.sign(Z.x-K.x),y:Math.sign(Z.y-K.y)};return{x:{[I5.Backward]:X.x[I5.Backward]||U.x===-1,[I5.Forward]:X.x[I5.Forward]||U.x===1},y:{[I5.Backward]:X.y[I5.Backward]||U.y===-1,[I5.Forward]:X.y[I5.Forward]||U.y===1}}},[Q,Z,K])}function LH8(J,Z){let Q=Z!=null?J.get(Z):void 0,K=Q?Q.node.current:null;return zD((X)=>{var U;if(Z==null)return null;return(U=K!=null?K:X)!=null?U:null},[K,Z])}function AH8(J,Z){return l6.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 dk;(function(J){J[J.Always=0]="Always",J[J.BeforeDragging=1]="BeforeDragging",J[J.WhileDragging=2]="WhileDragging"})(dk||(dk={}));var bB0;(function(J){J.Optimized="optimized"})(bB0||(bB0={}));var _K6=new Map;function NH8(J,Z){let{dragging:Q,dependencies:K,config:X}=Z,[U,Y]=l6.useState(null),{frequency:z,measure:G,strategy:W}=X,q=l6.useRef(J),H=N(),B=YD(H),M=l6.useCallback(function(R){if(R===void 0)R=[];if(B.current)return;Y((w)=>{if(w===null)return R;return w.concat(R.filter((P)=>!w.includes(P)))})},[B]),O=l6.useRef(null),A=zD((R)=>{if(H&&!Q)return _K6;if(!R||R===_K6||q.current!==J||U!=null){let w=new Map;for(let P of J){if(!P)continue;if(U&&U.length>0&&!U.includes(P.id)&&P.rect.current){w.set(P.id,P.rect.current);continue}let V=P.node.current,D=V?new Rr(G(V),V):null;if(P.rect.current=D,D)w.set(P.id,D)}return w}return R},[J,U,Q,H,G]);return l6.useEffect(()=>{q.current=J},[J]),l6.useEffect(()=>{if(H)return;M()},[Q,H]),l6.useEffect(()=>{if(U&&U.length>0)Y(null)},[JSON.stringify(U)]),l6.useEffect(()=>{if(H||typeof z!=="number"||O.current!==null)return;O.current=setTimeout(()=>{M(),O.current=null},z)},[z,H,M,...K]),{droppableRects:A,measureDroppableContainers:M,measuringScheduled:U!=null};function N(){switch(W){case dk.Always:return!1;case dk.BeforeDragging:return Q;default:return!Q}}}function yB0(J,Z){return zD((Q)=>{if(!J)return null;if(Q)return Q;return typeof Z==="function"?Z(J):J},[Z,J])}function RH8(J,Z){return yB0(J,Z)}function wH8(J){let{callback:Z,disabled:Q}=J,K=yk(Z),X=l6.useMemo(()=>{if(Q||typeof window>"u"||typeof window.MutationObserver>"u")return;let{MutationObserver:U}=window;return new U(K)},[K,Q]);return l6.useEffect(()=>{return()=>X==null?void 0:X.disconnect()},[X]),X}function Ir(J){let{callback:Z,disabled:Q}=J,K=yk(Z),X=l6.useMemo(()=>{if(Q||typeof window>"u"||typeof window.ResizeObserver>"u")return;let{ResizeObserver:U}=window;return new U(K)},[Q]);return l6.useEffect(()=>{return()=>X==null?void 0:X.disconnect()},[X]),X}function IH8(J){return new Rr(ik(J),J)}function bK6(J,Z,Q){if(Z===void 0)Z=IH8;let[K,X]=l6.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=wH8({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=Ir({callback:U});return Xq(()=>{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 PH8(J){let Z=yB0(J);return cK6(J,Z)}var xK6=[];function DH8(J){let Z=l6.useRef(J),Q=zD((K)=>{if(!J)return xK6;if(K&&K!==xK6&&J&&Z.current&&J.parentNode===Z.current.parentNode)return K;return hB0(J)},[J]);return l6.useEffect(()=>{Z.current=J},[J]),Q}function EH8(J){let[Z,Q]=l6.useState(null),K=l6.useRef(J),X=l6.useCallback((U)=>{let Y=$B0(U.target);if(!Y)return;Q((z)=>{if(!z)return null;return z.set(Y,fB0(Y)),new Map(z)})},[]);return l6.useEffect(()=>{let U=K.current;if(J!==U){Y(U);let z=J.map((G)=>{let W=$B0(G);if(W)return W.addEventListener("scroll",X,{passive:!0}),[W,fB0(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=$B0(G);W==null||W.removeEventListener("scroll",X)})}},[X,J]),l6.useMemo(()=>{if(J.length)return Z?Array.from(Z.values()).reduce((U,Y)=>u3(U,Y),GG):aK6(J);return GG},[J,Z])}function hK6(J,Z){if(Z===void 0)Z=[];let Q=l6.useRef(null);return l6.useEffect(()=>{Q.current=null},Z),l6.useEffect(()=>{let K=J!==GG;if(K&&!Q.current)Q.current=J;if(!K&&Q.current)Q.current=null},[J]),Q.current?pk(J,Q.current):GG}function VH8(J){l6.useEffect(()=>{if(!hk)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 jH8(J,Z){return l6.useMemo(()=>{return J.reduce((Q,K)=>{let{eventName:X,handler:U}=K;return Q[X]=(Y)=>{U(Y,Z)},Q},{})},[J,Z])}function ZX6(J){return l6.useMemo(()=>J?e28(J):null,[J])}var yK6=[];function TH8(J,Z){if(Z===void 0)Z=ik;let[Q]=J,K=ZX6(Q?y1(Q):null),[X,U]=l6.useState(yK6);function Y(){U(()=>{if(!J.length)return yK6;return J.map((G)=>nK6(G)?K:new Rr(Z(G),G))})}let z=Ir({callback:Y});return Xq(()=>{z==null||z.disconnect(),Y(),J.forEach((G)=>z==null?void 0:z.observe(G))},[J]),X}function QX6(J){if(!J)return null;if(J.children.length>1)return J;let Z=J.children[0];return UD(Z)?Z:J}function CH8(J){let{measure:Z}=J,[Q,K]=l6.useState(null),X=l6.useCallback((W)=>{for(let{target:q}of W)if(UD(q)){K((H)=>{let B=Z(q);return H?{...H,width:B.width,height:B.height}:B});break}},[Z]),U=Ir({callback:X}),Y=l6.useCallback((W)=>{let q=QX6(W);if(U==null||U.disconnect(),q)U==null||U.observe(q);K(q?Z(q):null)},[Z,U]),[z,G]=gk(Y);return l6.useMemo(()=>({nodeRef:z,rect:Q,setRef:G}),[Q,z,G])}var SH8=[{sensor:nk,options:{}},{sensor:rk,options:{}}],$H8={current:{}},Lr={draggable:{measure:$K6},droppable:{measure:$K6,strategy:dk.WhileDragging,frequency:bB0.Optimized},dragOverlay:{measure:ik}};class WD 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 kH8={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new WD,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Ar},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:Lr,measureDroppableContainers:Ar,windowRect:null,measuringScheduled:!1},KX6={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Ar,draggableNodes:new Map,over:null,measureDroppableContainers:Ar},sk=l6.createContext(KX6),XX6=l6.createContext(kH8);function vH8(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new WD}}}function fH8(J,Z){switch(Z.type){case oQ.DragStart:return{...J,draggable:{...J.draggable,initialCoordinates:Z.initialCoordinates,active:Z.active}};case oQ.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 oQ.DragEnd:case oQ.DragCancel:return{...J,draggable:{...J.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case oQ.RegisterDroppable:{let{element:Q}=Z,{id:K}=Q,X=new WD(J.droppable.containers);return X.set(K,Q),{...J,droppable:{...J.droppable,containers:X}}}case oQ.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 WD(J.droppable.containers);return Y.set(Q,{...U,disabled:X}),{...J,droppable:{...J.droppable,containers:Y}}}case oQ.UnregisterDroppable:{let{id:Q,key:K}=Z,X=J.droppable.containers.get(Q);if(!X||K!==X.key)return J;let U=new WD(J.droppable.containers);return U.delete(Q),{...J,droppable:{...J.droppable,containers:U}}}default:return J}}function _H8(J){let{disabled:Z}=J,{active:Q,activatorEvent:K,draggableNodes:X}=l6.useContext(sk),U=mk(K),Y=mk(Q==null?void 0:Q.id);return l6.useEffect(()=>{if(Z)return;if(!K&&U&&Y!=null){if(!Or(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=jK6(q);if(H){H.focus();break}}})}},[K,Z,X,Y,U]),null}function UX6(J,Z){let{transform:Q,...K}=Z;return J!=null&&J.length?J.reduce((X,U)=>{return U({transform:X,...K})},Q):Q}function bH8(J){return l6.useMemo(()=>({draggable:{...Lr.draggable,...J==null?void 0:J.draggable},droppable:{...Lr.droppable,...J==null?void 0:J.droppable},dragOverlay:{...Lr.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 xH8(J){let{activeNode:Z,measure:Q,initialRect:K,config:X=!0}=J,U=l6.useRef(!1),{x:Y,y:z}=typeof X==="boolean"?{x:X,y:X}:X;Xq(()=>{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=cK6(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=dK6(W);if(B)B.scrollBy({top:H.y,left:H.x})}},[Z,Y,z,K,Q])}var Pr=l6.createContext({...GG,scaleX:1,scaleY:1}),PM;(function(J){J[J.Uninitialized=0]="Uninitialized",J[J.Initializing=1]="Initializing",J[J.Initialized=2]="Initialized"})(PM||(PM={}));var YX6=l6.memo(function(Z){var Q,K,X,U;let{id:Y,accessibility:z,autoScroll:G=!0,children:W,sensors:q=SH8,collisionDetection:H=r28,measuring:B,modifiers:M,...O}=Z,A=l6.useReducer(fH8,void 0,vH8),[N,R]=A,[w,P]=g28(),[V,D]=l6.useState(PM.Uninitialized),T=V===PM.Initialized,{draggable:{active:C,nodes:S,translate:f},droppable:{containers:h}}=N,k=C!=null?S.get(C):null,$=l6.useRef({initial:null,translated:null}),v=l6.useMemo(()=>{var H6;return C!=null?{id:C,data:(H6=k==null?void 0:k.data)!=null?H6:$H8,rect:$}:null},[C,k]),_=l6.useRef(null),[b,x]=l6.useState(null),[m,g]=l6.useState(null),u=YD(O,Object.values(O)),d=uk("DndDescribedBy",Y),l=l6.useMemo(()=>h.getEnabled(),[h]),r=bH8(B),{droppableRects:o,measureDroppableContainers:Y0,measuringScheduled:e}=NH8(l,{dragging:T,dependencies:[f.x,f.y],config:r.droppable}),B0=LH8(S,C),Q0=l6.useMemo(()=>m?ck(m):null,[m]),M0=q6(),W0=RH8(B0,r.draggable.measure);xH8({activeNode:C!=null?S.get(C):null,config:M0.layoutShiftCompensation,initialRect:W0,measure:r.draggable.measure});let H0=bK6(B0,r.draggable.measure,W0),U0=bK6(B0?B0.parentElement:null),K0=l6.useRef({activatorEvent:null,active:null,activeNode:B0,collisionRect:null,collisions:null,droppableRects:o,draggableNodes:S,draggingNode:null,draggingNodeRect:null,droppableContainers:h,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),O0=h.getNodeFor((Q=K0.current.over)==null?void 0:Q.id),J0=CH8({measure:r.dragOverlay.measure}),j0=(K=J0.nodeRef.current)!=null?K:B0,q0=T?(X=J0.rect)!=null?X:H0:null,v0=Boolean(J0.nodeRef.current&&J0.rect),Z0=PH8(v0?null:H0),e0=ZX6(j0?y1(j0):null),X0=DH8(T?O0!=null?O0:B0:null),T0=TH8(X0),_0=UX6(M,{transform:{x:f.x-Z0.x,y:f.y-Z0.y,scaleX:1,scaleY:1},activatorEvent:m,active:v,activeNodeRect:H0,containerNodeRect:U0,draggingNodeRect:q0,over:K0.current.over,overlayNodeRect:J0.rect,scrollableAncestors:X0,scrollableAncestorRects:T0,windowRect:e0}),l0=Q0?u3(Q0,f):null,b0=EH8(X0),y0=hK6(b0),p0=hK6(b0,[H0]),m0=u3(_0,y0),d0=q0?a28(q0,_0):null,R0=v&&d0?H({active:v,collisionRect:d0,droppableRects:o,droppableContainers:l,pointerCoordinates:l0}):null,P0=d28(R0,"id"),[s,A0]=l6.useState(null),i=v0?_0:u3(_0,p0),L0=n28(i,(U=s==null?void 0:s.rect)!=null?U:null,H0),N0=l6.useRef(null),x0=l6.useCallback((H6,f6)=>{let{sensor:Z6,options:X6}=f6;if(_.current==null)return;let A6=S.get(_.current);if(!A6)return;let U6=H6.nativeEvent,b6=new Z6({active:_.current,activeNode:A6,event:U6,options:X6,context:K0,onAbort(v6){if(!S.get(v6))return;let{onDragAbort:$6}=u.current,S6={id:v6};$6==null||$6(S6),w({type:"onDragAbort",event:S6})},onPending(v6,t6,$6,S6){if(!S.get(v6))return;let{onDragPending:J6}=u.current,M6={id:v6,constraint:t6,initialCoordinates:$6,offset:S6};J6==null||J6(M6),w({type:"onDragPending",event:M6})},onStart(v6){let t6=_.current;if(t6==null)return;let $6=S.get(t6);if(!$6)return;let{onDragStart:S6}=u.current,k0={activatorEvent:U6,active:{id:t6,data:$6.data,rect:$}};c3.unstable_batchedUpdates(()=>{S6==null||S6(k0),D(PM.Initializing),R({type:oQ.DragStart,initialCoordinates:v6,active:t6}),w({type:"onDragStart",event:k0}),x(N0.current),g(U6)})},onMove(v6){R({type:oQ.DragMove,coordinates:v6})},onEnd:X8(oQ.DragEnd),onCancel:X8(oQ.DragCancel)});N0.current=b6;function X8(v6){return async function(){let{active:$6,collisions:S6,over:k0,scrollAdjustedTranslate:J6}=K0.current,M6=null;if($6&&J6){let{cancelDrop:V0}=u.current;if(M6={activatorEvent:U6,active:$6,collisions:S6,delta:J6,over:k0},v6===oQ.DragEnd&&typeof V0==="function"){if(await Promise.resolve(V0(M6)))v6=oQ.DragCancel}}_.current=null,c3.unstable_batchedUpdates(()=>{R({type:v6}),D(PM.Uninitialized),A0(null),x(null),g(null),N0.current=null;let V0=v6===oQ.DragEnd?"onDragEnd":"onDragCancel";if(M6){let G6=u.current[V0];G6==null||G6(M6),w({type:V0,event:M6})}})}}},[S]),$0=l6.useCallback((H6,f6)=>{return(Z6,X6)=>{let A6=Z6.nativeEvent,U6=S.get(X6);if(_.current!==null||!U6||A6.dndKit||A6.defaultPrevented)return;let b6={active:U6};if(H6(Z6,f6.options,b6)===!0)A6.dndKit={capturedBy:f6.sensor},_.current=X6,x0(Z6,f6)}},[S,x0]),D0=AH8(q,$0);VH8(q),Xq(()=>{if(H0&&V===PM.Initializing)D(PM.Initialized)},[H0,V]),l6.useEffect(()=>{let{onDragMove:H6}=u.current,{active:f6,activatorEvent:Z6,collisions:X6,over:A6}=K0.current;if(!f6||!Z6)return;let U6={active:f6,activatorEvent:Z6,collisions:X6,delta:{x:m0.x,y:m0.y},over:A6};c3.unstable_batchedUpdates(()=>{H6==null||H6(U6),w({type:"onDragMove",event:U6})})},[m0.x,m0.y]),l6.useEffect(()=>{let{active:H6,activatorEvent:f6,collisions:Z6,droppableContainers:X6,scrollAdjustedTranslate:A6}=K0.current;if(!H6||_.current==null||!f6||!A6)return;let{onDragOver:U6}=u.current,b6=X6.get(P0),X8=b6&&b6.rect.current?{id:b6.id,rect:b6.rect.current,data:b6.data,disabled:b6.disabled}:null,v6={active:H6,activatorEvent:f6,collisions:Z6,delta:{x:A6.x,y:A6.y},over:X8};c3.unstable_batchedUpdates(()=>{A0(X8),U6==null||U6(v6),w({type:"onDragOver",event:v6})})},[P0]),Xq(()=>{K0.current={activatorEvent:m,active:v,activeNode:B0,collisionRect:d0,collisions:R0,droppableRects:o,draggableNodes:S,draggingNode:j0,draggingNodeRect:q0,droppableContainers:h,over:s,scrollableAncestors:X0,scrollAdjustedTranslate:m0},$.current={initial:q0,translated:d0}},[v,B0,R0,d0,S,j0,q0,o,h,s,X0,m0]),FH8({...M0,delta:f,draggingRect:d0,pointerCoordinates:l0,scrollableAncestors:X0,scrollableAncestorRects:T0});let h0=l6.useMemo(()=>{return{active:v,activeNode:B0,activeNodeRect:H0,activatorEvent:m,collisions:R0,containerNodeRect:U0,dragOverlay:J0,draggableNodes:S,droppableContainers:h,droppableRects:o,over:s,measureDroppableContainers:Y0,scrollableAncestors:X0,scrollableAncestorRects:T0,measuringConfiguration:r,measuringScheduled:e,windowRect:e0}},[v,B0,H0,m,R0,U0,J0,S,h,o,s,Y0,X0,T0,r,e,e0]),c0=l6.useMemo(()=>{return{activatorEvent:m,activators:D0,active:v,activeNodeRect:H0,ariaDescribedById:{draggable:d},dispatch:R,draggableNodes:S,over:s,measureDroppableContainers:Y0}},[m,D0,v,H0,R,d,S,s,Y0]);return l6.default.createElement(uK6.Provider,{value:P},l6.default.createElement(sk.Provider,{value:c0},l6.default.createElement(XX6.Provider,{value:h0},l6.default.createElement(Pr.Provider,{value:L0},W)),l6.default.createElement(_H8,{disabled:(z==null?void 0:z.restoreFocus)===!1})),l6.default.createElement(p28,{...z,hiddenTextDescribedById:d}));function q6(){let H6=(b==null?void 0:b.autoScrollEnabled)===!1,f6=typeof G==="object"?G.enabled===!1:G===!1,Z6=T&&!H6&&!f6;if(typeof G==="object")return{...G,enabled:Z6};return{enabled:Z6}}}),hH8=l6.createContext(null),gK6="button",yH8="Draggable";function zX6(J){let{id:Z,data:Q,disabled:K=!1,attributes:X}=J,U=uk(yH8),{activators:Y,activatorEvent:z,active:G,activeNodeRect:W,ariaDescribedById:q,draggableNodes:H,over:B}=l6.useContext(sk),{role:M=gK6,roleDescription:O="draggable",tabIndex:A=0}=X!=null?X:{},N=(G==null?void 0:G.id)===Z,R=l6.useContext(N?Pr:hH8),[w,P]=gk(),[V,D]=gk(),T=jH8(Y,Z),C=YD(Q);Xq(()=>{return H.set(Z,{id:Z,key:U,node:w,activatorNode:V,data:C}),()=>{let f=H.get(Z);if(f&&f.key===U)H.delete(Z)}},[H,Z]);let S=l6.useMemo(()=>({role:M,tabIndex:A,"aria-disabled":K,"aria-pressed":N&&M===gK6?!0:void 0,"aria-roledescription":O,"aria-describedby":q.draggable}),[K,M,A,N,O,q.draggable]);return{active:G,activatorEvent:z,activeNodeRect:W,attributes:S,isDragging:N,listeners:K?void 0:T,node:w,over:B,setNodeRef:P,setActivatorNodeRef:D,transform:R}}function gH8(){return l6.useContext(XX6)}var mH8="Droppable",uH8={timeout:25};function GX6(J){let{data:Z,disabled:Q=!1,id:K,resizeObserverConfig:X}=J,U=uk(mH8),{active:Y,dispatch:z,over:G,measureDroppableContainers:W}=l6.useContext(sk),q=l6.useRef({disabled:Q}),H=l6.useRef(!1),B=l6.useRef(null),M=l6.useRef(null),{disabled:O,updateMeasurementsFor:A,timeout:N}={...uH8,...X},R=YD(A!=null?A:K),w=l6.useCallback(()=>{if(!H.current){H.current=!0;return}if(M.current!=null)clearTimeout(M.current);M.current=setTimeout(()=>{W(Array.isArray(R.current)?R.current:[R.current]),M.current=null},N)},[N]),P=Ir({callback:w,disabled:O||!Y}),V=l6.useCallback((S,f)=>{if(!P)return;if(f)P.unobserve(f),H.current=!1;if(S)P.observe(S)},[P]),[D,T]=gk(V),C=YD(Z);return l6.useEffect(()=>{if(!P||!D.current)return;P.disconnect(),H.current=!1,P.observe(D.current)},[D,P]),l6.useEffect(()=>{return z({type:oQ.RegisterDroppable,element:{id:K,key:U,disabled:Q,node:D,rect:B,data:C}}),()=>z({type:oQ.UnregisterDroppable,key:U,id:K})},[K]),l6.useEffect(()=>{if(Q!==q.current.disabled)z({type:oQ.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:D,over:G,setNodeRef:T}}function pH8(J){let{animation:Z,children:Q}=J,[K,X]=l6.useState(null),[U,Y]=l6.useState(null),z=mk(Q);if(!Q&&!K&&z)X(z);return Xq(()=>{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]),l6.default.createElement(l6.default.Fragment,null,Q,K?l6.cloneElement(K,{ref:Y}):null)}var cH8={x:0,y:0,scaleX:1,scaleY:1};function lH8(J){let{children:Z}=J;return l6.default.createElement(sk.Provider,{value:KX6},l6.default.createElement(Pr.Provider,{value:cH8},Z))}var dH8={position:"fixed",touchAction:"none"},iH8=(J)=>{return Or(J)?"transform 250ms ease":void 0},rH8=l6.forwardRef((J,Z)=>{let{as:Q,activatorEvent:K,adjustScale:X,children:U,className:Y,rect:z,style:G,transform:W,transition:q=iH8}=J;if(!z)return null;let H=X?W:{...W,scaleX:1,scaleY:1},B={...dH8,width:z.width,height:z.height,top:z.top,left:z.left,transform:XD.Transform.toString(H),transformOrigin:X&&K?c28(K,z):void 0,transition:typeof q==="function"?q(K):q,...G};return l6.default.createElement(Q,{className:Y,style:B,ref:Z},U)}),nH8=(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)}},sH8=(J)=>{let{transform:{initial:Z,final:Q}}=J;return[{transform:XD.Transform.toString(Z)},{transform:XD.Transform.toString(Q)}]},aH8={duration:250,easing:"ease",keyframes:sH8,sideEffects:nH8({styles:{active:{opacity:"0"}}})};function oH8(J){let{config:Z,draggableNodes:Q,droppableContainers:K,measuringConfiguration:X}=J;return yk((U,Y)=>{if(Z===null)return;let z=Q.get(U);if(!z)return;let G=z.node.current;if(!G)return;let W=QX6(Y);if(!W)return;let{transform:q}=y1(Y).getComputedStyle(Y),H=lK6(q);if(!H)return;let B=typeof Z==="function"?Z:tH8(Z);return oK6(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 tH8(J){let{duration:Z,easing:Q,sideEffects:K,keyframes:X}={...aH8,...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}}),[O]=M,A=M[M.length-1];if(JSON.stringify(O)===JSON.stringify(A))return;let N=K==null?void 0:K({active:Y,dragOverlay:z,...W}),R=z.node.animate(M,{duration:Z,easing:Q,fill:"forwards"});return new Promise((w)=>{R.onfinish=()=>{N==null||N(),w()}})}}var mK6=0;function eH8(J){return l6.useMemo(()=>{if(J==null)return;return mK6++,mK6},[J])}var WX6=l6.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:O,droppableContainers:A,dragOverlay:N,over:R,measuringConfiguration:w,scrollableAncestors:P,scrollableAncestorRects:V,windowRect:D}=gH8(),T=l6.useContext(Pr),C=eH8(H==null?void 0:H.id),S=UX6(Y,{activatorEvent:q,active:H,activeNodeRect:B,containerNodeRect:M,draggingNodeRect:N.rect,over:R,overlayNodeRect:N.rect,scrollableAncestors:P,scrollableAncestorRects:V,transform:T,windowRect:D}),f=yB0(B),h=oH8({config:K,draggableNodes:O,droppableContainers:A,measuringConfiguration:w}),k=f?N.setRef:void 0;return l6.default.createElement(lH8,null,l6.default.createElement(pH8,{animation:h},H&&C?l6.default.createElement(rH8,{key:C,id:H.id,ref:k,as:z,activatorEvent:q,adjustScale:Z,className:G,transition:U,rect:f,style:{zIndex:W,...X},transform:S},Q):null))});var JB8="",ZB8=()=>({"Content-Type":"application/json","X-Session-Id":o4()});async function qX6(J,Z,Q,{value:K,values:X}){let U=X?{values:X}:{value:K},Y=await fetch(`${JB8}/api/p/${J}/entities/${Z}/fields/${Q}`,{method:"PUT",headers:ZB8(),body:JSON.stringify(U)});return P9(Y,"Failed to set field value")}function Dr(J){let Z=r9();return I4({mutationFn:({entityId:Q,fieldName:K,value:X,values:U})=>qX6(J,Q,K,U?{values:U}:{value:X}),onSuccess:()=>{Z.invalidateQueries({queryKey:["folderContents",J]}),Z.invalidateQueries({queryKey:["stories",J]})}})}var QB8=f0(D6(),1);var l3=f0(e6(),1);function gB0({task:J,onClick:Z,onMoveTask:Q,states:K,isSelected:X}){let{attributes:U,listeners:Y,setNodeRef:z,isDragging:G}=zX6({id:J.id,data:{state:J.fields?.state,task:J}});return l3.jsxDEV("div",{ref:z,...Y,...U,role:"button",tabIndex:0,className:`px-3 py-2 bg-background border rounded-md
3113
3113
  cursor-pointer hover:border-foreground/30 transition-colors
3114
3114
  ${G?"opacity-50":""}
3115
- ${X?"border-primary ring-2 ring-primary/20":"border-border"}`,onClick:()=>Z(J),onKeyDown:(q)=>{if(q.key==="Enter"||q.key===" ")q.preventDefault(),Z(J);if(q.key==="ArrowLeft"){if(q.stopPropagation(),Q&&K){if(K.indexOf(J.fields?.state)>0)Q(J.id,-1)}}if(q.key==="ArrowRight"){if(q.stopPropagation(),Q&&K){let H=K.indexOf(J.fields?.state);if(H>=0&&H<K.length-1)Q(J.id,1)}}},children:[l3.jsxDEV("div",{className:"text-sm truncate",children:J.name},void 0,!1,void 0,this),J.fields?.label&&l3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.label},void 0,!1,void 0,this),J.fields?.colour&&l3.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&&l3.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&&l3.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 L7=f0(e6(),1);function KB8({state:J,children:Z}){let{setNodeRef:Q,isOver:K}=GX6({id:J});return L7.jsxDEV("div",{className:"flex-1 min-w-[160px] flex flex-col",children:[L7.jsxDEV("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground",children:J},void 0,!1,void 0,this),L7.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 HX6({projectId:J,storyId:Z,selectedId:Q,onOpenDocument:K}){let[X,U]=qD.useState(null),[Y,z]=qD.useState(!1),[G,W]=qD.useState(""),[q,H]=qD.useState(""),B=xB0(nk,{activationConstraint:{distance:8}}),M=xB0(rk),O=pK6(B,M),A=Dr(J),N=T3(J),R=r9(),{data:w,isLoading:P,isError:V}=Zj(J,{folderId:Z,type:"d"}),D=w?.find((g)=>g.isFolder&&g.subtype==="tasks"),T=D?.fields?.states??[],{data:C,isLoading:S,isError:f}=Zj(J,{folderId:D?.id,type:"d",enabled:!!D?.id}),h={};for(let g of T)h[g]=[];if(C){for(let g of C)if(!g.isFolder&&g.fields?.state&&h[g.fields.state])h[g.fields.state].push(g)}let k=D?["folderContents",J,"A",D.id,"d","default"]:null;function $(g,u){if(!k)return;A.mutate({entityId:g,fieldName:"state",value:u},{onMutate:()=>{let d=R.getQueryData(k);return R.setQueryData(k,(l)=>l?.map((r)=>r.id===g?{...r,fields:{...r.fields,state:u}}:r)),{previous:d,queryKey:k}},onError:(d,l,r)=>{if(r?.queryKey&&r?.previous)R.setQueryData(r.queryKey,r.previous)}})}function v(g){U(g.active.id)}function _(g){let{active:u,over:d}=g;if(U(null),!d)return;if(u.data.current?.state===d.id)return;$(u.id,d.id)}function b(g,u){let d=C?.find((Y0)=>Y0.id===g);if(!d)return;let l=d.fields?.state,r=T.indexOf(l);if(r===-1)return;let o=r+u;if(o<0||o>=T.length)return;$(g,T[o])}function x(){if(!G.trim())return;if(N.isPending)return;N.mutate({parentId:D.id,name:G.trim(),subtype:"task",fields:{state:q}},{onSuccess:(g)=>{z(!1),W(""),H(T[0]||""),K(g.id,{edit:!0})}})}let m=X?C?.find((g)=>g.id===X):null;if(P)return L7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this);if(V)return L7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Failed to load tasks folder."},void 0,!1,void 0,this);if(!D)return L7.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 L7.jsxDEV(L7.Fragment,{children:[T.length>0&&L7.jsxDEV("div",{className:"px-4 pt-4 flex items-center",children:L7.jsxDEV(g6,{variant:"warning",size:"sm",onClick:()=>{W(""),H(T[0]||""),z(!0)},children:[L7.jsxDEV(X5,{className:"w-4 h-4"},void 0,!1,void 0,this),L7.jsxDEV(aX,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L7.jsxDEV(YX6,{sensors:O,onDragStart:v,onDragEnd:_,children:[L7.jsxDEV("div",{className:"flex gap-3 pb-4 px-4 overflow-x-auto",children:T.map((g)=>L7.jsxDEV(KB8,{state:g,children:S?L7.jsxDEV("div",{className:"text-xs text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this):f?L7.jsxDEV("div",{className:"text-xs text-destructive",children:"Failed to load tasks"},void 0,!1,void 0,this):h[g]?.map((u)=>L7.jsxDEV(gB0,{task:u,isSelected:u.id===Q,onClick:(d)=>K(d.id),states:T,onMoveTask:b},u.id,!1,void 0,this))},g,!1,void 0,this))},void 0,!1,void 0,this),L7.jsxDEV(WX6,{children:m?L7.jsxDEV(gB0,{task:m,isSelected:!1,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),L7.jsxDEV(sJ,{open:Y,onOpenChange:(g)=>{if(z(g),!g)W(""),H(T[0]||"")},children:L7.jsxDEV(vJ,{children:[L7.jsxDEV(fJ,{children:L7.jsxDEV(_J,{children:"New Task"},void 0,!1,void 0,this)},void 0,!1,void 0,this),L7.jsxDEV("div",{className:"py-4 space-y-4",children:[L7.jsxDEV("div",{children:[L7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Name"},void 0,!1,void 0,this),L7.jsxDEV("input",{type:"text",value:G,onChange:(g)=>W(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"&&x(),autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L7.jsxDEV("div",{children:[L7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"State"},void 0,!1,void 0,this),L7.jsxDEV(kQ,{value:q,onValueChange:H,children:[L7.jsxDEV(eZ,{children:L7.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),L7.jsxDEV(JQ,{children:T.map((g)=>L7.jsxDEV(P4,{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),L7.jsxDEV(DZ,{children:[L7.jsxDEV(g6,{variant:"outline",onClick:()=>{z(!1),W(""),H(T[0]||"")},children:"Cancel"},void 0,!1,void 0,this),L7.jsxDEV(g6,{onClick:x,disabled:N.isPending||!G.trim(),children:N.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 Vr=f0(D6(),1);var XB8=f0(D6(),1);var tQ=f0(e6(),1),BX6=({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 tQ.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)},mB0=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},FX6=(J)=>{if(J===null||J===void 0)return"-";if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},Er=async(J)=>{if(!J)return;try{await navigator.clipboard.writeText(J),bZ.success("Copied")}catch(Z){console.error("Failed to copy:",Z)}},ak=(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},HD=({job:J,onClick:Z,projectPath:Q})=>{let K=ak(J.fields?.workingDirectory,Q);return tQ.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:[tQ.jsxDEV(BX6,{status:J.fields?.status},void 0,!1,void 0,this),tQ.jsxDEV(s9,{content:"Click to copy",children:tQ.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(X)=>{X.stopPropagation(),Er(J.id)},children:J.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),tQ.jsxDEV(s9,{content:"Click to copy",children:tQ.jsxDEV("span",{className:"w-64 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(X)=>{if(X.stopPropagation(),J.fields?.sessionId)Er(J.fields?.sessionId)},children:J.fields?.sessionId?J.fields?.sessionId.slice(0,24)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),tQ.jsxDEV("div",{className:"flex-1 min-w-0",children:[tQ.jsxDEV("span",{className:"truncate text-sm font-medium block",children:J.name},void 0,!1,void 0,this),K&&tQ.jsxDEV(s9,{content:J.fields?.workingDirectory,children:tQ.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),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.agent},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-24 truncate",children:J.fields?.model||"-"},void 0,!1,void 0,this),tQ.jsxDEV(s9,{content:"Click to copy",children:tQ.jsxDEV("span",{className:"w-16 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary",onClick:(X)=>{if(X.stopPropagation(),J.fields?.pid)Er(J.fields?.pid)},children:J.fields?.pid||"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:mB0(J.fields?.startedAt)},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:mB0(J.fields?.completedAt)},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:FX6(J.fields?.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var DM=f0(e6(),1),MX6={running:0,completed:1,error:2},OX6=3,LX6=({projectId:J,storyId:Z,storeCode:Q,projectPath:K})=>{let X=dJ(),{data:U=[],isLoading:Y}=Xr(J,{store:Q}),z=Vr.useMemo(()=>{return U.filter((q)=>q.fields?.objectId===Z)},[U,Z]),G=Vr.useMemo(()=>{return[...z].sort((q,H)=>{let B=MX6[q.fields?.status]??OX6,M=MX6[H.fields?.status]??OX6;if(B!==M)return B-M;let O=q.fields?.startedAt?new Date(q.fields.startedAt).getTime():0;return(H.fields?.startedAt?new Date(H.fields.startedAt).getTime():0)-O})},[z]),W=(q)=>{let H=Q?`/project/${J}/store/${Q}/job/${q.id}?from=${Z}`:`/project/${J}/job/${q.id}?from=${Z}`;X(H)};if(Y)return DM.jsxDEV("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(G.length===0)return DM.jsxDEV("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground gap-4",children:[DM.jsxDEV(fG,{className:"w-12 h-12 opacity-50"},void 0,!1,void 0,this),DM.jsxDEV("p",{children:"No jobs associated with this story"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return DM.jsxDEV("div",{className:"p-4 overflow-auto h-full",children:DM.jsxDEV("div",{className:"space-y-0",children:G.map((q)=>DM.jsxDEV(HD,{job:q,onClick:W,projectPath:K},q.id,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var ok="",tk=()=>({"Content-Type":"application/json","X-Session-Id":o4()}),AX6=async(J,{store:Z}={})=>{let Q=new URLSearchParams;if(Z)Q.set("store",Z);let K=Q.toString(),X=`${ok}/api/p/${J}/stories${K?`?${K}`:""}`,U=await fetch(X,{headers:tk()});return P9(U,"Failed to list stories")};var NX6=async(J,{name:Z,store:Q,state:K})=>{let X=await fetch(`${ok}/api/p/${J}/stories`,{method:"POST",headers:tk(),body:JSON.stringify({name:Z,store:Q,state:K})});return P9(X,"Failed to create story")},RX6=async(J,Z,Q)=>{let K=await fetch(`${ok}/api/p/${J}/stories/${Z}/state`,{method:"PATCH",headers:tk(),body:JSON.stringify({state:Q})});return P9(K,"Failed to update story state")},wX6=async(J,Z,Q)=>{let K=await fetch(`${ok}/api/p/${J}/stories/${Z}/name`,{method:"PATCH",headers:tk(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename story")},IX6=async(J,Z)=>{let Q=await fetch(`${ok}/api/p/${J}/stories/${Z}`,{method:"DELETE",headers:tk()});return P9(Q,"Failed to delete story")};var PX6=(J,{store:Z}={})=>{return iZ({queryKey:["stories",J,Z??"demux"],queryFn:()=>AX6(J,{store:Z}),enabled:!!J,staleTime:30000})};var DX6=(J)=>{let Z=r9();return I4({mutationFn:({name:Q,store:K,state:X})=>NX6(J,{name:Q,store:K,state:X}),onSuccess:(Q,{store:K})=>{Z.invalidateQueries({queryKey:["stories",J,K??"demux"]})}})},EX6=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,state:K})=>RX6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},VX6=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,name:K})=>wX6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},jX6=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>IX6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})};var TX6=f0(D6(),1),CX6=(J)=>{let Z=ST0(J,{path:"",store:"A",type:"s"});return{states:TX6.useMemo(()=>Z.data?.fields?.states??[],[Z.data]),isLoading:Z.isLoading,error:Z.error,refetch:Z.refetch}};class O8{constructor(){this.hex="#000000",this.rgb_r=0,this.rgb_g=0,this.rgb_b=0,this.xyz_x=0,this.xyz_y=0,this.xyz_z=0,this.luv_l=0,this.luv_u=0,this.luv_v=0,this.lch_l=0,this.lch_c=0,this.lch_h=0,this.hsluv_h=0,this.hsluv_s=0,this.hsluv_l=0,this.hpluv_h=0,this.hpluv_p=0,this.hpluv_l=0,this.r0s=0,this.r0i=0,this.r1s=0,this.r1i=0,this.g0s=0,this.g0i=0,this.g1s=0,this.g1i=0,this.b0s=0,this.b0i=0,this.b1s=0,this.b1i=0}static fromLinear(J){if(J<=0.0031308)return 12.92*J;else return 1.055*Math.pow(J,0.4166666666666667)-0.055}static toLinear(J){if(J>0.04045)return Math.pow((J+0.055)/1.055,2.4);else return J/12.92}static yToL(J){if(J<=O8.epsilon)return J/O8.refY*O8.kappa;else return 116*Math.pow(J/O8.refY,0.3333333333333333)-16}static lToY(J){if(J<=8)return O8.refY*J/O8.kappa;else return O8.refY*Math.pow((J+16)/116,3)}static rgbChannelToHex(J){let Z=Math.round(J*255),Q=Z%16,K=(Z-Q)/16|0;return O8.hexChars.charAt(K)+O8.hexChars.charAt(Q)}static hexToRgbChannel(J,Z){let Q=O8.hexChars.indexOf(J.charAt(Z)),K=O8.hexChars.indexOf(J.charAt(Z+1));return(Q*16+K)/255}static distanceFromOriginAngle(J,Z,Q){let K=Z/(Math.sin(Q)-J*Math.cos(Q));if(K<0)return 1/0;else return K}static distanceFromOrigin(J,Z){return Math.abs(Z)/Math.sqrt(Math.pow(J,2)+1)}static min6(J,Z,Q,K,X,U){return Math.min(J,Math.min(Z,Math.min(Q,Math.min(K,Math.min(X,U)))))}rgbToHex(){this.hex="#",this.hex+=O8.rgbChannelToHex(this.rgb_r),this.hex+=O8.rgbChannelToHex(this.rgb_g),this.hex+=O8.rgbChannelToHex(this.rgb_b)}hexToRgb(){this.hex=this.hex.toLowerCase(),this.rgb_r=O8.hexToRgbChannel(this.hex,1),this.rgb_g=O8.hexToRgbChannel(this.hex,3),this.rgb_b=O8.hexToRgbChannel(this.hex,5)}xyzToRgb(){this.rgb_r=O8.fromLinear(O8.m_r0*this.xyz_x+O8.m_r1*this.xyz_y+O8.m_r2*this.xyz_z),this.rgb_g=O8.fromLinear(O8.m_g0*this.xyz_x+O8.m_g1*this.xyz_y+O8.m_g2*this.xyz_z),this.rgb_b=O8.fromLinear(O8.m_b0*this.xyz_x+O8.m_b1*this.xyz_y+O8.m_b2*this.xyz_z)}rgbToXyz(){let J=O8.toLinear(this.rgb_r),Z=O8.toLinear(this.rgb_g),Q=O8.toLinear(this.rgb_b);this.xyz_x=0.41239079926595*J+0.35758433938387*Z+0.18048078840183*Q,this.xyz_y=0.21263900587151*J+0.71516867876775*Z+0.072192315360733*Q,this.xyz_z=0.019330818715591*J+0.11919477979462*Z+0.95053215224966*Q}xyzToLuv(){let J=this.xyz_x+15*this.xyz_y+3*this.xyz_z,Z=4*this.xyz_x,Q=9*this.xyz_y;if(J!==0)Z/=J,Q/=J;else Z=NaN,Q=NaN;if(this.luv_l=O8.yToL(this.xyz_y),this.luv_l===0)this.luv_u=0,this.luv_v=0;else this.luv_u=13*this.luv_l*(Z-O8.refU),this.luv_v=13*this.luv_l*(Q-O8.refV)}luvToXyz(){if(this.luv_l===0){this.xyz_x=0,this.xyz_y=0,this.xyz_z=0;return}let J=this.luv_u/(13*this.luv_l)+O8.refU,Z=this.luv_v/(13*this.luv_l)+O8.refV;this.xyz_y=O8.lToY(this.luv_l),this.xyz_x=0-9*this.xyz_y*J/((J-4)*Z-J*Z),this.xyz_z=(9*this.xyz_y-15*Z*this.xyz_y-Z*this.xyz_x)/(3*Z)}luvToLch(){if(this.lch_l=this.luv_l,this.lch_c=Math.sqrt(this.luv_u*this.luv_u+this.luv_v*this.luv_v),this.lch_c<0.00000001)this.lch_h=0;else{let J=Math.atan2(this.luv_v,this.luv_u);if(this.lch_h=J*180/Math.PI,this.lch_h<0)this.lch_h=360+this.lch_h}}lchToLuv(){let J=this.lch_h/180*Math.PI;this.luv_l=this.lch_l,this.luv_u=Math.cos(J)*this.lch_c,this.luv_v=Math.sin(J)*this.lch_c}calculateBoundingLines(J){let Z=Math.pow(J+16,3)/1560896,Q=Z>O8.epsilon?Z:J/O8.kappa,K=Q*(284517*O8.m_r0-94839*O8.m_r2),X=Q*(838422*O8.m_r2+769860*O8.m_r1+731718*O8.m_r0),U=Q*(632260*O8.m_r2-126452*O8.m_r1),Y=Q*(284517*O8.m_g0-94839*O8.m_g2),z=Q*(838422*O8.m_g2+769860*O8.m_g1+731718*O8.m_g0),G=Q*(632260*O8.m_g2-126452*O8.m_g1),W=Q*(284517*O8.m_b0-94839*O8.m_b2),q=Q*(838422*O8.m_b2+769860*O8.m_b1+731718*O8.m_b0),H=Q*(632260*O8.m_b2-126452*O8.m_b1);this.r0s=K/U,this.r0i=X*J/U,this.r1s=K/(U+126452),this.r1i=(X-769860)*J/(U+126452),this.g0s=Y/G,this.g0i=z*J/G,this.g1s=Y/(G+126452),this.g1i=(z-769860)*J/(G+126452),this.b0s=W/H,this.b0i=q*J/H,this.b1s=W/(H+126452),this.b1i=(q-769860)*J/(H+126452)}calcMaxChromaHpluv(){let J=O8.distanceFromOrigin(this.r0s,this.r0i),Z=O8.distanceFromOrigin(this.r1s,this.r1i),Q=O8.distanceFromOrigin(this.g0s,this.g0i),K=O8.distanceFromOrigin(this.g1s,this.g1i),X=O8.distanceFromOrigin(this.b0s,this.b0i),U=O8.distanceFromOrigin(this.b1s,this.b1i);return O8.min6(J,Z,Q,K,X,U)}calcMaxChromaHsluv(J){let Z=J/360*Math.PI*2,Q=O8.distanceFromOriginAngle(this.r0s,this.r0i,Z),K=O8.distanceFromOriginAngle(this.r1s,this.r1i,Z),X=O8.distanceFromOriginAngle(this.g0s,this.g0i,Z),U=O8.distanceFromOriginAngle(this.g1s,this.g1i,Z),Y=O8.distanceFromOriginAngle(this.b0s,this.b0i,Z),z=O8.distanceFromOriginAngle(this.b1s,this.b1i,Z);return O8.min6(Q,K,X,U,Y,z)}hsluvToLch(){if(this.hsluv_l>99.9999999)this.lch_l=100,this.lch_c=0;else if(this.hsluv_l<0.00000001)this.lch_l=0,this.lch_c=0;else{this.lch_l=this.hsluv_l,this.calculateBoundingLines(this.hsluv_l);let J=this.calcMaxChromaHsluv(this.hsluv_h);this.lch_c=J/100*this.hsluv_s}this.lch_h=this.hsluv_h}lchToHsluv(){if(this.lch_l>99.9999999)this.hsluv_s=0,this.hsluv_l=100;else if(this.lch_l<0.00000001)this.hsluv_s=0,this.hsluv_l=0;else{this.calculateBoundingLines(this.lch_l);let J=this.calcMaxChromaHsluv(this.lch_h);this.hsluv_s=this.lch_c/J*100,this.hsluv_l=this.lch_l}this.hsluv_h=this.lch_h}hpluvToLch(){if(this.hpluv_l>99.9999999)this.lch_l=100,this.lch_c=0;else if(this.hpluv_l<0.00000001)this.lch_l=0,this.lch_c=0;else{this.lch_l=this.hpluv_l,this.calculateBoundingLines(this.hpluv_l);let J=this.calcMaxChromaHpluv();this.lch_c=J/100*this.hpluv_p}this.lch_h=this.hpluv_h}lchToHpluv(){if(this.lch_l>99.9999999)this.hpluv_p=0,this.hpluv_l=100;else if(this.lch_l<0.00000001)this.hpluv_p=0,this.hpluv_l=0;else{this.calculateBoundingLines(this.lch_l);let J=this.calcMaxChromaHpluv();this.hpluv_p=this.lch_c/J*100,this.hpluv_l=this.lch_l}this.hpluv_h=this.lch_h}hsluvToRgb(){this.hsluvToLch(),this.lchToLuv(),this.luvToXyz(),this.xyzToRgb()}hpluvToRgb(){this.hpluvToLch(),this.lchToLuv(),this.luvToXyz(),this.xyzToRgb()}hsluvToHex(){this.hsluvToRgb(),this.rgbToHex()}hpluvToHex(){this.hpluvToRgb(),this.rgbToHex()}rgbToHsluv(){this.rgbToXyz(),this.xyzToLuv(),this.luvToLch(),this.lchToHpluv(),this.lchToHsluv()}rgbToHpluv(){this.rgbToXyz(),this.xyzToLuv(),this.luvToLch(),this.lchToHpluv(),this.lchToHpluv()}hexToHsluv(){this.hexToRgb(),this.rgbToHsluv()}hexToHpluv(){this.hexToRgb(),this.rgbToHpluv()}}O8.hexChars="0123456789abcdef";O8.refY=1;O8.refU=0.19783000664283;O8.refV=0.46831999493879;O8.kappa=903.2962962;O8.epsilon=0.0088564516;O8.m_r0=3.240969941904521;O8.m_r1=-1.537383177570093;O8.m_r2=-0.498610760293;O8.m_g0=-0.96924363628087;O8.m_g1=1.87596750150772;O8.m_g2=0.041555057407175;O8.m_b0=0.055630079696993;O8.m_b1=-0.20397695888897;O8.m_b2=1.056971514242878;var E6=f0(e6(),1),UB8={useItem:XG,useCreate:T3,useSaveDraft:CP,usePublish:SP,useDiscard:$P,useVersions:kP,useDelete:vP,useUpdatePath:fP,getVersion:TP},uB0=[{key:"unsorted",icon:hG,label:"Not sorted"},{key:"name-asc",icon:vG,label:"Sorting by name ascending"},{key:"name-desc",icon:kG,label:"Sorting by name descending"},{key:"date-asc",icon:MO,label:"Sorting by date ascending"},{key:"date-desc",icon:FO,label:"Sorting by date descending"},{key:"state-asc",icon:rH,label:"Sorting by state ascending"},{key:"state-desc",icon:iH,label:"Sorting by state descending"}],pB0=(J,Z,Q)=>{let K=new O8;return K.hsluv_h=J,K.hsluv_s=Z,K.hsluv_l=Q,K.hsluvToHex(),K.hex},YB8=(J,Z)=>{if(Z===0)return{bg:"linear-gradient(to bottom, #6b7280, #4b5563)",text:"white",border:"#374151"};let Q=J/Z*360,K=65,X=40,U=pB0(Q,K,X+15),Y=pB0(Q,K,X),z=pB0(Q,K,X-10);return{bg:`linear-gradient(to bottom, ${U}, ${Y})`,text:"white",border:z}},cB0=0.08333333333333333,zB8=0.16666666666666666,GB8=({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;if(U===1)Y=0.5;else Y=cB0+(1-2*cB0)/(U-1)*X;let z=(Y-cB0)*100,G=zB8*100,W=J.charAt(0).toUpperCase()+J.slice(1),q=YB8(X,Z.length);return E6.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:E6.jsxDEV("div",{className:"absolute rounded text-xs flex items-center justify-between px-1 shadow-sm",style:{left:`${z}%`,width:`${G}%`,top:"2px",bottom:"2px",background:q.bg,color:q.text,borderWidth:"1px",borderStyle:"solid",borderColor:q.border},children:[Q?E6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(H)=>{H.stopPropagation(),Q()},onKeyDown:(H)=>{if(H.key==="Enter"||H.key===" ")H.preventDefault(),H.stopPropagation(),Q()},children:E6.jsxDEV(OO,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):E6.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"flex-1 text-center",children:W},void 0,!1,void 0,this),K?E6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(H)=>{H.stopPropagation(),K()},onKeyDown:(H)=>{if(H.key==="Enter"||H.key===" ")H.preventDefault(),H.stopPropagation(),K()},children:E6.jsxDEV(LO,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):E6.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)},WB8=({projectId:J,storyId:Z})=>{let{data:Q,isLoading:K,error:X}=cZ6(J,"s"),[U,Y]=cJ.useState(null),z=Q?.templates??[],G=(H)=>{Y(H)},W=()=>{Y(null)};if(K)return E6.jsxDEV("div",{className:"flex items-center gap-2 p-4 text-muted-foreground",children:[E6.jsxDEV(c7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading templates..."]},void 0,!0,void 0,this);if(X)return E6.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 E6.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 E6.jsxDEV("div",{className:"p-4",children:[E6.jsxDEV("ul",{className:"space-y-1",children:z.map((H)=>E6.jsxDEV("li",{children:E6.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:[E6.jsxDEV(sX,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"truncate",children:H.name},void 0,!1,void 0,this),H.path&&E6.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),E6.jsxDEV(Wr,{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)},qB8=({projectId:J,story:Z,setFieldMutation:Q,onDeleted:K})=>{let[X,U]=cJ.useState(Z.name),[Y,z]=cJ.useState(null),[G,W]=cJ.useState(!1),[q,H]=cJ.useState(null),B=VX6(J),M=jX6(J),O=!X.trim()||X.trim()===Z.name||B.isPending,A=()=>{z(null),B.mutate({id:Z.id,name:X.trim()},{onError:(R)=>z(R.message)})},N=()=>{H(null),M.mutate({id:Z.id},{onSuccess:()=>{W(!1),K()},onError:(R)=>H(R.message)})};return E6.jsxDEV("div",{className:"p-4 space-y-8",children:[E6.jsxDEV("div",{className:"space-y-3",children:[E6.jsxDEV("h3",{className:"text-sm font-medium",children:"Rename"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"flex items-center gap-2",children:[E6.jsxDEV(uZ,{value:X,onChange:(R)=>U(R.target.value),onKeyDown:(R)=>R.key==="Enter"&&!O&&A(),className:"max-w-sm"},void 0,!1,void 0,this),E6.jsxDEV(g6,{size:"sm",onClick:A,disabled:O,children:B.isPending?"Saving...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&E6.jsxDEV("div",{className:"text-sm text-destructive",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"space-y-3",children:[E6.jsxDEV("h3",{className:"text-sm font-medium",children:"Flag"},void 0,!1,void 0,this),E6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"Flag this story to indicate it needs attention"},void 0,!1,void 0,this),E6.jsxDEV(g6,{size:"sm",variant:"outline",onClick:()=>Q.mutate({entityId:Z.id,fieldName:"flag",value:"true"}),disabled:Z.fields?.flag==="true",children:Z.fields?.flag==="true"?"Story is flagged":"Flag Story"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"space-y-3",children:[E6.jsxDEV("h3",{className:"text-sm font-medium",children:"Danger Zone"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"border border-destructive/30 rounded-md p-4",children:E6.jsxDEV("div",{className:"flex items-center justify-between",children:[E6.jsxDEV("div",{children:[E6.jsxDEV("div",{className:"text-sm font-medium",children:"Delete this story"},void 0,!1,void 0,this),E6.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),E6.jsxDEV(g6,{variant:"destructive",size:"sm",onClick:()=>W(!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),E6.jsxDEV(sJ,{open:G,onOpenChange:W,children:E6.jsxDEV(vJ,{children:[E6.jsxDEV(fJ,{children:E6.jsxDEV(_J,{className:"flex items-center gap-2 text-destructive",children:[E6.jsxDEV(B7,{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),E6.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete ",E6.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),q&&E6.jsxDEV("div",{className:"text-sm text-destructive",children:q},void 0,!1,void 0,this),E6.jsxDEV(DZ,{children:[E6.jsxDEV(g6,{variant:"outline",onClick:()=>W(!1),children:"Cancel"},void 0,!1,void 0,this),E6.jsxDEV(g6,{variant:"destructive",onClick:N,disabled:M.isPending,children:M.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)},lB0=()=>{let{id:J,storeCode:Z}=EQ(),{selectedId:Q,setSelectedId:K,isEditMode:X,setEditMode:U,activeTab:Y,setActiveTab:z,expandedId:G,setExpandedId:W}=BM(),{data:q}=w1(J);I1(q?`${q.name} - Stories`:"CAW");let H=Z??"A";GB(J);let{data:B=[],isLoading:M,error:O,refetch:A}=PX6(J,{store:H}),{states:N,isLoading:R,error:w,refetch:P}=CX6(J),V=DX6(J),D=EX6(J),T=Dr(J),[C,S]=cJ.useState(!1),[f,h]=cJ.useState(""),[k,$]=cJ.useState(""),[v,_]=cJ.useState(null);cJ.useEffect(()=>{if(N.length>0&&k==="")$(N[0])},[N,k]);let b=Y||"documents",x=(J0)=>{z(J0)},[m,g]=cJ.useState("state-asc"),u=cJ.useRef(null),{activeStates:d,setActiveStates:l}=xN0(J),r=cJ.useMemo(()=>{if(!d)return new Set(N);let J0=d.filter((j0)=>N.includes(j0));return J0.length>0?new Set(J0):new Set(N)},[d,N]);cJ.useEffect(()=>{if(!d||!N.length)return;let J0=d.filter((j0)=>N.includes(j0));if(J0.length!==d.length)l(J0.length>0&&J0.length<N.length?J0:null)},[d,N,l]);let o=(J0)=>{let j0=d?new Set(d):new Set(N),q0=new Set(j0);if(q0.has(J0))q0.delete(J0);else q0.add(J0);l(q0.size===N.length?null:[...q0])},Y0=cJ.useRef(null);cJ.useEffect(()=>{if(Q&&Y0.current!==Q){if(Y0.current=Q,!Y||Y!=="documents"&&Y!=="tasks")z("documents")}else if(!Q)Y0.current=null},[Q,Y,z]);let e=G??"",B0=cJ.useRef({});cJ.useEffect(()=>{if(!M&&G&&B0.current[G])setTimeout(()=>{B0.current[G]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},[M,G]);let Q0=(J0)=>{if(W(J0||null),J0)setTimeout(()=>{B0.current[J0]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},M0=cJ.useMemo(()=>{if(!N.length)return[];let J0=B.filter((q0)=>q0.fields?.state&&r.has(q0.fields.state));if(m==="unsorted"){if(u.current){let q0=u.current,v0=[...J0];return v0.sort((Z0,e0)=>{let X0=q0.indexOf(Z0.id),T0=q0.indexOf(e0.id);return(X0===-1?1/0:X0)-(T0===-1?1/0:T0)}),v0}return J0}let j0=[...J0];return j0.sort((q0,v0)=>{if(m==="name-asc")return q0.name.localeCompare(v0.name);if(m==="name-desc")return v0.name.localeCompare(q0.name);if(m==="date-asc"||m==="date-desc"){let Z0=(X0)=>X0.createdAt?new Date(X0.createdAt).getTime():parseInt(X0.id.replace(/\D/g,""),10)||0,e0=Z0(q0)-Z0(v0);return m==="date-asc"?e0:-e0}if(m==="state-asc")return N.indexOf(q0.fields.state)-N.indexOf(v0.fields.state);if(m==="state-desc")return N.indexOf(v0.fields.state)-N.indexOf(q0.fields.state);return 0}),j0},[B,N,m,r]),W0=()=>{if(!f.trim()){_("Story name is required");return}_(null),V.mutate({name:f.trim(),store:H,state:k},{onSuccess:(J0)=>{S(!1),h(""),$(N[0]||""),W(J0.id)},onError:(J0)=>{_(J0.message)}})},H0=()=>{S(!1),h(""),$(N[0]||""),_(null)},U0=M||R,K0=O||w,O0=O?A:P;if(U0)return E6.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(K0)return E6.jsxDEV("div",{className:"p-6",children:[E6.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading stories"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:K0.message},void 0,!1,void 0,this),E6.jsxDEV(g6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>O0(),children:[E6.jsxDEV(NO,{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 E6.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[E6.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:E6.jsxDEV("div",{className:"flex items-center gap-2",children:[E6.jsxDEV(g6,{size:"sm",variant:"warning",onClick:()=>S(!0),children:[E6.jsxDEV(X5,{className:"w-4 h-4"},void 0,!1,void 0,this),E6.jsxDEV(nH,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(Ah,{children:[E6.jsxDEV(s9,{content:uB0.find((J0)=>J0.key===m)?.label,children:E6.jsxDEV(Nh,{asChild:!0,children:E6.jsxDEV(g6,{size:"sm",variant:"outline",children:cJ.default.createElement(uB0.find((J0)=>J0.key===m)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(Fj,{align:"start",children:uB0.map((J0)=>E6.jsxDEV(Mj,{onClick:()=>{if(J0.key==="unsorted")u.current=M0.map((j0)=>j0.id);else u.current=null;g(J0.key)},className:m===J0.key?"bg-accent":"",children:[E6.jsxDEV(J0.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),J0.label]},J0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(IK6,{children:[E6.jsxDEV(s9,{content:"Filter by state",children:E6.jsxDEV(PK6,{asChild:!0,children:E6.jsxDEV(g6,{size:"sm",variant:"outline",children:E6.jsxDEV(eH,{className:"w-4 h-4",...d&&{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),E6.jsxDEV(TB0,{align:"center",children:E6.jsxDEV("div",{className:"space-y-2",children:[E6.jsxDEV("div",{className:"text-sm font-medium",children:"Show by state:"},void 0,!1,void 0,this),N.map((J0)=>E6.jsxDEV("label",{className:"flex items-center gap-2",children:[E6.jsxDEV(FH,{checked:r.has(J0),onCheckedChange:()=>o(J0)},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"text-sm capitalize",children:J0},void 0,!1,void 0,this)]},J0,!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),M0.length===0?E6.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories yet"},void 0,!1,void 0,this):E6.jsxDEV("div",{className:"flex-1 overflow-auto",children:E6.jsxDEV(Db,{type:"single",collapsible:!0,value:e,onValueChange:Q0,children:M0.map((J0)=>{let j0=N.indexOf(J0.fields.state),q0=j0>0?N[j0-1]:null,v0=j0<N.length-1?N[j0+1]:null;return E6.jsxDEV(Eb,{value:J0.id,className:"border-b",ref:(Z0)=>{B0.current[J0.id]=Z0},children:[E6.jsxDEV(Vb,{className:"grid grid-cols-[24%_50%_24%] 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 gap-[1%]",children:[E6.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[E6.jsxDEV(nH,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"truncate text-sm",children:J0.name},void 0,!1,void 0,this),E6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${J0.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:J0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"grid grid-cols-8 items-center",children:[E6.jsxDEV("span",{className:"text-xs text-muted-foreground text-right pr-1",children:"Status:"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"col-span-6",children:E6.jsxDEV(GB8,{state:J0.fields.state,states:N,onPrev:q0?()=>D.mutate({id:J0.id,state:q0}):null,onNext:v0?()=>D.mutate({id:J0.id,state:v0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"grid grid-cols-[20px_40px] items-center ml-2",children:[E6.jsxDEV("div",{className:"flex justify-center",children:J0.fields?.flag==="true"&&E6.jsxDEV(HV,{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(),T.mutate({entityId:J0.id,fieldName:"flag",value:"false"})}},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"flex justify-center",children:parseInt(J0.fields?.activeJobCount||"0",10)>0&&E6.jsxDEV("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[E6.jsxDEV(xG,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"text-[10px] font-mono text-blue-600 dark:text-blue-300",children:J0.fields.activeJobCount},void 0,!1,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),E6.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[J0.fields?.statusMessage?.trim()&&E6.jsxDEV(XK6,{message:J0.fields.statusMessage,onNavigate:(Z0)=>{W(J0.id,{history:"replace"}),K(Z0)}},void 0,!1,void 0,this),E6.jsxDEV(o1,{className:"chevron w-4 h-4 flex-shrink-0 transition-transform ml-auto"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(jb,{className:"border-t",children:E6.jsxDEV(ZK6,{value:b,onValueChange:x,children:[E6.jsxDEV(EB0,{variant:"line",className:"px-4",children:[E6.jsxDEV(h3,{value:"documents",children:[E6.jsxDEV(rZ,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Documents"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"tasks",children:[E6.jsxDEV(aX,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Tasks"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"prompts",children:[E6.jsxDEV(zz,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"jobs",children:[E6.jsxDEV(xG,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Jobs"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"settings",children:[E6.jsxDEV(Wz,{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),E6.jsxDEV(y3,{value:"documents",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(Dh,{projectId:J,rootFolderId:J0.id,type:"d",DetailPanel:yd,hooks:UB8},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"tasks",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(HX6,{projectId:J,storyId:J0.id,selectedId:Q,onOpenDocument:(Z0,e0)=>{K(Z0,{edit:e0?.edit})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"prompts",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(WB8,{projectId:J,storyId:J0.id},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"jobs",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(LX6,{projectId:J,storyId:J0.id,storeCode:Z,projectPath:q?.path},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"settings",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(qB8,{projectId:J,story:J0,setFieldMutation:T,onDeleted:()=>{W(null)}},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)]},J0.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(sJ,{open:C,onOpenChange:H0,children:E6.jsxDEV(vJ,{children:[E6.jsxDEV(fJ,{children:E6.jsxDEV(_J,{children:"Create Story"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"space-y-4 py-4",children:[E6.jsxDEV("div",{className:"space-y-2",children:[E6.jsxDEV(y4,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),E6.jsxDEV(uZ,{id:"name",value:f,onChange:(J0)=>h(J0.target.value),placeholder:"Enter story name",onKeyDown:(J0)=>J0.key==="Enter"&&W0()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"space-y-2",children:[E6.jsxDEV(y4,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),E6.jsxDEV(kQ,{value:k,onValueChange:$,children:[E6.jsxDEV(eZ,{children:E6.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(JQ,{children:N.map((J0)=>E6.jsxDEV(P4,{value:J0,children:J0.charAt(0).toUpperCase()+J0.slice(1)},J0,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),v&&E6.jsxDEV("div",{className:"text-sm text-destructive",children:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(DZ,{children:[E6.jsxDEV(g6,{variant:"outline",onClick:H0,children:"Cancel"},void 0,!1,void 0,this),E6.jsxDEV(g6,{onClick:W0,disabled:V.isPending,children:V.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 W1=f0(D6(),1);var g1=f0(D6(),1);var b9=f0(e6(),1),HB8=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],SX6=({open:J,onOpenChange:Z,projectId:Q,onSuccess:K,initialPrompt:X=""})=>{let[U,Y]=g1.useState(""),[z,G]=g1.useState("claude"),[W,q]=g1.useState(""),[H,B]=g1.useState({type:"main",path:null}),[M,O]=g1.useState(""),[A,N]=g1.useState(""),[R,w]=g1.useState(!1),[P,V]=g1.useState(!1),[D,T]=g1.useState({}),[C,S]=g1.useState(!1),[f,h]=g1.useState(null),[k,$]=g1.useState(null);g1.useEffect(()=>{if(X)O(X)},[X]);let{data:v,isLoading:_,error:b}=Yr(J?Q:null),x=v?.worktrees??[],m=v?.isGitProject??!0,g=Ur(Q),u=hd(Q),d=zr(Q),{data:l}=_P(Q,A.trim()||null),r=l?.parameters??[],o=l?.detectedVariables??[],Y0=A.trim().length>0,e=()=>{Y(""),G("claude"),q(""),B({type:"main",path:null}),O(X||""),N(""),w(!1),h(null),$(null),T({}),S(!1)},B0=()=>{e(),Z(!1)},Q0=()=>{if(H.type==="main")return;return H.path||void 0},M0=(q0)=>{g.mutate({name:U.trim()||void 0,agent:z,model:W.trim()||void 0,prompt:M.trim(),workingDirectory:q0,streaming:R},{onSuccess:(v0)=>{if(B0(),K)K(v0)},onError:(v0)=>{h(v0.message)}})},W0=()=>{if(!M.trim()){h("Prompt is required");return}if(H.type==="new"&&m){if(!H.branch||!H.branch.trim()){$("Branch name is required");return}}if(h(null),$(null),H.type==="new"&&m&&H.branch)d.mutate({branch:H.branch.trim(),baseBranch:H.baseBranch?.trim()||void 0},{onSuccess:(q0)=>{M0(q0.path)},onError:(q0)=>{$(q0.message)}});else M0(Q0())},H0=()=>{V(!0)},U0=(q0)=>{T(q0),u.mutate({id:A.trim(),params:q0,target:"stdout"},{onSuccess:(v0)=>{if(v0.content)O(v0.content);N(""),V(!1)},onError:(v0)=>{h(`Template render failed: ${v0.message}`),V(!1)}})},K0=Y0?"render":"run",O0=K0==="run"&&!M.trim(),J0=d.isPending,j0=g.isPending||u.isPending||J0;return b9.jsxDEV(b9.Fragment,{children:[b9.jsxDEV(sJ,{open:J,onOpenChange:B0,children:b9.jsxDEV(vJ,{className:"max-w-lg",children:[b9.jsxDEV(fJ,{children:b9.jsxDEV(_J,{children:"New Job"},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV("div",{className:"space-y-4 py-4",children:[b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),b9.jsxDEV(uZ,{id:"job-name",value:U,onChange:(q0)=>Y(q0.target.value),placeholder:"Auto-generated if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),b9.jsxDEV(kQ,{value:z,onValueChange:G,children:[b9.jsxDEV(eZ,{children:b9.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(JQ,{children:HB8.map((q0)=>b9.jsxDEV(P4,{value:q0.value,children:q0.label},q0.value,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),b9.jsxDEV(uZ,{id:"job-model",value:W,onChange:(q0)=>q(q0.target.value),placeholder:"Optional - uses default if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="claude"&&b9.jsxDEV("div",{className:"flex items-center gap-2",children:[b9.jsxDEV(FH,{id:"job-streaming",checked:R,onCheckedChange:w},void 0,!1,void 0,this),b9.jsxDEV(y4,{htmlFor:"job-streaming",className:"text-sm font-normal cursor-pointer",children:"Enable streaming output"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV("button",{type:"button",onClick:()=>S(!C),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[C?b9.jsxDEV(o1,{className:"w-4 h-4"},void 0,!1,void 0,this):b9.jsxDEV(rX,{className:"w-4 h-4"},void 0,!1,void 0,this),b9.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&b9.jsxDEV(Kr,{value:H,onChange:B,worktrees:x,isLoadingWorktrees:_,isGitProject:m,error:b,createError:k,onCreateErrorClear:()=>$(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),b9.jsxDEV(Kq,{id:"job-prompt",value:M,onChange:(q0)=>O(q0.target.value),placeholder:"Enter the prompt for the agent...",rows:6},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),b9.jsxDEV(uZ,{id:"job-template",value:A,onChange:(q0)=>N(q0.target.value),placeholder:"Template ID (optional)"},void 0,!1,void 0,this),Y0&&b9.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),f&&b9.jsxDEV("div",{className:"text-sm text-destructive",children:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(DZ,{children:[b9.jsxDEV(g6,{variant:"outline",onClick:B0,children:"Cancel"},void 0,!1,void 0,this),K0==="render"?b9.jsxDEV(g6,{onClick:H0,disabled:j0,children:[b9.jsxDEV(rZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),j0?"Rendering...":"Render"]},void 0,!0,void 0,this):b9.jsxDEV(g6,{onClick:W0,disabled:O0||j0,children:[b9.jsxDEV(oX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),J0?"Creating worktree...":g.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),b9.jsxDEV(sJ,{open:P,onOpenChange:V,children:b9.jsxDEV(vJ,{className:"max-w-lg",children:[b9.jsxDEV(fJ,{children:b9.jsxDEV(_J,{className:"flex items-center gap-2",children:[b9.jsxDEV(rZ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",KY(l?.path)," (",A,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(Qr,{fields:r,detectedVariables:o,initialValues:D,onSubmit:U0,onCancel:()=>V(!1),isSubmitting:u.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 D9=f0(e6(),1),BB8=86400000,$X6=({title:J,count:Z})=>{return D9.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[D9.jsxDEV("h3",{className:"text-sm font-semibold text-foreground",children:J},void 0,!1,void 0,this),D9.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",Z,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},FB8=({column:J,sortColumn:Z,sortDirection:Q})=>{if(Z!==J)return D9.jsxDEV(HO,{className:"w-3 h-3 ml-1 opacity-50"},void 0,!1,void 0,this);return Q==="asc"?D9.jsxDEV(BO,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this):D9.jsxDEV(qO,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)},iB0=({onSort:J,sortColumn:Z,sortDirection:Q})=>{return D9.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-64",sortable:!1},{key:"name",label:"Name",width:"flex-1"},{key:"agent",label:"Agent",width:"w-16"},{key:"model",label:"Model",width:"w-24"},{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 D9.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&&D9.jsxDEV(FB8,{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)},kX6=["active","history"],dB0=(J,Z,Q="")=>{let K=Z?`/project/${J}/store/${Z}/jobs`:`/project/${J}/jobs`;return Q?`${K}/${Q}`:K},vX6=({active:J,onClick:Z,children:Q})=>D9.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),MB8=({activeJobs:J,completedJobs:Z,onJobClick:Q,onNewJob:K,projectPath:X,onActiveSort:U,activeSortColumn:Y,activeSortDirection:z,onCompletedSort:G,completedSortColumn:W,completedSortDirection:q})=>D9.jsxDEV("div",{className:"space-y-6",children:[D9.jsxDEV("div",{className:"flex justify-start",children:D9.jsxDEV(g6,{size:"sm",variant:"warning",onClick:K,children:[D9.jsxDEV(X5,{className:"w-4 h-4"},void 0,!1,void 0,this),D9.jsxDEV(xG,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),D9.jsxDEV("div",{children:[D9.jsxDEV($X6,{title:"Active Jobs",count:J.length},void 0,!1,void 0,this),J.length>0?D9.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[D9.jsxDEV(iB0,{onSort:U,sortColumn:Y,sortDirection:z},void 0,!1,void 0,this),J.map((H)=>D9.jsxDEV(HD,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):D9.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[D9.jsxDEV(oX,{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),D9.jsxDEV("div",{children:[D9.jsxDEV($X6,{title:"Recently Completed",count:Z.length},void 0,!1,void 0,this),Z.length>0?D9.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[D9.jsxDEV(iB0,{onSort:G,sortColumn:W,sortDirection:q},void 0,!1,void 0,this),Z.map((H)=>D9.jsxDEV(HD,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):D9.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[D9.jsxDEV(fG,{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),OB8=({completedJobs:J,onJobClick:Z,projectPath:Q,onSort:K,sortColumn:X,sortDirection:U})=>D9.jsxDEV("div",{children:J.length>0?D9.jsxDEV(D9.Fragment,{children:[D9.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),D9.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[D9.jsxDEV(iB0,{onSort:K,sortColumn:X,sortDirection:U},void 0,!1,void 0,this),J.map((Y)=>D9.jsxDEV(HD,{job:Y,onClick:Z,projectPath:Q},Y.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):D9.jsxDEV("div",{className:"text-center py-8 text-muted-foreground",children:[D9.jsxDEV(fG,{className:"w-8 h-8 mx-auto mb-2 opacity-50"},void 0,!1,void 0,this),D9.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),ek=()=>{let{id:J,storeCode:Z,tab:Q}=EQ(),K=dJ(),X=a4(),{data:U}=w1(J),Y=Q&&!kX6.includes(Q),z=kX6.includes(Q)?Q:"active";I1(U?`${U.name} - Jobs`:"CAW");let[G,W]=W1.useState(!1),[q,H]=W1.useState(""),[B,M]=W1.useState("startedAt"),[O,A]=W1.useState("desc"),[N,R]=W1.useState("completedAt"),[w,P]=W1.useState("desc"),[V,D]=W1.useState("completedAt"),[T,C]=W1.useState("desc"),S=Z??"A";GB(J);let{data:f=[],isLoading:h,error:k,refetch:$}=Xr(J,{store:S}),v=(o)=>{return["startedAt","completedAt","tokensUsed"].includes(o)?"desc":"asc"},_=(o)=>{if(B===o)A((Y0)=>Y0==="asc"?"desc":"asc");else M(o),A(v(o))},b=(o)=>{if(N===o)P((Y0)=>Y0==="asc"?"desc":"asc");else R(o),P(v(o))},x=(o)=>{if(V===o)C((Y0)=>Y0==="asc"?"desc":"asc");else D(o),C(v(o))},m=(o,Y0,e)=>{return[...o].sort((B0,Q0)=>{let M0=0;switch(Y0){case"status":let W0={running:0,completed:1,error:2};M0=(W0[B0.fields?.status]??3)-(W0[Q0.fields?.status]??3);break;case"name":M0=(B0.name||"").localeCompare(Q0.name||"");break;case"agent":M0=(B0.fields?.agent||"").localeCompare(Q0.fields?.agent||"");break;case"model":M0=(B0.fields?.model||"").localeCompare(Q0.fields?.model||"");break;case"startedAt":case"completedAt":let H0=(O0)=>{if(!O0)return 0;let J0=new Date(O0).getTime();return isNaN(J0)?0:J0},U0=H0(B0.fields?.[Y0]),K0=H0(Q0.fields?.[Y0]);M0=U0-K0;break;case"tokensUsed":M0=(B0.fields?.tokensUsed??0)-(Q0.fields?.tokensUsed??0);break;default:M0=0}return e==="asc"?M0:-M0})},g=W1.useMemo(()=>{let o=f.filter((Y0)=>Y0.fields?.status==="running");return m(o,B,O)},[f,B,O]),u=W1.useMemo(()=>{let o=Date.now()-BB8,Y0=f.filter((e)=>e.fields?.status==="completed"||e.fields?.status==="error").filter((e)=>e.fields?.completedAt&&new Date(e.fields?.completedAt).getTime()>o);return m(Y0,N,w)},[f,N,w]),d=W1.useMemo(()=>{let o=f.filter((Y0)=>Y0.fields?.status==="completed"||Y0.fields?.status==="error");return m(o,V,T)},[f,V,T]),l=(o)=>{let Y0=Z?`/project/${J}/store/${Z}/job/${o.id}?from=${z}`:`/project/${J}/job/${o.id}?from=${z}`;K(Y0)},r=(o)=>{if(o&&o.id){let Y0=Z?`/project/${J}/store/${Z}/job/${o.id}?from=${z}`:`/project/${J}/job/${o.id}?from=${z}`;K(Y0)}};if(W1.useEffect(()=>{if(X.state?.openNewJobWithPrompt)H(X.state.openNewJobWithPrompt),W(!0),K(X.pathname,{replace:!0,state:{}})},[X.state,K,X.pathname]),W1.useEffect(()=>{if(Y)K(dB0(J,Z,"active"),{replace:!0})},[Y,K,J,Z]),Y)return null;if(h)return D9.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(k)return D9.jsxDEV("div",{className:"p-6",children:[D9.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),D9.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:k.message},void 0,!1,void 0,this),D9.jsxDEV(g6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>$(),children:[D9.jsxDEV(NO,{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 D9.jsxDEV("div",{className:"h-full flex flex-col",children:[D9.jsxDEV("div",{className:"flex border-b overflow-x-auto bg-muted/50 px-2",role:"tablist","aria-label":"Jobs tabs",children:[D9.jsxDEV(vX6,{active:z==="active",onClick:()=>K(dB0(J,Z,"active")),children:"Active"},void 0,!1,void 0,this),D9.jsxDEV(vX6,{active:z==="history",onClick:()=>K(dB0(J,Z,"history")),children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D9.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:z==="active"?D9.jsxDEV(MB8,{activeJobs:g,completedJobs:u,onJobClick:l,onNewJob:()=>W(!0),projectPath:U?.path,onActiveSort:_,activeSortColumn:B,activeSortDirection:O,onCompletedSort:b,completedSortColumn:N,completedSortDirection:w},void 0,!1,void 0,this):D9.jsxDEV(OB8,{completedJobs:d,onJobClick:l,projectPath:U?.path,onSort:x,sortColumn:V,sortDirection:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),D9.jsxDEV(SX6,{open:G,onOpenChange:(o)=>{if(W(o),!o)H("")},projectId:J,onSuccess:r,initialPrompt:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var lJ=f0(D6(),1);var rB0=f0(D6(),1);var Jv=f0(e6(),1),jr=({value:J,disabled:Z=!1,className:Q=""})=>{let[K,X]=rB0.useState(!1);return Jv.jsxDEV(s9,{content:"Copy to clipboard",children:Jv.jsxDEV(g6,{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?Jv.jsxDEV(A1,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):Jv.jsxDEV(kZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var LH=f0(D6(),1);var eQ=f0(e6(),1),fX6=({open:J,onOpenChange:Z,sessionId:Q,currentModel:K,onContinue:X,isLoading:U})=>{let[Y,z]=LH.useState(""),[G,W]=LH.useState(""),q=LH.useRef(null);LH.useEffect(()=>{if(!J)z(""),W("");else W(K||"")},[J,K]),LH.useEffect(()=>{if(J&&q.current){let O=setTimeout(()=>{q.current?.focus()},50);return()=>clearTimeout(O)}},[J]);let H=(O)=>{O.preventDefault();let A=Y.trim();if(A)X(A,G.trim()||void 0)},B=()=>{z(""),W(""),Z(!1)},M=!Y.trim()||U;return eQ.jsxDEV(sJ,{open:J,onOpenChange:B,children:eQ.jsxDEV(vJ,{children:[eQ.jsxDEV(fJ,{children:eQ.jsxDEV(_J,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),eQ.jsxDEV("form",{onSubmit:H,className:"space-y-4",children:[eQ.jsxDEV("div",{className:"space-y-2",children:[eQ.jsxDEV(y4,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),eQ.jsxDEV(uZ,{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),eQ.jsxDEV("div",{className:"space-y-2",children:[eQ.jsxDEV(y4,{htmlFor:"continue-model",children:"Model"},void 0,!1,void 0,this),eQ.jsxDEV(uZ,{id:"continue-model",value:G,onChange:(O)=>W(O.target.value),placeholder:"Optional - uses current model if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),eQ.jsxDEV("div",{className:"space-y-2",children:[eQ.jsxDEV(y4,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),eQ.jsxDEV(Kq,{ref:q,id:"continue-prompt",value:Y,onChange:(O)=>z(O.target.value),placeholder:"Enter your follow-up prompt...",rows:6,autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),eQ.jsxDEV(DZ,{children:[eQ.jsxDEV(g6,{type:"button",variant:"outline",onClick:B,children:"Cancel"},void 0,!1,void 0,this),eQ.jsxDEV(g6,{type:"submit",disabled:M,children:[U&&eQ.jsxDEV(c7,{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 LB8=f0(D6(),1);var FQ=f0(e6(),1),_X6=({open:J,onOpenChange:Z,projectId:Q,jobId:K,pid:X})=>{let{data:U,isLoading:Y,error:z,refetch:G}=$16(Q,K,J),W=()=>{if(Y)return FQ.jsxDEV(c7,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this);if(z)return FQ.jsxDEV(B7,{className:"w-5 h-5 text-destructive"},void 0,!1,void 0,this);if(U?.exists)return FQ.jsxDEV(yU,{className:"w-5 h-5 text-green-600"},void 0,!1,void 0,this);return FQ.jsxDEV(_G,{className:"w-5 h-5 text-muted-foreground"},void 0,!1,void 0,this)},q=()=>{if(Y)return"Checking process...";if(z)return`Error: ${z.message}`;if(U?.error)return U.error;if(!U?.exists)return"Process not running";return`Process is ${U.state||"active"}`};return FQ.jsxDEV(sJ,{open:J,onOpenChange:Z,children:FQ.jsxDEV(vJ,{children:[FQ.jsxDEV(fJ,{children:FQ.jsxDEV(_J,{children:"Process Diagnostics"},void 0,!1,void 0,this)},void 0,!1,void 0,this),FQ.jsxDEV("div",{className:"space-y-4",children:[FQ.jsxDEV("div",{className:"flex items-center gap-3 p-4 border rounded-lg",children:[W(),FQ.jsxDEV("div",{children:[FQ.jsxDEV("p",{className:"font-medium",children:q()},void 0,!1,void 0,this),FQ.jsxDEV("p",{className:"text-sm text-muted-foreground font-mono",children:["PID: ",X]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?.exists&&U?.command&&FQ.jsxDEV("div",{className:"text-sm",children:[FQ.jsxDEV("span",{className:"font-medium",children:"Command: "},void 0,!1,void 0,this),FQ.jsxDEV("span",{className:"font-mono",children:U.command},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),FQ.jsxDEV(DZ,{children:[FQ.jsxDEV(g6,{variant:"outline",onClick:()=>G(),children:"Refresh"},void 0,!1,void 0,this),FQ.jsxDEV(g6,{onClick:()=>Z(!1),children:"Close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var Q8=f0(e6(),1),AB8=({status:J})=>{let Z={running:{icon:c7,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:yU,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:_G,class:"text-red-700 border-red-300 bg-red-50",animate:!1},pending:{icon:GV,class:"text-gray-700 border-gray-300 bg-gray-50",animate:!1}},{icon:Q,class:K,animate:X}=Z[J]||Z.pending;return Q8.jsxDEV("span",{className:`inline-flex items-center gap-1.5 rounded border px-2 py-1 text-sm font-medium ${K}`,children:[Q8.jsxDEV(Q,{className:`w-4 h-4 ${X?"animate-spin":""}`},void 0,!1,void 0,this),J]},void 0,!0,void 0,this)},bX6=(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"})},NB8=(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()},xX6=(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},nB0=({title:J,docId:Z,isOpen:Q,onToggle:K,deepLinkUrl:X,children:U})=>Q8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[Q8.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?Q8.jsxDEV(o1,{className:"w-4 h-4"},void 0,!1,void 0,this):Q8.jsxDEV(rX,{className:"w-4 h-4"},void 0,!1,void 0,this),Q8.jsxDEV(rZ,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"font-medium",children:J},void 0,!1,void 0,this),Z&&Q8.jsxDEV("span",{className:"text-xs text-muted-foreground ml-auto font-mono flex items-center gap-1",children:[Z,X&&Q8.jsxDEV("span",{onClick:(Y)=>Y.stopPropagation(),children:Q8.jsxDEV(jr,{value:X},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q&&Q8.jsxDEV("div",{className:"p-4",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),hX6=({turnNumber:J,promptContent:Z,outputContent:Q,showHeading:K,promptDocId:X,outputDocId:U,isPromptOpen:Y,setIsPromptOpen:z,isOutputOpen:G,setIsOutputOpen:W,onInternalLinkClick:q,promptDeepLinkUrl:H,outputDeepLinkUrl:B,sectionRef:M,highlightedSection:O})=>{return Q8.jsxDEV("div",{className:"space-y-4",ref:O?M:null,children:[K&&Q8.jsxDEV("h3",{className:"text-lg font-semibold text-muted-foreground",children:["Turn ",J]},void 0,!0,void 0,this),Q&&Q8.jsxDEV(nB0,{title:"Output",docId:U,isOpen:G,onToggle:W,deepLinkUrl:B,children:Q8.jsxDEV(yY,{markdown:Q,onInternalLinkClick:q},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q8.jsxDEV(nB0,{title:"Prompt",docId:X,isOpen:Y,onToggle:z,deepLinkUrl:H,children:Q8.jsxDEV(yY,{markdown:Z||"",onInternalLinkClick:q},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},RB8=({content:J,isOpen:Z,onToggle:Q})=>Q8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[Q8.jsxDEV("button",{onClick:()=>Q(!Z),className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[Z?Q8.jsxDEV(o1,{className:"w-4 h-4"},void 0,!1,void 0,this):Q8.jsxDEV(rX,{className:"w-4 h-4"},void 0,!1,void 0,this),Q8.jsxDEV(LV,{className:"w-4 h-4 text-blue-500 animate-pulse"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"font-medium",children:"Streaming Output"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"text-xs text-blue-500 ml-2",children:"(live)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&Q8.jsxDEV("div",{className:"p-4",children:J?Q8.jsxDEV("pre",{className:"whitespace-pre-wrap font-mono text-sm bg-muted/20 p-4 rounded overflow-auto max-h-[600px]",children:J},void 0,!1,void 0,this):Q8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-4",children:[Q8.jsxDEV(c7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Waiting for output..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wB8=86400000,IB8=["active","history"],sB0=()=>{let{id:J,storeCode:Z,jobId:Q}=EQ(),K=dJ(),X=a4(),{data:U}=w1(J),{fromContext:Y}=BM(),z=new URLSearchParams(X.search).get("doc");I1(U?`${U.name} - Job: ${Q}`:"CAW"),GB(J);let[G,W]=lJ.useState(""),[q,H]=lJ.useState(!1),B=lJ.useRef(null),{data:M,isLoading:O,error:A}=j16(J,Q),{data:N,isLoading:R}=T16(J,Q),{promptDoc:w,outputDoc:P}=lJ.useMemo(()=>{if(!N)return{promptDoc:null,outputDoc:null};let R0=N.documents||[],P0=R0.find((A0)=>A0.name==="prompt.md"),s=R0.find((A0)=>A0.name==="output.md");return{promptDoc:P0,outputDoc:s}},[N]),{data:V}=XG(J,w?.id),{data:D}=XG(J,P?.id),T=V?.draftContent??V?.publishedContent??"",C=D?.draftContent??D?.publishedContent??"",S=lJ.useMemo(()=>xX6(T),[T]),f=lJ.useMemo(()=>xX6(C),[C]),h=S.length>1||f.length>1,k=async({type:R0,id:P0,path:s,anchor:A0})=>{if(R0==="anchor"){K(`${X.pathname}${X.search}#${A0}`,{replace:!0});return}if(R0==="id"){let N0=P0?.charAt(1)?.toLowerCase();if(N0==="d"||N0==="t"){H0({id:P0,anchor:A0||null});return}}let i=A0?`#${A0}`:"",L0=Z?`/store/${Z}`:"";if(R0==="id"){let N0=P0?.charAt(1)?.toLowerCase();if(N0==="j")K(`/project/${J}${L0}/job/${P0}${i}`);else if(N0==="s")K(`/project/${J}${L0}/stories?expanded=${P0}${i}`);else if(N0==="f")try{let x0=await g5(J,P0),$0=x0?.path||"";if($0.startsWith("Templates/"))K(`/project/${J}${L0}/templates?id=${P0}${i}`);else if($0.startsWith("Stories/")){let D0=x0?.parentId?.startsWith("As")?x0.parentId:null;if(!D0){let h0=x0?.parentId?await g5(J,x0.parentId):null;while(h0&&!D0)if(h0.parentId?.startsWith("As"))D0=h0.parentId;else if(h0.id?.startsWith("As"))D0=h0.id;else h0=h0.parentId?await g5(J,h0.parentId):null}if(D0)K(`/project/${J}${L0}/stories?expanded=${D0}&id=${P0}&tab=documents${i}`);else K(`/project/${J}${L0}/stories?id=${P0}${i}`)}else K(`/project/${J}${L0}/documents?id=${P0}${i}`)}catch{K(`/project/${J}${L0}/documents?id=${P0}${i}`)}else K(`/project/${J}${L0}/documents?id=${P0}${i}`)}else if(R0==="path")K(`/project/${J}${L0}${s}${i}`)},[$,v]=lJ.useState({}),[_,b]=lJ.useState(!0),x=Math.max(S.length,f.length);lJ.useEffect(()=>{v((R0)=>{let P0={...R0};for(let s=0;s<x;s++)if(!(s in P0))P0[s]={promptOpen:!0,outputOpen:!0};return P0})},[x]);let m=lJ.useRef(null);lJ.useEffect(()=>{if(!z)return;if(z!==w?.id&&z!==P?.id)return;let R0=z===w?.id,P0=z===P?.id;v(()=>{let s={};for(let A0=0;A0<x;A0++)s[A0]={promptOpen:R0,outputOpen:P0};return s})},[z,w?.id,P?.id,x]),lJ.useEffect(()=>{if(z&&m.current)setTimeout(()=>{m.current?.scrollIntoView({behavior:"smooth",block:"start"})},100)},[z]);let g=`${window.location.origin}${X.pathname}`,u=w?.id?`${g}?doc=${w.id}${Y?`&from=${Y}`:""}`:null,d=P?.id?`${g}?doc=${P.id}${Y?`&from=${Y}`:""}`:null,l=z===w?.id?"prompt":z===P?.id?"output":null,r=M?.fields?.status,o=M?.fields?.streaming==="true";lJ.useEffect(()=>{if(r!=="running"||!o){if(q&&r!=="running")H(!1);return}H(!0),W("");let R0=`/api/p/${J}/events`,P0=new EventSource(R0);return B.current=P0,console.log("[Streaming] EventSource created for job:",Q),P0.addEventListener("jobOutputChunk",(s)=>{try{let{id:A0,chunk:i}=JSON.parse(s.data);if(A0===Q&&i)W((L0)=>L0+i)}catch(A0){console.error("[Streaming] Error handling jobOutputChunk:",A0)}}),P0.addEventListener("jobCompleted",(s)=>{try{let{id:A0}=JSON.parse(s.data);if(A0===Q)console.log("[Streaming] Job completed, transitioning to persisted output"),H(!1),P0.close(),B.current=null}catch(A0){console.error("[Streaming] Error handling jobCompleted:",A0)}}),P0.addEventListener("jobStatusChanged",(s)=>{try{let{id:A0,newStatus:i}=JSON.parse(s.data);if(A0===Q&&i!=="running")console.log("[Streaming] Job status changed to:",i),H(!1),P0.close(),B.current=null}catch(A0){console.error("[Streaming] Error handling jobStatusChanged:",A0)}}),P0.onerror=(s)=>{console.error("[Streaming] EventSource error:",s)},()=>{console.log("[Streaming] Cleaning up EventSource"),P0.close(),B.current=null}},[J,Q,r,o]);let Y0=()=>{v((R0)=>{let P0={};for(let s of Object.keys(R0))P0[s]={promptOpen:!1,outputOpen:!1};return P0})},e=()=>{v((R0)=>{let P0={};for(let s of Object.keys(R0))P0[s]={promptOpen:!0,outputOpen:!0};return P0})},B0=async()=>{try{await navigator.clipboard.writeText(Q),bZ.success("ID copied")}catch(R0){console.error("Failed to copy ID:",R0)}},Q0=(R0)=>{if(!R0)return"active";if(R0.fields?.status==="running")return"active";if(R0.fields?.completedAt){let P0=new Date(R0.fields?.completedAt).getTime(),s=Date.now()-wB8;if(P0>s)return"active"}return"history"},M0=()=>{let R0=Y||X.state?.fromStory||X.state?.fromTab;if(R0?.startsWith("As")){let A0=Z?`/project/${J}/store/${Z}/stories?expanded=${R0}&tab=jobs`:`/project/${J}/stories?expanded=${R0}&tab=jobs`;K(A0);return}let P0=IB8.includes(R0)?R0:Q0(M),s=Z?`/project/${J}/store/${Z}/jobs/${P0}`:`/project/${J}/jobs/${P0}`;K(s)},[W0,H0]=lJ.useState(null),[U0,K0]=lJ.useState(!1),O0=C16(J,Q),[J0,j0]=lJ.useState(!1),q0=(M?.fields?.status==="completed"||M?.fields?.status==="error")&&M?.fields?.sessionId,v0=async(R0,P0)=>{await O0.mutateAsync({prompt:R0,model:P0}),K0(!1)},[Z0,e0]=lJ.useState(!1),[X0,T0]=lJ.useState(""),[_0,l0]=lJ.useState(null),b0=S16(J),y0=()=>{T0(M.name),l0(null),e0(!0)},p0=async()=>{let R0=X0.trim();if(!R0||R0===M.name){e0(!1),l0(null);return}try{await b0.mutateAsync({id:Q,name:R0}),e0(!1),l0(null)}catch(P0){let s=P0?.message||"Failed to rename job";l0(s)}},m0=(R0)=>{if(R0.key==="Enter")R0.preventDefault(),p0();if(R0.key==="Escape")e0(!1),l0(null)},d0=(R0)=>{if(T0(R0.target.value),_0)l0(null)};if(O)return Q8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:Q8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground",children:[Q8.jsxDEV(c7,{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(A||!M)return Q8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:Q8.jsxDEV("div",{className:"text-center",children:[Q8.jsxDEV(B7,{className:"w-8 h-8 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),Q8.jsxDEV("p",{className:"text-destructive font-medium",children:"Failed to load job"},void 0,!1,void 0,this),Q8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-1",children:A?.message||"Job not found"},void 0,!1,void 0,this),Q8.jsxDEV(g6,{variant:"outline",className:"mt-4",onClick:M0,children:[Q8.jsxDEV(eA,{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 Q8.jsxDEV("div",{className:"h-full flex flex-col p-6 overflow-auto",children:[Q8.jsxDEV("div",{className:"flex items-start gap-4 mb-6",children:[Q8.jsxDEV(g6,{variant:"ghost",size:"sm",onClick:M0,children:Q8.jsxDEV(eA,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q8.jsxDEV("div",{className:"flex-1",children:[Q8.jsxDEV("div",{className:"flex items-center gap-3 mb-2",children:[Z0?Q8.jsxDEV("input",{type:"text",value:X0,onChange:d0,onBlur:p0,onKeyDown:m0,autoFocus:!0,className:"text-xl font-semibold px-2 py-1 border border-input rounded bg-background"},void 0,!1,void 0,this):Q8.jsxDEV(Q8.Fragment,{children:[Q8.jsxDEV("h1",{className:"text-xl font-semibold",children:M.name},void 0,!1,void 0,this),Q8.jsxDEV(s9,{content:"Rename job",children:Q8.jsxDEV(g6,{variant:"ghost",size:"sm",onClick:y0,children:Q8.jsxDEV(N1,{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),Q8.jsxDEV(AB8,{status:M.fields?.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_0&&Q8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center gap-2 text-destructive",children:[Q8.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"text-sm",children:_0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q8.jsxDEV("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Agent:"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"capitalize",children:M.fields?.agent},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.model&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Model:"},void 0,!1,void 0,this),M.fields?.model]},void 0,!0,void 0,this),Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Started:"},void 0,!1,void 0,this),bX6(M.fields?.startedAt)]},void 0,!0,void 0,this),M.fields?.completedAt&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Completed:"},void 0,!1,void 0,this),bX6(M.fields?.completedAt)]},void 0,!0,void 0,this),M.fields?.tokensUsed&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Tokens:"},void 0,!1,void 0,this),NB8(M.fields?.tokensUsed)]},void 0,!0,void 0,this),ak(M.fields?.workingDirectory,U?.path)&&Q8.jsxDEV(s9,{content:M.fields?.workingDirectory,children:Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Location:"},void 0,!1,void 0,this),ak(M.fields?.workingDirectory,U?.path)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.fields?.status==="completed"&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Session:"},void 0,!1,void 0,this),Q8.jsxDEV("span",{children:M.fields?.sessionId||"-"},void 0,!1,void 0,this),Q8.jsxDEV(jr,{value:M.fields?.sessionId||"",disabled:!M.fields?.sessionId},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.pid&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"PID:"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"font-mono",children:M.fields.pid},void 0,!1,void 0,this),Q8.jsxDEV(jr,{value:M.fields.pid},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M.fields?.errorMessage&&Q8.jsxDEV("div",{className:"mt-3 p-3 bg-destructive/10 border border-destructive/30 rounded-md",children:[Q8.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error"},void 0,!1,void 0,this),Q8.jsxDEV("p",{className:"text-sm text-destructive/80 mt-1",children:M.fields?.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q8.jsxDEV("div",{className:"flex items-center gap-2",children:[q0&&Q8.jsxDEV(g6,{variant:"default",size:"sm",onClick:()=>K0(!0),children:[Q8.jsxDEV(MV,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Continue Conversation"]},void 0,!0,void 0,this),Q8.jsxDEV(s9,{content:"Copy job ID",children:Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:B0,children:[Q8.jsxDEV(kZ,{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),M.fields?.pid&&Q8.jsxDEV(s9,{content:"Check process status",children:Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>j0(!0),children:Q8.jsxDEV(AV,{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)]},void 0,!0,void 0,this),S.length>=3&&Q8.jsxDEV("div",{className:"flex gap-2 mb-4",children:[Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:Y0,children:"Collapse All"},void 0,!1,void 0,this),Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:e,children:"Expand All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q8.jsxDEV("div",{className:"flex-1 space-y-6",children:q?Q8.jsxDEV(Q8.Fragment,{children:[Q8.jsxDEV(RB8,{content:G,isOpen:_,onToggle:b},void 0,!1,void 0,this),Q8.jsxDEV(nB0,{title:"Prompt",docId:w?.id,isOpen:$[0]?.promptOpen??!0,onToggle:(R0)=>v((P0)=>({...P0,[0]:{...P0[0],promptOpen:R0}})),deepLinkUrl:u,children:Q8.jsxDEV(yY,{markdown:S[0]?.content||"",onInternalLinkClick:k},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):R?Q8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-8",children:[Q8.jsxDEV(c7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading documents..."]},void 0,!0,void 0,this):h?[...Array(Math.max(S.length,f.length))].map((R0,P0,s)=>{let A0=s.length-1-P0,i=S[A0],L0=f[A0],N0=i?.turnNumber??L0?.turnNumber??A0+1,x0=P0===0;return Q8.jsxDEV(hX6,{turnNumber:N0,promptContent:i?.content,outputContent:L0?.content,showHeading:!0,promptDocId:w?.id,outputDocId:P?.id,isPromptOpen:$[A0]?.promptOpen??!0,setIsPromptOpen:($0)=>v((D0)=>({...D0,[A0]:{...D0[A0],promptOpen:$0}})),isOutputOpen:$[A0]?.outputOpen??!0,setIsOutputOpen:($0)=>v((D0)=>({...D0,[A0]:{...D0[A0],outputOpen:$0}})),onInternalLinkClick:k,promptDeepLinkUrl:u,outputDeepLinkUrl:d,sectionRef:x0?m:null,highlightedSection:x0?l:null},A0,!1,void 0,this)}):Q8.jsxDEV(hX6,{turnNumber:1,promptContent:S[0]?.content,outputContent:f[0]?.content,showHeading:!1,promptDocId:w?.id,outputDocId:P?.id,isPromptOpen:$[0]?.promptOpen??!0,setIsPromptOpen:(R0)=>v((P0)=>({...P0,[0]:{...P0[0],promptOpen:R0}})),isOutputOpen:$[0]?.outputOpen??!0,setIsOutputOpen:(R0)=>v((P0)=>({...P0,[0]:{...P0[0],outputOpen:R0}})),onInternalLinkClick:k,promptDeepLinkUrl:u,outputDeepLinkUrl:d,sectionRef:m,highlightedSection:l},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q8.jsxDEV(fX6,{open:U0,onOpenChange:K0,sessionId:M.fields?.sessionId,currentModel:M.fields?.model,onContinue:v0,isLoading:O0.isPending},void 0,!1,void 0,this),Q8.jsxDEV(_X6,{open:J0,onOpenChange:j0,projectId:J,jobId:Q,pid:M.fields?.pid},void 0,!1,void 0,this),Q8.jsxDEV(bP,{open:!!W0,onOpenChange:(R0)=>!R0&&H0(null),projectId:J,documentId:W0?.id,anchor:W0?.anchor,onNavigate:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var xK=f0(D6(),1);var d3=f0(D6(),1);var i3=f0(e6(),1),Tr=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("rounded-lg border border-border bg-card text-card-foreground shadow-sm",J),...Z},void 0,!1,void 0,this));Tr.displayName="Card";var PB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("flex flex-col space-y-1.5 p-6",J),...Z},void 0,!1,void 0,this));PB8.displayName="CardHeader";var DB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("h3",{ref:Q,className:$8("text-2xl font-semibold leading-none tracking-tight",J),...Z},void 0,!1,void 0,this));DB8.displayName="CardTitle";var EB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("p",{ref:Q,className:$8("text-sm text-muted-foreground",J),...Z},void 0,!1,void 0,this));EB8.displayName="CardDescription";var Cr=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("p-6 pt-0",J),...Z},void 0,!1,void 0,this));Cr.displayName="CardContent";var VB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("flex items-center p-6 pt-0",J),...Z},void 0,!1,void 0,this));VB8.displayName="CardFooter";var Sr="",$r=()=>({"Content-Type":"application/json","X-Session-Id":o4()}),yX6=async(J)=>{let Z=await fetch(`${Sr}/api/p/${J}/export/preview`,{headers:$r()});return P9(Z,"Failed to get export preview")},gX6=async(J)=>{let Z=await fetch(`${Sr}/api/p/${J}/exports`,{headers:$r()});return P9(Z,"Failed to get exports")},mX6=async(J)=>{let Z=await fetch(`${Sr}/api/p/${J}/export`,{method:"POST",headers:$r(),body:JSON.stringify({confirm:!0})});return P9(Z,"Failed to export documents")},uX6=async(J,Z)=>{let Q=await fetch(`${Sr}/api/p/${J}/import`,{method:"POST",headers:$r(),body:JSON.stringify({filename:Z})});return P9(Q,"Failed to import documents")};var d6=f0(e6(),1),pX6=()=>{let{id:J}=EQ(),{data:Z,isLoading:Q}=w1(J),[K,X]=xK.useState(!1),[U,Y]=xK.useState(null),[z,G]=xK.useState(!1),[W,q]=xK.useState(null),[H,B]=xK.useState(!1),[M,O]=xK.useState(null),[A,N]=xK.useState(null),[R,w]=xK.useState(!1),[P,V]=xK.useState(!1),[D,T]=xK.useState(null),[C,S]=xK.useState(null),[f,h]=xK.useState([]),[k,$]=xK.useState("");I1(Z?`${Z.name} - Settings`:"CAW");let v=async(r,o)=>{if(Y(null),!navigator.clipboard?.writeText){Y("Clipboard not available");return}try{await navigator.clipboard.writeText(r),o(!0),setTimeout(()=>o(!1),2000)}catch(Y0){Y("Failed to copy")}},_=()=>{if(!Z?.objectId)return"";return`claude mcp add caw-${Z.objectId.toLowerCase()} https://caw.localhost/mcp/p/${Z.objectId} --transport http`},b=()=>v(_(),X),x=async()=>{O(null),N(null),q(null),B(!0),G(!0);try{let r=await yX6(Z.objectId);q(r)}catch(r){O(r.message)}finally{B(!1)}},m=async()=>{B(!0),O(null);try{let r=await mX6(Z.objectId);N(r)}catch(r){O(r.message)}finally{B(!1)}},g=()=>{G(!1),q(null),N(null),O(null)},u=async()=>{T(null),S(null),h([]),$(""),w(!0),V(!0);try{let r=await gX6(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(!k){T("Please select an export file");return}V(!0),T(null);try{let r=await uX6(Z.objectId,k);S(r)}catch(r){T(r.message)}finally{V(!1)}},l=()=>{w(!1),S(null),T(null)};if(Q)return d6.jsxDEV("div",{className:"p-6",children:d6.jsxDEV("p",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(!Z)return d6.jsxDEV("div",{className:"p-6",children:d6.jsxDEV("p",{className:"text-muted-foreground",children:"Project not found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return d6.jsxDEV("div",{className:"p-6",children:[d6.jsxDEV("h2",{className:"text-2xl font-bold text-foreground mb-6",children:"Project Settings"},void 0,!1,void 0,this),d6.jsxDEV("div",{className:"max-w-2xl space-y-6",children:[d6.jsxDEV(Tr,{children:d6.jsxDEV(Cr,{className:"pt-6 space-y-6",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Project Name"},void 0,!1,void 0,this),d6.jsxDEV("p",{className:"text-foreground mt-1",children:Z.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Path"},void 0,!1,void 0,this),d6.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),d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Add to Claude Code"},void 0,!1,void 0,this),d6.jsxDEV("div",{className:"flex items-start gap-2 mt-1",children:[d6.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:_()},void 0,!1,void 0,this),d6.jsxDEV(g6,{variant:"outline",size:"icon",onClick:b,className:"shrink-0",children:K?d6.jsxDEV(A1,{className:"w-4 h-4"},void 0,!1,void 0,this):d6.jsxDEV(kZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&d6.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),d6.jsxDEV(Tr,{children:d6.jsxDEV(Cr,{className:"pt-6",children:d6.jsxDEV("div",{className:"flex items-start justify-between",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"PROJECT STORE (A)"},void 0,!1,void 0,this),d6.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),d6.jsxDEV("div",{className:"flex gap-2",children:[d6.jsxDEV(g6,{onClick:x,size:"sm",children:[d6.jsxDEV(WV,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Export"]},void 0,!0,void 0,this),d6.jsxDEV(g6,{onClick:u,variant:"outline",size:"sm",children:[d6.jsxDEV(yG,{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),d6.jsxDEV(sJ,{open:z,onOpenChange:G,children:d6.jsxDEV(vJ,{children:[d6.jsxDEV(fJ,{children:[d6.jsxDEV(_J,{children:A?"Export Complete":"Export Preview"},void 0,!1,void 0,this),d6.jsxDEV(Wh,{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&&d6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:d6.jsxDEV(c7,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M&&d6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[d6.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),d6.jsxDEV("span",{className:"text-sm",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W?.toExport&&W?.draftOnly&&!A&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Will be exported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[d6.jsxDEV("li",{children:[W.toExport.documents.length," documents"]},void 0,!0,void 0,this),d6.jsxDEV("li",{children:[W.toExport.templates.length," templates"]},void 0,!0,void 0,this),d6.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)&&d6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:d6.jsxDEV("div",{className:"flex items-start gap-2",children:[d6.jsxDEV(B7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),d6.jsxDEV("div",{children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Draft-only items will NOT be exported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[W.draftOnly.documents.length>0&&d6.jsxDEV("li",{children:[W.draftOnly.documents.length," documents",W.draftOnly.documents.length<=3&&d6.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&&d6.jsxDEV("li",{children:[W.draftOnly.templates.length," templates",W.draftOnly.templates.length<=3&&d6.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&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Exported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[d6.jsxDEV("li",{children:[A.counts.documents," documents"]},void 0,!0,void 0,this),d6.jsxDEV("li",{children:[A.counts.templates," templates"]},void 0,!0,void 0,this),d6.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),d6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Saved to: ",d6.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),d6.jsxDEV(DZ,{children:!A?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(g6,{variant:"outline",onClick:g,children:"Cancel"},void 0,!1,void 0,this),d6.jsxDEV(g6,{onClick:m,disabled:H||!W,children:H?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(c7,{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):d6.jsxDEV(g6,{onClick:g,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),d6.jsxDEV(sJ,{open:R,onOpenChange:w,children:d6.jsxDEV(vJ,{children:[d6.jsxDEV(fJ,{children:[d6.jsxDEV(_J,{children:C?"Import Complete":"Import from .caw-exports/"},void 0,!1,void 0,this),d6.jsxDEV(Wh,{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),D&&d6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[d6.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),d6.jsxDEV("span",{className:"text-sm",children:D},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&f.length===0&&!D&&d6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:d6.jsxDEV(c7,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),!C&&!P&&f.length===0&&!D&&d6.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&&f.length>0&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-foreground block mb-2",children:"Select export file:"},void 0,!1,void 0,this),d6.jsxDEV(kQ,{value:k,onValueChange:$,children:[d6.jsxDEV(eZ,{children:d6.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),d6.jsxDEV(JQ,{children:f.map((r)=>d6.jsxDEV(P4,{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),d6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:d6.jsxDEV("div",{className:"flex items-start gap-2",children:[d6.jsxDEV(B7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),d6.jsxDEV("div",{children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Important:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[d6.jsxDEV("li",{children:"The store must be empty before importing"},void 0,!1,void 0,this),d6.jsxDEV("li",{children:"Entity IDs will be remapped to new values"},void 0,!1,void 0,this),d6.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&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Imported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[d6.jsxDEV("li",{children:[C.counts.documents," documents"]},void 0,!0,void 0,this),d6.jsxDEV("li",{children:[C.counts.templates," templates"]},void 0,!0,void 0,this),d6.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&&d6.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),d6.jsxDEV(DZ,{children:!C?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(g6,{variant:"outline",onClick:l,children:"Cancel"},void 0,!1,void 0,this),d6.jsxDEV(g6,{onClick:d,disabled:P||!k,children:P?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(c7,{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):d6.jsxDEV(g6,{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 jB8=f0(D6(),1);var EM=f0(e6(),1),kr=()=>{let J=a4(),Z=dJ();return EM.jsxDEV("div",{className:"flex items-center justify-center h-full",children:EM.jsxDEV("div",{className:"text-center max-w-md px-4",children:[EM.jsxDEV(B7,{className:"w-16 h-16 text-muted-foreground/50 mx-auto mb-4"},void 0,!1,void 0,this),EM.jsxDEV("h2",{className:"text-2xl font-semibold text-foreground mb-2",children:"Page Not Found"},void 0,!1,void 0,this),EM.jsxDEV("p",{className:"text-muted-foreground mb-4",children:["The path ",EM.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),EM.jsxDEV(g6,{onClick:()=>Z("/"),children:"Go Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var AH=f0(e6(),1),cX6=()=>{let{theme:J,toggleTheme:Z}=u_(),Q=J==="dark";return AH.jsxDEV("div",{className:"flex items-center justify-between",children:[AH.jsxDEV("div",{children:[AH.jsxDEV("div",{className:"font-medium text-foreground",children:"Theme"},void 0,!1,void 0,this),AH.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),AH.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:AH.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?AH.jsxDEV(OV,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this):AH.jsxDEV(NV,{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 WG=f0(e6(),1),lX6=()=>{return I1("CAW - Preferences"),WG.jsxDEV("div",{className:"flex-1 p-6",children:[WG.jsxDEV("div",{className:"mb-6",children:WG.jsxDEV("div",{className:"flex items-center gap-3",children:[WG.jsxDEV(Wz,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this),WG.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),WG.jsxDEV("div",{className:"max-w-2xl",children:WG.jsxDEV("section",{className:"mb-8",children:[WG.jsxDEV("h2",{className:"text-lg font-medium text-foreground mb-4",children:"Appearance"},void 0,!1,void 0,this),WG.jsxDEV("div",{className:"bg-card border border-border rounded-lg p-4",children:WG.jsxDEV(cX6,{},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 iX6=f0(e6(),1),dX6=(J)=>iX6.jsxDEV(yT0,{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 h9=f0(e6(),1),CB8=()=>{return h9.jsxDEV(Ut,{children:h9.jsxDEV(Rt,{client:NN0,children:[h9.jsxDEV(Qt,{children:h9.jsxDEV(AJ,{element:h9.jsxDEV(SI0,{},void 0,!1,void 0,this),children:[h9.jsxDEV(AJ,{index:!0,element:h9.jsxDEV(fI0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"preferences",element:h9.jsxDEV(lX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"project/:id",element:h9.jsxDEV(vI0,{},void 0,!1,void 0,this),children:[h9.jsxDEV(AJ,{index:!0,element:h9.jsxDEV(N_,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"documents/*",element:h9.jsxDEV(UG0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"templates/*",element:h9.jsxDEV(PB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"stories",element:h9.jsxDEV(lB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs/:tab",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"job/:jobId",element:h9.jsxDEV(sB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"settings",element:h9.jsxDEV(pX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"store/:storeCode",children:[h9.jsxDEV(AJ,{index:!0,element:h9.jsxDEV(N_,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"documents/*",element:h9.jsxDEV(UG0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"templates/*",element:h9.jsxDEV(PB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"stories",element:h9.jsxDEV(lB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs/:tab",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"job/:jobId",element:h9.jsxDEV(sB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"*",element:h9.jsxDEV(kr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h9.jsxDEV(AJ,{path:"*",element:h9.jsxDEV(kr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h9.jsxDEV(AJ,{path:"*",element:h9.jsxDEV(kr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(dX6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},rX6=CB8;var aB0=f0(e6(),1),aX6=document.getElementById("root");if(!aX6)throw Error("Root element not found");var SB8=sX6.createRoot(aX6);SB8.render(aB0.jsxDEV(nX6.default.StrictMode,{children:aB0.jsxDEV(rX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this));
3115
+ ${X?"border-primary ring-2 ring-primary/20":"border-border"}`,onClick:()=>Z(J),onKeyDown:(q)=>{if(q.key==="Enter"||q.key===" ")q.preventDefault(),Z(J);if(q.key==="ArrowLeft"){if(q.stopPropagation(),Q&&K){if(K.indexOf(J.fields?.state)>0)Q(J.id,-1)}}if(q.key==="ArrowRight"){if(q.stopPropagation(),Q&&K){let H=K.indexOf(J.fields?.state);if(H>=0&&H<K.length-1)Q(J.id,1)}}},children:[l3.jsxDEV("div",{className:"text-sm truncate",children:J.name},void 0,!1,void 0,this),J.fields?.label&&l3.jsxDEV("div",{className:"mt-1 text-xs text-muted-foreground",children:J.fields.label},void 0,!1,void 0,this),J.fields?.colour&&l3.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&&l3.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&&l3.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 L7=f0(e6(),1);function KB8({state:J,children:Z}){let{setNodeRef:Q,isOver:K}=GX6({id:J});return L7.jsxDEV("div",{className:"flex-1 min-w-[160px] flex flex-col",children:[L7.jsxDEV("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground",children:J},void 0,!1,void 0,this),L7.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 HX6({projectId:J,storyId:Z,selectedId:Q,onOpenDocument:K}){let[X,U]=qD.useState(null),[Y,z]=qD.useState(!1),[G,W]=qD.useState(""),[q,H]=qD.useState(""),B=xB0(nk,{activationConstraint:{distance:8}}),M=xB0(rk),O=pK6(B,M),A=Dr(J),N=T3(J),R=r9(),{data:w,isLoading:P,isError:V}=Zj(J,{folderId:Z,type:"d"}),D=w?.find((g)=>g.isFolder&&g.subtype==="tasks"),T=D?.fields?.states??[],{data:C,isLoading:S,isError:f}=Zj(J,{folderId:D?.id,type:"d",enabled:!!D?.id}),h={};for(let g of T)h[g]=[];if(C){for(let g of C)if(!g.isFolder&&g.fields?.state&&h[g.fields.state])h[g.fields.state].push(g)}let k=D?["folderContents",J,"A",D.id,"d","default"]:null;function $(g,u){if(!k)return;A.mutate({entityId:g,fieldName:"state",value:u},{onMutate:()=>{let d=R.getQueryData(k);return R.setQueryData(k,(l)=>l?.map((r)=>r.id===g?{...r,fields:{...r.fields,state:u}}:r)),{previous:d,queryKey:k}},onError:(d,l,r)=>{if(r?.queryKey&&r?.previous)R.setQueryData(r.queryKey,r.previous)}})}function v(g){U(g.active.id)}function _(g){let{active:u,over:d}=g;if(U(null),!d)return;if(u.data.current?.state===d.id)return;$(u.id,d.id)}function b(g,u){let d=C?.find((Y0)=>Y0.id===g);if(!d)return;let l=d.fields?.state,r=T.indexOf(l);if(r===-1)return;let o=r+u;if(o<0||o>=T.length)return;$(g,T[o])}function x(){if(!G.trim())return;if(N.isPending)return;N.mutate({parentId:D.id,name:G.trim(),subtype:"task",fields:{state:q}},{onSuccess:(g)=>{z(!1),W(""),H(T[0]||""),K(g.id,{edit:!0})}})}let m=X?C?.find((g)=>g.id===X):null;if(P)return L7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this);if(V)return L7.jsxDEV("div",{className:"p-6 text-sm text-muted-foreground",children:"Failed to load tasks folder."},void 0,!1,void 0,this);if(!D)return L7.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 L7.jsxDEV(L7.Fragment,{children:[T.length>0&&L7.jsxDEV("div",{className:"px-4 pt-4 flex items-center",children:L7.jsxDEV(g6,{variant:"warning",size:"sm",onClick:()=>{W(""),H(T[0]||""),z(!0)},children:[L7.jsxDEV(X5,{className:"w-4 h-4"},void 0,!1,void 0,this),L7.jsxDEV(aX,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L7.jsxDEV(YX6,{sensors:O,onDragStart:v,onDragEnd:_,children:[L7.jsxDEV("div",{className:"flex gap-3 pb-4 px-4 overflow-x-auto",children:T.map((g)=>L7.jsxDEV(KB8,{state:g,children:S?L7.jsxDEV("div",{className:"text-xs text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this):f?L7.jsxDEV("div",{className:"text-xs text-destructive",children:"Failed to load tasks"},void 0,!1,void 0,this):h[g]?.map((u)=>L7.jsxDEV(gB0,{task:u,isSelected:u.id===Q,onClick:(d)=>K(d.id),states:T,onMoveTask:b},u.id,!1,void 0,this))},g,!1,void 0,this))},void 0,!1,void 0,this),L7.jsxDEV(WX6,{children:m?L7.jsxDEV(gB0,{task:m,isSelected:!1,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),L7.jsxDEV(sJ,{open:Y,onOpenChange:(g)=>{if(z(g),!g)W(""),H(T[0]||"")},children:L7.jsxDEV(vJ,{children:[L7.jsxDEV(fJ,{children:L7.jsxDEV(_J,{children:"New Task"},void 0,!1,void 0,this)},void 0,!1,void 0,this),L7.jsxDEV("div",{className:"py-4 space-y-4",children:[L7.jsxDEV("div",{children:[L7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Name"},void 0,!1,void 0,this),L7.jsxDEV("input",{type:"text",value:G,onChange:(g)=>W(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"&&x(),autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L7.jsxDEV("div",{children:[L7.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"State"},void 0,!1,void 0,this),L7.jsxDEV(kQ,{value:q,onValueChange:H,children:[L7.jsxDEV(eZ,{children:L7.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),L7.jsxDEV(JQ,{children:T.map((g)=>L7.jsxDEV(P4,{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),L7.jsxDEV(DZ,{children:[L7.jsxDEV(g6,{variant:"outline",onClick:()=>{z(!1),W(""),H(T[0]||"")},children:"Cancel"},void 0,!1,void 0,this),L7.jsxDEV(g6,{onClick:x,disabled:N.isPending||!G.trim(),children:N.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 Vr=f0(D6(),1);var XB8=f0(D6(),1);var tQ=f0(e6(),1),BX6=({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 tQ.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)},mB0=(J)=>{if(!J)return"-";return new Date(J).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},FX6=(J)=>{if(J===null||J===void 0)return"-";if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},Er=async(J)=>{if(!J)return;try{await navigator.clipboard.writeText(J),bZ.success("Copied")}catch(Z){console.error("Failed to copy:",Z)}},ak=(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},HD=({job:J,onClick:Z,projectPath:Q})=>{let K=ak(J.fields?.workingDirectory,Q);return tQ.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:[tQ.jsxDEV(BX6,{status:J.fields?.status},void 0,!1,void 0,this),tQ.jsxDEV(s9,{content:"Click to copy",children:tQ.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(X)=>{X.stopPropagation(),Er(J.id)},children:J.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),tQ.jsxDEV(s9,{content:"Click to copy",children:tQ.jsxDEV("span",{className:"w-64 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(X)=>{if(X.stopPropagation(),J.fields?.sessionId)Er(J.fields?.sessionId)},children:J.fields?.sessionId?J.fields?.sessionId.slice(0,24)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),tQ.jsxDEV("div",{className:"flex-1 min-w-0",children:[tQ.jsxDEV("span",{className:"truncate text-sm font-medium block",children:J.name},void 0,!1,void 0,this),K&&tQ.jsxDEV(s9,{content:J.fields?.workingDirectory,children:tQ.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),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:J.fields?.agent},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-24 truncate",children:J.fields?.model||"-"},void 0,!1,void 0,this),tQ.jsxDEV(s9,{content:"Click to copy",children:tQ.jsxDEV("span",{className:"w-16 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary",onClick:(X)=>{if(X.stopPropagation(),J.fields?.pid)Er(J.fields?.pid)},children:J.fields?.pid||"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:mB0(J.fields?.startedAt)},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:mB0(J.fields?.completedAt)},void 0,!1,void 0,this),tQ.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:FX6(J.fields?.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var DM=f0(e6(),1),MX6={running:0,completed:1,error:2},OX6=3,LX6=({projectId:J,storyId:Z,storeCode:Q,projectPath:K})=>{let X=dJ(),{data:U=[],isLoading:Y}=Xr(J,{store:Q}),z=Vr.useMemo(()=>{return U.filter((q)=>q.fields?.objectId===Z)},[U,Z]),G=Vr.useMemo(()=>{return[...z].sort((q,H)=>{let B=MX6[q.fields?.status]??OX6,M=MX6[H.fields?.status]??OX6;if(B!==M)return B-M;let O=q.fields?.startedAt?new Date(q.fields.startedAt).getTime():0;return(H.fields?.startedAt?new Date(H.fields.startedAt).getTime():0)-O})},[z]),W=(q)=>{let H=Q?`/project/${J}/store/${Q}/job/${q.id}?from=${Z}`:`/project/${J}/job/${q.id}?from=${Z}`;X(H)};if(Y)return DM.jsxDEV("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(G.length===0)return DM.jsxDEV("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground gap-4",children:[DM.jsxDEV(fG,{className:"w-12 h-12 opacity-50"},void 0,!1,void 0,this),DM.jsxDEV("p",{children:"No jobs associated with this story"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return DM.jsxDEV("div",{className:"p-4 overflow-auto h-full",children:DM.jsxDEV("div",{className:"space-y-0",children:G.map((q)=>DM.jsxDEV(HD,{job:q,onClick:W,projectPath:K},q.id,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var ok="",tk=()=>({"Content-Type":"application/json","X-Session-Id":o4()}),AX6=async(J,{store:Z}={})=>{let Q=new URLSearchParams;if(Z)Q.set("store",Z);let K=Q.toString(),X=`${ok}/api/p/${J}/stories${K?`?${K}`:""}`,U=await fetch(X,{headers:tk()});return P9(U,"Failed to list stories")};var NX6=async(J,{name:Z,store:Q,state:K})=>{let X=await fetch(`${ok}/api/p/${J}/stories`,{method:"POST",headers:tk(),body:JSON.stringify({name:Z,store:Q,state:K})});return P9(X,"Failed to create story")},RX6=async(J,Z,Q)=>{let K=await fetch(`${ok}/api/p/${J}/stories/${Z}/state`,{method:"PATCH",headers:tk(),body:JSON.stringify({state:Q})});return P9(K,"Failed to update story state")},wX6=async(J,Z,Q)=>{let K=await fetch(`${ok}/api/p/${J}/stories/${Z}/name`,{method:"PATCH",headers:tk(),body:JSON.stringify({name:Q})});return P9(K,"Failed to rename story")},IX6=async(J,Z)=>{let Q=await fetch(`${ok}/api/p/${J}/stories/${Z}`,{method:"DELETE",headers:tk()});return P9(Q,"Failed to delete story")};var PX6=(J,{store:Z}={})=>{return iZ({queryKey:["stories",J,Z??"demux"],queryFn:()=>AX6(J,{store:Z}),enabled:!!J,staleTime:30000})};var DX6=(J)=>{let Z=r9();return I4({mutationFn:({name:Q,store:K,state:X})=>NX6(J,{name:Q,store:K,state:X}),onSuccess:(Q,{store:K})=>{Z.invalidateQueries({queryKey:["stories",J,K??"demux"]})}})},EX6=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,state:K})=>RX6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},VX6=(J)=>{let Z=r9();return I4({mutationFn:({id:Q,name:K})=>wX6(J,Q,K),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})},jX6=(J)=>{let Z=r9();return I4({mutationFn:({id:Q})=>IX6(J,Q),onSuccess:(Q,{id:K})=>{Z.invalidateQueries({queryKey:["story",K]}),Z.invalidateQueries({queryKey:["stories",J]})}})};var TX6=f0(D6(),1),CX6=(J)=>{let Z=ST0(J,{path:"",store:"A",type:"s"});return{states:TX6.useMemo(()=>Z.data?.fields?.states??[],[Z.data]),isLoading:Z.isLoading,error:Z.error,refetch:Z.refetch}};class O8{constructor(){this.hex="#000000",this.rgb_r=0,this.rgb_g=0,this.rgb_b=0,this.xyz_x=0,this.xyz_y=0,this.xyz_z=0,this.luv_l=0,this.luv_u=0,this.luv_v=0,this.lch_l=0,this.lch_c=0,this.lch_h=0,this.hsluv_h=0,this.hsluv_s=0,this.hsluv_l=0,this.hpluv_h=0,this.hpluv_p=0,this.hpluv_l=0,this.r0s=0,this.r0i=0,this.r1s=0,this.r1i=0,this.g0s=0,this.g0i=0,this.g1s=0,this.g1i=0,this.b0s=0,this.b0i=0,this.b1s=0,this.b1i=0}static fromLinear(J){if(J<=0.0031308)return 12.92*J;else return 1.055*Math.pow(J,0.4166666666666667)-0.055}static toLinear(J){if(J>0.04045)return Math.pow((J+0.055)/1.055,2.4);else return J/12.92}static yToL(J){if(J<=O8.epsilon)return J/O8.refY*O8.kappa;else return 116*Math.pow(J/O8.refY,0.3333333333333333)-16}static lToY(J){if(J<=8)return O8.refY*J/O8.kappa;else return O8.refY*Math.pow((J+16)/116,3)}static rgbChannelToHex(J){let Z=Math.round(J*255),Q=Z%16,K=(Z-Q)/16|0;return O8.hexChars.charAt(K)+O8.hexChars.charAt(Q)}static hexToRgbChannel(J,Z){let Q=O8.hexChars.indexOf(J.charAt(Z)),K=O8.hexChars.indexOf(J.charAt(Z+1));return(Q*16+K)/255}static distanceFromOriginAngle(J,Z,Q){let K=Z/(Math.sin(Q)-J*Math.cos(Q));if(K<0)return 1/0;else return K}static distanceFromOrigin(J,Z){return Math.abs(Z)/Math.sqrt(Math.pow(J,2)+1)}static min6(J,Z,Q,K,X,U){return Math.min(J,Math.min(Z,Math.min(Q,Math.min(K,Math.min(X,U)))))}rgbToHex(){this.hex="#",this.hex+=O8.rgbChannelToHex(this.rgb_r),this.hex+=O8.rgbChannelToHex(this.rgb_g),this.hex+=O8.rgbChannelToHex(this.rgb_b)}hexToRgb(){this.hex=this.hex.toLowerCase(),this.rgb_r=O8.hexToRgbChannel(this.hex,1),this.rgb_g=O8.hexToRgbChannel(this.hex,3),this.rgb_b=O8.hexToRgbChannel(this.hex,5)}xyzToRgb(){this.rgb_r=O8.fromLinear(O8.m_r0*this.xyz_x+O8.m_r1*this.xyz_y+O8.m_r2*this.xyz_z),this.rgb_g=O8.fromLinear(O8.m_g0*this.xyz_x+O8.m_g1*this.xyz_y+O8.m_g2*this.xyz_z),this.rgb_b=O8.fromLinear(O8.m_b0*this.xyz_x+O8.m_b1*this.xyz_y+O8.m_b2*this.xyz_z)}rgbToXyz(){let J=O8.toLinear(this.rgb_r),Z=O8.toLinear(this.rgb_g),Q=O8.toLinear(this.rgb_b);this.xyz_x=0.41239079926595*J+0.35758433938387*Z+0.18048078840183*Q,this.xyz_y=0.21263900587151*J+0.71516867876775*Z+0.072192315360733*Q,this.xyz_z=0.019330818715591*J+0.11919477979462*Z+0.95053215224966*Q}xyzToLuv(){let J=this.xyz_x+15*this.xyz_y+3*this.xyz_z,Z=4*this.xyz_x,Q=9*this.xyz_y;if(J!==0)Z/=J,Q/=J;else Z=NaN,Q=NaN;if(this.luv_l=O8.yToL(this.xyz_y),this.luv_l===0)this.luv_u=0,this.luv_v=0;else this.luv_u=13*this.luv_l*(Z-O8.refU),this.luv_v=13*this.luv_l*(Q-O8.refV)}luvToXyz(){if(this.luv_l===0){this.xyz_x=0,this.xyz_y=0,this.xyz_z=0;return}let J=this.luv_u/(13*this.luv_l)+O8.refU,Z=this.luv_v/(13*this.luv_l)+O8.refV;this.xyz_y=O8.lToY(this.luv_l),this.xyz_x=0-9*this.xyz_y*J/((J-4)*Z-J*Z),this.xyz_z=(9*this.xyz_y-15*Z*this.xyz_y-Z*this.xyz_x)/(3*Z)}luvToLch(){if(this.lch_l=this.luv_l,this.lch_c=Math.sqrt(this.luv_u*this.luv_u+this.luv_v*this.luv_v),this.lch_c<0.00000001)this.lch_h=0;else{let J=Math.atan2(this.luv_v,this.luv_u);if(this.lch_h=J*180/Math.PI,this.lch_h<0)this.lch_h=360+this.lch_h}}lchToLuv(){let J=this.lch_h/180*Math.PI;this.luv_l=this.lch_l,this.luv_u=Math.cos(J)*this.lch_c,this.luv_v=Math.sin(J)*this.lch_c}calculateBoundingLines(J){let Z=Math.pow(J+16,3)/1560896,Q=Z>O8.epsilon?Z:J/O8.kappa,K=Q*(284517*O8.m_r0-94839*O8.m_r2),X=Q*(838422*O8.m_r2+769860*O8.m_r1+731718*O8.m_r0),U=Q*(632260*O8.m_r2-126452*O8.m_r1),Y=Q*(284517*O8.m_g0-94839*O8.m_g2),z=Q*(838422*O8.m_g2+769860*O8.m_g1+731718*O8.m_g0),G=Q*(632260*O8.m_g2-126452*O8.m_g1),W=Q*(284517*O8.m_b0-94839*O8.m_b2),q=Q*(838422*O8.m_b2+769860*O8.m_b1+731718*O8.m_b0),H=Q*(632260*O8.m_b2-126452*O8.m_b1);this.r0s=K/U,this.r0i=X*J/U,this.r1s=K/(U+126452),this.r1i=(X-769860)*J/(U+126452),this.g0s=Y/G,this.g0i=z*J/G,this.g1s=Y/(G+126452),this.g1i=(z-769860)*J/(G+126452),this.b0s=W/H,this.b0i=q*J/H,this.b1s=W/(H+126452),this.b1i=(q-769860)*J/(H+126452)}calcMaxChromaHpluv(){let J=O8.distanceFromOrigin(this.r0s,this.r0i),Z=O8.distanceFromOrigin(this.r1s,this.r1i),Q=O8.distanceFromOrigin(this.g0s,this.g0i),K=O8.distanceFromOrigin(this.g1s,this.g1i),X=O8.distanceFromOrigin(this.b0s,this.b0i),U=O8.distanceFromOrigin(this.b1s,this.b1i);return O8.min6(J,Z,Q,K,X,U)}calcMaxChromaHsluv(J){let Z=J/360*Math.PI*2,Q=O8.distanceFromOriginAngle(this.r0s,this.r0i,Z),K=O8.distanceFromOriginAngle(this.r1s,this.r1i,Z),X=O8.distanceFromOriginAngle(this.g0s,this.g0i,Z),U=O8.distanceFromOriginAngle(this.g1s,this.g1i,Z),Y=O8.distanceFromOriginAngle(this.b0s,this.b0i,Z),z=O8.distanceFromOriginAngle(this.b1s,this.b1i,Z);return O8.min6(Q,K,X,U,Y,z)}hsluvToLch(){if(this.hsluv_l>99.9999999)this.lch_l=100,this.lch_c=0;else if(this.hsluv_l<0.00000001)this.lch_l=0,this.lch_c=0;else{this.lch_l=this.hsluv_l,this.calculateBoundingLines(this.hsluv_l);let J=this.calcMaxChromaHsluv(this.hsluv_h);this.lch_c=J/100*this.hsluv_s}this.lch_h=this.hsluv_h}lchToHsluv(){if(this.lch_l>99.9999999)this.hsluv_s=0,this.hsluv_l=100;else if(this.lch_l<0.00000001)this.hsluv_s=0,this.hsluv_l=0;else{this.calculateBoundingLines(this.lch_l);let J=this.calcMaxChromaHsluv(this.lch_h);this.hsluv_s=this.lch_c/J*100,this.hsluv_l=this.lch_l}this.hsluv_h=this.lch_h}hpluvToLch(){if(this.hpluv_l>99.9999999)this.lch_l=100,this.lch_c=0;else if(this.hpluv_l<0.00000001)this.lch_l=0,this.lch_c=0;else{this.lch_l=this.hpluv_l,this.calculateBoundingLines(this.hpluv_l);let J=this.calcMaxChromaHpluv();this.lch_c=J/100*this.hpluv_p}this.lch_h=this.hpluv_h}lchToHpluv(){if(this.lch_l>99.9999999)this.hpluv_p=0,this.hpluv_l=100;else if(this.lch_l<0.00000001)this.hpluv_p=0,this.hpluv_l=0;else{this.calculateBoundingLines(this.lch_l);let J=this.calcMaxChromaHpluv();this.hpluv_p=this.lch_c/J*100,this.hpluv_l=this.lch_l}this.hpluv_h=this.lch_h}hsluvToRgb(){this.hsluvToLch(),this.lchToLuv(),this.luvToXyz(),this.xyzToRgb()}hpluvToRgb(){this.hpluvToLch(),this.lchToLuv(),this.luvToXyz(),this.xyzToRgb()}hsluvToHex(){this.hsluvToRgb(),this.rgbToHex()}hpluvToHex(){this.hpluvToRgb(),this.rgbToHex()}rgbToHsluv(){this.rgbToXyz(),this.xyzToLuv(),this.luvToLch(),this.lchToHpluv(),this.lchToHsluv()}rgbToHpluv(){this.rgbToXyz(),this.xyzToLuv(),this.luvToLch(),this.lchToHpluv(),this.lchToHpluv()}hexToHsluv(){this.hexToRgb(),this.rgbToHsluv()}hexToHpluv(){this.hexToRgb(),this.rgbToHpluv()}}O8.hexChars="0123456789abcdef";O8.refY=1;O8.refU=0.19783000664283;O8.refV=0.46831999493879;O8.kappa=903.2962962;O8.epsilon=0.0088564516;O8.m_r0=3.240969941904521;O8.m_r1=-1.537383177570093;O8.m_r2=-0.498610760293;O8.m_g0=-0.96924363628087;O8.m_g1=1.87596750150772;O8.m_g2=0.041555057407175;O8.m_b0=0.055630079696993;O8.m_b1=-0.20397695888897;O8.m_b2=1.056971514242878;var E6=f0(e6(),1),UB8={useItem:XG,useCreate:T3,useSaveDraft:CP,usePublish:SP,useDiscard:$P,useVersions:kP,useDelete:vP,useUpdatePath:fP,getVersion:TP},uB0=[{key:"unsorted",icon:hG,label:"Not sorted"},{key:"name-asc",icon:vG,label:"Sorting by name ascending"},{key:"name-desc",icon:kG,label:"Sorting by name descending"},{key:"date-asc",icon:MO,label:"Sorting by date ascending"},{key:"date-desc",icon:FO,label:"Sorting by date descending"},{key:"state-asc",icon:rH,label:"Sorting by state ascending"},{key:"state-desc",icon:iH,label:"Sorting by state descending"}],pB0=(J,Z,Q)=>{let K=new O8;return K.hsluv_h=J,K.hsluv_s=Z,K.hsluv_l=Q,K.hsluvToHex(),K.hex},YB8=(J,Z)=>{if(Z===0)return{bg:"linear-gradient(to bottom, #6b7280, #4b5563)",text:"white",border:"#374151"};let Q=J/Z*360,K=65,X=40,U=pB0(Q,K,X+15),Y=pB0(Q,K,X),z=pB0(Q,K,X-10);return{bg:`linear-gradient(to bottom, ${U}, ${Y})`,text:"white",border:z}},cB0=0.08333333333333333,zB8=0.16666666666666666,GB8=({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;if(U===1)Y=0.5;else Y=cB0+(1-2*cB0)/(U-1)*X;let z=(Y-cB0)*100,G=zB8*100,W=J.charAt(0).toUpperCase()+J.slice(1),q=YB8(X,Z.length);return E6.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:E6.jsxDEV("div",{className:"absolute rounded text-xs flex items-center justify-between px-1 shadow-sm",style:{left:`${z}%`,width:`${G}%`,top:"2px",bottom:"2px",background:q.bg,color:q.text,borderWidth:"1px",borderStyle:"solid",borderColor:q.border},children:[Q?E6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(H)=>{H.stopPropagation(),Q()},onKeyDown:(H)=>{if(H.key==="Enter"||H.key===" ")H.preventDefault(),H.stopPropagation(),Q()},children:E6.jsxDEV(OO,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):E6.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"flex-1 text-center",children:W},void 0,!1,void 0,this),K?E6.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(H)=>{H.stopPropagation(),K()},onKeyDown:(H)=>{if(H.key==="Enter"||H.key===" ")H.preventDefault(),H.stopPropagation(),K()},children:E6.jsxDEV(LO,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):E6.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)},WB8=({projectId:J,storyId:Z})=>{let{data:Q,isLoading:K,error:X}=cZ6(J,"s"),[U,Y]=cJ.useState(null),z=Q?.templates??[],G=(H)=>{Y(H)},W=()=>{Y(null)};if(K)return E6.jsxDEV("div",{className:"flex items-center gap-2 p-4 text-muted-foreground",children:[E6.jsxDEV(c7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading templates..."]},void 0,!0,void 0,this);if(X)return E6.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 E6.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 E6.jsxDEV("div",{className:"p-4",children:[E6.jsxDEV("ul",{className:"space-y-1",children:z.map((H)=>E6.jsxDEV("li",{children:E6.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:[E6.jsxDEV(sX,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"truncate",children:H.name},void 0,!1,void 0,this),H.path&&E6.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),E6.jsxDEV(Wr,{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)},qB8=({projectId:J,story:Z,setFieldMutation:Q,onDeleted:K})=>{let[X,U]=cJ.useState(Z.name),[Y,z]=cJ.useState(null),[G,W]=cJ.useState(!1),[q,H]=cJ.useState(null),B=VX6(J),M=jX6(J),O=!X.trim()||X.trim()===Z.name||B.isPending,A=()=>{z(null),B.mutate({id:Z.id,name:X.trim()},{onError:(R)=>z(R.message)})},N=()=>{H(null),M.mutate({id:Z.id},{onSuccess:()=>{W(!1),K()},onError:(R)=>H(R.message)})};return E6.jsxDEV("div",{className:"p-4 space-y-8",children:[E6.jsxDEV("div",{className:"space-y-3",children:[E6.jsxDEV("h3",{className:"text-sm font-medium",children:"Rename"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"flex items-center gap-2",children:[E6.jsxDEV(uZ,{value:X,onChange:(R)=>U(R.target.value),onKeyDown:(R)=>R.key==="Enter"&&!O&&A(),className:"max-w-sm"},void 0,!1,void 0,this),E6.jsxDEV(g6,{size:"sm",onClick:A,disabled:O,children:B.isPending?"Saving...":"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&E6.jsxDEV("div",{className:"text-sm text-destructive",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"space-y-3",children:[E6.jsxDEV("h3",{className:"text-sm font-medium",children:"Flag"},void 0,!1,void 0,this),E6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"Flag this story to indicate it needs attention"},void 0,!1,void 0,this),E6.jsxDEV(g6,{size:"sm",variant:"outline",onClick:()=>Q.mutate({entityId:Z.id,fieldName:"flag",value:"true"}),disabled:Z.fields?.flag==="true",children:Z.fields?.flag==="true"?"Story is flagged":"Flag Story"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"space-y-3",children:[E6.jsxDEV("h3",{className:"text-sm font-medium",children:"Danger Zone"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"border border-destructive/30 rounded-md p-4",children:E6.jsxDEV("div",{className:"flex items-center justify-between",children:[E6.jsxDEV("div",{children:[E6.jsxDEV("div",{className:"text-sm font-medium",children:"Delete this story"},void 0,!1,void 0,this),E6.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),E6.jsxDEV(g6,{variant:"destructive",size:"sm",onClick:()=>W(!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),E6.jsxDEV(sJ,{open:G,onOpenChange:W,children:E6.jsxDEV(vJ,{children:[E6.jsxDEV(fJ,{children:E6.jsxDEV(_J,{className:"flex items-center gap-2 text-destructive",children:[E6.jsxDEV(B7,{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),E6.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete ",E6.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),q&&E6.jsxDEV("div",{className:"text-sm text-destructive",children:q},void 0,!1,void 0,this),E6.jsxDEV(DZ,{children:[E6.jsxDEV(g6,{variant:"outline",onClick:()=>W(!1),children:"Cancel"},void 0,!1,void 0,this),E6.jsxDEV(g6,{variant:"destructive",onClick:N,disabled:M.isPending,children:M.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)},lB0=()=>{let{id:J,storeCode:Z}=EQ(),{selectedId:Q,setSelectedId:K,isEditMode:X,setEditMode:U,activeTab:Y,setActiveTab:z,expandedId:G,setExpandedId:W}=BM(),{data:q}=w1(J);I1(q?`${q.name} - Stories`:"CAW");let H=Z??"A";GB(J);let{data:B=[],isLoading:M,error:O,refetch:A}=PX6(J,{store:H}),{states:N,isLoading:R,error:w,refetch:P}=CX6(J),V=DX6(J),D=EX6(J),T=Dr(J),[C,S]=cJ.useState(!1),[f,h]=cJ.useState(""),[k,$]=cJ.useState(""),[v,_]=cJ.useState(null);cJ.useEffect(()=>{if(N.length>0&&k==="")$(N[0])},[N,k]);let b=Y||"documents",x=(J0)=>{z(J0)},[m,g]=cJ.useState("state-asc"),u=cJ.useRef(null),{activeStates:d,setActiveStates:l}=xN0(J),r=cJ.useMemo(()=>{if(!d)return new Set(N);let J0=d.filter((j0)=>N.includes(j0));return J0.length>0?new Set(J0):new Set(N)},[d,N]);cJ.useEffect(()=>{if(!d||!N.length)return;let J0=d.filter((j0)=>N.includes(j0));if(J0.length!==d.length)l(J0.length>0&&J0.length<N.length?J0:null)},[d,N,l]);let o=(J0)=>{let j0=d?new Set(d):new Set(N),q0=new Set(j0);if(q0.has(J0))q0.delete(J0);else q0.add(J0);l(q0.size===N.length?null:[...q0])},Y0=cJ.useRef(null);cJ.useEffect(()=>{if(Q&&Y0.current!==Q){if(Y0.current=Q,!Y||Y!=="documents"&&Y!=="tasks")z("documents")}else if(!Q)Y0.current=null},[Q,Y,z]);let e=G??"",B0=cJ.useRef({});cJ.useEffect(()=>{if(!M&&G&&B0.current[G])setTimeout(()=>{B0.current[G]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},[M,G]);let Q0=(J0)=>{if(W(J0||null),J0)setTimeout(()=>{B0.current[J0]?.scrollIntoView({behavior:"smooth",block:"start"})},100)},M0=cJ.useMemo(()=>{if(!N.length)return[];let J0=B.filter((q0)=>q0.fields?.state&&r.has(q0.fields.state));if(m==="unsorted"){if(u.current){let q0=u.current,v0=[...J0];return v0.sort((Z0,e0)=>{let X0=q0.indexOf(Z0.id),T0=q0.indexOf(e0.id);return(X0===-1?1/0:X0)-(T0===-1?1/0:T0)}),v0}return J0}let j0=[...J0];return j0.sort((q0,v0)=>{if(m==="name-asc")return q0.name.localeCompare(v0.name);if(m==="name-desc")return v0.name.localeCompare(q0.name);if(m==="date-asc"||m==="date-desc"){let Z0=(X0)=>X0.createdAt?new Date(X0.createdAt).getTime():parseInt(X0.id.replace(/\D/g,""),10)||0,e0=Z0(q0)-Z0(v0);return m==="date-asc"?e0:-e0}if(m==="state-asc")return N.indexOf(q0.fields.state)-N.indexOf(v0.fields.state);if(m==="state-desc")return N.indexOf(v0.fields.state)-N.indexOf(q0.fields.state);return 0}),j0},[B,N,m,r]),W0=()=>{if(!f.trim()){_("Story name is required");return}_(null),V.mutate({name:f.trim(),store:H,state:k},{onSuccess:(J0)=>{S(!1),h(""),$(N[0]||""),W(J0.id)},onError:(J0)=>{_(J0.message)}})},H0=()=>{S(!1),h(""),$(N[0]||""),_(null)},U0=M||R,K0=O||w,O0=O?A:P;if(U0)return E6.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(K0)return E6.jsxDEV("div",{className:"p-6",children:[E6.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading stories"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:K0.message},void 0,!1,void 0,this),E6.jsxDEV(g6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>O0(),children:[E6.jsxDEV(NO,{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 E6.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[E6.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:E6.jsxDEV("div",{className:"flex items-center gap-2",children:[E6.jsxDEV(g6,{size:"sm",variant:"warning",onClick:()=>S(!0),children:[E6.jsxDEV(X5,{className:"w-4 h-4"},void 0,!1,void 0,this),E6.jsxDEV(nH,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(Ah,{children:[E6.jsxDEV(s9,{content:uB0.find((J0)=>J0.key===m)?.label,children:E6.jsxDEV(Nh,{asChild:!0,children:E6.jsxDEV(g6,{size:"sm",variant:"outline",children:cJ.default.createElement(uB0.find((J0)=>J0.key===m)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(Fj,{align:"start",children:uB0.map((J0)=>E6.jsxDEV(Mj,{onClick:()=>{if(J0.key==="unsorted")u.current=M0.map((j0)=>j0.id);else u.current=null;g(J0.key)},className:m===J0.key?"bg-accent":"",children:[E6.jsxDEV(J0.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),J0.label]},J0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(IK6,{children:[E6.jsxDEV(s9,{content:"Filter by state",children:E6.jsxDEV(PK6,{asChild:!0,children:E6.jsxDEV(g6,{size:"sm",variant:"outline",children:E6.jsxDEV(eH,{className:"w-4 h-4",...d&&{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),E6.jsxDEV(TB0,{align:"center",children:E6.jsxDEV("div",{className:"space-y-2",children:[E6.jsxDEV("div",{className:"text-sm font-medium",children:"Show by state:"},void 0,!1,void 0,this),N.map((J0)=>E6.jsxDEV("label",{className:"flex items-center gap-2",children:[E6.jsxDEV(FH,{checked:r.has(J0),onCheckedChange:()=>o(J0)},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"text-sm capitalize",children:J0},void 0,!1,void 0,this)]},J0,!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),M0.length===0?E6.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories yet"},void 0,!1,void 0,this):E6.jsxDEV("div",{className:"flex-1 overflow-auto",children:E6.jsxDEV(Db,{type:"single",collapsible:!0,value:e,onValueChange:Q0,children:M0.map((J0)=>{let j0=N.indexOf(J0.fields.state),q0=j0>0?N[j0-1]:null,v0=j0<N.length-1?N[j0+1]:null;return E6.jsxDEV(Eb,{value:J0.id,className:"border-b",ref:(Z0)=>{B0.current[J0.id]=Z0},children:[E6.jsxDEV(Vb,{className:"grid grid-cols-[24%_50%_24%] 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 gap-[1%]",children:[E6.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[E6.jsxDEV(nH,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"truncate text-sm",children:J0.name},void 0,!1,void 0,this),E6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${J0.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:J0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"grid grid-cols-8 items-center",children:[E6.jsxDEV("span",{className:"text-xs text-muted-foreground text-right pr-1",children:"Status:"},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"col-span-6",children:E6.jsxDEV(GB8,{state:J0.fields.state,states:N,onPrev:q0?()=>D.mutate({id:J0.id,state:q0}):null,onNext:v0?()=>D.mutate({id:J0.id,state:v0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"grid grid-cols-[20px_40px] items-center ml-2",children:[E6.jsxDEV("div",{className:"flex justify-center",children:J0.fields?.flag==="true"&&E6.jsxDEV(HV,{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(),T.mutate({entityId:J0.id,fieldName:"flag",value:"false"})}},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"flex justify-center",children:parseInt(J0.fields?.activeJobCount||"0",10)>0&&E6.jsxDEV("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[E6.jsxDEV(xG,{className:"w-4 h-4 text-blue-500 dark:text-blue-400"},void 0,!1,void 0,this),E6.jsxDEV("span",{className:"text-[10px] font-mono text-blue-600 dark:text-blue-300",children:J0.fields.activeJobCount},void 0,!1,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),E6.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[J0.fields?.statusMessage?.trim()&&E6.jsxDEV(XK6,{message:J0.fields.statusMessage,onNavigate:(Z0)=>{W(J0.id,{history:"replace",withSelection:Z0})}},void 0,!1,void 0,this),E6.jsxDEV(o1,{className:"chevron w-4 h-4 flex-shrink-0 transition-transform ml-auto"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(jb,{className:"border-t",children:E6.jsxDEV(ZK6,{value:b,onValueChange:x,children:[E6.jsxDEV(EB0,{variant:"line",className:"px-4",children:[E6.jsxDEV(h3,{value:"documents",children:[E6.jsxDEV(rZ,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Documents"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"tasks",children:[E6.jsxDEV(aX,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Tasks"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"prompts",children:[E6.jsxDEV(zz,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"jobs",children:[E6.jsxDEV(xG,{className:"w-4 h-4 mr-1.5"},void 0,!1,void 0,this),"Jobs"]},void 0,!0,void 0,this),E6.jsxDEV(h3,{value:"settings",children:[E6.jsxDEV(Wz,{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),E6.jsxDEV(y3,{value:"documents",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(Dh,{projectId:J,rootFolderId:J0.id,type:"d",DetailPanel:yd,hooks:UB8},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"tasks",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(HX6,{projectId:J,storyId:J0.id,selectedId:Q,onOpenDocument:(Z0,e0)=>{K(Z0,{edit:e0?.edit})}},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"prompts",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(WB8,{projectId:J,storyId:J0.id},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"jobs",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(LX6,{projectId:J,storyId:J0.id,storeCode:Z,projectPath:q?.path},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(y3,{value:"settings",children:E6.jsxDEV("div",{className:"h-[800px]",children:E6.jsxDEV(qB8,{projectId:J,story:J0,setFieldMutation:T,onDeleted:()=>{W(null)}},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)]},J0.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(sJ,{open:C,onOpenChange:H0,children:E6.jsxDEV(vJ,{children:[E6.jsxDEV(fJ,{children:E6.jsxDEV(_J,{children:"Create Story"},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV("div",{className:"space-y-4 py-4",children:[E6.jsxDEV("div",{className:"space-y-2",children:[E6.jsxDEV(y4,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),E6.jsxDEV(uZ,{id:"name",value:f,onChange:(J0)=>h(J0.target.value),placeholder:"Enter story name",onKeyDown:(J0)=>J0.key==="Enter"&&W0()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV("div",{className:"space-y-2",children:[E6.jsxDEV(y4,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),E6.jsxDEV(kQ,{value:k,onValueChange:$,children:[E6.jsxDEV(eZ,{children:E6.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),E6.jsxDEV(JQ,{children:N.map((J0)=>E6.jsxDEV(P4,{value:J0,children:J0.charAt(0).toUpperCase()+J0.slice(1)},J0,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),v&&E6.jsxDEV("div",{className:"text-sm text-destructive",children:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E6.jsxDEV(DZ,{children:[E6.jsxDEV(g6,{variant:"outline",onClick:H0,children:"Cancel"},void 0,!1,void 0,this),E6.jsxDEV(g6,{onClick:W0,disabled:V.isPending,children:V.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 W1=f0(D6(),1);var g1=f0(D6(),1);var b9=f0(e6(),1),HB8=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],SX6=({open:J,onOpenChange:Z,projectId:Q,onSuccess:K,initialPrompt:X=""})=>{let[U,Y]=g1.useState(""),[z,G]=g1.useState("claude"),[W,q]=g1.useState(""),[H,B]=g1.useState({type:"main",path:null}),[M,O]=g1.useState(""),[A,N]=g1.useState(""),[R,w]=g1.useState(!1),[P,V]=g1.useState(!1),[D,T]=g1.useState({}),[C,S]=g1.useState(!1),[f,h]=g1.useState(null),[k,$]=g1.useState(null);g1.useEffect(()=>{if(X)O(X)},[X]);let{data:v,isLoading:_,error:b}=Yr(J?Q:null),x=v?.worktrees??[],m=v?.isGitProject??!0,g=Ur(Q),u=hd(Q),d=zr(Q),{data:l}=_P(Q,A.trim()||null),r=l?.parameters??[],o=l?.detectedVariables??[],Y0=A.trim().length>0,e=()=>{Y(""),G("claude"),q(""),B({type:"main",path:null}),O(X||""),N(""),w(!1),h(null),$(null),T({}),S(!1)},B0=()=>{e(),Z(!1)},Q0=()=>{if(H.type==="main")return;return H.path||void 0},M0=(q0)=>{g.mutate({name:U.trim()||void 0,agent:z,model:W.trim()||void 0,prompt:M.trim(),workingDirectory:q0,streaming:R},{onSuccess:(v0)=>{if(B0(),K)K(v0)},onError:(v0)=>{h(v0.message)}})},W0=()=>{if(!M.trim()){h("Prompt is required");return}if(H.type==="new"&&m){if(!H.branch||!H.branch.trim()){$("Branch name is required");return}}if(h(null),$(null),H.type==="new"&&m&&H.branch)d.mutate({branch:H.branch.trim(),baseBranch:H.baseBranch?.trim()||void 0},{onSuccess:(q0)=>{M0(q0.path)},onError:(q0)=>{$(q0.message)}});else M0(Q0())},H0=()=>{V(!0)},U0=(q0)=>{T(q0),u.mutate({id:A.trim(),params:q0,target:"stdout"},{onSuccess:(v0)=>{if(v0.content)O(v0.content);N(""),V(!1)},onError:(v0)=>{h(`Template render failed: ${v0.message}`),V(!1)}})},K0=Y0?"render":"run",O0=K0==="run"&&!M.trim(),J0=d.isPending,j0=g.isPending||u.isPending||J0;return b9.jsxDEV(b9.Fragment,{children:[b9.jsxDEV(sJ,{open:J,onOpenChange:B0,children:b9.jsxDEV(vJ,{className:"max-w-lg",children:[b9.jsxDEV(fJ,{children:b9.jsxDEV(_J,{children:"New Job"},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV("div",{className:"space-y-4 py-4",children:[b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),b9.jsxDEV(uZ,{id:"job-name",value:U,onChange:(q0)=>Y(q0.target.value),placeholder:"Auto-generated if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),b9.jsxDEV(kQ,{value:z,onValueChange:G,children:[b9.jsxDEV(eZ,{children:b9.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(JQ,{children:HB8.map((q0)=>b9.jsxDEV(P4,{value:q0.value,children:q0.label},q0.value,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),b9.jsxDEV(uZ,{id:"job-model",value:W,onChange:(q0)=>q(q0.target.value),placeholder:"Optional - uses default if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="claude"&&b9.jsxDEV("div",{className:"flex items-center gap-2",children:[b9.jsxDEV(FH,{id:"job-streaming",checked:R,onCheckedChange:w},void 0,!1,void 0,this),b9.jsxDEV(y4,{htmlFor:"job-streaming",className:"text-sm font-normal cursor-pointer",children:"Enable streaming output"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV("button",{type:"button",onClick:()=>S(!C),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[C?b9.jsxDEV(o1,{className:"w-4 h-4"},void 0,!1,void 0,this):b9.jsxDEV(rX,{className:"w-4 h-4"},void 0,!1,void 0,this),b9.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C&&b9.jsxDEV(Kr,{value:H,onChange:B,worktrees:x,isLoadingWorktrees:_,isGitProject:m,error:b,createError:k,onCreateErrorClear:()=>$(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),b9.jsxDEV(Kq,{id:"job-prompt",value:M,onChange:(q0)=>O(q0.target.value),placeholder:"Enter the prompt for the agent...",rows:6},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV("div",{className:"space-y-2",children:[b9.jsxDEV(y4,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),b9.jsxDEV(uZ,{id:"job-template",value:A,onChange:(q0)=>N(q0.target.value),placeholder:"Template ID (optional)"},void 0,!1,void 0,this),Y0&&b9.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),f&&b9.jsxDEV("div",{className:"text-sm text-destructive",children:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b9.jsxDEV(DZ,{children:[b9.jsxDEV(g6,{variant:"outline",onClick:B0,children:"Cancel"},void 0,!1,void 0,this),K0==="render"?b9.jsxDEV(g6,{onClick:H0,disabled:j0,children:[b9.jsxDEV(rZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),j0?"Rendering...":"Render"]},void 0,!0,void 0,this):b9.jsxDEV(g6,{onClick:W0,disabled:O0||j0,children:[b9.jsxDEV(oX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),J0?"Creating worktree...":g.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),b9.jsxDEV(sJ,{open:P,onOpenChange:V,children:b9.jsxDEV(vJ,{className:"max-w-lg",children:[b9.jsxDEV(fJ,{children:b9.jsxDEV(_J,{className:"flex items-center gap-2",children:[b9.jsxDEV(rZ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",KY(l?.path)," (",A,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b9.jsxDEV(Qr,{fields:r,detectedVariables:o,initialValues:D,onSubmit:U0,onCancel:()=>V(!1),isSubmitting:u.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 D9=f0(e6(),1),BB8=86400000,$X6=({title:J,count:Z})=>{return D9.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:[D9.jsxDEV("h3",{className:"text-sm font-semibold text-foreground",children:J},void 0,!1,void 0,this),D9.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",Z,")"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},FB8=({column:J,sortColumn:Z,sortDirection:Q})=>{if(Z!==J)return D9.jsxDEV(HO,{className:"w-3 h-3 ml-1 opacity-50"},void 0,!1,void 0,this);return Q==="asc"?D9.jsxDEV(BO,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this):D9.jsxDEV(qO,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)},iB0=({onSort:J,sortColumn:Z,sortDirection:Q})=>{return D9.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-64",sortable:!1},{key:"name",label:"Name",width:"flex-1"},{key:"agent",label:"Agent",width:"w-16"},{key:"model",label:"Model",width:"w-24"},{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 D9.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&&D9.jsxDEV(FB8,{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)},kX6=["active","history"],dB0=(J,Z,Q="")=>{let K=Z?`/project/${J}/store/${Z}/jobs`:`/project/${J}/jobs`;return Q?`${K}/${Q}`:K},vX6=({active:J,onClick:Z,children:Q})=>D9.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),MB8=({activeJobs:J,completedJobs:Z,onJobClick:Q,onNewJob:K,projectPath:X,onActiveSort:U,activeSortColumn:Y,activeSortDirection:z,onCompletedSort:G,completedSortColumn:W,completedSortDirection:q})=>D9.jsxDEV("div",{className:"space-y-6",children:[D9.jsxDEV("div",{className:"flex justify-start",children:D9.jsxDEV(g6,{size:"sm",variant:"warning",onClick:K,children:[D9.jsxDEV(X5,{className:"w-4 h-4"},void 0,!1,void 0,this),D9.jsxDEV(xG,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),D9.jsxDEV("div",{children:[D9.jsxDEV($X6,{title:"Active Jobs",count:J.length},void 0,!1,void 0,this),J.length>0?D9.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[D9.jsxDEV(iB0,{onSort:U,sortColumn:Y,sortDirection:z},void 0,!1,void 0,this),J.map((H)=>D9.jsxDEV(HD,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):D9.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[D9.jsxDEV(oX,{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),D9.jsxDEV("div",{children:[D9.jsxDEV($X6,{title:"Recently Completed",count:Z.length},void 0,!1,void 0,this),Z.length>0?D9.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[D9.jsxDEV(iB0,{onSort:G,sortColumn:W,sortDirection:q},void 0,!1,void 0,this),Z.map((H)=>D9.jsxDEV(HD,{job:H,onClick:Q,projectPath:X},H.id,!1,void 0,this))]},void 0,!0,void 0,this):D9.jsxDEV("div",{className:"text-sm text-muted-foreground py-4 px-3 border rounded-lg bg-muted/20 flex items-center gap-2",children:[D9.jsxDEV(fG,{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),OB8=({completedJobs:J,onJobClick:Z,projectPath:Q,onSort:K,sortColumn:X,sortDirection:U})=>D9.jsxDEV("div",{children:J.length>0?D9.jsxDEV(D9.Fragment,{children:[D9.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),D9.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[D9.jsxDEV(iB0,{onSort:K,sortColumn:X,sortDirection:U},void 0,!1,void 0,this),J.map((Y)=>D9.jsxDEV(HD,{job:Y,onClick:Z,projectPath:Q},Y.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):D9.jsxDEV("div",{className:"text-center py-8 text-muted-foreground",children:[D9.jsxDEV(fG,{className:"w-8 h-8 mx-auto mb-2 opacity-50"},void 0,!1,void 0,this),D9.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),ek=()=>{let{id:J,storeCode:Z,tab:Q}=EQ(),K=dJ(),X=a4(),{data:U}=w1(J),Y=Q&&!kX6.includes(Q),z=kX6.includes(Q)?Q:"active";I1(U?`${U.name} - Jobs`:"CAW");let[G,W]=W1.useState(!1),[q,H]=W1.useState(""),[B,M]=W1.useState("startedAt"),[O,A]=W1.useState("desc"),[N,R]=W1.useState("completedAt"),[w,P]=W1.useState("desc"),[V,D]=W1.useState("completedAt"),[T,C]=W1.useState("desc"),S=Z??"A";GB(J);let{data:f=[],isLoading:h,error:k,refetch:$}=Xr(J,{store:S}),v=(o)=>{return["startedAt","completedAt","tokensUsed"].includes(o)?"desc":"asc"},_=(o)=>{if(B===o)A((Y0)=>Y0==="asc"?"desc":"asc");else M(o),A(v(o))},b=(o)=>{if(N===o)P((Y0)=>Y0==="asc"?"desc":"asc");else R(o),P(v(o))},x=(o)=>{if(V===o)C((Y0)=>Y0==="asc"?"desc":"asc");else D(o),C(v(o))},m=(o,Y0,e)=>{return[...o].sort((B0,Q0)=>{let M0=0;switch(Y0){case"status":let W0={running:0,completed:1,error:2};M0=(W0[B0.fields?.status]??3)-(W0[Q0.fields?.status]??3);break;case"name":M0=(B0.name||"").localeCompare(Q0.name||"");break;case"agent":M0=(B0.fields?.agent||"").localeCompare(Q0.fields?.agent||"");break;case"model":M0=(B0.fields?.model||"").localeCompare(Q0.fields?.model||"");break;case"startedAt":case"completedAt":let H0=(O0)=>{if(!O0)return 0;let J0=new Date(O0).getTime();return isNaN(J0)?0:J0},U0=H0(B0.fields?.[Y0]),K0=H0(Q0.fields?.[Y0]);M0=U0-K0;break;case"tokensUsed":M0=(B0.fields?.tokensUsed??0)-(Q0.fields?.tokensUsed??0);break;default:M0=0}return e==="asc"?M0:-M0})},g=W1.useMemo(()=>{let o=f.filter((Y0)=>Y0.fields?.status==="running");return m(o,B,O)},[f,B,O]),u=W1.useMemo(()=>{let o=Date.now()-BB8,Y0=f.filter((e)=>e.fields?.status==="completed"||e.fields?.status==="error").filter((e)=>e.fields?.completedAt&&new Date(e.fields?.completedAt).getTime()>o);return m(Y0,N,w)},[f,N,w]),d=W1.useMemo(()=>{let o=f.filter((Y0)=>Y0.fields?.status==="completed"||Y0.fields?.status==="error");return m(o,V,T)},[f,V,T]),l=(o)=>{let Y0=Z?`/project/${J}/store/${Z}/job/${o.id}?from=${z}`:`/project/${J}/job/${o.id}?from=${z}`;K(Y0)},r=(o)=>{if(o&&o.id){let Y0=Z?`/project/${J}/store/${Z}/job/${o.id}?from=${z}`:`/project/${J}/job/${o.id}?from=${z}`;K(Y0)}};if(W1.useEffect(()=>{if(X.state?.openNewJobWithPrompt)H(X.state.openNewJobWithPrompt),W(!0),K(X.pathname,{replace:!0,state:{}})},[X.state,K,X.pathname]),W1.useEffect(()=>{if(Y)K(dB0(J,Z,"active"),{replace:!0})},[Y,K,J,Z]),Y)return null;if(h)return D9.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(k)return D9.jsxDEV("div",{className:"p-6",children:[D9.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),D9.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:k.message},void 0,!1,void 0,this),D9.jsxDEV(g6,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>$(),children:[D9.jsxDEV(NO,{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 D9.jsxDEV("div",{className:"h-full flex flex-col",children:[D9.jsxDEV("div",{className:"flex border-b overflow-x-auto bg-muted/50 px-2",role:"tablist","aria-label":"Jobs tabs",children:[D9.jsxDEV(vX6,{active:z==="active",onClick:()=>K(dB0(J,Z,"active")),children:"Active"},void 0,!1,void 0,this),D9.jsxDEV(vX6,{active:z==="history",onClick:()=>K(dB0(J,Z,"history")),children:"History"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D9.jsxDEV("div",{className:"flex-1 overflow-auto p-6",children:z==="active"?D9.jsxDEV(MB8,{activeJobs:g,completedJobs:u,onJobClick:l,onNewJob:()=>W(!0),projectPath:U?.path,onActiveSort:_,activeSortColumn:B,activeSortDirection:O,onCompletedSort:b,completedSortColumn:N,completedSortDirection:w},void 0,!1,void 0,this):D9.jsxDEV(OB8,{completedJobs:d,onJobClick:l,projectPath:U?.path,onSort:x,sortColumn:V,sortDirection:T},void 0,!1,void 0,this)},void 0,!1,void 0,this),D9.jsxDEV(SX6,{open:G,onOpenChange:(o)=>{if(W(o),!o)H("")},projectId:J,onSuccess:r,initialPrompt:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var lJ=f0(D6(),1);var rB0=f0(D6(),1);var Jv=f0(e6(),1),jr=({value:J,disabled:Z=!1,className:Q=""})=>{let[K,X]=rB0.useState(!1);return Jv.jsxDEV(s9,{content:"Copy to clipboard",children:Jv.jsxDEV(g6,{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?Jv.jsxDEV(A1,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):Jv.jsxDEV(kZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var LH=f0(D6(),1);var eQ=f0(e6(),1),fX6=({open:J,onOpenChange:Z,sessionId:Q,currentModel:K,onContinue:X,isLoading:U})=>{let[Y,z]=LH.useState(""),[G,W]=LH.useState(""),q=LH.useRef(null);LH.useEffect(()=>{if(!J)z(""),W("");else W(K||"")},[J,K]),LH.useEffect(()=>{if(J&&q.current){let O=setTimeout(()=>{q.current?.focus()},50);return()=>clearTimeout(O)}},[J]);let H=(O)=>{O.preventDefault();let A=Y.trim();if(A)X(A,G.trim()||void 0)},B=()=>{z(""),W(""),Z(!1)},M=!Y.trim()||U;return eQ.jsxDEV(sJ,{open:J,onOpenChange:B,children:eQ.jsxDEV(vJ,{children:[eQ.jsxDEV(fJ,{children:eQ.jsxDEV(_J,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),eQ.jsxDEV("form",{onSubmit:H,className:"space-y-4",children:[eQ.jsxDEV("div",{className:"space-y-2",children:[eQ.jsxDEV(y4,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),eQ.jsxDEV(uZ,{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),eQ.jsxDEV("div",{className:"space-y-2",children:[eQ.jsxDEV(y4,{htmlFor:"continue-model",children:"Model"},void 0,!1,void 0,this),eQ.jsxDEV(uZ,{id:"continue-model",value:G,onChange:(O)=>W(O.target.value),placeholder:"Optional - uses current model if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),eQ.jsxDEV("div",{className:"space-y-2",children:[eQ.jsxDEV(y4,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),eQ.jsxDEV(Kq,{ref:q,id:"continue-prompt",value:Y,onChange:(O)=>z(O.target.value),placeholder:"Enter your follow-up prompt...",rows:6,autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),eQ.jsxDEV(DZ,{children:[eQ.jsxDEV(g6,{type:"button",variant:"outline",onClick:B,children:"Cancel"},void 0,!1,void 0,this),eQ.jsxDEV(g6,{type:"submit",disabled:M,children:[U&&eQ.jsxDEV(c7,{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 LB8=f0(D6(),1);var FQ=f0(e6(),1),_X6=({open:J,onOpenChange:Z,projectId:Q,jobId:K,pid:X})=>{let{data:U,isLoading:Y,error:z,refetch:G}=$16(Q,K,J),W=()=>{if(Y)return FQ.jsxDEV(c7,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this);if(z)return FQ.jsxDEV(B7,{className:"w-5 h-5 text-destructive"},void 0,!1,void 0,this);if(U?.exists)return FQ.jsxDEV(yU,{className:"w-5 h-5 text-green-600"},void 0,!1,void 0,this);return FQ.jsxDEV(_G,{className:"w-5 h-5 text-muted-foreground"},void 0,!1,void 0,this)},q=()=>{if(Y)return"Checking process...";if(z)return`Error: ${z.message}`;if(U?.error)return U.error;if(!U?.exists)return"Process not running";return`Process is ${U.state||"active"}`};return FQ.jsxDEV(sJ,{open:J,onOpenChange:Z,children:FQ.jsxDEV(vJ,{children:[FQ.jsxDEV(fJ,{children:FQ.jsxDEV(_J,{children:"Process Diagnostics"},void 0,!1,void 0,this)},void 0,!1,void 0,this),FQ.jsxDEV("div",{className:"space-y-4",children:[FQ.jsxDEV("div",{className:"flex items-center gap-3 p-4 border rounded-lg",children:[W(),FQ.jsxDEV("div",{children:[FQ.jsxDEV("p",{className:"font-medium",children:q()},void 0,!1,void 0,this),FQ.jsxDEV("p",{className:"text-sm text-muted-foreground font-mono",children:["PID: ",X]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?.exists&&U?.command&&FQ.jsxDEV("div",{className:"text-sm",children:[FQ.jsxDEV("span",{className:"font-medium",children:"Command: "},void 0,!1,void 0,this),FQ.jsxDEV("span",{className:"font-mono",children:U.command},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),FQ.jsxDEV(DZ,{children:[FQ.jsxDEV(g6,{variant:"outline",onClick:()=>G(),children:"Refresh"},void 0,!1,void 0,this),FQ.jsxDEV(g6,{onClick:()=>Z(!1),children:"Close"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var Q8=f0(e6(),1),AB8=({status:J})=>{let Z={running:{icon:c7,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:yU,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:_G,class:"text-red-700 border-red-300 bg-red-50",animate:!1},pending:{icon:GV,class:"text-gray-700 border-gray-300 bg-gray-50",animate:!1}},{icon:Q,class:K,animate:X}=Z[J]||Z.pending;return Q8.jsxDEV("span",{className:`inline-flex items-center gap-1.5 rounded border px-2 py-1 text-sm font-medium ${K}`,children:[Q8.jsxDEV(Q,{className:`w-4 h-4 ${X?"animate-spin":""}`},void 0,!1,void 0,this),J]},void 0,!0,void 0,this)},bX6=(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"})},NB8=(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()},xX6=(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},nB0=({title:J,docId:Z,isOpen:Q,onToggle:K,deepLinkUrl:X,children:U})=>Q8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[Q8.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?Q8.jsxDEV(o1,{className:"w-4 h-4"},void 0,!1,void 0,this):Q8.jsxDEV(rX,{className:"w-4 h-4"},void 0,!1,void 0,this),Q8.jsxDEV(rZ,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"font-medium",children:J},void 0,!1,void 0,this),Z&&Q8.jsxDEV("span",{className:"text-xs text-muted-foreground ml-auto font-mono flex items-center gap-1",children:[Z,X&&Q8.jsxDEV("span",{onClick:(Y)=>Y.stopPropagation(),children:Q8.jsxDEV(jr,{value:X},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q&&Q8.jsxDEV("div",{className:"p-4",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),hX6=({turnNumber:J,promptContent:Z,outputContent:Q,showHeading:K,promptDocId:X,outputDocId:U,isPromptOpen:Y,setIsPromptOpen:z,isOutputOpen:G,setIsOutputOpen:W,onInternalLinkClick:q,promptDeepLinkUrl:H,outputDeepLinkUrl:B,sectionRef:M,highlightedSection:O})=>{return Q8.jsxDEV("div",{className:"space-y-4",ref:O?M:null,children:[K&&Q8.jsxDEV("h3",{className:"text-lg font-semibold text-muted-foreground",children:["Turn ",J]},void 0,!0,void 0,this),Q&&Q8.jsxDEV(nB0,{title:"Output",docId:U,isOpen:G,onToggle:W,deepLinkUrl:B,children:Q8.jsxDEV(yY,{markdown:Q,onInternalLinkClick:q},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q8.jsxDEV(nB0,{title:"Prompt",docId:X,isOpen:Y,onToggle:z,deepLinkUrl:H,children:Q8.jsxDEV(yY,{markdown:Z||"",onInternalLinkClick:q},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},RB8=({content:J,isOpen:Z,onToggle:Q})=>Q8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[Q8.jsxDEV("button",{onClick:()=>Q(!Z),className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[Z?Q8.jsxDEV(o1,{className:"w-4 h-4"},void 0,!1,void 0,this):Q8.jsxDEV(rX,{className:"w-4 h-4"},void 0,!1,void 0,this),Q8.jsxDEV(LV,{className:"w-4 h-4 text-blue-500 animate-pulse"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"font-medium",children:"Streaming Output"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"text-xs text-blue-500 ml-2",children:"(live)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&Q8.jsxDEV("div",{className:"p-4",children:J?Q8.jsxDEV("pre",{className:"whitespace-pre-wrap font-mono text-sm bg-muted/20 p-4 rounded overflow-auto max-h-[600px]",children:J},void 0,!1,void 0,this):Q8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-4",children:[Q8.jsxDEV(c7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Waiting for output..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),wB8=86400000,IB8=["active","history"],sB0=()=>{let{id:J,storeCode:Z,jobId:Q}=EQ(),K=dJ(),X=a4(),{data:U}=w1(J),{fromContext:Y}=BM(),z=new URLSearchParams(X.search).get("doc");I1(U?`${U.name} - Job: ${Q}`:"CAW"),GB(J);let[G,W]=lJ.useState(""),[q,H]=lJ.useState(!1),B=lJ.useRef(null),{data:M,isLoading:O,error:A}=j16(J,Q),{data:N,isLoading:R}=T16(J,Q),{promptDoc:w,outputDoc:P}=lJ.useMemo(()=>{if(!N)return{promptDoc:null,outputDoc:null};let R0=N.documents||[],P0=R0.find((A0)=>A0.name==="prompt.md"),s=R0.find((A0)=>A0.name==="output.md");return{promptDoc:P0,outputDoc:s}},[N]),{data:V}=XG(J,w?.id),{data:D}=XG(J,P?.id),T=V?.draftContent??V?.publishedContent??"",C=D?.draftContent??D?.publishedContent??"",S=lJ.useMemo(()=>xX6(T),[T]),f=lJ.useMemo(()=>xX6(C),[C]),h=S.length>1||f.length>1,k=async({type:R0,id:P0,path:s,anchor:A0})=>{if(R0==="anchor"){K(`${X.pathname}${X.search}#${A0}`,{replace:!0});return}if(R0==="id"){let N0=P0?.charAt(1)?.toLowerCase();if(N0==="d"||N0==="t"){H0({id:P0,anchor:A0||null});return}}let i=A0?`#${A0}`:"",L0=Z?`/store/${Z}`:"";if(R0==="id"){let N0=P0?.charAt(1)?.toLowerCase();if(N0==="j")K(`/project/${J}${L0}/job/${P0}${i}`);else if(N0==="s")K(`/project/${J}${L0}/stories?expanded=${P0}${i}`);else if(N0==="f")try{let x0=await g5(J,P0),$0=x0?.path||"";if($0.startsWith("Templates/"))K(`/project/${J}${L0}/templates?id=${P0}${i}`);else if($0.startsWith("Stories/")){let D0=x0?.parentId?.startsWith("As")?x0.parentId:null;if(!D0){let h0=x0?.parentId?await g5(J,x0.parentId):null;while(h0&&!D0)if(h0.parentId?.startsWith("As"))D0=h0.parentId;else if(h0.id?.startsWith("As"))D0=h0.id;else h0=h0.parentId?await g5(J,h0.parentId):null}if(D0)K(`/project/${J}${L0}/stories?expanded=${D0}&id=${P0}&tab=documents${i}`);else K(`/project/${J}${L0}/stories?id=${P0}${i}`)}else K(`/project/${J}${L0}/documents?id=${P0}${i}`)}catch{K(`/project/${J}${L0}/documents?id=${P0}${i}`)}else K(`/project/${J}${L0}/documents?id=${P0}${i}`)}else if(R0==="path")K(`/project/${J}${L0}${s}${i}`)},[$,v]=lJ.useState({}),[_,b]=lJ.useState(!0),x=Math.max(S.length,f.length);lJ.useEffect(()=>{v((R0)=>{let P0={...R0};for(let s=0;s<x;s++)if(!(s in P0))P0[s]={promptOpen:!0,outputOpen:!0};return P0})},[x]);let m=lJ.useRef(null);lJ.useEffect(()=>{if(!z)return;if(z!==w?.id&&z!==P?.id)return;let R0=z===w?.id,P0=z===P?.id;v(()=>{let s={};for(let A0=0;A0<x;A0++)s[A0]={promptOpen:R0,outputOpen:P0};return s})},[z,w?.id,P?.id,x]),lJ.useEffect(()=>{if(z&&m.current)setTimeout(()=>{m.current?.scrollIntoView({behavior:"smooth",block:"start"})},100)},[z]);let g=`${window.location.origin}${X.pathname}`,u=w?.id?`${g}?doc=${w.id}${Y?`&from=${Y}`:""}`:null,d=P?.id?`${g}?doc=${P.id}${Y?`&from=${Y}`:""}`:null,l=z===w?.id?"prompt":z===P?.id?"output":null,r=M?.fields?.status,o=M?.fields?.streaming==="true";lJ.useEffect(()=>{if(r!=="running"||!o){if(q&&r!=="running")H(!1);return}H(!0),W("");let R0=`/api/p/${J}/events`,P0=new EventSource(R0);return B.current=P0,console.log("[Streaming] EventSource created for job:",Q),P0.addEventListener("jobOutputChunk",(s)=>{try{let{id:A0,chunk:i}=JSON.parse(s.data);if(A0===Q&&i)W((L0)=>L0+i)}catch(A0){console.error("[Streaming] Error handling jobOutputChunk:",A0)}}),P0.addEventListener("jobCompleted",(s)=>{try{let{id:A0}=JSON.parse(s.data);if(A0===Q)console.log("[Streaming] Job completed, transitioning to persisted output"),H(!1),P0.close(),B.current=null}catch(A0){console.error("[Streaming] Error handling jobCompleted:",A0)}}),P0.addEventListener("jobStatusChanged",(s)=>{try{let{id:A0,newStatus:i}=JSON.parse(s.data);if(A0===Q&&i!=="running")console.log("[Streaming] Job status changed to:",i),H(!1),P0.close(),B.current=null}catch(A0){console.error("[Streaming] Error handling jobStatusChanged:",A0)}}),P0.onerror=(s)=>{console.error("[Streaming] EventSource error:",s)},()=>{console.log("[Streaming] Cleaning up EventSource"),P0.close(),B.current=null}},[J,Q,r,o]);let Y0=()=>{v((R0)=>{let P0={};for(let s of Object.keys(R0))P0[s]={promptOpen:!1,outputOpen:!1};return P0})},e=()=>{v((R0)=>{let P0={};for(let s of Object.keys(R0))P0[s]={promptOpen:!0,outputOpen:!0};return P0})},B0=async()=>{try{await navigator.clipboard.writeText(Q),bZ.success("ID copied")}catch(R0){console.error("Failed to copy ID:",R0)}},Q0=(R0)=>{if(!R0)return"active";if(R0.fields?.status==="running")return"active";if(R0.fields?.completedAt){let P0=new Date(R0.fields?.completedAt).getTime(),s=Date.now()-wB8;if(P0>s)return"active"}return"history"},M0=()=>{let R0=Y||X.state?.fromStory||X.state?.fromTab;if(R0?.startsWith("As")){let A0=Z?`/project/${J}/store/${Z}/stories?expanded=${R0}&tab=jobs`:`/project/${J}/stories?expanded=${R0}&tab=jobs`;K(A0);return}let P0=IB8.includes(R0)?R0:Q0(M),s=Z?`/project/${J}/store/${Z}/jobs/${P0}`:`/project/${J}/jobs/${P0}`;K(s)},[W0,H0]=lJ.useState(null),[U0,K0]=lJ.useState(!1),O0=C16(J,Q),[J0,j0]=lJ.useState(!1),q0=(M?.fields?.status==="completed"||M?.fields?.status==="error")&&M?.fields?.sessionId,v0=async(R0,P0)=>{await O0.mutateAsync({prompt:R0,model:P0}),K0(!1)},[Z0,e0]=lJ.useState(!1),[X0,T0]=lJ.useState(""),[_0,l0]=lJ.useState(null),b0=S16(J),y0=()=>{T0(M.name),l0(null),e0(!0)},p0=async()=>{let R0=X0.trim();if(!R0||R0===M.name){e0(!1),l0(null);return}try{await b0.mutateAsync({id:Q,name:R0}),e0(!1),l0(null)}catch(P0){let s=P0?.message||"Failed to rename job";l0(s)}},m0=(R0)=>{if(R0.key==="Enter")R0.preventDefault(),p0();if(R0.key==="Escape")e0(!1),l0(null)},d0=(R0)=>{if(T0(R0.target.value),_0)l0(null)};if(O)return Q8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:Q8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground",children:[Q8.jsxDEV(c7,{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(A||!M)return Q8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:Q8.jsxDEV("div",{className:"text-center",children:[Q8.jsxDEV(B7,{className:"w-8 h-8 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),Q8.jsxDEV("p",{className:"text-destructive font-medium",children:"Failed to load job"},void 0,!1,void 0,this),Q8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-1",children:A?.message||"Job not found"},void 0,!1,void 0,this),Q8.jsxDEV(g6,{variant:"outline",className:"mt-4",onClick:M0,children:[Q8.jsxDEV(eA,{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 Q8.jsxDEV("div",{className:"h-full flex flex-col p-6 overflow-auto",children:[Q8.jsxDEV("div",{className:"flex items-start gap-4 mb-6",children:[Q8.jsxDEV(g6,{variant:"ghost",size:"sm",onClick:M0,children:Q8.jsxDEV(eA,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q8.jsxDEV("div",{className:"flex-1",children:[Q8.jsxDEV("div",{className:"flex items-center gap-3 mb-2",children:[Z0?Q8.jsxDEV("input",{type:"text",value:X0,onChange:d0,onBlur:p0,onKeyDown:m0,autoFocus:!0,className:"text-xl font-semibold px-2 py-1 border border-input rounded bg-background"},void 0,!1,void 0,this):Q8.jsxDEV(Q8.Fragment,{children:[Q8.jsxDEV("h1",{className:"text-xl font-semibold",children:M.name},void 0,!1,void 0,this),Q8.jsxDEV(s9,{content:"Rename job",children:Q8.jsxDEV(g6,{variant:"ghost",size:"sm",onClick:y0,children:Q8.jsxDEV(N1,{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),Q8.jsxDEV(AB8,{status:M.fields?.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_0&&Q8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center gap-2 text-destructive",children:[Q8.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"text-sm",children:_0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q8.jsxDEV("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Agent:"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"capitalize",children:M.fields?.agent},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.model&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Model:"},void 0,!1,void 0,this),M.fields?.model]},void 0,!0,void 0,this),Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Started:"},void 0,!1,void 0,this),bX6(M.fields?.startedAt)]},void 0,!0,void 0,this),M.fields?.completedAt&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Completed:"},void 0,!1,void 0,this),bX6(M.fields?.completedAt)]},void 0,!0,void 0,this),M.fields?.tokensUsed&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Tokens:"},void 0,!1,void 0,this),NB8(M.fields?.tokensUsed)]},void 0,!0,void 0,this),ak(M.fields?.workingDirectory,U?.path)&&Q8.jsxDEV(s9,{content:M.fields?.workingDirectory,children:Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Location:"},void 0,!1,void 0,this),ak(M.fields?.workingDirectory,U?.path)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.fields?.status==="completed"&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"Session:"},void 0,!1,void 0,this),Q8.jsxDEV("span",{children:M.fields?.sessionId||"-"},void 0,!1,void 0,this),Q8.jsxDEV(jr,{value:M.fields?.sessionId||"",disabled:!M.fields?.sessionId},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.pid&&Q8.jsxDEV("span",{className:"flex items-center gap-1",children:[Q8.jsxDEV("span",{className:"font-medium",children:"PID:"},void 0,!1,void 0,this),Q8.jsxDEV("span",{className:"font-mono",children:M.fields.pid},void 0,!1,void 0,this),Q8.jsxDEV(jr,{value:M.fields.pid},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M.fields?.errorMessage&&Q8.jsxDEV("div",{className:"mt-3 p-3 bg-destructive/10 border border-destructive/30 rounded-md",children:[Q8.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error"},void 0,!1,void 0,this),Q8.jsxDEV("p",{className:"text-sm text-destructive/80 mt-1",children:M.fields?.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q8.jsxDEV("div",{className:"flex items-center gap-2",children:[q0&&Q8.jsxDEV(g6,{variant:"default",size:"sm",onClick:()=>K0(!0),children:[Q8.jsxDEV(MV,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Continue Conversation"]},void 0,!0,void 0,this),Q8.jsxDEV(s9,{content:"Copy job ID",children:Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:B0,children:[Q8.jsxDEV(kZ,{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),M.fields?.pid&&Q8.jsxDEV(s9,{content:"Check process status",children:Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:()=>j0(!0),children:Q8.jsxDEV(AV,{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)]},void 0,!0,void 0,this),S.length>=3&&Q8.jsxDEV("div",{className:"flex gap-2 mb-4",children:[Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:Y0,children:"Collapse All"},void 0,!1,void 0,this),Q8.jsxDEV(g6,{variant:"outline",size:"sm",onClick:e,children:"Expand All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q8.jsxDEV("div",{className:"flex-1 space-y-6",children:q?Q8.jsxDEV(Q8.Fragment,{children:[Q8.jsxDEV(RB8,{content:G,isOpen:_,onToggle:b},void 0,!1,void 0,this),Q8.jsxDEV(nB0,{title:"Prompt",docId:w?.id,isOpen:$[0]?.promptOpen??!0,onToggle:(R0)=>v((P0)=>({...P0,[0]:{...P0[0],promptOpen:R0}})),deepLinkUrl:u,children:Q8.jsxDEV(yY,{markdown:S[0]?.content||"",onInternalLinkClick:k},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):R?Q8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-8",children:[Q8.jsxDEV(c7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading documents..."]},void 0,!0,void 0,this):h?[...Array(Math.max(S.length,f.length))].map((R0,P0,s)=>{let A0=s.length-1-P0,i=S[A0],L0=f[A0],N0=i?.turnNumber??L0?.turnNumber??A0+1,x0=P0===0;return Q8.jsxDEV(hX6,{turnNumber:N0,promptContent:i?.content,outputContent:L0?.content,showHeading:!0,promptDocId:w?.id,outputDocId:P?.id,isPromptOpen:$[A0]?.promptOpen??!0,setIsPromptOpen:($0)=>v((D0)=>({...D0,[A0]:{...D0[A0],promptOpen:$0}})),isOutputOpen:$[A0]?.outputOpen??!0,setIsOutputOpen:($0)=>v((D0)=>({...D0,[A0]:{...D0[A0],outputOpen:$0}})),onInternalLinkClick:k,promptDeepLinkUrl:u,outputDeepLinkUrl:d,sectionRef:x0?m:null,highlightedSection:x0?l:null},A0,!1,void 0,this)}):Q8.jsxDEV(hX6,{turnNumber:1,promptContent:S[0]?.content,outputContent:f[0]?.content,showHeading:!1,promptDocId:w?.id,outputDocId:P?.id,isPromptOpen:$[0]?.promptOpen??!0,setIsPromptOpen:(R0)=>v((P0)=>({...P0,[0]:{...P0[0],promptOpen:R0}})),isOutputOpen:$[0]?.outputOpen??!0,setIsOutputOpen:(R0)=>v((P0)=>({...P0,[0]:{...P0[0],outputOpen:R0}})),onInternalLinkClick:k,promptDeepLinkUrl:u,outputDeepLinkUrl:d,sectionRef:m,highlightedSection:l},void 0,!1,void 0,this)},void 0,!1,void 0,this),Q8.jsxDEV(fX6,{open:U0,onOpenChange:K0,sessionId:M.fields?.sessionId,currentModel:M.fields?.model,onContinue:v0,isLoading:O0.isPending},void 0,!1,void 0,this),Q8.jsxDEV(_X6,{open:J0,onOpenChange:j0,projectId:J,jobId:Q,pid:M.fields?.pid},void 0,!1,void 0,this),Q8.jsxDEV(bP,{open:!!W0,onOpenChange:(R0)=>!R0&&H0(null),projectId:J,documentId:W0?.id,anchor:W0?.anchor,onNavigate:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var xK=f0(D6(),1);var d3=f0(D6(),1);var i3=f0(e6(),1),Tr=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("rounded-lg border border-border bg-card text-card-foreground shadow-sm",J),...Z},void 0,!1,void 0,this));Tr.displayName="Card";var PB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("flex flex-col space-y-1.5 p-6",J),...Z},void 0,!1,void 0,this));PB8.displayName="CardHeader";var DB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("h3",{ref:Q,className:$8("text-2xl font-semibold leading-none tracking-tight",J),...Z},void 0,!1,void 0,this));DB8.displayName="CardTitle";var EB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("p",{ref:Q,className:$8("text-sm text-muted-foreground",J),...Z},void 0,!1,void 0,this));EB8.displayName="CardDescription";var Cr=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("p-6 pt-0",J),...Z},void 0,!1,void 0,this));Cr.displayName="CardContent";var VB8=d3.default.forwardRef(({className:J,...Z},Q)=>i3.jsxDEV("div",{ref:Q,className:$8("flex items-center p-6 pt-0",J),...Z},void 0,!1,void 0,this));VB8.displayName="CardFooter";var Sr="",$r=()=>({"Content-Type":"application/json","X-Session-Id":o4()}),yX6=async(J)=>{let Z=await fetch(`${Sr}/api/p/${J}/export/preview`,{headers:$r()});return P9(Z,"Failed to get export preview")},gX6=async(J)=>{let Z=await fetch(`${Sr}/api/p/${J}/exports`,{headers:$r()});return P9(Z,"Failed to get exports")},mX6=async(J)=>{let Z=await fetch(`${Sr}/api/p/${J}/export`,{method:"POST",headers:$r(),body:JSON.stringify({confirm:!0})});return P9(Z,"Failed to export documents")},uX6=async(J,Z)=>{let Q=await fetch(`${Sr}/api/p/${J}/import`,{method:"POST",headers:$r(),body:JSON.stringify({filename:Z})});return P9(Q,"Failed to import documents")};var d6=f0(e6(),1),pX6=()=>{let{id:J}=EQ(),{data:Z,isLoading:Q}=w1(J),[K,X]=xK.useState(!1),[U,Y]=xK.useState(null),[z,G]=xK.useState(!1),[W,q]=xK.useState(null),[H,B]=xK.useState(!1),[M,O]=xK.useState(null),[A,N]=xK.useState(null),[R,w]=xK.useState(!1),[P,V]=xK.useState(!1),[D,T]=xK.useState(null),[C,S]=xK.useState(null),[f,h]=xK.useState([]),[k,$]=xK.useState("");I1(Z?`${Z.name} - Settings`:"CAW");let v=async(r,o)=>{if(Y(null),!navigator.clipboard?.writeText){Y("Clipboard not available");return}try{await navigator.clipboard.writeText(r),o(!0),setTimeout(()=>o(!1),2000)}catch(Y0){Y("Failed to copy")}},_=()=>{if(!Z?.objectId)return"";return`claude mcp add caw-${Z.objectId.toLowerCase()} https://caw.localhost/mcp/p/${Z.objectId} --transport http`},b=()=>v(_(),X),x=async()=>{O(null),N(null),q(null),B(!0),G(!0);try{let r=await yX6(Z.objectId);q(r)}catch(r){O(r.message)}finally{B(!1)}},m=async()=>{B(!0),O(null);try{let r=await mX6(Z.objectId);N(r)}catch(r){O(r.message)}finally{B(!1)}},g=()=>{G(!1),q(null),N(null),O(null)},u=async()=>{T(null),S(null),h([]),$(""),w(!0),V(!0);try{let r=await gX6(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(!k){T("Please select an export file");return}V(!0),T(null);try{let r=await uX6(Z.objectId,k);S(r)}catch(r){T(r.message)}finally{V(!1)}},l=()=>{w(!1),S(null),T(null)};if(Q)return d6.jsxDEV("div",{className:"p-6",children:d6.jsxDEV("p",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(!Z)return d6.jsxDEV("div",{className:"p-6",children:d6.jsxDEV("p",{className:"text-muted-foreground",children:"Project not found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return d6.jsxDEV("div",{className:"p-6",children:[d6.jsxDEV("h2",{className:"text-2xl font-bold text-foreground mb-6",children:"Project Settings"},void 0,!1,void 0,this),d6.jsxDEV("div",{className:"max-w-2xl space-y-6",children:[d6.jsxDEV(Tr,{children:d6.jsxDEV(Cr,{className:"pt-6 space-y-6",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Project Name"},void 0,!1,void 0,this),d6.jsxDEV("p",{className:"text-foreground mt-1",children:Z.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Path"},void 0,!1,void 0,this),d6.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),d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"Add to Claude Code"},void 0,!1,void 0,this),d6.jsxDEV("div",{className:"flex items-start gap-2 mt-1",children:[d6.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:_()},void 0,!1,void 0,this),d6.jsxDEV(g6,{variant:"outline",size:"icon",onClick:b,className:"shrink-0",children:K?d6.jsxDEV(A1,{className:"w-4 h-4"},void 0,!1,void 0,this):d6.jsxDEV(kZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&d6.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),d6.jsxDEV(Tr,{children:d6.jsxDEV(Cr,{className:"pt-6",children:d6.jsxDEV("div",{className:"flex items-start justify-between",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-muted-foreground",children:"PROJECT STORE (A)"},void 0,!1,void 0,this),d6.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),d6.jsxDEV("div",{className:"flex gap-2",children:[d6.jsxDEV(g6,{onClick:x,size:"sm",children:[d6.jsxDEV(WV,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Export"]},void 0,!0,void 0,this),d6.jsxDEV(g6,{onClick:u,variant:"outline",size:"sm",children:[d6.jsxDEV(yG,{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),d6.jsxDEV(sJ,{open:z,onOpenChange:G,children:d6.jsxDEV(vJ,{children:[d6.jsxDEV(fJ,{children:[d6.jsxDEV(_J,{children:A?"Export Complete":"Export Preview"},void 0,!1,void 0,this),d6.jsxDEV(Wh,{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&&d6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:d6.jsxDEV(c7,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M&&d6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[d6.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),d6.jsxDEV("span",{className:"text-sm",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W?.toExport&&W?.draftOnly&&!A&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("h4",{className:"text-sm font-medium mb-2",children:"Will be exported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[d6.jsxDEV("li",{children:[W.toExport.documents.length," documents"]},void 0,!0,void 0,this),d6.jsxDEV("li",{children:[W.toExport.templates.length," templates"]},void 0,!0,void 0,this),d6.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)&&d6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:d6.jsxDEV("div",{className:"flex items-start gap-2",children:[d6.jsxDEV(B7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),d6.jsxDEV("div",{children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Draft-only items will NOT be exported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[W.draftOnly.documents.length>0&&d6.jsxDEV("li",{children:[W.draftOnly.documents.length," documents",W.draftOnly.documents.length<=3&&d6.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&&d6.jsxDEV("li",{children:[W.draftOnly.templates.length," templates",W.draftOnly.templates.length<=3&&d6.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&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Exported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[d6.jsxDEV("li",{children:[A.counts.documents," documents"]},void 0,!0,void 0,this),d6.jsxDEV("li",{children:[A.counts.templates," templates"]},void 0,!0,void 0,this),d6.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),d6.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Saved to: ",d6.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),d6.jsxDEV(DZ,{children:!A?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(g6,{variant:"outline",onClick:g,children:"Cancel"},void 0,!1,void 0,this),d6.jsxDEV(g6,{onClick:m,disabled:H||!W,children:H?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(c7,{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):d6.jsxDEV(g6,{onClick:g,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),d6.jsxDEV(sJ,{open:R,onOpenChange:w,children:d6.jsxDEV(vJ,{children:[d6.jsxDEV(fJ,{children:[d6.jsxDEV(_J,{children:C?"Import Complete":"Import from .caw-exports/"},void 0,!1,void 0,this),d6.jsxDEV(Wh,{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),D&&d6.jsxDEV("div",{className:"flex items-center gap-2 text-destructive bg-destructive/10 p-3 rounded",children:[d6.jsxDEV(B7,{className:"w-4 h-4"},void 0,!1,void 0,this),d6.jsxDEV("span",{className:"text-sm",children:D},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P&&f.length===0&&!D&&d6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:d6.jsxDEV(c7,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),!C&&!P&&f.length===0&&!D&&d6.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&&f.length>0&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{children:[d6.jsxDEV("label",{className:"text-sm font-medium text-foreground block mb-2",children:"Select export file:"},void 0,!1,void 0,this),d6.jsxDEV(kQ,{value:k,onValueChange:$,children:[d6.jsxDEV(eZ,{children:d6.jsxDEV(vQ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),d6.jsxDEV(JQ,{children:f.map((r)=>d6.jsxDEV(P4,{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),d6.jsxDEV("div",{className:"bg-amber-500/10 border border-amber-500/20 p-3 rounded",children:d6.jsxDEV("div",{className:"flex items-start gap-2",children:[d6.jsxDEV(B7,{className:"w-4 h-4 text-amber-500 mt-0.5"},void 0,!1,void 0,this),d6.jsxDEV("div",{children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-amber-500",children:"Important:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[d6.jsxDEV("li",{children:"The store must be empty before importing"},void 0,!1,void 0,this),d6.jsxDEV("li",{children:"Entity IDs will be remapped to new values"},void 0,!1,void 0,this),d6.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&&d6.jsxDEV("div",{className:"space-y-4",children:[d6.jsxDEV("div",{className:"bg-green-500/10 border border-green-500/20 p-3 rounded",children:[d6.jsxDEV("h4",{className:"text-sm font-medium text-green-500 mb-2",children:"Imported:"},void 0,!1,void 0,this),d6.jsxDEV("ul",{className:"text-sm text-muted-foreground space-y-1",children:[d6.jsxDEV("li",{children:[C.counts.documents," documents"]},void 0,!0,void 0,this),d6.jsxDEV("li",{children:[C.counts.templates," templates"]},void 0,!0,void 0,this),d6.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&&d6.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),d6.jsxDEV(DZ,{children:!C?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(g6,{variant:"outline",onClick:l,children:"Cancel"},void 0,!1,void 0,this),d6.jsxDEV(g6,{onClick:d,disabled:P||!k,children:P?d6.jsxDEV(d6.Fragment,{children:[d6.jsxDEV(c7,{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):d6.jsxDEV(g6,{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 jB8=f0(D6(),1);var EM=f0(e6(),1),kr=()=>{let J=a4(),Z=dJ();return EM.jsxDEV("div",{className:"flex items-center justify-center h-full",children:EM.jsxDEV("div",{className:"text-center max-w-md px-4",children:[EM.jsxDEV(B7,{className:"w-16 h-16 text-muted-foreground/50 mx-auto mb-4"},void 0,!1,void 0,this),EM.jsxDEV("h2",{className:"text-2xl font-semibold text-foreground mb-2",children:"Page Not Found"},void 0,!1,void 0,this),EM.jsxDEV("p",{className:"text-muted-foreground mb-4",children:["The path ",EM.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),EM.jsxDEV(g6,{onClick:()=>Z("/"),children:"Go Home"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)};var AH=f0(e6(),1),cX6=()=>{let{theme:J,toggleTheme:Z}=u_(),Q=J==="dark";return AH.jsxDEV("div",{className:"flex items-center justify-between",children:[AH.jsxDEV("div",{children:[AH.jsxDEV("div",{className:"font-medium text-foreground",children:"Theme"},void 0,!1,void 0,this),AH.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),AH.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:AH.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?AH.jsxDEV(OV,{className:"w-4 h-4 text-foreground"},void 0,!1,void 0,this):AH.jsxDEV(NV,{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 WG=f0(e6(),1),lX6=()=>{return I1("CAW - Preferences"),WG.jsxDEV("div",{className:"flex-1 p-6",children:[WG.jsxDEV("div",{className:"mb-6",children:WG.jsxDEV("div",{className:"flex items-center gap-3",children:[WG.jsxDEV(Wz,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this),WG.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),WG.jsxDEV("div",{className:"max-w-2xl",children:WG.jsxDEV("section",{className:"mb-8",children:[WG.jsxDEV("h2",{className:"text-lg font-medium text-foreground mb-4",children:"Appearance"},void 0,!1,void 0,this),WG.jsxDEV("div",{className:"bg-card border border-border rounded-lg p-4",children:WG.jsxDEV(cX6,{},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 iX6=f0(e6(),1),dX6=(J)=>iX6.jsxDEV(yT0,{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 h9=f0(e6(),1),CB8=()=>{return h9.jsxDEV(Ut,{children:h9.jsxDEV(Rt,{client:NN0,children:[h9.jsxDEV(Qt,{children:h9.jsxDEV(AJ,{element:h9.jsxDEV(SI0,{},void 0,!1,void 0,this),children:[h9.jsxDEV(AJ,{index:!0,element:h9.jsxDEV(fI0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"preferences",element:h9.jsxDEV(lX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"project/:id",element:h9.jsxDEV(vI0,{},void 0,!1,void 0,this),children:[h9.jsxDEV(AJ,{index:!0,element:h9.jsxDEV(N_,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"documents/*",element:h9.jsxDEV(UG0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"templates/*",element:h9.jsxDEV(PB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"stories",element:h9.jsxDEV(lB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs/:tab",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"job/:jobId",element:h9.jsxDEV(sB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"settings",element:h9.jsxDEV(pX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"store/:storeCode",children:[h9.jsxDEV(AJ,{index:!0,element:h9.jsxDEV(N_,{to:"documents",replace:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"documents/*",element:h9.jsxDEV(UG0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"templates/*",element:h9.jsxDEV(PB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"stories",element:h9.jsxDEV(lB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"jobs/:tab",element:h9.jsxDEV(ek,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"job/:jobId",element:h9.jsxDEV(sB0,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(AJ,{path:"*",element:h9.jsxDEV(kr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h9.jsxDEV(AJ,{path:"*",element:h9.jsxDEV(kr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h9.jsxDEV(AJ,{path:"*",element:h9.jsxDEV(kr,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),h9.jsxDEV(dX6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},rX6=CB8;var aB0=f0(e6(),1),aX6=document.getElementById("root");if(!aX6)throw Error("Root element not found");var SB8=sX6.createRoot(aX6);SB8.render(aB0.jsxDEV(nX6.default.StrictMode,{children:aB0.jsxDEV(rX6,{},void 0,!1,void 0,this)},void 0,!1,void 0,this));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kelceyp/caw-server",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "CAW server - REST API, MCP server and core features",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",