@kelceyp/caw-server 1.0.135 → 1.0.136
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +8 -8
- package/dist/public_html/main.js +1 -1
- package/dist/public_html/styles.css +1 -1
- package/package.json +1 -1
package/dist/public_html/main.js
CHANGED
|
@@ -3087,7 +3087,7 @@ ${m9}`}}));await navigator.clipboard.writeText(Z8.join(`
|
|
|
3087
3087
|
`)),v8("Contents copied")}catch(Z8){E6("Failed to copy contents")}},W7=async()=>{if(!await new Promise((m9)=>{d8(!0),o9(()=>m9)}))return;let Q9={succeeded:[],failed:[]},k9=[..._].sort((m9,R7)=>{let C6=N1(m9),vJ=N1(R7);if(C6===vJ)return 0;return C6?1:-1});for(let m9 of k9)try{if(N1(m9))await W8.mutateAsync({id:m9});else await n0.mutateAsync({id:m9});Q9.succeeded.push(m9)}catch(R7){Q9.failed.push({id:m9,error:R7.message})}if(f(Q9.failed.map((m9)=>m9.id)),Q9.failed.length===0)a8.success(`Deleted ${Q9.succeeded.length} items`);else a8.warning(`Deleted ${Q9.succeeded.length} of ${_.length} items. ${Q9.failed.length} failed.`);K8(J)},Z6=async()=>{if(!j)return;f6(!0);try{let Q9=(await cN(Z,{folderId:j,type:Q})).map((k9)=>k9.id);if(Q9.length===0){v8("Folder is empty");return}await navigator.clipboard.writeText(Q9.join(",")),v8(`${Q9.length} ID${Q9.length===1?"":"s"} copied`)}catch(Z8){E6("Failed to copy IDs")}finally{f6(!1)}},l6=async(Z8)=>{if(!VK){c1(null);return}if(!Z8.isFolder){c1(null);return}let Q9=_.includes(VK.id)?_:[VK.id],k9=Z8.storeCode||eZ(Z8.id);for(let R7 of Q9)if(eZ(R7)!==k9){a8.error("Cannot move items: store mismatch detected"),c1(null);return}if(Q9.length===1){let R7=Q9[0],C6=N1(R7);try{if(C6)await x8.mutateAsync({id:R7,parentId:Z8.id});else await c0.mutateAsync({id:R7,parentId:Z8.id});c1(null),K8(J)}catch(vJ){E6(vJ.message),c1(null)}return}let m9={succeeded:[],failed:[]};for(let R7 of Q9)try{if(N1(R7))await $c(Z,R7,Z8.id);else await Dc(Z,R7,{parentId:Z8.id});m9.succeeded.push(R7)}catch(C6){m9.failed.push({id:R7,error:C6.message})}if(f(m9.failed.map((R7)=>R7.id)),m9.failed.length===0)a8.success(`Moved ${m9.succeeded.length} item${m9.succeeded.length>1?"s":""}`);else if(m9.succeeded.length===0)a8.error(`Failed to move ${m9.failed.length} item${m9.failed.length>1?"s":""}`);else a8.warning(`Moved ${m9.succeeded.length} of ${Q9.length} items. ${m9.failed.length} failed.`);c1(null),A.invalidateQueries({queryKey:["folderContents"]}),A.invalidateQueries({queryKey:["documents"]})},aZ=$9.useCallback((Z8,Q9)=>{let k9=Q9.filter((R7)=>R7.isFolder);if(k9.length===0)return!1;let m9=(R7,C6,vJ)=>{if(!R7)return;for(let zZ of R7){if(zZ.id===C6){let mX=(N3)=>{if(!N3)return;for(let oL of N3)if(vJ.add(oL.id),oL.children)mX(oL.children)};mX(zZ.children);return}if(zZ.children)m9(zZ.children,C6,vJ)}};for(let R7 of k9){let C6=new Set;if(m9(C0,R7.id,C6),C6.has(Z8))return!0}return!1},[C0]),kJ=async(Z8)=>{if(!H.hasContent())return;let{items:Q9,operation:k9}=H,m9=Z8.id,R7=Z8.storeCode||eZ(m9);if(!Q9.every((zZ)=>zZ.storeCode===R7)){a8.error("Cannot paste: items are from a different store");return}if(k9==="cut"&&aZ(m9,Q9)){a8.error("Cannot paste: cannot move a folder into its own descendant");return}let vJ={succeeded:[],failed:[]};for(let zZ of Q9)try{if(k9==="cut")if(zZ.isFolder)await x8.mutateAsync({id:zZ.id,parentId:m9});else await c0.mutateAsync({id:zZ.id,parentId:m9});else if(zZ.isFolder)await O.mutateAsync({id:zZ.id,targetParentId:m9});else await B.mutateAsync({id:zZ.id,targetParentId:m9});vJ.succeeded.push(zZ)}catch(mX){vJ.failed.push({item:zZ,error:mX.message})}if(vJ.failed.length===0){let zZ=k9==="cut"?"Moved":"Pasted";if(vJ.succeeded.length===1)a8.success(`${zZ} ${vJ.succeeded[0].name}`);else a8.success(`${zZ} ${vJ.succeeded.length} items`)}else if(vJ.succeeded.length===0){let zZ=k9==="cut"?"move":"paste";a8.error(`Failed to ${zZ} ${vJ.failed.length} item${vJ.failed.length>1?"s":""}`)}else{let zZ=k9==="cut"?"Moved":"Pasted";a8.warning(`${zZ} ${vJ.succeeded.length} of ${Q9.length} items. ${vJ.failed.length} failed.`)}if(k9==="cut")if(vJ.failed.length===0)H.clearClipboard();else H.setClipboard(vJ.failed.map((zZ)=>zZ.item),"cut");K8(J)},_J=$9.useCallback((Z8)=>{let Q9=`${X}?id=${Z8.id}`;window.open(Q9,"_blank")},[X]),QQ=$9.useCallback(async(Z8)=>{try{if(Z8.isFolder){let k9=(await cN(Z,{folderId:Z8.id,type:Q})).map((m9)=>m9.id);if(k9.length===0){a8.info("Folder is empty");return}await navigator.clipboard.writeText(k9.join(",")),a8.success(`${k9.length} ID${k9.length===1?"":"s"} copied`)}else{let Q9=await gz(Z,Z8.id),k9=Q9.draftContent??Q9.resolvedContent??Q9.publishedContent??"";await navigator.clipboard.writeText(k9),a8.success("Content copied")}}catch(Q9){a8.error("Failed to copy content")}},[Z,Q]),mQ=$9.useCallback(async(Z8)=>{try{await navigator.clipboard.writeText(Z8.id),a8.success("ID copied")}catch(Q9){a8.error("Failed to copy ID")}},[]),$Z=$9.useCallback(async(Z8,Q9)=>{let k9=Q9.includes(Z8.id)?Q9:[Z8.id];if(k9.length===1){k(k9[0]),n6(!0);return}f(k9),d8(!0)},[k,n6,f,d8]),iH=$9.useCallback((Z8)=>{if(Z8.type!=="t")return;p4(Z8.id)},[]),A3=$9.useCallback((Z8)=>{if(Z8)F0.current=!0;else requestAnimationFrame(()=>{F0.current=!1})},[]),nL=$9.useCallback((Z8,Q9)=>{K4({id:Z8.id,type:Z8.type,targetSubtype:Q9})},[]),QE=$9.useCallback((Z8)=>{jJ({id:Z8.id,type:Z8.type,subtype:Z8.subtype})},[]),Zz=$9.useCallback(()=>{if(!VY)return;y0.mutate({id:VY.id},{onSuccess:()=>{a8.success("Generalised successfully"),jJ(null)},onError:(Z8)=>{E6(Z8.message),jJ(null)}})},[VY,y0]),rL=$9.useCallback((Z8)=>{if(!CZ)return;let Q9={};for(let[m9,R7]of Object.entries(Z8))if(R7!==""&&R7!==void 0&&R7!==null){if(Array.isArray(R7)&&R7.length===0)continue;Q9[m9]=R7}let k9={id:CZ.id,subtype:CZ.targetSubtype};if(Object.keys(Q9).length>0)k9.fields=Q9;l0.mutate(k9,{onSuccess:()=>{a8.success("Specialised successfully"),K4(null)},onError:(m9)=>{a8.error(m9.message),K4(null)}})},[CZ,l0]),aL=$9.useCallback((Z8)=>{return((k9,m9)=>{let R7=[],C6=new Set(m9),vJ=(zZ)=>{for(let mX of zZ){if(C6.has(mX.id))R7.push(mX);if(mX.children)vJ(mX.children)}};return vJ(k9),R7})(C0,Z8)},[C0]),ZP=()=>F8.jsxDEV("div",{className:"flex-shrink-0 w-10 flex flex-col items-center py-4 bg-card",children:F8.jsxDEV(y9,{content:"Expand tree",children:F8.jsxDEV(q8,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>D(!1),"aria-expanded":"false","aria-label":"Expand tree",children:F8.jsxDEV(PB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),pe=()=>F8.jsxDEV("div",{className:"flex flex-col h-full overflow-hidden",children:[F8.jsxDEV("div",{className:"flex items-center gap-2 mb-4",children:[F8.jsxDEV(y9,{content:`New ${G}`,children:F8.jsxDEV(q8,{size:"sm",variant:"warning",onClick:vW,children:[F8.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),F8.jsxDEV(M,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(y9,{content:"New Folder",children:F8.jsxDEV(q8,{size:"sm",variant:"warning",onClick:DG,children:[F8.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),F8.jsxDEV(mU,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(A4,{children:[F8.jsxDEV(y9,{content:$M0.find((Z8)=>Z8.key===t)?.label,children:F8.jsxDEV(sQ,{asChild:!0,children:F8.jsxDEV(q8,{size:"sm",variant:"outline",children:$9.default.createElement($M0.find((Z8)=>Z8.key===t)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(nQ,{align:"start",children:$M0.map((Z8)=>F8.jsxDEV(z6,{onClick:()=>B0(Z8.key),className:t===Z8.key?"bg-accent":"",children:[F8.jsxDEV(Z8.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),Z8.label]},Z8.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(y9,{content:"Collapse all folders",children:F8.jsxDEV(q8,{size:"sm",variant:"outline",onClick:H8,children:F8.jsxDEV(VB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(y9,{content:"Collapse tree",children:F8.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>D(!0),"aria-expanded":"true","aria-label":"Collapse tree",children:F8.jsxDEV(wB,{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),F8.jsxDEV("div",{ref:K0,className:"flex-1 overflow-auto min-h-0",onClick:(Z8)=>{if(F0.current)return;if(!Z8.target.closest("li"))h()},onDragOver:(Z8)=>{if(VK)Z8.preventDefault()},onDrop:(Z8)=>{if(VK)Z8.preventDefault(),l6({isFolder:!0,path:"",storeCode:E,id:J})},children:C0.length>0?F8.jsxDEV(Cj,{data:C0,initialSelectedItemId:j,onSelectChange:z8,onToggleExpand:e,expandAll:p,expandedFolderIds:u,autoExpandToSelection:!1,defaultLeafIcon:G4,defaultNodeIcon:mU,handleDragStart:R0,handleDrop:l6,draggedItem:VK,renderItem:({item:Z8,isLeaf:Q9,isOpen:k9})=>{let m9=Z8.isFolder&&Z8.isLoading,R7=Z8.isFolder&&Z8.isError,C6=!Z8.isFolder&&(Z8.hasDraft||Z8.id===j&&SU),vJ=y1(Z8.isFolder?"f":Q,Z8.subtype,{hasDraft:C6,isOpen:k9,isLoading:m9}),zZ=W&&_.includes(Z8.id),mX=zZ?_.indexOf(Z8.id)+1:null,N3=`h-4 w-4 shrink-0 ${m9?"animate-spin text-blue-500":""}`,oL=()=>{if(Z8.isFolder&&!m9){if(R7)return{fill:"#fee2e2",stroke:"#dc2626"};return cB[Z8.storeCode]||cB.A}if(!Z8.isFolder&&Z8.subtype==="task"){let EG=xH(Z8.fields?.state,C6);if(EG)return{fill:EG,stroke:"#000000"}}if(!Z8.isFolder&&C6)return{fill:"#fcd34d",stroke:"#000000"};return{}},JP=H.isCut(Z8.id),Gh=aL(_),uX=F8.jsxDEV("div",{className:y8("flex items-center gap-2 min-w-0",zZ&&"text-primary font-medium",JP&&"opacity-50"),children:[F8.jsxDEV(vJ,{className:y8(N3,!Z8.isFolder&&!C6&&"text-muted-foreground"),...oL()},void 0,!1,void 0,this),F8.jsxDEV("span",{className:"text-sm truncate",children:Z8.name},void 0,!1,void 0,this),R7&&F8.jsxDEV(y9,{content:"Failed to load - click to expand and retry",children:F8.jsxDEV("span",{className:"inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono text-red-700 border-red-300 bg-red-50",children:"Failed"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(y9,{content:`${Z8.isFolder?"Folder":G} ID: ${Z8.id}`,children:F8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${O4[Z8.storeCode]||O4.A}`,children:Z8.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),!Z8.isFolder&&Z8.versionCount>0&&F8.jsxDEV(y9,{content:`Published version ${Z8.versionCount}`,children:F8.jsxDEV("span",{className:"inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground border-border/60 bg-muted/40",children:["v",Z8.versionCount]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!Z8.isFolder&&Z8.isBeingEdited&&(Z8.editState?.sessionId===$6()?F8.jsxDEV(y9,{content:`You are editing this ${G.toLowerCase()}`,children:F8.jsxDEV("span",{className:"inline-flex items-center",children:F8.jsxDEV(Q5,{className:"h-3 w-3 text-orange-500"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F8.jsxDEV(y9,{content:`${G} is locked by another session`,children:F8.jsxDEV("span",{className:"inline-flex items-center",children:F8.jsxDEV(uU,{className:"h-3 w-3 text-red-500"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)),zZ&&F8.jsxDEV(y9,{content:`Selected #${mX}`,children:F8.jsxDEV("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full text-[10px] font-bold text-white bg-primary",children:mX},void 0,!1,void 0,this)},void 0,!1,void 0,this),q&&q({item:Z8})]},void 0,!0,void 0,this);return F8.jsxDEV(_q8,{item:Z8,type:Q,collectedIds:_,collectedItems:Gh,disabled:!!VK,onOpenInNewTab:()=>_J(Z8),onCopyContent:()=>QQ(Z8),onCopyId:()=>mQ(Z8),onDelete:()=>$Z(Z8,_),onRender:()=>iH(Z8),onPaste:kJ,onCreateDocument:()=>tw(Z8),onCreateFolder:()=>ew(Z8),subtypes:h0,onSpecialise:nL,onGeneralise:QE,onOpenChange:A3,children:uX},void 0,!1,void 0,this)}},void 0,!1,void 0,this):F8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:["No ",z.toLowerCase()," or folders"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(V0)return F8.jsxDEV("div",{className:"h-full flex p-6",children:$?ZP():F8.jsxDEV("div",{className:"flex-shrink-0 w-80",children:F8.jsxDEV("div",{className:"flex items-center gap-2 mb-4",children:[F8.jsxDEV(G7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),F8.jsxDEV("span",{className:"text-muted-foreground",children:"Loading..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(O0)return F8.jsxDEV("div",{className:"p-6",children:[F8.jsxDEV("div",{className:"flex items-center gap-2 text-destructive mb-4",children:[F8.jsxDEV(w7,{className:"w-5 h-5"},void 0,!1,void 0,this),F8.jsxDEV("span",{children:["Error: ",S0?.message??`Failed to load ${z.toLowerCase()}`]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>K8(J),children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(C0.length===0&&!K9&&!d0)return F8.jsxDEV("div",{className:"p-6",children:F8.jsxDEV("div",{className:"flex items-center justify-center h-96",children:F8.jsxDEV("div",{className:"text-center",children:[F8.jsxDEV(mU,{className:"w-12 h-12 text-muted-foreground/50 mx-auto mb-3"},void 0,!1,void 0,this),F8.jsxDEV("h3",{className:"text-lg font-medium text-foreground mb-1",children:["No ",z]},void 0,!0,void 0,this),F8.jsxDEV("p",{className:"text-sm text-muted-foreground mb-4",children:["Create a ",G.toLowerCase()," or folder to get started."]},void 0,!0,void 0,this),F8.jsxDEV("div",{className:"flex gap-2 justify-center",children:[F8.jsxDEV(q8,{variant:"warning",onClick:vW,children:[F8.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),F8.jsxDEV(M,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(q8,{variant:"warning",onClick:DG,children:[F8.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),F8.jsxDEV(mU,{className:"w-4 h-4"},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,!1,void 0,this);let Uh=()=>F8.jsxDEV(F8.Fragment,{children:[_.length>=1&&F8.jsxDEV(rW8,{projectId:Z,collectedIds:_,type:Q,typeName:G,onClearSelection:()=>f([]),onItemSelect:(Z8)=>k(Z8.id),onCopyIds:P9,onCopyContents:g7,onDelete:W7},void 0,!1,void 0,this),_.length===0&&E0&&m0&&!p0&&F8.jsxDEV("div",{className:"flex-1 flex items-center justify-center",children:F8.jsxDEV("div",{className:"text-center",children:[F8.jsxDEV(G7,{className:"w-8 h-8 text-muted-foreground animate-spin mx-auto mb-3"},void 0,!1,void 0,this),F8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Loading ",G.toLowerCase(),"..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),_.length===0&&E0&&b0&&!m0&&F8.jsxDEV("div",{className:"flex-1 flex items-center justify-center",children:F8.jsxDEV("div",{className:"text-center",children:[F8.jsxDEV(w7,{className:"w-8 h-8 text-muted-foreground mx-auto mb-3"},void 0,!1,void 0,this),F8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:[G," not found or has been deleted"]},void 0,!0,void 0,this),F8.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1",children:["ID: ",j]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),_.length===0&&Z0&&p0&&Y&&F8.jsxDEV("div",{className:"flex-1 flex min-h-0",children:F8.jsxDEV(Y,{projectId:Z,rootFolderId:J,selectedId:j,selectedItem:j0,selectedItemData:p0,versions:G8,draftContent:c8,serverContent:e8,isDirty:SU,hasDraft:JE,isEditMode:b,setEditMode:v,viewingVersion:m8,versionContent:r7,viewingVersionEntityId:_9,showVersions:l8,setShowVersions:J8,showRename:xX,setShowRename:DU,renameFilename:hX,setRenameFilename:EU,actionError:kW,setActionError:E6,saveStatus:IY,handleEditorChange:gX,handleViewVersion:L3,handleBackToEdit:lH,handlePublish:aw,handleDiscardDraft:_W,handleRetry:ow,handleOpenRename:iL,handleRename:sL,handleCopyContent:s8,handleCopyIds:P9,setShowDeleteConfirm:n6,publishMutation:v0,discardMutation:f0,updatePathMutation:c0,debouncedSave:CQ,collectedIds:_,typeName:G,triggerEditMode:H6,setTriggerEditMode:e2},void 0,!1,void 0,this)},void 0,!1,void 0,this),_.length===0&&s0&&j0&&F8.jsxDEV("div",{className:"flex-1 flex min-h-0",children:F8.jsxDEV(nW8,{projectId:Z,folderId:j,folderItem:j0,storeCode:j0.storeCode??E,onItemSelect:(Z8,Q9)=>{if(z8(Z8,Q9),Z8.isFolder)J0(Z8.id)},type:Q,typeName:G,handleOpenRename:iL,handleCopyIds:P9,handleCopyFolderChildren:Z6,setShowDeleteConfirm:n6,showRename:xX,setShowRename:DU,renameFilename:hX,setRenameFilename:EU,handleRename:sL,renameFolderMutation:C8,actionError:kW,setActionError:E6,isCopying:D4},void 0,!1,void 0,this)},void 0,!1,void 0,this),_.length===0&&!j&&C0.length>0&&F8.jsxDEV("div",{className:"flex-1 flex items-center justify-center",children:F8.jsxDEV("div",{className:"text-center text-muted-foreground",children:[F8.jsxDEV(G4,{className:"w-12 h-12 mx-auto mb-3 opacity-30"},void 0,!1,void 0,this),F8.jsxDEV("p",{children:["Select a ",G.toLowerCase()," or folder to view details"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),XE=(Z8)=>{if(!Z8.target.closest('button, a, input, tr, [role="button"]')&&_.length>0)f([])};return F8.jsxDEV("div",{className:`h-full flex ${$?"py-6 pr-6":"p-6"}`,children:[$?F8.jsxDEV(F8.Fragment,{children:[ZP(),F8.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0 pl-1",onClick:XE,children:Uh()},void 0,!1,void 0,this)]},void 0,!0,void 0,this):F8.jsxDEV(q50,{orientation:"horizontal",defaultLayout:C??void 0,onLayoutChanged:T,children:[F8.jsxDEV(H50,{defaultSize:"25%",minSize:fw9,children:pe()},void 0,!1,void 0,this),F8.jsxDEV(B50,{withHandle:!0},void 0,!1,void 0,this),F8.jsxDEV(H50,{defaultSize:"75%",minSize:bw9,children:F8.jsxDEV("div",{className:"flex flex-col h-full pl-1",onClick:XE,children:Uh()},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(D6,{open:s0&&qJ,onOpenChange:(Z8)=>n6(Z8),children:F8.jsxDEV(O6,{children:[F8.jsxDEV(M6,{children:F8.jsxDEV(L6,{className:"flex items-center gap-2 text-destructive",children:[F8.jsxDEV(w7,{className:"w-5 h-5"},void 0,!1,void 0,this),"Delete Folder"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV("div",{className:"py-4",children:[F8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Are you sure you want to delete ",F8.jsxDEV("span",{className:"font-medium text-foreground",children:j0?.name},void 0,!1,void 0,this),"?"]},void 0,!0,void 0,this),F8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-2",children:"This will delete the folder and all its contents. It can be restored later."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(i6,{children:[F8.jsxDEV(q8,{variant:"outline",onClick:()=>n6(!1),children:"Cancel"},void 0,!1,void 0,this),F8.jsxDEV(q8,{variant:"destructive",onClick:dL,disabled:W8.isPending,children:W8.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),F8.jsxDEV(D6,{open:Z0&&qJ,onOpenChange:(Z8)=>n6(Z8),children:F8.jsxDEV(O6,{children:[F8.jsxDEV(M6,{children:F8.jsxDEV(L6,{className:"flex items-center gap-2 text-destructive",children:[F8.jsxDEV(w7,{className:"w-5 h-5"},void 0,!1,void 0,this),"Delete ",G]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV("div",{className:"py-4",children:[F8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["Are you sure you want to delete ",F8.jsxDEV("span",{className:"font-medium text-foreground",children:p0?.path},void 0,!1,void 0,this),"?"]},void 0,!0,void 0,this),F8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-2",children:["This will soft-delete the ",G.toLowerCase(),". It can be restored later."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(i6,{children:[F8.jsxDEV(q8,{variant:"outline",onClick:()=>n6(!1),children:"Cancel"},void 0,!1,void 0,this),F8.jsxDEV(q8,{variant:"destructive",onClick:dL,disabled:n0.isPending,children:n0.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),F8.jsxDEV(D6,{open:v6,onOpenChange:(Z8)=>{if(!Z8&&B9)B9(!1),o9(null);d8(Z8)},children:F8.jsxDEV(O6,{children:[F8.jsxDEV(M6,{children:F8.jsxDEV(L6,{className:"flex items-center gap-2 text-destructive",children:[F8.jsxDEV(w7,{className:"w-5 h-5"},void 0,!1,void 0,this),"Delete ",_.length," Items"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV("div",{className:"py-4",children:[F8.jsxDEV("p",{className:"text-sm text-muted-foreground mb-2",children:"Are you sure you want to delete these items?"},void 0,!1,void 0,this),F8.jsxDEV("ul",{className:"text-sm text-muted-foreground list-disc list-inside max-h-40 overflow-auto",children:_.map((Z8)=>F8.jsxDEV("li",{children:Z8},Z8,!1,void 0,this))},void 0,!1,void 0,this),F8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-2",children:"This will soft-delete all items. They can be restored later."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(i6,{children:[F8.jsxDEV(q8,{variant:"outline",onClick:()=>{B9(!1),o9(null),d8(!1)},children:"Cancel"},void 0,!1,void 0,this),F8.jsxDEV(q8,{variant:"destructive",onClick:()=>{B9(!0),o9(null),d8(!1)},children:"Delete All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(D6,{open:!!VY,onOpenChange:(Z8)=>{if(!Z8)jJ(null)},children:F8.jsxDEV(O6,{children:VY&&F8.jsxDEV(yw9,{projectId:Z,generaliseTarget:VY,onConfirm:Zz,onCancel:()=>jJ(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(D6,{open:!!CZ,onOpenChange:(Z8)=>{if(!Z8)K4(null)},children:F8.jsxDEV(O6,{children:CZ&&F8.jsxDEV(gw9,{projectId:Z,specialiseTarget:CZ,onConfirm:rL,onCancel:()=>K4(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(D6,{open:K9,onOpenChange:(Z8)=>{if(X6(Z8),!Z8)z1(""),$0(""),o0({}),K6(null)},children:F8.jsxDEV(O6,{children:[F8.jsxDEV(M6,{children:F8.jsxDEV(L6,{children:["New ",G]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV("div",{className:"py-4 space-y-4",children:[F8.jsxDEV("p",{className:"text-xs text-muted-foreground",children:["Creating in: ",F8.jsxDEV("span",{className:"font-mono",children:a0?.path?`${a0.path}/`:s0&&j0?.path?`${j0.path}/`:`${E==="B"?"Shared/":""}${Q==="d"?"Documents":"Templates"}/`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV("div",{children:[F8.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Name"},void 0,!1,void 0,this),F8.jsxDEV("input",{type:"text",value:u4,onChange:(Z8)=>z1(Z8.target.value.replace(/\//g,"")),placeholder:Q==="d"?"example.md":"greeting.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:(Z8)=>Z8.key==="Enter"&&$G(),autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h0&&h0.length>0&&F8.jsxDEV("div",{children:[F8.jsxDEV("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Type"},void 0,!1,void 0,this),F8.jsxDEV(IJ,{value:i0||"_base",onValueChange:(Z8)=>{$0(Z8==="_base"?"":Z8)},children:[F8.jsxDEV(BJ,{children:F8.jsxDEV(VJ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV(FJ,{children:h0.map((Z8)=>F8.jsxDEV(BZ,{value:Z8.subtype??"_base",children:Z8.name},Z8.subtype??"_base",!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i0&&F8.jsxDEV(tt,{projectId:Z,typeCode:Q,subtype:i0,parentFolderId:a0?.subtype==="tasks"?a0.id:s0&&j0?.subtype==="tasks"?j:J,fieldValues:A8,onFieldChange:(Z8,Q9)=>o0((k9)=>({...k9,[Z8]:Q9})),onRequiredFieldsChange:r0,onLoadingChange:L0,storeCode:E},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(i6,{children:[F8.jsxDEV(q8,{variant:"outline",onClick:()=>{X6(!1),z1(""),$0(""),o0({}),K6(null)},children:"Cancel"},void 0,!1,void 0,this),F8.jsxDEV(q8,{onClick:$G,disabled:A0.isPending||!u4.trim()||Q8||i0&&g0,children:A0.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),F8.jsxDEV(D6,{open:d0,onOpenChange:(Z8)=>{if(I5(Z8),!Z8)IK(""),K6(null)},children:F8.jsxDEV(O6,{children:[F8.jsxDEV(M6,{children:F8.jsxDEV(L6,{children:"New Folder"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F8.jsxDEV("div",{className:"py-4",children:[(a0?.path||s0&&j0?.path)&&F8.jsxDEV("p",{className:"text-xs text-muted-foreground mb-2",children:["Creating in: ",F8.jsxDEV("span",{className:"font-mono",children:a0?.path?`${a0.path}/`:`${j0.path}/`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV("input",{type:"text",value:bX,onChange:(Z8)=>IK(Z8.target.value.replace(/\//g,"")),placeholder:"my-folder",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:(Z8)=>Z8.key==="Enter"&&dH(),autoFocus:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F8.jsxDEV(i6,{children:[F8.jsxDEV(q8,{variant:"outline",onClick:()=>{I5(!1),IK(""),K6(null)},children:"Cancel"},void 0,!1,void 0,this),F8.jsxDEV(q8,{onClick:dH,disabled:B8.isPending||!bX.trim(),children:B8.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),yX&&F8.jsxDEV(r2,{projectId:Z,templateId:yX,isOpen:!!yX,onClose:()=>p4(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Ke=(Z)=>{return F8.jsxDEV(tW8,{children:F8.jsxDEV(mw9,{...Z},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var PH8=W0(N8(),1),Ye=({type:Z,typeName:J,typeNamePlural:Q,DetailPanel:X,hooks:K,enableCollectionMode:Y=!1,renderTreeItemExtras:U})=>{return()=>{let{id:z,storeCode:W}=YQ();Rq(z);let H=lB(W??"A",Z),O=`${W?`/project/${z}/store/${W}`:`/project/${z}`}/${Z==="d"?"documents":"templates"}`;return PH8.jsxDEV(Ke,{projectId:z,rootFolderId:H,type:Z,urlPrefix:O,DetailPanel:X,hooks:K,typeName:J,typeNamePlural:Q,enableCollectionMode:Y,renderTreeItemExtras:U},void 0,!1,void 0,this)}};var rZ=W0(t0(),1);var H3=W0(t0(),1);var I6=W0(N8(),1),mH=({open:Z,onOpenChange:J,projectId:Q,documentId:X,anchor:K,onNavigate:Y})=>{let{storeCode:U}=YQ(),{data:G,isLoading:z,isError:W,refetch:q}=VW(Q,X),H=G?.name??"",B=G?.draftContent??G?.resolvedContent??G?.publishedContent??"",O=G?.ancestorFolderIds??[],M=G?.subtype,A=X?.startsWith("At"),R=A?null:O.find((J0)=>J0?.startsWith("As"))??null,N=A?null:O.find((J0)=>J0?.startsWith("Aj"))??null,w=!A&&M==="task",{data:P}=bH(Q,w?"d/task":null),[C,T]=H3.useState(null),[$,D]=H3.useState(null),[E,j]=H3.useState(!1),b=A?"Context: Templates":N?"Context: Jobs tab":R?"Context: Stories tab":"Context: Documents tab",_=G?.hasDraft??!1,k=y1(A?"t":"d",M,{hasDraft:_}),v=()=>{if(M==="task"){let J0=G?.fields?.state,t=xH(J0,_);if(t)return{fill:t,stroke:"#000000"}}if(_)return{fill:"#fcd34d",stroke:"#000000"};return{}},f=X?eZ(X):"A",h=U&&U!=="A"?`/store/${U}`:"",x=H3.useRef(null),g=H3.useCallback(()=>{if(K&&x.current)setTimeout(()=>{let J0=x.current.querySelector(`#${CSS.escape(K)}`);if(J0)J0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[K]),m=(J0)=>{J0.stopPropagation();let t;if(A)t=`/project/${Q}${h}/templates?id=${X}`;else if(N)t=`/project/${Q}${h}/job/${N}`;else if(R)t=`/project/${Q}${h}/story/${R}?id=${X}&tab=documents`;else t=`/project/${Q}${h}/documents?id=${X}`;Y(t),J(!1)},u=(J0)=>{J0.stopPropagation();let t=`/project/${Q}${h}/story/${R}?id=${X}&tab=tasks`;Y(t),J(!1)},d=async()=>{try{await navigator.clipboard.writeText(B),a8.success("Contents copied")}catch(J0){console.error("Failed to copy contents:",J0),a8.error("Failed to copy")}},p=async()=>{try{await navigator.clipboard.writeText(X),a8.success("ID copied")}catch(J0){console.error("Failed to copy ID:",J0),a8.error("Failed to copy")}},s=(J0)=>{T(J0.id),D(J0.path),j(!0)},e=async({type:J0,id:t,path:B0,anchor:n})=>{if(J0==="anchor")return;let H0=n?`#${n}`:"";if(J0==="id"){let Q0=t?.charAt(1)?.toLowerCase(),U0;if(Q0==="j")U0=`/project/${Q}${h}/job/${t}${H0}`;else if(Q0==="s")U0=`/project/${Q}${h}/story/${t}${H0}`;else if(Q0==="f")try{let Y0=await u5(Q,t),K0=Y0?.path||"";if(K0.startsWith("Templates/"))U0=`/project/${Q}${h}/templates?id=${t}${H0}`;else if(K0.startsWith("Stories/")){let F0=Y0?.parentId?.startsWith("As")?Y0.parentId:null;if(!F0){let z0=Y0?.parentId?await u5(Q,Y0.parentId):null;while(z0&&!F0)if(z0.parentId?.startsWith("As"))F0=z0.parentId;else if(z0.id?.startsWith("As"))F0=z0.id;else z0=z0.parentId?await u5(Q,z0.parentId):null}if(F0)U0=`/project/${Q}${h}/story/${F0}?id=${t}&tab=documents${H0}`;else U0=`/project/${Q}${h}/stories?id=${t}${H0}`}else U0=`/project/${Q}${h}/documents?id=${t}${H0}`}catch{U0=`/project/${Q}${h}/documents?id=${t}${H0}`}else U0=`/project/${Q}${h}/${Q0==="t"?"templates":"documents"}?id=${t}${H0}`;J(!1),Y(U0)}else if(J0==="path"){let Q0=`/project/${Q}${h}${B0}${H0}`;J(!1),Y(Q0)}};return I6.jsxDEV(D6,{open:Z,onOpenChange:J,children:[I6.jsxDEV(O6,{className:"max-w-6xl max-h-[85vh] flex flex-col",children:[I6.jsxDEV(M6,{className:"flex-shrink-0",children:[I6.jsxDEV("div",{className:"relative flex items-center min-h-[28px]",children:[I6.jsxDEV("span",{className:"text-sm text-muted-foreground",children:b},void 0,!1,void 0,this),I6.jsxDEV(L6,{className:"absolute inset-0 flex items-center gap-2 justify-center pointer-events-none",children:[!z&&I6.jsxDEV(I6.Fragment,{children:[I6.jsxDEV(k,{className:"h-5 w-5 shrink-0",...v()},void 0,!1,void 0,this),I6.jsxDEV("span",{children:H||(A?"Template":"Document")},void 0,!1,void 0,this),I6.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${O4[f]||O4.A}`,children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&"Loading..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I6.jsxDEV("div",{className:"flex flex-wrap gap-2 pt-2",children:[I6.jsxDEV(q8,{variant:"outline",size:"sm",onClick:m,disabled:z,children:[I6.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"View in Context"]},void 0,!0,void 0,this),w&&R&&I6.jsxDEV(q8,{variant:"outline",size:"sm",onClick:u,disabled:z,children:[I6.jsxDEV(s3,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"View on Kanban"]},void 0,!0,void 0,this),I6.jsxDEV(A4,{children:[I6.jsxDEV(sQ,{asChild:!0,children:I6.jsxDEV(q8,{variant:"outline",size:"sm",children:[I6.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",I6.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),I6.jsxDEV(nQ,{align:"start",children:[I6.jsxDEV(z6,{onClick:d,disabled:z||!B,children:[I6.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),I6.jsxDEV(z6,{onClick:p,children:[I6.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy ID"]},void 0,!0,void 0,this),I6.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(H),a8.success("Name copied")}catch(J0){a8.error("Failed to copy")}},children:[I6.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),I6.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(`[${H}](${X})`),a8.success("MD Link copied")}catch(J0){a8.error("Failed to copy")}},children:[I6.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),I6.jsxDEV(z6,{onClick:async()=>{try{let J0;if(A)J0=`/project/${Q}${h}/templates?id=${X}`;else if(N)J0=`/project/${Q}${h}/job/${N}`;else if(R)J0=`/project/${Q}${h}/story/${R}?id=${X}&tab=documents`;else J0=`/project/${Q}${h}/documents?id=${X}`;await navigator.clipboard.writeText(`${window.location.origin}${J0}`),a8.success("URL copied")}catch(J0){a8.error("Failed to copy")}},children:[I6.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),w&&P?.length>0&&P.map((J0)=>I6.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>s(J0),disabled:z,children:[I6.jsxDEV(pU,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),J0.name?.replace(/\.md$/,"")||J0.id]},J0.id,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I6.jsxDEV("div",{ref:x,className:"flex-1 overflow-auto min-h-0 mt-4",children:z?I6.jsxDEV("div",{className:"flex items-center justify-center py-8",children:I6.jsxDEV(G7,{className:"w-6 h-6 animate-spin"},void 0,!1,void 0,this)},void 0,!1,void 0,this):W?I6.jsxDEV("div",{className:"text-center py-8",children:[I6.jsxDEV(w7,{className:"w-6 h-6 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),I6.jsxDEV("p",{className:"text-muted-foreground mb-2",children:"Failed to load document"},void 0,!1,void 0,this),I6.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>q(),children:"Retry"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):B?I6.jsxDEV(MK,{markdown:B,onInternalLinkClick:e,onRenderComplete:g},void 0,!1,void 0,this):I6.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),w&&C&&I6.jsxDEV(r2,{open:E,onOpenChange:j,projectId:Q,templateId:C,templatePath:$,mode:"task",taskId:X,storyId:R,rootFolderId:R},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var $U=W0(t0(),1);var TH8=(Z)=>{if(!Z)return[];let J=/\/api\/p\/[^/]+\/assets\/(Aa\d+)\/binary/g,Q=[],X;while((X=J.exec(Z))!==null)Q.push(X[1]);return[...new Set(Q)]};var u7=W0(N8(),1),pw9=async(Z,J)=>{try{let Q=await Fm0(J,Z);return{id:Z,status:"referenced",asset:Q}}catch(Q){if(Q.code==="ASSET_NOT_FOUND")return{id:Z,status:"broken",asset:null};throw Q}},cw9=(Z,J)=>{let Q=(Z.originalFilename||"image").replace(/"/g,"""),X=`/api/p/${J}/assets/${Z.id}/binary?h=${Z.hash}`;if(Z.displayWidth&&Z.displayHeight)return`<img src="${X}" alt="${Q}" width="${Z.displayWidth}" height="${Z.displayHeight}">`;return``},lw9=(Z)=>{if(!Z)return"-";try{return new Date(Z).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"-"}},Ue=({projectId:Z,documentId:J,content:Q,storeCode:X})=>{let K=s9(),[Y,U]=$U.useState(null),[G,z]=$U.useState([]),[W,q]=$U.useState(!1),[H,B]=$U.useState(!1),[O,M]=$U.useState(null),A=$U.useMemo(()=>TH8(Q),[Q]),{data:R,isLoading:N,error:w}=b6({queryKey:["attachments",Z,...A],queryFn:async()=>{let D=await Promise.allSettled(A.map((b)=>pw9(b,Z))),E=[],j=[];for(let b of D)if(b.status==="fulfilled")E.push(b.value);else j.push(b.reason);if(j.length>0)a8.error(`Failed to fetch ${j.length} asset(s)`);return E},enabled:A.length>0}),P=$U.useCallback(async(D)=>{let E=cw9(D,Z);try{await navigator.clipboard.writeText(E),a8("Reference copied to clipboard")}catch{a8.error("Failed to copy reference")}},[Z]),C=$U.useCallback(async(D)=>{U(D),M(null),q(!0),z([]);try{let E=await Lm0(Z,D,{exclude:J});z(E.references||[])}catch{z([])}finally{q(!1)}},[Z,J]),T=$U.useCallback(async()=>{if(!Y)return;B(!0),M(null);try{await Om0(Z,Y),K.invalidateQueries({queryKey:["attachments",Z]}),U(null),a8("Asset deleted")}catch(D){M(D.message)}finally{B(!1)}},[Y,Z,K]),$=$U.useCallback((D)=>{if(!D&&!H)U(null),z([]),M(null)},[H]);if(A.length===0)return u7.jsxDEV("div",{className:"flex items-center justify-center p-8 text-muted-foreground text-sm",children:"No asset references found in this document."},void 0,!1,void 0,this);if(N)return u7.jsxDEV("div",{className:"flex items-center justify-center p-8",children:[u7.jsxDEV(G7,{className:"w-6 h-6 animate-spin text-muted-foreground"},void 0,!1,void 0,this),u7.jsxDEV("span",{className:"ml-2 text-muted-foreground",children:"Loading assets..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(w)return u7.jsxDEV("div",{className:"p-4 text-destructive",children:[u7.jsxDEV("p",{className:"font-medium",children:"Error loading assets"},void 0,!1,void 0,this),u7.jsxDEV("p",{className:"text-sm mt-1",children:w.message},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return u7.jsxDEV("div",{className:"space-y-2",children:[R?.map((D)=>u7.jsxDEV(dw9,{item:D,projectId:Z,onCopy:P,onDelete:C},D.id,!1,void 0,this)),u7.jsxDEV(D6,{open:!!Y,onOpenChange:$,children:u7.jsxDEV(O6,{children:[u7.jsxDEV(M6,{children:u7.jsxDEV(L6,{className:"flex items-center gap-2 text-destructive",children:[u7.jsxDEV(w7,{className:"w-5 h-5"},void 0,!1,void 0,this),"Delete Asset"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),W?u7.jsxDEV("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u7.jsxDEV(G7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Checking for references in other documents..."]},void 0,!0,void 0,this):u7.jsxDEV(u7.Fragment,{children:[G.length>0&&u7.jsxDEV("div",{className:"rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm",children:[u7.jsxDEV("p",{className:"font-medium text-destructive mb-2",children:["This asset is referenced by ",G.length," other document",G.length===1?"":"s",":"]},void 0,!0,void 0,this),u7.jsxDEV("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground",children:G.map((D)=>u7.jsxDEV("li",{children:[u7.jsxDEV("span",{className:"font-mono text-xs",children:D.id},void 0,!1,void 0,this)," ",D.name||D.path]},D.id,!0,void 0,this))},void 0,!1,void 0,this),u7.jsxDEV("p",{className:"mt-2 text-destructive",children:"Deleting this asset will break references in those documents."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u7.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete asset ",u7.jsxDEV("span",{className:"font-mono",children:Y},void 0,!1,void 0,this),"?",G.length===0&&" This action cannot be undone."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O&&u7.jsxDEV("div",{className:"text-sm text-destructive",children:O},void 0,!1,void 0,this),u7.jsxDEV(i6,{children:[u7.jsxDEV(q8,{variant:"outline",onClick:()=>$(!1),disabled:H,children:"Cancel"},void 0,!1,void 0,this),u7.jsxDEV(q8,{variant:"destructive",onClick:T,disabled:W||H,children:H?"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)},dw9=({item:Z,projectId:J,onCopy:Q,onDelete:X})=>{let{id:K,status:Y,asset:U}=Z,G=Y==="broken",z=!G&&U?`/api/p/${J}/assets/${U.id}/binary?h=${U.hash}`:null,W=U?.originalFilename||"Untitled",q=U?.widthPx&&U?.heightPx?`${U.widthPx} x ${U.heightPx}`:null;return u7.jsxDEV("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-border hover:bg-accent/50 transition-colors",children:[u7.jsxDEV("div",{className:"flex-shrink-0 w-16 h-16 rounded border border-border bg-muted flex items-center justify-center overflow-hidden",children:z?u7.jsxDEV("img",{src:z,alt:W,className:"max-w-full max-h-full object-contain"},void 0,!1,void 0,this):u7.jsxDEV(Jj,{className:"w-6 h-6 text-muted-foreground"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u7.jsxDEV("div",{className:"flex-1 min-w-0 space-y-1",children:[u7.jsxDEV("div",{className:"flex items-center gap-2",children:[u7.jsxDEV("span",{className:"text-sm font-medium truncate",children:W},void 0,!1,void 0,this),u7.jsxDEV("span",{className:O4,children:K},void 0,!1,void 0,this),u7.jsxDEV(iw9,{status:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u7.jsxDEV("div",{className:"flex flex-wrap gap-x-4 gap-y-0.5 text-xs text-muted-foreground",children:[U?.sizeBytes!=null&&u7.jsxDEV("span",{children:bD(U.sizeBytes)},void 0,!1,void 0,this),U?.mimeType&&u7.jsxDEV("span",{children:U.mimeType},void 0,!1,void 0,this),q&&u7.jsxDEV("span",{children:q},void 0,!1,void 0,this),U?.createdAt&&u7.jsxDEV("span",{children:lw9(U.createdAt)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),u7.jsxDEV("div",{className:"flex-shrink-0 flex items-center gap-1",children:[!G&&U&&u7.jsxDEV(q8,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>Q(U),title:"Copy reference",children:u7.jsxDEV(uZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u7.jsxDEV(q8,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>X(K),title:"Delete asset",children:u7.jsxDEV(fJ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},iw9=({status:Z})=>{if(Z==="broken")return u7.jsxDEV("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-destructive/10 text-destructive",children:"Broken"},void 0,!1,void 0,this);return u7.jsxDEV("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-green-500/10 text-green-600 dark:text-green-400",children:"Referenced"},void 0,!1,void 0,this)};var DW=W0(t0(),1);var hL=()=>{let[Z,J]=mS(),{"*":Q}=YQ(),X=Q||null,K=sJ(),Y=DW.useMemo(()=>{return K.hash?.slice(1)||null},[K.hash]),U=Z.get("id")||null,G=Z.get("edit")==="true",z=DW.useMemo(()=>{let T=Z.get("selected");return T?T.split(",").filter(Boolean):[]},[Z]),W=Z.get("tab")||null,q=Z.get("from")||null,H=X?"path":U?"id":null,B=G,O=N1(U),M=G&&U&&!O;DW.useMemo(()=>{let T=!1,$=new URLSearchParams(Z);if(U&&z.length>0)$.delete("selected"),T=!0;if(X&&z.length>0)$.delete("selected"),T=!0;if(G&&!X&&(!U||O))$.delete("edit"),T=!0;if(T)queueMicrotask(()=>{J($,{replace:!0})})},[Z,U,z,G,O,X,J]);let A=DW.useCallback((T,$={})=>{let{history:D="push",preserveEdit:E=!1,edit:j}=$;J((b)=>{let _=b.get("id")||null,k=b.get("edit")==="true";if(T===_&&j===k)return b;let v=new URLSearchParams(b);if(T)v.set("id",T);else v.delete("id");if(j===!0&&T&&!N1(T))v.set("edit","true");else if(!E||!T||N1(T))v.delete("edit");return v.delete("selected"),v},{replace:D==="replace"})},[J]),R=DW.useCallback((T,$={})=>{let{history:D="replace"}=$;if(T===G)return;if(T&&!X&&(!U||O))return;J((E)=>{let j=new URLSearchParams(E);if(T)j.set("edit","true");else j.delete("edit");return j},{replace:D==="replace"})},[J,G,U,O,X]),N=DW.useCallback((T,$={})=>{let{history:D="replace"}=$;J((E)=>{let j=new URLSearchParams(E);if(T.length>0){let b=T.slice(0,20);j.set("selected",b.join(",")),j.delete("id"),j.delete("edit")}else j.delete("selected");return j},{replace:D==="replace"})},[J]),w=DW.useCallback((T={})=>{let{history:$="replace"}=T;J((D)=>{let E=new URLSearchParams(D);return E.delete("id"),E.delete("edit"),E.delete("selected"),E},{replace:$==="replace"})},[J]),P=DW.useCallback((T,$={})=>{let{history:D="replace"}=$;J((E)=>{let j=new URLSearchParams(E);if(T)j.set("tab",T);else j.delete("tab");return j},{replace:D==="replace"})},[J]),C=DW.useCallback((T,$={})=>{let{history:D="replace"}=$;J((E)=>{let j=new URLSearchParams(E);if(T)j.set("from",T);else j.delete("from");return j},{replace:D==="replace"})},[J]);return{selectedId:U,isEditMode:M,collectedIds:z,documentPath:X,addressingScheme:H,isEditRequested:B,anchorFragment:Y,activeTab:W,fromContext:q,setSelectedId:A,setEditMode:R,setCollectedIds:N,clearSelection:w,setActiveTab:P,setFromContext:C}};var xw=(Z,J,Q)=>{let X=Z.startsWith("At"),K=Z.startsWith("Ad"),Y=Z.startsWith("As"),U=Z.startsWith("Aj");if(!X&&!K&&!Y&&!U)return null;let G=J.match(/\/project\/([^/]+)(?:\/store\/([^/]+))?/);if(!G)return null;let[,z,W]=G,q=W?`/project/${z}/store/${W}`:`/project/${z}`;if(Y)return{url:`${q}/story/${Z}`,isCrossTab:!0};if(U)return{url:`${q}/job/${Z}`,isCrossTab:!0};let H=X?"templates":"documents",B=Q?`#${Q}`:"",O=J.includes("/templates")?"templates":"documents",M=H!==O;return{url:`${q}/${H}?id=${Z}${B}`,isCrossTab:M}};var L9=W0(N8(),1),Ge=({projectId:Z,rootFolderId:J,selectedId:Q,selectedItemData:X,versions:K,draftContent:Y,serverContent:U,isDirty:G,hasDraft:z,isEditMode:W,setEditMode:q,viewingVersion:H,versionContent:B,viewingVersionEntityId:O,showVersions:M,setShowVersions:A,showRename:R,setShowRename:N,renameFilename:w,setRenameFilename:P,actionError:C,setActionError:T,saveStatus:$,handleEditorChange:D,handleViewVersion:E,handleBackToEdit:j,handlePublish:b,handleDiscardDraft:_,handleRetry:k,handleOpenRename:v,handleRename:f,handleCopyContent:h,handleCopyIds:x,setShowDeleteConfirm:g,publishMutation:m,discardMutation:u,updatePathMutation:d,debouncedSave:p,collectedIds:s,typeName:e,triggerEditMode:J0,setTriggerEditMode:t})=>{let B0=s9(),{setSelectedId:n,documentPath:H0,anchorFragment:Q0}=hL(),U0=PZ(),Y0=sJ(),K0=J?.startsWith("As")?J:null,F0=async({type:y0,id:i0,path:$0,anchor:A8})=>{if(y0==="anchor"){U0(`${Y0.pathname}${Y0.search}#${A8}`,{replace:!0});return}let o0=A8?`#${A8}`:"";if(y0==="id"){let g0=i0?.charAt(1)?.toLowerCase();if(g0==="t"){let Q8=xw(i0,Y0.pathname,A8);if(Q8){U0(Q8.url);return}V0({id:i0,anchor:A8||null});return}if(g0==="d")try{let Q8=await gz(Z,i0),L0=Q8?.ancestorFolderIds?.find((e0)=>e0?.startsWith("As")),h0=Q8?.ancestorFolderIds?.some((e0)=>e0?.startsWith("Aj"));if(K0)if(L0===K0);else{V0({id:i0,anchor:A8||null});return}else if(L0||h0){V0({id:i0,anchor:A8||null});return}}catch{}let r0=Y0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?)/)?.[1];if(g0==="s"){U0(`${r0}/story/${i0}${o0}`);return}if(g0==="j"){U0(`${r0}/job/${i0}${o0}`);return}if(g0==="f"){try{let Q8=await u5(Z,i0),L0=Q8?.path||"";if(L0.startsWith("Templates/"))U0(`${r0}/templates?id=${i0}${o0}`);else if(L0.startsWith("Stories/")){let h0=Q8?.parentId?.startsWith("As")?Q8.parentId:null;if(!h0){let e0=Q8?.parentId?await u5(Z,Q8.parentId):null;while(e0&&!h0)if(e0.parentId?.startsWith("As"))h0=e0.parentId;else if(e0.id?.startsWith("As"))h0=e0.id;else e0=e0.parentId?await u5(Z,e0.parentId):null}if(h0)U0(`${r0}/story/${h0}?id=${i0}&tab=documents${o0}`);else U0(`${r0}/stories?id=${i0}${o0}`)}else U0(`${r0}/documents?id=${i0}${o0}`)}catch{U0(`${r0}/documents?id=${i0}${o0}`)}return}if(H0){let Q8=Y0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?\/(?:documents|templates))/)?.[1];if(Q8){U0(`${Q8}?id=${i0}${o0}`);return}}if(A8)U0(`${Y0.pathname}?id=${i0}${o0}`);else n(i0)}else if(y0==="path")U0(`/project/${Z}${$0}${o0}`)},[z0,V0]=rZ.useState(null),[O0,S0]=rZ.useState("view"),X0=rZ.useRef("view"),[K8,C0]=rZ.useState({}),[H8,L8]=rZ.useState({}),{data:s0}=aY(Z,Q),E0=oY(Z),p0=rZ.useMemo(()=>{let y0=new Set;for(let i0 of Object.keys(H8)){let $0=K8[i0]??"",A8=H8[i0]??"";if(Array.isArray($0)&&Array.isArray(A8)){if(JSON.stringify($0)!==JSON.stringify(A8))y0.add(i0)}else if($0!==A8)y0.add(i0)}return y0},[K8,H8]);rZ.useEffect(()=>{if(s0)C0(s0),L8(s0)},[s0]);let m0=rZ.useCallback((y0,i0)=>{L8(($0)=>({...$0,[y0]:i0}))},[]),b0=rZ.useCallback(async()=>{let y0=Object.entries(H8).filter(([$0,A8])=>{let o0=K8[$0]??"";if(Array.isArray(o0)&&Array.isArray(A8))return JSON.stringify(o0)!==JSON.stringify(A8);return o0!==A8}),i0={};for(let[$0,A8]of y0)try{if(Array.isArray(A8))await E0.mutateAsync({entityId:Q,fieldName:$0,values:A8});else await E0.mutateAsync({entityId:Q,fieldName:$0,value:A8});i0[$0]=A8}catch(o0){a8.error(`Failed to save ${$0}: ${o0.message}`)}if(Object.keys(i0).length>0)C0(($0)=>({...$0,...i0}));if(Object.keys(i0).length===y0.length)a8.success("Fields saved")},[H8,K8,Q,E0]),G8=rZ.useCallback(()=>{L8({...K8})},[K8]);rZ.useEffect(()=>{S0("view"),X0.current="view"},[Q]);let D0=rZ.useCallback((y0)=>{if(y0==="edit"&&H){S0("view");return}if(y0==="edit"&&O0!=="edit")X0.current=O0;if(S0(y0),y0==="edit")q(!0);else if(O0==="edit")q(!1)},[O0,H,q]),[j0,Z0]=rZ.useState(null),T0=j0===Q,[i,N0]=rZ.useState(!1),A0=rZ.useRef(Q),x0=rZ.useRef(!1),v0=rZ.useRef(!1),f0=rZ.useRef(null),n0=J?eZ(J):"A";gH(Z,"documents","detail",f0,!!X,n0,J),rZ.useEffect(()=>{if(Q0&&f0.current)setTimeout(()=>{let y0=f0.current.querySelector(`#${CSS.escape(Q0)}`);if(y0)y0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[Q0]);let c0=rZ.useCallback(()=>{if(Q0&&f0.current)setTimeout(()=>{let y0=f0.current.querySelector(`#${CSS.escape(Q0)}`);if(y0)y0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[Q0]),B8=W&&T0,C8=rZ.useMemo(()=>{if(!X||!X.editState)return!1;let y0=$6();return X.editState.sessionId!==y0},[X]);rZ.useEffect(()=>{console.log("[LOCK EFFECT] Running:",{isEditMode:W,selectedId:Q,lockAcquired:T0});let y0=A0.current;if(A0.current=Q,j0&&y0&&y0!==Q&&j0===y0)console.log("[LOCK EFFECT] Releasing lock on previous doc:",y0),dO(Z,y0).then(()=>{B0.invalidateQueries({queryKey:["folderContents"]}),B0.invalidateQueries({queryKey:["document",y0]})}).catch((i0)=>{console.error("Failed to clear edit state on selection change:",i0)}),Z0(null);if(W&&Q&&j0!==Q)console.log("[LOCK EFFECT] Acquiring lock for:",Q),Ec(Z,Q).then((i0)=>{if(i0.success)console.log("[LOCK EFFECT] Lock acquired, setting activeTab to edit"),Z0(Q),S0("edit"),B0.invalidateQueries({queryKey:["folderContents"]}),B0.invalidateQueries({queryKey:["document",Q]});else{console.log("[LOCK EFFECT] Lock failed");let $0=X0.current||"view";S0($0),q(!1),T(`Document is currently being edited. Try again in ${Math.ceil(i0.meta?.timeoutSeconds/60)} minutes.`)}}).catch((i0)=>{console.log("[LOCK EFFECT] Lock error:",i0);let $0=X0.current||"view";S0($0),q(!1),T(i0.message)});if(!W&&T0&&Q)console.log("[LOCK EFFECT] Releasing lock (edit mode false):",Q),dO(Z,Q).then(()=>{B0.invalidateQueries({queryKey:["folderContents"]}),B0.invalidateQueries({queryKey:["document",Q]})}).catch((i0)=>{console.error("Failed to clear edit state:",i0)}),Z0(null)},[W,Q,j0,T0,Z,q,T,B0]),rZ.useEffect(()=>{if(!X||!Q)return;let y0=X.editState,i0=$6();if(y0&&y0.sessionId===i0){let $0=new Date(y0.lastActivityAt),A8=new Date(Date.now()-3600000);if($0>=A8){if(Z0(Q),!W)q(!0)}}else if(j0===Q&&y0&&y0.sessionId!==i0){if(Z0(null),W)N0(!0),q(!1)}},[X,Q]),rZ.useEffect(()=>{if(H)S0("view")},[H]),rZ.useEffect(()=>{if(J0)S0("edit"),X0.current="view",t(!1)},[J0,t]),rZ.useEffect(()=>{console.log("[BUTTON] Visibility check:",{viewingVersion:H,isDirty:G,hasDraft:z,saveStatus:$,visible:!H&&(G||z||$==="saving")})},[H,G,z,$]),rZ.useEffect(()=>{return()=>{if(j0&&Z)dO(Z,j0).catch((y0)=>{console.error("Failed to clear edit state on unmount:",y0)})}},[j0,Z]);let x8=async()=>{console.log("[BUTTON] Publish button clicked"),await b(),S0("view")},W8=async()=>{if(s&&s.length>0)try{let y0=await Promise.all(s.map(async(i0)=>{let A8=await(await fetch(`/api/p/${Z}/documents/${i0}`,{headers:{"Content-Type":"application/json"}})).json(),o0=A8.draftContent??A8.publishedContent??"";return`=== [${i0}] - ${A8.path||i0} ===
|
|
3088
3088
|
${o0}`}));await navigator.clipboard.writeText(y0.join(`
|
|
3089
3089
|
|
|
3090
|
-
`)),a8.success("Contents copied")}catch(y0){T("Failed to copy contents")}else h()},l0=G||z?Y:X.resolvedContent||X.publishedContent;return L9.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0",children:[i&&L9.jsxDEV("div",{className:"mb-3 p-4 border border-red-300 rounded-md bg-red-50",children:L9.jsxDEV("div",{className:"flex items-start gap-3",children:[L9.jsxDEV(w7,{className:"w-5 h-5 text-red-600 shrink-0 mt-0.5"},void 0,!1,void 0,this),L9.jsxDEV("div",{className:"flex-1",children:[L9.jsxDEV("p",{className:"text-sm font-medium text-red-800 mb-2",children:"Your edit session has expired"},void 0,!1,void 0,this),L9.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),L9.jsxDEV("div",{className:"flex gap-2",children:[L9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(Y),a8.success("Copied to clipboard"),T(null)},children:[L9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy My Changes"]},void 0,!0,void 0,this),L9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{N0(!1),Z0(null),q(!1),window.location.reload()},children:[L9.jsxDEV(cU,{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),C&&L9.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center justify-between",children:[L9.jsxDEV("div",{className:"flex items-center gap-2 text-destructive",children:[L9.jsxDEV(w7,{className:"w-4 h-4"},void 0,!1,void 0,this),L9.jsxDEV("span",{className:"text-sm",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(q8,{variant:"ghost",size:"icon",onClick:()=>T(null),className:"h-6 w-6",children:L9.jsxDEV(pZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(vz,{value:O0,onValueChange:D0,variant:"segment",className:"flex-1 flex flex-col min-h-0",children:[L9.jsxDEV("div",{className:"flex items-center justify-between gap-4 mb-2",children:[L9.jsxDEV("div",{className:"flex items-center gap-2",children:[L9.jsxDEV(fz,{children:[L9.jsxDEV(F4,{value:"view",children:"View"},void 0,!1,void 0,this),L9.jsxDEV(F4,{value:"edit",disabled:!!H||C8,children:C8?L9.jsxDEV(L9.Fragment,{children:[L9.jsxDEV(uU,{className:"w-4 h-4"},void 0,!1,void 0,this),"Edit"]},void 0,!0,void 0,this):"Edit"},void 0,!1,void 0,this),L9.jsxDEV(F4,{value:"fields",children:"Fields"},void 0,!1,void 0,this),L9.jsxDEV(F4,{value:"attachments",children:"Assets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(A4,{children:[L9.jsxDEV(sQ,{asChild:!0,children:L9.jsxDEV(q8,{variant:"outline",size:"sm",children:[L9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",L9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(nQ,{align:"start",children:[L9.jsxDEV(z6,{onClick:W8,children:[L9.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:x,children:[L9.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy IDs"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:async()=>{try{let y0=wY(X?.path);await navigator.clipboard.writeText(y0),a8.success("Name copied")}catch(y0){a8.error("Failed to copy")}},children:[L9.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:async()=>{try{let y0=wY(X?.path);await navigator.clipboard.writeText(`[${y0}](${Q})`),a8.success("MD Link copied")}catch(y0){a8.error("Failed to copy")}},children:[L9.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:async()=>{try{let y0=Q?eZ(Q):"A",i0=y0&&y0!=="A"?`/store/${y0}`:"",$0=`${window.location.origin}/project/${Z}${i0}/documents?id=${Q}`;await navigator.clipboard.writeText($0),a8.success("URL copied")}catch(y0){a8.error("Failed to copy")}},children:[L9.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O0==="view"&&K.length>1&&L9.jsxDEV(A4,{children:[L9.jsxDEV(sQ,{asChild:!0,children:L9.jsxDEV(q8,{variant:"outline",size:"sm",children:[L9.jsxDEV(gG,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Versions",L9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(nQ,{align:"start",children:K.slice().reverse().map((y0)=>{let i0=y0.versionNumber===X.versionCount,$0=y1("d",X?.subtype);return L9.jsxDEV(z6,{onClick:()=>i0?j():E(y0.versionNumber),children:[L9.jsxDEV($0,{className:"w-4 h-4 mr-2 text-muted-foreground"},void 0,!1,void 0,this),i0?"Latest":new Date(y0.publishedAt).toLocaleDateString(),L9.jsxDEV("span",{className:"ml-auto text-muted-foreground",children:["v",y0.versionNumber]},void 0,!0,void 0,this)]},y0.versionNumber,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H&&L9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:j,children:[L9.jsxDEV(cU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Back to latest"]},void 0,!0,void 0,this),!H&&O0==="edit"&&(G||z||$==="saving")&&L9.jsxDEV(q8,{onMouseDown:()=>{x0.current=!0},onClick:x8,disabled:m.isPending,variant:"outline",size:"sm",children:[L9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),m.isPending?"Publishing...":"Publish"]},void 0,!0,void 0,this),!H&&O0==="edit"&&(G||z)&&L9.jsxDEV(q8,{onMouseDown:()=>{v0.current=!0},onClick:_,disabled:u.isPending,variant:"outline",size:"sm",children:[L9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),u.isPending?"Discarding...":"Discard"]},void 0,!0,void 0,this),O0==="fields"&&p0.size>0&&L9.jsxDEV(q8,{onClick:b0,disabled:E0.isPending,variant:"default",size:"sm",children:[L9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),E0.isPending?"Saving...":"Save Fields"]},void 0,!0,void 0,this),O0==="fields"&&p0.size>0&&L9.jsxDEV(q8,{onClick:G8,variant:"outline",size:"sm",children:[L9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Discard"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV("div",{className:"flex items-center gap-2",children:[L9.jsxDEV("div",{className:"flex flex-col mr-2",children:[L9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[(()=>{let y0=z||G,i0=y1("d",X?.subtype,{hasDraft:y0}),$0=()=>{if(X?.subtype==="task"){let A8=xH(X?.fields?.state,y0);if(A8)return{fill:A8,stroke:"#000000"}}if(y0)return{fill:"#fcd34d",stroke:"#000000"};return{}};return L9.jsxDEV(i0,{className:`h-4 w-4 shrink-0 ${!y0&&X?.subtype!=="task"?"text-muted-foreground":""}`,...$0()},void 0,!1,void 0,this)})(),L9.jsxDEV("span",{className:"text-sm font-medium truncate max-w-[200px]",children:wY(X?.path)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[L9.jsxDEV(y9,{content:`Document ID: ${Q}`,children:L9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${O4[X?.storeCode]||O4.A}`,children:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),(X?.versionCount??0)>0&&L9.jsxDEV(y9,{content:H?`Viewing version ${H}`:`Published version ${X.versionCount}`,children:L9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${H?"text-red-600 border-red-300 bg-red-50":"text-muted-foreground border-border/60 bg-muted/40"}`,children:["v",H||X.versionCount]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(q8,{onClick:()=>g(!0),variant:"destructive",size:"sm",children:[L9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(GQ,{value:"view",className:"flex-1 min-h-0",children:H?L9.jsxDEV("div",{ref:f0,className:"h-full p-4 border border-border rounded-md bg-muted overflow-auto",children:[L9.jsxDEV("div",{className:"text-xs text-muted-foreground mb-3",children:["Viewing version ",H," (read-only)"]},void 0,!0,void 0,this),L9.jsxDEV(MK,{markdown:B??"",onInternalLinkClick:F0,onRenderComplete:c0},void 0,!1,void 0,this)]},void 0,!0,void 0,this):L9.jsxDEV("div",{ref:f0,className:"h-full p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:l0?L9.jsxDEV(MK,{markdown:l0,onInternalLinkClick:F0,onRenderComplete:c0},void 0,!1,void 0,this):L9.jsxDEV("p",{className:"text-muted-foreground italic",children:"No content yet. Select Edit tab to start."},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(GQ,{value:"edit",className:"flex-1 min-h-0 flex flex-col",children:[L9.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:B8&&!H&&L9.jsxDEV(yx,{status:$,onRetry:k},void 0,!1,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV("div",{className:"flex-1 min-h-0",children:L9.jsxDEV(eN,{value:Y,onChange:D,onBlur:()=>{if(x0.current){console.log("[BLUR] Skipping flush - publish pending"),x0.current=!1;return}if(v0.current){console.log("[BLUR] Skipping flush - discard pending"),v0.current=!1;return}console.log("[BLUR] Monaco blur - calling flush"),p.flush()},path:X.path,height:"100%",projectId:Z,storeCode:Q?Q[0]:"A"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(GQ,{value:"fields",className:"flex-1 min-h-0 overflow-auto p-4",children:H?L9.jsxDEV(n2,{projectId:Z,entityId:O,entityType:"v",entitySubtype:null,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this):L9.jsxDEV(n2,{projectId:Z,entityId:Q,entityType:"d",entitySubtype:X?.subtype,entityPath:X?.path,onFieldChange:m0,fieldValues:H8,dirtyFieldNames:p0,originalFieldValues:K8,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(GQ,{value:"attachments",className:"flex-1 min-h-0 overflow-auto p-4",children:L9.jsxDEV(Ue,{projectId:Z,documentId:Q,content:H?B:l0,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(mH,{open:!!z0,onOpenChange:(y0)=>!y0&&V0(null),projectId:Z,documentId:z0?.id,anchor:z0?.anchor,onNavigate:U0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var SM0=Ye({type:"d",typeName:"Document",typeNamePlural:"Documents",DetailPanel:Ge,hooks:{useItem:VW,useCreate:jw,useSaveDraft:SD,usePublish:jD,useDiscard:kD,useVersions:_L,useDelete:_D,useUpdatePath:vD,getVersion:xI},enableCollectionMode:!0});var yZ=W0(t0(),1);var J9=W0(N8(),1),IH8=(Z)=>{if(!Z)return"";let J=Z.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);if(J)return Z.slice(J[0].length);return Z},VH8=({projectId:Z,rootFolderId:J,selectedId:Q,selectedItemData:X,versions:K,draftContent:Y,isDirty:U,hasDraft:G,isEditMode:z,setEditMode:W,viewingVersion:q,versionContent:H,showVersions:B,setShowVersions:O,showRename:M,setShowRename:A,renameFilename:R,setRenameFilename:N,actionError:w,setActionError:P,saveStatus:C,handleEditorChange:T,handleViewVersion:$,handleBackToEdit:D,handlePublish:E,handleDiscardDraft:j,handleRetry:b,handleOpenRename:_,handleRename:k,handleCopyContent:v,handleCopyIds:f,setShowDeleteConfirm:h,publishMutation:x,discardMutation:g,updatePathMutation:m,debouncedSave:u,typeName:d,triggerEditMode:p,setTriggerEditMode:s})=>{let e=s9(),{setSelectedId:J0,documentPath:t,anchorFragment:B0}=hL(),n=PZ(),H0=sJ(),Q0=async({type:l0,id:y0,path:i0,anchor:$0})=>{if(l0==="anchor"){n(`${H0.pathname}${H0.search}#${$0}`,{replace:!0});return}if(l0==="id"){if(y0?.charAt(1)?.toLowerCase()==="d"){let g0=xw(y0,H0.pathname,$0);if(g0){n(g0.url);return}Y0({id:y0,anchor:$0||null});return}}let A8=$0?`#${$0}`:"";if(l0==="id"){let o0=y0?.charAt(1)?.toLowerCase(),g0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?)/)?.[1];if(o0==="s"){n(`${g0}/story/${y0}${A8}`);return}if(o0==="j"){n(`${g0}/job/${y0}${A8}`);return}if(o0==="f"){try{let r0=await u5(Z,y0),Q8=r0?.path||"";if(Q8.startsWith("Templates/"))n(`${g0}/templates?id=${y0}${A8}`);else if(Q8.startsWith("Stories/")){let L0=r0?.parentId?.startsWith("As")?r0.parentId:null;if(!L0){let h0=r0?.parentId?await u5(Z,r0.parentId):null;while(h0&&!L0)if(h0.parentId?.startsWith("As"))L0=h0.parentId;else if(h0.id?.startsWith("As"))L0=h0.id;else h0=h0.parentId?await u5(Z,h0.parentId):null}if(L0)n(`${g0}/story/${L0}?id=${y0}&tab=documents${A8}`);else n(`${g0}/stories?id=${y0}${A8}`)}else n(`${g0}/documents?id=${y0}${A8}`)}catch{n(`${g0}/documents?id=${y0}${A8}`)}return}if(t){let r0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?\/(?:documents|templates))/)?.[1];if(r0){n(`${r0}?id=${y0}${A8}`);return}}if($0)n(`${H0.pathname}?id=${y0}${A8}`);else J0(y0)}else if(l0==="path")n(`/project/${Z}${i0}${A8}`)},[U0,Y0]=yZ.useState(null),[K0,F0]=yZ.useState(null),z0=K0===Q,[V0,O0]=yZ.useState(!1),S0=yZ.useRef(Q),X0=yZ.useRef(!1),K8=yZ.useRef(!1),C0=yZ.useRef(null),H8=J?eZ(J):"A";gH(Z,"templates","detail",C0,!!X,H8,J),yZ.useEffect(()=>{if(B0&&C0.current)setTimeout(()=>{let l0=C0.current.querySelector(`#${CSS.escape(B0)}`);if(l0)l0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[B0]);let L8=yZ.useCallback(()=>{if(B0&&C0.current)setTimeout(()=>{let l0=C0.current.querySelector(`#${CSS.escape(B0)}`);if(l0)l0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[B0]),s0=z&&z0,E0=yZ.useMemo(()=>{if(!X||!X.editState)return!1;let l0=$6();return X.editState.sessionId!==l0},[X]);yZ.useEffect(()=>{let l0=S0.current;if(S0.current=Q,z0&&l0&&l0!==Q)dO(Z,l0).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",l0]})}).catch((y0)=>{console.error("Failed to clear edit state on selection change:",y0)}),F0(null);if(z&&Q&&!z0)Ec(Z,Q).then((y0)=>{if(y0.success)F0(Q),G8("edit"),e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]});else{let i0=D0.current||"view";G8(i0),W(!1),P(`Template is currently being edited. Try again in ${Math.ceil(y0.meta?.timeoutSeconds/60)} minutes.`)}}).catch((y0)=>{let i0=D0.current||"view";G8(i0),W(!1),P(y0.message)});if(!z&&z0&&Q)dO(Z,Q).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]})}).catch((y0)=>{console.error("Failed to clear edit state:",y0)}),F0(null)},[z,Q,z0,Z,W,P,e]),yZ.useEffect(()=>{if(!X||!Q)return;let l0=X.editState,y0=$6();if(l0&&l0.sessionId===y0){let i0=new Date(l0.lastActivityAt),$0=new Date(Date.now()-3600000);if(i0>=$0){if(F0(Q),!z)W(!0)}}else if(K0===Q&&l0&&l0.sessionId!==y0){if(F0(null),z)O0(!0),W(!1)}},[X,Q]),yZ.useEffect(()=>{if(p)G8("edit"),D0.current="view",s(!1)},[p,s]),yZ.useEffect(()=>{return()=>{if(K0&&Z)dO(Z,K0).catch((l0)=>{console.error("Failed to clear edit state on unmount:",l0)})}},[K0,Z]);let[p0,m0]=yZ.useState(!1),[b0,G8]=yZ.useState("view"),D0=yZ.useRef("view"),[j0,Z0]=yZ.useState({}),[T0,i]=yZ.useState({}),{data:N0}=aY(Z,Q),A0=oY(Z),x0=yZ.useMemo(()=>{let l0=new Set;for(let y0 of Object.keys(T0)){let i0=j0[y0]??"",$0=T0[y0]??"";if(Array.isArray(i0)&&Array.isArray($0)){if(JSON.stringify(i0)!==JSON.stringify($0))l0.add(y0)}else if(i0!==$0)l0.add(y0)}return l0},[j0,T0]);yZ.useEffect(()=>{if(N0)Z0(N0),i(N0)},[N0]);let v0=yZ.useCallback((l0,y0)=>{i((i0)=>({...i0,[l0]:y0}))},[]),f0=yZ.useCallback(async()=>{let l0=Object.entries(T0).filter(([i0,$0])=>{let A8=j0[i0]??"";if(Array.isArray(A8)&&Array.isArray($0))return JSON.stringify(A8)!==JSON.stringify($0);return A8!==$0}),y0={};for(let[i0,$0]of l0)try{if(Array.isArray($0))await A0.mutateAsync({entityId:Q,fieldName:i0,values:$0});else await A0.mutateAsync({entityId:Q,fieldName:i0,value:$0});y0[i0]=$0}catch(A8){a8.error(`Failed to save ${i0}: ${A8.message}`)}if(Object.keys(y0).length>0)Z0((i0)=>({...i0,...y0}));if(Object.keys(y0).length===l0.length)a8.success("Fields saved")},[T0,j0,Q,A0]),n0=yZ.useCallback(()=>{i({...j0})},[j0]);yZ.useEffect(()=>{G8("view"),D0.current="view"},[Q]);let c0=yZ.useCallback((l0)=>{if(l0==="edit"&&q){G8("view");return}if(l0==="edit"&&b0!=="edit")D0.current=b0;if(G8(l0),l0==="edit")W(!0);else if(b0==="edit")W(!1)},[b0,q,W]);yZ.useEffect(()=>{if(q)G8("view")},[q]);let{data:B8}=fD(Z,Q),C8=B8?.parameters??[],x8=B8?.detectedVariables??[],W8=async()=>{await E(),G8("view")};return yZ.default.useEffect(()=>{m0(!1)},[Q]),J9.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0",children:[V0&&J9.jsxDEV("div",{className:"mb-3 p-4 border border-red-300 rounded-md bg-red-50",children:J9.jsxDEV("div",{className:"flex items-start gap-3",children:[J9.jsxDEV(w7,{className:"w-5 h-5 text-red-600 shrink-0 mt-0.5"},void 0,!1,void 0,this),J9.jsxDEV("div",{className:"flex-1",children:[J9.jsxDEV("p",{className:"text-sm font-medium text-red-800 mb-2",children:"Your edit session has expired"},void 0,!1,void 0,this),J9.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),J9.jsxDEV("div",{className:"flex gap-2",children:[J9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(Y),a8.success("Copied to clipboard"),P(null)},children:[J9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy My Changes"]},void 0,!0,void 0,this),J9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{O0(!1),F0(null),W(!1),window.location.reload()},children:[J9.jsxDEV(cU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Reload Template"]},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),w&&J9.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center justify-between",children:[J9.jsxDEV("div",{className:"flex items-center gap-2 text-destructive",children:[J9.jsxDEV(w7,{className:"w-4 h-4"},void 0,!1,void 0,this),J9.jsxDEV("span",{className:"text-sm",children:w},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(q8,{variant:"ghost",size:"icon",onClick:()=>P(null),className:"h-6 w-6",children:J9.jsxDEV(pZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(r2,{open:p0,onOpenChange:m0,projectId:Z,templateId:Q,templatePath:X?.path,mode:"documents"},void 0,!1,void 0,this),J9.jsxDEV(vz,{value:b0,onValueChange:c0,variant:"segment",className:"flex-1 flex flex-col min-h-0",children:[J9.jsxDEV("div",{className:"flex items-center justify-between gap-4 mb-2",children:[J9.jsxDEV("div",{className:"flex items-center gap-2",children:[J9.jsxDEV(fz,{children:[J9.jsxDEV(F4,{value:"view",children:"View"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"edit",disabled:!!q||E0,children:E0?J9.jsxDEV(J9.Fragment,{children:[J9.jsxDEV(uU,{className:"w-4 h-4"},void 0,!1,void 0,this),"Edit"]},void 0,!0,void 0,this):"Edit"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"fields",disabled:!!q,children:"Fields"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"params",children:"Params"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"attachments",disabled:!!q,children:"Assets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X?.hasPublished&&J9.jsxDEV(q8,{onClick:()=>m0(!0),variant:"outline",size:"sm",children:[J9.jsxDEV(pU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Render"]},void 0,!0,void 0,this),J9.jsxDEV(A4,{children:[J9.jsxDEV(sQ,{asChild:!0,children:J9.jsxDEV(q8,{variant:"outline",size:"sm",children:[J9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",J9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(nQ,{align:"start",children:[J9.jsxDEV(z6,{onClick:v,children:[J9.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:f,children:[J9.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy IDs"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:async()=>{try{let l0=wY(X?.path);await navigator.clipboard.writeText(l0),a8.success("Name copied")}catch(l0){a8.error("Failed to copy")}},children:[J9.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:async()=>{try{let l0=wY(X?.path);await navigator.clipboard.writeText(`[${l0}](${Q})`),a8.success("MD Link copied")}catch(l0){a8.error("Failed to copy")}},children:[J9.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:async()=>{try{let l0=Q?eZ(Q):"A",y0=l0&&l0!=="A"?`/store/${l0}`:"",i0=`${window.location.origin}/project/${Z}${y0}/templates?id=${Q}`;await navigator.clipboard.writeText(i0),a8.success("URL copied")}catch(l0){a8.error("Failed to copy")}},children:[J9.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b0==="view"&&K.length>1&&J9.jsxDEV(A4,{children:[J9.jsxDEV(sQ,{asChild:!0,children:J9.jsxDEV(q8,{variant:"outline",size:"sm",children:[J9.jsxDEV(gG,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Versions",J9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(nQ,{align:"start",children:K.slice().reverse().map((l0)=>{let y0=l0.versionNumber===X.versionCount,i0=y1("t",X?.subtype);return J9.jsxDEV(z6,{onClick:()=>y0?D():$(l0.versionNumber),children:[J9.jsxDEV(i0,{className:"w-4 h-4 mr-2 text-muted-foreground"},void 0,!1,void 0,this),y0?"Latest":new Date(l0.publishedAt).toLocaleDateString(),J9.jsxDEV("span",{className:"ml-auto text-muted-foreground",children:["v",l0.versionNumber]},void 0,!0,void 0,this)]},l0.versionNumber,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&J9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:D,children:[J9.jsxDEV(cU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Back to latest"]},void 0,!0,void 0,this),!q&&b0==="edit"&&(U||G||C==="saving")&&J9.jsxDEV(q8,{onMouseDown:()=>{X0.current=!0},onClick:W8,disabled:x.isPending,variant:"outline",size:"sm",children:[J9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),x.isPending?"Publishing...":"Publish"]},void 0,!0,void 0,this),!q&&b0==="edit"&&(U||G)&&J9.jsxDEV(q8,{onMouseDown:()=>{K8.current=!0},onClick:j,disabled:g.isPending,variant:"outline",size:"sm",children:[J9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),g.isPending?"Discarding...":"Discard"]},void 0,!0,void 0,this),b0==="fields"&&x0.size>0&&J9.jsxDEV(q8,{onClick:f0,disabled:A0.isPending,variant:"default",size:"sm",children:[J9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),A0.isPending?"Saving...":"Save Fields"]},void 0,!0,void 0,this),b0==="fields"&&x0.size>0&&J9.jsxDEV(q8,{onClick:n0,variant:"outline",size:"sm",children:[J9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Discard"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV("div",{className:"flex items-center gap-2",children:[J9.jsxDEV("div",{className:"flex flex-col mr-2",children:[J9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[(()=>{let l0=G||U,y0=y1("t",X?.subtype,{hasDraft:l0});return J9.jsxDEV(y0,{className:`h-4 w-4 shrink-0 ${!l0?"text-muted-foreground":""}`,...l0?{fill:"#fcd34d",stroke:"#000000"}:{}},void 0,!1,void 0,this)})(),J9.jsxDEV("span",{className:"text-sm font-medium truncate max-w-[200px]",children:wY(X?.path)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[J9.jsxDEV(y9,{content:`Template ID: ${Q}`,children:J9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${O4[X?.storeCode]||O4.A}`,children:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),(X?.versionCount??0)>0&&J9.jsxDEV(y9,{content:q?`Viewing version ${q}`:`Published version ${X.versionCount}`,children:J9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${q?"text-red-600 border-red-300 bg-red-50":"text-muted-foreground border-border/60 bg-muted/40"}`,children:["v",q||X.versionCount]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(q8,{onClick:()=>h(!0),variant:"destructive",size:"sm",children:[J9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(GQ,{value:"view",className:"flex-1 min-h-0",children:(()=>{let l0=U||G?Y:X.resolvedContent||X.publishedContent,y0=X.path?.endsWith(".md");if(q){let $0=IH8(H);return J9.jsxDEV("div",{ref:y0?C0:null,className:"h-full p-4 border border-border rounded-md bg-muted overflow-auto",children:[J9.jsxDEV("div",{className:"text-xs text-muted-foreground mb-3",children:["Viewing version ",q," (read-only)"]},void 0,!0,void 0,this),y0?J9.jsxDEV(MK,{markdown:$0,onInternalLinkClick:Q0,onRenderComplete:L8},void 0,!1,void 0,this):J9.jsxDEV("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:$0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}let i0=IH8(l0);return J9.jsxDEV("div",{ref:y0?C0:null,className:"h-full p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:i0?y0?J9.jsxDEV(MK,{markdown:i0,onInternalLinkClick:Q0,onRenderComplete:L8},void 0,!1,void 0,this):J9.jsxDEV("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:i0},void 0,!1,void 0,this):J9.jsxDEV("p",{className:"text-muted-foreground italic",children:"No content yet. Select Edit tab to start."},void 0,!1,void 0,this)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),J9.jsxDEV(GQ,{value:"edit",className:"flex-1 min-h-0 flex flex-col",children:[J9.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:s0&&!q&&J9.jsxDEV(yx,{status:C,onRetry:b},void 0,!1,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV("div",{className:"flex-1 min-h-0",children:J9.jsxDEV(eN,{value:Y,onChange:T,onBlur:()=>{if(X0.current){console.log("[BLUR] Skipping flush - publish pending"),X0.current=!1;return}if(K8.current){console.log("[BLUR] Skipping flush - discard pending"),K8.current=!1;return}console.log("[BLUR] Monaco blur - calling flush"),u.flush()},path:X.path,height:"100%",projectId:Z,storeCode:Q?Q[0]:"A"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(GQ,{value:"fields",className:"flex-1 min-h-0 overflow-auto p-4",children:J9.jsxDEV(n2,{projectId:Z,entityId:Q,entityType:"t",entitySubtype:X?.subtype,entityPath:X?.path,onFieldChange:v0,fieldValues:T0,dirtyFieldNames:x0,originalFieldValues:j0,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(GQ,{value:"params",className:"flex-1 min-h-0 overflow-auto p-4",children:C8.length>0?J9.jsxDEV("div",{className:"grid grid-cols-4 gap-2",children:C8.map((l0)=>J9.jsxDEV("div",{className:"text-sm bg-background p-2 rounded border border-border",children:[J9.jsxDEV("div",{className:"flex items-center gap-2",children:[J9.jsxDEV("span",{className:"font-mono font-medium",children:l0.name},void 0,!1,void 0,this),J9.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",l0.primitiveType,")"]},void 0,!0,void 0,this),l0.required&&J9.jsxDEV("span",{className:"text-xs text-destructive",children:"required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l0.description&&J9.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1",children:l0.description},void 0,!1,void 0,this),l0.default!==void 0&&J9.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1",children:["Default: ",J9.jsxDEV("span",{className:"font-mono",children:JSON.stringify(l0.default)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},l0.name,!0,void 0,this))},void 0,!1,void 0,this):x8.length>0?J9.jsxDEV("div",{className:"grid grid-cols-4 gap-2",children:[J9.jsxDEV("p",{className:"text-xs text-muted-foreground mb-2 col-span-4",children:"Detected from template (no front matter defined)"},void 0,!1,void 0,this),x8.map((l0)=>J9.jsxDEV("div",{className:"text-sm bg-background p-2 rounded border border-border",children:[J9.jsxDEV("span",{className:"font-mono font-medium",children:l0},void 0,!1,void 0,this),J9.jsxDEV("span",{className:"text-xs text-muted-foreground ml-2",children:"(string)"},void 0,!1,void 0,this)]},l0,!0,void 0,this))]},void 0,!0,void 0,this):J9.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"No parameters or variables detected."},void 0,!1,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(GQ,{value:"attachments",className:"flex-1 min-h-0 overflow-auto p-4",children:J9.jsxDEV(Ue,{projectId:Z,documentId:Q,content:Y||X.draftContent||X.publishedContent,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(mH,{open:!!U0,onOpenChange:(l0)=>!l0&&Y0(null),projectId:Z,documentId:U0?.id,anchor:U0?.anchor,onNavigate:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var jM0=Ye({type:"t",typeName:"Template",typeNamePlural:"Templates",DetailPanel:VH8,hooks:{useItem:VW,useCreate:lW8,useSaveDraft:SD,usePublish:jD,useDiscard:kD,useVersions:_L,useDelete:_D,useUpdatePath:vD,getVersion:xI},enableCollectionMode:!0});var RZ=W0(t0(),1);var sw9=W0(t0(),1);var nw9=W0(N8(),1);var lD=W0(N8(),1),CH8=/\[([^\]]+)\]\((A[dtf]\d+)\)/g,rw9=(Z)=>{let J=[],Q=0,X;CH8.lastIndex=0;while((X=CH8.exec(Z))!==null){if(X.index>Q)J.push({type:"text",content:Z.slice(Q,X.index)});J.push({type:"link",content:X[1],id:X[2]}),Q=X.index+X[0].length}if(Q<Z.length)J.push({type:"text",content:Z.slice(Q)});return J},ze=({message:Z,onNavigate:J})=>{if(!Z?.trim())return null;let Q=rw9(Z),X=(Y,U)=>{if(Y.stopPropagation(),J)J(U)},K=lD.jsxDEV("span",{className:"italic text-muted-foreground truncate text-xs",children:Q.map((Y,U)=>{if(Y.type==="link")return lD.jsxDEV("span",{onClick:(G)=>X(G,Y.id),className:"text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 cursor-pointer hover:underline",children:Y.content},U,!1,void 0,this);return lD.jsxDEV("span",{children:Y.content},U,!1,void 0,this)})},void 0,!1,void 0,this);return lD.jsxDEV(y9,{content:Z,side:"left",children:lD.jsxDEV("div",{className:"min-w-0 truncate",children:K},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var hw="",yw=()=>({"Content-Type":"application/json","X-Session-Id":$6()}),$H8=async(Z,{store:J}={})=>{let Q=new URLSearchParams;if(J)Q.set("store",J);let X=Q.toString(),K=`${hw}/api/p/${Z}/stories${X?`?${X}`:""}`,Y=await fetch(K,{headers:yw()});return O9(Y,"Failed to list stories")},DH8=async(Z,J)=>{let Q=await fetch(`${hw}/api/p/${Z}/stories/${J}`,{headers:yw()});return O9(Q,"Failed to fetch story")},EH8=async(Z,{name:J,store:Q,state:X,track:K})=>{let Y=await fetch(`${hw}/api/p/${Z}/stories`,{method:"POST",headers:yw(),body:JSON.stringify({name:J,store:Q,state:X,track:K})});return O9(Y,"Failed to create story")},SH8=async(Z,J,Q)=>{let X=await fetch(`${hw}/api/p/${Z}/stories/${J}/state`,{method:"PATCH",headers:yw(),body:JSON.stringify({state:Q})});return O9(X,"Failed to update story state")},jH8=async(Z,J,Q)=>{let X=await fetch(`${hw}/api/p/${Z}/stories/${J}/name`,{method:"PATCH",headers:yw(),body:JSON.stringify({name:Q})});return O9(X,"Failed to rename story")},kH8=async(Z,J)=>{let Q=await fetch(`${hw}/api/p/${Z}/stories/${J}`,{method:"DELETE",headers:yw()});return O9(Q,"Failed to delete story")},_H8=async(Z,J,{track:Q,targetState:X})=>{let K={track:Q};if(X)K.targetState=X;let Y=await fetch(`${hw}/api/p/${Z}/stories/${J}/track`,{method:"PATCH",headers:yw(),body:JSON.stringify(K)});return O9(Y,"Failed to change story track")};var vH8=(Z,{store:J}={})=>{return b6({queryKey:["stories",Z,J??"demux"],queryFn:()=>$H8(Z,{store:J}),enabled:!!Z,staleTime:30000})},fH8=(Z,J)=>{return b6({queryKey:["story",J],queryFn:()=>DH8(Z,J),enabled:!!Z&&!!J})},bH8=(Z)=>{let J=s9();return h7({mutationFn:({name:Q,store:X,state:K,track:Y})=>EH8(Z,{name:Q,store:X,state:K,track:Y}),onSuccess:(Q,{store:X})=>{J.invalidateQueries({queryKey:["stories",Z,X??"demux"]})}})},We=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,state:X})=>SH8(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})},xH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,name:X})=>jH8(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})},hH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q})=>kH8(Z,Q),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})},yH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,track:X,targetState:K})=>_H8(Z,Q,{track:X,targetState:K}),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})};var qe="",He=()=>({"Content-Type":"application/json","X-Session-Id":$6()}),gH8=async(Z,{store:J}={})=>{let Q=new URLSearchParams;if(J)Q.set("store",J);let X=Q.toString(),K=`${qe}/api/p/${Z}/tracks${X?`?${X}`:""}`,Y=await fetch(K,{headers:He()});return O9(Y,"Failed to list tracks")},mH8=async(Z,{store:J,name:Q,states:X})=>{let K=await fetch(`${qe}/api/p/${Z}/tracks`,{method:"POST",headers:He(),body:JSON.stringify({store:J,name:Q,states:X})});return O9(K,"Failed to create track")},uH8=async(Z,J,{name:Q,states:X})=>{let K=await fetch(`${qe}/api/p/${Z}/tracks/${J}`,{method:"PUT",headers:He(),body:JSON.stringify({name:Q,states:X})});return O9(K,"Failed to update track")},pH8=async(Z,J)=>{let Q=await fetch(`${qe}/api/p/${Z}/tracks/${J}`,{method:"DELETE",headers:He()});return O9(Q,"Failed to delete track")};var dD=(Z,{store:J}={})=>{return b6({queryKey:["tracks",Z,J??"demux"],queryFn:()=>gH8(Z,{store:J}),enabled:!!Z,staleTime:30000})},cH8=(Z)=>{let J=s9();return h7({mutationFn:({store:Q,name:X,states:K})=>mH8(Z,{store:Q,name:X,states:K}),onSuccess:(Q,{store:X})=>{J.invalidateQueries({queryKey:["tracks",Z,X??"demux"]})}})},lH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,name:X,states:K})=>uH8(Z,Q,{name:X,states:K}),onSuccess:()=>{J.invalidateQueries({queryKey:["tracks",Z]}),J.invalidateQueries({queryKey:["stories",Z]})}})},dH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q})=>pH8(Z,Q),onSuccess:()=>{J.invalidateQueries({queryKey:["tracks",Z]})}})};var a2=W0(t0(),1);class w9{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(Z){if(Z<=0.0031308)return 12.92*Z;else return 1.055*Math.pow(Z,0.4166666666666667)-0.055}static toLinear(Z){if(Z>0.04045)return Math.pow((Z+0.055)/1.055,2.4);else return Z/12.92}static yToL(Z){if(Z<=w9.epsilon)return Z/w9.refY*w9.kappa;else return 116*Math.pow(Z/w9.refY,0.3333333333333333)-16}static lToY(Z){if(Z<=8)return w9.refY*Z/w9.kappa;else return w9.refY*Math.pow((Z+16)/116,3)}static rgbChannelToHex(Z){let J=Math.round(Z*255),Q=J%16,X=(J-Q)/16|0;return w9.hexChars.charAt(X)+w9.hexChars.charAt(Q)}static hexToRgbChannel(Z,J){let Q=w9.hexChars.indexOf(Z.charAt(J)),X=w9.hexChars.indexOf(Z.charAt(J+1));return(Q*16+X)/255}static distanceFromOriginAngle(Z,J,Q){let X=J/(Math.sin(Q)-Z*Math.cos(Q));if(X<0)return 1/0;else return X}static distanceFromOrigin(Z,J){return Math.abs(J)/Math.sqrt(Math.pow(Z,2)+1)}static min6(Z,J,Q,X,K,Y){return Math.min(Z,Math.min(J,Math.min(Q,Math.min(X,Math.min(K,Y)))))}rgbToHex(){this.hex="#",this.hex+=w9.rgbChannelToHex(this.rgb_r),this.hex+=w9.rgbChannelToHex(this.rgb_g),this.hex+=w9.rgbChannelToHex(this.rgb_b)}hexToRgb(){this.hex=this.hex.toLowerCase(),this.rgb_r=w9.hexToRgbChannel(this.hex,1),this.rgb_g=w9.hexToRgbChannel(this.hex,3),this.rgb_b=w9.hexToRgbChannel(this.hex,5)}xyzToRgb(){this.rgb_r=w9.fromLinear(w9.m_r0*this.xyz_x+w9.m_r1*this.xyz_y+w9.m_r2*this.xyz_z),this.rgb_g=w9.fromLinear(w9.m_g0*this.xyz_x+w9.m_g1*this.xyz_y+w9.m_g2*this.xyz_z),this.rgb_b=w9.fromLinear(w9.m_b0*this.xyz_x+w9.m_b1*this.xyz_y+w9.m_b2*this.xyz_z)}rgbToXyz(){let Z=w9.toLinear(this.rgb_r),J=w9.toLinear(this.rgb_g),Q=w9.toLinear(this.rgb_b);this.xyz_x=0.41239079926595*Z+0.35758433938387*J+0.18048078840183*Q,this.xyz_y=0.21263900587151*Z+0.71516867876775*J+0.072192315360733*Q,this.xyz_z=0.019330818715591*Z+0.11919477979462*J+0.95053215224966*Q}xyzToLuv(){let Z=this.xyz_x+15*this.xyz_y+3*this.xyz_z,J=4*this.xyz_x,Q=9*this.xyz_y;if(Z!==0)J/=Z,Q/=Z;else J=NaN,Q=NaN;if(this.luv_l=w9.yToL(this.xyz_y),this.luv_l===0)this.luv_u=0,this.luv_v=0;else this.luv_u=13*this.luv_l*(J-w9.refU),this.luv_v=13*this.luv_l*(Q-w9.refV)}luvToXyz(){if(this.luv_l===0){this.xyz_x=0,this.xyz_y=0,this.xyz_z=0;return}let Z=this.luv_u/(13*this.luv_l)+w9.refU,J=this.luv_v/(13*this.luv_l)+w9.refV;this.xyz_y=w9.lToY(this.luv_l),this.xyz_x=0-9*this.xyz_y*Z/((Z-4)*J-Z*J),this.xyz_z=(9*this.xyz_y-15*J*this.xyz_y-J*this.xyz_x)/(3*J)}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 Z=Math.atan2(this.luv_v,this.luv_u);if(this.lch_h=Z*180/Math.PI,this.lch_h<0)this.lch_h=360+this.lch_h}}lchToLuv(){let Z=this.lch_h/180*Math.PI;this.luv_l=this.lch_l,this.luv_u=Math.cos(Z)*this.lch_c,this.luv_v=Math.sin(Z)*this.lch_c}calculateBoundingLines(Z){let J=Math.pow(Z+16,3)/1560896,Q=J>w9.epsilon?J:Z/w9.kappa,X=Q*(284517*w9.m_r0-94839*w9.m_r2),K=Q*(838422*w9.m_r2+769860*w9.m_r1+731718*w9.m_r0),Y=Q*(632260*w9.m_r2-126452*w9.m_r1),U=Q*(284517*w9.m_g0-94839*w9.m_g2),G=Q*(838422*w9.m_g2+769860*w9.m_g1+731718*w9.m_g0),z=Q*(632260*w9.m_g2-126452*w9.m_g1),W=Q*(284517*w9.m_b0-94839*w9.m_b2),q=Q*(838422*w9.m_b2+769860*w9.m_b1+731718*w9.m_b0),H=Q*(632260*w9.m_b2-126452*w9.m_b1);this.r0s=X/Y,this.r0i=K*Z/Y,this.r1s=X/(Y+126452),this.r1i=(K-769860)*Z/(Y+126452),this.g0s=U/z,this.g0i=G*Z/z,this.g1s=U/(z+126452),this.g1i=(G-769860)*Z/(z+126452),this.b0s=W/H,this.b0i=q*Z/H,this.b1s=W/(H+126452),this.b1i=(q-769860)*Z/(H+126452)}calcMaxChromaHpluv(){let Z=w9.distanceFromOrigin(this.r0s,this.r0i),J=w9.distanceFromOrigin(this.r1s,this.r1i),Q=w9.distanceFromOrigin(this.g0s,this.g0i),X=w9.distanceFromOrigin(this.g1s,this.g1i),K=w9.distanceFromOrigin(this.b0s,this.b0i),Y=w9.distanceFromOrigin(this.b1s,this.b1i);return w9.min6(Z,J,Q,X,K,Y)}calcMaxChromaHsluv(Z){let J=Z/360*Math.PI*2,Q=w9.distanceFromOriginAngle(this.r0s,this.r0i,J),X=w9.distanceFromOriginAngle(this.r1s,this.r1i,J),K=w9.distanceFromOriginAngle(this.g0s,this.g0i,J),Y=w9.distanceFromOriginAngle(this.g1s,this.g1i,J),U=w9.distanceFromOriginAngle(this.b0s,this.b0i,J),G=w9.distanceFromOriginAngle(this.b1s,this.b1i,J);return w9.min6(Q,X,K,Y,U,G)}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 Z=this.calcMaxChromaHsluv(this.hsluv_h);this.lch_c=Z/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 Z=this.calcMaxChromaHsluv(this.lch_h);this.hsluv_s=this.lch_c/Z*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 Z=this.calcMaxChromaHpluv();this.lch_c=Z/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 Z=this.calcMaxChromaHpluv();this.hpluv_p=this.lch_c/Z*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()}}w9.hexChars="0123456789abcdef";w9.refY=1;w9.refU=0.19783000664283;w9.refV=0.46831999493879;w9.kappa=903.2962962;w9.epsilon=0.0088564516;w9.m_r0=3.240969941904521;w9.m_r1=-1.537383177570093;w9.m_r2=-0.498610760293;w9.m_g0=-0.96924363628087;w9.m_g1=1.87596750150772;w9.m_g2=0.041555057407175;w9.m_b0=0.055630079696993;w9.m_b1=-0.20397695888897;w9.m_b2=1.056971514242878;var EW=W0(N8(),1),kM0=(Z,J,Q)=>{let X=new w9;return X.hsluv_h=Z,X.hsluv_s=J,X.hsluv_l=Q,X.hsluvToHex(),X.hex},aw9=(Z,J)=>{if(J===0)return{bg:"linear-gradient(to bottom, #6b7280, #4b5563)",text:"white",border:"#374151"};let Q=J<=1?0:Z/(J-1)*360,X=65,K=40,Y=kM0(Q,X,K+15),U=kM0(Q,X,K),G=kM0(Q,X,K-10);return{bg:`linear-gradient(to bottom, ${Y}, ${U})`,text:"white",border:G}},ow9=16,tw9=24,ew9=60,_M0=null,ZP9=(Z,J="12px ui-sans-serif, system-ui, sans-serif")=>{if(!_M0)_M0=document.createElement("canvas");let Q=_M0.getContext("2d");return Q.font=J,Q.measureText(Z).width},JP9=(Z,J)=>{if(!Z.length||J<=0)return[];let Q=Z.map((W)=>{let q=W.charAt(0).toUpperCase()+W.slice(1),H=ZP9(q);return Math.max(H+ow9*2+tw9,ew9)}),X=Z.length;if(X===1){let W=Q[0];return[{width:W,centerX:J/2,leftPx:(J-W)/2}]}let K=Q[0]/2,Y=Q[X-1]/2,U=K,z=(J-Y-U)/(X-1);return Z.map((W,q)=>{let H=U+q*z,B=Q[q],O=H-B/2;return{width:B,centerX:H,leftPx:O}})};var Be=({state:Z,states:J,onPrev:Q,onNext:X,compact:K=!1})=>{let Y=a2.useRef(null),[U,G]=a2.useState(0),z=J.indexOf(Z),W=J.length,[q,H]=a2.useState(!1),B=a2.useCallback((N)=>{Y.current=N,H(!!N)},[]);a2.useEffect(()=>{if(!Y.current)return;let N=new ResizeObserver((w)=>{for(let P of w)G(P.contentRect.width)});return N.observe(Y.current),G(Y.current.offsetWidth),()=>N.disconnect()},[q]);let O=a2.useMemo(()=>{return JP9(J,U)},[J,U]);if(z<0||W===0)return null;let M=O[z],A=Z.charAt(0).toUpperCase()+Z.slice(1),R=aw9(z,J.length);if(!M||U===0)return EW.jsxDEV("div",{ref:B,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"},void 0,!1,void 0,this);return EW.jsxDEV("div",{ref:B,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:EW.jsxDEV("div",{className:"absolute rounded text-xs flex items-center justify-between px-1 shadow-sm",style:{left:`${M.leftPx}px`,width:`${M.width}px`,top:"2px",bottom:"2px",background:R.bg,color:R.text,borderWidth:"1px",borderStyle:"solid",borderColor:R.border},children:[Q?EW.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(N)=>{N.stopPropagation(),Q()},onKeyDown:(N)=>{if(N.key==="Enter"||N.key===" ")N.preventDefault(),N.stopPropagation(),Q()},children:EW.jsxDEV(wB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):EW.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this),EW.jsxDEV("span",{className:"flex-1 text-center truncate",children:A},void 0,!1,void 0,this),X?EW.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(N)=>{N.stopPropagation(),X()},onKeyDown:(N)=>{if(N.key==="Enter"||N.key===" ")N.preventDefault(),N.stopPropagation(),X()},children:EW.jsxDEV(PB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):EW.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)};var Fe=[{value:"documents",icon:G4,label:"Documents",shortLabel:"Docs",showLabel:!0},{value:"tasks",icon:Jq,label:"Tasks",shortLabel:"Tasks",showLabel:!0},{value:"prompts",icon:rX,label:"Prompts",shortLabel:"Prompts",showLabel:!0},{value:"jobs",icon:dG,label:"Jobs",shortLabel:"Jobs",showLabel:!0},{value:"fields",icon:a3,label:"Fields",showLabel:!1}];function yL(Z,J,{track:Q,state:X}={}){return Z.filter((K)=>QP9(K,J,Q,X))}function QP9(Z,J,Q,X){let{config:K}=Z;if(!K)return!1;let Y;try{Y=JSON.parse(K)}catch{return!1}let U=Y?.visibility;if(!U)return!1;let G=U[J];if(!G)return!0;let{tracks:z,states:W}=G,q=Array.isArray(z)&&z.length>0,H=Array.isArray(W)&&W.length>0;if(!q&&!H)return!0;if(q&&!z.includes(Q))return!1;if(H&&!W.includes(X))return!1;return!0}function Oe(Z,J,Q){let{data:X,isLoading:K}=mD(Z,{store:Q});return{hasJobs:X?.jobs?.some((U)=>U.fields?.objectId===J)??!1,isLoading:K}}function iH8(Z,{track:J,state:Q}={}){let{data:X,isLoading:K}=bH(Z,"s"),Y=X?.templates??[];return{hasPrompts:yL(Y,"story",{track:J,state:Q}).length>0,isLoading:K}}var $8=W0(N8(),1),vM0=[{key:"unsorted",icon:Xq,label:"Not sorted"},{key:"name-asc",icon:hG,label:"Sorting by name ascending"},{key:"name-desc",icon:xG,label:"Sorting by name descending"},{key:"date-asc",icon:Az,label:"Sorting by date ascending"},{key:"date-desc",icon:Lz,label:"Sorting by date descending"},{key:"date-completed-asc",icon:Az,label:"Sorting by date completed ascending"},{key:"date-completed-desc",icon:Lz,label:"Sorting by date completed descending"},{key:"state-asc",icon:d3,label:"Sorting by state ascending"},{key:"state-desc",icon:l3,label:"Sorting by state descending"}],fM0=[{value:"active",label:"Active",icon:uA},{value:"backlog",label:"Backlog",icon:rS},{value:"history",label:"History",icon:gG}],bM0=50,KP9={d:"documents",t:"tasks",p:"prompts",j:"jobs",f:"fields"};function YP9({projectId:Z,storyId:J,storeCode:Q,onNavigate:X,hasPrompts:K}){let{hasJobs:Y,isLoading:U}=Oe(Z,J,Q),G=!U&&!Y,z=!K,W=(q)=>{switch(q){case"jobs":return G;case"prompts":return z;default:return!1}};return $8.jsxDEV("div",{className:"inline-flex gap-0.5 rounded bg-black/[0.03] dark:bg-white/[0.03] shadow-sm border border-border/50 p-0.5",children:Fe.map((q)=>{let H=W(q.value),B=H?`No ${q.label.toLowerCase()}`:q.label;return $8.jsxDEV(y9,{content:B,children:$8.jsxDEV("button",{onClick:(O)=>{if(O.stopPropagation(),!H)X(q.value)},disabled:H,tabIndex:H?-1:0,className:y8("rounded-md px-2 py-1.5 flex items-center gap-1 justify-center",H?"text-muted-foreground/50":"text-muted-foreground hover:text-foreground hover:bg-muted/50 cursor-pointer"),children:[$8.jsxDEV(q.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),q.showLabel&&$8.jsxDEV("span",{className:"text-xs",children:q.shortLabel},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},q.value,!1,void 0,this)})},void 0,!1,void 0,this)}var xM0=()=>{let{id:Z,storeCode:J}=YQ(),Q=PZ(),{data:X}=k4(Z);A1(X?`${X.name} - Stories`:"CAW");let K=J??"A";Rq(Z);let Y=RZ.useRef(null),{data:U=[],isLoading:G,error:z,refetch:W}=vH8(Z,{store:K}),{data:q=[],isLoading:H,error:B,refetch:O}=dD(Z,{store:K}),{data:M}=bH(Z,"s"),A=M?.templates??[],R=bH8(Z),N=We(Z),w=hH8(Z),P=oY(Z),C=yH8(Z),T=($0)=>{return q.find((o0)=>o0.name===$0)?.fields?.states||[]},$=RZ.useMemo(()=>{let $0=new Set;return q.forEach((A8)=>{(A8.fields?.states||[]).forEach((g0)=>$0.add(g0))}),[...$0]},[q]),D=($0,A8)=>{let o0=q.find((Q8)=>Q8.name===A8);if(!o0)return 0.5;let g0=o0.fields?.states||[];if(g0.length===0)return 0.5;let r0=g0.indexOf($0);if(r0===-1)return 0.5;return g0.length<=1?0:r0/(g0.length-1)},[E,j]=RZ.useState(!1),[b,_]=RZ.useState(""),[k,v]=RZ.useState(""),[f,h]=RZ.useState(""),[x,g]=RZ.useState(null),[m,u]=PY(Z,"stories","selectedStoryId",null,K),d=m?U.find(($0)=>$0.id===m):null,[p,s]=RZ.useState(null),[e,J0]=RZ.useState(!1),[t,B0]=RZ.useState(null),[n,H0]=RZ.useState(!1),[Q0,U0]=RZ.useState(null),[Y0,K0]=RZ.useState(null),[F0,z0]=RZ.useState(""),[V0,O0]=RZ.useState(null),[S0,X0]=RZ.useState(null),K8=A.find(($0)=>$0.id===V0);RZ.useEffect(()=>{if(q.length>0&&k===""){let $0=q.find((A8)=>A8.name==="Default");v($0?"Default":q[0].name)}},[q,k]),RZ.useEffect(()=>{if(k){let $0=T(k);if($0.length>0)h($0[0])}},[k,q]);let[C0,H8]=PY(Z,"stories","sortMode","state-asc",K),L8=RZ.useRef(null),{phase:s0,activeStates:E0,setPhase:p0,setActiveStates:m0}=rT0(Z),[b0,G8]=PY(Z,"stories","currentPage",1,K);gH(Z,"stories","list",Y,!G,K);let D0=RZ.useMemo(()=>{if(!E0)return new Set($);let $0=E0.filter((A8)=>$.includes(A8));return $0.length>0?new Set($0):new Set($)},[E0,$]);RZ.useEffect(()=>{if(!E0||!$.length)return;let $0=E0.filter((A8)=>$.includes(A8));if($0.length!==E0.length)m0($0.length>0&&$0.length<$.length?$0:null)},[E0,$,m0]);let j0=($0)=>{let A8=E0?new Set(E0):new Set($),o0=new Set(A8);if(o0.has($0))o0.delete($0);else o0.add($0);m0(o0.size===$.length?null:[...o0])},Z0=($0)=>{let A8=J?`/project/${Z}/store/${J}/story/${$0}`:`/project/${Z}/story/${$0}`;Q(A8)},T0=($0,A8)=>{let o0=J?`/project/${Z}/store/${J}/story/${$0}?tab=${A8}`:`/project/${Z}/story/${$0}?tab=${A8}`;Q(o0)},i=($0,A8)=>{if($0.key==="Enter"||$0.key===" ")$0.preventDefault(),u(m===A8?null:A8)},N0=($0,A8)=>{let g0=U.find((r0)=>r0.id===$0)?.fields?.phase;P.mutate({entityId:$0,fieldName:"phase",value:A8},{onSuccess:()=>{if(g0==="history")a8(`Story moved to ${A8.charAt(0).toUpperCase()+A8.slice(1)}`)}})},A0=($0,A8)=>{let g0=U.find((Q8)=>Q8.id===$0)?.fields?.state,r0=T(A8);if(g0&&r0.includes(g0))C.mutate({id:$0,track:A8},{onSuccess:()=>a8(`Track changed to ${A8}`),onError:(Q8)=>a8.error(Q8.message||"Failed to change track")});else U0($0),K0(A8),z0(""),H0(!0)},x0=()=>{C.mutate({id:Q0,track:Y0,targetState:F0},{onSuccess:()=>{a8(`Track changed to ${Y0}`),H0(!1),U0(null),K0(null),z0("")},onError:($0)=>a8.error($0.message||"Failed to change track")})},{visibleStories:v0,phaseFilteredCount:f0}=RZ.useMemo(()=>{if(!q.length)return{visibleStories:[],phaseFilteredCount:0};let $0=U.filter((g0)=>{return(g0.fields?.phase||"active")===s0}),A8=$0.filter((g0)=>{return g0.fields?.state&&D0.has(g0.fields.state)});if(C0==="unsorted"){if(L8.current){let g0=L8.current,r0=[...A8];return r0.sort((Q8,L0)=>{let h0=g0.indexOf(Q8.id),e0=g0.indexOf(L0.id);return(h0===-1?1/0:h0)-(e0===-1?1/0:e0)}),{visibleStories:r0,phaseFilteredCount:$0.length}}return{visibleStories:A8,phaseFilteredCount:$0.length}}let o0=[...A8];return o0.sort((g0,r0)=>{let Q8=(h0)=>h0.createdAt?new Date(h0.createdAt).getTime():parseInt(h0.id.replace(/\D/g,""),10)||0,L0=(h0)=>{let e0=h0.fields?.dateCompleted;return e0?new Date(e0).getTime():null};if(C0==="name-asc")return g0.name.localeCompare(r0.name);if(C0==="name-desc")return r0.name.localeCompare(g0.name);if(C0==="date-asc"||C0==="date-desc"){let h0=Q8(g0)-Q8(r0);return C0==="date-asc"?h0:-h0}if(C0==="date-completed-asc"||C0==="date-completed-desc"){let h0=L0(g0),e0=L0(r0);if(h0===null&&e0===null)return 0;if(h0===null)return 1;if(e0===null)return-1;let P0=h0-e0;return C0==="date-completed-asc"?P0:-P0}if(C0==="state-asc"){let h0=D(g0.fields.state,g0.fields.track),e0=D(r0.fields.state,r0.fields.track),P0=h0-e0;if(Math.abs(P0)>0.001)return P0;let M8=L0(g0),w8=L0(r0);if(M8===null&&w8===null)return 0;if(M8===null)return 1;if(w8===null)return-1;return w8-M8}if(C0==="state-desc"){let h0=D(g0.fields.state,g0.fields.track),P0=D(r0.fields.state,r0.fields.track)-h0;if(Math.abs(P0)>0.001)return P0;let M8=L0(g0),w8=L0(r0);if(M8===null&&w8===null)return 0;if(M8===null)return 1;if(w8===null)return-1;return M8-w8}return 0}),{visibleStories:o0,phaseFilteredCount:$0.length}},[U,q,C0,D0,s0]),n0=Math.ceil(v0.length/bM0),c0=Math.min(b0,Math.max(1,n0)),B8=RZ.useMemo(()=>{let $0=(c0-1)*bM0;return v0.slice($0,$0+bM0)},[v0,c0]),C8=RZ.useRef(!0);RZ.useEffect(()=>{if(C8.current){C8.current=!1;return}G8(1)},[C0,E0,s0]),RZ.useEffect(()=>{L8.current=null},[s0]),RZ.useEffect(()=>{if(m&&!v0.some(($0)=>$0.id===m))u(null)},[m,v0]),RZ.useEffect(()=>{if(m&&!U.some(($0)=>$0.id===m))u(null)},[m,U]),RZ.useEffect(()=>{let $0=(A8)=>{if(!p)return;if(A8.shiftKey||A8.ctrlKey||A8.altKey||A8.metaKey)return;let o0=document.activeElement;if(o0&&(o0.tagName==="INPUT"||o0.tagName==="TEXTAREA"))return;let g0=KP9[A8.key];if(g0)T0(p,g0)};return window.addEventListener("keydown",$0),()=>window.removeEventListener("keydown",$0)},[p]),RZ.useEffect(()=>{if(J==="B")Q(`/project/${Z}/store/B/documents`,{replace:!0})},[J,Z,Q]);let x8=()=>{if(!b.trim()){g("Story name is required");return}g(null),R.mutate({name:b.trim(),store:K,state:f,track:k},{onSuccess:($0)=>{j(!1),_("");let A8=q.find((o0)=>o0.name==="Default");v(A8?"Default":q[0]?.name||""),Z0($0.id)},onError:($0)=>{g($0.message)}})},W8=()=>{j(!1),_("");let $0=q.find((A8)=>A8.name==="Default");v($0?"Default":q[0]?.name||""),g(null)},l0=G||H,y0=z||B,i0=z?W:O;if(J==="B")return null;if(l0)return $8.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(y0)return $8.jsxDEV("div",{className:"p-6",children:[$8.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading stories"},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:y0.message},void 0,!1,void 0,this),$8.jsxDEV(q8,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>i0(),children:[$8.jsxDEV($B,{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 $8.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[$8.jsxDEV("div",{className:"flex items-center justify-between mb-4 relative",onClick:()=>u(null),children:[$8.jsxDEV("div",{className:"flex items-center gap-2",onClick:($0)=>$0.stopPropagation(),children:[$8.jsxDEV(q8,{size:"sm",variant:"warning",onClick:()=>j(!0),children:[$8.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),$8.jsxDEV(RB,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(q3,{orientation:"vertical",className:"h-6 mx-2"},void 0,!1,void 0,this),$8.jsxDEV(A4,{children:[$8.jsxDEV(y9,{content:vM0.find(($0)=>$0.key===C0)?.label,children:$8.jsxDEV(sQ,{asChild:!0,children:$8.jsxDEV(q8,{size:"sm",variant:"outline",children:RZ.default.createElement(vM0.find(($0)=>$0.key===C0)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(nQ,{align:"start",children:vM0.map(($0)=>$8.jsxDEV(z6,{onClick:()=>{if($0.key==="unsorted")L8.current=v0.map((A8)=>A8.id);else L8.current=null;H8($0.key)},className:C0===$0.key?"bg-accent":"",children:[$8.jsxDEV($0.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),$0.label]},$0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(DL,{children:[$8.jsxDEV(y9,{content:"Filter by state",children:$8.jsxDEV(EL,{asChild:!0,children:$8.jsxDEV(q8,{size:"sm",variant:"outline",children:$8.jsxDEV(Zq,{className:"w-4 h-4",...E0&&{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),$8.jsxDEV(G3,{align:"center",children:$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV("div",{className:"text-sm font-medium",children:"Show by state:"},void 0,!1,void 0,this),$.map(($0)=>$8.jsxDEV("label",{className:"flex items-center gap-2",children:[$8.jsxDEV(g1,{checked:D0.has($0),onCheckedChange:()=>j0($0)},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"text-sm capitalize",children:$0},void 0,!1,void 0,this)]},$0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(A4,{children:[$8.jsxDEV(y9,{content:"Phase",children:$8.jsxDEV(sQ,{asChild:!0,children:$8.jsxDEV(q8,{variant:"outline",size:"sm",children:[RZ.default.createElement(fM0.find(($0)=>$0.value===s0)?.icon,{className:"w-4 h-4 mr-1"}),fM0.find(($0)=>$0.value===s0)?.label,$8.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(nQ,{align:"start",children:fM0.map(($0)=>$8.jsxDEV(z6,{onClick:()=>p0($0.value),className:s0===$0.value?"bg-accent":"",children:[$8.jsxDEV($0.icon,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),$0.label]},$0.value,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&$8.jsxDEV($8.Fragment,{children:[$8.jsxDEV(q3,{orientation:"vertical",className:"h-6 mx-2"},void 0,!1,void 0,this),$8.jsxDEV(A4,{children:[$8.jsxDEV(sQ,{asChild:!0,children:$8.jsxDEV(q8,{variant:"outline",size:"sm",children:[$8.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",$8.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(nQ,{align:"start",children:[$8.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(d.id),a8.success("Story ID copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Story ID"]},void 0,!0,void 0,this),$8.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(d.name),a8.success("Name copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),$8.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(`[${d.name}](${d.id})`),a8.success("MD Link copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),$8.jsxDEV(z6,{onClick:async()=>{try{let $0=eZ(d.id),A8=$0&&$0!=="A"?`/store/${$0}`:"",o0=`${window.location.origin}/project/${Z}${A8}/story/${d.id}`;await navigator.clipboard.writeText(o0),a8.success("URL copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(q8,{size:"sm",variant:"destructive",onClick:()=>{B0(null),J0(!0)},children:[$8.jsxDEV(fJ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),d&&$8.jsxDEV("div",{className:"absolute left-1/2 -translate-x-1/2 flex items-center gap-2",onClick:($0)=>$0.stopPropagation(),children:[$8.jsxDEV(RB,{className:"w-5 h-5 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"truncate text-base font-medium max-w-[300px]",children:d.name},void 0,!1,void 0,this),$8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${d.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:d.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n0>1&&$8.jsxDEV("div",{className:"flex items-center gap-2",onClick:($0)=>$0.stopPropagation(),children:[$8.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>G8(($0)=>$0-1),disabled:c0===1,children:$8.jsxDEV(Nz,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"text-sm text-muted-foreground px-2",children:["Page ",c0," of ",n0]},void 0,!0,void 0,this),$8.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>G8(($0)=>$0+1),disabled:c0===n0,children:$8.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),v0.length===0?U.length===0?$8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories yet"},void 0,!1,void 0,this):f0===0?$8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:["No stories in ",s0,". Stories exist in other phases.",s0!=="active"&&$8.jsxDEV($8.Fragment,{children:[" ",$8.jsxDEV("button",{className:"underline text-primary cursor-pointer",onClick:()=>p0("active"),children:"Switch to Active"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):$8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories match the current filters"},void 0,!1,void 0,this):$8.jsxDEV("div",{ref:Y,className:"flex-1 overflow-auto",onClick:()=>u(null),children:B8.map(($0)=>{let A8=T($0.fields.track),o0=A8.indexOf($0.fields.state),g0=o0>0?A8[o0-1]:null,r0=o0<A8.length-1?A8[o0+1]:null,Q8=m===$0.id,L0=$8.jsxDEV("div",{role:"button",tabIndex:0,"aria-selected":Q8,onMouseEnter:()=>s($0.id),onMouseLeave:()=>s(null),onClick:(e0)=>{e0.stopPropagation(),u(m===$0.id?null:$0.id)},onDoubleClick:()=>Z0($0.id),onKeyDown:(e0)=>i(e0,$0.id),className:`grid grid-cols-[5fr_5fr_6fr_4fr] items-center px-3 py-2 w-full cursor-pointer border-b gap-2 ${Q8?"bg-muted":"hover:bg-muted/50"}`,children:[$8.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[$8.jsxDEV(RB,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"truncate text-sm",children:$0.name},void 0,!1,void 0,this),$8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${$0.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:$0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"flex items-center gap-2",children:[$8.jsxDEV(y9,{content:`Track: ${$0.fields?.track||"Default"}`,children:$8.jsxDEV("span",{className:"text-xs text-muted-foreground flex-shrink-0 truncate w-[80px] text-right",children:[$0.fields?.track||"Default",":"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"flex-1",onClick:(e0)=>e0.stopPropagation(),children:$8.jsxDEV(Be,{state:$0.fields.state,states:A8,onPrev:g0?()=>N.mutate({id:$0.id,state:g0}):null,onNext:r0?()=>N.mutate({id:$0.id,state:r0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"flex items-center gap-2",children:[$8.jsxDEV(YP9,{projectId:Z,storyId:$0.id,storeCode:K,onNavigate:(e0)=>T0($0.id,e0),hasPrompts:A.length>0},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"grid grid-cols-[20px_40px] items-center",children:[$8.jsxDEV("div",{className:"flex justify-center",children:$0.fields?.flag==="true"&&$8.jsxDEV(hA,{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:(e0)=>{e0.stopPropagation(),P.mutate({entityId:$0.id,fieldName:"flag",value:"false"})}},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"flex justify-start pl-2",children:parseInt($0.fields?.activeJobCount||"0",10)>0&&$8.jsxDEV("div",{className:"relative flex items-center gap-0.5 flex-shrink-0 p-1 rounded-md overflow-hidden",children:[$8.jsxDEV(dG,{className:"w-4 h-4 text-blue-500 dark:text-blue-400 animate-spin",style:{animationDuration:"6.28s"}},void 0,!1,void 0,this),parseInt($0.fields?.activeJobCount||"0",10)>=2&&$8.jsxDEV("span",{className:"text-[10px] font-mono text-blue-600 dark:text-blue-300",children:$0.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),$8.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:$0.fields?.statusMessage?.trim()&&$8.jsxDEV(ze,{message:$0.fields.statusMessage,onNavigate:(e0)=>{let P0=J?`/project/${Z}/store/${J}/story/${$0.id}?id=${e0}&tab=documents`:`/project/${Z}/story/${$0.id}?id=${e0}&tab=documents`;Q(P0)}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},$0.id,!0,void 0,this),h0=$0.fields?.phase??"active";return $8.jsxDEV(xD,{children:[$8.jsxDEV(hD,{asChild:!0,children:L0},void 0,!1,void 0,this),$8.jsxDEV(vw,{children:[(()=>{let e0=yL(A,"story",{track:$0.fields?.track,state:$0.fields?.state});return e0.length>0&&$8.jsxDEV(yD,{children:[$8.jsxDEV(kw,{children:[$8.jsxDEV(rX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),$8.jsxDEV(_w,{children:e0.map((P0)=>{let M8=P0.subtype==="prompt"?rX:vK;return $8.jsxDEV(gQ,{onClick:()=>{O0(P0.id),X0($0.id)},children:[$8.jsxDEV(M8,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),P0.name]},P0.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),$8.jsxDEV(yD,{children:[$8.jsxDEV(kw,{children:[$8.jsxDEV(aS,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Move to"]},void 0,!0,void 0,this),$8.jsxDEV(_w,{children:[$8.jsxDEV(gQ,{disabled:h0==="active",onClick:()=>N0($0.id,"active"),children:"Active"},void 0,!1,void 0,this),$8.jsxDEV(gQ,{disabled:h0==="backlog",onClick:()=>N0($0.id,"backlog"),children:"Backlog"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(yD,{children:[$8.jsxDEV(kw,{disabled:q.length<=1,children:[$8.jsxDEV(nX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Change Track"]},void 0,!0,void 0,this),$8.jsxDEV(_w,{children:q.filter((e0)=>e0.name!==$0.fields?.track).map((e0)=>$8.jsxDEV(gQ,{onClick:()=>A0($0.id,e0.name),children:e0.name},e0.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},$0.id,!0,void 0,this)})},void 0,!1,void 0,this),$8.jsxDEV(D6,{open:E,onOpenChange:W8,children:$8.jsxDEV(O6,{children:[$8.jsxDEV(M6,{children:$8.jsxDEV(L6,{children:"Create Story"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"space-y-4 py-4",children:[$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),$8.jsxDEV(u6,{id:"name",value:b,onChange:($0)=>_($0.target.value),placeholder:"Enter story name",onKeyDown:($0)=>$0.key==="Enter"&&x8()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"track",children:"Track"},void 0,!1,void 0,this),$8.jsxDEV(IJ,{value:k,onValueChange:v,children:[$8.jsxDEV(BJ,{children:$8.jsxDEV(VJ,{placeholder:"Select track"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(FJ,{children:q.map(($0)=>$8.jsxDEV(BZ,{value:$0.name,children:$0.name},$0.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),$8.jsxDEV(IJ,{value:f,onValueChange:h,children:[$8.jsxDEV(BJ,{children:$8.jsxDEV(VJ,{placeholder:"Select state"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(FJ,{children:T(k).map(($0)=>$8.jsxDEV(BZ,{value:$0,children:$0.charAt(0).toUpperCase()+$0.slice(1)},$0,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x&&$8.jsxDEV("div",{className:"text-sm text-destructive",children:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(i6,{children:[$8.jsxDEV(q8,{variant:"outline",onClick:W8,children:"Cancel"},void 0,!1,void 0,this),$8.jsxDEV(q8,{onClick:x8,disabled:R.isPending,children:R.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),$8.jsxDEV(D6,{open:e,onOpenChange:J0,children:$8.jsxDEV(O6,{children:[$8.jsxDEV(M6,{children:$8.jsxDEV(L6,{className:"flex items-center gap-2 text-destructive",children:[$8.jsxDEV(w7,{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),$8.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete ",$8.jsxDEV("strong",{children:U.find(($0)=>$0.id===m)?.name},void 0,!1,void 0,this),"? This will remove the story and all its contents."]},void 0,!0,void 0,this),t&&$8.jsxDEV("div",{className:"text-sm text-destructive",children:t},void 0,!1,void 0,this),$8.jsxDEV(i6,{children:[$8.jsxDEV(q8,{variant:"outline",onClick:()=>J0(!1),children:"Cancel"},void 0,!1,void 0,this),$8.jsxDEV(q8,{variant:"destructive",onClick:()=>{B0(null),w.mutate({id:m},{onSuccess:()=>{J0(!1),u(null)},onError:($0)=>B0($0.message)})},disabled:w.isPending,children:w.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),$8.jsxDEV(D6,{open:n,onOpenChange:($0)=>{if(!$0)H0(!1),U0(null),K0(null),z0("")},children:$8.jsxDEV(O6,{children:[$8.jsxDEV(M6,{children:$8.jsxDEV(L6,{children:"Change Track"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"space-y-4 py-4",children:[$8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["The current state is not available in ",$8.jsxDEV("strong",{children:Y0},void 0,!1,void 0,this),". Select a new state to continue:"]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"change-track-state",children:"State"},void 0,!1,void 0,this),$8.jsxDEV(IJ,{value:F0,onValueChange:z0,children:[$8.jsxDEV(BJ,{id:"change-track-state",children:$8.jsxDEV(VJ,{placeholder:"Select state"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(FJ,{children:T(Y0??"").map(($0)=>$8.jsxDEV(BZ,{value:$0,children:$0.charAt(0).toUpperCase()+$0.slice(1)},$0,!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),$8.jsxDEV(i6,{children:[$8.jsxDEV(q8,{variant:"outline",onClick:()=>H0(!1),children:"Cancel"},void 0,!1,void 0,this),$8.jsxDEV(q8,{onClick:x0,disabled:!F0||C.isPending,children:C.isPending?"Changing...":"OK"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(r2,{open:!!V0,onOpenChange:($0)=>{if(!$0)O0(null),X0(null)},projectId:Z,templateId:V0,templatePath:K8?.path||K8?.name,mode:"story",storyId:S0,rootFolderId:S0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var U1=W0(t0(),1);var UP9=W0(t0(),1);var w5=W0(N8(),1),GP9=({status:Z})=>{let J={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",stopped:"text-orange-700 border-orange-300 bg-orange-50 dark:text-orange-300 dark:border-orange-700 dark:bg-orange-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 w5.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase ${J[Z]||J.pending}`,children:Z},void 0,!1,void 0,this)},sH8=(Z)=>{if(!Z)return"-";return new Date(Z).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},zP9=(Z)=>{if(Z===null||Z===void 0)return"-";if(Z>=1000)return`${(Z/1000).toFixed(1)}k`;return Z.toString()},hM0=async(Z)=>{if(!Z)return;try{await navigator.clipboard.writeText(Z),a8.success("Copied")}catch(J){console.error("Failed to copy:",J)}},Me=(Z,J)=>{if(!Z||!J)return null;let Q=`${J}/worktree/`;if(Z.startsWith(Q)){let X=Z.slice(Q.length),K=X.endsWith("/")?X.slice(0,-1):X,Y=K.indexOf("/");return Y===-1?K:K.slice(0,Y)}if(Z.startsWith(J)){let X=Z.slice(J.length);return X.startsWith("/")?X.slice(1):X}return Z},iD=({job:Z,onClick:J,projectPath:Q})=>{let X=Me(Z.fields?.workingDirectory,Q);return w5.jsxDEV("div",{onClick:()=>J(Z),className:"p-3 rounded cursor-pointer flex items-center gap-3 hover:bg-muted border-b border-border last:border-b-0",children:[w5.jsxDEV("div",{className:"w-[78px] flex-shrink-0 flex items-center",children:w5.jsxDEV(GP9,{status:Z.fields?.status},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV(y9,{content:"Click to copy",children:w5.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(K)=>{K.stopPropagation(),hM0(Z.id)},children:Z.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV(y9,{content:"Click to copy",children:w5.jsxDEV("span",{className:"w-64 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(K)=>{if(K.stopPropagation(),Z.fields?.sessionId)hM0(Z.fields?.sessionId)},children:Z.fields?.sessionId?Z.fields?.sessionId.slice(0,24)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV("div",{className:"flex-1 min-w-0",children:[w5.jsxDEV("span",{className:"truncate text-sm font-medium block",children:Z.name},void 0,!1,void 0,this),X&&w5.jsxDEV(y9,{content:Z.fields?.workingDirectory,children:w5.jsxDEV("span",{className:"text-xs text-muted-foreground truncate block",children:X},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:Z.fields?.agent},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-24 truncate",children:Z.fields?.model||"-"},void 0,!1,void 0,this),w5.jsxDEV(y9,{content:"Click to copy",children:w5.jsxDEV("span",{className:"w-16 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary",onClick:(K)=>{if(K.stopPropagation(),Z.fields?.pid)hM0(Z.fields?.pid)},children:Z.fields?.pid||"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:sH8(Z.fields?.startedAt)},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:sH8(Z.fields?.completedAt)},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:zP9(Z.fields?.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var $4=W0(t0(),1);var a9=W0(N8(),1),WP9=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],nH8=({open:Z,onOpenChange:J,projectId:Q,onSuccess:X,initialPrompt:K=""})=>{let[Y,U]=$4.useState(""),[G,z]=$4.useState("claude"),[W,q]=$4.useState(""),[H,B]=$4.useState(""),[O,M]=$4.useState({type:"main",path:null}),[A,R]=$4.useState(""),[N,w]=$4.useState(""),[P,C]=$4.useState(!1),[T,$]=$4.useState(!0),[D,E]=$4.useState(!1),[j,b]=$4.useState(!1),[_,k]=$4.useState({}),[v,f]=$4.useState(!1),[h,x]=$4.useState(null),[g,m]=$4.useState(null),[u,d]=$4.useState(null),p=$4.useRef(null),s=Q?.charAt(0)||"A";$4.useEffect(()=>{if(K)R(K)},[K]),$4.useEffect(()=>{if(Z&&p.current){let m0=setTimeout(()=>{p.current?.focus()},50);return()=>clearTimeout(m0)}},[Z]);let{data:e,isLoading:J0,error:t}=uD(Z?Q:null),B0=e?.worktrees??[],n=e?.isGitProject??!0,H0=Qe(Q),Q0=ot(Q),U0=pD(Q),{data:Y0}=fD(Q,N.trim()||null),K0=Y0?.parameters??[],F0=Y0?.detectedVariables??[],z0=N.trim().length>0,V0=()=>{U(""),z("claude"),q(""),B(""),M({type:"main",path:null}),R(K||""),w(""),C(!1),$(!0),x(null),m(null),k({}),f(!1),E(!1)},O0=()=>{V0(),J(!1)},S0=()=>{if(O.type==="main")return;return O.path||void 0},X0=(m0)=>{H0.mutate({name:Y.trim()||void 0,agent:G,model:W.trim()||void 0,prompt:A.trim(),workingDirectory:m0,streaming:P,skipPermissions:T,dockerImage:H.trim()||void 0},{onSuccess:(b0)=>{if(O0(),X)X(b0)},onError:(b0)=>{if(b0.code==="DUPLICATE_NAME"){let G8=Y.trim()||cD(b0.message);if(G8)d({originalName:G8,suggestedName:xL(G8)});else x(b0.message)}else x(b0.message)}})},K8=()=>{if(!A.trim()){x("Prompt is required");return}if(O.type==="new"&&n){if(!O.branch||!O.branch.trim()){m("Branch name is required");return}}if(x(null),m(null),O.type==="new"&&n&&O.branch)U0.mutate({branch:O.branch.trim(),baseBranch:O.baseBranch?.trim()||void 0},{onSuccess:(m0)=>{X0(m0.path)},onError:(m0)=>{m(m0.message)}});else X0(S0())},C0=()=>{b(!0)},H8=(m0)=>{k(m0),Q0.mutate({id:N.trim(),params:m0,target:"stdout"},{onSuccess:(b0)=>{if(b0.content)R(b0.content);w(""),b(!1)},onError:(b0)=>{x(`Template render failed: ${b0.message}`),b(!1)}})},L8=z0?"render":"run",s0=L8==="run"&&!A.trim(),E0=U0.isPending,p0=H0.isPending||Q0.isPending||E0;return a9.jsxDEV(a9.Fragment,{children:[a9.jsxDEV(D6,{open:Z,onOpenChange:O0,children:a9.jsxDEV(O6,{className:"max-w-7xl",children:[a9.jsxDEV(M6,{children:a9.jsxDEV(L6,{children:"New Job"},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV("div",{className:"space-y-4 py-4",children:[a9.jsxDEV("div",{className:"grid grid-cols-4 gap-4",children:[a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-name",value:Y,onChange:(m0)=>U(m0.target.value),placeholder:"Auto-generated if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),a9.jsxDEV(IJ,{value:G,onValueChange:z,children:[a9.jsxDEV(BJ,{children:a9.jsxDEV(VJ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV(FJ,{children:WP9.map((m0)=>a9.jsxDEV(BZ,{value:m0.value,children:m0.label},m0.value,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-model",value:W,onChange:(m0)=>q(m0.target.value),placeholder:"Optional"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-docker-image",children:"Docker Image"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-docker-image",value:H,onChange:(m0)=>B(m0.target.value),placeholder:"Optional"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G==="claude"&&a9.jsxDEV("div",{className:"grid grid-cols-2 gap-4",children:[a9.jsxDEV("div",{className:"flex items-center gap-2",children:[a9.jsxDEV(g1,{id:"job-streaming",checked:P,onCheckedChange:C},void 0,!1,void 0,this),a9.jsxDEV(g6,{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),a9.jsxDEV("div",{className:"flex items-center gap-2",children:[a9.jsxDEV(g1,{id:"job-skip-permissions",checked:T,onCheckedChange:$},void 0,!1,void 0,this),a9.jsxDEV(g6,{htmlFor:"job-skip-permissions",className:"text-sm font-normal cursor-pointer",children:"Skip permission prompts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV("button",{type:"button",onClick:()=>f(!v),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[v?a9.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):a9.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),a9.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&a9.jsxDEV(gD,{value:O,onChange:M,worktrees:B0,isLoadingWorktrees:J0,isGitProject:n,error:t,createError:g,onCreateErrorClear:()=>m(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),a9.jsxDEV("div",{className:"relative",children:[a9.jsxDEV(oU,{ref:p,id:"job-prompt",value:A,onChange:(m0)=>R(m0.target.value),placeholder:"Enter the prompt for the agent...",rows:6,className:"pr-8"},void 0,!1,void 0,this),a9.jsxDEV(q8,{type:"button",variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-6 w-6",onClick:()=>E(!0),"aria-label":"Open in editor",children:a9.jsxDEV(Rz,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV(kH,{open:D,onOpenChange:E,value:A,onSave:(m0)=>{R(m0),E(!1)},projectId:Q,storeCode:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-template",value:N,onChange:(m0)=>w(m0.target.value),placeholder:"Template ID (optional)"},void 0,!1,void 0,this),z0&&a9.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),h&&a9.jsxDEV("div",{className:"text-sm text-destructive",children:h},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV(i6,{children:[a9.jsxDEV(q8,{variant:"outline",onClick:O0,children:"Cancel"},void 0,!1,void 0,this),L8==="render"?a9.jsxDEV(q8,{onClick:C0,disabled:p0,children:[a9.jsxDEV(G4,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),p0?"Rendering...":"Render"]},void 0,!0,void 0,this):a9.jsxDEV(q8,{onClick:K8,disabled:s0||p0,children:[a9.jsxDEV(pU,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),E0?"Creating worktree...":H0.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),a9.jsxDEV(D6,{open:j,onOpenChange:b,children:a9.jsxDEV(O6,{className:"max-w-7xl",children:[a9.jsxDEV(M6,{children:a9.jsxDEV(L6,{className:"flex items-center gap-2",children:[a9.jsxDEV(G4,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",wY(Y0?.path)," (",N,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV(Je,{fields:K0,detectedVariables:F0,initialValues:_,onSubmit:H8,onCancel:()=>b(!1),isSubmitting:Q0.isPending,autoFocusFirst:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),u&&a9.jsxDEV(D6,{open:!0,onOpenChange:()=>d(null),children:a9.jsxDEV(O6,{children:[a9.jsxDEV(M6,{children:a9.jsxDEV(L6,{children:"Duplicate Job Name"},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV("p",{children:['Job "',u.originalName,'" already exists.']},void 0,!0,void 0,this),a9.jsxDEV("p",{children:['Call it "',u.suggestedName,'"?']},void 0,!0,void 0,this),a9.jsxDEV(i6,{children:[a9.jsxDEV(q8,{variant:"outline",onClick:()=>d(null),children:"Cancel"},void 0,!1,void 0,this),a9.jsxDEV(q8,{onClick:()=>{let m0=u.suggestedName;U(m0),d(null),H0.mutate({name:m0,agent:G,model:W.trim()||void 0,prompt:A.trim(),workingDirectory:S0(),streaming:P,skipPermissions:T,dockerImage:H.trim()||void 0},{onSuccess:(b0)=>{if(O0(),X)X(b0)},onError:(b0)=>{if(b0.code==="DUPLICATE_NAME"){let G8=m0||cD(b0.message);if(G8)d({originalName:G8,suggestedName:xL(G8)});else x(b0.message)}else x(b0.message)}})},children:"OK"},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 rH8=5000;function Le(Z,J,Q){if(!Z||Z.length===0)return[];let X=new Map;for(let G of Z)X.set(G.id,{job:G,children:[],depth:0});let K=[];for(let G of Z){let z=X.get(G.id),W=G.fields?.parentJobId;if(!W||!X.has(W)||!G.fields?.blocking){K.push(z);continue}let q=!1,H=W,B=new Set;while(H&&X.has(H)){if(H===G.id){q=!0;break}if(B.has(H))break;B.add(H),H=X.get(H).job.fields?.parentJobId}if(q)K.push(z);else X.get(W).children.push(z)}let Y=(G,z)=>{for(let W of G)if(W.depth=z,W.children.length>0)Y(W.children,z+1)};Y(K,0);let U=(G)=>{G.sort((z,W)=>{if(J==="name"){let O=z.job.name??null,M=W.job.name??null;if(O===null&&M===null)return 0;if(O===null)return 1;if(M===null)return-1;let A=O.localeCompare(M);return Q==="desc"?-A:A}let q=J==="completedAt"?"completedAt":"startedAt",H=z.job.fields?.[q]?new Date(z.job.fields[q]).getTime():null,B=W.job.fields?.[q]?new Date(W.job.fields[q]).getTime():null;if(H===null&&B===null)return 0;if(H===null)return 1;if(B===null)return-1;return Q==="desc"?B-H:H-B});for(let z of G)if(z.children.length>0)U(z.children)};return U(K),K}var qP9=W0(t0(),1),B3=W0(N8(),1),Ae=({depth:Z,ancestorContinues:J,isLastChild:Q})=>{if(Z===0)return null;return B3.jsxDEV(B3.Fragment,{children:[J.slice(1).map((X,K)=>B3.jsxDEV("div",{className:"w-6 flex-shrink-0 relative",children:X&&B3.jsxDEV("div",{className:"absolute left-1/2 top-0 bottom-0 border-l border-border"},void 0,!1,void 0,this)},K,!1,void 0,this)),B3.jsxDEV("div",{className:"w-6 flex-shrink-0 relative",children:[B3.jsxDEV("div",{className:`absolute left-1/2 top-0 ${Q?"h-1/2":"bottom-0"} border-l border-border`},void 0,!1,void 0,this),B3.jsxDEV("div",{className:"absolute left-1/2 right-0 top-1/2 border-t border-border"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var u9=W0(N8(),1),aH8=50,oH8=25,yM0=[{value:"active",label:"Active",icon:uA},{value:"recent",label:"Recently Completed",icon:IB},{value:"history",label:"History",icon:gG}],HP9={active:["running","pending"],recent:["completed","error","stopped"],history:["completed","error","stopped"]},Ne=[{key:"startedAt-desc",icon:Lz,label:"Started date newest first"},{key:"startedAt-asc",icon:Az,label:"Started date oldest first"},{key:"completedAt-desc",icon:Lz,label:"Completed date newest first"},{key:"completedAt-asc",icon:Az,label:"Completed date oldest first"},{key:"name-asc",icon:hG,label:"Name A → Z"},{key:"name-desc",icon:xG,label:"Name Z → A"}],BP9=new Set(Ne.map((Z)=>Z.key)),gx=()=>{let{id:Z,storeCode:J}=YQ(),Q=PZ(),{data:X}=k4(Z);A1(X?`${X.name} - Jobs`:"CAW");let K=J??"A",{phase:Y,activeStatuses:U,setPhase:G,setActiveStatuses:z}=aT0(Z),[W,q]=PY(Z,"jobs","sortMode","startedAt-desc",K),[H,B]=PY(Z,"jobs","viewMode","flat",K),[O,M]=PY(Z,"jobs","page-active",1,K),[A,R]=PY(Z,"jobs","page-recent",1,K),[N,w]=PY(Z,"jobs","page-history",1,K),[P,C]=U1.useState(!1),[T,$]=U1.useState(""),[D,E]=U1.useState(new Set),j=U1.useRef(null),b=U1.useRef(!0);Rq(Z);let _=HP9[Y]??[],k=U1.useMemo(()=>{if(!U||U.length===0)return _;let s0=U.filter((E0)=>_.includes(E0));return s0.length>0?s0:_},[U,_]),v=U1.useMemo(()=>new Set(k),[k]),f=BP9.has(W)?W:"startedAt-desc",h=f.lastIndexOf("-"),x=f.substring(0,h),g=f.substring(h+1),m=Y==="active"?O:Y==="recent"?A:N,u=Y==="active"?M:Y==="recent"?R:w,d=H==="tree"?oH8:aH8,p=(m-1)*d,{data:s,isLoading:e,error:J0,refetch:t}=mD(Z,H==="tree"?{store:K,phase:Y,status:k,sortBy:x,sortDir:g,limit:oH8,offset:p,treeMode:!0}:{store:K,phase:Y,status:k,sortBy:x,sortDir:g,limit:aH8,offset:p}),B0=s?.jobs??[],n=s?.total??0,H0=n>0?Math.ceil(n/d):0,Q0=H0>0?Math.min(m,Math.max(1,H0)):1;gH(Z,"jobs","content",j,!e,K),U1.useEffect(()=>{if(J==="B")Q(`/project/${Z}/store/B/documents`,{replace:!0})},[J,Z,Q]),U1.useEffect(()=>{if(b.current){b.current=!1;return}u(1)},[Y,W,U]),U1.useEffect(()=>{if(!e&&n>0&&p>=n)u(Math.max(1,Math.ceil(n/d)))},[e,n,p,d]);let U0=H==="tree",Y0=U1.useMemo(()=>U0?Le(B0,x,g):[],[B0,U0,x,g]),K0=U1.useMemo(()=>{if(!U0)return[];let s0=(E0,p0=[])=>{let m0=[];for(let b0=0;b0<E0.length;b0++){let G8=E0[b0],D0=b0===E0.length-1;if(m0.push({...G8,isLastChild:D0,ancestorContinues:[...p0]}),G8.children.length>0&&D.has(G8.job.id))m0.push(...s0(G8.children,[...p0,!D0]))}return m0};return s0(Y0)},[Y0,D,U0]);if(J==="B")return null;if(e)return u9.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(J0)return u9.jsxDEV("div",{className:"p-6",children:[u9.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),u9.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:J0.message},void 0,!1,void 0,this),u9.jsxDEV(q8,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>t(),children:[u9.jsxDEV($B,{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);let F0=()=>{if(H==="flat")E(new Set);B(H==="tree"?"flat":"tree"),u(1)},z0=(s0)=>{E((E0)=>{let p0=new Set(E0);if(p0.has(s0))p0.delete(s0);else p0.add(s0);return p0})},V0=()=>{let s0=new Set,E0=(p0)=>{for(let m0 of p0)if(m0.children.length>0)s0.add(m0.job.id),E0(m0.children)};E0(Y0),E(s0)},O0=()=>{E(new Set)},S0=(s0)=>{let E0=U?new Set(U):new Set(_),p0=new Set(E0);if(p0.has(s0))p0.delete(s0);else p0.add(s0);z(p0.size===_.length?null:[...p0])},X0=(s0)=>{let E0=J?`/project/${Z}/store/${J}/job/${s0.id}?from=jobs`:`/project/${Z}/job/${s0.id}?from=jobs`;Q(E0)},K8=(s0)=>{if(s0?.id){let E0=J?`/project/${Z}/store/${J}/job/${s0.id}?from=jobs`:`/project/${Z}/job/${s0.id}?from=jobs`;Q(E0)}},C0=yM0.find((s0)=>s0.value===Y)??yM0[0],H8=Ne.find((s0)=>s0.key===f)??Ne[0],L8=!!U&&U.length>0;return u9.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[u9.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:[u9.jsxDEV("div",{className:"flex items-center gap-2",children:[u9.jsxDEV(q8,{size:"sm",variant:"warning",onClick:()=>C(!0),children:[u9.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),u9.jsxDEV(dG,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV(q3,{orientation:"vertical",className:"h-6 mx-2"},void 0,!1,void 0,this),u9.jsxDEV(A4,{children:[u9.jsxDEV(y9,{content:H8.label,children:u9.jsxDEV(sQ,{asChild:!0,children:u9.jsxDEV(q8,{size:"sm",variant:"outline",children:U1.default.createElement(H8.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(nQ,{align:"start",children:Ne.map((s0)=>u9.jsxDEV(z6,{onClick:()=>q(s0.key),className:W===s0.key?"bg-accent":"",children:[u9.jsxDEV(s0.icon,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),s0.label]},s0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV(DL,{children:[u9.jsxDEV(y9,{content:"Filter by status",children:u9.jsxDEV(EL,{asChild:!0,children:u9.jsxDEV(q8,{size:"sm",variant:"outline",children:u9.jsxDEV(Zq,{className:"w-4 h-4",...L8&&{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),u9.jsxDEV(G3,{align:"start",children:u9.jsxDEV("div",{className:"space-y-2",children:[u9.jsxDEV("div",{className:"text-sm font-medium",children:"Show by status:"},void 0,!1,void 0,this),_.map((s0)=>u9.jsxDEV("label",{className:"flex items-center gap-2",children:[u9.jsxDEV(g1,{checked:v.has(s0),onCheckedChange:()=>S0(s0)},void 0,!1,void 0,this),u9.jsxDEV("span",{className:"text-sm capitalize",children:s0},void 0,!1,void 0,this)]},s0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV(y9,{content:U0?"Switch to flat list":"Switch to tree view",children:u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:F0,children:U0?u9.jsxDEV(nX,{className:"w-4 h-4"},void 0,!1,void 0,this):u9.jsxDEV(gA,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),U0&&u9.jsxDEV(u9.Fragment,{children:[u9.jsxDEV(y9,{content:"Expand all",children:u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:V0,children:u9.jsxDEV(mA,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(y9,{content:"Collapse all",children:u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:O0,children:u9.jsxDEV(VB,{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),u9.jsxDEV(A4,{children:[u9.jsxDEV(y9,{content:"Phase",children:u9.jsxDEV(sQ,{asChild:!0,children:u9.jsxDEV(q8,{variant:"outline",size:"sm",children:[U1.default.createElement(C0.icon,{className:"w-4 h-4 mr-1"}),C0.label,u9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(nQ,{align:"start",children:yM0.map((s0)=>u9.jsxDEV(z6,{onClick:()=>G(s0.value),className:Y===s0.value?"bg-accent":"",children:[u9.jsxDEV(s0.icon,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),s0.label]},s0.value,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV("div",{className:"flex items-center gap-2",children:H0>1&&u9.jsxDEV(u9.Fragment,{children:[u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>u((s0)=>s0-1),disabled:Q0===1,children:u9.jsxDEV(Nz,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV("span",{className:"text-sm text-muted-foreground px-2",children:["Page ",Q0," of ",H0]},void 0,!0,void 0,this),u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>u((s0)=>s0+1),disabled:Q0===H0,children:u9.jsxDEV(tZ,{className:"w-4 h-4"},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),u9.jsxDEV("div",{ref:j,className:"flex-1 overflow-auto",children:B0.length===0?L8?u9.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No jobs match the current filters"},void 0,!1,void 0,this):u9.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No jobs in this phase"},void 0,!1,void 0,this):U0?u9.jsxDEV("div",{children:K0.map((s0)=>{let E0=D.has(s0.job.id);return u9.jsxDEV("div",{className:"flex items-stretch min-w-0",children:[u9.jsxDEV(Ae,{depth:s0.depth,ancestorContinues:s0.ancestorContinues,isLastChild:s0.isLastChild},void 0,!1,void 0,this),u9.jsxDEV("div",{className:"flex-shrink-0 w-5 flex items-center justify-center self-center",children:s0.children.length>0?u9.jsxDEV("button",{className:"flex items-center justify-center text-muted-foreground hover:text-foreground",onClick:(p0)=>{p0.stopPropagation(),z0(s0.job.id)},children:u9.jsxDEV(tZ,{className:`w-3.5 h-3.5 transition-transform duration-150 ${E0?"rotate-90":""}`},void 0,!1,void 0,this)},void 0,!1,void 0,this):u9.jsxDEV("span",{className:"w-3.5 h-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV("div",{className:"flex-1 min-w-0",children:u9.jsxDEV(iD,{job:s0.job,onClick:X0,projectPath:X?.path},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},s0.job.id,!0,void 0,this)})},void 0,!1,void 0,this):u9.jsxDEV("div",{children:B0.map((s0)=>u9.jsxDEV(iD,{job:s0,onClick:X0,projectPath:X?.path},s0.id,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(nH8,{open:P,onOpenChange:(s0)=>{if(C(s0),!s0)$("")},projectId:Z,onSuccess:K8,initialPrompt:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var QZ=W0(t0(),1);var gM0=W0(t0(),1);var mx=W0(N8(),1),ux=({value:Z,disabled:J=!1,className:Q=""})=>{let[X,K]=gM0.useState(!1);return mx.jsxDEV(y9,{content:"Copy to clipboard",children:mx.jsxDEV(q8,{variant:"ghost",size:"sm",onClick:async()=>{if(J)return;await navigator.clipboard.writeText(Z),K(!0),setTimeout(()=>K(!1),2000)},disabled:J,className:Q,children:X?mx.jsxDEV(_5,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):mx.jsxDEV(uZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var FP9=W0(t0(),1);var t4=W0(N8(),1),tH8=({id:Z,name:J,content:Q,deepLinkUrl:X,variant:K="icon",align:Y="end"})=>{return t4.jsxDEV(A4,{children:[K==="icon"?t4.jsxDEV(y9,{content:"Copy options",children:t4.jsxDEV(sQ,{asChild:!0,onClick:(G)=>G.stopPropagation(),children:t4.jsxDEV(q8,{variant:"ghost",size:"sm",children:t4.jsxDEV(uZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this):t4.jsxDEV(sQ,{asChild:!0,children:t4.jsxDEV(q8,{variant:"outline",size:"sm",children:[t4.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",t4.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),t4.jsxDEV(nQ,{align:Y,children:[Q&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(Q),a8.success("Content copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),Z&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(Z),a8.success("ID copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy ID"]},void 0,!0,void 0,this),J&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(J),a8.success("Name copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),Z&&J&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(`[${J}](${Z})`),a8.success("MD Link copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),X&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(X),a8.success("URL copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var kX=W0(t0(),1);var V6=W0(N8(),1),eH8=({open:Z,onOpenChange:J,jobName:Q,sessionId:X,agent:K,currentModel:Y,streaming:U,workingDirectory:G,dockerImage:z,skipPermissions:W,projectId:q,onContinue:H,isLoading:B})=>{let[O,M]=kX.useState(""),[A,R]=kX.useState(""),[N,w]=kX.useState(!1),[P,C]=kX.useState(""),[T,$]=kX.useState(!0),[D,E]=kX.useState({type:"main",path:null}),[j,b]=kX.useState(!1),[_,k]=kX.useState(null),[v,f]=kX.useState(!1),h=kX.useRef(null),x=q?.charAt(0)||"A",{data:g,isLoading:m,error:u}=uD(Z?q:null),d=g?.worktrees??[],p=g?.isGitProject??!0,s=pD(q);kX.useEffect(()=>{if(!Z)M(""),R(""),w(!1),C(""),$(!0),E({type:"main",path:null}),b(!1),k(null),f(!1);else R(Y||""),w(U??!1),C(z||""),$(W??!0)},[Z,Y,U,z,W]),kX.useEffect(()=>{if(Z&&g&&G)if(d.find((H0)=>H0.path===G))E({type:"worktree",path:G});else E({type:"main",path:null})},[Z,g,G,d]),kX.useEffect(()=>{if(Z&&h.current){let n=setTimeout(()=>{h.current?.focus()},50);return()=>clearTimeout(n)}},[Z]);let e=()=>{if(D.type==="main")return null;if(D.type==="worktree")return D.path;return null},J0=(n)=>{n.preventDefault();let H0=O.trim();if(!H0)return;if(k(null),D.type==="new"&&p&&D.branch)s.mutate({branch:D.branch.trim(),baseBranch:D.baseBranch?.trim()||void 0},{onSuccess:(Q0)=>{H({prompt:H0,model:A.trim()||void 0,streaming:N,workingDirectory:Q0.path,dockerImage:P.trim()||void 0,skipPermissions:T})},onError:(Q0)=>{k(Q0.message)}});else H({prompt:H0,model:A.trim()||void 0,streaming:N,workingDirectory:e(),dockerImage:P.trim()||void 0,skipPermissions:T})},t=()=>{M(""),R(""),w(!1),C(""),$(!0),E({type:"main",path:null}),b(!1),k(null),f(!1),J(!1)},B0=!O.trim()||B||s.isPending;return V6.jsxDEV(D6,{open:Z,onOpenChange:t,children:V6.jsxDEV(O6,{className:"max-w-7xl",children:[V6.jsxDEV(M6,{children:V6.jsxDEV(L6,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),V6.jsxDEV("form",{onSubmit:J0,className:"space-y-4",children:[V6.jsxDEV("div",{className:"grid grid-cols-4 gap-4",children:[V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-name",children:"Name"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-name",value:Q||"",readOnly:!0,className:"text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-agent",children:"Agent"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-agent",value:K||"",readOnly:!0,className:"text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-model",children:"Model"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-model",value:A,onChange:(n)=>R(n.target.value),placeholder:"Optional - uses current model if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-docker-image",children:"Docker Image"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-docker-image",value:P,onChange:(n)=>C(n.target.value),placeholder:"Optional"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"session-id",value:X||"",readOnly:!0,className:"font-mono text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K==="claude"&&V6.jsxDEV("div",{className:"grid grid-cols-2 gap-4",children:[V6.jsxDEV("div",{className:"flex items-center gap-2",children:[V6.jsxDEV(g1,{id:"continue-streaming",checked:N,onCheckedChange:w},void 0,!1,void 0,this),V6.jsxDEV(g6,{htmlFor:"continue-streaming",className:"text-sm font-normal cursor-pointer",children:"Enable streaming output"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"flex items-center gap-2",children:[V6.jsxDEV(g1,{id:"continue-skip-permissions",checked:T,onCheckedChange:$},void 0,!1,void 0,this),V6.jsxDEV(g6,{htmlFor:"continue-skip-permissions",className:"text-sm font-normal cursor-pointer",children:"Skip permission prompts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"space-y-2",children:[V6.jsxDEV("button",{type:"button",onClick:()=>b(!j),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[j?V6.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):V6.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),V6.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&V6.jsxDEV(gD,{value:D,onChange:E,worktrees:d,isLoadingWorktrees:m,isGitProject:p,error:u,createError:_,onCreateErrorClear:()=>k(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),V6.jsxDEV("div",{className:"relative",children:[V6.jsxDEV(oU,{ref:h,id:"continue-prompt",value:O,onChange:(n)=>M(n.target.value),placeholder:"Enter your follow-up prompt...",rows:6,className:"pr-8",autoFocus:!0},void 0,!1,void 0,this),V6.jsxDEV(q8,{type:"button",variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-6 w-6",onClick:()=>f(!0),"aria-label":"Open in editor",children:V6.jsxDEV(Rz,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),V6.jsxDEV(kH,{open:v,onOpenChange:f,value:O,onSave:(n)=>{M(n),f(!1)},projectId:q,storeCode:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV(i6,{children:[V6.jsxDEV(q8,{type:"button",variant:"outline",onClick:t,children:"Cancel"},void 0,!1,void 0,this),V6.jsxDEV(q8,{type:"submit",disabled:B0,children:[(B||s.isPending)&&V6.jsxDEV(G7,{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 OP9=W0(t0(),1);var P5=W0(N8(),1),ZB8=({open:Z,onOpenChange:J,projectId:Q,jobId:X,pid:K})=>{let{data:Y,isLoading:U,error:G,refetch:z}=WH8(Q,X,Z),W=()=>{if(U)return P5.jsxDEV(G7,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this);if(G)return P5.jsxDEV(w7,{className:"w-5 h-5 text-destructive"},void 0,!1,void 0,this);if(Y?.exists)return P5.jsxDEV(yG,{className:"w-5 h-5 text-green-600"},void 0,!1,void 0,this);return P5.jsxDEV(tW,{className:"w-5 h-5 text-muted-foreground"},void 0,!1,void 0,this)},q=()=>{if(U)return"Checking process...";if(G)return`Error: ${G.message}`;if(Y?.error)return Y.error;if(!Y?.exists)return"Process not running";return`Process is ${Y.state||"active"}`};return P5.jsxDEV(D6,{open:Z,onOpenChange:J,children:P5.jsxDEV(O6,{children:[P5.jsxDEV(M6,{children:P5.jsxDEV(L6,{children:"Process Diagnostics"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P5.jsxDEV("div",{className:"space-y-4",children:[P5.jsxDEV("div",{className:"flex items-center gap-3 p-4 border rounded-lg",children:[W(),P5.jsxDEV("div",{children:[P5.jsxDEV("p",{className:"font-medium",children:q()},void 0,!1,void 0,this),P5.jsxDEV("p",{className:"text-sm text-muted-foreground font-mono",children:["PID: ",K]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y?.exists&&Y?.command&&P5.jsxDEV("div",{className:"text-sm",children:[P5.jsxDEV("span",{className:"font-medium",children:"Command: "},void 0,!1,void 0,this),P5.jsxDEV("span",{className:"font-mono",children:Y.command},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P5.jsxDEV(i6,{children:[P5.jsxDEV(q8,{variant:"outline",onClick:()=>z(),children:"Refresh"},void 0,!1,void 0,this),P5.jsxDEV(q8,{onClick:()=>J(!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 u8=W0(N8(),1),MP9=({status:Z})=>{let J={running:{icon:G7,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:yG,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:tW,class:"text-red-700 border-red-300 bg-red-50",animate:!1},stopped:{icon:i3,class:"text-orange-700 border-orange-300 bg-orange-50",animate:!1},pending:{icon:IB,class:"text-gray-700 border-gray-300 bg-gray-50",animate:!1}},{icon:Q,class:X,animate:K}=J[Z]||J.pending;return u8.jsxDEV("span",{className:`inline-flex items-center gap-1.5 rounded border px-2 py-1 text-sm font-medium ${X}`,children:[u8.jsxDEV(Q,{className:`w-4 h-4 ${K?"animate-spin":""}`},void 0,!1,void 0,this),Z]},void 0,!0,void 0,this)},JB8=(Z)=>{if(!Z)return"-";return new Date(Z).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})},LP9=(Z)=>{if(Z===null||Z===void 0)return"-";let J=parseInt(Z,10);if(isNaN(J))return Z;if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},mM0=(Z)=>{if(!Z)return[];let J=/---\n## Turn (\d+)\n/g,Q=[...Z.matchAll(J)];if(Q.length===0)return[{turnNumber:1,content:Z.trim()}];let X=[],K=Q[0].index,Y=Z.slice(0,K).trim();if(Y)X.push({turnNumber:1,content:Y});for(let U=0;U<Q.length;U++){let G=Q[U],z=parseInt(G[1],10),W=G.index+G[0].length,q=Q[U+1]?.index??Z.length,H=Z.slice(W,q).trim();X.push({turnNumber:z,content:H})}return X},AP9=(Z)=>{if(!Z||!Array.isArray(Z))return!1;return Z.some((J)=>J.name==="prompt.md")},NP9=(Z)=>{if(!Z||!Array.isArray(Z))return[];let J=/^prompt-(\d+)\.md$/,Q=/^output-(\d+)\.md$/,X=Z.filter((Y)=>Y.name&&J.test(Y.name)).map((Y)=>({...Y,turnNumber:parseInt(Y.name.match(J)[1],10)})).sort((Y,U)=>Y.turnNumber-U.turnNumber),K=Z.filter((Y)=>Y.name&&Q.test(Y.name)).reduce((Y,U)=>{let G=U.name.match(Q);if(G)Y[parseInt(G[1],10)]=U;return Y},{});return X.map((Y)=>({turnNumber:Y.turnNumber,promptDoc:Y,outputDoc:K[Y.turnNumber]||null}))},Re=({title:Z,docId:J,docName:Q,docContent:X,isOpen:K,onToggle:Y,deepLinkUrl:U,onFieldsClick:G,children:z})=>u8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[u8.jsxDEV("div",{role:"button",tabIndex:0,onClick:()=>Y(!K),onKeyDown:(W)=>{if(W.key==="Enter"||W.key===" ")W.preventDefault(),Y(!K)},className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[K?u8.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):u8.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),u8.jsxDEV(G4,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"font-medium",children:Z},void 0,!1,void 0,this),J&&u8.jsxDEV("span",{className:"text-xs text-muted-foreground ml-auto font-mono flex items-center gap-1",children:[G&&u8.jsxDEV(q8,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:(W)=>{W.stopPropagation(),G()},children:u8.jsxDEV(WT,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),J,u8.jsxDEV(tH8,{id:J,name:Q,content:X,deepLinkUrl:U,variant:"icon"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),K&&u8.jsxDEV("div",{className:"p-4",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),uM0=({turnNumber:Z,promptContent:J,outputContent:Q,showHeading:X,promptDocId:K,outputDocId:Y,promptDocName:U,outputDocName:G,isPromptOpen:z,setIsPromptOpen:W,isOutputOpen:q,setIsOutputOpen:H,onInternalLinkClick:B,promptDeepLinkUrl:O,outputDeepLinkUrl:M,sectionRef:A,highlightedSection:R,onPromptFieldsClick:N,onOutputFieldsClick:w})=>{return u8.jsxDEV("div",{className:"space-y-4",ref:R?A:null,children:[X&&u8.jsxDEV("h3",{className:"text-lg font-semibold text-muted-foreground",children:["Turn ",Z]},void 0,!0,void 0,this),Q&&u8.jsxDEV(Re,{title:"Output",docId:Y,docName:G,docContent:Q,isOpen:q,onToggle:H,deepLinkUrl:M,onFieldsClick:w,children:u8.jsxDEV(MK,{markdown:Q,onInternalLinkClick:B},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(Re,{title:"Prompt",docId:K,docName:U,docContent:J,isOpen:z,onToggle:W,deepLinkUrl:O,onFieldsClick:N,children:u8.jsxDEV(MK,{markdown:J||"",onInternalLinkClick:B},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},QB8=({content:Z,isOpen:J,onToggle:Q,onInternalLinkClick:X})=>u8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[u8.jsxDEV("div",{role:"button",tabIndex:0,onClick:()=>Q(!J),onKeyDown:(K)=>{if(K.key==="Enter"||K.key===" ")K.preventDefault(),Q(!J)},className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[J?u8.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):u8.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),u8.jsxDEV(Yj,{className:"w-4 h-4 text-blue-500 animate-pulse"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"font-medium",children:"Output"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&u8.jsxDEV("div",{className:"p-4",children:Z?u8.jsxDEV("div",{className:"overflow-auto max-h-[600px]",children:u8.jsxDEV(MK,{markdown:Z,onInternalLinkClick:X},void 0,!1,void 0,this)},void 0,!1,void 0,this):u8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-4",children:[u8.jsxDEV(G7,{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),RP9=86400000,wP9=["active","history"],pM0=()=>{let{id:Z,storeCode:J,jobId:Q}=YQ(),X=PZ(),K=sJ(),{data:Y}=k4(Z),{fromContext:U}=hL(),G=new URLSearchParams(K.search).get("doc");A1(Y?`${Y.name} - Job: ${Q}`:"CAW"),Rq(Z);let[z,W]=QZ.useState(""),[q,H]=QZ.useState(!1),B=QZ.useRef(null),O=QZ.useRef(!1),{data:M,isLoading:A,error:R}=YH8(Z,Q),{data:N,isLoading:w}=UH8(Z,Q),{isLegacy:P,promptDoc:C,outputDoc:T,turns:$}=QZ.useMemo(()=>{if(!N)return{isLegacy:!0,promptDoc:null,outputDoc:null,turns:[]};let g0=N.documents||[];if(AP9(g0)){let Q8=g0.find((h0)=>h0.name==="prompt.md"),L0=g0.find((h0)=>h0.name==="output.md");return{isLegacy:!0,promptDoc:Q8,outputDoc:L0,turns:[]}}else{let Q8=NP9(g0),L0=Q8[Q8.length-1];return{isLegacy:!1,promptDoc:L0?.promptDoc||null,outputDoc:L0?.outputDoc||null,turns:Q8}}},[N]),{data:D}=VW(Z,P?C?.id:null),{data:E}=VW(Z,P?T?.id:null),j=QZ.useMemo(()=>{if(P)return[];let g0=[];for(let r0 of $){if(r0.promptDoc?.id)g0.push(r0.promptDoc.id);if(r0.outputDoc?.id)g0.push(r0.outputDoc.id)}return g0},[P,$]),b=bA({queries:j.map((g0)=>({queryKey:["document",g0],queryFn:()=>gz(Z,g0),enabled:!!Z&&!!g0&&!P}))}),_=QZ.useMemo(()=>{if(P)return{};let g0={};return j.forEach((r0,Q8)=>{let L0=b[Q8];if(L0?.data)g0[r0]=L0.data}),g0},[P,j,b]),k=QZ.useMemo(()=>{if(P)return E;let g0=$[$.length-1];return g0?.outputDoc?.id?_[g0.outputDoc.id]:null},[P,E,$,_]),{promptTurns:v,outputTurns:f,completedOutputTurns:h}=QZ.useMemo(()=>{if(P){let g0=D?.draftContent??D?.publishedContent??"",r0=E?.draftContent??E?.publishedContent??"",Q8=mM0(g0),L0=mM0(r0),h0=mM0(E?.publishedContent??"");return{promptTurns:Q8,outputTurns:L0,completedOutputTurns:h0}}else{let g0=$.map((L0)=>{let h0=L0.promptDoc?.id?_[L0.promptDoc.id]:null,e0=h0?.draftContent??h0?.publishedContent??"";return{turnNumber:L0.turnNumber,content:e0}}),r0=$.map((L0)=>{let h0=L0.outputDoc?.id?_[L0.outputDoc.id]:null,e0=h0?.draftContent??h0?.publishedContent??"";return{turnNumber:L0.turnNumber,content:e0}}),Q8=r0.slice(0,-1);return{promptTurns:g0,outputTurns:r0,completedOutputTurns:Q8}}},[P,D,E,$,_]),x=v.length>1||f.length>1,g=async({type:g0,id:r0,path:Q8,anchor:L0})=>{if(g0==="anchor"){X(`${K.pathname}${K.search}#${L0}`,{replace:!0});return}if(g0==="id"){let P0=r0?.charAt(1)?.toLowerCase();if(P0==="d"||P0==="t"){O0({id:r0,anchor:L0||null});return}}let h0=L0?`#${L0}`:"",e0=J?`/store/${J}`:"";if(g0==="id"){let P0=r0?.charAt(1)?.toLowerCase();if(P0==="j")X(`/project/${Z}${e0}/job/${r0}${h0}`);else if(P0==="s")X(`/project/${Z}${e0}/story/${r0}${h0}`);else if(P0==="f")try{let M8=await u5(Z,r0),w8=M8?.path||"";if(w8.startsWith("Templates/"))X(`/project/${Z}${e0}/templates?id=${r0}${h0}`);else if(w8.startsWith("Stories/")){let h8=M8?.parentId?.startsWith("As")?M8.parentId:null;if(!h8){let c8=M8?.parentId?await u5(Z,M8.parentId):null;while(c8&&!h8)if(c8.parentId?.startsWith("As"))h8=c8.parentId;else if(c8.id?.startsWith("As"))h8=c8.id;else c8=c8.parentId?await u5(Z,c8.parentId):null}if(h8)X(`/project/${Z}${e0}/story/${h8}?id=${r0}&tab=documents${h0}`);else X(`/project/${Z}${e0}/stories?id=${r0}${h0}`)}else X(`/project/${Z}${e0}/documents?id=${r0}${h0}`)}catch{X(`/project/${Z}${e0}/documents?id=${r0}${h0}`)}else X(`/project/${Z}${e0}/documents?id=${r0}${h0}`)}else if(g0==="path")X(`/project/${Z}${e0}${Q8}${h0}`)},[m,u]=QZ.useState({}),[d,p]=QZ.useState(!0),s=Math.max(v.length,f.length);QZ.useEffect(()=>{u((g0)=>{let r0={...g0};for(let Q8=0;Q8<s;Q8++)if(!(Q8 in r0))r0[Q8]={promptOpen:!0,outputOpen:!0};return r0})},[s]);let e=QZ.useRef(null);QZ.useEffect(()=>{if(!G)return;if(G!==C?.id&&G!==T?.id)return;let g0=G===C?.id,r0=G===T?.id;u(()=>{let Q8={};for(let L0=0;L0<s;L0++)Q8[L0]={promptOpen:g0,outputOpen:r0};return Q8})},[G,C?.id,T?.id,s]),QZ.useEffect(()=>{if(G&&e.current)setTimeout(()=>{e.current?.scrollIntoView({behavior:"smooth",block:"start"})},100)},[G]);let J0=`${window.location.origin}${K.pathname}`,t=C?.id?`${J0}?doc=${C.id}${U?`&from=${U}`:""}`:null,B0=T?.id?`${J0}?doc=${T.id}${U?`&from=${U}`:""}`:null,n=G===C?.id?"prompt":G===T?.id?"output":null,H0=M?.fields?.status,Q0=M?.fields?.streaming==="true";QZ.useEffect(()=>{O.current=!1},[Q]),QZ.useEffect(()=>{if(H0!=="running"||!Q0){if(q&&H0!=="running")H(!1);return}if(W(""),H(!0),B.current)return;let g0=`/api/p/${Z}/events`,r0=new EventSource(g0);return B.current=r0,r0.addEventListener("jobOutputChunk",(Q8)=>{try{let{id:L0,chunk:h0}=JSON.parse(Q8.data);if(L0===Q&&h0)W((e0)=>e0+h0)}catch{}}),r0.addEventListener("jobCompleted",(Q8)=>{try{let{id:L0}=JSON.parse(Q8.data);if(L0===Q)H(!1),r0.close(),B.current=null}catch{}}),r0.addEventListener("jobStatusChanged",(Q8)=>{try{let{id:L0,newStatus:h0}=JSON.parse(Q8.data);if(L0===Q&&h0!=="running")H(!1),r0.close(),B.current=null}catch{}}),()=>{r0.close(),B.current=null}},[Z,Q,H0,Q0]),QZ.useEffect(()=>{let g0=k;if(H0!=="running"||!Q0)return;if(O.current)return;if(g0===void 0)return;let r0=g0?.draftContent??"";if(!r0)return;W(r0),O.current=!0},[H0,Q0,k]);let U0=()=>{u((g0)=>{let r0={};for(let Q8 of Object.keys(g0))r0[Q8]={promptOpen:!1,outputOpen:!1};return r0})},Y0=()=>{u((g0)=>{let r0={};for(let Q8 of Object.keys(g0))r0[Q8]={promptOpen:!0,outputOpen:!0};return r0})},K0=async()=>{try{await navigator.clipboard.writeText(Q),a8.success("ID copied")}catch(g0){console.error("Failed to copy ID:",g0)}},F0=(g0)=>{if(!g0)return"active";if(g0.fields?.status==="running")return"active";if(g0.fields?.completedAt){let r0=new Date(g0.fields?.completedAt).getTime(),Q8=Date.now()-RP9;if(r0>Q8)return"active"}return"history"},z0=()=>{let g0=U||K.state?.fromStory||K.state?.fromTab;if(g0?.startsWith("As")){let L0=J?`/project/${Z}/store/${J}/story/${g0}?tab=jobs`:`/project/${Z}/story/${g0}?tab=jobs`;X(L0);return}let r0=wP9.includes(g0)?g0:F0(M),Q8=J?`/project/${Z}/store/${J}/jobs/${r0}`:`/project/${Z}/jobs/${r0}`;X(Q8)},[V0,O0]=QZ.useState(null),[S0,X0]=QZ.useState(!1),K8=GH8(Z,Q),C0=qH8(Z),[H8,L8]=QZ.useState(!1),[s0,E0]=QZ.useState(!1),[p0,m0]=QZ.useState({}),[b0,G8]=QZ.useState({}),{data:D0}=aY(Z,Q),j0=oY(Z),Z0=QZ.useMemo(()=>{let g0=new Set;for(let r0 of Object.keys(b0)){let Q8=p0[r0]??"",L0=b0[r0]??"";if(Array.isArray(Q8)&&Array.isArray(L0)){if(JSON.stringify(Q8)!==JSON.stringify(L0))g0.add(r0)}else if(Q8!==L0)g0.add(r0)}return g0},[p0,b0]);QZ.useEffect(()=>{if(D0)m0(D0),G8(D0)},[D0]);let T0=QZ.useCallback((g0,r0)=>{G8((Q8)=>({...Q8,[g0]:r0}))},[]),i=QZ.useCallback(async()=>{let g0=Object.entries(b0).filter(([Q8,L0])=>{if(L0===null)return!1;let h0=p0[Q8]??"";if(Array.isArray(h0)&&Array.isArray(L0))return JSON.stringify(h0)!==JSON.stringify(L0);return h0!==L0}),r0={};for(let[Q8,L0]of g0)try{if(Array.isArray(L0))await j0.mutateAsync({entityId:Q,fieldName:Q8,values:L0});else await j0.mutateAsync({entityId:Q,fieldName:Q8,value:L0});r0[Q8]=L0}catch(h0){a8.error(`Failed to save ${Q8}: ${h0.message}`)}if(Object.keys(r0).length>0)m0((Q8)=>({...Q8,...r0}));if(Object.keys(r0).length===g0.length)a8.success("Fields saved")},[b0,p0,Q,j0]),N0=QZ.useCallback(()=>{G8({...p0})},[p0]),[A0,x0]=QZ.useState(null),v0=(M?.fields?.status==="completed"||M?.fields?.status==="error"||M?.fields?.status==="stopped")&&M?.fields?.sessionId,f0=async({prompt:g0,model:r0,streaming:Q8,workingDirectory:L0,dockerImage:h0,skipPermissions:e0})=>{await K8.mutateAsync({prompt:g0,model:r0,streaming:Q8,workingDirectory:L0,dockerImage:h0,skipPermissions:e0}),X0(!1)},[n0,c0]=QZ.useState(!1),[B8,C8]=QZ.useState(""),[x8,W8]=QZ.useState(null),l0=zH8(Z),y0=()=>{C8(M.name),W8(null),c0(!0)},i0=async()=>{let g0=B8.trim();if(!g0||g0===M.name){c0(!1),W8(null);return}try{await l0.mutateAsync({id:Q,name:g0}),c0(!1),W8(null)}catch(r0){let Q8=r0?.message||"Failed to rename job";W8(Q8)}},$0=(g0)=>{if(g0.key==="Enter")g0.preventDefault(),i0();if(g0.key==="Escape")c0(!1),W8(null)},A8=(g0)=>{if(C8(g0.target.value),x8)W8(null)},o0=q&&h.length>0;if(A)return u8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:u8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground",children:[u8.jsxDEV(G7,{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(R||!M)return u8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:u8.jsxDEV("div",{className:"text-center",children:[u8.jsxDEV(w7,{className:"w-8 h-8 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),u8.jsxDEV("p",{className:"text-destructive font-medium",children:"Failed to load job"},void 0,!1,void 0,this),u8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-1",children:R?.message||"Job not found"},void 0,!1,void 0,this),u8.jsxDEV(q8,{variant:"outline",className:"mt-4",onClick:z0,children:[u8.jsxDEV(LB,{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 u8.jsxDEV("div",{className:"h-full flex flex-col p-6 overflow-auto",children:[u8.jsxDEV("div",{className:"flex items-start gap-4 mb-6",children:[u8.jsxDEV(q8,{variant:"ghost",size:"sm",onClick:z0,children:u8.jsxDEV(LB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV("div",{className:"flex-1",children:[u8.jsxDEV("div",{className:"flex items-center gap-3 mb-2",children:[n0?u8.jsxDEV("input",{type:"text",value:B8,onChange:A8,onBlur:i0,onKeyDown:$0,autoFocus:!0,className:"text-xl font-semibold px-2 py-1 border border-input rounded bg-background"},void 0,!1,void 0,this):u8.jsxDEV(u8.Fragment,{children:[u8.jsxDEV("h1",{className:"text-xl font-semibold",children:M.name},void 0,!1,void 0,this),u8.jsxDEV(y9,{content:"Rename job",children:u8.jsxDEV(q8,{variant:"ghost",size:"sm",onClick:y0,children:u8.jsxDEV(Q5,{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),u8.jsxDEV(MP9,{status:M.fields?.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x8&&u8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center gap-2 text-destructive",children:[u8.jsxDEV(w7,{className:"w-4 h-4"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"text-sm",children:x8},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u8.jsxDEV("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Agent:"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"capitalize",children:M.fields?.agent},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.model&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Model:"},void 0,!1,void 0,this),M.fields?.model]},void 0,!0,void 0,this),u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Started:"},void 0,!1,void 0,this),JB8(M.fields?.startedAt)]},void 0,!0,void 0,this),M.fields?.completedAt&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Completed:"},void 0,!1,void 0,this),JB8(M.fields?.completedAt)]},void 0,!0,void 0,this),M.fields?.tokensUsed&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Tokens:"},void 0,!1,void 0,this),LP9(M.fields?.tokensUsed)]},void 0,!0,void 0,this),Me(M.fields?.workingDirectory,Y?.path)&&u8.jsxDEV(y9,{content:M.fields?.workingDirectory,children:u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Location:"},void 0,!1,void 0,this),Me(M.fields?.workingDirectory,Y?.path)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.fields?.status==="completed"&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Session:"},void 0,!1,void 0,this),u8.jsxDEV("span",{children:M.fields?.sessionId||"-"},void 0,!1,void 0,this),u8.jsxDEV(ux,{value:M.fields?.sessionId||"",disabled:!M.fields?.sessionId},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.pid&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"PID:"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"font-mono",children:M.fields.pid},void 0,!1,void 0,this),u8.jsxDEV(ux,{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&&(M.fields?.status==="stopped"?u8.jsxDEV("div",{className:"mt-3 p-3 bg-orange-50 border border-orange-200 rounded-md",children:[u8.jsxDEV("p",{className:"text-sm text-orange-700 font-medium",children:"Stopped"},void 0,!1,void 0,this),u8.jsxDEV("p",{className:"text-sm text-orange-600 mt-1",children:M.fields?.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this):u8.jsxDEV("div",{className:"mt-3 p-3 bg-destructive/10 border border-destructive/30 rounded-md",children:[u8.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error"},void 0,!1,void 0,this),u8.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),u8.jsxDEV("div",{className:"flex items-center gap-2",children:[u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>E0(!0),children:[u8.jsxDEV(WT,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Fields"]},void 0,!0,void 0,this),v0&&u8.jsxDEV(q8,{variant:"default",size:"sm",onClick:()=>X0(!0),children:[u8.jsxDEV(Xj,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Continue Conversation"]},void 0,!0,void 0,this),M.fields?.status==="running"&&u8.jsxDEV(q8,{variant:"destructive",size:"sm",onClick:()=>C0.mutate({id:Q}),disabled:C0.isPending,children:[C0.isPending?u8.jsxDEV(G7,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this):u8.jsxDEV(zj,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Stop Job"]},void 0,!0,void 0,this),u8.jsxDEV(y9,{content:"Copy job ID",children:u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:K0,children:[u8.jsxDEV(uZ,{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&&u8.jsxDEV(y9,{content:"Check process status",children:u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>L8(!0),children:u8.jsxDEV(Wj,{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),v.length>=3&&u8.jsxDEV("div",{className:"flex gap-2 mb-4",children:[u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:U0,children:"Collapse All"},void 0,!1,void 0,this),u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:Y0,children:"Expand All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u8.jsxDEV("div",{className:"flex-1 space-y-6",children:q?o0?u8.jsxDEV(u8.Fragment,{children:[u8.jsxDEV(QB8,{content:z,isOpen:d,onToggle:p,onInternalLinkClick:g},void 0,!1,void 0,this),u8.jsxDEV(Re,{title:`Prompt (Turn ${h.length+1})`,docId:C?.id,docName:C?.name,docContent:v[v.length-1]?.content,isOpen:m[v.length-1]?.promptOpen??!0,onToggle:(g0)=>u((r0)=>({...r0,[v.length-1]:{...r0[v.length-1],promptOpen:g0}})),deepLinkUrl:t,onFieldsClick:C?.id?()=>x0(C.id):void 0,children:u8.jsxDEV(MK,{markdown:v[v.length-1]?.content||"",onInternalLinkClick:g},void 0,!1,void 0,this)},void 0,!1,void 0,this),[...h].reverse().map((g0,r0)=>{let Q8=h.length-1-r0,L0=P?C?.id:$[Q8]?.promptDoc?.id,h0=P?T?.id:$[Q8]?.outputDoc?.id,e0=P?C?.name:$[Q8]?.promptDoc?.name,P0=P?T?.name:$[Q8]?.outputDoc?.name,M8=L0?`${J0}?doc=${L0}${U?`&from=${U}`:""}`:null,w8=h0?`${J0}?doc=${h0}${U?`&from=${U}`:""}`:null;return u8.jsxDEV(uM0,{turnNumber:Q8+1,promptContent:v[Q8]?.content,outputContent:g0.content,showHeading:!0,promptDocId:L0,outputDocId:h0,promptDocName:e0,outputDocName:P0,isPromptOpen:m[Q8]?.promptOpen??!0,setIsPromptOpen:(h8)=>u((c8)=>({...c8,[Q8]:{...c8[Q8],promptOpen:h8}})),isOutputOpen:m[Q8]?.outputOpen??!0,setIsOutputOpen:(h8)=>u((c8)=>({...c8,[Q8]:{...c8[Q8],outputOpen:h8}})),onInternalLinkClick:g,promptDeepLinkUrl:M8,outputDeepLinkUrl:w8,onPromptFieldsClick:L0?()=>x0(L0):void 0,onOutputFieldsClick:h0?()=>x0(h0):void 0},Q8,!1,void 0,this)})]},void 0,!0,void 0,this):u8.jsxDEV(u8.Fragment,{children:[u8.jsxDEV(QB8,{content:z,isOpen:d,onToggle:p,onInternalLinkClick:g},void 0,!1,void 0,this),u8.jsxDEV(Re,{title:"Prompt",docId:C?.id,docName:C?.name,docContent:v[0]?.content,isOpen:m[0]?.promptOpen??!0,onToggle:(g0)=>u((r0)=>({...r0,[0]:{...r0[0],promptOpen:g0}})),deepLinkUrl:t,onFieldsClick:C?.id?()=>x0(C.id):void 0,children:u8.jsxDEV(MK,{markdown:v[0]?.content||"",onInternalLinkClick:g},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):w?u8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-8",children:[u8.jsxDEV(G7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading documents..."]},void 0,!0,void 0,this):x?[...Array(Math.max(v.length,f.length))].map((g0,r0,Q8)=>{let L0=Q8.length-1-r0,h0=v[L0],e0=f[L0],P0=h0?.turnNumber??e0?.turnNumber??L0+1,M8=r0===0,w8=P?C?.id:$[L0]?.promptDoc?.id,h8=P?T?.id:$[L0]?.outputDoc?.id,c8=P?C?.name:$[L0]?.promptDoc?.name,t8=P?T?.name:$[L0]?.outputDoc?.name,e8=w8?`${J0}?doc=${w8}${U?`&from=${U}`:""}`:null,Y9=h8?`${J0}?doc=${h8}${U?`&from=${U}`:""}`:null;return u8.jsxDEV(uM0,{turnNumber:P0,promptContent:h0?.content,outputContent:e0?.content,showHeading:!0,promptDocId:w8,outputDocId:h8,promptDocName:c8,outputDocName:t8,isPromptOpen:m[L0]?.promptOpen??!0,setIsPromptOpen:(d9)=>u((l8)=>({...l8,[L0]:{...l8[L0],promptOpen:d9}})),isOutputOpen:m[L0]?.outputOpen??!0,setIsOutputOpen:(d9)=>u((l8)=>({...l8,[L0]:{...l8[L0],outputOpen:d9}})),onInternalLinkClick:g,promptDeepLinkUrl:e8,outputDeepLinkUrl:Y9,sectionRef:M8?e:null,highlightedSection:M8?n:null,onPromptFieldsClick:w8?()=>x0(w8):void 0,onOutputFieldsClick:h8?()=>x0(h8):void 0},L0,!1,void 0,this)}):u8.jsxDEV(uM0,{turnNumber:1,promptContent:v[0]?.content,outputContent:f[0]?.content,showHeading:!1,promptDocId:C?.id,outputDocId:T?.id,promptDocName:C?.name,outputDocName:T?.name,isPromptOpen:m[0]?.promptOpen??!0,setIsPromptOpen:(g0)=>u((r0)=>({...r0,[0]:{...r0[0],promptOpen:g0}})),isOutputOpen:m[0]?.outputOpen??!0,setIsOutputOpen:(g0)=>u((r0)=>({...r0,[0]:{...r0[0],outputOpen:g0}})),onInternalLinkClick:g,promptDeepLinkUrl:t,outputDeepLinkUrl:B0,sectionRef:e,highlightedSection:n,onPromptFieldsClick:C?.id?()=>x0(C.id):void 0,onOutputFieldsClick:T?.id?()=>x0(T.id):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(eH8,{open:S0,onOpenChange:X0,jobName:M.name,sessionId:M.fields?.sessionId,agent:M.fields?.agent,currentModel:M.fields?.model,streaming:M.fields?.streaming==="true",workingDirectory:M.fields?.workingDirectory,dockerImage:M.fields?.dockerImage,skipPermissions:M.fields?.skipPermissions!=="false",projectId:Z,onContinue:f0,isLoading:K8.isPending},void 0,!1,void 0,this),u8.jsxDEV(ZB8,{open:H8,onOpenChange:L8,projectId:Z,jobId:Q,pid:M.fields?.pid},void 0,!1,void 0,this),u8.jsxDEV(mH,{open:!!V0,onOpenChange:(g0)=>!g0&&O0(null),projectId:Z,documentId:V0?.id,anchor:V0?.anchor,onNavigate:X},void 0,!1,void 0,this),u8.jsxDEV(D6,{open:s0,onOpenChange:E0,children:u8.jsxDEV(O6,{className:"max-w-7xl",children:[u8.jsxDEV(M6,{children:u8.jsxDEV(L6,{children:"Job Fields"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(n2,{projectId:Z,entityId:Q,entityType:"j",entitySubtype:null,entityPath:M?.path,onFieldChange:T0,fieldValues:b0,dirtyFieldNames:Z0,originalFieldValues:p0,storeCode:J},void 0,!1,void 0,this),Z0.size>0&&u8.jsxDEV("div",{className:"flex justify-end gap-2 pt-4",children:[u8.jsxDEV(q8,{onClick:N0,variant:"outline",size:"sm",children:[u8.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Discard"]},void 0,!0,void 0,this),u8.jsxDEV(q8,{onClick:i,disabled:j0.isPending,variant:"default",size:"sm",children:[u8.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),j0.isPending?"Saving...":"Save Fields"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(D6,{open:!!A0,onOpenChange:(g0)=>!g0&&x0(null),children:u8.jsxDEV(O6,{className:"max-w-7xl",children:[u8.jsxDEV(M6,{children:u8.jsxDEV(L6,{children:"Document Fields"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(n2,{projectId:Z,entityId:A0,entityType:"d",entitySubtype:null,storeCode:J},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 p1=W0(t0(),1);var F3=W0(t0(),1);var r8=W0(t0(),1),cw=W0(sW(),1);var T5=W0(t0(),1);var px=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function gw(Z){let J=Object.prototype.toString.call(Z);return J==="[object Window]"||J==="[object global]"}function we(Z){return"nodeType"in Z}function wK(Z){var J,Q;if(!Z)return window;if(gw(Z))return Z;if(!we(Z))return window;return(J=(Q=Z.ownerDocument)==null?void 0:Q.defaultView)!=null?J:window}function Pe(Z){let{Document:J}=wK(Z);return Z instanceof J}function nD(Z){if(gw(Z))return!1;return Z instanceof wK(Z).HTMLElement}function lM0(Z){return Z instanceof wK(Z).SVGElement}function mw(Z){if(!Z)return document;if(gw(Z))return Z.document;if(!we(Z))return document;if(Pe(Z))return Z;if(nD(Z)||lM0(Z))return Z.ownerDocument;return document}var uH=px?T5.useLayoutEffect:T5.useEffect;function cx(Z){let J=T5.useRef(Z);return uH(()=>{J.current=Z}),T5.useCallback(function(){for(var Q=arguments.length,X=Array(Q),K=0;K<Q;K++)X[K]=arguments[K];return J.current==null?void 0:J.current(...X)},[])}function KB8(){let Z=T5.useRef(null),J=T5.useCallback((X,K)=>{Z.current=setInterval(X,K)},[]),Q=T5.useCallback(()=>{if(Z.current!==null)clearInterval(Z.current),Z.current=null},[]);return[J,Q]}function rD(Z,J){if(J===void 0)J=[Z];let Q=T5.useRef(Z);return uH(()=>{if(Q.current!==Z)Q.current=Z},J),Q}function aD(Z,J){let Q=T5.useRef();return T5.useMemo(()=>{let X=Z(Q.current);return Q.current=X,X},[...J])}function lx(Z){let J=cx(Z),Q=T5.useRef(null),X=T5.useCallback((K)=>{if(K!==Q.current)J==null||J(K,Q.current);Q.current=K},[]);return[Q,X]}function dx(Z){let J=T5.useRef();return T5.useEffect(()=>{J.current=Z},[Z]),J.current}var cM0={};function ix(Z,J){return T5.useMemo(()=>{if(J)return J;let Q=cM0[Z]==null?0:cM0[Z]+1;return cM0[Z]=Q,Z+"-"+Q},[Z,J])}function YB8(Z){return function(J){for(var Q=arguments.length,X=Array(Q>1?Q-1:0),K=1;K<Q;K++)X[K-1]=arguments[K];return X.reduce((Y,U)=>{let G=Object.entries(U);for(let[z,W]of G){let q=Y[z];if(q!=null)Y[z]=q+Z*W}return Y},{...J})}}var uw=YB8(1),sx=YB8(-1);function PP9(Z){return"clientX"in Z&&"clientY"in Z}function Te(Z){if(!Z)return!1;let{KeyboardEvent:J}=wK(Z.target);return J&&Z instanceof J}function TP9(Z){if(!Z)return!1;let{TouchEvent:J}=wK(Z.target);return J&&Z instanceof J}function nx(Z){if(TP9(Z)){if(Z.touches&&Z.touches.length){let{clientX:J,clientY:Q}=Z.touches[0];return{x:J,y:Q}}else if(Z.changedTouches&&Z.changedTouches.length){let{clientX:J,clientY:Q}=Z.changedTouches[0];return{x:J,y:Q}}}if(PP9(Z))return{x:Z.clientX,y:Z.clientY};return null}var sD=Object.freeze({Translate:{toString(Z){if(!Z)return;let{x:J,y:Q}=Z;return"translate3d("+(J?Math.round(J):0)+"px, "+(Q?Math.round(Q):0)+"px, 0)"}},Scale:{toString(Z){if(!Z)return;let{scaleX:J,scaleY:Q}=Z;return"scaleX("+J+") scaleY("+Q+")"}},Transform:{toString(Z){if(!Z)return;return[sD.Translate.toString(Z),sD.Scale.toString(Z)].join(" ")}},Transition:{toString(Z){let{property:J,duration:Q,easing:X}=Z;return J+" "+Q+"ms "+X}}}),XB8="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function UB8(Z){if(Z.matches(XB8))return Z;return Z.querySelector(XB8)}var pw=W0(t0(),1),IP9={display:"none"};function GB8(Z){let{id:J,value:Q}=Z;return pw.default.createElement("div",{id:J,style:IP9},Q)}function zB8(Z){let{id:J,announcement:Q,ariaLiveType:X="assertive"}=Z,K={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return pw.default.createElement("div",{id:J,style:K,role:"status","aria-live":X,"aria-atomic":!0},Q)}function WB8(){let[Z,J]=pw.useState("");return{announce:pw.useCallback((X)=>{if(X!=null)J(X)},[]),announcement:Z}}var PB8=r8.createContext(null);function VP9(Z){let J=r8.useContext(PB8);r8.useEffect(()=>{if(!J)throw Error("useDndMonitor must be used within a children of <DndContext>");return J(Z)},[Z,J])}function CP9(){let[Z]=r8.useState(()=>new Set),J=r8.useCallback((X)=>{return Z.add(X),()=>Z.delete(X)},[Z]);return[r8.useCallback((X)=>{let{type:K,event:Y}=X;Z.forEach((U)=>{var G;return(G=U[K])==null?void 0:G.call(U,Y)})},[Z]),J]}var $P9={draggable:`
|
|
3090
|
+
`)),a8.success("Contents copied")}catch(y0){T("Failed to copy contents")}else h()},l0=G||z?Y:X.resolvedContent||X.publishedContent;return L9.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0",children:[i&&L9.jsxDEV("div",{className:"mb-3 p-4 border border-red-300 rounded-md bg-red-50",children:L9.jsxDEV("div",{className:"flex items-start gap-3",children:[L9.jsxDEV(w7,{className:"w-5 h-5 text-red-600 shrink-0 mt-0.5"},void 0,!1,void 0,this),L9.jsxDEV("div",{className:"flex-1",children:[L9.jsxDEV("p",{className:"text-sm font-medium text-red-800 mb-2",children:"Your edit session has expired"},void 0,!1,void 0,this),L9.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),L9.jsxDEV("div",{className:"flex gap-2",children:[L9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(Y),a8.success("Copied to clipboard"),T(null)},children:[L9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy My Changes"]},void 0,!0,void 0,this),L9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{N0(!1),Z0(null),q(!1),window.location.reload()},children:[L9.jsxDEV(cU,{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),C&&L9.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center justify-between",children:[L9.jsxDEV("div",{className:"flex items-center gap-2 text-destructive",children:[L9.jsxDEV(w7,{className:"w-4 h-4"},void 0,!1,void 0,this),L9.jsxDEV("span",{className:"text-sm",children:C},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(q8,{variant:"ghost",size:"icon",onClick:()=>T(null),className:"h-6 w-6",children:L9.jsxDEV(pZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(vz,{value:O0,onValueChange:D0,variant:"segment",className:"flex-1 flex flex-col min-h-0",children:[L9.jsxDEV("div",{className:"flex items-center justify-between gap-4 mb-2",children:[L9.jsxDEV("div",{className:"flex items-center gap-2",children:[L9.jsxDEV(fz,{children:[L9.jsxDEV(F4,{value:"view",children:"View"},void 0,!1,void 0,this),L9.jsxDEV(F4,{value:"edit",disabled:!!H||C8,children:C8?L9.jsxDEV(L9.Fragment,{children:[L9.jsxDEV(uU,{className:"w-4 h-4"},void 0,!1,void 0,this),"Edit"]},void 0,!0,void 0,this):"Edit"},void 0,!1,void 0,this),L9.jsxDEV(F4,{value:"fields",children:"Fields"},void 0,!1,void 0,this),L9.jsxDEV(F4,{value:"attachments",children:"Assets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(A4,{children:[L9.jsxDEV(sQ,{asChild:!0,children:L9.jsxDEV(q8,{variant:"outline",size:"sm",children:[L9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",L9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(nQ,{align:"start",children:[L9.jsxDEV(z6,{onClick:W8,children:[L9.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:x,children:[L9.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy IDs"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:async()=>{try{let y0=wY(X?.path);await navigator.clipboard.writeText(y0),a8.success("Name copied")}catch(y0){a8.error("Failed to copy")}},children:[L9.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:async()=>{try{let y0=wY(X?.path);await navigator.clipboard.writeText(`[${y0}](${Q})`),a8.success("MD Link copied")}catch(y0){a8.error("Failed to copy")}},children:[L9.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),L9.jsxDEV(z6,{onClick:async()=>{try{let y0=Q?eZ(Q):"A",i0=y0&&y0!=="A"?`/store/${y0}`:"",$0=`${window.location.origin}/project/${Z}${i0}/documents?id=${Q}`;await navigator.clipboard.writeText($0),a8.success("URL copied")}catch(y0){a8.error("Failed to copy")}},children:[L9.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O0==="view"&&K.length>1&&L9.jsxDEV(A4,{children:[L9.jsxDEV(sQ,{asChild:!0,children:L9.jsxDEV(q8,{variant:"outline",size:"sm",children:[L9.jsxDEV(gG,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Versions",L9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(nQ,{align:"start",children:K.slice().reverse().map((y0)=>{let i0=y0.versionNumber===X.versionCount,$0=y1("d",X?.subtype);return L9.jsxDEV(z6,{onClick:()=>i0?j():E(y0.versionNumber),children:[L9.jsxDEV($0,{className:"w-4 h-4 mr-2 text-muted-foreground"},void 0,!1,void 0,this),i0?"Latest":new Date(y0.publishedAt).toLocaleDateString(),L9.jsxDEV("span",{className:"ml-auto text-muted-foreground",children:["v",y0.versionNumber]},void 0,!0,void 0,this)]},y0.versionNumber,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H&&L9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:j,children:[L9.jsxDEV(cU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Back to latest"]},void 0,!0,void 0,this),!H&&O0==="edit"&&(G||z||$==="saving")&&L9.jsxDEV(q8,{onMouseDown:()=>{x0.current=!0},onClick:x8,disabled:m.isPending,variant:"outline",size:"sm",children:[L9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),m.isPending?"Publishing...":"Publish"]},void 0,!0,void 0,this),!H&&O0==="edit"&&(G||z)&&L9.jsxDEV(q8,{onMouseDown:()=>{v0.current=!0},onClick:_,disabled:u.isPending,variant:"outline",size:"sm",children:[L9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),u.isPending?"Discarding...":"Discard"]},void 0,!0,void 0,this),O0==="fields"&&p0.size>0&&L9.jsxDEV(q8,{onClick:b0,disabled:E0.isPending,variant:"default",size:"sm",children:[L9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),E0.isPending?"Saving...":"Save Fields"]},void 0,!0,void 0,this),O0==="fields"&&p0.size>0&&L9.jsxDEV(q8,{onClick:G8,variant:"outline",size:"sm",children:[L9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Discard"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV("div",{className:"flex items-center gap-2",children:[L9.jsxDEV("div",{className:"flex flex-col mr-2",children:[L9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[(()=>{let y0=z||G,i0=y1("d",X?.subtype,{hasDraft:y0}),$0=()=>{if(X?.subtype==="task"){let A8=xH(X?.fields?.state,y0);if(A8)return{fill:A8,stroke:"#000000"}}if(y0)return{fill:"#fcd34d",stroke:"#000000"};return{}};return L9.jsxDEV(i0,{className:`h-4 w-4 shrink-0 ${!y0&&X?.subtype!=="task"?"text-muted-foreground":""}`,...$0()},void 0,!1,void 0,this)})(),L9.jsxDEV("span",{className:"text-sm font-medium truncate max-w-[200px]",children:wY(X?.path)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[L9.jsxDEV(y9,{content:`Document ID: ${Q}`,children:L9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${O4[X?.storeCode]||O4.A}`,children:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),(X?.versionCount??0)>0&&L9.jsxDEV(y9,{content:H?`Viewing version ${H}`:`Published version ${X.versionCount}`,children:L9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${H?"text-red-600 border-red-300 bg-red-50":"text-muted-foreground border-border/60 bg-muted/40"}`,children:["v",H||X.versionCount]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(q8,{onClick:()=>g(!0),variant:"destructive",size:"sm",children:[L9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(GQ,{value:"view",className:"flex-1 min-h-0",children:H?L9.jsxDEV("div",{ref:f0,className:"h-full p-4 border border-border rounded-md bg-muted overflow-auto",children:[L9.jsxDEV("div",{className:"text-xs text-muted-foreground mb-3",children:["Viewing version ",H," (read-only)"]},void 0,!0,void 0,this),L9.jsxDEV(MK,{markdown:B??"",onInternalLinkClick:F0,onRenderComplete:c0},void 0,!1,void 0,this)]},void 0,!0,void 0,this):L9.jsxDEV("div",{ref:f0,className:"h-full p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:l0?L9.jsxDEV(MK,{markdown:l0,onInternalLinkClick:F0,onRenderComplete:c0},void 0,!1,void 0,this):L9.jsxDEV("p",{className:"text-muted-foreground italic",children:"No content yet. Select Edit tab to start."},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(GQ,{value:"edit",className:"flex-1 min-h-0 flex flex-col",children:[L9.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:B8&&!H&&L9.jsxDEV(yx,{status:$,onRetry:k},void 0,!1,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV("div",{className:"flex-1 min-h-0",children:L9.jsxDEV(eN,{value:Y,onChange:D,onBlur:()=>{if(x0.current){console.log("[BLUR] Skipping flush - publish pending"),x0.current=!1;return}if(v0.current){console.log("[BLUR] Skipping flush - discard pending"),v0.current=!1;return}console.log("[BLUR] Monaco blur - calling flush"),p.flush()},path:X.path,height:"100%",projectId:Z,storeCode:Q?Q[0]:"A"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(GQ,{value:"fields",className:"flex-1 min-h-0 overflow-auto p-4",children:H?L9.jsxDEV(n2,{projectId:Z,entityId:O,entityType:"v",entitySubtype:null,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this):L9.jsxDEV(n2,{projectId:Z,entityId:Q,entityType:"d",entitySubtype:X?.subtype,entityPath:X?.path,onFieldChange:m0,fieldValues:H8,dirtyFieldNames:p0,originalFieldValues:K8,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this),L9.jsxDEV(GQ,{value:"attachments",className:"flex-1 min-h-0 overflow-auto p-4",children:L9.jsxDEV(Ue,{projectId:Z,documentId:Q,content:H?B:l0,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L9.jsxDEV(mH,{open:!!z0,onOpenChange:(y0)=>!y0&&V0(null),projectId:Z,documentId:z0?.id,anchor:z0?.anchor,onNavigate:U0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var SM0=Ye({type:"d",typeName:"Document",typeNamePlural:"Documents",DetailPanel:Ge,hooks:{useItem:VW,useCreate:jw,useSaveDraft:SD,usePublish:jD,useDiscard:kD,useVersions:_L,useDelete:_D,useUpdatePath:vD,getVersion:xI},enableCollectionMode:!0});var yZ=W0(t0(),1);var J9=W0(N8(),1),IH8=(Z)=>{if(!Z)return"";let J=Z.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/);if(J)return Z.slice(J[0].length);return Z},VH8=({projectId:Z,rootFolderId:J,selectedId:Q,selectedItemData:X,versions:K,draftContent:Y,isDirty:U,hasDraft:G,isEditMode:z,setEditMode:W,viewingVersion:q,versionContent:H,showVersions:B,setShowVersions:O,showRename:M,setShowRename:A,renameFilename:R,setRenameFilename:N,actionError:w,setActionError:P,saveStatus:C,handleEditorChange:T,handleViewVersion:$,handleBackToEdit:D,handlePublish:E,handleDiscardDraft:j,handleRetry:b,handleOpenRename:_,handleRename:k,handleCopyContent:v,handleCopyIds:f,setShowDeleteConfirm:h,publishMutation:x,discardMutation:g,updatePathMutation:m,debouncedSave:u,typeName:d,triggerEditMode:p,setTriggerEditMode:s})=>{let e=s9(),{setSelectedId:J0,documentPath:t,anchorFragment:B0}=hL(),n=PZ(),H0=sJ(),Q0=async({type:l0,id:y0,path:i0,anchor:$0})=>{if(l0==="anchor"){n(`${H0.pathname}${H0.search}#${$0}`,{replace:!0});return}if(l0==="id"){if(y0?.charAt(1)?.toLowerCase()==="d"){let g0=xw(y0,H0.pathname,$0);if(g0){n(g0.url);return}Y0({id:y0,anchor:$0||null});return}}let A8=$0?`#${$0}`:"";if(l0==="id"){let o0=y0?.charAt(1)?.toLowerCase(),g0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?)/)?.[1];if(o0==="s"){n(`${g0}/story/${y0}${A8}`);return}if(o0==="j"){n(`${g0}/job/${y0}${A8}`);return}if(o0==="f"){try{let r0=await u5(Z,y0),Q8=r0?.path||"";if(Q8.startsWith("Templates/"))n(`${g0}/templates?id=${y0}${A8}`);else if(Q8.startsWith("Stories/")){let L0=r0?.parentId?.startsWith("As")?r0.parentId:null;if(!L0){let h0=r0?.parentId?await u5(Z,r0.parentId):null;while(h0&&!L0)if(h0.parentId?.startsWith("As"))L0=h0.parentId;else if(h0.id?.startsWith("As"))L0=h0.id;else h0=h0.parentId?await u5(Z,h0.parentId):null}if(L0)n(`${g0}/story/${L0}?id=${y0}&tab=documents${A8}`);else n(`${g0}/stories?id=${y0}${A8}`)}else n(`${g0}/documents?id=${y0}${A8}`)}catch{n(`${g0}/documents?id=${y0}${A8}`)}return}if(t){let r0=H0.pathname.match(/(\/project\/[^/]+(?:\/store\/[^/]+)?\/(?:documents|templates))/)?.[1];if(r0){n(`${r0}?id=${y0}${A8}`);return}}if($0)n(`${H0.pathname}?id=${y0}${A8}`);else J0(y0)}else if(l0==="path")n(`/project/${Z}${i0}${A8}`)},[U0,Y0]=yZ.useState(null),[K0,F0]=yZ.useState(null),z0=K0===Q,[V0,O0]=yZ.useState(!1),S0=yZ.useRef(Q),X0=yZ.useRef(!1),K8=yZ.useRef(!1),C0=yZ.useRef(null),H8=J?eZ(J):"A";gH(Z,"templates","detail",C0,!!X,H8,J),yZ.useEffect(()=>{if(B0&&C0.current)setTimeout(()=>{let l0=C0.current.querySelector(`#${CSS.escape(B0)}`);if(l0)l0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[B0]);let L8=yZ.useCallback(()=>{if(B0&&C0.current)setTimeout(()=>{let l0=C0.current.querySelector(`#${CSS.escape(B0)}`);if(l0)l0.scrollIntoView({behavior:"smooth",block:"start"})},0)},[B0]),s0=z&&z0,E0=yZ.useMemo(()=>{if(!X||!X.editState)return!1;let l0=$6();return X.editState.sessionId!==l0},[X]);yZ.useEffect(()=>{let l0=S0.current;if(S0.current=Q,z0&&l0&&l0!==Q)dO(Z,l0).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",l0]})}).catch((y0)=>{console.error("Failed to clear edit state on selection change:",y0)}),F0(null);if(z&&Q&&!z0)Ec(Z,Q).then((y0)=>{if(y0.success)F0(Q),G8("edit"),e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]});else{let i0=D0.current||"view";G8(i0),W(!1),P(`Template is currently being edited. Try again in ${Math.ceil(y0.meta?.timeoutSeconds/60)} minutes.`)}}).catch((y0)=>{let i0=D0.current||"view";G8(i0),W(!1),P(y0.message)});if(!z&&z0&&Q)dO(Z,Q).then(()=>{e.invalidateQueries({queryKey:["folderContents"]}),e.invalidateQueries({queryKey:["document",Q]})}).catch((y0)=>{console.error("Failed to clear edit state:",y0)}),F0(null)},[z,Q,z0,Z,W,P,e]),yZ.useEffect(()=>{if(!X||!Q)return;let l0=X.editState,y0=$6();if(l0&&l0.sessionId===y0){let i0=new Date(l0.lastActivityAt),$0=new Date(Date.now()-3600000);if(i0>=$0){if(F0(Q),!z)W(!0)}}else if(K0===Q&&l0&&l0.sessionId!==y0){if(F0(null),z)O0(!0),W(!1)}},[X,Q]),yZ.useEffect(()=>{if(p)G8("edit"),D0.current="view",s(!1)},[p,s]),yZ.useEffect(()=>{return()=>{if(K0&&Z)dO(Z,K0).catch((l0)=>{console.error("Failed to clear edit state on unmount:",l0)})}},[K0,Z]);let[p0,m0]=yZ.useState(!1),[b0,G8]=yZ.useState("view"),D0=yZ.useRef("view"),[j0,Z0]=yZ.useState({}),[T0,i]=yZ.useState({}),{data:N0}=aY(Z,Q),A0=oY(Z),x0=yZ.useMemo(()=>{let l0=new Set;for(let y0 of Object.keys(T0)){let i0=j0[y0]??"",$0=T0[y0]??"";if(Array.isArray(i0)&&Array.isArray($0)){if(JSON.stringify(i0)!==JSON.stringify($0))l0.add(y0)}else if(i0!==$0)l0.add(y0)}return l0},[j0,T0]);yZ.useEffect(()=>{if(N0)Z0(N0),i(N0)},[N0]);let v0=yZ.useCallback((l0,y0)=>{i((i0)=>({...i0,[l0]:y0}))},[]),f0=yZ.useCallback(async()=>{let l0=Object.entries(T0).filter(([i0,$0])=>{let A8=j0[i0]??"";if(Array.isArray(A8)&&Array.isArray($0))return JSON.stringify(A8)!==JSON.stringify($0);return A8!==$0}),y0={};for(let[i0,$0]of l0)try{if(Array.isArray($0))await A0.mutateAsync({entityId:Q,fieldName:i0,values:$0});else await A0.mutateAsync({entityId:Q,fieldName:i0,value:$0});y0[i0]=$0}catch(A8){a8.error(`Failed to save ${i0}: ${A8.message}`)}if(Object.keys(y0).length>0)Z0((i0)=>({...i0,...y0}));if(Object.keys(y0).length===l0.length)a8.success("Fields saved")},[T0,j0,Q,A0]),n0=yZ.useCallback(()=>{i({...j0})},[j0]);yZ.useEffect(()=>{G8("view"),D0.current="view"},[Q]);let c0=yZ.useCallback((l0)=>{if(l0==="edit"&&q){G8("view");return}if(l0==="edit"&&b0!=="edit")D0.current=b0;if(G8(l0),l0==="edit")W(!0);else if(b0==="edit")W(!1)},[b0,q,W]);yZ.useEffect(()=>{if(q)G8("view")},[q]);let{data:B8}=fD(Z,Q),C8=B8?.parameters??[],x8=B8?.detectedVariables??[],W8=async()=>{await E(),G8("view")};return yZ.default.useEffect(()=>{m0(!1)},[Q]),J9.jsxDEV("div",{className:"flex-1 flex flex-col min-h-0",children:[V0&&J9.jsxDEV("div",{className:"mb-3 p-4 border border-red-300 rounded-md bg-red-50",children:J9.jsxDEV("div",{className:"flex items-start gap-3",children:[J9.jsxDEV(w7,{className:"w-5 h-5 text-red-600 shrink-0 mt-0.5"},void 0,!1,void 0,this),J9.jsxDEV("div",{className:"flex-1",children:[J9.jsxDEV("p",{className:"text-sm font-medium text-red-800 mb-2",children:"Your edit session has expired"},void 0,!1,void 0,this),J9.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),J9.jsxDEV("div",{className:"flex gap-2",children:[J9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{navigator.clipboard.writeText(Y),a8.success("Copied to clipboard"),P(null)},children:[J9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy My Changes"]},void 0,!0,void 0,this),J9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>{O0(!1),F0(null),W(!1),window.location.reload()},children:[J9.jsxDEV(cU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Reload Template"]},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),w&&J9.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center justify-between",children:[J9.jsxDEV("div",{className:"flex items-center gap-2 text-destructive",children:[J9.jsxDEV(w7,{className:"w-4 h-4"},void 0,!1,void 0,this),J9.jsxDEV("span",{className:"text-sm",children:w},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(q8,{variant:"ghost",size:"icon",onClick:()=>P(null),className:"h-6 w-6",children:J9.jsxDEV(pZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(r2,{open:p0,onOpenChange:m0,projectId:Z,templateId:Q,templatePath:X?.path,mode:"documents"},void 0,!1,void 0,this),J9.jsxDEV(vz,{value:b0,onValueChange:c0,variant:"segment",className:"flex-1 flex flex-col min-h-0",children:[J9.jsxDEV("div",{className:"flex items-center justify-between gap-4 mb-2",children:[J9.jsxDEV("div",{className:"flex items-center gap-2",children:[J9.jsxDEV(fz,{children:[J9.jsxDEV(F4,{value:"view",children:"View"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"edit",disabled:!!q||E0,children:E0?J9.jsxDEV(J9.Fragment,{children:[J9.jsxDEV(uU,{className:"w-4 h-4"},void 0,!1,void 0,this),"Edit"]},void 0,!0,void 0,this):"Edit"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"fields",disabled:!!q,children:"Fields"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"params",children:"Params"},void 0,!1,void 0,this),J9.jsxDEV(F4,{value:"attachments",disabled:!!q,children:"Assets"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X?.hasPublished&&J9.jsxDEV(q8,{onClick:()=>m0(!0),variant:"outline",size:"sm",children:[J9.jsxDEV(pU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Render"]},void 0,!0,void 0,this),J9.jsxDEV(A4,{children:[J9.jsxDEV(sQ,{asChild:!0,children:J9.jsxDEV(q8,{variant:"outline",size:"sm",children:[J9.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",J9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(nQ,{align:"start",children:[J9.jsxDEV(z6,{onClick:v,children:[J9.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:f,children:[J9.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy IDs"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:async()=>{try{let l0=wY(X?.path);await navigator.clipboard.writeText(l0),a8.success("Name copied")}catch(l0){a8.error("Failed to copy")}},children:[J9.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:async()=>{try{let l0=wY(X?.path);await navigator.clipboard.writeText(`[${l0}](${Q})`),a8.success("MD Link copied")}catch(l0){a8.error("Failed to copy")}},children:[J9.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),J9.jsxDEV(z6,{onClick:async()=>{try{let l0=Q?eZ(Q):"A",y0=l0&&l0!=="A"?`/store/${l0}`:"",i0=`${window.location.origin}/project/${Z}${y0}/templates?id=${Q}`;await navigator.clipboard.writeText(i0),a8.success("URL copied")}catch(l0){a8.error("Failed to copy")}},children:[J9.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),b0==="view"&&K.length>1&&J9.jsxDEV(A4,{children:[J9.jsxDEV(sQ,{asChild:!0,children:J9.jsxDEV(q8,{variant:"outline",size:"sm",children:[J9.jsxDEV(gG,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Versions",J9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(nQ,{align:"start",children:K.slice().reverse().map((l0)=>{let y0=l0.versionNumber===X.versionCount,i0=y1("t",X?.subtype);return J9.jsxDEV(z6,{onClick:()=>y0?D():$(l0.versionNumber),children:[J9.jsxDEV(i0,{className:"w-4 h-4 mr-2 text-muted-foreground"},void 0,!1,void 0,this),y0?"Latest":new Date(l0.publishedAt).toLocaleDateString(),J9.jsxDEV("span",{className:"ml-auto text-muted-foreground",children:["v",l0.versionNumber]},void 0,!0,void 0,this)]},l0.versionNumber,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&J9.jsxDEV(q8,{variant:"outline",size:"sm",onClick:D,children:[J9.jsxDEV(cU,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Back to latest"]},void 0,!0,void 0,this),!q&&b0==="edit"&&(U||G||C==="saving")&&J9.jsxDEV(q8,{onMouseDown:()=>{X0.current=!0},onClick:W8,disabled:x.isPending,variant:"outline",size:"sm",children:[J9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),x.isPending?"Publishing...":"Publish"]},void 0,!0,void 0,this),!q&&b0==="edit"&&(U||G)&&J9.jsxDEV(q8,{onMouseDown:()=>{K8.current=!0},onClick:j,disabled:g.isPending,variant:"outline",size:"sm",children:[J9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),g.isPending?"Discarding...":"Discard"]},void 0,!0,void 0,this),b0==="fields"&&x0.size>0&&J9.jsxDEV(q8,{onClick:f0,disabled:A0.isPending,variant:"default",size:"sm",children:[J9.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),A0.isPending?"Saving...":"Save Fields"]},void 0,!0,void 0,this),b0==="fields"&&x0.size>0&&J9.jsxDEV(q8,{onClick:n0,variant:"outline",size:"sm",children:[J9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Discard"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV("div",{className:"flex items-center gap-2",children:[J9.jsxDEV("div",{className:"flex flex-col mr-2",children:[J9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[(()=>{let l0=G||U,y0=y1("t",X?.subtype,{hasDraft:l0});return J9.jsxDEV(y0,{className:`h-4 w-4 shrink-0 ${!l0?"text-muted-foreground":""}`,...l0?{fill:"#fcd34d",stroke:"#000000"}:{}},void 0,!1,void 0,this)})(),J9.jsxDEV("span",{className:"text-sm font-medium truncate max-w-[200px]",children:wY(X?.path)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV("div",{className:"flex items-center gap-1.5",children:[J9.jsxDEV(y9,{content:`Template ID: ${Q}`,children:J9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${O4[X?.storeCode]||O4.A}`,children:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this),(X?.versionCount??0)>0&&J9.jsxDEV(y9,{content:q?`Viewing version ${q}`:`Published version ${X.versionCount}`,children:J9.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono ${q?"text-red-600 border-red-300 bg-red-50":"text-muted-foreground border-border/60 bg-muted/40"}`,children:["v",q||X.versionCount]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(q8,{onClick:()=>h(!0),variant:"destructive",size:"sm",children:[J9.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(GQ,{value:"view",className:"flex-1 min-h-0",children:(()=>{let l0=U||G?Y:X.resolvedContent||X.publishedContent,y0=X.path?.endsWith(".md");if(q){let $0=IH8(H);return J9.jsxDEV("div",{ref:y0?C0:null,className:"h-full p-4 border border-border rounded-md bg-muted overflow-auto",children:[J9.jsxDEV("div",{className:"text-xs text-muted-foreground mb-3",children:["Viewing version ",q," (read-only)"]},void 0,!0,void 0,this),y0?J9.jsxDEV(MK,{markdown:$0,onInternalLinkClick:Q0,onRenderComplete:L8},void 0,!1,void 0,this):J9.jsxDEV("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:$0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}let i0=IH8(l0);return J9.jsxDEV("div",{ref:y0?C0:null,className:"h-full p-4 border border-border rounded-md bg-muted scrollbar-styled overflow-auto",children:i0?y0?J9.jsxDEV(MK,{markdown:i0,onInternalLinkClick:Q0,onRenderComplete:L8},void 0,!1,void 0,this):J9.jsxDEV("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:i0},void 0,!1,void 0,this):J9.jsxDEV("p",{className:"text-muted-foreground italic",children:"No content yet. Select Edit tab to start."},void 0,!1,void 0,this)},void 0,!1,void 0,this)})()},void 0,!1,void 0,this),J9.jsxDEV(GQ,{value:"edit",className:"flex-1 min-h-0 flex flex-col",children:[J9.jsxDEV("div",{className:"flex items-center gap-2 mb-2",children:s0&&!q&&J9.jsxDEV(yx,{status:C,onRetry:b},void 0,!1,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV("div",{className:"flex-1 min-h-0",children:J9.jsxDEV(eN,{value:Y,onChange:T,onBlur:()=>{if(X0.current){console.log("[BLUR] Skipping flush - publish pending"),X0.current=!1;return}if(K8.current){console.log("[BLUR] Skipping flush - discard pending"),K8.current=!1;return}console.log("[BLUR] Monaco blur - calling flush"),u.flush()},path:X.path,height:"100%",projectId:Z,storeCode:Q?Q[0]:"A"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(GQ,{value:"fields",className:"flex-1 min-h-0 overflow-auto p-4",children:J9.jsxDEV(n2,{projectId:Z,entityId:Q,entityType:"t",entitySubtype:X?.subtype,entityPath:X?.path,onFieldChange:v0,fieldValues:T0,dirtyFieldNames:x0,originalFieldValues:j0,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(GQ,{value:"params",className:"flex-1 min-h-0 overflow-auto p-4",children:C8.length>0?J9.jsxDEV("div",{className:"grid grid-cols-4 gap-2",children:C8.map((l0)=>J9.jsxDEV("div",{className:"text-sm bg-background p-2 rounded border border-border",children:[J9.jsxDEV("div",{className:"flex items-center gap-2",children:[J9.jsxDEV("span",{className:"font-mono font-medium",children:l0.name},void 0,!1,void 0,this),J9.jsxDEV("span",{className:"text-xs text-muted-foreground",children:["(",l0.primitiveType,")"]},void 0,!0,void 0,this),l0.required&&J9.jsxDEV("span",{className:"text-xs text-destructive",children:"required"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l0.description&&J9.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1",children:l0.description},void 0,!1,void 0,this),l0.default!==void 0&&J9.jsxDEV("p",{className:"text-xs text-muted-foreground mt-1",children:["Default: ",J9.jsxDEV("span",{className:"font-mono",children:JSON.stringify(l0.default)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},l0.name,!0,void 0,this))},void 0,!1,void 0,this):x8.length>0?J9.jsxDEV("div",{className:"grid grid-cols-4 gap-2",children:[J9.jsxDEV("p",{className:"text-xs text-muted-foreground mb-2 col-span-4",children:"Detected from template (no front matter defined)"},void 0,!1,void 0,this),x8.map((l0)=>J9.jsxDEV("div",{className:"text-sm bg-background p-2 rounded border border-border",children:[J9.jsxDEV("span",{className:"font-mono font-medium",children:l0},void 0,!1,void 0,this),J9.jsxDEV("span",{className:"text-xs text-muted-foreground ml-2",children:"(string)"},void 0,!1,void 0,this)]},l0,!0,void 0,this))]},void 0,!0,void 0,this):J9.jsxDEV("p",{className:"text-sm text-muted-foreground",children:"No parameters or variables detected."},void 0,!1,void 0,this)},void 0,!1,void 0,this),J9.jsxDEV(GQ,{value:"attachments",className:"flex-1 min-h-0 overflow-auto p-4",children:J9.jsxDEV(Ue,{projectId:Z,documentId:Q,content:Y||X.draftContent||X.publishedContent,storeCode:Q?eZ(Q):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J9.jsxDEV(mH,{open:!!U0,onOpenChange:(l0)=>!l0&&Y0(null),projectId:Z,documentId:U0?.id,anchor:U0?.anchor,onNavigate:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var jM0=Ye({type:"t",typeName:"Template",typeNamePlural:"Templates",DetailPanel:VH8,hooks:{useItem:VW,useCreate:lW8,useSaveDraft:SD,usePublish:jD,useDiscard:kD,useVersions:_L,useDelete:_D,useUpdatePath:vD,getVersion:xI},enableCollectionMode:!0});var RZ=W0(t0(),1);var sw9=W0(t0(),1);var nw9=W0(N8(),1);var lD=W0(N8(),1),CH8=/\[([^\]]+)\]\((A[dtf]\d+)\)/g,rw9=(Z)=>{let J=[],Q=0,X;CH8.lastIndex=0;while((X=CH8.exec(Z))!==null){if(X.index>Q)J.push({type:"text",content:Z.slice(Q,X.index)});J.push({type:"link",content:X[1],id:X[2]}),Q=X.index+X[0].length}if(Q<Z.length)J.push({type:"text",content:Z.slice(Q)});return J},ze=({message:Z,onNavigate:J})=>{if(!Z?.trim())return null;let Q=rw9(Z),X=(Y,U)=>{if(Y.stopPropagation(),J)J(U)},K=lD.jsxDEV("span",{className:"italic text-muted-foreground truncate text-xs",children:Q.map((Y,U)=>{if(Y.type==="link")return lD.jsxDEV("span",{onClick:(G)=>X(G,Y.id),className:"text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 cursor-pointer hover:underline",children:Y.content},U,!1,void 0,this);return lD.jsxDEV("span",{children:Y.content},U,!1,void 0,this)})},void 0,!1,void 0,this);return lD.jsxDEV(y9,{content:Z,side:"left",children:lD.jsxDEV("div",{className:"min-w-0 truncate",children:K},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var hw="",yw=()=>({"Content-Type":"application/json","X-Session-Id":$6()}),$H8=async(Z,{store:J}={})=>{let Q=new URLSearchParams;if(J)Q.set("store",J);let X=Q.toString(),K=`${hw}/api/p/${Z}/stories${X?`?${X}`:""}`,Y=await fetch(K,{headers:yw()});return O9(Y,"Failed to list stories")},DH8=async(Z,J)=>{let Q=await fetch(`${hw}/api/p/${Z}/stories/${J}`,{headers:yw()});return O9(Q,"Failed to fetch story")},EH8=async(Z,{name:J,store:Q,state:X,track:K})=>{let Y=await fetch(`${hw}/api/p/${Z}/stories`,{method:"POST",headers:yw(),body:JSON.stringify({name:J,store:Q,state:X,track:K})});return O9(Y,"Failed to create story")},SH8=async(Z,J,Q)=>{let X=await fetch(`${hw}/api/p/${Z}/stories/${J}/state`,{method:"PATCH",headers:yw(),body:JSON.stringify({state:Q})});return O9(X,"Failed to update story state")},jH8=async(Z,J,Q)=>{let X=await fetch(`${hw}/api/p/${Z}/stories/${J}/name`,{method:"PATCH",headers:yw(),body:JSON.stringify({name:Q})});return O9(X,"Failed to rename story")},kH8=async(Z,J)=>{let Q=await fetch(`${hw}/api/p/${Z}/stories/${J}`,{method:"DELETE",headers:yw()});return O9(Q,"Failed to delete story")},_H8=async(Z,J,{track:Q,targetState:X})=>{let K={track:Q};if(X)K.targetState=X;let Y=await fetch(`${hw}/api/p/${Z}/stories/${J}/track`,{method:"PATCH",headers:yw(),body:JSON.stringify(K)});return O9(Y,"Failed to change story track")};var vH8=(Z,{store:J}={})=>{return b6({queryKey:["stories",Z,J??"demux"],queryFn:()=>$H8(Z,{store:J}),enabled:!!Z,staleTime:30000})},fH8=(Z,J)=>{return b6({queryKey:["story",J],queryFn:()=>DH8(Z,J),enabled:!!Z&&!!J})},bH8=(Z)=>{let J=s9();return h7({mutationFn:({name:Q,store:X,state:K,track:Y})=>EH8(Z,{name:Q,store:X,state:K,track:Y}),onSuccess:(Q,{store:X})=>{J.invalidateQueries({queryKey:["stories",Z,X??"demux"]})}})},We=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,state:X})=>SH8(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})},xH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,name:X})=>jH8(Z,Q,X),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})},hH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q})=>kH8(Z,Q),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})},yH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,track:X,targetState:K})=>_H8(Z,Q,{track:X,targetState:K}),onSuccess:(Q,{id:X})=>{J.invalidateQueries({queryKey:["story",X]}),J.invalidateQueries({queryKey:["stories",Z]})}})};var qe="",He=()=>({"Content-Type":"application/json","X-Session-Id":$6()}),gH8=async(Z,{store:J}={})=>{let Q=new URLSearchParams;if(J)Q.set("store",J);let X=Q.toString(),K=`${qe}/api/p/${Z}/tracks${X?`?${X}`:""}`,Y=await fetch(K,{headers:He()});return O9(Y,"Failed to list tracks")},mH8=async(Z,{store:J,name:Q,states:X})=>{let K=await fetch(`${qe}/api/p/${Z}/tracks`,{method:"POST",headers:He(),body:JSON.stringify({store:J,name:Q,states:X})});return O9(K,"Failed to create track")},uH8=async(Z,J,{name:Q,states:X})=>{let K=await fetch(`${qe}/api/p/${Z}/tracks/${J}`,{method:"PUT",headers:He(),body:JSON.stringify({name:Q,states:X})});return O9(K,"Failed to update track")},pH8=async(Z,J)=>{let Q=await fetch(`${qe}/api/p/${Z}/tracks/${J}`,{method:"DELETE",headers:He()});return O9(Q,"Failed to delete track")};var dD=(Z,{store:J}={})=>{return b6({queryKey:["tracks",Z,J??"demux"],queryFn:()=>gH8(Z,{store:J}),enabled:!!Z,staleTime:30000})},cH8=(Z)=>{let J=s9();return h7({mutationFn:({store:Q,name:X,states:K})=>mH8(Z,{store:Q,name:X,states:K}),onSuccess:(Q,{store:X})=>{J.invalidateQueries({queryKey:["tracks",Z,X??"demux"]})}})},lH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q,name:X,states:K})=>uH8(Z,Q,{name:X,states:K}),onSuccess:()=>{J.invalidateQueries({queryKey:["tracks",Z]}),J.invalidateQueries({queryKey:["stories",Z]})}})},dH8=(Z)=>{let J=s9();return h7({mutationFn:({id:Q})=>pH8(Z,Q),onSuccess:()=>{J.invalidateQueries({queryKey:["tracks",Z]})}})};var a2=W0(t0(),1);class w9{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(Z){if(Z<=0.0031308)return 12.92*Z;else return 1.055*Math.pow(Z,0.4166666666666667)-0.055}static toLinear(Z){if(Z>0.04045)return Math.pow((Z+0.055)/1.055,2.4);else return Z/12.92}static yToL(Z){if(Z<=w9.epsilon)return Z/w9.refY*w9.kappa;else return 116*Math.pow(Z/w9.refY,0.3333333333333333)-16}static lToY(Z){if(Z<=8)return w9.refY*Z/w9.kappa;else return w9.refY*Math.pow((Z+16)/116,3)}static rgbChannelToHex(Z){let J=Math.round(Z*255),Q=J%16,X=(J-Q)/16|0;return w9.hexChars.charAt(X)+w9.hexChars.charAt(Q)}static hexToRgbChannel(Z,J){let Q=w9.hexChars.indexOf(Z.charAt(J)),X=w9.hexChars.indexOf(Z.charAt(J+1));return(Q*16+X)/255}static distanceFromOriginAngle(Z,J,Q){let X=J/(Math.sin(Q)-Z*Math.cos(Q));if(X<0)return 1/0;else return X}static distanceFromOrigin(Z,J){return Math.abs(J)/Math.sqrt(Math.pow(Z,2)+1)}static min6(Z,J,Q,X,K,Y){return Math.min(Z,Math.min(J,Math.min(Q,Math.min(X,Math.min(K,Y)))))}rgbToHex(){this.hex="#",this.hex+=w9.rgbChannelToHex(this.rgb_r),this.hex+=w9.rgbChannelToHex(this.rgb_g),this.hex+=w9.rgbChannelToHex(this.rgb_b)}hexToRgb(){this.hex=this.hex.toLowerCase(),this.rgb_r=w9.hexToRgbChannel(this.hex,1),this.rgb_g=w9.hexToRgbChannel(this.hex,3),this.rgb_b=w9.hexToRgbChannel(this.hex,5)}xyzToRgb(){this.rgb_r=w9.fromLinear(w9.m_r0*this.xyz_x+w9.m_r1*this.xyz_y+w9.m_r2*this.xyz_z),this.rgb_g=w9.fromLinear(w9.m_g0*this.xyz_x+w9.m_g1*this.xyz_y+w9.m_g2*this.xyz_z),this.rgb_b=w9.fromLinear(w9.m_b0*this.xyz_x+w9.m_b1*this.xyz_y+w9.m_b2*this.xyz_z)}rgbToXyz(){let Z=w9.toLinear(this.rgb_r),J=w9.toLinear(this.rgb_g),Q=w9.toLinear(this.rgb_b);this.xyz_x=0.41239079926595*Z+0.35758433938387*J+0.18048078840183*Q,this.xyz_y=0.21263900587151*Z+0.71516867876775*J+0.072192315360733*Q,this.xyz_z=0.019330818715591*Z+0.11919477979462*J+0.95053215224966*Q}xyzToLuv(){let Z=this.xyz_x+15*this.xyz_y+3*this.xyz_z,J=4*this.xyz_x,Q=9*this.xyz_y;if(Z!==0)J/=Z,Q/=Z;else J=NaN,Q=NaN;if(this.luv_l=w9.yToL(this.xyz_y),this.luv_l===0)this.luv_u=0,this.luv_v=0;else this.luv_u=13*this.luv_l*(J-w9.refU),this.luv_v=13*this.luv_l*(Q-w9.refV)}luvToXyz(){if(this.luv_l===0){this.xyz_x=0,this.xyz_y=0,this.xyz_z=0;return}let Z=this.luv_u/(13*this.luv_l)+w9.refU,J=this.luv_v/(13*this.luv_l)+w9.refV;this.xyz_y=w9.lToY(this.luv_l),this.xyz_x=0-9*this.xyz_y*Z/((Z-4)*J-Z*J),this.xyz_z=(9*this.xyz_y-15*J*this.xyz_y-J*this.xyz_x)/(3*J)}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 Z=Math.atan2(this.luv_v,this.luv_u);if(this.lch_h=Z*180/Math.PI,this.lch_h<0)this.lch_h=360+this.lch_h}}lchToLuv(){let Z=this.lch_h/180*Math.PI;this.luv_l=this.lch_l,this.luv_u=Math.cos(Z)*this.lch_c,this.luv_v=Math.sin(Z)*this.lch_c}calculateBoundingLines(Z){let J=Math.pow(Z+16,3)/1560896,Q=J>w9.epsilon?J:Z/w9.kappa,X=Q*(284517*w9.m_r0-94839*w9.m_r2),K=Q*(838422*w9.m_r2+769860*w9.m_r1+731718*w9.m_r0),Y=Q*(632260*w9.m_r2-126452*w9.m_r1),U=Q*(284517*w9.m_g0-94839*w9.m_g2),G=Q*(838422*w9.m_g2+769860*w9.m_g1+731718*w9.m_g0),z=Q*(632260*w9.m_g2-126452*w9.m_g1),W=Q*(284517*w9.m_b0-94839*w9.m_b2),q=Q*(838422*w9.m_b2+769860*w9.m_b1+731718*w9.m_b0),H=Q*(632260*w9.m_b2-126452*w9.m_b1);this.r0s=X/Y,this.r0i=K*Z/Y,this.r1s=X/(Y+126452),this.r1i=(K-769860)*Z/(Y+126452),this.g0s=U/z,this.g0i=G*Z/z,this.g1s=U/(z+126452),this.g1i=(G-769860)*Z/(z+126452),this.b0s=W/H,this.b0i=q*Z/H,this.b1s=W/(H+126452),this.b1i=(q-769860)*Z/(H+126452)}calcMaxChromaHpluv(){let Z=w9.distanceFromOrigin(this.r0s,this.r0i),J=w9.distanceFromOrigin(this.r1s,this.r1i),Q=w9.distanceFromOrigin(this.g0s,this.g0i),X=w9.distanceFromOrigin(this.g1s,this.g1i),K=w9.distanceFromOrigin(this.b0s,this.b0i),Y=w9.distanceFromOrigin(this.b1s,this.b1i);return w9.min6(Z,J,Q,X,K,Y)}calcMaxChromaHsluv(Z){let J=Z/360*Math.PI*2,Q=w9.distanceFromOriginAngle(this.r0s,this.r0i,J),X=w9.distanceFromOriginAngle(this.r1s,this.r1i,J),K=w9.distanceFromOriginAngle(this.g0s,this.g0i,J),Y=w9.distanceFromOriginAngle(this.g1s,this.g1i,J),U=w9.distanceFromOriginAngle(this.b0s,this.b0i,J),G=w9.distanceFromOriginAngle(this.b1s,this.b1i,J);return w9.min6(Q,X,K,Y,U,G)}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 Z=this.calcMaxChromaHsluv(this.hsluv_h);this.lch_c=Z/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 Z=this.calcMaxChromaHsluv(this.lch_h);this.hsluv_s=this.lch_c/Z*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 Z=this.calcMaxChromaHpluv();this.lch_c=Z/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 Z=this.calcMaxChromaHpluv();this.hpluv_p=this.lch_c/Z*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()}}w9.hexChars="0123456789abcdef";w9.refY=1;w9.refU=0.19783000664283;w9.refV=0.46831999493879;w9.kappa=903.2962962;w9.epsilon=0.0088564516;w9.m_r0=3.240969941904521;w9.m_r1=-1.537383177570093;w9.m_r2=-0.498610760293;w9.m_g0=-0.96924363628087;w9.m_g1=1.87596750150772;w9.m_g2=0.041555057407175;w9.m_b0=0.055630079696993;w9.m_b1=-0.20397695888897;w9.m_b2=1.056971514242878;var EW=W0(N8(),1),kM0=(Z,J,Q)=>{let X=new w9;return X.hsluv_h=Z,X.hsluv_s=J,X.hsluv_l=Q,X.hsluvToHex(),X.hex},aw9=(Z,J)=>{if(J===0)return{bg:"linear-gradient(to bottom, #6b7280, #4b5563)",text:"white",border:"#374151"};let Q=J<=1?0:Z/(J-1)*360,X=65,K=40,Y=kM0(Q,X,K+15),U=kM0(Q,X,K),G=kM0(Q,X,K-10);return{bg:`linear-gradient(to bottom, ${Y}, ${U})`,text:"white",border:G}},ow9=16,tw9=24,ew9=60,_M0=null,ZP9=(Z,J="12px ui-sans-serif, system-ui, sans-serif")=>{if(!_M0)_M0=document.createElement("canvas");let Q=_M0.getContext("2d");return Q.font=J,Q.measureText(Z).width},JP9=(Z,J)=>{if(!Z.length||J<=0)return[];let Q=Z.map((W)=>{let q=W.charAt(0).toUpperCase()+W.slice(1),H=ZP9(q);return Math.max(H+ow9*2+tw9,ew9)}),X=Z.length;if(X===1){let W=Q[0];return[{width:W,centerX:J/2,leftPx:(J-W)/2}]}let K=Q[0]/2,Y=Q[X-1]/2,U=K,z=(J-Y-U)/(X-1);return Z.map((W,q)=>{let H=U+q*z,B=Q[q],O=H-B/2;return{width:B,centerX:H,leftPx:O}})};var Be=({state:Z,states:J,onPrev:Q,onNext:X,compact:K=!1})=>{let Y=a2.useRef(null),[U,G]=a2.useState(0),z=J.indexOf(Z),W=J.length,[q,H]=a2.useState(!1),B=a2.useCallback((N)=>{Y.current=N,H(!!N)},[]);a2.useEffect(()=>{if(!Y.current)return;let N=new ResizeObserver((w)=>{for(let P of w)G(P.contentRect.width)});return N.observe(Y.current),G(Y.current.offsetWidth),()=>N.disconnect()},[q]);let O=a2.useMemo(()=>{return JP9(J,U)},[J,U]);if(z<0||W===0)return null;let M=O[z],A=Z.charAt(0).toUpperCase()+Z.slice(1),R=aw9(z,J.length);if(!M||U===0)return EW.jsxDEV("div",{ref:B,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"},void 0,!1,void 0,this);return EW.jsxDEV("div",{ref:B,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:EW.jsxDEV("div",{className:"absolute rounded text-xs flex items-center justify-between px-1 shadow-sm",style:{left:`${M.leftPx}px`,width:`${M.width}px`,top:"2px",bottom:"2px",background:R.bg,color:R.text,borderWidth:"1px",borderStyle:"solid",borderColor:R.border},children:[Q?EW.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(N)=>{N.stopPropagation(),Q()},onKeyDown:(N)=>{if(N.key==="Enter"||N.key===" ")N.preventDefault(),N.stopPropagation(),Q()},children:EW.jsxDEV(wB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):EW.jsxDEV("span",{className:"w-4 flex-shrink-0"},void 0,!1,void 0,this),EW.jsxDEV("span",{className:"flex-1 text-center truncate",children:A},void 0,!1,void 0,this),X?EW.jsxDEV("div",{role:"button",tabIndex:0,className:"flex items-center justify-center flex-shrink-0 opacity-70 hover:opacity-100 cursor-pointer",onClick:(N)=>{N.stopPropagation(),X()},onKeyDown:(N)=>{if(N.key==="Enter"||N.key===" ")N.preventDefault(),N.stopPropagation(),X()},children:EW.jsxDEV(PB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this):EW.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)};var Fe=[{value:"documents",icon:G4,label:"Documents",shortLabel:"Docs",showLabel:!0},{value:"tasks",icon:Jq,label:"Tasks",shortLabel:"Tasks",showLabel:!0},{value:"prompts",icon:rX,label:"Prompts",shortLabel:"Prompts",showLabel:!0},{value:"jobs",icon:dG,label:"Jobs",shortLabel:"Jobs",showLabel:!0},{value:"fields",icon:a3,label:"Fields",showLabel:!1}];function yL(Z,J,{track:Q,state:X}={}){return Z.filter((K)=>QP9(K,J,Q,X))}function QP9(Z,J,Q,X){let{config:K}=Z;if(!K)return!1;let Y;try{Y=JSON.parse(K)}catch{return!1}let U=Y?.visibility;if(!U)return!1;let G=U[J];if(!G)return!0;let{tracks:z,states:W}=G,q=Array.isArray(z)&&z.length>0,H=Array.isArray(W)&&W.length>0;if(!q&&!H)return!0;if(q&&!z.includes(Q))return!1;if(H&&!W.includes(X))return!1;return!0}function Oe(Z,J,Q){let{data:X,isLoading:K}=mD(Z,{store:Q});return{hasJobs:X?.jobs?.some((U)=>U.fields?.objectId===J)??!1,isLoading:K}}function iH8(Z,{track:J,state:Q}={}){let{data:X,isLoading:K}=bH(Z,"s"),Y=X?.templates??[];return{hasPrompts:yL(Y,"story",{track:J,state:Q}).length>0,isLoading:K}}var $8=W0(N8(),1),vM0=[{key:"unsorted",icon:Xq,label:"Not sorted"},{key:"name-asc",icon:hG,label:"Sorting by name ascending"},{key:"name-desc",icon:xG,label:"Sorting by name descending"},{key:"date-asc",icon:Az,label:"Sorting by date ascending"},{key:"date-desc",icon:Lz,label:"Sorting by date descending"},{key:"date-completed-asc",icon:Az,label:"Sorting by date completed ascending"},{key:"date-completed-desc",icon:Lz,label:"Sorting by date completed descending"},{key:"state-asc",icon:d3,label:"Sorting by state ascending"},{key:"state-desc",icon:l3,label:"Sorting by state descending"}],fM0=[{value:"active",label:"Active",icon:uA},{value:"backlog",label:"Backlog",icon:rS},{value:"history",label:"History",icon:gG}],bM0=50,KP9={d:"documents",t:"tasks",p:"prompts",j:"jobs",f:"fields"};function YP9({projectId:Z,storyId:J,storeCode:Q,onNavigate:X,hasPrompts:K}){let{hasJobs:Y,isLoading:U}=Oe(Z,J,Q),G=!U&&!Y,z=!K,W=(q)=>{switch(q){case"jobs":return G;case"prompts":return z;default:return!1}};return $8.jsxDEV("div",{className:"inline-flex gap-0.5 rounded bg-black/[0.03] dark:bg-white/[0.03] shadow-sm border border-border/50 p-0.5",children:Fe.map((q)=>{let H=W(q.value),B=H?`No ${q.label.toLowerCase()}`:q.label;return $8.jsxDEV(y9,{content:B,children:$8.jsxDEV("button",{onClick:(O)=>{if(O.stopPropagation(),!H)X(q.value)},disabled:H,tabIndex:H?-1:0,className:y8("rounded-md px-2 py-1.5 flex items-center gap-1 justify-center",H?"text-muted-foreground/50":"text-muted-foreground hover:text-foreground hover:bg-muted/50 cursor-pointer"),children:[$8.jsxDEV(q.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),q.showLabel&&$8.jsxDEV("span",{className:"text-xs",children:q.shortLabel},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},q.value,!1,void 0,this)})},void 0,!1,void 0,this)}var xM0=()=>{let{id:Z,storeCode:J}=YQ(),Q=PZ(),{data:X}=k4(Z);A1(X?`${X.name} - Stories`:"CAW");let K=J??"A";Rq(Z);let Y=RZ.useRef(null),{data:U=[],isLoading:G,error:z,refetch:W}=vH8(Z,{store:K}),{data:q=[],isLoading:H,error:B,refetch:O}=dD(Z,{store:K}),{data:M}=bH(Z,"s"),A=M?.templates??[],R=bH8(Z),N=We(Z),w=hH8(Z),P=oY(Z),C=yH8(Z),T=($0)=>{return q.find((o0)=>o0.name===$0)?.fields?.states||[]},$=RZ.useMemo(()=>{let $0=new Set;return q.forEach((A8)=>{(A8.fields?.states||[]).forEach((g0)=>$0.add(g0))}),[...$0]},[q]),D=($0,A8)=>{let o0=q.find((Q8)=>Q8.name===A8);if(!o0)return 0.5;let g0=o0.fields?.states||[];if(g0.length===0)return 0.5;let r0=g0.indexOf($0);if(r0===-1)return 0.5;return g0.length<=1?0:r0/(g0.length-1)},[E,j]=RZ.useState(!1),[b,_]=RZ.useState(""),[k,v]=RZ.useState(""),[f,h]=RZ.useState(""),[x,g]=RZ.useState(null),[m,u]=PY(Z,"stories","selectedStoryId",null,K),d=m?U.find(($0)=>$0.id===m):null,[p,s]=RZ.useState(null),[e,J0]=RZ.useState(!1),[t,B0]=RZ.useState(null),[n,H0]=RZ.useState(!1),[Q0,U0]=RZ.useState(null),[Y0,K0]=RZ.useState(null),[F0,z0]=RZ.useState(""),[V0,O0]=RZ.useState(null),[S0,X0]=RZ.useState(null),K8=A.find(($0)=>$0.id===V0);RZ.useEffect(()=>{if(q.length>0&&k===""){let $0=q.find((A8)=>A8.name==="Default");v($0?"Default":q[0].name)}},[q,k]),RZ.useEffect(()=>{if(k){let $0=T(k);if($0.length>0)h($0[0])}},[k,q]);let[C0,H8]=PY(Z,"stories","sortMode","state-asc",K),L8=RZ.useRef(null),{phase:s0,activeStates:E0,setPhase:p0,setActiveStates:m0}=rT0(Z),[b0,G8]=PY(Z,"stories","currentPage",1,K);gH(Z,"stories","list",Y,!G,K);let D0=RZ.useMemo(()=>{if(!E0)return new Set($);let $0=E0.filter((A8)=>$.includes(A8));return $0.length>0?new Set($0):new Set($)},[E0,$]);RZ.useEffect(()=>{if(!E0||!$.length)return;let $0=E0.filter((A8)=>$.includes(A8));if($0.length!==E0.length)m0($0.length>0&&$0.length<$.length?$0:null)},[E0,$,m0]);let j0=($0)=>{let A8=E0?new Set(E0):new Set($),o0=new Set(A8);if(o0.has($0))o0.delete($0);else o0.add($0);m0(o0.size===$.length?null:[...o0])},Z0=($0)=>{let A8=J?`/project/${Z}/store/${J}/story/${$0}`:`/project/${Z}/story/${$0}`;Q(A8)},T0=($0,A8)=>{let o0=J?`/project/${Z}/store/${J}/story/${$0}?tab=${A8}`:`/project/${Z}/story/${$0}?tab=${A8}`;Q(o0)},i=($0,A8)=>{if($0.key==="Enter"||$0.key===" ")$0.preventDefault(),u(m===A8?null:A8)},N0=($0,A8)=>{let g0=U.find((r0)=>r0.id===$0)?.fields?.phase;P.mutate({entityId:$0,fieldName:"phase",value:A8},{onSuccess:()=>{if(g0==="history")a8(`Story moved to ${A8.charAt(0).toUpperCase()+A8.slice(1)}`)}})},A0=($0,A8)=>{let g0=U.find((Q8)=>Q8.id===$0)?.fields?.state,r0=T(A8);if(g0&&r0.includes(g0))C.mutate({id:$0,track:A8},{onSuccess:()=>a8(`Track changed to ${A8}`),onError:(Q8)=>a8.error(Q8.message||"Failed to change track")});else U0($0),K0(A8),z0(""),H0(!0)},x0=()=>{C.mutate({id:Q0,track:Y0,targetState:F0},{onSuccess:()=>{a8(`Track changed to ${Y0}`),H0(!1),U0(null),K0(null),z0("")},onError:($0)=>a8.error($0.message||"Failed to change track")})},{visibleStories:v0,phaseFilteredCount:f0}=RZ.useMemo(()=>{if(!q.length)return{visibleStories:[],phaseFilteredCount:0};let $0=U.filter((g0)=>{return(g0.fields?.phase||"active")===s0}),A8=$0.filter((g0)=>{return g0.fields?.state&&D0.has(g0.fields.state)});if(C0==="unsorted"){if(L8.current){let g0=L8.current,r0=[...A8];return r0.sort((Q8,L0)=>{let h0=g0.indexOf(Q8.id),e0=g0.indexOf(L0.id);return(h0===-1?1/0:h0)-(e0===-1?1/0:e0)}),{visibleStories:r0,phaseFilteredCount:$0.length}}return{visibleStories:A8,phaseFilteredCount:$0.length}}let o0=[...A8];return o0.sort((g0,r0)=>{let Q8=(h0)=>h0.createdAt?new Date(h0.createdAt).getTime():parseInt(h0.id.replace(/\D/g,""),10)||0,L0=(h0)=>{let e0=h0.fields?.dateCompleted;return e0?new Date(e0).getTime():null};if(C0==="name-asc")return g0.name.localeCompare(r0.name);if(C0==="name-desc")return r0.name.localeCompare(g0.name);if(C0==="date-asc"||C0==="date-desc"){let h0=Q8(g0)-Q8(r0);return C0==="date-asc"?h0:-h0}if(C0==="date-completed-asc"||C0==="date-completed-desc"){let h0=L0(g0),e0=L0(r0);if(h0===null&&e0===null)return 0;if(h0===null)return 1;if(e0===null)return-1;let P0=h0-e0;return C0==="date-completed-asc"?P0:-P0}if(C0==="state-asc"){let h0=D(g0.fields.state,g0.fields.track),e0=D(r0.fields.state,r0.fields.track),P0=h0-e0;if(Math.abs(P0)>0.001)return P0;let M8=L0(g0),w8=L0(r0);if(M8===null&&w8===null)return 0;if(M8===null)return 1;if(w8===null)return-1;return w8-M8}if(C0==="state-desc"){let h0=D(g0.fields.state,g0.fields.track),P0=D(r0.fields.state,r0.fields.track)-h0;if(Math.abs(P0)>0.001)return P0;let M8=L0(g0),w8=L0(r0);if(M8===null&&w8===null)return 0;if(M8===null)return 1;if(w8===null)return-1;return M8-w8}return 0}),{visibleStories:o0,phaseFilteredCount:$0.length}},[U,q,C0,D0,s0]),n0=Math.ceil(v0.length/bM0),c0=Math.min(b0,Math.max(1,n0)),B8=RZ.useMemo(()=>{let $0=(c0-1)*bM0;return v0.slice($0,$0+bM0)},[v0,c0]),C8=RZ.useRef(!0);RZ.useEffect(()=>{if(C8.current){C8.current=!1;return}G8(1)},[C0,E0,s0]),RZ.useEffect(()=>{L8.current=null},[s0]),RZ.useEffect(()=>{if(m&&!v0.some(($0)=>$0.id===m))u(null)},[m,v0]),RZ.useEffect(()=>{if(m&&!U.some(($0)=>$0.id===m))u(null)},[m,U]),RZ.useEffect(()=>{let $0=(A8)=>{if(!p)return;if(A8.shiftKey||A8.ctrlKey||A8.altKey||A8.metaKey)return;let o0=document.activeElement;if(o0&&(o0.tagName==="INPUT"||o0.tagName==="TEXTAREA"))return;let g0=KP9[A8.key];if(g0)T0(p,g0)};return window.addEventListener("keydown",$0),()=>window.removeEventListener("keydown",$0)},[p]),RZ.useEffect(()=>{if(J==="B")Q(`/project/${Z}/store/B/documents`,{replace:!0})},[J,Z,Q]);let x8=()=>{if(!b.trim()){g("Story name is required");return}g(null),R.mutate({name:b.trim(),store:K,state:f,track:k},{onSuccess:($0)=>{j(!1),_("");let A8=q.find((o0)=>o0.name==="Default");v(A8?"Default":q[0]?.name||""),Z0($0.id)},onError:($0)=>{g($0.message)}})},W8=()=>{j(!1),_("");let $0=q.find((A8)=>A8.name==="Default");v($0?"Default":q[0]?.name||""),g(null)},l0=G||H,y0=z||B,i0=z?W:O;if(J==="B")return null;if(l0)return $8.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading stories..."},void 0,!1,void 0,this);if(y0)return $8.jsxDEV("div",{className:"p-6",children:[$8.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading stories"},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:y0.message},void 0,!1,void 0,this),$8.jsxDEV(q8,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>i0(),children:[$8.jsxDEV($B,{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 $8.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[$8.jsxDEV("div",{className:"flex items-center justify-between mb-4 relative",onClick:()=>u(null),children:[$8.jsxDEV("div",{className:"flex items-center gap-2",onClick:($0)=>$0.stopPropagation(),children:[$8.jsxDEV(q8,{size:"sm",variant:"warning",onClick:()=>j(!0),children:[$8.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),$8.jsxDEV(RB,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(q3,{orientation:"vertical",className:"h-6 mx-2"},void 0,!1,void 0,this),$8.jsxDEV(A4,{children:[$8.jsxDEV(y9,{content:vM0.find(($0)=>$0.key===C0)?.label,children:$8.jsxDEV(sQ,{asChild:!0,children:$8.jsxDEV(q8,{size:"sm",variant:"outline",children:RZ.default.createElement(vM0.find(($0)=>$0.key===C0)?.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(nQ,{align:"start",children:vM0.map(($0)=>$8.jsxDEV(z6,{onClick:()=>{if($0.key==="unsorted")L8.current=v0.map((A8)=>A8.id);else L8.current=null;H8($0.key)},className:C0===$0.key?"bg-accent":"",children:[$8.jsxDEV($0.icon,{className:"w-4 h-4"},void 0,!1,void 0,this),$0.label]},$0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(DL,{children:[$8.jsxDEV(y9,{content:"Filter by state",children:$8.jsxDEV(EL,{asChild:!0,children:$8.jsxDEV(q8,{size:"sm",variant:"outline",children:$8.jsxDEV(Zq,{className:"w-4 h-4",...E0&&{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),$8.jsxDEV(G3,{align:"center",children:$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV("div",{className:"text-sm font-medium",children:"Show by state:"},void 0,!1,void 0,this),$.map(($0)=>$8.jsxDEV("label",{className:"flex items-center gap-2",children:[$8.jsxDEV(g1,{checked:D0.has($0),onCheckedChange:()=>j0($0)},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"text-sm capitalize",children:$0},void 0,!1,void 0,this)]},$0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(A4,{children:[$8.jsxDEV(y9,{content:"Phase",children:$8.jsxDEV(sQ,{asChild:!0,children:$8.jsxDEV(q8,{variant:"outline",size:"sm",children:[RZ.default.createElement(fM0.find(($0)=>$0.value===s0)?.icon,{className:"w-4 h-4 mr-1"}),fM0.find(($0)=>$0.value===s0)?.label,$8.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(nQ,{align:"start",children:fM0.map(($0)=>$8.jsxDEV(z6,{onClick:()=>p0($0.value),className:s0===$0.value?"bg-accent":"",children:[$8.jsxDEV($0.icon,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),$0.label]},$0.value,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d&&$8.jsxDEV($8.Fragment,{children:[$8.jsxDEV(q3,{orientation:"vertical",className:"h-6 mx-2"},void 0,!1,void 0,this),$8.jsxDEV(A4,{children:[$8.jsxDEV(sQ,{asChild:!0,children:$8.jsxDEV(q8,{variant:"outline",size:"sm",children:[$8.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",$8.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(nQ,{align:"start",children:[$8.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(d.id),a8.success("Story ID copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Story ID"]},void 0,!0,void 0,this),$8.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(d.name),a8.success("Name copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),$8.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(`[${d.name}](${d.id})`),a8.success("MD Link copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),$8.jsxDEV(z6,{onClick:async()=>{try{let $0=eZ(d.id),A8=$0&&$0!=="A"?`/store/${$0}`:"",o0=`${window.location.origin}/project/${Z}${A8}/story/${d.id}`;await navigator.clipboard.writeText(o0),a8.success("URL copied")}catch($0){a8.error("Failed to copy")}},children:[$8.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(q8,{size:"sm",variant:"destructive",onClick:()=>{B0(null),J0(!0)},children:[$8.jsxDEV(fJ,{className:"w-4 h-4"},void 0,!1,void 0,this),"Delete"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),d&&$8.jsxDEV("div",{className:"absolute left-1/2 -translate-x-1/2 flex items-center gap-2",onClick:($0)=>$0.stopPropagation(),children:[$8.jsxDEV(RB,{className:"w-5 h-5 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"truncate text-base font-medium max-w-[300px]",children:d.name},void 0,!1,void 0,this),$8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${d.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:d.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n0>1&&$8.jsxDEV("div",{className:"flex items-center gap-2",onClick:($0)=>$0.stopPropagation(),children:[$8.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>G8(($0)=>$0-1),disabled:c0===1,children:$8.jsxDEV(Nz,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"text-sm text-muted-foreground px-2",children:["Page ",c0," of ",n0]},void 0,!0,void 0,this),$8.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>G8(($0)=>$0+1),disabled:c0===n0,children:$8.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),v0.length===0?U.length===0?$8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories yet"},void 0,!1,void 0,this):f0===0?$8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:["No stories in ",s0,". Stories exist in other phases.",s0!=="active"&&$8.jsxDEV($8.Fragment,{children:[" ",$8.jsxDEV("button",{className:"underline text-primary cursor-pointer",onClick:()=>p0("active"),children:"Switch to Active"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):$8.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No stories match the current filters"},void 0,!1,void 0,this):$8.jsxDEV("div",{ref:Y,className:"flex-1 overflow-auto",onClick:()=>u(null),children:B8.map(($0)=>{let A8=T($0.fields.track),o0=A8.indexOf($0.fields.state),g0=o0>0?A8[o0-1]:null,r0=o0<A8.length-1?A8[o0+1]:null,Q8=m===$0.id,L0=$8.jsxDEV("div",{role:"button",tabIndex:0,"aria-selected":Q8,onMouseEnter:()=>s($0.id),onMouseLeave:()=>s(null),onClick:(e0)=>{e0.stopPropagation(),u(m===$0.id?null:$0.id)},onDoubleClick:()=>Z0($0.id),onKeyDown:(e0)=>i(e0,$0.id),className:`grid grid-cols-[5fr_5fr_6fr_4fr] items-center px-3 py-2 w-full cursor-pointer border-b gap-2 ${Q8?"bg-muted":"hover:bg-muted/50"}`,children:[$8.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:[$8.jsxDEV(RB,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"},void 0,!1,void 0,this),$8.jsxDEV("span",{className:"truncate text-sm",children:$0.name},void 0,!1,void 0,this),$8.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-mono flex-shrink-0 ${$0.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:$0.id},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"flex items-center gap-2",children:[$8.jsxDEV(y9,{content:`Track: ${$0.fields?.track||"Default"}`,children:$8.jsxDEV("span",{className:"text-xs text-muted-foreground flex-shrink-0 truncate w-[80px] text-right",children:[$0.fields?.track||"Default",":"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"flex-1",onClick:(e0)=>e0.stopPropagation(),children:$8.jsxDEV(Be,{state:$0.fields.state,states:A8,onPrev:g0?()=>N.mutate({id:$0.id,state:g0}):null,onNext:r0?()=>N.mutate({id:$0.id,state:r0}):null},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"flex items-center gap-2",children:[$8.jsxDEV(YP9,{projectId:Z,storyId:$0.id,storeCode:K,onNavigate:(e0)=>T0($0.id,e0),hasPrompts:A.length>0},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"grid grid-cols-[20px_40px] items-center",children:[$8.jsxDEV("div",{className:"flex justify-center",children:$0.fields?.flag==="true"&&$8.jsxDEV(hA,{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:(e0)=>{e0.stopPropagation(),P.mutate({entityId:$0.id,fieldName:"flag",value:"false"})}},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"flex justify-start pl-2",children:parseInt($0.fields?.activeJobCount||"0",10)>0&&$8.jsxDEV("div",{className:"relative flex items-center gap-0.5 flex-shrink-0 p-1 rounded-md overflow-hidden",children:[$8.jsxDEV(dG,{className:"w-4 h-4 text-blue-500 dark:text-blue-400 animate-spin",style:{animationDuration:"6.28s"}},void 0,!1,void 0,this),parseInt($0.fields?.activeJobCount||"0",10)>=2&&$8.jsxDEV("span",{className:"text-[10px] font-mono text-blue-600 dark:text-blue-300",children:$0.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),$8.jsxDEV("div",{className:"flex items-center gap-2 min-w-0",children:$0.fields?.statusMessage?.trim()&&$8.jsxDEV(ze,{message:$0.fields.statusMessage,onNavigate:(e0)=>{let P0=J?`/project/${Z}/store/${J}/story/${$0.id}?id=${e0}&tab=documents`:`/project/${Z}/story/${$0.id}?id=${e0}&tab=documents`;Q(P0)}},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},$0.id,!0,void 0,this),h0=$0.fields?.phase??"active";return $8.jsxDEV(xD,{children:[$8.jsxDEV(hD,{asChild:!0,children:L0},void 0,!1,void 0,this),$8.jsxDEV(vw,{children:[(()=>{let e0=yL(A,"story",{track:$0.fields?.track,state:$0.fields?.state});return e0.length>0&&$8.jsxDEV(yD,{children:[$8.jsxDEV(kw,{children:[$8.jsxDEV(rX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Prompts"]},void 0,!0,void 0,this),$8.jsxDEV(_w,{children:e0.map((P0)=>{let M8=P0.subtype==="prompt"?rX:vK;return $8.jsxDEV(gQ,{onClick:()=>{O0(P0.id),X0($0.id)},children:[$8.jsxDEV(M8,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),P0.name]},P0.id,!0,void 0,this)})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)})(),$8.jsxDEV(yD,{children:[$8.jsxDEV(kw,{children:[$8.jsxDEV(aS,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Move to"]},void 0,!0,void 0,this),$8.jsxDEV(_w,{children:[$8.jsxDEV(gQ,{disabled:h0==="active",onClick:()=>N0($0.id,"active"),children:"Active"},void 0,!1,void 0,this),$8.jsxDEV(gQ,{disabled:h0==="backlog",onClick:()=>N0($0.id,"backlog"),children:"Backlog"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(yD,{children:[$8.jsxDEV(kw,{disabled:q.length<=1,children:[$8.jsxDEV(nX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Change Track"]},void 0,!0,void 0,this),$8.jsxDEV(_w,{children:q.filter((e0)=>e0.name!==$0.fields?.track).map((e0)=>$8.jsxDEV(gQ,{onClick:()=>A0($0.id,e0.name),children:e0.name},e0.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},$0.id,!0,void 0,this)})},void 0,!1,void 0,this),$8.jsxDEV(D6,{open:E,onOpenChange:W8,children:$8.jsxDEV(O6,{children:[$8.jsxDEV(M6,{children:$8.jsxDEV(L6,{children:"Create Story"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"space-y-4 py-4",children:[$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"name",children:"Name"},void 0,!1,void 0,this),$8.jsxDEV(u6,{id:"name",value:b,onChange:($0)=>_($0.target.value),placeholder:"Enter story name",onKeyDown:($0)=>$0.key==="Enter"&&x8()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"track",children:"Track"},void 0,!1,void 0,this),$8.jsxDEV(IJ,{value:k,onValueChange:v,children:[$8.jsxDEV(BJ,{children:$8.jsxDEV(VJ,{placeholder:"Select track"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(FJ,{children:q.map(($0)=>$8.jsxDEV(BZ,{value:$0.name,children:$0.name},$0.name,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"state",children:"Initial State"},void 0,!1,void 0,this),$8.jsxDEV(IJ,{value:f,onValueChange:h,children:[$8.jsxDEV(BJ,{children:$8.jsxDEV(VJ,{placeholder:"Select state"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(FJ,{children:T(k).map(($0)=>$8.jsxDEV(BZ,{value:$0,children:$0.charAt(0).toUpperCase()+$0.slice(1)},$0,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x&&$8.jsxDEV("div",{className:"text-sm text-destructive",children:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$8.jsxDEV(i6,{children:[$8.jsxDEV(q8,{variant:"outline",onClick:W8,children:"Cancel"},void 0,!1,void 0,this),$8.jsxDEV(q8,{onClick:x8,disabled:R.isPending,children:R.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),$8.jsxDEV(D6,{open:e,onOpenChange:J0,children:$8.jsxDEV(O6,{children:[$8.jsxDEV(M6,{children:$8.jsxDEV(L6,{className:"flex items-center gap-2 text-destructive",children:[$8.jsxDEV(w7,{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),$8.jsxDEV("p",{className:"text-sm",children:["Are you sure you want to delete ",$8.jsxDEV("strong",{children:U.find(($0)=>$0.id===m)?.name},void 0,!1,void 0,this),"? This will remove the story and all its contents."]},void 0,!0,void 0,this),t&&$8.jsxDEV("div",{className:"text-sm text-destructive",children:t},void 0,!1,void 0,this),$8.jsxDEV(i6,{children:[$8.jsxDEV(q8,{variant:"outline",onClick:()=>J0(!1),children:"Cancel"},void 0,!1,void 0,this),$8.jsxDEV(q8,{variant:"destructive",onClick:()=>{B0(null),w.mutate({id:m},{onSuccess:()=>{J0(!1),u(null)},onError:($0)=>B0($0.message)})},disabled:w.isPending,children:w.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),$8.jsxDEV(D6,{open:n,onOpenChange:($0)=>{if(!$0)H0(!1),U0(null),K0(null),z0("")},children:$8.jsxDEV(O6,{children:[$8.jsxDEV(M6,{children:$8.jsxDEV(L6,{children:"Change Track"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV("div",{className:"space-y-4 py-4",children:[$8.jsxDEV("p",{className:"text-sm text-muted-foreground",children:["The current state is not available in ",$8.jsxDEV("strong",{children:Y0},void 0,!1,void 0,this),". Select a new state to continue:"]},void 0,!0,void 0,this),$8.jsxDEV("div",{className:"space-y-2",children:[$8.jsxDEV(g6,{htmlFor:"change-track-state",children:"State"},void 0,!1,void 0,this),$8.jsxDEV(IJ,{value:F0,onValueChange:z0,children:[$8.jsxDEV(BJ,{id:"change-track-state",children:$8.jsxDEV(VJ,{placeholder:"Select state"},void 0,!1,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(FJ,{children:T(Y0??"").map(($0)=>$8.jsxDEV(BZ,{value:$0,children:$0.charAt(0).toUpperCase()+$0.slice(1)},$0,!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),$8.jsxDEV(i6,{children:[$8.jsxDEV(q8,{variant:"outline",onClick:()=>H0(!1),children:"Cancel"},void 0,!1,void 0,this),$8.jsxDEV(q8,{onClick:x0,disabled:!F0||C.isPending,children:C.isPending?"Changing...":"OK"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),$8.jsxDEV(r2,{open:!!V0,onOpenChange:($0)=>{if(!$0)O0(null),X0(null)},projectId:Z,templateId:V0,templatePath:K8?.path||K8?.name,mode:"story",storyId:S0,rootFolderId:S0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var U1=W0(t0(),1);var UP9=W0(t0(),1);var w5=W0(N8(),1),GP9=({status:Z})=>{let J={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",stopped:"text-orange-700 border-orange-300 bg-orange-50 dark:text-orange-300 dark:border-orange-700 dark:bg-orange-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 w5.jsxDEV("span",{className:`inline-flex items-center rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase ${J[Z]||J.pending}`,children:Z},void 0,!1,void 0,this)},sH8=(Z)=>{if(!Z)return"-";return new Date(Z).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})},zP9=(Z)=>{if(Z===null||Z===void 0)return"-";if(Z>=1000)return`${(Z/1000).toFixed(1)}k`;return Z.toString()},hM0=async(Z)=>{if(!Z)return;try{await navigator.clipboard.writeText(Z),a8.success("Copied")}catch(J){console.error("Failed to copy:",J)}},Me=(Z,J)=>{if(!Z||!J)return null;let Q=`${J}/worktree/`;if(Z.startsWith(Q)){let X=Z.slice(Q.length),K=X.endsWith("/")?X.slice(0,-1):X,Y=K.indexOf("/");return Y===-1?K:K.slice(0,Y)}if(Z.startsWith(J)){let X=Z.slice(J.length);return X.startsWith("/")?X.slice(1):X}return Z},iD=({job:Z,onClick:J,projectPath:Q})=>{let X=Me(Z.fields?.workingDirectory,Q);return w5.jsxDEV("div",{onClick:()=>J(Z),className:"p-3 rounded cursor-pointer flex items-center gap-3 hover:bg-muted border-b border-border last:border-b-0",children:[w5.jsxDEV("div",{className:"w-[78px] flex-shrink-0 flex items-center",children:w5.jsxDEV(GP9,{status:Z.fields?.status},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV(y9,{content:"Click to copy",children:w5.jsxDEV("span",{className:"w-16 text-xs font-mono cursor-pointer hover:text-primary",onClick:(K)=>{K.stopPropagation(),hM0(Z.id)},children:Z.id},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV(y9,{content:"Click to copy",children:w5.jsxDEV("span",{className:"w-64 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary truncate",onClick:(K)=>{if(K.stopPropagation(),Z.fields?.sessionId)hM0(Z.fields?.sessionId)},children:Z.fields?.sessionId?Z.fields?.sessionId.slice(0,24)+"...":"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV("div",{className:"flex-1 min-w-0",children:[w5.jsxDEV("span",{className:"truncate text-sm font-medium block",children:Z.name},void 0,!1,void 0,this),X&&w5.jsxDEV(y9,{content:Z.fields?.workingDirectory,children:w5.jsxDEV("span",{className:"text-xs text-muted-foreground truncate block",children:X},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-16",children:Z.fields?.agent},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-24 truncate",children:Z.fields?.model||"-"},void 0,!1,void 0,this),w5.jsxDEV(y9,{content:"Click to copy",children:w5.jsxDEV("span",{className:"w-16 text-xs font-mono text-muted-foreground cursor-pointer hover:text-primary",onClick:(K)=>{if(K.stopPropagation(),Z.fields?.pid)hM0(Z.fields?.pid)},children:Z.fields?.pid||"-"},void 0,!1,void 0,this)},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:sH8(Z.fields?.startedAt)},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-28",children:sH8(Z.fields?.completedAt)},void 0,!1,void 0,this),w5.jsxDEV("span",{className:"text-xs text-muted-foreground w-16 text-right",children:zP9(Z.fields?.tokensUsed)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var $4=W0(t0(),1);var a9=W0(N8(),1),WP9=[{value:"claude",label:"Claude"},{value:"codex",label:"Codex"}],nH8=({open:Z,onOpenChange:J,projectId:Q,onSuccess:X,initialPrompt:K=""})=>{let[Y,U]=$4.useState(""),[G,z]=$4.useState("claude"),[W,q]=$4.useState(""),[H,B]=$4.useState(""),[O,M]=$4.useState({type:"main",path:null}),[A,R]=$4.useState(""),[N,w]=$4.useState(""),[P,C]=$4.useState(!1),[T,$]=$4.useState(!0),[D,E]=$4.useState(!1),[j,b]=$4.useState(!1),[_,k]=$4.useState({}),[v,f]=$4.useState(!1),[h,x]=$4.useState(null),[g,m]=$4.useState(null),[u,d]=$4.useState(null),p=$4.useRef(null),s=Q?.charAt(0)||"A";$4.useEffect(()=>{if(K)R(K)},[K]),$4.useEffect(()=>{if(Z&&p.current){let m0=setTimeout(()=>{p.current?.focus()},50);return()=>clearTimeout(m0)}},[Z]);let{data:e,isLoading:J0,error:t}=uD(Z?Q:null),B0=e?.worktrees??[],n=e?.isGitProject??!0,H0=Qe(Q),Q0=ot(Q),U0=pD(Q),{data:Y0}=fD(Q,N.trim()||null),K0=Y0?.parameters??[],F0=Y0?.detectedVariables??[],z0=N.trim().length>0,V0=()=>{U(""),z("claude"),q(""),B(""),M({type:"main",path:null}),R(K||""),w(""),C(!1),$(!0),x(null),m(null),k({}),f(!1),E(!1)},O0=()=>{V0(),J(!1)},S0=()=>{if(O.type==="main")return;return O.path||void 0},X0=(m0)=>{H0.mutate({name:Y.trim()||void 0,agent:G,model:W.trim()||void 0,prompt:A.trim(),workingDirectory:m0,streaming:P,skipPermissions:T,dockerImage:H.trim()||void 0},{onSuccess:(b0)=>{if(O0(),X)X(b0)},onError:(b0)=>{if(b0.code==="DUPLICATE_NAME"){let G8=Y.trim()||cD(b0.message);if(G8)d({originalName:G8,suggestedName:xL(G8)});else x(b0.message)}else x(b0.message)}})},K8=()=>{if(!A.trim()){x("Prompt is required");return}if(O.type==="new"&&n){if(!O.branch||!O.branch.trim()){m("Branch name is required");return}}if(x(null),m(null),O.type==="new"&&n&&O.branch)U0.mutate({branch:O.branch.trim(),baseBranch:O.baseBranch?.trim()||void 0},{onSuccess:(m0)=>{X0(m0.path)},onError:(m0)=>{m(m0.message)}});else X0(S0())},C0=()=>{b(!0)},H8=(m0)=>{k(m0),Q0.mutate({id:N.trim(),params:m0,target:"stdout"},{onSuccess:(b0)=>{if(b0.content)R(b0.content);w(""),b(!1)},onError:(b0)=>{x(`Template render failed: ${b0.message}`),b(!1)}})},L8=z0?"render":"run",s0=L8==="run"&&!A.trim(),E0=U0.isPending,p0=H0.isPending||Q0.isPending||E0;return a9.jsxDEV(a9.Fragment,{children:[a9.jsxDEV(D6,{open:Z,onOpenChange:O0,children:a9.jsxDEV(O6,{className:"max-w-7xl",children:[a9.jsxDEV(M6,{children:a9.jsxDEV(L6,{children:"New Job"},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV("div",{className:"space-y-4 py-4",children:[a9.jsxDEV("div",{className:"grid grid-cols-4 gap-4",children:[a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-name",children:"Name"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-name",value:Y,onChange:(m0)=>U(m0.target.value),placeholder:"Auto-generated if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-agent",children:"Agent"},void 0,!1,void 0,this),a9.jsxDEV(IJ,{value:G,onValueChange:z,children:[a9.jsxDEV(BJ,{children:a9.jsxDEV(VJ,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV(FJ,{children:WP9.map((m0)=>a9.jsxDEV(BZ,{value:m0.value,children:m0.label},m0.value,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-model",children:"Model"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-model",value:W,onChange:(m0)=>q(m0.target.value),placeholder:"Optional"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-docker-image",children:"Docker Image"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-docker-image",value:H,onChange:(m0)=>B(m0.target.value),placeholder:"Optional"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),G==="claude"&&a9.jsxDEV("div",{className:"grid grid-cols-2 gap-4",children:[a9.jsxDEV("div",{className:"flex items-center gap-2",children:[a9.jsxDEV(g1,{id:"job-streaming",checked:P,onCheckedChange:C},void 0,!1,void 0,this),a9.jsxDEV(g6,{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),a9.jsxDEV("div",{className:"flex items-center gap-2",children:[a9.jsxDEV(g1,{id:"job-skip-permissions",checked:T,onCheckedChange:$},void 0,!1,void 0,this),a9.jsxDEV(g6,{htmlFor:"job-skip-permissions",className:"text-sm font-normal cursor-pointer",children:"Skip permission prompts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV("button",{type:"button",onClick:()=>f(!v),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[v?a9.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):a9.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),a9.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),v&&a9.jsxDEV(gD,{value:O,onChange:M,worktrees:B0,isLoadingWorktrees:J0,isGitProject:n,error:t,createError:g,onCreateErrorClear:()=>m(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-prompt",children:"Enter Prompt"},void 0,!1,void 0,this),a9.jsxDEV("div",{className:"relative",children:[a9.jsxDEV(oU,{ref:p,id:"job-prompt",value:A,onChange:(m0)=>R(m0.target.value),placeholder:"Enter the prompt for the agent...",rows:6,className:"pr-8"},void 0,!1,void 0,this),a9.jsxDEV(q8,{type:"button",variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-6 w-6",onClick:()=>E(!0),"aria-label":"Open in editor",children:a9.jsxDEV(Rz,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV(kH,{open:D,onOpenChange:E,value:A,onSave:(m0)=>{R(m0),E(!1)},projectId:Q,storeCode:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV("div",{className:"space-y-2",children:[a9.jsxDEV(g6,{htmlFor:"job-template",children:"OR Create prompt with a template"},void 0,!1,void 0,this),a9.jsxDEV(u6,{id:"job-template",value:N,onChange:(m0)=>w(m0.target.value),placeholder:"Template ID (optional)"},void 0,!1,void 0,this),z0&&a9.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),h&&a9.jsxDEV("div",{className:"text-sm text-destructive",children:h},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a9.jsxDEV(i6,{children:[a9.jsxDEV(q8,{variant:"outline",onClick:O0,children:"Cancel"},void 0,!1,void 0,this),L8==="render"?a9.jsxDEV(q8,{onClick:C0,disabled:p0,children:[a9.jsxDEV(G4,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),p0?"Rendering...":"Render"]},void 0,!0,void 0,this):a9.jsxDEV(q8,{onClick:K8,disabled:s0||p0,children:[a9.jsxDEV(pU,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),E0?"Creating worktree...":H0.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),a9.jsxDEV(D6,{open:j,onOpenChange:b,children:a9.jsxDEV(O6,{className:"max-w-7xl",children:[a9.jsxDEV(M6,{children:a9.jsxDEV(L6,{className:"flex items-center gap-2",children:[a9.jsxDEV(G4,{className:"w-4 h-4"},void 0,!1,void 0,this),"Render Template - ",wY(Y0?.path)," (",N,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV(Je,{fields:K0,detectedVariables:F0,initialValues:_,onSubmit:H8,onCancel:()=>b(!1),isSubmitting:Q0.isPending,autoFocusFirst:!0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),u&&a9.jsxDEV(D6,{open:!0,onOpenChange:()=>d(null),children:a9.jsxDEV(O6,{children:[a9.jsxDEV(M6,{children:a9.jsxDEV(L6,{children:"Duplicate Job Name"},void 0,!1,void 0,this)},void 0,!1,void 0,this),a9.jsxDEV("p",{children:['Job "',u.originalName,'" already exists.']},void 0,!0,void 0,this),a9.jsxDEV("p",{children:['Call it "',u.suggestedName,'"?']},void 0,!0,void 0,this),a9.jsxDEV(i6,{children:[a9.jsxDEV(q8,{variant:"outline",onClick:()=>d(null),children:"Cancel"},void 0,!1,void 0,this),a9.jsxDEV(q8,{onClick:()=>{let m0=u.suggestedName;U(m0),d(null),H0.mutate({name:m0,agent:G,model:W.trim()||void 0,prompt:A.trim(),workingDirectory:S0(),streaming:P,skipPermissions:T,dockerImage:H.trim()||void 0},{onSuccess:(b0)=>{if(O0(),X)X(b0)},onError:(b0)=>{if(b0.code==="DUPLICATE_NAME"){let G8=m0||cD(b0.message);if(G8)d({originalName:G8,suggestedName:xL(G8)});else x(b0.message)}else x(b0.message)}})},children:"OK"},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 rH8=5000;function Le(Z,J,Q){if(!Z||Z.length===0)return[];let X=new Map;for(let G of Z)X.set(G.id,{job:G,children:[],depth:0});let K=[];for(let G of Z){let z=X.get(G.id),W=G.fields?.parentJobId;if(!W||!X.has(W)||!G.fields?.blocking){K.push(z);continue}let q=!1,H=W,B=new Set;while(H&&X.has(H)){if(H===G.id){q=!0;break}if(B.has(H))break;B.add(H),H=X.get(H).job.fields?.parentJobId}if(q)K.push(z);else X.get(W).children.push(z)}let Y=(G,z)=>{for(let W of G)if(W.depth=z,W.children.length>0)Y(W.children,z+1)};Y(K,0);let U=(G)=>{G.sort((z,W)=>{if(J==="name"){let O=z.job.name??null,M=W.job.name??null;if(O===null&&M===null)return 0;if(O===null)return 1;if(M===null)return-1;let A=O.localeCompare(M);return Q==="desc"?-A:A}let q=J==="completedAt"?"completedAt":"startedAt",H=z.job.fields?.[q]?new Date(z.job.fields[q]).getTime():null,B=W.job.fields?.[q]?new Date(W.job.fields[q]).getTime():null;if(H===null&&B===null)return 0;if(H===null)return 1;if(B===null)return-1;return Q==="desc"?B-H:H-B});for(let z of G)if(z.children.length>0)U(z.children)};return U(K),K}var qP9=W0(t0(),1),B3=W0(N8(),1),Ae=({depth:Z,ancestorContinues:J,isLastChild:Q})=>{if(Z===0)return null;return B3.jsxDEV(B3.Fragment,{children:[J.slice(1).map((X,K)=>B3.jsxDEV("div",{className:"w-6 flex-shrink-0 relative",children:X&&B3.jsxDEV("div",{className:"absolute left-1/2 top-0 bottom-0 border-l border-muted-foreground/50"},void 0,!1,void 0,this)},K,!1,void 0,this)),B3.jsxDEV("div",{className:"w-6 flex-shrink-0 relative",children:[B3.jsxDEV("div",{className:`absolute left-1/2 top-0 ${Q?"h-1/2":"bottom-0"} border-l border-muted-foreground/50`},void 0,!1,void 0,this),B3.jsxDEV("div",{className:"absolute left-1/2 right-0 top-1/2 border-t border-muted-foreground/50"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var u9=W0(N8(),1),aH8=50,oH8=25,yM0=[{value:"active",label:"Active",icon:uA},{value:"recent",label:"Recently Completed",icon:IB},{value:"history",label:"History",icon:gG}],HP9={active:["running","pending"],recent:["completed","error","stopped"],history:["completed","error","stopped"]},Ne=[{key:"startedAt-desc",icon:Lz,label:"Started date newest first"},{key:"startedAt-asc",icon:Az,label:"Started date oldest first"},{key:"completedAt-desc",icon:Lz,label:"Completed date newest first"},{key:"completedAt-asc",icon:Az,label:"Completed date oldest first"},{key:"name-asc",icon:hG,label:"Name A → Z"},{key:"name-desc",icon:xG,label:"Name Z → A"}],BP9=new Set(Ne.map((Z)=>Z.key)),gx=()=>{let{id:Z,storeCode:J}=YQ(),Q=PZ(),{data:X}=k4(Z);A1(X?`${X.name} - Jobs`:"CAW");let K=J??"A",{phase:Y,activeStatuses:U,setPhase:G,setActiveStatuses:z}=aT0(Z),[W,q]=PY(Z,"jobs","sortMode","startedAt-desc",K),[H,B]=PY(Z,"jobs","viewMode","flat",K),[O,M]=PY(Z,"jobs","page-active",1,K),[A,R]=PY(Z,"jobs","page-recent",1,K),[N,w]=PY(Z,"jobs","page-history",1,K),[P,C]=U1.useState(!1),[T,$]=U1.useState(""),[D,E]=U1.useState(new Set),j=U1.useRef(null),b=U1.useRef(!0);Rq(Z);let _=HP9[Y]??[],k=U1.useMemo(()=>{if(!U||U.length===0)return _;let s0=U.filter((E0)=>_.includes(E0));return s0.length>0?s0:_},[U,_]),v=U1.useMemo(()=>new Set(k),[k]),f=BP9.has(W)?W:"startedAt-desc",h=f.lastIndexOf("-"),x=f.substring(0,h),g=f.substring(h+1),m=Y==="active"?O:Y==="recent"?A:N,u=Y==="active"?M:Y==="recent"?R:w,d=H==="tree"?oH8:aH8,p=(m-1)*d,{data:s,isLoading:e,error:J0,refetch:t}=mD(Z,H==="tree"?{store:K,phase:Y,status:k,sortBy:x,sortDir:g,limit:oH8,offset:p,treeMode:!0}:{store:K,phase:Y,status:k,sortBy:x,sortDir:g,limit:aH8,offset:p}),B0=s?.jobs??[],n=s?.total??0,H0=n>0?Math.ceil(n/d):0,Q0=H0>0?Math.min(m,Math.max(1,H0)):1;gH(Z,"jobs","content",j,!e,K),U1.useEffect(()=>{if(J==="B")Q(`/project/${Z}/store/B/documents`,{replace:!0})},[J,Z,Q]),U1.useEffect(()=>{if(b.current){b.current=!1;return}u(1)},[Y,W,U]),U1.useEffect(()=>{if(!e&&n>0&&p>=n)u(Math.max(1,Math.ceil(n/d)))},[e,n,p,d]);let U0=H==="tree",Y0=U1.useMemo(()=>U0?Le(B0,x,g):[],[B0,U0,x,g]),K0=U1.useMemo(()=>{if(!U0)return[];let s0=(E0,p0=[])=>{let m0=[];for(let b0=0;b0<E0.length;b0++){let G8=E0[b0],D0=b0===E0.length-1;if(m0.push({...G8,isLastChild:D0,ancestorContinues:[...p0]}),G8.children.length>0&&D.has(G8.job.id))m0.push(...s0(G8.children,[...p0,!D0]))}return m0};return s0(Y0)},[Y0,D,U0]);if(J==="B")return null;if(e)return u9.jsxDEV("div",{className:"p-6 text-muted-foreground",children:"Loading jobs..."},void 0,!1,void 0,this);if(J0)return u9.jsxDEV("div",{className:"p-6",children:[u9.jsxDEV("div",{className:"text-destructive font-medium",children:"Error loading jobs"},void 0,!1,void 0,this),u9.jsxDEV("div",{className:"text-sm text-muted-foreground mt-1",children:J0.message},void 0,!1,void 0,this),u9.jsxDEV(q8,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>t(),children:[u9.jsxDEV($B,{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);let F0=()=>{if(H==="flat")E(new Set);B(H==="tree"?"flat":"tree"),u(1)},z0=(s0)=>{E((E0)=>{let p0=new Set(E0);if(p0.has(s0))p0.delete(s0);else p0.add(s0);return p0})},V0=()=>{let s0=new Set,E0=(p0)=>{for(let m0 of p0)if(m0.children.length>0)s0.add(m0.job.id),E0(m0.children)};E0(Y0),E(s0)},O0=()=>{E(new Set)},S0=(s0)=>{let E0=U?new Set(U):new Set(_),p0=new Set(E0);if(p0.has(s0))p0.delete(s0);else p0.add(s0);z(p0.size===_.length?null:[...p0])},X0=(s0)=>{let E0=J?`/project/${Z}/store/${J}/job/${s0.id}?from=jobs`:`/project/${Z}/job/${s0.id}?from=jobs`;Q(E0)},K8=(s0)=>{if(s0?.id){let E0=J?`/project/${Z}/store/${J}/job/${s0.id}?from=jobs`:`/project/${Z}/job/${s0.id}?from=jobs`;Q(E0)}},C0=yM0.find((s0)=>s0.value===Y)??yM0[0],H8=Ne.find((s0)=>s0.key===f)??Ne[0],L8=!!U&&U.length>0;return u9.jsxDEV("div",{className:"h-full flex flex-col p-6",children:[u9.jsxDEV("div",{className:"flex items-center justify-between mb-4",children:[u9.jsxDEV("div",{className:"flex items-center gap-2",children:[u9.jsxDEV(q8,{size:"sm",variant:"warning",onClick:()=>C(!0),children:[u9.jsxDEV(z4,{className:"w-4 h-4"},void 0,!1,void 0,this),u9.jsxDEV(dG,{className:"w-4 h-4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV(q3,{orientation:"vertical",className:"h-6 mx-2"},void 0,!1,void 0,this),u9.jsxDEV(A4,{children:[u9.jsxDEV(y9,{content:H8.label,children:u9.jsxDEV(sQ,{asChild:!0,children:u9.jsxDEV(q8,{size:"sm",variant:"outline",children:U1.default.createElement(H8.icon,{className:"w-4 h-4"})},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(nQ,{align:"start",children:Ne.map((s0)=>u9.jsxDEV(z6,{onClick:()=>q(s0.key),className:W===s0.key?"bg-accent":"",children:[u9.jsxDEV(s0.icon,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),s0.label]},s0.key,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV(DL,{children:[u9.jsxDEV(y9,{content:"Filter by status",children:u9.jsxDEV(EL,{asChild:!0,children:u9.jsxDEV(q8,{size:"sm",variant:"outline",children:u9.jsxDEV(Zq,{className:"w-4 h-4",...L8&&{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),u9.jsxDEV(G3,{align:"start",children:u9.jsxDEV("div",{className:"space-y-2",children:[u9.jsxDEV("div",{className:"text-sm font-medium",children:"Show by status:"},void 0,!1,void 0,this),_.map((s0)=>u9.jsxDEV("label",{className:"flex items-center gap-2",children:[u9.jsxDEV(g1,{checked:v.has(s0),onCheckedChange:()=>S0(s0)},void 0,!1,void 0,this),u9.jsxDEV("span",{className:"text-sm capitalize",children:s0},void 0,!1,void 0,this)]},s0,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV(y9,{content:U0?"Switch to flat list":"Switch to tree view",children:u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:F0,children:U0?u9.jsxDEV(nX,{className:"w-4 h-4"},void 0,!1,void 0,this):u9.jsxDEV(gA,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),U0&&u9.jsxDEV(u9.Fragment,{children:[u9.jsxDEV(y9,{content:"Expand all",children:u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:V0,children:u9.jsxDEV(mA,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(y9,{content:"Collapse all",children:u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:O0,children:u9.jsxDEV(VB,{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),u9.jsxDEV(A4,{children:[u9.jsxDEV(y9,{content:"Phase",children:u9.jsxDEV(sQ,{asChild:!0,children:u9.jsxDEV(q8,{variant:"outline",size:"sm",children:[U1.default.createElement(C0.icon,{className:"w-4 h-4 mr-1"}),C0.label,u9.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(nQ,{align:"start",children:yM0.map((s0)=>u9.jsxDEV(z6,{onClick:()=>G(s0.value),className:Y===s0.value?"bg-accent":"",children:[u9.jsxDEV(s0.icon,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),s0.label]},s0.value,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),u9.jsxDEV("div",{className:"flex items-center gap-2",children:H0>1&&u9.jsxDEV(u9.Fragment,{children:[u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>u((s0)=>s0-1),disabled:Q0===1,children:u9.jsxDEV(Nz,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV("span",{className:"text-sm text-muted-foreground px-2",children:["Page ",Q0," of ",H0]},void 0,!0,void 0,this),u9.jsxDEV(q8,{size:"sm",variant:"outline",onClick:()=>u((s0)=>s0+1),disabled:Q0===H0,children:u9.jsxDEV(tZ,{className:"w-4 h-4"},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),u9.jsxDEV("div",{ref:j,className:"flex-1 overflow-auto",children:B0.length===0?L8?u9.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No jobs match the current filters"},void 0,!1,void 0,this):u9.jsxDEV("p",{className:"text-sm text-muted-foreground py-4",children:"No jobs in this phase"},void 0,!1,void 0,this):U0?u9.jsxDEV("div",{children:K0.map((s0)=>{let E0=D.has(s0.job.id);return u9.jsxDEV("div",{className:"flex items-stretch min-w-0",children:[u9.jsxDEV(Ae,{depth:s0.depth,ancestorContinues:s0.ancestorContinues,isLastChild:s0.isLastChild},void 0,!1,void 0,this),u9.jsxDEV("div",{className:"flex-shrink-0 w-5 flex items-center justify-center self-center",children:s0.children.length>0?u9.jsxDEV("button",{className:"flex items-center justify-center text-muted-foreground hover:text-foreground",onClick:(p0)=>{p0.stopPropagation(),z0(s0.job.id)},children:u9.jsxDEV(tZ,{className:`w-3.5 h-3.5 transition-transform duration-150 ${E0?"rotate-90":""}`},void 0,!1,void 0,this)},void 0,!1,void 0,this):u9.jsxDEV("span",{className:"w-3.5 h-3.5"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV("div",{className:"flex-1 min-w-0",children:u9.jsxDEV(iD,{job:s0.job,onClick:X0,projectPath:X?.path},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},s0.job.id,!0,void 0,this)})},void 0,!1,void 0,this):u9.jsxDEV("div",{children:B0.map((s0)=>u9.jsxDEV(iD,{job:s0,onClick:X0,projectPath:X?.path},s0.id,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this),u9.jsxDEV(nH8,{open:P,onOpenChange:(s0)=>{if(C(s0),!s0)$("")},projectId:Z,onSuccess:K8,initialPrompt:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this)};var QZ=W0(t0(),1);var gM0=W0(t0(),1);var mx=W0(N8(),1),ux=({value:Z,disabled:J=!1,className:Q=""})=>{let[X,K]=gM0.useState(!1);return mx.jsxDEV(y9,{content:"Copy to clipboard",children:mx.jsxDEV(q8,{variant:"ghost",size:"sm",onClick:async()=>{if(J)return;await navigator.clipboard.writeText(Z),K(!0),setTimeout(()=>K(!1),2000)},disabled:J,className:Q,children:X?mx.jsxDEV(_5,{className:"w-4 h-4 text-green-500"},void 0,!1,void 0,this):mx.jsxDEV(uZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)};var FP9=W0(t0(),1);var t4=W0(N8(),1),tH8=({id:Z,name:J,content:Q,deepLinkUrl:X,variant:K="icon",align:Y="end"})=>{return t4.jsxDEV(A4,{children:[K==="icon"?t4.jsxDEV(y9,{content:"Copy options",children:t4.jsxDEV(sQ,{asChild:!0,onClick:(G)=>G.stopPropagation(),children:t4.jsxDEV(q8,{variant:"ghost",size:"sm",children:t4.jsxDEV(uZ,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this):t4.jsxDEV(sQ,{asChild:!0,children:t4.jsxDEV(q8,{variant:"outline",size:"sm",children:[t4.jsxDEV(uZ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Copy",t4.jsxDEV(d6,{className:"w-3 h-3 ml-1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),t4.jsxDEV(nQ,{align:Y,children:[Q&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(Q),a8.success("Content copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(uZ,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Content"]},void 0,!0,void 0,this),Z&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(Z),a8.success("ID copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(F1,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy ID"]},void 0,!0,void 0,this),J&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(J),a8.success("Name copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(bK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy Name"]},void 0,!0,void 0,this),Z&&J&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(`[${J}](${Z})`),a8.success("MD Link copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(fK,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy MD Link"]},void 0,!0,void 0,this),X&&t4.jsxDEV(z6,{onClick:async()=>{try{await navigator.clipboard.writeText(X),a8.success("URL copied")}catch{a8.error("Failed to copy")}},children:[t4.jsxDEV(sX,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Copy URL"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)};var kX=W0(t0(),1);var V6=W0(N8(),1),eH8=({open:Z,onOpenChange:J,jobName:Q,sessionId:X,agent:K,currentModel:Y,streaming:U,workingDirectory:G,dockerImage:z,skipPermissions:W,projectId:q,onContinue:H,isLoading:B})=>{let[O,M]=kX.useState(""),[A,R]=kX.useState(""),[N,w]=kX.useState(!1),[P,C]=kX.useState(""),[T,$]=kX.useState(!0),[D,E]=kX.useState({type:"main",path:null}),[j,b]=kX.useState(!1),[_,k]=kX.useState(null),[v,f]=kX.useState(!1),h=kX.useRef(null),x=q?.charAt(0)||"A",{data:g,isLoading:m,error:u}=uD(Z?q:null),d=g?.worktrees??[],p=g?.isGitProject??!0,s=pD(q);kX.useEffect(()=>{if(!Z)M(""),R(""),w(!1),C(""),$(!0),E({type:"main",path:null}),b(!1),k(null),f(!1);else R(Y||""),w(U??!1),C(z||""),$(W??!0)},[Z,Y,U,z,W]),kX.useEffect(()=>{if(Z&&g&&G)if(d.find((H0)=>H0.path===G))E({type:"worktree",path:G});else E({type:"main",path:null})},[Z,g,G,d]),kX.useEffect(()=>{if(Z&&h.current){let n=setTimeout(()=>{h.current?.focus()},50);return()=>clearTimeout(n)}},[Z]);let e=()=>{if(D.type==="main")return null;if(D.type==="worktree")return D.path;return null},J0=(n)=>{n.preventDefault();let H0=O.trim();if(!H0)return;if(k(null),D.type==="new"&&p&&D.branch)s.mutate({branch:D.branch.trim(),baseBranch:D.baseBranch?.trim()||void 0},{onSuccess:(Q0)=>{H({prompt:H0,model:A.trim()||void 0,streaming:N,workingDirectory:Q0.path,dockerImage:P.trim()||void 0,skipPermissions:T})},onError:(Q0)=>{k(Q0.message)}});else H({prompt:H0,model:A.trim()||void 0,streaming:N,workingDirectory:e(),dockerImage:P.trim()||void 0,skipPermissions:T})},t=()=>{M(""),R(""),w(!1),C(""),$(!0),E({type:"main",path:null}),b(!1),k(null),f(!1),J(!1)},B0=!O.trim()||B||s.isPending;return V6.jsxDEV(D6,{open:Z,onOpenChange:t,children:V6.jsxDEV(O6,{className:"max-w-7xl",children:[V6.jsxDEV(M6,{children:V6.jsxDEV(L6,{children:"Continue Conversation"},void 0,!1,void 0,this)},void 0,!1,void 0,this),V6.jsxDEV("form",{onSubmit:J0,className:"space-y-4",children:[V6.jsxDEV("div",{className:"grid grid-cols-4 gap-4",children:[V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-name",children:"Name"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-name",value:Q||"",readOnly:!0,className:"text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-agent",children:"Agent"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-agent",value:K||"",readOnly:!0,className:"text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-model",children:"Model"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-model",value:A,onChange:(n)=>R(n.target.value),placeholder:"Optional - uses current model if empty"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"col-span-1 space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-docker-image",children:"Docker Image"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"continue-docker-image",value:P,onChange:(n)=>C(n.target.value),placeholder:"Optional"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"session-id",children:"Session ID"},void 0,!1,void 0,this),V6.jsxDEV(u6,{id:"session-id",value:X||"",readOnly:!0,className:"font-mono text-sm bg-muted cursor-not-allowed"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K==="claude"&&V6.jsxDEV("div",{className:"grid grid-cols-2 gap-4",children:[V6.jsxDEV("div",{className:"flex items-center gap-2",children:[V6.jsxDEV(g1,{id:"continue-streaming",checked:N,onCheckedChange:w},void 0,!1,void 0,this),V6.jsxDEV(g6,{htmlFor:"continue-streaming",className:"text-sm font-normal cursor-pointer",children:"Enable streaming output"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"flex items-center gap-2",children:[V6.jsxDEV(g1,{id:"continue-skip-permissions",checked:T,onCheckedChange:$},void 0,!1,void 0,this),V6.jsxDEV(g6,{htmlFor:"continue-skip-permissions",className:"text-sm font-normal cursor-pointer",children:"Skip permission prompts"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"space-y-2",children:[V6.jsxDEV("button",{type:"button",onClick:()=>b(!j),className:"flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground",children:[j?V6.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):V6.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),V6.jsxDEV("span",{children:"Worktree Selection for Coding Jobs"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&V6.jsxDEV(gD,{value:D,onChange:E,worktrees:d,isLoadingWorktrees:m,isGitProject:p,error:u,createError:_,onCreateErrorClear:()=>k(null)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV("div",{className:"space-y-2",children:[V6.jsxDEV(g6,{htmlFor:"continue-prompt",children:"Prompt"},void 0,!1,void 0,this),V6.jsxDEV("div",{className:"relative",children:[V6.jsxDEV(oU,{ref:h,id:"continue-prompt",value:O,onChange:(n)=>M(n.target.value),placeholder:"Enter your follow-up prompt...",rows:6,className:"pr-8",autoFocus:!0},void 0,!1,void 0,this),V6.jsxDEV(q8,{type:"button",variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-6 w-6",onClick:()=>f(!0),"aria-label":"Open in editor",children:V6.jsxDEV(Rz,{className:"h-4 w-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),V6.jsxDEV(kH,{open:v,onOpenChange:f,value:O,onSave:(n)=>{M(n),f(!1)},projectId:q,storeCode:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),V6.jsxDEV(i6,{children:[V6.jsxDEV(q8,{type:"button",variant:"outline",onClick:t,children:"Cancel"},void 0,!1,void 0,this),V6.jsxDEV(q8,{type:"submit",disabled:B0,children:[(B||s.isPending)&&V6.jsxDEV(G7,{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 OP9=W0(t0(),1);var P5=W0(N8(),1),ZB8=({open:Z,onOpenChange:J,projectId:Q,jobId:X,pid:K})=>{let{data:Y,isLoading:U,error:G,refetch:z}=WH8(Q,X,Z),W=()=>{if(U)return P5.jsxDEV(G7,{className:"w-5 h-5 animate-spin text-muted-foreground"},void 0,!1,void 0,this);if(G)return P5.jsxDEV(w7,{className:"w-5 h-5 text-destructive"},void 0,!1,void 0,this);if(Y?.exists)return P5.jsxDEV(yG,{className:"w-5 h-5 text-green-600"},void 0,!1,void 0,this);return P5.jsxDEV(tW,{className:"w-5 h-5 text-muted-foreground"},void 0,!1,void 0,this)},q=()=>{if(U)return"Checking process...";if(G)return`Error: ${G.message}`;if(Y?.error)return Y.error;if(!Y?.exists)return"Process not running";return`Process is ${Y.state||"active"}`};return P5.jsxDEV(D6,{open:Z,onOpenChange:J,children:P5.jsxDEV(O6,{children:[P5.jsxDEV(M6,{children:P5.jsxDEV(L6,{children:"Process Diagnostics"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P5.jsxDEV("div",{className:"space-y-4",children:[P5.jsxDEV("div",{className:"flex items-center gap-3 p-4 border rounded-lg",children:[W(),P5.jsxDEV("div",{children:[P5.jsxDEV("p",{className:"font-medium",children:q()},void 0,!1,void 0,this),P5.jsxDEV("p",{className:"text-sm text-muted-foreground font-mono",children:["PID: ",K]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y?.exists&&Y?.command&&P5.jsxDEV("div",{className:"text-sm",children:[P5.jsxDEV("span",{className:"font-medium",children:"Command: "},void 0,!1,void 0,this),P5.jsxDEV("span",{className:"font-mono",children:Y.command},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P5.jsxDEV(i6,{children:[P5.jsxDEV(q8,{variant:"outline",onClick:()=>z(),children:"Refresh"},void 0,!1,void 0,this),P5.jsxDEV(q8,{onClick:()=>J(!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 u8=W0(N8(),1),MP9=({status:Z})=>{let J={running:{icon:G7,class:"text-blue-700 border-blue-300 bg-blue-50",animate:!0},completed:{icon:yG,class:"text-green-700 border-green-300 bg-green-50",animate:!1},error:{icon:tW,class:"text-red-700 border-red-300 bg-red-50",animate:!1},stopped:{icon:i3,class:"text-orange-700 border-orange-300 bg-orange-50",animate:!1},pending:{icon:IB,class:"text-gray-700 border-gray-300 bg-gray-50",animate:!1}},{icon:Q,class:X,animate:K}=J[Z]||J.pending;return u8.jsxDEV("span",{className:`inline-flex items-center gap-1.5 rounded border px-2 py-1 text-sm font-medium ${X}`,children:[u8.jsxDEV(Q,{className:`w-4 h-4 ${K?"animate-spin":""}`},void 0,!1,void 0,this),Z]},void 0,!0,void 0,this)},JB8=(Z)=>{if(!Z)return"-";return new Date(Z).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})},LP9=(Z)=>{if(Z===null||Z===void 0)return"-";let J=parseInt(Z,10);if(isNaN(J))return Z;if(J>=1000)return`${(J/1000).toFixed(1)}k`;return J.toString()},mM0=(Z)=>{if(!Z)return[];let J=/---\n## Turn (\d+)\n/g,Q=[...Z.matchAll(J)];if(Q.length===0)return[{turnNumber:1,content:Z.trim()}];let X=[],K=Q[0].index,Y=Z.slice(0,K).trim();if(Y)X.push({turnNumber:1,content:Y});for(let U=0;U<Q.length;U++){let G=Q[U],z=parseInt(G[1],10),W=G.index+G[0].length,q=Q[U+1]?.index??Z.length,H=Z.slice(W,q).trim();X.push({turnNumber:z,content:H})}return X},AP9=(Z)=>{if(!Z||!Array.isArray(Z))return!1;return Z.some((J)=>J.name==="prompt.md")},NP9=(Z)=>{if(!Z||!Array.isArray(Z))return[];let J=/^prompt-(\d+)\.md$/,Q=/^output-(\d+)\.md$/,X=Z.filter((Y)=>Y.name&&J.test(Y.name)).map((Y)=>({...Y,turnNumber:parseInt(Y.name.match(J)[1],10)})).sort((Y,U)=>Y.turnNumber-U.turnNumber),K=Z.filter((Y)=>Y.name&&Q.test(Y.name)).reduce((Y,U)=>{let G=U.name.match(Q);if(G)Y[parseInt(G[1],10)]=U;return Y},{});return X.map((Y)=>({turnNumber:Y.turnNumber,promptDoc:Y,outputDoc:K[Y.turnNumber]||null}))},Re=({title:Z,docId:J,docName:Q,docContent:X,isOpen:K,onToggle:Y,deepLinkUrl:U,onFieldsClick:G,children:z})=>u8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[u8.jsxDEV("div",{role:"button",tabIndex:0,onClick:()=>Y(!K),onKeyDown:(W)=>{if(W.key==="Enter"||W.key===" ")W.preventDefault(),Y(!K)},className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[K?u8.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):u8.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),u8.jsxDEV(G4,{className:"w-4 h-4 text-muted-foreground"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"font-medium",children:Z},void 0,!1,void 0,this),J&&u8.jsxDEV("span",{className:"text-xs text-muted-foreground ml-auto font-mono flex items-center gap-1",children:[G&&u8.jsxDEV(q8,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:(W)=>{W.stopPropagation(),G()},children:u8.jsxDEV(WT,{className:"w-3 h-3"},void 0,!1,void 0,this)},void 0,!1,void 0,this),J,u8.jsxDEV(tH8,{id:J,name:Q,content:X,deepLinkUrl:U,variant:"icon"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),K&&u8.jsxDEV("div",{className:"p-4",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),uM0=({turnNumber:Z,promptContent:J,outputContent:Q,showHeading:X,promptDocId:K,outputDocId:Y,promptDocName:U,outputDocName:G,isPromptOpen:z,setIsPromptOpen:W,isOutputOpen:q,setIsOutputOpen:H,onInternalLinkClick:B,promptDeepLinkUrl:O,outputDeepLinkUrl:M,sectionRef:A,highlightedSection:R,onPromptFieldsClick:N,onOutputFieldsClick:w})=>{return u8.jsxDEV("div",{className:"space-y-4",ref:R?A:null,children:[X&&u8.jsxDEV("h3",{className:"text-lg font-semibold text-muted-foreground",children:["Turn ",Z]},void 0,!0,void 0,this),Q&&u8.jsxDEV(Re,{title:"Output",docId:Y,docName:G,docContent:Q,isOpen:q,onToggle:H,deepLinkUrl:M,onFieldsClick:w,children:u8.jsxDEV(MK,{markdown:Q,onInternalLinkClick:B},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(Re,{title:"Prompt",docId:K,docName:U,docContent:J,isOpen:z,onToggle:W,deepLinkUrl:O,onFieldsClick:N,children:u8.jsxDEV(MK,{markdown:J||"",onInternalLinkClick:B},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},QB8=({content:Z,isOpen:J,onToggle:Q,onInternalLinkClick:X})=>u8.jsxDEV("div",{className:"border rounded-lg overflow-hidden",children:[u8.jsxDEV("div",{role:"button",tabIndex:0,onClick:()=>Q(!J),onKeyDown:(K)=>{if(K.key==="Enter"||K.key===" ")K.preventDefault(),Q(!J)},className:"w-full flex items-center gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors cursor-pointer",children:[J?u8.jsxDEV(d6,{className:"w-4 h-4"},void 0,!1,void 0,this):u8.jsxDEV(tZ,{className:"w-4 h-4"},void 0,!1,void 0,this),u8.jsxDEV(Yj,{className:"w-4 h-4 text-blue-500 animate-pulse"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"font-medium",children:"Output"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&u8.jsxDEV("div",{className:"p-4",children:Z?u8.jsxDEV("div",{className:"overflow-auto max-h-[600px]",children:u8.jsxDEV(MK,{markdown:Z,onInternalLinkClick:X},void 0,!1,void 0,this)},void 0,!1,void 0,this):u8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-4",children:[u8.jsxDEV(G7,{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),RP9=86400000,wP9=["active","history"],pM0=()=>{let{id:Z,storeCode:J,jobId:Q}=YQ(),X=PZ(),K=sJ(),{data:Y}=k4(Z),{fromContext:U}=hL(),G=new URLSearchParams(K.search).get("doc");A1(Y?`${Y.name} - Job: ${Q}`:"CAW"),Rq(Z);let[z,W]=QZ.useState(""),[q,H]=QZ.useState(!1),B=QZ.useRef(null),O=QZ.useRef(!1),{data:M,isLoading:A,error:R}=YH8(Z,Q),{data:N,isLoading:w}=UH8(Z,Q),{isLegacy:P,promptDoc:C,outputDoc:T,turns:$}=QZ.useMemo(()=>{if(!N)return{isLegacy:!0,promptDoc:null,outputDoc:null,turns:[]};let g0=N.documents||[];if(AP9(g0)){let Q8=g0.find((h0)=>h0.name==="prompt.md"),L0=g0.find((h0)=>h0.name==="output.md");return{isLegacy:!0,promptDoc:Q8,outputDoc:L0,turns:[]}}else{let Q8=NP9(g0),L0=Q8[Q8.length-1];return{isLegacy:!1,promptDoc:L0?.promptDoc||null,outputDoc:L0?.outputDoc||null,turns:Q8}}},[N]),{data:D}=VW(Z,P?C?.id:null),{data:E}=VW(Z,P?T?.id:null),j=QZ.useMemo(()=>{if(P)return[];let g0=[];for(let r0 of $){if(r0.promptDoc?.id)g0.push(r0.promptDoc.id);if(r0.outputDoc?.id)g0.push(r0.outputDoc.id)}return g0},[P,$]),b=bA({queries:j.map((g0)=>({queryKey:["document",g0],queryFn:()=>gz(Z,g0),enabled:!!Z&&!!g0&&!P}))}),_=QZ.useMemo(()=>{if(P)return{};let g0={};return j.forEach((r0,Q8)=>{let L0=b[Q8];if(L0?.data)g0[r0]=L0.data}),g0},[P,j,b]),k=QZ.useMemo(()=>{if(P)return E;let g0=$[$.length-1];return g0?.outputDoc?.id?_[g0.outputDoc.id]:null},[P,E,$,_]),{promptTurns:v,outputTurns:f,completedOutputTurns:h}=QZ.useMemo(()=>{if(P){let g0=D?.draftContent??D?.publishedContent??"",r0=E?.draftContent??E?.publishedContent??"",Q8=mM0(g0),L0=mM0(r0),h0=mM0(E?.publishedContent??"");return{promptTurns:Q8,outputTurns:L0,completedOutputTurns:h0}}else{let g0=$.map((L0)=>{let h0=L0.promptDoc?.id?_[L0.promptDoc.id]:null,e0=h0?.draftContent??h0?.publishedContent??"";return{turnNumber:L0.turnNumber,content:e0}}),r0=$.map((L0)=>{let h0=L0.outputDoc?.id?_[L0.outputDoc.id]:null,e0=h0?.draftContent??h0?.publishedContent??"";return{turnNumber:L0.turnNumber,content:e0}}),Q8=r0.slice(0,-1);return{promptTurns:g0,outputTurns:r0,completedOutputTurns:Q8}}},[P,D,E,$,_]),x=v.length>1||f.length>1,g=async({type:g0,id:r0,path:Q8,anchor:L0})=>{if(g0==="anchor"){X(`${K.pathname}${K.search}#${L0}`,{replace:!0});return}if(g0==="id"){let P0=r0?.charAt(1)?.toLowerCase();if(P0==="d"||P0==="t"){O0({id:r0,anchor:L0||null});return}}let h0=L0?`#${L0}`:"",e0=J?`/store/${J}`:"";if(g0==="id"){let P0=r0?.charAt(1)?.toLowerCase();if(P0==="j")X(`/project/${Z}${e0}/job/${r0}${h0}`);else if(P0==="s")X(`/project/${Z}${e0}/story/${r0}${h0}`);else if(P0==="f")try{let M8=await u5(Z,r0),w8=M8?.path||"";if(w8.startsWith("Templates/"))X(`/project/${Z}${e0}/templates?id=${r0}${h0}`);else if(w8.startsWith("Stories/")){let h8=M8?.parentId?.startsWith("As")?M8.parentId:null;if(!h8){let c8=M8?.parentId?await u5(Z,M8.parentId):null;while(c8&&!h8)if(c8.parentId?.startsWith("As"))h8=c8.parentId;else if(c8.id?.startsWith("As"))h8=c8.id;else c8=c8.parentId?await u5(Z,c8.parentId):null}if(h8)X(`/project/${Z}${e0}/story/${h8}?id=${r0}&tab=documents${h0}`);else X(`/project/${Z}${e0}/stories?id=${r0}${h0}`)}else X(`/project/${Z}${e0}/documents?id=${r0}${h0}`)}catch{X(`/project/${Z}${e0}/documents?id=${r0}${h0}`)}else X(`/project/${Z}${e0}/documents?id=${r0}${h0}`)}else if(g0==="path")X(`/project/${Z}${e0}${Q8}${h0}`)},[m,u]=QZ.useState({}),[d,p]=QZ.useState(!0),s=Math.max(v.length,f.length);QZ.useEffect(()=>{u((g0)=>{let r0={...g0};for(let Q8=0;Q8<s;Q8++)if(!(Q8 in r0))r0[Q8]={promptOpen:!0,outputOpen:!0};return r0})},[s]);let e=QZ.useRef(null);QZ.useEffect(()=>{if(!G)return;if(G!==C?.id&&G!==T?.id)return;let g0=G===C?.id,r0=G===T?.id;u(()=>{let Q8={};for(let L0=0;L0<s;L0++)Q8[L0]={promptOpen:g0,outputOpen:r0};return Q8})},[G,C?.id,T?.id,s]),QZ.useEffect(()=>{if(G&&e.current)setTimeout(()=>{e.current?.scrollIntoView({behavior:"smooth",block:"start"})},100)},[G]);let J0=`${window.location.origin}${K.pathname}`,t=C?.id?`${J0}?doc=${C.id}${U?`&from=${U}`:""}`:null,B0=T?.id?`${J0}?doc=${T.id}${U?`&from=${U}`:""}`:null,n=G===C?.id?"prompt":G===T?.id?"output":null,H0=M?.fields?.status,Q0=M?.fields?.streaming==="true";QZ.useEffect(()=>{O.current=!1},[Q]),QZ.useEffect(()=>{if(H0!=="running"||!Q0){if(q&&H0!=="running")H(!1);return}if(W(""),H(!0),B.current)return;let g0=`/api/p/${Z}/events`,r0=new EventSource(g0);return B.current=r0,r0.addEventListener("jobOutputChunk",(Q8)=>{try{let{id:L0,chunk:h0}=JSON.parse(Q8.data);if(L0===Q&&h0)W((e0)=>e0+h0)}catch{}}),r0.addEventListener("jobCompleted",(Q8)=>{try{let{id:L0}=JSON.parse(Q8.data);if(L0===Q)H(!1),r0.close(),B.current=null}catch{}}),r0.addEventListener("jobStatusChanged",(Q8)=>{try{let{id:L0,newStatus:h0}=JSON.parse(Q8.data);if(L0===Q&&h0!=="running")H(!1),r0.close(),B.current=null}catch{}}),()=>{r0.close(),B.current=null}},[Z,Q,H0,Q0]),QZ.useEffect(()=>{let g0=k;if(H0!=="running"||!Q0)return;if(O.current)return;if(g0===void 0)return;let r0=g0?.draftContent??"";if(!r0)return;W(r0),O.current=!0},[H0,Q0,k]);let U0=()=>{u((g0)=>{let r0={};for(let Q8 of Object.keys(g0))r0[Q8]={promptOpen:!1,outputOpen:!1};return r0})},Y0=()=>{u((g0)=>{let r0={};for(let Q8 of Object.keys(g0))r0[Q8]={promptOpen:!0,outputOpen:!0};return r0})},K0=async()=>{try{await navigator.clipboard.writeText(Q),a8.success("ID copied")}catch(g0){console.error("Failed to copy ID:",g0)}},F0=(g0)=>{if(!g0)return"active";if(g0.fields?.status==="running")return"active";if(g0.fields?.completedAt){let r0=new Date(g0.fields?.completedAt).getTime(),Q8=Date.now()-RP9;if(r0>Q8)return"active"}return"history"},z0=()=>{let g0=U||K.state?.fromStory||K.state?.fromTab;if(g0?.startsWith("As")){let L0=J?`/project/${Z}/store/${J}/story/${g0}?tab=jobs`:`/project/${Z}/story/${g0}?tab=jobs`;X(L0);return}let r0=wP9.includes(g0)?g0:F0(M),Q8=J?`/project/${Z}/store/${J}/jobs/${r0}`:`/project/${Z}/jobs/${r0}`;X(Q8)},[V0,O0]=QZ.useState(null),[S0,X0]=QZ.useState(!1),K8=GH8(Z,Q),C0=qH8(Z),[H8,L8]=QZ.useState(!1),[s0,E0]=QZ.useState(!1),[p0,m0]=QZ.useState({}),[b0,G8]=QZ.useState({}),{data:D0}=aY(Z,Q),j0=oY(Z),Z0=QZ.useMemo(()=>{let g0=new Set;for(let r0 of Object.keys(b0)){let Q8=p0[r0]??"",L0=b0[r0]??"";if(Array.isArray(Q8)&&Array.isArray(L0)){if(JSON.stringify(Q8)!==JSON.stringify(L0))g0.add(r0)}else if(Q8!==L0)g0.add(r0)}return g0},[p0,b0]);QZ.useEffect(()=>{if(D0)m0(D0),G8(D0)},[D0]);let T0=QZ.useCallback((g0,r0)=>{G8((Q8)=>({...Q8,[g0]:r0}))},[]),i=QZ.useCallback(async()=>{let g0=Object.entries(b0).filter(([Q8,L0])=>{if(L0===null)return!1;let h0=p0[Q8]??"";if(Array.isArray(h0)&&Array.isArray(L0))return JSON.stringify(h0)!==JSON.stringify(L0);return h0!==L0}),r0={};for(let[Q8,L0]of g0)try{if(Array.isArray(L0))await j0.mutateAsync({entityId:Q,fieldName:Q8,values:L0});else await j0.mutateAsync({entityId:Q,fieldName:Q8,value:L0});r0[Q8]=L0}catch(h0){a8.error(`Failed to save ${Q8}: ${h0.message}`)}if(Object.keys(r0).length>0)m0((Q8)=>({...Q8,...r0}));if(Object.keys(r0).length===g0.length)a8.success("Fields saved")},[b0,p0,Q,j0]),N0=QZ.useCallback(()=>{G8({...p0})},[p0]),[A0,x0]=QZ.useState(null),v0=(M?.fields?.status==="completed"||M?.fields?.status==="error"||M?.fields?.status==="stopped")&&M?.fields?.sessionId,f0=async({prompt:g0,model:r0,streaming:Q8,workingDirectory:L0,dockerImage:h0,skipPermissions:e0})=>{await K8.mutateAsync({prompt:g0,model:r0,streaming:Q8,workingDirectory:L0,dockerImage:h0,skipPermissions:e0}),X0(!1)},[n0,c0]=QZ.useState(!1),[B8,C8]=QZ.useState(""),[x8,W8]=QZ.useState(null),l0=zH8(Z),y0=()=>{C8(M.name),W8(null),c0(!0)},i0=async()=>{let g0=B8.trim();if(!g0||g0===M.name){c0(!1),W8(null);return}try{await l0.mutateAsync({id:Q,name:g0}),c0(!1),W8(null)}catch(r0){let Q8=r0?.message||"Failed to rename job";W8(Q8)}},$0=(g0)=>{if(g0.key==="Enter")g0.preventDefault(),i0();if(g0.key==="Escape")c0(!1),W8(null)},A8=(g0)=>{if(C8(g0.target.value),x8)W8(null)},o0=q&&h.length>0;if(A)return u8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:u8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground",children:[u8.jsxDEV(G7,{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(R||!M)return u8.jsxDEV("div",{className:"h-full flex items-center justify-center",children:u8.jsxDEV("div",{className:"text-center",children:[u8.jsxDEV(w7,{className:"w-8 h-8 text-destructive mx-auto mb-2"},void 0,!1,void 0,this),u8.jsxDEV("p",{className:"text-destructive font-medium",children:"Failed to load job"},void 0,!1,void 0,this),u8.jsxDEV("p",{className:"text-sm text-muted-foreground mt-1",children:R?.message||"Job not found"},void 0,!1,void 0,this),u8.jsxDEV(q8,{variant:"outline",className:"mt-4",onClick:z0,children:[u8.jsxDEV(LB,{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 u8.jsxDEV("div",{className:"h-full flex flex-col p-6 overflow-auto",children:[u8.jsxDEV("div",{className:"flex items-start gap-4 mb-6",children:[u8.jsxDEV(q8,{variant:"ghost",size:"sm",onClick:z0,children:u8.jsxDEV(LB,{className:"w-4 h-4"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV("div",{className:"flex-1",children:[u8.jsxDEV("div",{className:"flex items-center gap-3 mb-2",children:[n0?u8.jsxDEV("input",{type:"text",value:B8,onChange:A8,onBlur:i0,onKeyDown:$0,autoFocus:!0,className:"text-xl font-semibold px-2 py-1 border border-input rounded bg-background"},void 0,!1,void 0,this):u8.jsxDEV(u8.Fragment,{children:[u8.jsxDEV("h1",{className:"text-xl font-semibold",children:M.name},void 0,!1,void 0,this),u8.jsxDEV(y9,{content:"Rename job",children:u8.jsxDEV(q8,{variant:"ghost",size:"sm",onClick:y0,children:u8.jsxDEV(Q5,{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),u8.jsxDEV(MP9,{status:M.fields?.status},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x8&&u8.jsxDEV("div",{className:"mb-3 p-3 border border-destructive rounded-md bg-destructive/10 flex items-center gap-2 text-destructive",children:[u8.jsxDEV(w7,{className:"w-4 h-4"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"text-sm",children:x8},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u8.jsxDEV("div",{className:"flex flex-wrap items-center gap-4 text-sm text-muted-foreground",children:[u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Agent:"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"capitalize",children:M.fields?.agent},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.model&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Model:"},void 0,!1,void 0,this),M.fields?.model]},void 0,!0,void 0,this),u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Started:"},void 0,!1,void 0,this),JB8(M.fields?.startedAt)]},void 0,!0,void 0,this),M.fields?.completedAt&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Completed:"},void 0,!1,void 0,this),JB8(M.fields?.completedAt)]},void 0,!0,void 0,this),M.fields?.tokensUsed&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Tokens:"},void 0,!1,void 0,this),LP9(M.fields?.tokensUsed)]},void 0,!0,void 0,this),Me(M.fields?.workingDirectory,Y?.path)&&u8.jsxDEV(y9,{content:M.fields?.workingDirectory,children:u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Location:"},void 0,!1,void 0,this),Me(M.fields?.workingDirectory,Y?.path)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.fields?.status==="completed"&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"Session:"},void 0,!1,void 0,this),u8.jsxDEV("span",{children:M.fields?.sessionId||"-"},void 0,!1,void 0,this),u8.jsxDEV(ux,{value:M.fields?.sessionId||"",disabled:!M.fields?.sessionId},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.fields?.pid&&u8.jsxDEV("span",{className:"flex items-center gap-1",children:[u8.jsxDEV("span",{className:"font-medium",children:"PID:"},void 0,!1,void 0,this),u8.jsxDEV("span",{className:"font-mono",children:M.fields.pid},void 0,!1,void 0,this),u8.jsxDEV(ux,{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&&(M.fields?.status==="stopped"?u8.jsxDEV("div",{className:"mt-3 p-3 bg-orange-50 border border-orange-200 rounded-md",children:[u8.jsxDEV("p",{className:"text-sm text-orange-700 font-medium",children:"Stopped"},void 0,!1,void 0,this),u8.jsxDEV("p",{className:"text-sm text-orange-600 mt-1",children:M.fields?.errorMessage},void 0,!1,void 0,this)]},void 0,!0,void 0,this):u8.jsxDEV("div",{className:"mt-3 p-3 bg-destructive/10 border border-destructive/30 rounded-md",children:[u8.jsxDEV("p",{className:"text-sm text-destructive font-medium",children:"Error"},void 0,!1,void 0,this),u8.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),u8.jsxDEV("div",{className:"flex items-center gap-2",children:[u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>E0(!0),children:[u8.jsxDEV(WT,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Fields"]},void 0,!0,void 0,this),v0&&u8.jsxDEV(q8,{variant:"default",size:"sm",onClick:()=>X0(!0),children:[u8.jsxDEV(Xj,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Continue Conversation"]},void 0,!0,void 0,this),M.fields?.status==="running"&&u8.jsxDEV(q8,{variant:"destructive",size:"sm",onClick:()=>C0.mutate({id:Q}),disabled:C0.isPending,children:[C0.isPending?u8.jsxDEV(G7,{className:"w-4 h-4 mr-2 animate-spin"},void 0,!1,void 0,this):u8.jsxDEV(zj,{className:"w-4 h-4 mr-2"},void 0,!1,void 0,this),"Stop Job"]},void 0,!0,void 0,this),u8.jsxDEV(y9,{content:"Copy job ID",children:u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:K0,children:[u8.jsxDEV(uZ,{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&&u8.jsxDEV(y9,{content:"Check process status",children:u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:()=>L8(!0),children:u8.jsxDEV(Wj,{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),v.length>=3&&u8.jsxDEV("div",{className:"flex gap-2 mb-4",children:[u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:U0,children:"Collapse All"},void 0,!1,void 0,this),u8.jsxDEV(q8,{variant:"outline",size:"sm",onClick:Y0,children:"Expand All"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u8.jsxDEV("div",{className:"flex-1 space-y-6",children:q?o0?u8.jsxDEV(u8.Fragment,{children:[u8.jsxDEV(QB8,{content:z,isOpen:d,onToggle:p,onInternalLinkClick:g},void 0,!1,void 0,this),u8.jsxDEV(Re,{title:`Prompt (Turn ${h.length+1})`,docId:C?.id,docName:C?.name,docContent:v[v.length-1]?.content,isOpen:m[v.length-1]?.promptOpen??!0,onToggle:(g0)=>u((r0)=>({...r0,[v.length-1]:{...r0[v.length-1],promptOpen:g0}})),deepLinkUrl:t,onFieldsClick:C?.id?()=>x0(C.id):void 0,children:u8.jsxDEV(MK,{markdown:v[v.length-1]?.content||"",onInternalLinkClick:g},void 0,!1,void 0,this)},void 0,!1,void 0,this),[...h].reverse().map((g0,r0)=>{let Q8=h.length-1-r0,L0=P?C?.id:$[Q8]?.promptDoc?.id,h0=P?T?.id:$[Q8]?.outputDoc?.id,e0=P?C?.name:$[Q8]?.promptDoc?.name,P0=P?T?.name:$[Q8]?.outputDoc?.name,M8=L0?`${J0}?doc=${L0}${U?`&from=${U}`:""}`:null,w8=h0?`${J0}?doc=${h0}${U?`&from=${U}`:""}`:null;return u8.jsxDEV(uM0,{turnNumber:Q8+1,promptContent:v[Q8]?.content,outputContent:g0.content,showHeading:!0,promptDocId:L0,outputDocId:h0,promptDocName:e0,outputDocName:P0,isPromptOpen:m[Q8]?.promptOpen??!0,setIsPromptOpen:(h8)=>u((c8)=>({...c8,[Q8]:{...c8[Q8],promptOpen:h8}})),isOutputOpen:m[Q8]?.outputOpen??!0,setIsOutputOpen:(h8)=>u((c8)=>({...c8,[Q8]:{...c8[Q8],outputOpen:h8}})),onInternalLinkClick:g,promptDeepLinkUrl:M8,outputDeepLinkUrl:w8,onPromptFieldsClick:L0?()=>x0(L0):void 0,onOutputFieldsClick:h0?()=>x0(h0):void 0},Q8,!1,void 0,this)})]},void 0,!0,void 0,this):u8.jsxDEV(u8.Fragment,{children:[u8.jsxDEV(QB8,{content:z,isOpen:d,onToggle:p,onInternalLinkClick:g},void 0,!1,void 0,this),u8.jsxDEV(Re,{title:"Prompt",docId:C?.id,docName:C?.name,docContent:v[0]?.content,isOpen:m[0]?.promptOpen??!0,onToggle:(g0)=>u((r0)=>({...r0,[0]:{...r0[0],promptOpen:g0}})),deepLinkUrl:t,onFieldsClick:C?.id?()=>x0(C.id):void 0,children:u8.jsxDEV(MK,{markdown:v[0]?.content||"",onInternalLinkClick:g},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):w?u8.jsxDEV("div",{className:"flex items-center gap-2 text-muted-foreground py-8",children:[u8.jsxDEV(G7,{className:"w-4 h-4 animate-spin"},void 0,!1,void 0,this),"Loading documents..."]},void 0,!0,void 0,this):x?[...Array(Math.max(v.length,f.length))].map((g0,r0,Q8)=>{let L0=Q8.length-1-r0,h0=v[L0],e0=f[L0],P0=h0?.turnNumber??e0?.turnNumber??L0+1,M8=r0===0,w8=P?C?.id:$[L0]?.promptDoc?.id,h8=P?T?.id:$[L0]?.outputDoc?.id,c8=P?C?.name:$[L0]?.promptDoc?.name,t8=P?T?.name:$[L0]?.outputDoc?.name,e8=w8?`${J0}?doc=${w8}${U?`&from=${U}`:""}`:null,Y9=h8?`${J0}?doc=${h8}${U?`&from=${U}`:""}`:null;return u8.jsxDEV(uM0,{turnNumber:P0,promptContent:h0?.content,outputContent:e0?.content,showHeading:!0,promptDocId:w8,outputDocId:h8,promptDocName:c8,outputDocName:t8,isPromptOpen:m[L0]?.promptOpen??!0,setIsPromptOpen:(d9)=>u((l8)=>({...l8,[L0]:{...l8[L0],promptOpen:d9}})),isOutputOpen:m[L0]?.outputOpen??!0,setIsOutputOpen:(d9)=>u((l8)=>({...l8,[L0]:{...l8[L0],outputOpen:d9}})),onInternalLinkClick:g,promptDeepLinkUrl:e8,outputDeepLinkUrl:Y9,sectionRef:M8?e:null,highlightedSection:M8?n:null,onPromptFieldsClick:w8?()=>x0(w8):void 0,onOutputFieldsClick:h8?()=>x0(h8):void 0},L0,!1,void 0,this)}):u8.jsxDEV(uM0,{turnNumber:1,promptContent:v[0]?.content,outputContent:f[0]?.content,showHeading:!1,promptDocId:C?.id,outputDocId:T?.id,promptDocName:C?.name,outputDocName:T?.name,isPromptOpen:m[0]?.promptOpen??!0,setIsPromptOpen:(g0)=>u((r0)=>({...r0,[0]:{...r0[0],promptOpen:g0}})),isOutputOpen:m[0]?.outputOpen??!0,setIsOutputOpen:(g0)=>u((r0)=>({...r0,[0]:{...r0[0],outputOpen:g0}})),onInternalLinkClick:g,promptDeepLinkUrl:t,outputDeepLinkUrl:B0,sectionRef:e,highlightedSection:n,onPromptFieldsClick:C?.id?()=>x0(C.id):void 0,onOutputFieldsClick:T?.id?()=>x0(T.id):void 0},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(eH8,{open:S0,onOpenChange:X0,jobName:M.name,sessionId:M.fields?.sessionId,agent:M.fields?.agent,currentModel:M.fields?.model,streaming:M.fields?.streaming==="true",workingDirectory:M.fields?.workingDirectory,dockerImage:M.fields?.dockerImage,skipPermissions:M.fields?.skipPermissions!=="false",projectId:Z,onContinue:f0,isLoading:K8.isPending},void 0,!1,void 0,this),u8.jsxDEV(ZB8,{open:H8,onOpenChange:L8,projectId:Z,jobId:Q,pid:M.fields?.pid},void 0,!1,void 0,this),u8.jsxDEV(mH,{open:!!V0,onOpenChange:(g0)=>!g0&&O0(null),projectId:Z,documentId:V0?.id,anchor:V0?.anchor,onNavigate:X},void 0,!1,void 0,this),u8.jsxDEV(D6,{open:s0,onOpenChange:E0,children:u8.jsxDEV(O6,{className:"max-w-7xl",children:[u8.jsxDEV(M6,{children:u8.jsxDEV(L6,{children:"Job Fields"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(n2,{projectId:Z,entityId:Q,entityType:"j",entitySubtype:null,entityPath:M?.path,onFieldChange:T0,fieldValues:b0,dirtyFieldNames:Z0,originalFieldValues:p0,storeCode:J},void 0,!1,void 0,this),Z0.size>0&&u8.jsxDEV("div",{className:"flex justify-end gap-2 pt-4",children:[u8.jsxDEV(q8,{onClick:N0,variant:"outline",size:"sm",children:[u8.jsxDEV(fJ,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),"Discard"]},void 0,!0,void 0,this),u8.jsxDEV(q8,{onClick:i,disabled:j0.isPending,variant:"default",size:"sm",children:[u8.jsxDEV(j4,{className:"w-4 h-4 mr-1"},void 0,!1,void 0,this),j0.isPending?"Saving...":"Save Fields"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(D6,{open:!!A0,onOpenChange:(g0)=>!g0&&x0(null),children:u8.jsxDEV(O6,{className:"max-w-7xl",children:[u8.jsxDEV(M6,{children:u8.jsxDEV(L6,{children:"Document Fields"},void 0,!1,void 0,this)},void 0,!1,void 0,this),u8.jsxDEV(n2,{projectId:Z,entityId:A0,entityType:"d",entitySubtype:null,storeCode:J},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 p1=W0(t0(),1);var F3=W0(t0(),1);var r8=W0(t0(),1),cw=W0(sW(),1);var T5=W0(t0(),1);var px=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function gw(Z){let J=Object.prototype.toString.call(Z);return J==="[object Window]"||J==="[object global]"}function we(Z){return"nodeType"in Z}function wK(Z){var J,Q;if(!Z)return window;if(gw(Z))return Z;if(!we(Z))return window;return(J=(Q=Z.ownerDocument)==null?void 0:Q.defaultView)!=null?J:window}function Pe(Z){let{Document:J}=wK(Z);return Z instanceof J}function nD(Z){if(gw(Z))return!1;return Z instanceof wK(Z).HTMLElement}function lM0(Z){return Z instanceof wK(Z).SVGElement}function mw(Z){if(!Z)return document;if(gw(Z))return Z.document;if(!we(Z))return document;if(Pe(Z))return Z;if(nD(Z)||lM0(Z))return Z.ownerDocument;return document}var uH=px?T5.useLayoutEffect:T5.useEffect;function cx(Z){let J=T5.useRef(Z);return uH(()=>{J.current=Z}),T5.useCallback(function(){for(var Q=arguments.length,X=Array(Q),K=0;K<Q;K++)X[K]=arguments[K];return J.current==null?void 0:J.current(...X)},[])}function KB8(){let Z=T5.useRef(null),J=T5.useCallback((X,K)=>{Z.current=setInterval(X,K)},[]),Q=T5.useCallback(()=>{if(Z.current!==null)clearInterval(Z.current),Z.current=null},[]);return[J,Q]}function rD(Z,J){if(J===void 0)J=[Z];let Q=T5.useRef(Z);return uH(()=>{if(Q.current!==Z)Q.current=Z},J),Q}function aD(Z,J){let Q=T5.useRef();return T5.useMemo(()=>{let X=Z(Q.current);return Q.current=X,X},[...J])}function lx(Z){let J=cx(Z),Q=T5.useRef(null),X=T5.useCallback((K)=>{if(K!==Q.current)J==null||J(K,Q.current);Q.current=K},[]);return[Q,X]}function dx(Z){let J=T5.useRef();return T5.useEffect(()=>{J.current=Z},[Z]),J.current}var cM0={};function ix(Z,J){return T5.useMemo(()=>{if(J)return J;let Q=cM0[Z]==null?0:cM0[Z]+1;return cM0[Z]=Q,Z+"-"+Q},[Z,J])}function YB8(Z){return function(J){for(var Q=arguments.length,X=Array(Q>1?Q-1:0),K=1;K<Q;K++)X[K-1]=arguments[K];return X.reduce((Y,U)=>{let G=Object.entries(U);for(let[z,W]of G){let q=Y[z];if(q!=null)Y[z]=q+Z*W}return Y},{...J})}}var uw=YB8(1),sx=YB8(-1);function PP9(Z){return"clientX"in Z&&"clientY"in Z}function Te(Z){if(!Z)return!1;let{KeyboardEvent:J}=wK(Z.target);return J&&Z instanceof J}function TP9(Z){if(!Z)return!1;let{TouchEvent:J}=wK(Z.target);return J&&Z instanceof J}function nx(Z){if(TP9(Z)){if(Z.touches&&Z.touches.length){let{clientX:J,clientY:Q}=Z.touches[0];return{x:J,y:Q}}else if(Z.changedTouches&&Z.changedTouches.length){let{clientX:J,clientY:Q}=Z.changedTouches[0];return{x:J,y:Q}}}if(PP9(Z))return{x:Z.clientX,y:Z.clientY};return null}var sD=Object.freeze({Translate:{toString(Z){if(!Z)return;let{x:J,y:Q}=Z;return"translate3d("+(J?Math.round(J):0)+"px, "+(Q?Math.round(Q):0)+"px, 0)"}},Scale:{toString(Z){if(!Z)return;let{scaleX:J,scaleY:Q}=Z;return"scaleX("+J+") scaleY("+Q+")"}},Transform:{toString(Z){if(!Z)return;return[sD.Translate.toString(Z),sD.Scale.toString(Z)].join(" ")}},Transition:{toString(Z){let{property:J,duration:Q,easing:X}=Z;return J+" "+Q+"ms "+X}}}),XB8="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function UB8(Z){if(Z.matches(XB8))return Z;return Z.querySelector(XB8)}var pw=W0(t0(),1),IP9={display:"none"};function GB8(Z){let{id:J,value:Q}=Z;return pw.default.createElement("div",{id:J,style:IP9},Q)}function zB8(Z){let{id:J,announcement:Q,ariaLiveType:X="assertive"}=Z,K={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return pw.default.createElement("div",{id:J,style:K,role:"status","aria-live":X,"aria-atomic":!0},Q)}function WB8(){let[Z,J]=pw.useState("");return{announce:pw.useCallback((X)=>{if(X!=null)J(X)},[]),announcement:Z}}var PB8=r8.createContext(null);function VP9(Z){let J=r8.useContext(PB8);r8.useEffect(()=>{if(!J)throw Error("useDndMonitor must be used within a children of <DndContext>");return J(Z)},[Z,J])}function CP9(){let[Z]=r8.useState(()=>new Set),J=r8.useCallback((X)=>{return Z.add(X),()=>Z.delete(X)},[Z]);return[r8.useCallback((X)=>{let{type:K,event:Y}=X;Z.forEach((U)=>{var G;return(G=U[K])==null?void 0:G.call(U,Y)})},[Z]),J]}var $P9={draggable:`
|
|
3091
3091
|
To pick up a draggable item, press the space bar.
|
|
3092
3092
|
While dragging, use the arrow keys to move the item.
|
|
3093
3093
|
Press space again to drop the item in its new position, or press escape to cancel.
|