@taskforcehq/taskforce 0.3.306 → 0.3.308

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.
Files changed (232) hide show
  1. package/README.md +0 -2
  2. package/dist/Taskforce.module.css +317 -27
  3. package/dist/TaskforceCore.js +1 -0
  4. package/dist/TaskforceCore.test.js +178 -0
  5. package/dist/components/activity/EntityActivityTimeline.d.ts +34 -0
  6. package/dist/components/activity/EntityActivityTimeline.js +81 -0
  7. package/dist/components/context/ContextAttachmentManager.js +15 -3
  8. package/dist/components/features/AgentsModule.d.ts +5 -1
  9. package/dist/components/features/AgentsModule.js +142 -39
  10. package/dist/components/features/AgentsModule.test.js +260 -11
  11. package/dist/components/features/AnnotatedAttachmentWorkspace.d.ts +3 -1
  12. package/dist/components/features/AnnotatedAttachmentWorkspace.js +118 -4
  13. package/dist/components/features/AnnotatedAttachmentWorkspace.test.js +52 -0
  14. package/dist/components/features/DocumentIndex.d.ts +2 -2
  15. package/dist/components/features/DocumentIndex.js +3 -4
  16. package/dist/components/features/DocumentViewer.d.ts +3 -1
  17. package/dist/components/features/DocumentViewer.js +6 -5
  18. package/dist/components/features/DocumentWorkspace.d.ts +10 -2
  19. package/dist/components/features/DocumentWorkspace.js +15 -4
  20. package/dist/components/features/DocumentWorkspace.test.js +20 -3
  21. package/dist/components/features/TaskSettings.d.ts +2 -0
  22. package/dist/components/features/TaskSettings.js +83 -78
  23. package/dist/components/features/TaskSettings.test.js +171 -82
  24. package/dist/components/task/TaskActionHeader.js +11 -5
  25. package/dist/components/task/TaskActionHeader.test.js +10 -0
  26. package/dist/components/task/TaskCard.js +6 -2
  27. package/dist/components/task/TaskContextUpload.test.js +3 -3
  28. package/dist/components/task/TaskForm.js +14 -64
  29. package/dist/components/task/TaskKanban.js +0 -8
  30. package/dist/components/task/TaskList.js +5 -1
  31. package/dist/components/task/TaskList.test.js +4 -0
  32. package/dist/components/ui/HierarchyActionBadge.d.ts +10 -0
  33. package/dist/components/ui/HierarchyActionBadge.js +5 -0
  34. package/dist/components/views/AppShellHeader.d.ts +3 -1
  35. package/dist/components/views/AppShellHeader.js +27 -11
  36. package/dist/components/views/AppShellHeader.test.js +18 -1
  37. package/dist/components/views/PlanComparisonPage.d.ts +20 -15
  38. package/dist/components/views/PlanComparisonPage.js +221 -82
  39. package/dist/components/views/PlanComparisonPage.test.js +268 -14
  40. package/dist/components/views/PlansPage.js +16 -10
  41. package/dist/components/views/PlansPage.test.js +4 -2
  42. package/dist/components/views/StandaloneLayout.js +256 -69
  43. package/dist/components/views/WidgetView.js +10 -8
  44. package/dist/components/views/panels/PlanningDrawer.d.ts +19 -6
  45. package/dist/components/views/panels/PlanningDrawer.js +259 -51
  46. package/dist/components/views/panels/PlanningDrawer.test.js +392 -4
  47. package/dist/config/envSchema.js +1 -0
  48. package/dist/core/AiProfileService.d.ts +7 -0
  49. package/dist/core/AiProfileService.js +460 -35
  50. package/dist/core/AiProfiles.test.js +648 -2
  51. package/dist/core/AttachmentLinkService.d.ts +3 -0
  52. package/dist/core/AttachmentLinkService.js +58 -13
  53. package/dist/core/GlobalSettingsService.js +30 -0
  54. package/dist/core/GlobalSettingsService.test.d.ts +1 -0
  55. package/dist/core/GlobalSettingsService.test.js +45 -0
  56. package/dist/core/McpTokenService.d.ts +12 -0
  57. package/dist/core/McpTokenService.js +44 -1
  58. package/dist/core/PlanEntitlementService.d.ts +20 -0
  59. package/dist/core/PlanEntitlementService.js +215 -19
  60. package/dist/core/PlanFeatureCatalog.test.js +55 -0
  61. package/dist/core/PlanningEntities.test.js +366 -4
  62. package/dist/core/TaskActivityService.d.ts +28 -1
  63. package/dist/core/TaskActivityService.js +227 -46
  64. package/dist/core/TaskActivitySync.test.d.ts +1 -0
  65. package/dist/core/TaskActivitySync.test.js +90 -0
  66. package/dist/core/TaskAuditTimeline.test.js +96 -0
  67. package/dist/core/Taskforce.d.ts +204 -26
  68. package/dist/core/Taskforce.ids.test.js +58 -0
  69. package/dist/core/Taskforce.js +781 -71
  70. package/dist/core/Taskforce.mcpAuth.test.js +109 -0
  71. package/dist/core/types.d.ts +10 -0
  72. package/dist/hooks/auth/useTaskforceAuthBootstrap.js +2 -1
  73. package/dist/hooks/bootstrapTimeouts.d.ts +4 -0
  74. package/dist/hooks/bootstrapTimeouts.js +8 -0
  75. package/dist/hooks/bootstrapTimeouts.test.d.ts +1 -0
  76. package/dist/hooks/bootstrapTimeouts.test.js +12 -0
  77. package/dist/hooks/sync/orchestratorShared.d.ts +3 -3
  78. package/dist/hooks/sync/orchestratorShared.js +61 -1
  79. package/dist/hooks/sync/recovery.js +8 -0
  80. package/dist/hooks/sync/recovery.test.js +5 -5
  81. package/dist/hooks/sync/transfers.d.ts +2 -1
  82. package/dist/hooks/sync/transfers.js +36 -9
  83. package/dist/hooks/sync/transfers.test.js +534 -2
  84. package/dist/hooks/useFilterSort.js +13 -13
  85. package/dist/hooks/useFilterSort.test.js +87 -1
  86. package/dist/hooks/useSyncOrchestrator.js +50 -5
  87. package/dist/hooks/useTaskforce.d.ts +85 -50
  88. package/dist/hooks/useTaskforce.js +44 -14
  89. package/dist/hooks/useTaskforce.runtime-routing.test.js +94 -0
  90. package/dist/hooks/useTaskforce.sync-behavior.test.js +99 -0
  91. package/dist/hooks/useWorkspaceSyncController.js +7 -1
  92. package/dist/hooks/useWorkspaceSyncController.test.js +48 -0
  93. package/dist/hooks/workspace/useTaskforceWorkspaceBootstrap.js +14 -7
  94. package/dist/mcp/canonicalAssetHelpers.d.ts +16 -4
  95. package/dist/mcp/canonicalAssetHelpers.js +18 -10
  96. package/dist/mcp/canonicalAssetHelpers.test.d.ts +1 -0
  97. package/dist/mcp/canonicalAssetHelpers.test.js +67 -0
  98. package/dist/mcp/clientIntegrations.d.ts +1 -0
  99. package/dist/mcp/clientIntegrations.js +25 -0
  100. package/dist/mcp/clientIntegrations.test.js +14 -3
  101. package/dist/mcp/clientProfileDefaults.js +3 -3
  102. package/dist/mcp/collaborationRegistrar.js +7 -7
  103. package/dist/mcp/documentAssetRegistrar.js +113 -7
  104. package/dist/mcp/runtime.d.ts +1 -0
  105. package/dist/mcp/runtime.js +969 -122
  106. package/dist/mcp/runtime.test.js +1083 -11
  107. package/dist/mcp/taskAttachmentTypes.d.ts +1 -1
  108. package/dist/mcp/taskPlanningRegistrar.js +48 -0
  109. package/dist/mcp/toolRegistry.d.ts +56 -0
  110. package/dist/mcp/toolRegistry.js +8 -0
  111. package/dist/mcp/toolRegistry.test.js +4 -0
  112. package/dist/migrations/taskSchemaMigrations.js +58 -15
  113. package/dist/server/aiProfileAvatarAssets.d.ts +49 -0
  114. package/dist/server/aiProfileAvatarAssets.js +319 -0
  115. package/dist/server/aiProfileAvatarAssets.test.d.ts +1 -0
  116. package/dist/server/aiProfileAvatarAssets.test.js +213 -0
  117. package/dist/server/annotatedAttachmentsRoutes.test.js +66 -7
  118. package/dist/server/index.js +4 -0
  119. package/dist/server/index.test.js +6 -1
  120. package/dist/server/routes/admin.js +328 -9
  121. package/dist/server/routes/annotatedAttachments.js +51 -0
  122. package/dist/server/routes/auth.d.ts +11 -0
  123. package/dist/server/routes/auth.js +189 -27
  124. package/dist/server/routes/authSupport.d.ts +5 -0
  125. package/dist/server/routes/authSupport.js +13 -1
  126. package/dist/server/routes/billing.d.ts +1 -0
  127. package/dist/server/routes/billing.js +116 -63
  128. package/dist/server/routes/billing.test.js +162 -11
  129. package/dist/server/routes/documents.js +10 -0
  130. package/dist/server/routes/shared.js +0 -10
  131. package/dist/server/routes/sync.integration.test.js +221 -0
  132. package/dist/server/routes/sync.js +13 -3
  133. package/dist/server/routes/syncSnapshotRoutes.js +2 -0
  134. package/dist/server/routes/tasks.js +12 -9
  135. package/dist/server/routes.js +87 -8
  136. package/dist/server/routes.test.js +972 -23
  137. package/dist/shared/aiProfileSurfaceType.d.ts +1 -1
  138. package/dist/shared/aiProfileSurfaceType.js +10 -8
  139. package/dist/storage/objectStorage.d.ts +1 -0
  140. package/dist/storage/objectStorage.js +2 -1
  141. package/dist/storage/objectStorageClient.d.ts +1 -0
  142. package/dist/storage/objectStorageClient.js +41 -8
  143. package/dist/storage/objectStorageClient.test.js +26 -1
  144. package/dist/storage/objectStorageConfig.js +3 -1
  145. package/dist/storage/objectStorageConfig.test.js +13 -1
  146. package/dist/sync/collaborationSyncPayload.js +2 -0
  147. package/dist/sync/collaborationSyncPayload.test.js +1 -0
  148. package/dist/sync/collaborationSyncState.d.ts +3 -3
  149. package/dist/sync/collaborationSyncState.js +19 -12
  150. package/dist/sync/contentSyncPayload.d.ts +5 -1
  151. package/dist/sync/contentSyncPayload.js +9 -0
  152. package/dist/sync/contentSyncPayload.test.js +39 -0
  153. package/dist/sync/contentSyncState.d.ts +5 -1
  154. package/dist/sync/contentSyncState.js +231 -37
  155. package/dist/sync/planningSyncPayload.js +5 -0
  156. package/dist/sync/planningSyncPayload.test.js +24 -0
  157. package/dist/sync/syncApplyHandlers.d.ts +4 -4
  158. package/dist/sync/syncApplyHandlers.js +89 -31
  159. package/dist/sync/syncApplyHandlers.test.js +184 -4
  160. package/dist/sync/syncResourceAdapters.d.ts +2 -0
  161. package/dist/sync/syncResourceAdapters.js +2 -0
  162. package/dist/sync/syncService.d.ts +1 -0
  163. package/dist/sync/syncService.js +13 -1
  164. package/dist/sync/syncService.test.js +39 -0
  165. package/dist/sync/workspacePullFeed.d.ts +4 -0
  166. package/dist/sync/workspacePullFeed.js +129 -70
  167. package/dist/sync/workspacePullFeed.test.js +49 -0
  168. package/dist/sync/workspaceSyncModel.d.ts +28 -6
  169. package/dist/sync/workspaceSyncModel.js +159 -45
  170. package/dist/sync/workspaceSyncModel.test.js +269 -3
  171. package/dist/types.d.ts +33 -2
  172. package/dist/ui/agent-logos/ChatGPT.png +0 -0
  173. package/dist/ui/agent-logos/Gemini CLI.jpeg +0 -0
  174. package/dist/ui/agent-logos/antigravity.jpeg +0 -0
  175. package/dist/ui/agent-logos/claude-code.jpeg +0 -0
  176. package/dist/ui/agent-logos/codex.jpeg +0 -0
  177. package/dist/ui/agent-logos/cursor.png +0 -0
  178. package/dist/ui/agent-logos/openclaw.jpeg +0 -0
  179. package/dist/ui/agent-logos/windsurf.png +0 -0
  180. package/dist/ui/assets/AgentsModule-BS4Pi_nC.js +1 -0
  181. package/dist/ui/assets/AnnotatedAttachmentWorkspace-BVKew-mH.css +1 -0
  182. package/dist/ui/assets/AnnotatedAttachmentWorkspace-CCckzWYZ.js +3 -0
  183. package/dist/ui/assets/ContextAttachmentManager-CfG_ER7C.js +3 -0
  184. package/dist/ui/assets/DocumentWorkspace-BVaWPA25.js +252 -0
  185. package/dist/ui/assets/DocumentWorkspace-D4rJKXzd.css +1 -0
  186. package/dist/ui/assets/EntityActivityTimeline-DSj0ThaK.js +1 -0
  187. package/dist/ui/assets/EntityActivityTimeline-DyqvvhuF.css +1 -0
  188. package/dist/ui/assets/{InitiativesModule-9E6ParrY.js → InitiativesModule-AxMkWtxH.js} +1 -1
  189. package/dist/ui/assets/PlansPage-B_z-D6Nh.css +1 -0
  190. package/dist/ui/assets/PlansPage-Ndt7mYfo.js +1 -0
  191. package/dist/ui/assets/TaskContextUpload-Dw4rTF4i.js +1 -0
  192. package/dist/ui/assets/TaskSettings-f2ga42_V.js +9 -0
  193. package/dist/ui/assets/{WorkflowsModule-BA7jcEpH.js → WorkflowsModule-E4UL3mov.js} +4 -4
  194. package/dist/ui/assets/documentReferences-BOUcJm6-.js +1 -0
  195. package/dist/ui/assets/index-BvAbqx5Q.css +1 -0
  196. package/dist/ui/assets/index-MAHKvFqp.js +4 -0
  197. package/dist/ui/assets/{vendor-icons-DuEd_65c.js → vendor-icons-B32hGuF2.js} +1 -1
  198. package/dist/ui/index.html +3 -3
  199. package/dist/ui/og-image.png +0 -0
  200. package/dist/ui/product/agent manager.png +0 -0
  201. package/dist/ui/product/agent_manager_02.png +0 -0
  202. package/dist/utils/aiProfileEvents.d.ts +7 -0
  203. package/dist/utils/aiProfileEvents.js +6 -0
  204. package/dist/utils/assignees.d.ts +6 -0
  205. package/dist/utils/assignees.js +8 -1
  206. package/dist/utils/assignees.test.d.ts +1 -0
  207. package/dist/utils/assignees.test.js +25 -0
  208. package/dist/utils/avatarDisplay.d.ts +1 -0
  209. package/dist/utils/avatarDisplay.js +15 -0
  210. package/dist/utils/contextFiles.d.ts +3 -1
  211. package/dist/utils/contextFiles.js +2 -1
  212. package/dist/utils/taskActivity.d.ts +7 -1
  213. package/dist/utils/taskActivity.js +63 -1
  214. package/dist/utils/taskActivity.test.js +23 -1
  215. package/dist/utils/taskSearch.d.ts +22 -0
  216. package/dist/utils/taskSearch.js +87 -0
  217. package/dist/utils/taskSearch.test.d.ts +1 -0
  218. package/dist/utils/taskSearch.test.js +69 -0
  219. package/dist/utils/taskUtils.js +10 -3
  220. package/dist/utils/taskUtils.test.d.ts +1 -0
  221. package/dist/utils/taskUtils.test.js +19 -0
  222. package/package.json +1 -1
  223. package/dist/ui/assets/AgentsModule-DrLawwNl.js +0 -1
  224. package/dist/ui/assets/AnnotatedAttachmentWorkspace-BaS2VwIr.css +0 -1
  225. package/dist/ui/assets/AnnotatedAttachmentWorkspace-Z9_whf7F.js +0 -3
  226. package/dist/ui/assets/DocumentWorkspace-B03MaSkw.js +0 -252
  227. package/dist/ui/assets/DocumentWorkspace-Dhdso07p.css +0 -1
  228. package/dist/ui/assets/PlansPage-CvfnMiWq.css +0 -1
  229. package/dist/ui/assets/PlansPage-DRXscYxH.js +0 -1
  230. package/dist/ui/assets/TaskSettings-DZX4jk7e.js +0 -9
  231. package/dist/ui/assets/index-9eT8e0Lu.css +0 -1
  232. package/dist/ui/assets/index-C6k75jr8.js +0 -6
@@ -0,0 +1,3 @@
1
+ import{j as t,r as s,R as ta}from"./vendor-react-CKJs5o3c.js";import{R as An,f as ge,e as $t,g as Mn,t as Da,M as aa}from"./index-MAHKvFqp.js";import{a4 as za,w as En,v as Ln,p as Fn,P as Hn,c as na,T as Ua,r as On,h as Ga,ak as Dn,R as zn,al as Un,am as Gn,an as Yn,ao as oa,C as ia,ap as Wn,aq as Ja,ar as Za,as as Qa,at as en,g as Kn,f as Xn,b as la}from"./vendor-icons-B32hGuF2.js";import"./vendor-markdown-BUxTU7dS.js";import"./vendor-dnd-DRzYolkg.js";import"./vendor-router-BbWMxlnO.js";function Vn({copied:r,disabled:l=!1,label:f,onClick:p,title:b="Copy image reference",ariaLabel:x,className:L=""}){return t.jsx(An,{copied:r,disabled:l,label:"",onClick:p,title:b,ariaLabel:x,className:L,children:f})}const qn="_shell_17mlo_1",Jn="_shellWithImageTray_17mlo_18",Zn="_shellImageTrayOpen_17mlo_22",Qn="_imageTrayPanel_17mlo_26",es="_imageTrayPanelOpen_17mlo_50",ts="_imageTrayHeader_17mlo_58",as="_imageTrayTitle_17mlo_73",ns="_imageTraySearch_17mlo_85",ss="_imageTraySearchIcon_17mlo_91",rs="_imageTraySearchInput_17mlo_100",os="_imageTrayList_17mlo_117",is="_imageTrayState_17mlo_129",ls="_imageTrayStateError_17mlo_130",cs="_imageTrayItem_17mlo_142",ds="_imageTrayItemActive_17mlo_164",us="_imageTrayThumb_17mlo_174",ms="_imageTrayItemBody_17mlo_191",fs="_imageTrayItemTitle_17mlo_199",hs="_imageTrayItemTask_17mlo_200",ps="_imageTrayItemMetaDetails_17mlo_201",gs="_imageTrayItemMeta_17mlo_201",ys="_imageTrayItemReference_17mlo_239",bs="_panel_17mlo_246",xs="_sessionPanel_17mlo_252",vs="_detailPanel_17mlo_253",_s="_sessionContextBar_17mlo_259",Is="_sessionContextLeft_17mlo_270",ks="_sessionContextRight_17mlo_271",ws="_sessionContextLabel_17mlo_286",Ss="_sessionContextSpacer_17mlo_292",Ns="_canvasPanel_17mlo_297",Cs="_canvasWorkspace_17mlo_304",js="_canvasMain_17mlo_311",Ts="_panelHeader_17mlo_318",$s="_panelHeaderText_17mlo_327",Rs="_panelTitle_17mlo_331",Ps="_canvasHeading_17mlo_335",Bs="_sessionActions_17mlo_339",As="_sessionList_17mlo_347",Ms="_annotationList_17mlo_348",Es="_markerHelpModalBody_17mlo_363",Ls="_openImageModalBody_17mlo_369",Fs="_openImageField_17mlo_375",Hs="_openImageActions_17mlo_379",Os="_markerHelpItem_17mlo_385",Ds="_markerHelpHeader_17mlo_393",zs="_markerHelpExample_17mlo_405",Us="_sessionCard_17mlo_409",Gs="_annotationCard_17mlo_410",Ys="_sessionEmptyState_17mlo_427",Ws="_sessionCardButton_17mlo_434",Ks="_annotationCardButton_17mlo_444",Xs="_sessionCardBody_17mlo_454",Vs="_sessionCardActive_17mlo_460",qs="_annotationCardActive_17mlo_461",Js="_annotationMeta_17mlo_471",Zs="_annotationInstructionPreview_17mlo_478",Qs="_annotationPreviewFooter_17mlo_486",er="_annotationInstructionEditor_17mlo_493",tr="_annotationTypeField_17mlo_499",ar="_annotationInstructionButton_17mlo_505",nr="_annotationInstructionField_17mlo_514",sr="_sessionMeta_17mlo_518",rr="_sessionTitle_17mlo_525",or="_annotationTitle_17mlo_526",ir="_sessionTimestamp_17mlo_532",lr="_annotationKind_17mlo_533",cr="_annotationInstructionTypeIcon_17mlo_537",dr="_sessionInstructionPreview_17mlo_543",ur="_sessionInstructionEditor_17mlo_551",mr="_sessionCardFooter_17mlo_557",fr="_toolRail_17mlo_564",hr="_canvasToolRail_17mlo_573",pr="_toolbarCluster_17mlo_594",gr="_toolbarViewportCluster_17mlo_601",yr="_toolbarSeparator_17mlo_605",br="_toolBtn_17mlo_611",xr="_toolRailButton_17mlo_615",vr="_toolbarButton_17mlo_625",_r="_toolBtnActive_17mlo_630",Ir="_toolbarActions_17mlo_637",kr="_toolbarSelectionActions_17mlo_646",wr="_toolbarColorPicker_17mlo_654",Sr="_colorPickerButton_17mlo_658",Nr="_colorPickerSwatch_17mlo_663",Cr="_colorPickerPopover_17mlo_671",jr="_colorOption_17mlo_686",Tr="_colorOptionActive_17mlo_696",$r="_toolbarUtilities_17mlo_703",Rr="_toolbarGeometryFields_17mlo_711",Pr="_toolbarGeometryField_17mlo_711",Br="_toolbarGeometryLabel_17mlo_724",Ar="_toolbarGeometryInput_17mlo_730",Mr="_iconButton_17mlo_735",Er="_ghostBtn_17mlo_740",Lr="_payloadBtn_17mlo_741",Fr="_backToTaskBtn_17mlo_742",Hr="_canvasScroller_17mlo_762",Or="_canvasFrame_17mlo_778",Dr="_canvasMedia_17mlo_785",zr="_canvasStatusOverlay_17mlo_793",Ur="_canvasStatusCard_17mlo_805",Gr="_canvasImage_17mlo_818",Yr="_overlay_17mlo_825",Wr="_overlaySelect_17mlo_831",Kr="_overlayPan_17mlo_835",Xr="_overlaySvg_17mlo_839",Vr="_overlayHitLayer_17mlo_848",qr="_arrowHitArea_17mlo_857",Jr="_canvasHandleHit_17mlo_864",Zr="_canvasResizeHandleHit_17mlo_871",Qr="_canvasHandleVisible_17mlo_875",eo="_pin_17mlo_892",to="_note_17mlo_893",ao="_annotationNumberBadge_17mlo_910",no="_box_17mlo_935",so="_boxNumberBadge_17mlo_944",ro="_arrowNumberBadge_17mlo_950",oo="_boxSurface_17mlo_954",io="_selected_17mlo_967",lo="_textInput_17mlo_984",co="_textArea_17mlo_985",uo="_select_17mlo_967",mo="_sessionTitleInput_17mlo_992",fo="_sessionInstructionField_17mlo_997",ho="_detailEmpty_17mlo_1006",po="_emptyState_17mlo_1007",go="_payloadModalBody_17mlo_1019",yo="_payloadModalToolbar_17mlo_1026",bo="_payloadViewToggle_17mlo_1033",xo="_payloadModalActions_17mlo_1034",vo="_payloadModalPreview_17mlo_1041",_o="_statusBar_17mlo_1056",Io="_annotationSummary_17mlo_1068",a={shell:qn,shellWithImageTray:Jn,shellImageTrayOpen:Zn,imageTrayPanel:Qn,imageTrayPanelOpen:es,imageTrayHeader:ts,imageTrayTitle:as,imageTraySearch:ns,imageTraySearchIcon:ss,imageTraySearchInput:rs,imageTrayList:os,imageTrayState:is,imageTrayStateError:ls,imageTrayItem:cs,imageTrayItemActive:ds,imageTrayThumb:us,imageTrayItemBody:ms,imageTrayItemTitle:fs,imageTrayItemTask:hs,imageTrayItemMetaDetails:ps,imageTrayItemMeta:gs,imageTrayItemReference:ys,panel:bs,sessionPanel:xs,detailPanel:vs,sessionContextBar:_s,sessionContextLeft:Is,sessionContextRight:ks,sessionContextLabel:ws,sessionContextSpacer:Ss,canvasPanel:Ns,canvasWorkspace:Cs,canvasMain:js,panelHeader:Ts,panelHeaderText:$s,panelTitle:Rs,canvasHeading:Ps,sessionActions:Bs,sessionList:As,annotationList:Ms,markerHelpModalBody:Es,openImageModalBody:Ls,openImageField:Fs,openImageActions:Hs,markerHelpItem:Os,markerHelpHeader:Ds,markerHelpExample:zs,sessionCard:Us,annotationCard:Gs,sessionEmptyState:Ys,sessionCardButton:Ws,annotationCardButton:Ks,sessionCardBody:Xs,sessionCardActive:Vs,annotationCardActive:qs,annotationMeta:Js,annotationInstructionPreview:Zs,annotationPreviewFooter:Qs,annotationInstructionEditor:er,annotationTypeField:tr,annotationInstructionButton:ar,annotationInstructionField:nr,sessionMeta:sr,sessionTitle:rr,annotationTitle:or,sessionTimestamp:ir,annotationKind:lr,annotationInstructionTypeIcon:cr,sessionInstructionPreview:dr,sessionInstructionEditor:ur,sessionCardFooter:mr,toolRail:fr,canvasToolRail:hr,toolbarCluster:pr,toolbarViewportCluster:gr,toolbarSeparator:yr,toolBtn:br,toolRailButton:xr,toolbarButton:vr,toolBtnActive:_r,toolbarActions:Ir,toolbarSelectionActions:kr,toolbarColorPicker:wr,colorPickerButton:Sr,colorPickerSwatch:Nr,colorPickerPopover:Cr,colorOption:jr,colorOptionActive:Tr,toolbarUtilities:$r,toolbarGeometryFields:Rr,toolbarGeometryField:Pr,toolbarGeometryLabel:Br,toolbarGeometryInput:Ar,iconButton:Mr,ghostBtn:Er,payloadBtn:Lr,backToTaskBtn:Fr,canvasScroller:Hr,canvasFrame:Or,canvasMedia:Dr,canvasStatusOverlay:zr,canvasStatusCard:Ur,canvasImage:Gr,overlay:Yr,overlaySelect:Wr,overlayPan:Kr,overlaySvg:Xr,overlayHitLayer:Vr,arrowHitArea:qr,canvasHandleHit:Jr,canvasResizeHandleHit:Zr,canvasHandleVisible:Qr,pin:eo,note:to,annotationNumberBadge:ao,box:no,boxNumberBadge:so,arrowNumberBadge:ro,boxSurface:oo,selected:io,textInput:lo,textArea:co,select:uo,sessionTitleInput:mo,sessionInstructionField:fo,detailEmpty:ho,emptyState:po,payloadModalBody:go,payloadModalToolbar:yo,payloadViewToggle:bo,payloadModalActions:xo,payloadModalPreview:vo,statusBar:_o,annotationSummary:Io},Ya=[{value:"review",label:"Review"},{value:"change",label:"Change"},{value:"question",label:"Question"}],Wa=[{value:"select",label:"Select",icon:Wn},{value:"pin",label:"Pin",icon:Ja},{value:"box",label:"Box",icon:Za},{value:"arrow",label:"Arrow",icon:Qa},{value:"text-note",label:"Note",icon:en}],ko={pin:Ja,box:Za,arrow:Qa,"text-note":en},wo={pin:"Pin",box:"Box",arrow:"Arrow","text-note":"Note"},So={review:oa,change:la,question:ia,issue:ia,idea:oa},Rt={select:{short:"Select and edit existing markers.",detail:"Use Select to click, drag, reorder, resize, and update markers that are already on the image.",example:"Example: move an existing marker after the screenshot changes."},pin:{short:"Mark a precise spot.",detail:"Use Pin when feedback points to one exact location instead of a broader area.",example:'Example: "This icon is misaligned by 2px."'},box:{short:"Mark an area or component.",detail:"Use Box when the feedback applies to a whole region, card, panel, or bounded UI block.",example:'Example: "This whole card needs tighter padding and a stronger border."'},arrow:{short:"Show direction or relationship.",detail:"Use Arrow when you need to show movement, attachment, flow, or source-to-target intent.",example:'Example: "This tooltip should anchor to this button, not the panel."'},"text-note":{short:"Add a comment-style point marker.",detail:"Use Note when you want a point marker that reads more like a comment or open question.",example:'Example: "Ask design whether this badge should stay."'}},lt={question:"#0f766e",change:"#2563eb",issue:"#dc2626",idea:"#d97706",review:"#7c3aed"},No=["#7c3aed","#2563eb","#0f766e","#dc2626","#d97706","#111827"],ce="review";function Ye(r){const l=String(r.displayName||"").trim();return l?`${l} review`:"Annotated session"}function tn(){return`annotation-${Math.random().toString(36).slice(2,10)}`}function I(r){return!Number.isFinite(r)||r<=0?0:r>=1?1:r}function Ne(r){return I(Math.max(.02,r))}function Ge(r){return r?[String(r.taskId||"").trim(),String(r.assetId||"").trim(),String(r.path||"").trim()].join("::"):""}function Co(r){if(!(r instanceof HTMLElement))return!1;const l=r.tagName.toLowerCase();return r.isContentEditable?!0:l==="input"||l==="textarea"||l==="select"}function Se(r){return r.map((l,f)=>({...l,order:f}))}function sa(r){if(!r)return"Unsaved";const l=new Date(r);return Number.isNaN(l.getTime())?"Unsaved":l.toLocaleString()}function jo(r){const l=typeof r=="number"&&Number.isFinite(r)?Math.max(0,r):0;return l<1024?`${l}B`:l<1024*1024?`${(l/1024).toFixed(1)}KB`:`${(l/(1024*1024)).toFixed(1)}MB`}function To(r){if(!r)return"";const l=new Date(r);if(Number.isNaN(l.getTime()))return"";const p=new Date().getTime()-l.getTime(),b=Math.floor(p/(1e3*60*60*24));return b<=0?"Today":b===1?"Yesterday":b<7?`${b}d ago`:b<30?`${Math.floor(b/7)}w ago`:l.toLocaleDateString()}function Pt(r){const l=String(r.createdByActor?.label||"").trim();return l||null}function $o(r){const l=String(r||"").trim().replace(/\s+/g," ");return l?l.length>110?`${l.slice(0,107)}...`:l:""}function Ka(r,l,f,p=lt[ce]){const b={id:tn(),order:0,instruction:"",markerType:ce,color:p};if(r==="pin")return{...b,kind:r,x:l.x,y:l.y};if(r==="text-note")return{...b,kind:r,x:l.x,y:l.y};if(r==="box"){const L=f||l;return{...b,kind:r,x:I(Math.min(l.x,L.x)),y:I(Math.min(l.y,L.y)),width:Ne(Math.abs(L.x-l.x)),height:Ne(Math.abs(L.y-l.y))}}const x=f||l;return{...b,kind:"arrow",x:l.x,y:l.y,x2:x.x,y2:x.y}}function ra(r){return r.color?r.color:lt[r.markerType||ce]}function Ro(r,l){const f=Math.max(l.width,1),p=Math.max(l.height,1),b=r.x*f,x=r.y*p,L=r.x2*f,ne=r.y2*p,se=L-b,ct=ne-x,Ce=Math.hypot(se,ct)||1,We=se/Ce,je=ct/Ce,G=Math.max(10,Math.min(16,Ce-2)),ye=G*.62,Te=L-We*G,$=ne-je*G,dt=-je,be=We;return{shaftX1:b,shaftY1:x,shaftX2:Te,shaftY2:$,headPoints:[`${L},${ne}`,`${Te+dt*ye},${$+be*ye}`,`${Te-dt*ye},${$-be*ye}`].join(" ")}}function Po(r,l){return{...r,markerType:l,color:r.color||lt[l]}}function Bo(r,l){return{...r,id:tn(),order:l}}function Ao(r,l){const f=String(r||"").trim()||(l?Ye(l):"Annotated session");return/\bcopy$/i.test(f)?`${f} 2`:`${f} copy`}function Mo(r,l,f){if(l===f||l<0||f<0||l>=r.length||f>=r.length)return r;const p=[...r],[b]=p.splice(l,1);return b?(p.splice(f,0,b),Se(p)):r}function ae(r){return String(Math.round(I(r)*1e3)/10)}function Eo(r){const l=Number.parseFloat(r);return Number.isFinite(l)?I(l/100):null}function Lo(r,l,f){return r.kind==="pin"||r.kind==="text-note"?l==="x"||l==="y"?{...r,[l]:I(f)}:r:r.kind==="box"?l==="x"||l==="y"?{...r,[l]:I(f)}:l==="width"||l==="height"?{...r,[l]:Ne(f)}:r:l==="x"||l==="y"||l==="x2"||l==="y2"?{...r,[l]:I(f)}:r}function Fo(r){return r.kind==="pin"||r.kind==="text-note"?[{key:"x",label:"X",value:ae(r.x)},{key:"y",label:"Y",value:ae(r.y)}]:r.kind==="box"?[{key:"x",label:"X",value:ae(r.x)},{key:"y",label:"Y",value:ae(r.y)},{key:"width",label:"Width",value:ae(r.width)},{key:"height",label:"Height",value:ae(r.height)}]:[{key:"x",label:"Start X",value:ae(r.x)},{key:"y",label:"Start Y",value:ae(r.y)},{key:"x2",label:"End X",value:ae(r.x2)},{key:"y2",label:"End Y",value:ae(r.y2)}]}function Ho(r){if(!r)return null;const l=Math.round(r.x*100),f=Math.round(r.y*100),p=Math.round(r.width*100),b=Math.round(r.height*100);return`crop ${l}%, ${f}% size ${p}% x ${b}%`}function Oo(r){return Number.isFinite(r)?Math.min(4,Math.max(.25,Number(r.toFixed(2)))):1}function Xa(r){const l=[`Annotated attachment: ${r.title||r.image.displayName}`,`Image: ${r.image.displayName}`,`Image Reference: ${r.image.referenceLabel||r.image.assetId}`,`Task ID: ${r.taskId}`,r.globalInstruction?`Global instruction: ${r.globalInstruction}`:"Global instruction: None provided.","Markers:"];return r.annotations.length===0?(l.push("0. No markers."),l.join(`
2
+ `)):(r.annotations.forEach((f,p)=>{const b=f.markerType||ce,x=Ho(f.cropHint);l.push(`${p+1}. ${f.kind} (${b})`),l.push(`Instruction: ${f.instruction||"No marker instruction."}`),x&&l.push(`Region: ${x}`)}),l.join(`
3
+ `))}function Bt(r){return{title:r.title,globalInstruction:r.globalInstruction,annotations:Se(r.annotations)}}function Va(r){return JSON.stringify(Bt(r))}function qa(r){const l=JSON.parse(r);return Bt({title:String(l?.title||""),globalInstruction:String(l?.globalInstruction||""),annotations:Array.isArray(l?.annotations)?l.annotations:[]})}function Do(r,l){return Bt({title:r?.title||l,globalInstruction:r?.globalInstruction||"",annotations:r?.annotations||[]})}function Vo({runtimeMode:r="local",apiBaseUrl:l="",cloudAuthBaseUrl:f="",workspaceId:p="default",sessionLoadReady:b=!0,requestedTarget:x=null,requestedSessionId:L=null,requestedOpenVersion:ne=0,imageTrayOpen:se,onCloseImageTray:ct,resolveTaskReferenceLabel:Ce,resolveImageReferenceLabel:We,onRequestedTargetHandled:je,onOpenTarget:G,onContextChange:ye,onBackToTask:Te}){const $=r==="cloud"&&(f||l)||"",[dt,be]=s.useState(x),[ut,$e]=s.useState([]),[v,Re]=s.useState(null),[At,Ke]=s.useState(!1),[Pe,Xe]=s.useState(""),[Be,Ve]=s.useState(""),[j,re]=s.useState([]),[S,F]=s.useState(null),[mt,ca]=s.useState(lt[ce]),[ft,ht]=s.useState(!1),[T,Ae]=s.useState("select"),[an,xe]=s.useState(!1),[pt,da]=s.useState(!1),[V,q]=s.useState(!1),[ua,g]=s.useState(null),[Y,R]=s.useState("saved"),[zo,D]=s.useState(null),[gt,ma]=s.useState(!1),[oe,Mt]=s.useState(null),[de,Et]=s.useState(!1),[nn,Lt]=s.useState(!1),[Ft,fa]=s.useState("json"),[yt,Ht]=s.useState(!1),[bt,Ot]=s.useState(!1),[sn,ha]=s.useState(!1),[rn,xt]=s.useState(!1),[Dt,vt]=s.useState(""),[qe,pa]=s.useState(!1),[zt,on]=s.useState([]),[_t,ln]=s.useState(""),[cn,ga]=s.useState(!1),[ya,ba]=s.useState(null),[ue,Je]=s.useState(!1),[Ut,Ze]=s.useState(!1),[P,Gt]=s.useState(1),[W,Qe]=s.useState(!1),[It,xa]=s.useState(!1),[kt,et]=s.useState({width:0,height:0}),va=s.useRef(null),Me=s.useRef(null),Yt=s.useRef(null),_a=s.useRef(null),me=s.useRef(L),ie=s.useRef(""),wt=s.useRef(0),Wt=s.useRef(""),ve=s.useRef(0),St=s.useRef(null),Ia=s.useRef(0),fe=s.useRef(!1),tt=s.useRef(null),Kt=s.useRef(null),_e=s.useRef(null),H=s.useRef(""),M=s.useRef(""),Nt=s.useRef(null),J=s.useRef(null),Ee=s.useRef(!1),Ct=s.useRef(null),at=s.useRef(null),nt=s.useRef(null),Ie=s.useRef(null),Le=s.useRef(null),Fe=s.useRef(null),He=s.useRef(null),he=s.useRef(null),Z=s.useRef(null),ka=s.useRef(null),wa=s.useRef(null),B=s.useMemo(()=>ut.find(e=>e.id===v)||null,[v,ut]),Q=s.useMemo(()=>`workspaceId=${encodeURIComponent(String(p||"default").trim()||"default")}`,[p]),A=s.useMemo(()=>({"x-taskforce-workspace-id":String(p||"default").trim()||"default"}),[p]),z=s.useMemo(()=>j.find(e=>e.id===S)||null,[j,S]),ee=s.useMemo(()=>Ge(x),[x]),le=typeof G=="function",d=le?x:dt,jt=s.useMemo(()=>{const e=String(d?.taskId||"").trim();if(!e)return"";const n=Ce?.(e).trim()||"";if(n)return n;const o=String(d?.taskReferenceLabel||"").trim();return o&&o!==e?o:n||e},[d?.taskId,d?.taskReferenceLabel,Ce]),st=s.useMemo(()=>{const e=String(d?.assetId||"").trim();if(!e)return"";const n=We?.(e).trim()||"";return n||String(d?.imageReferenceLabel||"").trim()},[d?.assetId,d?.imageReferenceLabel,We]),Xt=s.useMemo(()=>j.findIndex(e=>e.id===S),[j,S]),Vt=z?.color||mt,Sa=s.useMemo(()=>Bt({title:Pe,globalInstruction:Be,annotations:j}),[j,Be,Pe]),Oe=s.useMemo(()=>Va(Sa),[Sa]),Na=Oe!==M.current,y=s.useMemo(()=>({width:Math.max(kt.width*P,0),height:Math.max(kt.height*P,0)}),[kt.height,kt.width,P]),De=s.useMemo(()=>({visibleRadius:7,hitRadius:11}),[]),qt=s.useMemo(()=>`0 0 ${Math.max(y.width,1)} ${Math.max(y.height,1)}`,[y.height,y.width]),rt=typeof se=="boolean",Ca=s.useMemo(()=>{const e=_t.trim().toLowerCase();return e?zt.filter(n=>[n.displayName,n.originalFilename,n.imageReferenceLabel,n.taskReferenceLabel,n.assetId].filter(Boolean).join(" ").toLowerCase().includes(e)):zt},[zt,_t]),ke=s.useMemo(()=>{const e=Me.current;return e?P>1||y.width>e.clientWidth+1||y.height>e.clientHeight+1:P>1},[y.height,y.width,P]),Jt=`${Math.round(P*100)}%`,Zt=s.useMemo(()=>{const e=new Map;return j.forEach((n,o)=>{e.set(n.id,o+1)}),e},[j]);s.useEffect(()=>{me.current=L},[L]),s.useEffect(()=>{const e=_a.current;if(!e||!S)return;e.focus();const n=e.value.length;e.setSelectionRange(n,n)},[S]),s.useEffect(()=>{_e.current=v},[v]),s.useEffect(()=>{Ke(!1)},[v]),s.useEffect(()=>{if(!z){ht(!1);return}ca(z.color||lt[z.markerType||ce])},[z]);const Tt=s.useCallback(async e=>{const n=typeof performance<"u"?performance.now():Date.now(),o=await ge(`/api/taskforce/annotated-attachments/sessions?${Q}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...A},body:JSON.stringify({taskId:e.taskId,baseImageAssetId:e.assetId,title:Ye(e),globalInstruction:"",annotations:[]})},$),i=await o.json().catch(()=>({}));if(!o.ok)throw new Error(String(i?.error||"Failed to create session."));const c=i?.session;if(!c?.id)throw new Error("Failed to create session.");return $t("annotated_session_create_completed",{assetId:e.assetId,taskId:e.taskId||null,sessionId:c.id,durationMs:Math.round((typeof performance<"u"?performance.now():Date.now())-n),debugTimings:i?.debugTimings||null,serverTiming:typeof o.headers?.get=="function"&&o.headers.get("server-timing")||null}),c},[A,$,Q]),ja=s.useCallback(e=>new Promise((n,o)=>{const i=new FileReader;i.onload=()=>n(typeof i.result=="string"?i.result:""),i.onerror=()=>o(i.error||new Error("Failed to read clipboard image.")),i.readAsDataURL(e)}),[]),N=s.useCallback(()=>{tt.current!==null&&(window.clearTimeout(tt.current),tt.current=null),nt.current!==null&&(window.clearTimeout(nt.current),nt.current=null)},[]),ze=s.useCallback(e=>{Xe(e.title),Ve(e.globalInstruction),re(e.annotations),F(n=>n&&e.annotations.some(o=>o.id===n)?n:e.annotations[0]?.id||null)},[]),pe=s.useCallback((e,n)=>{const o=Ye(n||d||{assetId:e.baseImageAssetId,displayName:"Annotated session"}),i=Do(e,o),c=Va(i);fe.current=!0,N(),ze(i),M.current=c,H.current=c,Nt.current=null,Ee.current=!1,Ct.current=null,at.current=null,D(null),R("saved"),q(!1)},[d,ze,N]),ot=s.useCallback(e=>{fe.current=!0,N(),$e([]),Re(null),xe(!1),Ke(!1),Xe(Ye(e)),Ve(""),re([]),F(null),M.current="",H.current="",Nt.current=null,Ee.current=!1,Ct.current=null,at.current=null,Mt(null),Lt(!1),D(null),R("saved"),q(!1)},[N]),we=s.useCallback(async(e,n,o)=>{const i=_e.current;if(!i)return!0;if(e===M.current)return J.current||(D(null),R("saved")),!0;if(J.current){if(Ee.current=!0,!o?.waitForInFlight||!await J.current)return!1;const m=H.current;return m===M.current?!0:we(m,n,o)}N();const c=qa(e);Ct.current=i,Nt.current=e,q(!0),g(null),D(null),R("saving");const h=(async()=>{try{const u=await ge(`/api/taskforce/annotated-attachments/sessions/${encodeURIComponent(i)}?${Q}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json",...A},body:JSON.stringify(c)},$),m=await u.json().catch(()=>({}));if(!u.ok)throw new Error(String(m?.error||"Failed to save session."));const _=m?.session;if(!_?.id)throw new Error("Failed to save session.");$e(ea=>{const Ha=ea.findIndex(Bn=>Bn.id===_.id);if(Ha===-1)return[_,...ea];const Oa=[...ea];return Oa[Ha]=_,Oa}),M.current=e,at.current=null,D(null);const w=_e.current===_.id,C=H.current,X=C!==e,it=Ee.current||X;return Ee.current=!1,w&&!it?(fe.current=!0,ze(c),R("saved")):!it&&C===M.current?R("saved"):R("pending"),!0}catch(u){const m=u instanceof Error?u.message:"Failed to save session.";return g(m),D(m),R("error"),at.current!==e&&_e.current===i&&H.current===e&&(at.current=e,nt.current=window.setTimeout(()=>{nt.current=null,!(_e.current!==i||H.current!==e)&&we(e,n,{waitForInFlight:!0})},1500)),!1}finally{Nt.current=null,J.current=null,Ct.current=null,q(!1)}})();J.current=h;const k=await h;if(k){const u=H.current;if(u!==M.current)return we(u,n,o)}return k},[ze,N,A,$,Q]),Ta=s.useCallback(e=>{if(_e.current){if(H.current===M.current){D(null),J.current||R("saved");return}Y!=="saving"&&R("pending"),N(),tt.current=window.setTimeout(()=>{tt.current=null,we(H.current,"structure")},e)}},[N,we,Y]),K=s.useCallback(e=>{Kt.current=e},[]),E=s.useCallback(async e=>{N();const n=H.current;return!_e.current||n===M.current?(D(null),J.current||R("saved"),!0):we(n,e,{waitForInFlight:!0})},[N,we]),dn=s.useCallback(()=>{const e=M.current;e&&(N(),fe.current=!0,ze(qa(e)),D(null),R("saved"),g(null))},[ze,N]),U=s.useCallback(async(e,n)=>{const o=typeof performance<"u"?performance.now():Date.now(),i=JSON.stringify({targetKey:Ge(e),requestedSessionId:n?.requestedSessionId??null,autoCreateIfEmpty:n?.autoCreateIfEmpty===!0});if(St.current===i)return;const c=ve.current+1;ve.current=c,St.current=i,da(!0),g(null);try{const h=new URLSearchParams;p&&h.set("workspaceId",p),e.taskId&&h.set("taskId",e.taskId),h.set("imageAssetId",e.assetId);const k=await ge(`/api/taskforce/annotated-attachments/sessions?${h.toString()}`,{credentials:"include",headers:A,cache:"no-store"},$),u=await k.json().catch(()=>({}));if(!k.ok)throw new Error(String(u?.error||"Failed to load annotated attachment sessions."));const m=Array.isArray(u?.sessions)?u.sessions:[];if($t("annotated_sessions_loaded",{assetId:e.assetId,taskId:e.taskId||null,requestedSessionId:n?.requestedSessionId??null,autoCreateIfEmpty:n?.autoCreateIfEmpty===!0,sessionCount:m.length,durationMs:Math.round((typeof performance<"u"?performance.now():Date.now())-o),serverTiming:typeof k.headers?.get=="function"&&k.headers.get("server-timing")||null}),m.length===0&&n?.autoCreateIfEmpty&&String(e.assetId||"").trim()){const C=n?.requestedSessionId??me.current;if(me.current=null,C&&g("The previously selected annotation session could not be restored."),ve.current!==c)return;const X=await Tt(e);if($t("annotated_sessions_auto_created_after_empty_load",{assetId:e.assetId,taskId:e.taskId||null,sessionId:X.id,totalDurationMs:Math.round((typeof performance<"u"?performance.now():Date.now())-o)}),ve.current!==c)return;$e([X]),Re(X.id),xe(!1),pe(X,e);return}if(ve.current!==c)return;$e(m),xe(m.length===0);const _=n?.requestedSessionId??me.current;me.current=null;const w=m.find(C=>C.id===_)||m[0]||null;_&&!w&&g("The previously selected annotation session could not be restored."),Re(w?.id||null),w?pe(w,e):(fe.current=!0,N(),Xe(Ye(e)),Ve(""),re([]),F(null),M.current="",H.current="",D(null),R("saved"))}catch(h){if(ve.current!==c)return;g(h instanceof Error?h.message:"Failed to load sessions.")}finally{St.current===i&&(St.current=null),ve.current===c&&da(!1)}},[N,Tt,A,$,pe,p]),$a=s.useCallback(async()=>{ga(!0),ba(null);try{const e=new URLSearchParams;e.set("workspaceId",String(p||"default").trim()||"default");const n=await ge(`/api/taskforce/annotated-attachments/images?${e.toString()}`,{credentials:"include",headers:A,cache:"no-store"},$),o=await n.json().catch(()=>({}));if(!n.ok)throw new Error(String(o?.error||"Failed to load images."));on(Array.isArray(o?.images)?o.images:[])}catch(e){ba(e instanceof Error?e.message:"Failed to load images.")}finally{ga(!1)}},[A,$,p]),un=s.useCallback(async()=>{if(typeof navigator>"u"||!navigator.clipboard||typeof navigator.clipboard.read!="function"){g("Clipboard image paste is not supported in this environment.");return}xa(!0),g(null),Ia.current=Date.now()+2e3;try{const n=(await navigator.clipboard.read()).find(_=>_.types.some(w=>w.startsWith("image/"))),o=n?.types.find(_=>_.startsWith("image/"))||"";if(!n||!o)throw new Error("No image found on the clipboard.");const i=await n.getType(o),c=await ja(i);if(!c)throw new Error("Failed to read clipboard image.");const h=o==="image/jpeg"?"jpg":o==="image/webp"?"webp":o==="image/gif"?"gif":"png",k=await fetch("/api/taskforce/context-upload",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...A},body:JSON.stringify({file:c,originalName:`pasted-image.${h}`,workspaceId:String(p||"default").trim()||"default"})}),u=await k.json().catch(()=>({}));if(!k.ok||!u?.success||typeof u?.assetId!="string"||typeof u?.path!="string")throw new Error(String(u?.error||"Failed to paste image into Image Notes."));const m={assetId:u.assetId,imageReferenceLabel:typeof u?.referenceLabel=="string"?u.referenceLabel:void 0,path:u.path,displayName:typeof u?.displayName=="string"&&u.displayName.trim().length>0?u.displayName.trim():"Pasted image"};me.current=null,le?(ie.current="",G?.(m,{sessionId:null})):(be(m),ie.current=Ge(m),U(m,{autoCreateIfEmpty:!0}))}catch(e){g(e instanceof Error?e.message:"Failed to paste image.")}finally{xa(!1)}},[le,U,G,ja,A,p]),mn=s.useCallback(async()=>{const e=Dt.trim();if(!e){g("Enter an image reference to open.");return}pa(!0),g(null);try{const n=new URLSearchParams({workspaceId:String(p||"default").trim()||"default"}),o=await ge(`/api/taskforce/annotated-attachments/images/${encodeURIComponent(e)}?${n.toString()}`,{method:"GET",credentials:"include",headers:A}),i=await o.json().catch(()=>({}));if(!o.ok||!i?.target||typeof i.target.assetId!="string"||typeof i.target.path!="string")throw new Error(String(i?.error||"Failed to open image reference."));const c={assetId:i.target.assetId,path:i.target.path,displayName:typeof i.target.displayName=="string"&&i.target.displayName.trim().length>0?i.target.displayName.trim():"Image attachment",taskId:typeof i.target.taskId=="string"&&i.target.taskId.trim().length>0?i.target.taskId.trim():void 0,taskReferenceLabel:typeof i.target.taskReferenceLabel=="string"&&i.target.taskReferenceLabel.trim().length>0?i.target.taskReferenceLabel.trim():void 0,imageReferenceLabel:typeof i.target.imageReferenceLabel=="string"&&i.target.imageReferenceLabel.trim().length>0?i.target.imageReferenceLabel.trim():void 0};me.current=null,xt(!1),vt(""),le?(ie.current="",G?.(c,{sessionId:null})):(be(c),ie.current=Ge(c),U(c,{autoCreateIfEmpty:!0}))}catch(n){g(n instanceof Error?n.message:"Failed to open image reference.")}finally{pa(!1)}},[le,U,G,Dt,A,p]),fn=s.useCallback(async e=>{if(!e.assetId||!e.path||!await E("session-switch"))return;const o={assetId:e.assetId,path:e.path,displayName:String(e.displayName||e.originalFilename||"Image attachment").trim()||"Image attachment",...e.taskId?{taskId:e.taskId}:{},...e.taskReferenceLabel?{taskReferenceLabel:e.taskReferenceLabel}:{},...e.imageReferenceLabel?{imageReferenceLabel:e.imageReferenceLabel}:{}};me.current=null,g(null),le?(ie.current="",G?.(o,{sessionId:null})):(be(o),ie.current=Ge(o),ot(o),U(o,{autoCreateIfEmpty:!0}))},[E,le,U,G,ot]),Ra=s.useCallback(e=>{$e(n=>{const o=n.findIndex(c=>c.id===e.id);if(o===-1)return[e,...n];const i=[...n];return i[o]=e,i}),Re(e.id),pe(e,d)},[d,pe]),Pa=s.useCallback(e=>{$e(n=>{const o=n.filter(c=>c.id!==e),i=o[0]||null;return Re(i?.id||null),i?pe(i,d):(fe.current=!0,N(),Xe(Ye(d||{displayName:"Annotated session"})),Ve(""),re([]),F(null),M.current="",H.current="",D(null),R("saved")),o})},[d,N,pe]);s.useEffect(()=>{if(!x)return;if(le||be(n=>n&&Ge(n)===ee&&n.taskReferenceLabel===x.taskReferenceLabel&&n.imageReferenceLabel===x.imageReferenceLabel&&n.displayName===x.displayName?n:x),!b){ee&&(ee!==ie.current||ne!==wt.current)&&ee!==Wt.current&&(ot(x),Wt.current=ee,wt.current=ne,$t("annotated_sessions_load_deferred",{assetId:x.assetId,taskId:x.taskId||null,requestedTargetKey:ee})),je?.();return}ee&&(ee!==ie.current||ne!==wt.current)&&(ot(x),ie.current=ee,wt.current=ne,Wt.current="",U(x,{autoCreateIfEmpty:!0})),je?.()},[le,U,je,ne,x,ee,ot,L,b]),s.useEffect(()=>{d&&ye?.({target:d,sessionId:v})},[d,ye,v]),s.useEffect(()=>{if(!d||typeof document>"u"||!b)return;const e=()=>{Date.now()<Ia.current||H.current!==M.current||V||pt||U(d,{requestedSessionId:v})},n=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",n),()=>{document.removeEventListener("visibilitychange",n)}},[d,U,pt,V,v,b]),s.useEffect(()=>{if(!d?.path){Je(!1),Ze(!1),et({width:0,height:0});return}Je(!0),Ze(!1),et({width:0,height:0}),Gt(1),Qe(!1)},[d?.path]),s.useEffect(()=>{if(!ue)return;const e=Yt.current;!e||!e.complete||e.naturalWidth<=0||e.naturalHeight<=0||(et({width:e.naturalWidth,height:e.naturalHeight}),Je(!1),Ze(!1))},[d?.path,ue]),s.useEffect(()=>{ke||Qe(!1)},[ke]),s.useEffect(()=>{Mt(null)},[v]),s.useEffect(()=>{if(H.current=Oe,fe.current){fe.current=!1;return}if(!v){N(),D(null),R("saved");return}if(Oe===M.current){N(),J.current||(D(null),R("saved"));return}const e=Kt.current;if(Kt.current=null,Y==="error"&&e===null)return;const n=e??600;if(J.current){Ee.current=!0,R("pending");return}Ta(n)},[N,Oe,Y,Ta,v]),s.useEffect(()=>{v&&(J.current||Oe===M.current&&Y!=="error"&&Y!=="saved"&&(D(null),R("saved")))},[Oe,Y,v]),s.useEffect(()=>{!rt||!se||$a()},[$a,se,rt]),s.useEffect(()=>{if(typeof window>"u")return;const e=n=>{H.current!==M.current&&(n.preventDefault(),n.returnValue="")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),s.useEffect(()=>{if(typeof document>"u")return;const e=()=>{document.visibilityState==="hidden"&&E("visibility-hidden")};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[E]),s.useEffect(()=>{if(!ft||typeof document>"u")return;const e=n=>{const o=n.target;o instanceof Node&&(ka.current?.contains(o)||ht(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[ft]),s.useEffect(()=>{if(!At||typeof document>"u")return;const e=n=>{const o=n.target;o instanceof Node&&(wa.current?.contains(o)||Ke(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[At]),s.useEffect(()=>()=>{N()},[N]),s.useEffect(()=>{if(!de)return;const e=window.setTimeout(()=>Et(!1),2e3);return()=>window.clearTimeout(e)},[de]),s.useEffect(()=>{if(!yt)return;const e=window.setTimeout(()=>Ht(!1),2e3);return()=>window.clearTimeout(e)},[yt]),s.useEffect(()=>{if(!bt)return;const e=window.setTimeout(()=>Ot(!1),2e3);return()=>window.clearTimeout(e)},[bt]);const te=s.useCallback((e,n,o=300)=>{re(i=>Se(i.map(c=>c.id===e?n(c):c))),K(o)},[K]),hn=s.useCallback(e=>{z&&(te(z.id,n=>({...n,color:e})),ca(e),ht(!1))},[z,te]),Ba=s.useCallback(async()=>{if(!(!d||!await E("session-switch"))){q(!0),g(null);try{const n=await Tt(d);xe(!1),await U(d,{requestedSessionId:n.id,autoCreateIfEmpty:!1}),Ae("select")}catch(n){g(n instanceof Error?n.message:"Failed to create session."),xe(!0)}finally{q(!1)}}},[d,Tt,E,U]),pn=s.useCallback(e=>{if(e!=="select"&&!B){Qe(!1),g("No session exists for this image yet."),xe(!0);return}g(null),xe(!1),Qe(!1),Ae(e)},[B]),gn=s.useCallback(async()=>{if(!(!d||!B||!await E("duplicate"))){q(!0),g(null);try{const n=Se(j.map((h,k)=>Bo(h,k))),o=await ge(`/api/taskforce/annotated-attachments/sessions?${Q}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...A},body:JSON.stringify({taskId:d.taskId,baseImageAssetId:d.assetId,title:Ao(Pe||B.title,d),globalInstruction:Be,annotations:n})},$),i=await o.json().catch(()=>({}));if(!o.ok)throw new Error(String(i?.error||"Failed to duplicate session."));const c=i?.session;if(!c?.id)throw new Error("Failed to duplicate session.");Ra(c),Ae("select")}catch(n){g(n instanceof Error?n.message:"Failed to duplicate session.")}finally{q(!1)}}},[d,j,Be,Pe,Ra,E,A,$,B,Q]),yn=s.useCallback(async()=>E("manual"),[E]),Aa=s.useCallback(async()=>{if(v){ma(!0),g(null);try{const e=await ge(`/api/taskforce/annotated-attachments/sessions/${encodeURIComponent(v)}/payload?${Q}`,{credentials:"include",headers:A},$),n=await e.json().catch(()=>({}));if(!e.ok)throw new Error(String(n?.error||"Failed to load payload preview."));Mt(n?.payload||null)}catch(e){g(e instanceof Error?e.message:"Failed to load payload preview.")}finally{ma(!1)}}},[A,$,v,Q]),bn=s.useCallback(()=>{v&&E("payload-preview").then(e=>{e&&(Lt(!0),Aa())})},[E,Aa,v]),Ma=s.useCallback(async e=>{if(!oe||!navigator.clipboard||typeof navigator.clipboard.writeText!="function"){g("Clipboard copy is not available in this browser.");return}try{const n=e==="json"?JSON.stringify(oe,null,2):Xa(oe);await navigator.clipboard.writeText(n),Et(e)}catch(n){g(n instanceof Error?n.message:"Failed to copy payload content."),Et(!1)}},[oe]),xn=s.useCallback(async()=>{if(!jt||!navigator.clipboard||typeof navigator.clipboard.writeText!="function"){g("Clipboard copy is not available in this browser.");return}try{await navigator.clipboard.writeText(jt),Ht(!0)}catch(e){g(e instanceof Error?e.message:"Failed to copy task id."),Ht(!1)}},[jt]),vn=s.useCallback(async()=>{if(!st||!navigator.clipboard||typeof navigator.clipboard.writeText!="function"){g("Clipboard copy is not available in this browser.");return}try{await navigator.clipboard.writeText(st),Ot(!0)}catch(e){g(e instanceof Error?e.message:"Failed to copy image reference."),Ot(!1)}},[st]),_n=s.useCallback(async()=>{if(!v||!await E("delete-session"))return;const n=(B?.title||"Untitled session").trim()||"Untitled session";if(window.confirm(`Delete the annotated attachment session "${n}"?`)){q(!0),g(null);try{const o=await ge(`/api/taskforce/annotated-attachments/sessions/${encodeURIComponent(v)}?${Q}`,{method:"DELETE",credentials:"include",headers:A},$),i=await o.json().catch(()=>({}));if(!o.ok)throw new Error(String(i?.error||"Failed to delete session."));Pa(v),Ae("select")}catch(o){g(o instanceof Error?o.message:"Failed to delete session.")}finally{q(!1)}}},[E,Pa,A,$,B,v,Q]),Qt=s.useCallback(()=>{S&&(re(e=>Se(e.filter(n=>n.id!==S))),F(null),K(300))},[K,S]),Ue=s.useCallback(e=>{const n=Oo(e),o=Me.current;if(!o||n===P){Gt(n);return}const i=(o.scrollLeft+o.clientWidth/2)*(n/P)-o.clientWidth/2,c=(o.scrollTop+o.clientHeight/2)*(n/P)-o.clientHeight/2;Gt(n),window.requestAnimationFrame(()=>{o.scrollLeft=Math.max(0,i),o.scrollTop=Math.max(0,c)})},[P]),In=s.useCallback(()=>{Ue(P+.25)},[Ue,P]),kn=s.useCallback(()=>{Ue(P-.25)},[Ue,P]),wn=s.useCallback(()=>{Ue(1);const e=Me.current;e&&window.requestAnimationFrame(()=>{e.scrollLeft=0,e.scrollTop=0})},[Ue]),Ea=s.useCallback(e=>{S&&re(n=>{const o=n.findIndex(c=>c.id===S);if(o===-1)return n;const i=e==="up"?o-1:o+1;return i<0||i>=n.length?n:(K(300),Mo(n,o,i))})},[K,S]);s.useEffect(()=>{if(!S)return;const e=n=>{n.key==="Delete"&&(Co(n.target)||(n.preventDefault(),Qt()))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Qt,S]);const O=s.useCallback(e=>{const n=va.current?.getBoundingClientRect();return!n||n.width<=0||n.height<=0?null:{x:I((e.clientX-n.left)/n.width),y:I((e.clientY-n.top)/n.height)}},[]),Sn=s.useCallback(e=>{if(W&&ke){const i=Me.current;if(!i)return;Z.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,scrollLeft:i.scrollLeft,scrollTop:i.scrollTop},e.currentTarget.setPointerCapture(e.pointerId),e.preventDefault();return}if(!v)return;if(T==="select"){F(null);return}const n=O(e);if(!n)return;if(T==="pin"||T==="text-note"){const i=Ka(T,n,n,mt);re(c=>Se([...c,i])),F(i.id),K(300),Ae("select");return}Ie.current=n;const o=Ka(T,n,n,mt);he.current={annotationId:o.id,kind:T},e.currentTarget.setPointerCapture?.(e.pointerId),re(i=>Se([...i,o])),F(o.id),K(300)},[ke,mt,K,W,O,v,T]),Nn=s.useCallback(e=>{if(Z.current?.pointerId===e.pointerId){e.currentTarget.releasePointerCapture?.(e.pointerId);return}if(!Ie.current||!he.current||T!=="box"&&T!=="arrow")return;const n=O(e);Ie.current=null,he.current=null,e.currentTarget.releasePointerCapture?.(e.pointerId),n&&Ae("select")},[O,T]),La=s.useCallback((e,n)=>{if(T!=="select"||W)return;const o=O(e);o&&(Le.current={annotationId:n.id,originPointer:o,originAnnotation:n},F(n.id),e.stopPropagation())},[W,O,T]),Cn=s.useCallback(e=>{if(Z.current?.pointerId===e.pointerId){const u=Me.current;if(!u)return;const m=e.clientX-Z.current.startX,_=e.clientY-Z.current.startY;u.scrollLeft=Z.current.scrollLeft-m,u.scrollTop=Z.current.scrollTop-_;return}if(he.current&&Ie.current){const u=O(e);if(!u)return;const{annotationId:m,kind:_}=he.current,w=Ie.current;te(m,C=>_==="box"&&C.kind==="box"?{...C,x:I(Math.min(w.x,u.x)),y:I(Math.min(w.y,u.y)),width:Ne(Math.abs(u.x-w.x)),height:Ne(Math.abs(u.y-w.y))}:_==="arrow"&&C.kind==="arrow"?{...C,x:w.x,y:w.y,x2:u.x,y2:u.y}:C);return}if(Fe.current){const u=O(e);if(!u)return;const{annotationId:m,originPointer:_,originAnnotation:w}=Fe.current,C=u.x-_.x,X=u.y-_.y;te(m,()=>({...w,width:Ne(w.width+C),height:Ne(w.height+X)}));return}if(He.current){const u=O(e);if(!u)return;const{annotationId:m,endpoint:_,originPointer:w,originAnnotation:C}=He.current,X=u.x-w.x,it=u.y-w.y;te(m,()=>_==="tail"?{...C,x:I(C.x+X),y:I(C.y+it)}:{...C,x2:I(C.x2+X),y2:I(C.y2+it)});return}if(!Le.current)return;const n=O(e);if(!n)return;const{annotationId:o,originPointer:i,originAnnotation:c}=Le.current,h=n.x-i.x,k=n.y-i.y;te(o,()=>c.kind==="pin"||c.kind==="text-note"?{...c,x:I(c.x+h),y:I(c.y+k)}:c.kind==="box"?{...c,x:I(c.x+h),y:I(c.y+k)}:{...c,x:I(c.x+h),y:I(c.y+k),x2:I(c.x2+h),y2:I(c.y2+k)})},[O,te]),jn=s.useCallback(()=>{Ie.current=null,Le.current=null,Fe.current=null,He.current=null,he.current=null,Z.current=null},[]),Tn=s.useCallback(()=>{Ie.current=null,Le.current=null,Fe.current=null,He.current=null,he.current=null,Z.current=null},[]),$n=s.useCallback(()=>{Le.current=null,Fe.current=null,He.current=null,he.current=null,Z.current=null},[]),Rn=s.useCallback((e,n)=>{if(T!=="select"||W)return;const o=O(e);o&&(Fe.current={annotationId:n.id,originPointer:o,originAnnotation:n},F(n.id),e.stopPropagation())},[W,O,T]),Fa=s.useCallback((e,n,o)=>{if(T!=="select"||W)return;const i=O(e);i&&(He.current={annotationId:n.id,originPointer:i,originAnnotation:n,endpoint:o},F(n.id),e.stopPropagation())},[W,O,T]),Pn=B?.updatedAt?sa(B.updatedAt):"Not saved yet";return t.jsxs("div",{className:`${a.shell} ${rt?a.shellWithImageTray:""} ${rt&&se?a.shellImageTrayOpen:""}`.trim(),children:[rt?t.jsxs("aside",{className:`${a.imageTrayPanel} ${se?a.imageTrayPanelOpen:""}`.trim(),"aria-label":"Image tray","aria-hidden":!se,children:[t.jsxs("div",{className:a.imageTrayHeader,children:[t.jsxs("span",{className:a.imageTrayTitle,children:[t.jsx(za,{size:14}),"Images"]}),t.jsx("button",{type:"button",className:"tf-control-icon",onClick:ct,title:"Collapse image tray","aria-label":"Collapse image tray",children:t.jsx(En,{size:16})})]}),t.jsxs("div",{className:a.imageTraySearch,children:[t.jsx(Ln,{size:12,className:a.imageTraySearchIcon}),t.jsx("input",{type:"text",placeholder:"Search images...",value:_t,onChange:e=>ln(e.target.value),className:a.imageTraySearchInput})]}),t.jsx("div",{className:`tf-scrollbar ${a.imageTrayList}`,children:cn?t.jsx("div",{className:a.imageTrayState,children:"Loading images..."}):ya?t.jsx("div",{className:a.imageTrayStateError,children:ya}):Ca.length===0?t.jsx("div",{className:a.imageTrayState,children:_t.trim()?"No images match your search.":"No images found."}):Ca.map(e=>{const n=d?.assetId===e.assetId,o=typeof e.attachmentCount=="number"&&Number.isFinite(e.attachmentCount)?Math.max(0,e.attachmentCount):0,i=typeof e.sessionCount=="number"&&Number.isFinite(e.sessionCount)?Math.max(0,e.sessionCount):0,c=o>1?`${o} tasks linked`:o===1?e.taskReferenceLabel||"1 task linked":"Unattached",h=String(e.displayName||e.originalFilename||"Image attachment").trim()||"Image attachment";return t.jsxs("button",{type:"button",className:`${a.imageTrayItem} ${n?a.imageTrayItemActive:""}`.trim(),onClick:()=>{fn(e)},title:h,children:[t.jsx("span",{className:a.imageTrayThumb,children:t.jsx("img",{src:e.path,alt:"",loading:"lazy"})}),t.jsxs("span",{className:a.imageTrayItemBody,children:[t.jsx("span",{className:a.imageTrayItemTitle,children:h}),t.jsx("span",{className:a.imageTrayItemTask,children:c}),t.jsxs("span",{className:a.imageTrayItemMeta,children:[t.jsxs("span",{className:a.imageTrayItemMetaDetails,children:[jo(e.sizeBytes),e.updatedAt?t.jsxs(t.Fragment,{children:[" · ",To(e.updatedAt)]}):null,i>0?t.jsxs(t.Fragment,{children:[" · ",i," session",i===1?"":"s"]}):null]}),e.imageReferenceLabel?t.jsx("span",{className:a.imageTrayItemReference,children:e.imageReferenceLabel}):null]})]})]},e.assetId)})})]}):null,t.jsxs("section",{className:`tf-surface-panel ${a.panel} ${a.sessionPanel}`,children:[t.jsx("div",{className:a.sessionContextBar,children:d?.taskId?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:a.sessionContextLeft,children:Te?t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.backToTaskBtn}`,onClick:()=>{E("back-to-task").then(e=>{e&&d.taskId&&Te(d.taskId)})},"aria-label":"Back to task",title:"Back to task",children:t.jsx(Fn,{size:16})}):t.jsx("div",{className:a.sessionContextSpacer,"aria-hidden":"true"})}),t.jsx("div",{className:a.sessionContextRight,children:t.jsx(Mn,{copied:yt,onClick:()=>{xn()},title:"Copy task id",ariaLabel:yt?"Copied task id":"Copy task id",label:jt})})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:a.sessionContextLeft,children:t.jsx("span",{className:`tf-label-micro ${a.sessionContextLabel}`,children:"Unattached Image"})}),t.jsx("div",{className:a.sessionContextRight,children:t.jsx("div",{className:a.sessionContextSpacer,"aria-hidden":"true"})})]})}),t.jsxs("div",{className:a.panelHeader,children:[t.jsxs("div",{className:a.panelHeaderText,children:[t.jsx("div",{className:`tf-heading-card ${a.panelTitle}`,children:"Sessions"}),d?null:t.jsx("div",{className:"tf-text-secondary",children:"Open an image attachment to begin"})]}),t.jsx("div",{className:a.sessionActions,children:t.jsx("button",{type:"button",className:`tf-control-icon ${a.iconButton}`,onClick:()=>{Ba()},disabled:!d||V,"aria-label":"Create session",title:"Create session",children:t.jsx(Hn,{size:16})})})]}),d?pt?t.jsx("div",{className:a.emptyState,children:t.jsx("p",{className:"tf-empty-copy",children:"Loading sessions…"})}):t.jsx("div",{className:`tf-scrollbar ${a.sessionList}`,children:ut.length===0?t.jsxs("div",{className:a.sessionEmptyState,children:[t.jsx("div",{className:`tf-heading-card ${a.sessionTitle}`,children:"No sessions yet"}),t.jsx("div",{className:`tf-text-secondary ${a.annotationSummary}`,children:"Create the first annotation session for this image."})]}):ut.map(e=>{const n=v===e.id,o=n&&At,i=$o(n?Be:e.globalInstruction),c=(n?Pe:e.title)||"Untitled session";return t.jsxs("div",{className:`tf-surface-elevated ${a.sessionCard} ${n?a.sessionCardActive:""}`,ref:n?wa:void 0,onBlur:o?h=>{const k=h.relatedTarget;k instanceof Node&&h.currentTarget.contains(k)||Ke(!1)}:void 0,children:[o?t.jsxs("div",{className:a.sessionCardBody,children:[t.jsxs("div",{className:a.sessionMeta,children:[t.jsx("label",{className:"tf-field-label",htmlFor:"annotated-session-title",children:"Session title"}),t.jsx("input",{id:"annotated-session-title",className:`tf-field-shell ${a.textInput} ${a.sessionTitleInput}`,value:Pe,onChange:h=>{Xe(h.target.value),K(600)},placeholder:"Session title"}),t.jsx("span",{className:`tf-text-meta ${a.sessionTimestamp}`,children:sa(e.updatedAt)})]}),Pt(e)?t.jsxs("div",{className:`tf-text-secondary ${a.sessionCreator}`,children:["Created by ",Pt(e)]}):null,t.jsxs("div",{className:a.sessionInstructionEditor,children:[t.jsx("label",{className:"tf-field-label",htmlFor:"annotated-session-instruction",children:"Session instruction"}),t.jsx("textarea",{id:"annotated-session-instruction",className:`tf-field-shell ${a.textArea} ${a.sessionInstructionField}`,value:Be,onChange:h=>{Ve(h.target.value),K(600)},placeholder:"Add overall instructions, context, or framing for this session."})]}),t.jsxs("div",{className:`tf-text-secondary ${a.annotationSummary}`,children:[e.annotations.length," annotation",e.annotations.length===1?"":"s"]})]}):t.jsxs("button",{type:"button",className:a.sessionCardButton,onClick:()=>{if(n){Ke(!0);return}E("session-switch").then(h=>{h&&(Re(e.id),pe(e,d))})},"aria-pressed":n,children:[t.jsxs("div",{className:a.sessionMeta,children:[t.jsx("span",{className:`tf-heading-card ${a.sessionTitle}`,children:c}),t.jsx("span",{className:`tf-text-meta ${a.sessionTimestamp}`,children:sa(e.updatedAt)})]}),Pt(e)?t.jsxs("div",{className:`tf-text-secondary ${a.sessionCreator}`,children:["Created by ",Pt(e)]}):null,i?t.jsx("div",{className:`tf-text-secondary ${a.sessionInstructionPreview}`,children:i}):null,t.jsxs("div",{className:`tf-text-secondary ${a.annotationSummary}`,children:[e.annotations.length," annotation",e.annotations.length===1?"":"s"]})]}),n?t.jsx("div",{className:a.sessionCardFooter,children:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:`tf-button-ghost ${a.toolRailButton} ${a.iconButton}`,onClick:()=>{gn()},disabled:V,"aria-label":"Duplicate session",title:`Duplicate session "${c}"`,children:t.jsx(na,{size:16})}),t.jsx("button",{type:"button",className:`tf-button-ghost ${a.toolRailButton} ${a.iconButton}`,onClick:()=>{_n()},disabled:V,"aria-label":"Delete session",title:`Delete session "${c}"`,children:t.jsx(Ua,{size:16})})]})}):null]},e.id)})}):t.jsxs("div",{className:a.emptyState,children:[t.jsx("strong",{className:"tf-empty-title",children:"No image selected"}),t.jsx("p",{className:"tf-empty-copy",children:"Open an image attachment from a task to start an annotated session."})]})]}),t.jsxs("section",{className:`tf-surface-panel ${a.panel} ${a.canvasPanel}`,children:[t.jsxs("div",{className:a.panelHeader,children:[t.jsxs("div",{className:a.canvasHeading,children:[t.jsx("div",{className:"tf-heading-card",children:d?.displayName||"Annotated attachment"}),t.jsx("div",{className:"tf-text-secondary",children:B?`${j.length} markers · ${Pn}`:"Pick or create a session"})]}),st?t.jsx(Vn,{copied:bt,onClick:()=>{vn()},title:"Copy image reference",ariaLabel:bt?"Copied image reference":"Copy image reference",label:st}):null]}),t.jsxs("div",{className:a.toolRail,children:[t.jsxs("div",{className:`${a.toolbarCluster} ${a.toolbarViewportCluster}`,children:[t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:()=>{yn()},disabled:!B||V||!Na&&Y!=="error","aria-label":V?"Saving session":"Save session",title:V?"Saving session":"Save session",children:t.jsx(On,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:()=>xt(!0),disabled:qe,"aria-label":"Open image",title:"Open image",children:t.jsx(za,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:()=>{un()},disabled:It,"aria-label":It?"Pasting image":"Paste image",title:It?"Pasting image":"Paste image",children:It?t.jsx(Ga,{size:18,className:Da.spin}):t.jsx(Dn,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:()=>{B&&dn()},disabled:!B||!Na,"aria-label":"Reset unsaved changes",title:"Reset unsaved changes",children:t.jsx(zn,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost ${a.toolRailButton} ${a.iconButton}`,onClick:kn,disabled:!d||ue||P<=.25,"aria-label":"Zoom out",children:t.jsx(Un,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:wn,disabled:!d||ue||P===1,"aria-label":`Reset zoom to 100 percent (currently ${Jt})`,title:`Reset zoom to 100% (currently ${Jt})`,children:t.jsx("span",{children:Jt})}),t.jsx("button",{type:"button",className:`tf-button-ghost ${a.toolRailButton} ${a.iconButton}`,onClick:In,disabled:!d||ue||P>=4,"aria-label":"Zoom in",children:t.jsx(Gn,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.toolBtn} ${a.toolbarButton} ${W?a.toolBtnActive:""}`,onClick:()=>Qe(e=>!e),disabled:!d||ue||!ke,"aria-label":"Pan canvas",title:"Pan canvas",children:t.jsx(Yn,{size:18})})]}),t.jsx("span",{className:a.toolbarSeparator,"aria-hidden":"true"}),t.jsxs("div",{className:a.toolbarActions,children:[t.jsx("div",{className:a.toolbarSelectionActions,children:z?t.jsxs(t.Fragment,{children:[t.jsxs("div",{ref:ka,className:a.toolbarColorPicker,children:[t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton} ${a.colorPickerButton}`,onClick:()=>ht(e=>!e),"aria-label":"Marker color","aria-expanded":ft,title:"Marker color",children:t.jsx("span",{className:a.colorPickerSwatch,style:{backgroundColor:Vt},"aria-hidden":"true"})}),ft?t.jsx("div",{className:a.colorPickerPopover,role:"menu","aria-label":"Marker color options",children:No.map(e=>t.jsx("button",{type:"button",className:`${a.colorOption} ${Vt===e?a.colorOptionActive:""}`,style:{backgroundColor:e},onClick:()=>hn(e),"aria-label":`Use marker color ${e}`,"aria-pressed":Vt===e},e))}):null]}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:Qt,"aria-label":"Delete marker",title:"Delete selected marker",children:t.jsx(Ua,{size:18})}),t.jsx("div",{className:a.toolbarGeometryFields,"aria-label":"Marker geometry percent controls",children:Fo(z).map(e=>t.jsxs("label",{className:a.toolbarGeometryField,children:[t.jsx("span",{className:`tf-text-meta ${a.toolbarGeometryLabel}`,children:e.label}),t.jsx("input",{className:`tf-field-shell ${a.toolbarGeometryInput}`,type:"number",min:0,max:100,step:.1,value:e.value,onChange:n=>{const o=Eo(n.target.value);o!==null&&te(z.id,i=>Lo(i,e.key,o))},"aria-label":`${e.label} percent`})]},e.key))})]}):null}),t.jsxs("div",{className:a.toolbarUtilities,children:[t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.payloadBtn} ${a.toolbarButton}`,onClick:bn,disabled:!B||gt,"aria-label":gt?"Loading payload preview":"Preview payload",title:gt?"Loading payload preview":"Preview payload",children:t.jsx(oa,{size:18})}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:()=>ha(!0),"aria-label":"How to use marker tools",title:"How to use marker tools",children:t.jsx(ia,{size:18})})]})]})]}),t.jsxs("div",{className:a.canvasWorkspace,children:[t.jsx("div",{className:a.canvasToolRail,"aria-label":"Annotation tools",children:Wa.map(e=>{const n=e.icon;return t.jsx("button",{type:"button",className:`tf-button-ghost ${a.toolRailButton} ${T===e.value?a.toolBtnActive:""}`,onClick:()=>pn(e.value),disabled:!d,title:e.label,"aria-label":`${e.label} tool. ${Rt[e.value].short}`,children:t.jsx(n,{size:18})},e.value)})}),t.jsx("div",{className:a.canvasMain,children:t.jsx("div",{ref:Me,className:`tf-scrollbar ${a.canvasScroller}`,children:d?t.jsxs(t.Fragment,{children:[ue&&!Ut?t.jsx("div",{className:a.canvasStatusOverlay,"aria-live":"polite",children:t.jsxs("div",{className:a.canvasStatusCard,children:[t.jsx(Ga,{size:20,className:Da.spinner}),t.jsx("span",{children:"Loading image…"})]})}):null,Ut?t.jsx("div",{className:a.canvasStatusOverlay,"aria-live":"polite",children:t.jsx("div",{className:a.canvasStatusCard,children:t.jsx("span",{children:"Image failed to load."})})}):null,t.jsx("div",{className:a.canvasFrame,children:t.jsxs("div",{className:a.canvasMedia,style:{width:y.width?`${y.width}px`:void 0,height:y.height?`${y.height}px`:void 0},children:[t.jsx("img",{ref:Yt,src:d.path,alt:d.displayName,className:a.canvasImage,onLoad:()=>{const e=Yt.current;et({width:e?.naturalWidth||0,height:e?.naturalHeight||0}),Je(!1),Ze(!1)},onError:()=>{et({width:0,height:0}),Je(!1),Ze(!0)}}),!ue&&!Ut&&B?t.jsxs("div",{ref:va,className:`${a.overlay} ${T==="select"?a.overlaySelect:""} ${W&&ke?a.overlayPan:""}`,onPointerDown:Sn,onPointerMove:Cn,onPointerUp:e=>{Nn(e),$n()},"data-testid":"annotated-attachment-overlay",onPointerLeave:jn,onPointerCancel:Tn,children:[t.jsx("svg",{className:a.overlaySvg,viewBox:qt,preserveAspectRatio:"none","aria-hidden":"true",children:j.filter(e=>e.kind==="arrow").map(e=>{const n=Ro(e,y),o=ra(e),i=S===e.id;return t.jsxs(ta.Fragment,{children:[i?t.jsxs(t.Fragment,{children:[t.jsx("line",{x1:n.shaftX1,y1:n.shaftY1,x2:n.shaftX2,y2:n.shaftY2,stroke:"color-mix(in srgb, var(--surface-elevated) 92%, transparent)",strokeWidth:14,strokeLinecap:"round"}),t.jsx("polygon",{points:n.headPoints,fill:o,stroke:"color-mix(in srgb, var(--surface-elevated) 92%, transparent)",strokeWidth:4,strokeLinejoin:"round"})]}):null,t.jsx("line",{x1:n.shaftX1,y1:n.shaftY1,x2:n.shaftX2,y2:n.shaftY2,stroke:o,strokeWidth:i?10:6,strokeLinecap:"round"}),t.jsx("polygon",{points:n.headPoints,fill:o})]},e.id)})}),t.jsx("svg",{className:a.overlayHitLayer,viewBox:qt,preserveAspectRatio:"none",children:j.filter(e=>e.kind==="arrow").map(e=>t.jsxs(ta.Fragment,{children:[t.jsx("line",{x1:e.x*y.width,y1:e.y*y.height,x2:e.x2*y.width,y2:e.y2*y.height,className:a.arrowHitArea,"data-testid":`annotated-arrow-hit-${e.id}`,"aria-label":`Arrow marker ${Zt.get(e.id)||0}`,onPointerDown:n=>La(n,e),onClick:n=>{n.stopPropagation(),F(e.id)}}),S===e.id?t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:e.x*y.width,cy:e.y*y.height,r:De.hitRadius,className:a.canvasHandleHit,role:"button",tabIndex:0,"aria-label":"Move arrow tail",onPointerDown:n=>Fa(n,e,"tail")}),t.jsx("circle",{cx:e.x*y.width,cy:e.y*y.height,r:De.visibleRadius,className:a.canvasHandleVisible,"aria-hidden":"true"}),t.jsx("circle",{cx:e.x2*y.width,cy:e.y2*y.height,r:De.hitRadius,className:a.canvasHandleHit,role:"button",tabIndex:0,"aria-label":"Move arrow tip",onPointerDown:n=>Fa(n,e,"tip")}),t.jsx("circle",{cx:e.x2*y.width,cy:e.y2*y.height,r:De.visibleRadius,className:a.canvasHandleVisible,"aria-hidden":"true"})]}):null]},`hit-${e.id}`))}),j.filter(e=>e.kind==="arrow").map(e=>t.jsx("div",{className:`${a.annotationNumberBadge} ${a.arrowNumberBadge}`,style:{left:`${(e.x+e.x2)/2*100}%`,top:`${(e.y+e.y2)/2*100}%`,backgroundColor:ra(e)},"aria-hidden":"true",children:Zt.get(e.id)||0},`arrow-number-${e.id}`)),j.filter(e=>e.kind!=="arrow").map(e=>{const n=ra(e),o=Zt.get(e.id)||0,i={onPointerDown:c=>La(c,e),onClick:c=>{c.stopPropagation(),F(e.id)}};return e.kind==="pin"?t.jsx("button",{type:"button",...i,className:`${a.pin} ${S===e.id?a.selected:""}`,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,backgroundColor:n},children:o},e.id):e.kind==="text-note"?t.jsx("button",{type:"button",...i,className:`${a.note} ${S===e.id?a.selected:""}`,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,backgroundColor:n},children:o},e.id):t.jsxs("div",{className:`${a.box} ${S===e.id?a.selected:""}`,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.width*100}%`,height:`${e.height*100}%`,borderColor:n},children:[t.jsx("span",{className:`${a.annotationNumberBadge} ${a.boxNumberBadge}`,style:{backgroundColor:n},"aria-hidden":"true",children:o}),t.jsx("button",{type:"button",...i,className:a.boxSurface,"aria-label":`Box marker ${o}`})]},e.id)}),t.jsx("svg",{className:a.overlaySvg,viewBox:qt,preserveAspectRatio:"none",children:j.filter(e=>e.kind==="box"&&S===e.id).map(e=>t.jsxs(ta.Fragment,{children:[t.jsx("circle",{cx:(e.x+e.width)*y.width,cy:(e.y+e.height)*y.height,r:De.hitRadius,className:`${a.canvasHandleHit} ${a.canvasResizeHandleHit}`,role:"button",tabIndex:0,"aria-label":"Resize box marker",onPointerDown:n=>Rn(n,e)}),t.jsx("circle",{cx:(e.x+e.width)*y.width,cy:(e.y+e.height)*y.height,r:De.visibleRadius,className:a.canvasHandleVisible,"aria-hidden":"true"})]},`box-handle-${e.id}`))})]}):null]})})]}):t.jsx("div",{className:a.emptyState,children:t.jsx("p",{className:"tf-empty-copy",children:"Select an image attachment to annotate."})})})})]}),t.jsxs("div",{className:a.statusBar,children:[t.jsx("span",{children:Y==="error"?"Save failed. Retry now.":Y==="saving"||Y==="pending"?"Saving…":"Saved"}),ua?t.jsx("span",{children:ua}):t.jsx("span",{children:B?W&&ke?"Drag on the image to pan.":T==="select"?"Select a marker to edit it.":`Click on the image to place a ${T}.`:"Create a session to begin placing markers on this image."}),d&&!B&&an?t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn} ${a.toolbarButton}`,onClick:()=>{Ba()},disabled:V||pt,children:V?"Creating…":"Create one now"}):null]})]}),t.jsx("section",{className:`tf-surface-panel ${a.panel} ${a.detailPanel}`,children:B?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:a.panelHeader,children:[t.jsxs("div",{className:a.panelHeaderText,children:[t.jsx("div",{className:`tf-heading-card ${a.panelTitle}`,children:"Markers"}),t.jsxs("div",{className:"tf-text-secondary",children:[j.length," in this session"]})]}),t.jsxs("div",{className:a.sessionActions,children:[t.jsx("button",{type:"button",className:`tf-control-icon ${a.iconButton}`,onClick:()=>Ea("up"),disabled:!z||Xt<=0,"aria-label":"Move marker up",children:t.jsx(Kn,{size:16})}),t.jsx("button",{type:"button",className:`tf-control-icon ${a.iconButton}`,onClick:()=>Ea("down"),disabled:!z||Xt===-1||Xt>=j.length-1,"aria-label":"Move marker down",children:t.jsx(Xn,{size:16})})]})]}),t.jsx("div",{className:`tf-scrollbar ${a.annotationList}`,children:j.length===0?t.jsx("div",{className:a.detailEmpty,children:t.jsx("p",{className:"tf-empty-copy",children:"Add a marker on the image to begin."})}):j.map((e,n)=>{const o=ko[e.kind],i=wo[e.kind],c=`${i} ${n+1}`,h=So[e.markerType||ce],k=Ya.find(m=>m.value===(e.markerType||ce))?.label||"Review",u=S===e.id;return t.jsxs("div",{className:`tf-surface-elevated ${a.annotationCard} ${u?a.annotationCardActive:""}`,children:[t.jsx("button",{type:"button",className:a.annotationCardButton,onClick:()=>F(e.id),"aria-label":i,children:t.jsxs("div",{className:a.annotationMeta,children:[t.jsx("span",{className:`tf-heading-card ${a.annotationTitle}`,children:c}),t.jsx("span",{className:`tf-text-meta ${a.annotationKind}`,"aria-hidden":"true",children:t.jsx(o,{size:16})})]})}),u?t.jsxs("div",{className:a.annotationInstructionEditor,children:[t.jsx("label",{className:"tf-field-label",htmlFor:"annotated-marker-instruction",children:"Marker instruction"}),t.jsx("textarea",{id:"annotated-marker-instruction",ref:u?_a:null,className:`tf-field-shell ${a.textArea} ${a.annotationInstructionField}`,value:e.instruction,onChange:m=>{te(e.id,_=>({..._,instruction:m.target.value}),600)},onBlur:()=>{E("text")},placeholder:"What should the AI focus on for this marker?"}),t.jsxs("div",{className:a.annotationTypeField,children:[t.jsx("label",{className:"tf-field-label",htmlFor:"annotated-marker-type",children:"Instruction type"}),t.jsx("select",{id:"annotated-marker-type",className:`tf-field-shell ${a.select}`,value:e.markerType||ce,onChange:m=>{te(e.id,_=>Po(_,m.target.value))},children:Ya.map(m=>t.jsx("option",{value:m.value,children:m.label},m.value))})]})]}):t.jsx("button",{type:"button",className:a.annotationInstructionButton,onClick:()=>F(e.id),"aria-label":`Edit ${i} instruction`,children:t.jsxs("div",{className:a.annotationInstructionEditor,children:[t.jsx("div",{className:`tf-text-secondary ${a.annotationInstructionPreview}`,children:e.instruction.trim()||"No marker instruction yet."}),t.jsx("div",{className:a.annotationPreviewFooter,children:t.jsx("span",{className:`tf-text-meta ${a.annotationInstructionTypeIcon}`,"aria-label":`Instruction type: ${k}`,title:k,children:t.jsx(h,{size:16})})})]})})]},e.id)})})]}):t.jsxs("div",{className:a.emptyState,children:[t.jsx("strong",{className:"tf-empty-title",children:"No active session"}),t.jsx("p",{className:"tf-empty-copy",children:"Create or select a session to edit annotations."})]})}),t.jsx(aa,{isOpen:rn,onClose:()=>{qe||(xt(!1),vt(""))},title:"Open Image",size:"sm",children:t.jsxs("form",{className:a.openImageModalBody,onSubmit:e=>{e.preventDefault(),mn()},children:[t.jsx("label",{className:"tf-field-label",htmlFor:"annotated-open-image-reference",children:"Image reference number"}),t.jsx("input",{id:"annotated-open-image-reference",className:`tf-field-shell ${a.textInput} ${a.openImageField}`,value:Dt,onChange:e=>vt(e.target.value),placeholder:"I-24",autoFocus:!0}),t.jsxs("div",{className:a.openImageActions,children:[t.jsx("button",{type:"button",className:"tf-button-ghost tf-button-compact",onClick:()=>{xt(!1),vt("")},disabled:qe,children:"Cancel"}),t.jsx("button",{type:"submit",className:"tf-button-primary tf-button-compact",disabled:qe,children:qe?"Opening…":"Open"})]})]})}),t.jsx(aa,{isOpen:sn,onClose:()=>ha(!1),title:"How To Use Markers",size:"md",children:t.jsx("div",{className:a.markerHelpModalBody,children:Wa.filter(e=>e.value!=="select").map(e=>t.jsxs("div",{className:`tf-surface-inset ${a.markerHelpItem}`,children:[t.jsxs("div",{className:a.markerHelpHeader,children:[t.jsx("strong",{className:"tf-heading-card",children:e.label}),t.jsx("span",{className:"tf-text-meta",children:Rt[e.value].short})]}),t.jsx("p",{className:"tf-text-secondary",children:Rt[e.value].detail}),t.jsx("p",{className:`tf-text-body ${a.markerHelpExample}`,children:Rt[e.value].example})]},e.value))})}),t.jsx(aa,{isOpen:nn,onClose:()=>Lt(!1),title:"AI Payload",size:"lg",children:t.jsxs("div",{className:a.payloadModalBody,children:[t.jsxs("div",{className:a.payloadModalToolbar,children:[t.jsxs("div",{className:a.payloadViewToggle,children:[t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.toolBtn} ${Ft==="json"?a.toolBtnActive:""}`,onClick:()=>fa("json"),children:"JSON"}),t.jsx("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.toolBtn} ${Ft==="brief"?a.toolBtnActive:""}`,onClick:()=>fa("brief"),children:"AI Brief"})]}),t.jsxs("div",{className:a.payloadModalActions,children:[t.jsxs("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn}`,onClick:()=>{Ma("json")},disabled:!oe,"aria-label":de==="json"?"Copied JSON":"Copy JSON",title:de==="json"?"Copied JSON":"Copy JSON",children:[de==="json"?t.jsx(la,{size:16}):t.jsx(na,{size:16}),t.jsx("span",{children:"JSON"})]}),t.jsxs("button",{type:"button",className:`tf-button-ghost tf-button-compact ${a.ghostBtn}`,onClick:()=>{Ma("brief")},disabled:!oe,"aria-label":de==="brief"?"Copied AI Brief":"Copy AI Brief",title:de==="brief"?"Copied AI Brief":"Copy AI Brief",children:[de==="brief"?t.jsx(la,{size:16}):t.jsx(na,{size:16}),t.jsx("span",{children:"AI Brief"})]})]})]}),gt?t.jsx("div",{className:a.detailEmpty,children:t.jsx("p",{className:"tf-empty-copy",children:"Loading payload…"})}):oe?t.jsx("pre",{className:`tf-surface-inset tf-scrollbar ${a.payloadModalPreview}`,children:Ft==="json"?JSON.stringify(oe,null,2):Xa(oe)}):t.jsx("div",{className:a.detailEmpty,children:t.jsx("p",{className:"tf-empty-copy",children:"Load a payload preview to inspect the current session contract."})})]})})]})}export{Vo as AnnotatedAttachmentWorkspaceShell};
@@ -0,0 +1,3 @@
1
+ import{r as y,j as e}from"./vendor-react-CKJs5o3c.js";import{t as s,Z as Et,_ as pt,$ as dt,a0 as Lt}from"./index-MAHKvFqp.js";import{g as St}from"./documentReferences-BOUcJm6-.js";import{a as Dt,j as Pt,h as Ut,aJ as K,c as X,m as $t,aK as Ft,aF as ut,T as ht,au as Rt}from"./vendor-icons-B32hGuF2.js";import"./vendor-markdown-BUxTU7dS.js";import"./vendor-dnd-DRzYolkg.js";import"./vendor-router-BbWMxlnO.js";const gt=[".png",".jpg",".jpeg",".webp",".gif",".pdf",".txt",".md",".csv",".json",".doc",".docx",".html",".js",".ts",".tsx",".css",".py",".java",".go",".rs",".sh"].join(","),zt=new Set(["image/png","image/jpeg","image/webp"]),Ot=new Set(gt.split(",").map(o=>o.trim().toLowerCase())),_t=10*1024*1024,Bt=3500;function xt(o){const c=o.trim().toLowerCase(),m=c.lastIndexOf(".");return m===-1?"":c.slice(m)}function J(o){if(o.length===0)return"";const c=o.slice(0,3).join(", "),m=o.length-3;return m>0?`${c}, +${m} more`:c}function Mt(o){return`${o.name.trim().toLowerCase()}::${o.size}::${o.lastModified}`}function Ht(o){return new Promise((c,m)=>{const g=new FileReader;g.onload=()=>c(String(g.result||"")),g.onerror=()=>m(g.error||new Error("Failed to read file")),g.readAsDataURL(o)})}function S(o){return/\.(png|jpe?g|webp|gif)(\?|#|$)/i.test(o)}function Kt(o){const c=o.types;if(!c)return null;for(const m of Array.from(c)){const g=String(m||"").trim().toLowerCase();if(zt.has(g))return g}return null}function ft(o,c){const m=o.includes("?")?"&":"?";return`${o}${m}download=1&filename=${encodeURIComponent(c)}`}function mt(o){return typeof o=="string"?o.split("/").pop()||"Context file":o.displayName||o.originalFilename||o.caption||o.fsPath||o.path.split("/").pop()||"Context file"}function Xt(o){const c=typeof o=="string"?[o]:[o.originalFilename,o.displayName,o.caption,o.fsPath,o.path];for(const g of c){if(!g)continue;const D=xt(g);if(D)return D.replace(".","").slice(0,5).toUpperCase()}const m=typeof o=="string"?o:o.path;return/^https?:\/\//i.test(m)?"LINK":"FILE"}function te(o){const{ownerType:c="task",ownerId:m,ownerReferenceLabel:g,workspaceId:D,attachments:N,onAddAttachment:Y,onRemoveAttachment:G,onUpdateAttachmentCaption:W}=o,v=y.useRef(null),[P,Z]=y.useState(!1),[V,C]=y.useState(null),[F,q]=y.useState(""),[R,A]=y.useState(null),[I,j]=y.useState(null),[U,yt]=y.useState(!1),[wt,z]=y.useState(!1),[Jt,O]=y.useState(0),T=y.useRef(new Set),Q=y.useRef(new Set),tt=t=>(t||"").trim(),$=(t,n)=>{const a=[],r=tt(t),p=tt(n);return r&&a.push(`path:${r}`),p&&a.push(`fs:${p}`),a},et=y.useMemo(()=>{const t=new Set;return N.forEach(n=>{if(typeof n=="string"){$(n).forEach(a=>t.add(a));return}$(n.path,n.fsPath).forEach(a=>t.add(a))}),t},[N]);y.useEffect(()=>{T.current=new Set(et)},[et]);const nt=(t,n)=>n.some(a=>t.has(a)),at=(t,n)=>n.forEach(a=>t.add(a)),E=String(D||"").trim(),b=String(m||"").trim(),st=c==="initiative"?"initiative":c==="workstream"?"workstream":"task",_={ownerType:c,ownerId:b||null,taskId:c==="task"&&b||null},B=(t="application/json")=>{const n={"Content-Type":t};return E&&(n["x-taskforce-workspace-id"]=E),n},ot=(t,n=!0,a=T.current)=>{const r=t.trim();if(!r||!/^https?:\/\//i.test(r))return"invalid";const i=r,f=$(i);if(nt(a,f))return"duplicate";const u=r.split(/[\\/]/).pop()||r;return Y({path:i,caption:u,timestamp:new Date().toISOString()}),at(a,f),n&&q(""),A(null),"added"};y.useEffect(()=>{if(!I)return;const t=window.setTimeout(()=>{j(null)},Bt);return()=>window.clearTimeout(t)},[I]);const rt=async t=>{if(t.length===0)return;C(null),j(null);const n=t,a=[],r=[],p=[],i=[],f=new Set(Q.current);n.forEach(x=>{const h=xt(x.name);if(!Ot.has(h)){a.push(x.name);return}if(x.size>_t){r.push(x.name);return}const L=Mt(x);if(f.has(L)){p.push(x.name);return}f.add(L),i.push({file:x,fingerprint:L})});const u=[];if(a.length>0&&u.push(`${a.length} unsupported file${a.length===1?"":"s"} skipped: ${J(a)}.`),r.length>0&&u.push(`${r.length} file${r.length===1?"":"s"} over 10 MB skipped: ${J(r)}.`),p.length>0&&u.push(`${p.length} local duplicate file${p.length===1?"":"s"} skipped before upload: ${J(p)}.`),i.length===0){u.length>0&&j(u.join(" ")),v.current&&(v.current.value="");return}Z(!0);const k=new Set(T.current);let d=0;try{for(const{file:h,fingerprint:L}of i){let l=null;const lt=await fetch("/api/taskforce/context-upload/init",{method:"POST",headers:B(),body:JSON.stringify({originalName:h.name,mimeType:h.type||"application/octet-stream",size:h.size,..._,workspaceId:E||null})});if(lt.ok){const w=await lt.json();if(w?.success&&typeof w?.uploadUrl=="string"&&typeof w?.path=="string"){if(!(await fetch(w.uploadUrl,{method:String(w.method||"PUT"),headers:w.headers||{"Content-Type":h.type||"application/octet-stream"},body:h})).ok)throw new Error(`Upload failed for ${h.name}`);const H=await fetch("/api/taskforce/context-upload/finalize",{method:"POST",headers:B(),body:JSON.stringify({relativePath:w.relativePath,mimeType:h.type||"application/octet-stream",originalName:h.name,size:h.size,..._,workspaceId:E||null})});if(!H.ok){const Tt=await H.json().catch(()=>({}));throw new Error(Tt?.error||`Upload failed for ${h.name}`)}l=await H.json().catch(()=>null)}else w?.success&&typeof w?.path=="string"&&(l=w)}if(!l){const w=await Ht(h),M=await fetch("/api/taskforce/context-upload",{method:"POST",headers:B(),body:JSON.stringify({file:w,originalName:h.name,..._,workspaceId:E||null})});if(!M.ok)throw new Error(`Upload failed for ${h.name}`);l=await M.json()}if(!l?.success||!l?.path)throw new Error(`Upload failed for ${h.name}`);const ct=$(l.path,l.fsPath);if(nt(k,ct)){d+=1;continue}Y({path:l.path,fsPath:l.fsPath,caption:typeof l.caption=="string"&&l.caption.trim().length>0?l.caption:h.name,displayName:typeof l.displayName=="string"?l.displayName:void 0,originalFilename:typeof l.originalFilename=="string"?l.originalFilename:h.name,assetId:typeof l.assetId=="string"?l.assetId:void 0,referenceNumber:typeof l.referenceNumber=="number"?l.referenceNumber:null,referenceLabel:typeof l.referenceLabel=="string"?l.referenceLabel:void 0,taskId:c==="task"&&typeof l.taskId=="string"?l.taskId:null,timestamp:typeof l.timestamp=="string"&&l.timestamp.trim().length>0?l.timestamp:new Date().toISOString()}),Lt({workspaceId:E||"default",ownerType:c,ownerId:b||null,taskId:c==="task"&&b||null,reason:"upload"}),at(k,ct),Q.current.add(L)}const x=[...u];d>0&&x.push(`${d} duplicate file${d===1?"":"s"} skipped.`),j(x.length>0?x.join(" "):null),T.current=k}catch(x){C(x instanceof Error?x.message:"Failed to upload context file")}finally{Z(!1),v.current&&(v.current.value="")}},it=async t=>{!t||t.length===0||await rt(Array.from(t))},kt=async()=>{if(C(null),j(null),!navigator.clipboard||typeof navigator.clipboard.read!="function"){C("Clipboard image paste is not available in this browser.");return}try{const t=await navigator.clipboard.read(),n=[];for(const a of t){const r=Kt(a);if(!r)continue;const p=await a.getType(r),i=r.toLowerCase()==="image/png"?"png":r.toLowerCase()==="image/webp"?"webp":"jpg";n.push(new globalThis.File([p],`pasted-image-${Date.now()}.${i}`,{type:r}))}if(n.length===0){C("Clipboard does not currently contain a supported image.");return}await rt(n)}catch(t){C(t?.message||"Failed to read an image from the clipboard.")}},jt=t=>{const n=new Set,a=t.dataTransfer.getData("text/uri-list")||"",r=t.dataTransfer.getData("text/plain")||"",p=`${a}
2
+ ${r}`.split(`
3
+ `).map(i=>i.trim()).filter(i=>!!i&&!i.startsWith("#"));for(const i of p){if(/^file:\/\//i.test(i)){try{const f=new URL(i),u=decodeURIComponent(f.pathname||"").trim();u&&n.add(u)}catch{}continue}n.add(i)}return Array.from(n)},bt=t=>{if(t.preventDefault(),t.stopPropagation(),z(!1),O(0),C(null),A(null),j(null),t.dataTransfer.files&&t.dataTransfer.files.length>0){it(t.dataTransfer.files);return}const n=jt(t);if(n.length===0){A("Drop a file or URL.");return}const a=new Set(T.current);let r=0,p=0,i=0;n.forEach(u=>{const k=ot(u,!1,a);k==="duplicate"&&(r+=1),k==="added"&&(p+=1),k==="invalid"&&(i+=1)});const f=[];r>0&&f.push(`${r} duplicate link${r===1?"":"s"} skipped.`),i>0&&f.push(`${i} local path${i===1?"":"s"} skipped. Upload files to attach them, or drop an http(s) URL to link.`),j(f.length>0?f.join(" "):p>0?null:I),T.current=a},Nt=t=>{t.preventDefault(),t.stopPropagation(),O(n=>n+1),z(!0)},Ct=t=>{t.preventDefault(),t.stopPropagation(),O(n=>{const a=Math.max(0,n-1);return a===0&&z(!1),a})},vt=t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect="copy"},At=N.filter(t=>{const n=typeof t=="string"?t:t.path;return S(n)}),It=N.filter(t=>{const n=typeof t=="string"?t:t.path;return!S(n)});return e.jsxs("div",{className:s.specialistSection,children:[e.jsxs("div",{className:s.toggleHeading,onClick:()=>yt(!U),title:U?"Hide context documents":"Show context documents",children:[e.jsxs("label",{className:s.label,children:["Context Documents ",N.length>0&&`(${N.length})`]}),U?e.jsx(Dt,{size:14}):e.jsx(Pt,{size:14})]}),U&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:s.settingsHint,children:["Upload files into ",st," context storage, or add an external http(s) URL."]}),e.jsxs("div",{className:s.contextUploadPanel,children:[e.jsxs("div",{className:s.contextUploadActions,children:[e.jsxs("button",{type:"button",className:s.secondaryHeaderBtn,onClick:()=>v.current?.click(),disabled:P,children:[P?e.jsx(Ut,{size:12,className:s.spinner}):e.jsx(K,{size:12}),P?"Uploading...":"Upload File"]}),e.jsxs("button",{type:"button",className:s.secondaryHeaderBtn,onClick:()=>{kt()},disabled:P,children:[e.jsx(X,{size:12}),"Paste Image from Clipboard"]})]}),e.jsx("input",{ref:v,type:"file",accept:gt,multiple:!0,className:s.hiddenInput,onChange:t=>{it(t.target.files)}}),V&&e.jsx("div",{className:s.error,children:V}),e.jsxs("div",{className:s.contextLinkRow,children:[e.jsx("input",{type:"text",className:s.input,placeholder:"Add external URL (https://...)",value:F,onChange:t=>{q(t.target.value),R&&A(null),I&&j(null)}}),e.jsx("button",{type:"button",className:s.secondaryHeaderBtn,onClick:()=>{if(!F.trim()){A("Enter an http(s) URL to link.");return}const t=ot(F,!0);if(t==="invalid"){A("Only external http(s) URLs can be linked here. Upload files to attach them.");return}t==="duplicate"?j(`Link already exists in ${st} context.`):t==="added"&&j(null)},children:"Add URL"})]}),e.jsxs("div",{className:`${s.contextDropzone} ${wt?s.contextDropzoneActive:""}`,onDragEnter:Nt,onDragLeave:Ct,onDragOver:vt,onDrop:bt,children:[e.jsx(K,{size:14}),e.jsx("span",{children:"Drop files or URLs here"})]})]}),I&&e.jsx("div",{className:s.contextNotice,children:I}),R&&e.jsx("div",{className:s.error,children:R}),At.length>0&&e.jsx("div",{className:s.attachmentGrid,children:N.map((t,n)=>{const a=typeof t=="string"?t:t.path;if(!S(a))return null;const r=typeof t=="string"?void 0:t.fsPath,p=typeof t=="string"?"":t.caption||"",i=mt(t),f=S(a),u=/^https?:\/\//i.test(a),k=c==="task"&&Et(t);return e.jsxs("div",{className:s.attachmentCard,children:[e.jsxs("div",{className:s.attachmentPreviewContainer,children:[f?e.jsx("img",{src:a,alt:p||`Context file ${n}`,onClick:()=>{c==="task"&&pt(t,{taskId:b,taskReferenceLabel:g})||window.open(a,"_blank")},onError:d=>{d.target.style.display="none",d.target.parentElement.classList.add(s.brokenImage)}}):e.jsxs("button",{type:"button",className:s.contextFileLink,onClick:()=>{const d=c==="task"?typeof t=="string"?{path:t,taskId:b}:{...t,taskId:b}:t;dt(d,r)||window.open(a,"_blank")},title:"Open file",children:[e.jsx(K,{size:16}),e.jsx("span",{children:p||r||a.split("/").pop()||"Context file"})]}),e.jsxs("div",{className:s.brokenImagePlaceholder,children:[e.jsx($t,{size:16}),e.jsx("span",{children:"Preview unavailable"})]}),e.jsxs("div",{className:s.attachmentActions,children:[k&&e.jsx("button",{type:"button",className:s.attachmentActionBtn,onClick:d=>{d.stopPropagation(),pt(t,{taskId:b,taskReferenceLabel:g})},title:"Annotate",children:e.jsx(Ft,{size:12})}),r&&e.jsx("button",{type:"button",className:s.attachmentActionBtn,onClick:d=>{d.stopPropagation(),navigator.clipboard.writeText(r)},title:`Copy path: ${r}`,children:e.jsx(X,{size:12})}),!u&&e.jsx("button",{type:"button",className:s.attachmentActionBtn,onClick:d=>{d.stopPropagation(),window.open(ft(a,p||i),"_blank")},title:"Download",children:e.jsx(ut,{size:12})}),e.jsx("button",{type:"button",className:s.attachmentActionBtn,onClick:d=>{d.stopPropagation(),G(n)},title:"Delete",children:e.jsx(ht,{size:12})})]})]}),e.jsx("input",{type:"text",className:s.attachmentCaptionInput,placeholder:"Add a label...",value:p,onChange:d=>W(n,d.target.value)})]},n)})}),It.length>0&&e.jsx("div",{className:s.documentAttachmentList,children:N.map((t,n)=>{const a=typeof t=="string"?t:t.path;if(S(a))return null;const r=typeof t=="string"?void 0:t.fsPath,p=typeof t=="string"?"":t.caption||"",i=mt(t),f=Xt(t),u=typeof t=="string"?"":St(t),k=/^https?:\/\//i.test(a);return e.jsxs("div",{className:s.documentAttachmentItem,children:[e.jsxs("div",{className:s.documentAttachmentRow,children:[e.jsxs("button",{type:"button",className:s.documentAttachmentLink,onClick:()=>{const d=c==="task"?typeof t=="string"?{path:t,taskId:b}:{...t,taskId:b}:t;dt(d,r)||window.open(a,"_blank")},title:i,children:[e.jsxs("span",{className:s.documentAttachmentMain,children:[e.jsx("span",{className:s.documentAttachmentIcon,"aria-hidden":"true",children:e.jsx(Rt,{size:13})}),e.jsxs("span",{className:s.documentAttachmentText,children:[e.jsx("span",{className:s.documentAttachmentName,children:i}),u&&e.jsx("span",{className:s.taskIdBadge,children:u})]})]}),e.jsx("span",{className:s.documentAttachmentType,children:f})]}),e.jsxs("div",{className:s.documentAttachmentActions,children:[r&&e.jsx("button",{type:"button",className:s.documentAttachmentActionBtn,onClick:()=>{navigator.clipboard.writeText(r)},title:`Copy path: ${r}`,children:e.jsx(X,{size:12})}),!k&&e.jsx("button",{type:"button",className:s.documentAttachmentActionBtn,onClick:()=>{window.open(ft(a,p||i),"_blank")},title:"Download",children:e.jsx(ut,{size:12})}),e.jsx("button",{type:"button",className:s.documentAttachmentActionBtn,onClick:()=>G(n),title:"Delete",children:e.jsx(ht,{size:12})})]})]}),e.jsx("input",{type:"text",className:s.documentAttachmentCaptionInput,placeholder:"Add a label...",value:p,onChange:d=>W(n,d.target.value)})]},n)})})]})]})}export{te as ContextAttachmentManager};
@@ -0,0 +1,252 @@
1
+ import{j as e,r as i,s as an,R as ve}from"./vendor-react-CKJs5o3c.js";import{h as $e,f as P,t as L,i as yt,j as gt,k as sn,R as rn,m as M,M as on,n as xt,o as cn,q as ln}from"./index-MAHKvFqp.js";import{q as dn,w as un,v as mn,au as hn,av as pn,x as qe,i as fn,Z as Qe,X as Rt,aw as _t,e as Ye,ax as At,ay as vn,az as wn,a as kn,j as yn,aA as gn,aB as xn,aC as _n,t as Ee,aD as bn,r as Sn,p as jn,aE as bt,at as Ve,aF as Cn,aG as Nn,T as Tn,R as En,aH as Rn,B as An,U as In,S as $n}from"./vendor-icons-B32hGuF2.js";import{g as Ln}from"./documentReferences-BOUcJm6-.js";import{s as Dn,M as Re,r as Ae}from"./vendor-markdown-BUxTU7dS.js";import"./vendor-dnd-DRzYolkg.js";import"./vendor-router-BbWMxlnO.js";const Bn="_index_1sp0v_1",Mn="_header_1sp0v_8",Pn="_title_1sp0v_23",zn="_search_1sp0v_35",Fn="_searchIcon_1sp0v_41",On="_searchInput_1sp0v_50",Hn="_list_1sp0v_67",Wn="_state_1sp0v_79",Gn="_stateError_1sp0v_87",Kn="_item_1sp0v_94",Un="_itemActive_1sp0v_116",Jn="_itemIcon_1sp0v_126",Vn="_itemBody_1sp0v_136",qn="_itemTitle_1sp0v_144",Qn="_itemTask_1sp0v_156",Yn="_itemBadge_1sp0v_167",Xn="_itemMeta_1sp0v_180",Zn="_itemMetaDetails_1sp0v_191",ea="_itemMetaReference_1sp0v_198",A={index:Bn,header:Mn,title:Pn,search:zn,searchIcon:Fn,searchInput:On,list:Hn,state:Wn,stateError:Gn,item:Kn,itemActive:Un,itemIcon:Jn,itemBody:Vn,itemTitle:qn,itemTask:Qn,itemBadge:Yn,itemMeta:Xn,itemMetaDetails:Zn,itemMetaReference:ea};function Xe(t){let l=t;try{l=decodeURIComponent(t)}catch{l=t}return l.trim().replace(/\\/g,"/").replace(/^\/+/,"").replace(/^\.\//,"").replace(/^\.taskforce\//,"")}function ta(t,l){return!!(t===l||t.endsWith(`/${l}`)||l.endsWith(`/${t}`))}function St(t){const l=Xe(String(t||""));if(!l)return null;const m=l.match(/(^|\/)(asset-[a-f0-9]{32})(?=[^/]*$)/i);return m?.[2]?m[2].toLowerCase():null}function et(t){return t.attachmentState==="attached"||t.attachmentState==="unattached"?t.attachmentState:(typeof t.attachmentCount=="number"&&Number.isFinite(t.attachmentCount)?t.attachmentCount:0)>0||t.taskId?"attached":"unattached"}function na(t,l,m,s){const c=l.trim().toLowerCase();return t.filter(u=>{const y=`${$e(u)} ${u.originalFilename||""}`.toLowerCase(),v=c.length===0||y.includes(c),b=m.length===0||m.includes(u.docType),h=et(u),g=s.length===0||s.includes(h);return v&&b&&g})}function aa({docType:t}){switch(t){case"implementation-plan":return e.jsx(fn,{size:13});case"review":return e.jsx(qe,{size:13});case"walkthrough":return e.jsx(pn,{size:13});default:return e.jsx(hn,{size:13})}}function sa(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/(1024*1024)).toFixed(1)}MB`}function ra(t){if(!t)return"";const l=new Date(t),s=new Date().getTime()-l.getTime(),c=Math.floor(s/(1e3*60*60*24));return c===0?"Today":c===1?"Yesterday":c<7?`${c}d ago`:c<30?`${Math.floor(c/7)}w ago`:l.toLocaleDateString()}function ia(t,l){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),l())}function oa({documents:t,selectedDocId:l,loading:m,error:s,searchQuery:c,taskById:u,onSearchChange:w,onSelect:y,onCloseTray:v,hasActiveFilters:b}){return e.jsxs("div",{className:A.index,children:[e.jsxs("div",{className:A.header,children:[e.jsxs("span",{className:A.title,children:[e.jsx(dn,{size:14}),"Documents"]}),v?e.jsx("button",{type:"button",className:"tf-control-icon",onClick:v,title:"Collapse document tray","aria-label":"Collapse document tray",children:e.jsx(un,{size:16})}):null]}),e.jsxs("div",{className:A.search,children:[e.jsx(mn,{size:12,className:A.searchIcon}),e.jsx("input",{type:"text",placeholder:"Search documents…",value:c,onChange:h=>w(h.target.value),className:A.searchInput})]}),e.jsxs("div",{className:`${A.list} tf-scrollbar`,children:[m&&e.jsx("div",{className:A.state,children:"Loading documents…"}),!m&&s&&e.jsx("div",{className:A.stateError,children:s}),!m&&!s&&t.length===0&&e.jsx("div",{className:A.state,children:b?"No documents match your filters.":"No documents found. Documents added as task attachments will appear here."}),!m&&t.map(h=>{const g=h.taskId?u.get(h.taskId):null,O=h.id===l,T=$e(h),C=et(h),D=typeof h.attachmentCount=="number"&&Number.isFinite(h.attachmentCount)?h.attachmentCount:h.taskId?1:0,E=D>1?`${D} tasks linked`:D===1?g?.title||"1 task linked":null;return e.jsxs("div",{role:"button",tabIndex:0,className:`${A.item} ${O?A.itemActive:""}`,onClick:()=>y(h),onKeyDown:I=>ia(I,()=>y(h)),children:[e.jsx("div",{className:A.itemIcon,children:e.jsx(aa,{docType:h.docType})}),e.jsxs("div",{className:A.itemBody,children:[e.jsx("span",{className:A.itemTitle,title:T,children:T}),C==="unattached"&&e.jsx("span",{className:A.itemBadge,children:"Unattached"}),E&&e.jsx("span",{className:A.itemTask,title:E,children:E}),e.jsxs("span",{className:A.itemMeta,children:[e.jsxs("span",{className:A.itemMetaDetails,children:[sa(h.sizeBytes),h.updatedAt&&e.jsxs(e.Fragment,{children:[" · ",ra(h.updatedAt)]})]}),h.referenceLabel&&e.jsx("span",{className:A.itemMetaReference,children:h.referenceLabel})]})]})]},h.id)})]})]})}function Ie(t){return function(l){return Dn(l,t)}}const ca="_viewer_v1pk0_1",la="_viewerMonochrome_v1pk0_10",da="_metaDocumentName_v1pk0_10",ua="_viewerEditMode_v1pk0_14",ma="_meta_v1pk0_10",ha="_metaLeft_v1pk0_30",pa="_metaRenameRow_v1pk0_49",fa="_typeBadge_v1pk0_56",va="_typeBadgeImplementationPlan_v1pk0_71",wa="_typeBadgeReview_v1pk0_77",ka="_typeBadgeWalkthrough_v1pk0_83",ya="_metaTaskName_v1pk0_89",ga="_statusBadge_v1pk0_98",xa="_metaDate_v1pk0_113",_a="_metaSize_v1pk0_114",ba="_actions_v1pk0_122",Sa="_actionBtn_v1pk0_129",ja="_dangerBtn_v1pk0_156",Ca="_generateBtn_v1pk0_167",Na="_editBtn_v1pk0_178",Ta="_saveBtn_v1pk0_189",Ea="_layoutToggle_v1pk0_205",Ra="_layoutBtn_v1pk0_213",Aa="_layoutBtnActive_v1pk0_229",Ia="_saveStatus_v1pk0_234",$a="_saveStatusSaved_v1pk0_241",La="_saveStatusError_v1pk0_245",Da="_unsaved_v1pk0_250",Ba="_viewerContent_v1pk0_256",Ma="_viewerBody_v1pk0_265",Pa="_viewerBodyFullWidth_v1pk0_273",za="_viewerMain_v1pk0_277",Fa="_reviewRail_v1pk0_285",Oa="_printHint_v1pk0_291",Ha="_reviewSection_v1pk0_298",Wa="_reviewHeader_v1pk0_307",Ga="_reviewTitle_v1pk0_315",Ka="_reviewSubtitle_v1pk0_324",Ua="_reviewControls_v1pk0_331",Ja="_reviewSelect_v1pk0_338",Va="_reviewSessionMeta_v1pk0_342",qa="_reviewStatusResolved_v1pk0_350",Qa="_reviewSessionLabel_v1pk0_356",Ya="_reviewTitleEditRow_v1pk0_361",Xa="_reviewSessionTimestamp_v1pk0_368",Za="_reviewAnchorLabel_v1pk0_372",es="_reviewComposer_v1pk0_378",ts="_reviewAnchorChip_v1pk0_385",ns="_reviewAnchorSnippet_v1pk0_398",as="_reviewAnchorClear_v1pk0_403",ss="_reviewCommentActions_v1pk0_416",rs="_reviewCommentAction_v1pk0_416",is="_reviewCommentEditor_v1pk0_437",os="_viewerState_v1pk0_443",cs="_viewerStateError_v1pk0_450",ls="_editorArea_v1pk0_457",ds="_editorPane_v1pk0_464",us="_editorLayoutSplit_v1pk0_472",ms="_previewPane_v1pk0_473",hs="_editorLayoutEditor_v1pk0_477",ps="_editorLayoutPreview_v1pk0_478",fs="_editorPaneLabel_v1pk0_482",vs="_editorTextarea_v1pk0_494",ws="_markdownSurface_v1pk0_536",ks="_attachModalBody_v1pk0_745",ys="_attachModalCopy_v1pk0_752",gs="_attachModalError_v1pk0_759",xs="_attachTaskList_v1pk0_772",_s="_attachTaskRow_v1pk0_781",bs="_attachTaskTitle_v1pk0_808",Ss="_attachTaskInfo_v1pk0_814",js="_attachTaskReference_v1pk0_822",Cs="_attachTaskMeta_v1pk0_829",Ns="_attachEmptyState_v1pk0_836",r={viewer:ca,viewerMonochrome:la,metaDocumentName:da,viewerEditMode:ua,meta:ma,metaLeft:ha,metaRenameRow:pa,typeBadge:fa,typeBadgeImplementationPlan:va,typeBadgeReview:wa,typeBadgeWalkthrough:ka,metaTaskName:ya,statusBadge:ga,metaDate:xa,metaSize:_a,actions:ba,actionBtn:Sa,dangerBtn:ja,generateBtn:Ca,editBtn:Na,saveBtn:Ta,layoutToggle:Ea,layoutBtn:Ra,layoutBtnActive:Aa,saveStatus:Ia,saveStatusSaved:$a,saveStatusError:La,unsaved:Da,viewerContent:Ba,viewerBody:Ma,viewerBodyFullWidth:Pa,viewerMain:za,reviewRail:Fa,printHint:Oa,reviewSection:Ha,reviewHeader:Wa,reviewTitle:Ga,reviewSubtitle:Ka,reviewControls:Ua,reviewSelect:Ja,reviewSessionMeta:Va,reviewStatusResolved:qa,reviewSessionLabel:Qa,reviewTitleEditRow:Ya,reviewSessionTimestamp:Xa,reviewAnchorLabel:Za,reviewComposer:es,reviewAnchorChip:ts,reviewAnchorSnippet:ns,reviewAnchorClear:as,reviewCommentActions:ss,reviewCommentAction:rs,reviewCommentEditor:is,viewerState:os,viewerStateError:cs,editorArea:ls,editorPane:ds,editorLayoutSplit:us,previewPane:ms,editorLayoutEditor:hs,editorLayoutPreview:ps,editorPaneLabel:fs,editorTextarea:vs,markdownSurface:ws,attachModalBody:ks,attachModalCopy:ys,attachModalError:gs,attachTaskList:xs,attachTaskRow:_s,attachTaskTitle:bs,attachTaskInfo:Ss,attachTaskReference:js,attachTaskMeta:Cs,attachEmptyState:Ns},Ts="_overlay_1unik_1",Es="_modal_1unik_12",Rs="_header_1unik_16",As="_title_1unik_20",Is="_docName_1unik_24",$s="_body_1unik_34",Ls="_state_1unik_41",Ds="_stateError_1unik_52",Bs="_stateDone_1unik_63",Ms="_toolbar_1unik_84",Ps="_toolbarCount_1unik_95",zs="_toolbarActions_1unik_100",Fs="_tree_1unik_105",Os="_taskRow_1unik_113",Hs="_taskRowDimmed_1unik_126",Ws="_taskCheck_1unik_130",Gs="_taskExpandBtn_1unik_139",Ks="_taskExpandSpacer_1unik_155",Us="_taskTitle_1unik_160",Js="_taskBadge_1unik_169",Vs="_footer_1unik_179",S={overlay:Ts,modal:Es,header:Rs,title:As,docName:Is,body:$s,state:Ls,stateError:Ds,stateDone:Bs,toolbar:Ms,toolbarCount:Ps,toolbarActions:zs,tree:Fs,taskRow:Os,taskRowDimmed:Hs,taskCheck:Ws,taskExpandBtn:Gs,taskExpandSpacer:Ks,taskTitle:Us,taskBadge:Js,footer:Vs},qs={1:"Low",2:"Medium",3:"High"};function we(t,l){return t.map(m=>({...m,selected:l,children:we(m.children,l)}))}function It(t,l,m){return t.map(s=>s.idempotencyKey===l?{...s,selected:m,children:we(s.children,m)}:{...s,children:It(s.children,l,m)})}function Ze(t){let l=0;for(const m of t)m.selected&&l++,l+=Ze(m.children);return l}function $t({node:t,depth:l,onToggle:m}){const[s,c]=i.useState(!0),u=t.children.length>0,w=l*20;return e.jsxs("div",{children:[e.jsxs("div",{className:`${S.taskRow} ${t.selected?"":S.taskRowDimmed}`,style:{paddingLeft:`${12+w}px`},children:[e.jsx("button",{className:S.taskCheck,onClick:()=>m(t.idempotencyKey,!t.selected),title:t.selected?"Deselect":"Select",children:t.selected?e.jsx(vn,{size:14,style:{color:"var(--brand-primary-strong)"}}):e.jsx(wn,{size:14,style:{color:"var(--text-muted)"}})}),u?e.jsx("button",{className:S.taskExpandBtn,onClick:()=>c(y=>!y),children:s?e.jsx(kn,{size:12}):e.jsx(yn,{size:12})}):e.jsx("span",{className:S.taskExpandSpacer}),e.jsx("span",{className:S.taskTitle,title:t.description||void 0,children:t.title}),e.jsx("span",{className:S.taskBadge,style:{color:yt(t.type),borderColor:yt(t.type)},children:t.type}),e.jsx("span",{className:S.taskBadge,style:{color:gt(t.priority),borderColor:gt(t.priority)},children:qs[t.priority]})]}),u&&s&&e.jsx("div",{children:t.children.map(y=>e.jsx($t,{node:y,depth:l+1,onToggle:m},y.idempotencyKey))})]})}function Qs({content:t,docTitle:l,apiBaseUrl:m="",onClose:s,onGenerated:c}){const[u,w]=i.useState("preview"),[y,v]=i.useState(null),[b,h]=i.useState([]),[g,O]=i.useState(!0),[T,C]=i.useState(0),[D,E]=i.useState(null);i.useEffect(()=>{let x=!1;return O(!0),v(null),P("/api/taskforce/documents/generate-tasks/preview",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})},m).then(j=>j.json()).then(j=>{if(!x){if(j.error)throw new Error(j.error);h(j.tasks||[]),w("preview")}}).catch(j=>{x||(v(j?.message||"Failed to parse plan"),w("error"))}).finally(()=>{x||O(!1)}),()=>{x=!0}},[t,m]);const I=i.useCallback((x,j)=>{h(F=>It(F,x,j))},[]),z=()=>h(x=>we(x,!0)),H=()=>h(x=>we(x,!1)),q=Ze(b),Q=async()=>{w("generating"),E(null);try{const x=await P("/api/taskforce/documents/generate-tasks/commit",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({tasks:b})},m),j=await x.json().catch(()=>({}));if(!x.ok)throw new Error(j.error||`Generation failed (${x.status})`);C(j.created??0),w("done"),c(j.created??0)}catch(x){E(x?.message||"Generation failed"),w("error")}};return e.jsx("div",{className:S.overlay,onClick:x=>{x.target===x.currentTarget&&s()},children:e.jsxs("div",{className:`tf-surface-modal tf-modal-shell ${S.modal}`,children:[e.jsxs("div",{className:`tf-modal-header ${S.header}`,children:[e.jsxs("div",{className:`tf-modal-title ${S.title}`,children:[e.jsx(Qe,{size:16,style:{color:"var(--brand-primary-strong)"}}),"Generate Tasks from Plan"]}),e.jsx("span",{className:S.docName,children:l}),e.jsx("button",{className:"tf-control-icon",onClick:s,title:"Close",children:e.jsx(Rt,{size:16})})]}),e.jsxs("div",{className:S.body,children:[g&&e.jsxs("div",{className:S.state,children:[e.jsx(_t,{size:20,className:L.docSpinning}),"Parsing plan…"]}),!g&&u==="error"&&e.jsxs("div",{className:S.stateError,children:[e.jsx(Ye,{size:16}),y||D||"An error occurred"]}),!g&&u==="done"&&e.jsxs("div",{className:S.stateDone,children:[e.jsx(At,{size:24,style:{color:"var(--status-success)"}}),e.jsxs("strong",{children:[T," task",T!==1?"s":""," created"]}),e.jsx("p",{children:"Tasks are now in your board. Switch to the Kanban or Hierarchy view to see them."})]}),!g&&(u==="preview"||u==="confirm"||u==="generating")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:S.toolbar,children:[e.jsxs("span",{className:S.toolbarCount,children:[q," of ",Ze(we(b,!0))," tasks selected"]}),e.jsxs("div",{className:S.toolbarActions,children:[e.jsx("button",{className:"tf-control-icon",onClick:z,children:"Select all"}),e.jsx("button",{className:"tf-control-icon",onClick:H,children:"Deselect all"})]})]}),b.length===0?e.jsx("div",{className:S.state,children:"No tasks could be parsed from this document. Make sure the document uses ## H2 headings for phases and bullet points for tasks."}):e.jsx("div",{className:`${S.tree} tf-scrollbar`,children:b.map(x=>e.jsx($t,{node:x,depth:0,onToggle:I},x.idempotencyKey))})]})]}),!g&&u!=="done"&&u!=="error"&&e.jsxs("div",{className:S.footer,children:[e.jsx("button",{className:"tf-button-secondary",onClick:s,children:"Cancel"}),e.jsx("button",{className:"tf-button-primary",onClick:Q,disabled:q===0||u==="generating",children:u==="generating"?e.jsxs(e.Fragment,{children:[e.jsx(_t,{size:13,className:L.docSpinning})," Generating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:13})," Generate ",q," task",q!==1?"s":""]})})]}),!g&&u==="done"&&e.jsx("div",{className:S.footer,children:e.jsx("button",{className:"tf-button-primary",onClick:s,children:"Done"})})]})})}const Ys={"implementation-plan":"Implementation Plan",review:"Review",walkthrough:"Walkthrough",planning:"Planning",other:"Document"},Xs={"implementation-plan":r.typeBadgeImplementationPlan,review:r.typeBadgeReview,walkthrough:r.typeBadgeWalkthrough,planning:void 0,other:void 0},Zs={editor:r.editorLayoutEditor,split:r.editorLayoutSplit,preview:r.editorLayoutPreview},er=1500,tr=`
2
+ @page {
3
+ margin: 0.94in 1.02in 1in;
4
+ }
5
+
6
+ html,
7
+ body {
8
+ margin: 0;
9
+ padding: 0;
10
+ background: #fff;
11
+ color: #111;
12
+ -webkit-print-color-adjust: exact;
13
+ print-color-adjust: exact;
14
+ }
15
+
16
+ body {
17
+ font: 12.15pt/1.66 Georgia, "Times New Roman", Times, serif;
18
+ letter-spacing: 0;
19
+ text-rendering: optimizeLegibility;
20
+ }
21
+
22
+ .tf-print-document {
23
+ max-width: 5.95in;
24
+ margin: 0 auto;
25
+ overflow: visible;
26
+ color: #171717;
27
+ }
28
+
29
+ .tf-print-document > :first-child {
30
+ margin-top: 0;
31
+ }
32
+
33
+ .tf-print-document > :last-child {
34
+ margin-bottom: 0;
35
+ }
36
+
37
+ .tf-print-document h1,
38
+ .tf-print-document h2,
39
+ .tf-print-document h3,
40
+ .tf-print-document h4 {
41
+ font-family: "Helvetica Neue", "Arial Nova", Arial, sans-serif;
42
+ color: #101010;
43
+ font-weight: 700;
44
+ line-height: 1.08;
45
+ letter-spacing: -0.03em;
46
+ break-after: avoid-page;
47
+ page-break-after: avoid;
48
+ }
49
+
50
+ .tf-print-document h1 {
51
+ font-size: 32pt;
52
+ font-weight: 800;
53
+ line-height: 0.98;
54
+ letter-spacing: -0.055em;
55
+ margin: 0 0 1.18em;
56
+ padding: 0 0 0.38em;
57
+ border-bottom: 2px solid #d8d8d8;
58
+ max-width: 84%;
59
+ }
60
+
61
+ .tf-print-document h1 + p,
62
+ .tf-print-document h1 + ul,
63
+ .tf-print-document h1 + ol {
64
+ margin-top: 0.4em;
65
+ }
66
+
67
+ .tf-print-document h2,
68
+ .tf-print-document h3,
69
+ .tf-print-document h4 {
70
+ margin-bottom: 0.28em;
71
+ }
72
+
73
+ .tf-print-document h2 {
74
+ font-size: 16.5pt;
75
+ font-weight: 750;
76
+ margin-top: 2.2em;
77
+ padding-bottom: 0.22em;
78
+ border-bottom: 1px solid #dfdfdf;
79
+ }
80
+
81
+ .tf-print-document h3 {
82
+ font-size: 13.3pt;
83
+ font-weight: 700;
84
+ margin-top: 1.48em;
85
+ }
86
+
87
+ .tf-print-document h4 {
88
+ font-size: 11.2pt;
89
+ font-weight: 700;
90
+ margin-top: 1.14em;
91
+ text-transform: uppercase;
92
+ letter-spacing: 0.08em;
93
+ }
94
+
95
+ .tf-print-document p,
96
+ .tf-print-document ul,
97
+ .tf-print-document ol,
98
+ .tf-print-document blockquote,
99
+ .tf-print-document table,
100
+ .tf-print-document pre,
101
+ .tf-print-document hr {
102
+ margin: 0.78em 0;
103
+ }
104
+
105
+ .tf-print-document ul,
106
+ .tf-print-document ol {
107
+ padding-left: 1.1em;
108
+ }
109
+
110
+ .tf-print-document li {
111
+ margin: 0.24em 0;
112
+ padding-left: 0.1em;
113
+ }
114
+
115
+ .tf-print-document li > ul,
116
+ .tf-print-document li > ol {
117
+ margin-top: 0.34em;
118
+ margin-bottom: 0.2em;
119
+ }
120
+
121
+ .tf-print-document a {
122
+ color: #121212;
123
+ text-decoration: underline;
124
+ text-underline-offset: 2px;
125
+ text-decoration-thickness: 0.65px;
126
+ }
127
+
128
+ .tf-print-document code {
129
+ font-family: "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", monospace;
130
+ font-size: 0.78em;
131
+ background: transparent;
132
+ color: #4a4a4a;
133
+ border: 0;
134
+ padding: 0;
135
+ border-radius: 0;
136
+ overflow-wrap: anywhere;
137
+ }
138
+
139
+ .tf-print-section-label {
140
+ font-family: "Helvetica Neue", "Arial Nova", Arial, sans-serif;
141
+ font-size: 10.7pt;
142
+ font-weight: 700;
143
+ line-height: 1.18;
144
+ letter-spacing: 0.12em;
145
+ text-transform: uppercase;
146
+ color: #191919;
147
+ margin-top: 2.2em;
148
+ margin-bottom: 0.58em;
149
+ padding-bottom: 0;
150
+ border-bottom: 0;
151
+ break-after: avoid-page;
152
+ page-break-after: avoid;
153
+ }
154
+
155
+ .tf-print-section-label strong {
156
+ font-weight: inherit;
157
+ }
158
+
159
+ .tf-print-document pre {
160
+ background: #fafafa;
161
+ border: 1px solid #e1e1e1;
162
+ border-radius: 6px;
163
+ padding: 10pt 11pt;
164
+ overflow: visible;
165
+ white-space: pre-wrap;
166
+ word-break: break-word;
167
+ break-inside: avoid-page;
168
+ page-break-inside: avoid;
169
+ }
170
+
171
+ .tf-print-document pre code {
172
+ background: transparent;
173
+ padding: 0;
174
+ border-radius: 0;
175
+ white-space: inherit;
176
+ word-break: inherit;
177
+ }
178
+
179
+ .tf-print-document blockquote {
180
+ border-left: 2px solid #9f9f9f;
181
+ color: #434343;
182
+ margin-left: 0;
183
+ padding-left: 9pt;
184
+ font-style: italic;
185
+ }
186
+
187
+ .tf-print-document table {
188
+ width: 100%;
189
+ border-collapse: collapse;
190
+ table-layout: fixed;
191
+ break-inside: auto;
192
+ page-break-inside: auto;
193
+ }
194
+
195
+ .tf-print-document thead {
196
+ display: table-header-group;
197
+ }
198
+
199
+ .tf-print-document tr {
200
+ break-inside: avoid-page;
201
+ page-break-inside: avoid;
202
+ }
203
+
204
+ .tf-print-document th,
205
+ .tf-print-document td {
206
+ border: 1px solid #dbdbdb;
207
+ padding: 6.5pt 7.5pt;
208
+ text-align: left;
209
+ vertical-align: top;
210
+ word-break: break-word;
211
+ background: #fff;
212
+ }
213
+
214
+ .tf-print-document th {
215
+ background: #f7f7f7;
216
+ color: #1e1e1e;
217
+ font-size: 9.4pt;
218
+ font-weight: 680;
219
+ letter-spacing: 0.018em;
220
+ text-transform: uppercase;
221
+ }
222
+
223
+ .tf-print-document hr {
224
+ border: 0;
225
+ border-top: 1px solid #e1e1e1;
226
+ }
227
+
228
+ .tf-print-document img {
229
+ max-width: 100%;
230
+ height: auto;
231
+ break-inside: avoid-page;
232
+ page-break-inside: avoid;
233
+ }
234
+
235
+ .tf-print-document input[type="checkbox"] {
236
+ accent-color: #111;
237
+ margin-right: 0.45em;
238
+ }
239
+ `;function nr(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function jt(t){return t?new Date(t).toLocaleString():"—"}function ar(){const t=s=>!s||!Array.isArray(s.children)?!1:s.children.some(c=>c?c.type==="element"&&c.tagName==="input"&&c.properties?.type==="checkbox"?!0:t(c):!1),l=s=>!s||!Array.isArray(s.children)?!1:s.children.some(c=>typeof c?.checked=="boolean"?!0:t(c)),m=s=>{const c=ve.Children.toArray(s).filter(v=>typeof v!="string"?!0:v.trim().length>0);if(c.length!==1)return null;const u=c[0];if(!ve.isValidElement(u)||u.type!=="strong")return null;const w=u.props,y=ve.Children.toArray(w.children).join("").trim();return y||null};return{input({type:s,checked:c,...u}){return s!=="checkbox"?e.jsx("input",{type:s,checked:c,...u}):e.jsx("input",{...u,type:"checkbox",checked:!!c,disabled:!0,readOnly:!0})},ul({children:s,node:c,...u}){const w=l(c);return e.jsx("ul",{...u,style:w?{paddingLeft:"1.2em"}:void 0,children:s})},ol({children:s,node:c,...u}){const w=l(c);return e.jsx("ol",{...u,style:w?{paddingLeft:"1.2em"}:void 0,children:s})},li({children:s,node:c,...u}){const w=typeof c?.checked=="boolean"||t(c);return e.jsx("li",{...u,style:w?{listStyleType:"none",listStyle:"none",marginLeft:0}:void 0,children:s})},p({children:s,...c}){const u=m(s);return u?e.jsx("p",{...c,className:"tf-print-section-label",children:u}):e.jsx("p",{...c,children:s})}}}function sr(t){const l=an.renderToStaticMarkup(e.jsx("div",{className:"tf-print-document",children:e.jsx(Re,{remarkPlugins:[Ae],rehypePlugins:[Ie],components:ar(),children:t})}));return`<!doctype html>
240
+ <html lang="en">
241
+ <head>
242
+ <meta charset="utf-8" />
243
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
244
+ <title>Taskforce print document</title>
245
+ <style>${tr}</style>
246
+ </head>
247
+ <body>${l}</body>
248
+ </html>`}async function rr(t,l){try{await l.fonts?.ready}catch{}await new Promise(m=>{const s=t.requestAnimationFrame?.bind(t)??(c=>window.setTimeout(()=>c(0),0));s(()=>s(()=>m()))})}function ir(t){return window.setTimeout(t,er)}function Ct(t){try{return new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return t}}function Nt(t){return t?t.kind==="document"?"Entire document":t.kind==="quote"?t.quote?`Quote: "${t.quote}"`:"Quoted text":t.kind==="line-range"?t.startLine===t.endLine?`Line ${t.startLine}`:`Lines ${t.startLine}-${t.endLine}`:null:null}function or(t){return t.authorActor?.label?t.authorActor.label:t.authorActorId==="user"||t.authorActorId==="human"?"You":t.authorActorId?t.authorActorId:"Reviewer"}function Tt(t){return t.replace(/\s+/g," ").trim()}function cr(t,l){if(!l)return 0;let m=0,s=0;for(;s>=0&&(s=t.indexOf(l,s),!(s<0));)m+=1,s+=l.length;return m}function lr(t,l,m){const s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);let c=s.nextNode(),u=0;for(;c;){const w=c.textContent||"";if(c===l)return u+Math.max(0,Math.min(m,w.length));u+=w.length,c=s.nextNode()}return null}function dr(t,l,m){const s=m.replace(/\s+/g," ").trim();if(!s)return null;const c=t.textContent||"",u=Tt(c),w=[];let y=u.indexOf(s);for(;y>=0;)w.push(y),y=u.indexOf(s,y+s.length);let v=null;const b=lr(t,l.startContainer,l.startOffset);if(b!==null){const C=Tt(c.slice(0,b));v=cr(C,s)}const h=v!==null&&v>=0&&v<w.length?v:w.length===1?0:null,g=h!==null?w[h]:w[0]??-1;if(g<0)return{kind:"quote",quote:s,occurrenceIndex:v};const O=u.slice(Math.max(0,g-40),g).trim()||null,T=u.slice(g+s.length,g+s.length+40).trim()||null;return{kind:"quote",quote:s,occurrenceIndex:h,prefix:O,suffix:T}}function ur(t,l,m){if(l<0)return t;const s=t.split(`
249
+ `);let c=-1;const u=/^(\s*(?:[-*+]|\d+\.)\s+)\[( |x|X)\](.*)$/,w=m?"x":" ";return s.map(v=>{const b=v.match(u);return!b||(c+=1,c!==l)?v:`${b[1]}[${w}]${b[3]}`}).join(`
250
+ `)}function mr({doc:t,taskTitle:l,tasks:m=[],apiBaseUrl:s="",onSaved:c,onDeleted:u,onBackToTask:w,enableTaskGeneration:y=!1}){const v=$e(t),[b,h]=i.useState(v),g=b,O=sn({...t,displayName:b}),T=Ln(t),[C,D]=i.useState(null),[E,I]=i.useState(!1),[z,H]=i.useState(null),[q,Q]=i.useState(!1),[x,j]=i.useState(!1),[F,B]=i.useState([]),[G,se]=i.useState(!1),[ke,R]=i.useState(null),[ee,K]=i.useState(null),[re,me]=i.useState(""),[p,$]=i.useState(!1),[W,Y]=i.useState(null),[he,ye]=i.useState(!1),[Le,De]=i.useState(""),[ie,pe]=i.useState(null),[ge,oe]=i.useState(""),[te,Lt]=i.useState(!0),[N,xe]=i.useState(!1),[U,ce]=i.useState(""),[J,Be]=i.useState("split"),[X,V]=i.useState({type:"idle"}),[Dt,Me]=i.useState(!1),[tt,Bt]=i.useState(!1),[_e,nt]=i.useState(!1),[be,ne]=i.useState(!1),[Mt,Se]=i.useState(!1),[at,st]=i.useState(""),[Pe,ze]=i.useState(null),[rt,je]=i.useState(null),[Fe,le]=i.useState(g),de=t.editable!==!1,fe=et(t),Pt=!!t.assetId,Oe=N&&U!==(C??""),He=i.useRef(null),We=i.useRef(null),it=i.useRef(null),ue=i.useRef(null),Ce=i.useRef(null),ot=i.useRef(null),ct=i.useRef(null),k=F.find(n=>n.id===ee)||F[0]||null,lt=m.filter(n=>{const a=at.trim().toLowerCase();return a?n.title.toLowerCase().includes(a)||String(n.referenceLabel||"").trim().toLowerCase().includes(a):!0}),dt=i.useCallback(async()=>{I(!0),H(null),D(null);try{const n=await P(t.apiUrl,{credentials:"same-origin"},s);if(!n.ok)throw new Error(`Failed to load document (${n.status})`);const a=await n.text();D(a),ce(a)}catch(n){H(n?.message||"Failed to load document")}finally{I(!1)}},[s,t.apiUrl]),Ne=i.useCallback(async n=>{if(!t.assetId){B([]),K(null),R(null);return}const a=n?.silent===!0;a||(se(!0),R(null));try{const o=await P(`/api/taskforce/document-reviews/sessions?assetId=${encodeURIComponent(t.assetId)}`,{credentials:"include"},s),d=await o.json().catch(()=>({}));if(!o.ok)throw new Error(d.error||`Failed to load reviews (${o.status})`);const f=Array.isArray(d.sessions)?d.sessions:[];B(f),K(_=>_&&f.some(Z=>Z.id===_)?_:f[0]?.id??null)}catch(o){a||(R(o?.message||"Failed to load reviews"),B([]),K(null))}finally{a||se(!1)}},[s,t.assetId]),Ge=i.useCallback(async()=>{if(!t.assetId||p)return null;$(!0),R(null);try{const n=await P("/api/taskforce/document-reviews/sessions",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({assetId:t.assetId,title:`Review ${F.length+1}`})},s),a=await n.json().catch(()=>({}));if(!n.ok)throw new Error(a.error||`Failed to create review (${n.status})`);const o=a.session||null;if(!o)throw new Error("Review session payload missing.");return B(d=>[o,...d.filter(f=>f.id!==o.id)]),K(o.id),o}catch(n){return R(n?.message||"Failed to create review"),null}finally{$(!1)}},[s,t.assetId,p,F.length]);i.useEffect(()=>{dt(),Ne(),xe(!1),V({type:"idle"}),ne(!1);const n=$e(t);h(n),le(n),Q(!1),j(!1),me(""),Y(null),ye(!1),De(""),pe(null),oe("")},[t,dt,Ne]),i.useEffect(()=>{if(!k)return;const n=ot.current;typeof n?.scrollIntoView=="function"&&n.scrollIntoView({block:"end"})},[k?.comments.length,k?.id]),i.useEffect(()=>{De(k?.title?.trim()||""),ye(!1)},[k?.id,k?.title]),i.useEffect(()=>{be&&window.setTimeout(()=>{We.current?.focus(),We.current?.select()},0)},[be]),i.useEffect(()=>{if(!t.assetId||N)return;const n=()=>{document.visibilityState==="visible"&&Ne({silent:!0})},a=window.setInterval(n,15e3);return window.addEventListener("focus",n),document.addEventListener("visibilitychange",n),()=>{window.clearInterval(a),window.removeEventListener("focus",n),document.removeEventListener("visibilitychange",n)}},[t.assetId,N,Ne]),i.useEffect(()=>{if(!N)return;const n=a=>{(a.metaKey||a.ctrlKey)&&a.key==="s"&&(a.preventDefault(),ut())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[N,U]);const ae=i.useCallback(()=>{Ce.current!==null&&(window.clearTimeout(Ce.current),Ce.current=null),ue.current&&(ue.current.remove(),ue.current=null)},[]);i.useEffect(()=>()=>{ae()},[ae]);const Te=i.useCallback(n=>{if(!N||J!=="split")return;const a=He.current,o=it.current;if(!a||!o)return;const d=n==="editor"?a:o,f=n==="editor"?o:a,_=Math.max(d.scrollHeight-d.clientHeight,0),Z=Math.max(f.scrollHeight-f.clientHeight,0),Je=_<=0?0:d.scrollTop/_,kt=Z*Je;Math.abs(f.scrollTop-kt)<=1||(f.scrollTop=kt)},[N,J]);i.useEffect(()=>{!N||J!=="split"||Te("editor")},[U,N,J,Te]);const zt=()=>{de&&(ce(C??""),V({type:"idle"}),xe(!0),setTimeout(()=>He.current?.focus(),50))},Ft=()=>{Oe&&!window.confirm("Discard unsaved changes?")||(xe(!1),ce(C??""),V({type:"idle"}))},ut=i.useCallback(async()=>{if(de&&X.type!=="saving"){V({type:"saving"});try{const n=await P("/api/taskforce/documents/save",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({fsPath:t.fsPath,content:U})},s),a=await n.json().catch(()=>({}));if(!n.ok)throw new Error(a.error||`Save failed (${n.status})`);const o=a.updatedAt||new Date().toISOString();D(U),V({type:"saved",savedAt:o}),c?.(o),xe(!1)}catch(n){V({type:"error",message:n?.message||"Save failed"})}}},[s,t.fsPath,U,X.type,c,de]),Ot=i.useCallback(()=>{const n=N?U:C??"";if(!n.trim())return;ae();const a=document.createElement("iframe");a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.position="fixed",a.style.right="0",a.style.bottom="0",a.style.width="0",a.style.height="0",a.style.border="0",a.style.opacity="0",a.style.pointerEvents="none",document.body.appendChild(a),ue.current=a;const o=a.contentWindow,d=a.contentDocument;if(!o||!d){ae();return}d.open(),d.write(sr(n)),d.close();let f=!1;const _=async()=>{f||ue.current!==a||(f=!0,await rr(o,d),ue.current===a&&(o.focus(),o.print(),Ce.current=ir(ae)))};o.addEventListener("afterprint",ae,{once:!0}),_()},[ae,C,U,N]),Ht=async()=>{const n=t.apiUrl,a=new URL(xt(n,s),window.location.origin).toString();try{await navigator.clipboard.writeText(a)}catch{const o=document.createElement("textarea");o.value=a,document.body.appendChild(o),o.select(),document.execCommand("copy"),document.body.removeChild(o)}Q(!0),setTimeout(()=>Q(!1),2e3)},Wt=i.useCallback(async()=>{if(T){try{await navigator.clipboard.writeText(T)}catch{const n=document.createElement("textarea");n.value=T,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n)}j(!0),setTimeout(()=>j(!1),2e3)}},[T]),Gt=()=>{const n=t.apiUrl.includes("?")?"&":"?",a=xt(`${t.apiUrl}${n}download=1&filename=${encodeURIComponent(O)}`,s),o=document.createElement("a");o.href=a,o.click()},Ke=i.useCallback(async()=>{if(!t.assetId)return;const n=Fe.trim();if(!n){le(g),ne(!1);return}if(n===g){ne(!1);return}const a=await P(`/api/taskforce/documents/${encodeURIComponent(t.assetId)}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayName:n})},s),o=await a.json().catch(()=>({}));if(!a.ok){window.alert(o.error||`Rename failed (${a.status})`);return}h(n),le(n),ne(!1),c?.(o.updatedAt||new Date().toISOString())},[s,t.assetId,c,g,Fe]),Kt=i.useCallback(n=>{if(n.key==="Enter"){n.preventDefault(),Ke();return}n.key==="Escape"&&(n.preventDefault(),le(g),ne(!1))},[Ke,g]),Ut=i.useCallback(async()=>{if(!t.assetId||_e)return;const n=fe==="attached",a=Math.max(0,Number(t.attachmentCount||0)),o=n?`Delete "${g}" everywhere?
251
+
252
+ This will remove it from ${a} linked task${a===1?"":"s"} and soft-delete the document across sync.`:`Permanently delete "${g}" from storage?`;if(window.confirm(o)){nt(!0);try{const d=await P(`/api/taskforce/documents/${encodeURIComponent(t.assetId)}`,{method:"DELETE",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(n?{forceDetach:!0}:{})},s),f=await d.json().catch(()=>({}));if(!d.ok)throw new Error(f.error||`Delete failed (${d.status})`);u?.()}catch(d){window.alert(d?.message||"Delete failed")}finally{nt(!1)}}},[s,fe,_e,t.assetId,t.attachmentCount,u,g]),Jt=i.useCallback(()=>{st(""),je(null),ze(null),Se(!0)},[]),Vt=i.useCallback(async n=>{if(t.assetId){je(null),ze(n);try{const a=await P(`/api/taskforce/documents/${encodeURIComponent(t.assetId)}/attach`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({targetType:"task",targetId:n})},s),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error||`Attach failed (${a.status})`);if(o.alreadyAttached){je("This document is already attached to that task.");return}Se(!1),c?.(new Date().toISOString())}catch(a){je(a?.message||"Failed to attach document.")}finally{ze(null)}}},[s,t.assetId,c]),qt=i.useCallback(async()=>{if(!(!k||p)){$(!0),R(null);try{const n=k.status==="resolved"?"open":"resolved",a=await P(`/api/taskforce/document-reviews/sessions/${encodeURIComponent(k.id)}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({status:n})},s),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error||`Failed to update review (${a.status})`);const d=o.session||null;if(!d)throw new Error("Review session payload missing.");B(f=>f.map(_=>_.id===d.id?d:_))}catch(n){R(n?.message||"Failed to update review")}finally{$(!1)}}},[k,s,p]),Qt=i.useCallback(async()=>{if(!k||p)return;const n=Le.trim();$(!0),R(null);try{const a=await P(`/api/taskforce/document-reviews/sessions/${encodeURIComponent(k.id)}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:n||null})},s),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error||`Failed to update review (${a.status})`);const d=o.session||null;if(!d)throw new Error("Review session payload missing.");B(f=>f.map(_=>_.id===d.id?d:_)),ye(!1)}catch(a){R(a?.message||"Failed to update review")}finally{$(!1)}},[k,s,p,Le]),mt=N?U:C??"",Yt=i.useCallback(()=>{if(N||!te)return;const n=typeof window.getSelection=="function"?window.getSelection():null,a=n?.toString().replace(/\s+/g," ").trim()||"";if(!n||!a)return;const o=n.rangeCount>0?n.getRangeAt(0):null,d=ct.current;if(!o||!d)return;const f=o.commonAncestorContainer,_=f.nodeType===Node.TEXT_NODE?f.parentNode:f;if(!(_ instanceof Node)||!d.contains(_))return;const Z=dr(d,o,a);Z&&Y(Z)},[N,te]),Xt=i.useCallback(()=>{Lt(n=>{const a=!n;return a||Y(null),a})},[]),ht=i.useCallback(async()=>{const n=re.trim();if(!n||p)return;let a=k;if(a||(a=await Ge()),!!a){$(!0),R(null);try{const o=await P(`/api/taskforce/document-reviews/sessions/${encodeURIComponent(a.id)}/comments`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:n,anchor:W||{kind:"document"}})},s),d=await o.json().catch(()=>({}));if(!o.ok)throw new Error(d.error||`Failed to add comment (${o.status})`);const f=d.session||null;if(!f)throw new Error("Review session payload missing.");B(_=>{const Z=_.filter(Je=>Je.id!==f.id);return[f,...Z]}),K(f.id),me(""),Y(null)}catch(o){R(o?.message||"Failed to add comment")}finally{$(!1)}}},[k,s,Ge,W,p,re]),Zt=i.useCallback((n,a)=>{pe(n),oe(a)},[]),en=i.useCallback(async()=>{if(!k||!ie||p)return;const n=ge.trim();if(n){$(!0),R(null);try{const a=await P(`/api/taskforce/document-reviews/sessions/${encodeURIComponent(k.id)}/comments/${encodeURIComponent(ie)}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:n})},s),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error||`Failed to update comment (${a.status})`);const d=o.session||null;if(!d)throw new Error("Review session payload missing.");B(f=>f.map(_=>_.id===d.id?d:_)),pe(null),oe("")}catch(a){R(a?.message||"Failed to update comment")}finally{$(!1)}}},[k,s,ge,ie,p]),tn=i.useCallback(async n=>{if(!(!k||p)&&window.confirm("Delete this review comment?")){$(!0),R(null);try{const a=await P(`/api/taskforce/document-reviews/sessions/${encodeURIComponent(k.id)}/comments/${encodeURIComponent(n)}`,{method:"DELETE",credentials:"include"},s),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error||`Failed to delete comment (${a.status})`);const d=o.session||null;if(!d)throw new Error("Review session payload missing.");B(f=>f.map(_=>_.id===d.id?d:_)),ie===n&&(pe(null),oe(""))}catch(a){R(a?.message||"Failed to delete comment")}finally{$(!1)}}},[k,s,ie,p]),pt=i.useCallback(async n=>{if(!de)return!1;V({type:"saving"});try{const a=await P("/api/taskforce/documents/save",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({fsPath:t.fsPath,content:n})},s),o=await a.json().catch(()=>({}));if(!a.ok)throw new Error(o.error||`Save failed (${a.status})`);const d=o.updatedAt||new Date().toISOString();return D(n),ce(n),V({type:"saved",savedAt:d}),c?.(d),!0}catch(a){return V({type:"error",message:a?.message||"Save failed"}),!1}},[s,t.fsPath,c,de]),nn=i.useCallback((n,a)=>{const o=N?U:C??"",d=ur(o,n,a);if(d!==o){if(N){ce(d),V(f=>f.type==="saving"?f:{type:"idle"});return}pt(d)}},[C,U,N,pt]);let ft=-1;const Ue=n=>!n||!Array.isArray(n.children)?!1:n.children.some(a=>a?a.type==="element"&&a.tagName==="input"&&a.properties?.type==="checkbox"?!0:Ue(a):!1),vt=n=>!n||!Array.isArray(n.children)?!1:n.children.some(a=>typeof a?.checked=="boolean"?!0:Ue(a)),wt={input({type:n,checked:a,...o}){if(n!=="checkbox")return e.jsx("input",{type:n,checked:a,...o});ft+=1;const d=ft;return e.jsx("input",{...o,type:"checkbox",checked:!!a,disabled:!1,onClick:f=>f.stopPropagation(),onChange:f=>nn(d,f.currentTarget.checked)})},ul({children:n,node:a,...o}){const d=vt(a);return e.jsx("ul",{...o,style:d?{paddingLeft:"1.25em"}:void 0,"data-task-list":d?"true":void 0,children:n})},ol({children:n,node:a,...o}){const d=vt(a);return e.jsx("ol",{...o,style:d?{paddingLeft:"1.25em"}:void 0,"data-task-list":d?"true":void 0,children:n})},li({children:n,node:a,...o}){const d=typeof a?.checked=="boolean"||Ue(a);return e.jsx("li",{...o,style:d?{listStyleType:"none",listStyle:"none",marginLeft:0}:void 0,"data-task-item":d?"true":void 0,children:n})}};return e.jsxs("div",{className:`${r.viewer} ${N?r.viewerEditMode:""} ${tt?r.viewerMonochrome:""}`,children:[e.jsxs("div",{className:r.meta,children:[e.jsxs("div",{className:r.metaLeft,children:[e.jsxs("span",{className:`${r.typeBadge} ${Xs[t.docType]??""}`,children:[e.jsx(gn,{size:10}),Ys[t.docType]]}),be?e.jsx("div",{className:r.metaRenameRow,children:e.jsx("input",{ref:We,type:"text",className:L.input,value:Fe,onChange:n=>le(n.target.value),onBlur:()=>{Ke()},onKeyDown:Kt})}):e.jsx("span",{className:r.metaDocumentName,title:g,onDoubleClick:()=>{t.assetId&&(le(g),ne(!0))},children:g}),l&&e.jsx("span",{className:r.metaTaskName,title:`From task: ${l}`,children:l}),fe==="unattached"&&e.jsx("span",{className:r.statusBadge,children:"Unattached"}),t.updatedAt&&e.jsxs("span",{className:r.metaDate,title:jt(t.updatedAt),children:[e.jsx(xn,{size:11}),jt(t.updatedAt)]}),e.jsxs("span",{className:r.metaSize,children:[e.jsx(_n,{size:11}),nr(t.sizeBytes)]}),T&&e.jsx(rn,{label:T,copied:x,onClick:()=>{Wt()},title:"Copy document reference"}),X.type==="saved"&&e.jsxs("span",{className:`${r.saveStatus} ${r.saveStatusSaved}`,children:[e.jsx(At,{size:11}),"Saved"]}),X.type==="error"&&e.jsxs("span",{className:`${r.saveStatus} ${r.saveStatusError}`,title:X.message,children:[e.jsx(Ye,{size:11}),X.message||"Save failed"]}),Oe&&X.type!=="saving"&&e.jsx("span",{className:r.unsaved,children:"Unsaved changes"})]}),e.jsx("div",{className:r.actions,children:N?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:r.layoutToggle,children:[e.jsx("button",{className:`${r.layoutBtn} ${J==="editor"?r.layoutBtnActive:""}`,onClick:()=>Be("editor"),title:"Editor only",children:e.jsx(Ee,{size:12})}),e.jsx("button",{className:`${r.layoutBtn} ${J==="split"?r.layoutBtnActive:""}`,onClick:()=>Be("split"),title:"Split view",children:e.jsx(bn,{size:12})}),e.jsx("button",{className:`${r.layoutBtn} ${J==="preview"?r.layoutBtnActive:""}`,onClick:()=>Be("preview"),title:"Preview only",children:e.jsx(qe,{size:12})})]}),e.jsxs("button",{className:r.actionBtn,onClick:Ft,title:"Discard changes",children:[e.jsx(Rt,{size:13}),"Cancel"]}),e.jsxs("button",{className:`${r.actionBtn} ${r.saveBtn}`,onClick:ut,disabled:X.type==="saving"||!Oe,title:"Save (Ctrl+S)",children:[e.jsx(Sn,{size:13}),X.type==="saving"?"Saving…":"Save"]})]}):e.jsxs(e.Fragment,{children:[t.taskId&&w&&e.jsxs("button",{className:r.actionBtn,onClick:()=>w(t.taskId),title:"Back to task","aria-label":"Back to task",children:[e.jsx(jn,{size:13}),"Back to task"]}),t.assetId&&e.jsxs("button",{className:r.actionBtn,onClick:()=>ne(n=>!n),title:"Rename document",children:[e.jsx(Ee,{size:13}),be?"Close Rename":"Rename"]}),de&&e.jsxs("button",{className:`${r.actionBtn} ${r.editBtn}`,onClick:zt,title:"Edit document",children:[e.jsx(Ee,{size:13}),"Edit"]}),t.assetId&&e.jsxs("button",{className:r.actionBtn,onClick:Jt,title:"Attach document to a task",children:[e.jsx(bt,{size:13}),"Attach"]}),e.jsxs("button",{className:r.actionBtn,onClick:Xt,title:te?"Hide review and comments":"Show review and comments",children:[e.jsx(Ve,{size:13}),te?"Hide Review":"Show Review"]}),e.jsxs("button",{className:r.actionBtn,onClick:Ht,title:"Copy link",children:[e.jsx(bt,{size:13}),q?"Copied!":"Copy link"]}),e.jsxs("button",{className:r.actionBtn,onClick:Gt,title:"Download .md",children:[e.jsx(Cn,{size:13}),"Download"]}),e.jsxs("button",{className:r.actionBtn,onClick:Ot,title:"Print",children:[e.jsx(Nn,{size:13}),"Print"]}),e.jsxs("button",{className:r.actionBtn,onClick:()=>Bt(n=>!n),title:"Toggle black and white style",children:[e.jsx(qe,{size:13}),tt?"Color":"B/W"]}),y&&t.docType==="implementation-plan"&&!N&&e.jsxs("button",{className:`${r.actionBtn} ${r.generateBtn}`,onClick:()=>Me(!0),title:"Generate tasks from this plan",children:[e.jsx(Qe,{size:13}),"Generate Tasks"]}),Pt&&e.jsxs("button",{className:`${r.actionBtn} ${r.dangerBtn}`,onClick:()=>{Ut()},disabled:_e,title:fe==="attached"?"Remove this document from linked tasks and delete it":"Permanently delete this unattached document",children:[e.jsx(Tn,{size:13}),_e?"Deleting…":fe==="attached"?"Delete & Unlink":"Delete Permanently"]})]})})]}),E&&e.jsx("div",{className:r.viewerState,children:"Loading…"}),!E&&z&&e.jsx("div",{className:r.viewerStateError,children:z}),!E&&!z&&(N?e.jsxs("div",{className:`${r.editorArea} ${Zs[J]}`,children:[(J==="editor"||J==="split")&&e.jsxs("div",{className:r.editorPane,children:[e.jsx("div",{className:r.editorPaneLabel,children:"Markdown"}),e.jsx("textarea",{ref:He,className:`${r.editorTextarea} tf-scrollbar`,value:U,onScroll:()=>Te("editor"),onChange:n=>{ce(n.target.value),V(a=>a.type==="saving"?a:{type:"idle"})},spellCheck:!0,placeholder:"Write markdown here…"})]}),(J==="preview"||J==="split")&&e.jsxs("div",{className:r.previewPane,children:[e.jsx("div",{className:r.editorPaneLabel,children:"Preview"}),e.jsx("div",{ref:it,className:`${L.docMarkdown} ${r.markdownSurface}`,"data-testid":"doc-preview-scroll",onScroll:()=>Te("preview"),children:e.jsx(Re,{remarkPlugins:[Ae],rehypePlugins:[Ie],components:wt,children:mt})})]})]}):e.jsxs("div",{className:`${r.viewerBody} ${te?"":r.viewerBodyFullWidth}`,children:[e.jsx("div",{className:`${r.viewerContent} ${r.viewerMain} tf-scrollbar`,children:e.jsx("div",{ref:ct,className:`${L.docMarkdown} ${r.markdownSurface}`,onMouseUp:te?Yt:void 0,children:e.jsx(Re,{remarkPlugins:[Ae],rehypePlugins:[Ie],components:wt,children:mt})})}),te&&e.jsx("aside",{className:r.reviewRail,children:e.jsxs("section",{className:r.reviewSection,"aria-label":"Review and comments",children:[e.jsxs("div",{className:r.reviewHeader,children:[e.jsxs("div",{children:[e.jsxs("div",{className:r.reviewTitle,children:[e.jsx(Ve,{size:14}),"Review & Comments"]}),e.jsx("p",{className:r.reviewSubtitle,children:"Comments stay attached to this document review session."})]}),e.jsxs("div",{className:r.reviewControls,children:[F.length>1&&e.jsx("select",{className:`${L.select} ${r.reviewSelect}`,value:k?.id||"",onChange:n=>K(n.target.value||null),"aria-label":"Select review session",children:F.map(n=>e.jsx("option",{value:n.id,children:n.title?.trim()||"Untitled review"},n.id))}),e.jsxs("button",{type:"button",className:r.actionBtn,onClick:()=>{Ge()},disabled:p||!t.assetId,children:[e.jsx(Ve,{size:13}),"Start Review"]}),k&&e.jsxs("button",{type:"button",className:r.actionBtn,onClick:()=>{qt()},disabled:p,children:[k.status==="resolved"?e.jsx(En,{size:13}):e.jsx(Rn,{size:13}),k.status==="resolved"?"Reopen":"Resolve"]})]})]}),k&&e.jsxs("div",{className:r.reviewSessionMeta,children:[e.jsx("span",{className:`${r.statusBadge} ${k.status==="resolved"?r.reviewStatusResolved:""}`,children:k.status==="resolved"?"Resolved":"Open"}),he?e.jsxs("div",{className:r.reviewTitleEditRow,children:[e.jsx("input",{type:"text",className:L.input,value:Le,onChange:n=>De(n.target.value),placeholder:"Untitled review"}),e.jsx("button",{type:"button",className:L.secondaryHeaderBtn,onClick:()=>{Qt()},disabled:p,children:"Save Title"})]}):e.jsx("span",{className:r.reviewSessionLabel,children:k.title?.trim()||"Untitled review"}),e.jsxs("span",{className:r.reviewSessionTimestamp,children:["Updated ",Ct(k.updatedAt)]}),!he&&e.jsxs("button",{type:"button",className:r.actionBtn,onClick:()=>ye(!0),disabled:p,children:[e.jsx(Ee,{size:13}),"Rename Review"]})]}),ke&&e.jsx("div",{className:r.viewerStateError,children:ke}),e.jsxs("div",{className:M.commentPanel,children:[e.jsxs("div",{className:M.commentThread,children:[G&&e.jsx("div",{className:M.emptyComments,children:"Loading review comments…"}),!G&&!k&&e.jsx("div",{className:M.emptyComments,children:"Start a review to collect comments for this document."}),!G&&k&&k.comments.length===0&&e.jsx("div",{className:M.emptyComments,children:"No comments yet. Add the first review note for this document."}),!G&&k&&k.comments.map(n=>{const a=n.authorActor?.kind==="ai",o=Nt(n.anchor),d=a?An:In,f=ie===n.id;return e.jsxs("div",{className:`${M.comment} ${a?M.commentAi:M.commentUser}`,children:[e.jsxs("div",{className:M.commentHeader,children:[e.jsxs("span",{className:M.commentAuthor,style:n.authorActor?.color?{color:n.authorActor.color}:void 0,children:[e.jsx(d,{size:12,strokeWidth:1.5}),or(n)]}),e.jsx("span",{className:M.commentTime,children:Ct(n.updatedAt)}),e.jsxs("span",{className:r.reviewCommentActions,children:[!f&&e.jsx("button",{type:"button",className:r.reviewCommentAction,onClick:()=>Zt(n.id,n.body),disabled:p,children:"Edit"}),f&&e.jsx("button",{type:"button",className:r.reviewCommentAction,onClick:()=>{pe(null),oe("")},disabled:p,children:"Cancel"}),e.jsx("button",{type:"button",className:r.reviewCommentAction,onClick:()=>{tn(n.id)},disabled:p,children:"Delete"})]})]}),o&&e.jsx("span",{className:r.reviewAnchorLabel,children:o}),e.jsx("div",{className:M.commentText,children:f?e.jsxs("div",{className:r.reviewCommentEditor,children:[e.jsx("textarea",{className:M.commentInput,value:ge,onChange:_=>oe(_.target.value),disabled:p}),e.jsx("button",{type:"button",className:L.secondaryHeaderBtn,onClick:()=>{en()},disabled:p||!ge.trim(),children:"Save Comment"})]}):e.jsx(Re,{remarkPlugins:[Ae],rehypePlugins:[Ie],children:n.body})})]},n.id)}),e.jsx("div",{ref:ot})]}),e.jsxs("div",{className:M.commentInputArea,children:[e.jsxs("div",{className:r.reviewComposer,children:[W&&e.jsxs("div",{className:r.reviewAnchorChip,children:[e.jsx("span",{children:Nt(W)||"Selected text"}),"quote"in W&&W.quote&&e.jsxs("span",{className:r.reviewAnchorSnippet,children:['"',W.quote,'"']}),e.jsx("button",{type:"button",className:r.reviewAnchorClear,onClick:()=>Y(null),children:"Clear"})]}),e.jsx("textarea",{className:M.commentInput,placeholder:k?.status==="resolved"?"Reopen this review to add more comments…":W?"Add a comment for the selected text…":"Add a comment for this document review…",value:re,onChange:n=>me(n.target.value),disabled:p||k?.status==="resolved",onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),ht())}})]}),e.jsx("button",{type:"button",className:M.sendCommentBtn,onClick:()=>{ht()},disabled:p||!re.trim()||k?.status==="resolved","aria-label":"Send review comment",title:"Send review comment",children:e.jsx($n,{size:15})})]})]})]})})]})),y&&Dt&&C!==null&&e.jsx(Qs,{content:C,docTitle:t.title,apiBaseUrl:s,onClose:()=>Me(!1),onGenerated:n=>Me(!1)}),e.jsx(on,{isOpen:Mt,onClose:()=>{Pe||Se(!1)},title:"Attach document",size:"md",footer:e.jsx("button",{className:r.actionBtn,onClick:()=>Se(!1),disabled:!!Pe,children:"Close"}),children:e.jsxs("div",{className:r.attachModalBody,children:[e.jsx("p",{className:r.attachModalCopy,children:"Attach this document to a task from the document manager. Initiative and workstream targets can be enabled later on the same attachment model."}),e.jsx("input",{type:"text",className:L.input,placeholder:"Search tasks…",value:at,onChange:n=>st(n.target.value)}),rt&&e.jsxs("div",{className:r.attachModalError,children:[e.jsx(Ye,{size:14}),e.jsx("span",{children:rt})]}),e.jsx("div",{className:`${r.attachTaskList} tf-scrollbar`,children:lt.length===0?e.jsx("div",{className:r.attachEmptyState,children:m.length===0?"No tasks are available in this workspace.":"No tasks match your search."}):lt.map(n=>{const a=t.taskId===n.id,o=Pe===n.id;return e.jsxs("button",{type:"button",className:r.attachTaskRow,disabled:o,onClick:()=>{Vt(n.id)},children:[e.jsxs("span",{className:r.attachTaskInfo,children:[e.jsx("span",{className:r.attachTaskTitle,children:n.title}),n.referenceLabel&&e.jsx("span",{className:r.attachTaskReference,children:n.referenceLabel})]}),e.jsx("span",{className:r.attachTaskMeta,children:o?"Attaching…":a?"Attached":"Attach"})]},n.id)})})]})}),!N&&e.jsx("div",{className:r.printHint,children:"For the cleanest output, disable browser Headers and footers in the print dialog."})]})}function Et(t){return typeof t=="string"?t.trim().replace(/\/+$/,""):""}function hr(t){return t.runtimeMode==="local"?"":Et(t.apiBaseUrl)||Et(t.cloudAuthBaseUrl)||""}function pr({runtimeMode:t="local",apiBaseUrl:l="",cloudAuthBaseUrl:m="",typeFilters:s,attachmentFilters:c,onTypeFiltersChange:u,onAttachmentFiltersChange:w,requestedDocPath:y=null,requestedDocAssetId:v=null,onRequestedDocHandled:b}){const[h,g]=i.useState([]),[O,T]=i.useState(!0),[C,D]=i.useState(null),[E,I]=i.useState(null),[z,H]=i.useState(""),[q,Q]=i.useState(()=>cn.map(p=>p.value)),[x,j]=i.useState(()=>ln.map(p=>p.value)),F=hr({runtimeMode:t,apiBaseUrl:l,cloudAuthBaseUrl:m}),B=s??q,G=c??x,se=u??Q,ke=w??j,R=i.useCallback(async()=>{T(!0),D(null);try{const p=await P("/api/taskforce/documents",{credentials:"include"},F);if(!p.ok)throw new Error(`Failed to load documents (${p.status})`);const $=await p.json(),W=Array.isArray($.documents)?$.documents:[];W.length,g(W)}catch(p){D(p?.message||"Failed to load documents"),p?.message}finally{T(!1)}},[F,t]);i.useEffect(()=>{R()},[R]);const ee=i.useMemo(()=>na(h,z,B,G),[G,h,z,B]),K=i.useMemo(()=>E?h.find(p=>p.id===E)??null:null,[h,E]);i.useEffect(()=>{if(!y&&!v||h.length===0)return;const p=y?Xe(y):"",$=String(v||"").trim().toLowerCase()||St(y),W=h.find(Y=>{const he=St(Y.fsPath)||String(Y.assetId||"").trim().toLowerCase()||null;return $&&he&&he===$?!0:p?ta(Xe(Y.fsPath),p):!1});W&&(I(W.id),b?.())},[h,b,v,y]),i.useEffect(()=>{if(!((y||v)&&!K)){if(ee.length===0){E!==null&&I(null);return}K&&ee.some(p=>p.id===K.id)||I(ee[0].id)}},[ee,v,y,K,E]);const re=i.useCallback(async()=>{I(null),await R()},[R]),me=z.trim().length>0||B.length>0||G.length>0;return{documentApiBaseUrl:F,documents:h,filteredDocs:ee,loading:O,error:C,selectedDoc:K,searchQuery:z,typeFilters:B,attachmentFilters:G,hasActiveFilters:me,setSearchQuery:H,handleTypeFiltersChange:se,handleAttachmentFiltersChange:ke,fetchDocuments:R,selectDoc:p=>I(p?.id??null),handleDeleteSelected:re}}function fr({tasks:t,apiBaseUrl:l="",documents:m,loading:s,error:c,selectedDoc:u,searchQuery:w,hasActiveFilters:y,documentTrayOpen:v,onSearchChange:b,onSelectDoc:h,onRefresh:g,onCloseDocumentTray:O,onDeleteSelected:T,onBackToTask:C,enableTaskGeneration:D=!1}){const E=new Map(t.map(H=>[H.id,H])),I=typeof v=="boolean",z=e.jsx(oa,{documents:m,selectedDocId:u?.id??null,loading:s,error:c,searchQuery:w,onSearchChange:b,onSelect:H=>h(H),onCloseTray:I?O:void 0,taskById:E,hasActiveFilters:y});return e.jsxs("div",{className:`${L.docWorkspace} ${I?L.docWorkspaceTrayMode:""} ${I&&v?L.docWorkspaceTrayOpen:""}`.trim(),children:[I?e.jsx("div",{className:`${L.docTrayPanel} ${v?L.docTrayPanelOpen:""}`.trim(),"aria-hidden":!v,children:z}):e.jsx("div",{className:L.docIndexPanel,children:z}),e.jsx("div",{className:L.docViewerPanel,children:u?e.jsx(mr,{doc:u,taskTitle:u.taskId?E.get(u.taskId)?.title??null:null,tasks:t,apiBaseUrl:l,onSaved:H=>g(),onDeleted:()=>{T()},onBackToTask:C,enableTaskGeneration:D}):!s&&e.jsx("div",{className:L.docViewerEmpty,children:e.jsx("p",{className:"tf-empty-copy",children:m.length===0?"No documents match your current filters.":"Select a document to view it."})})})]})}function br({tasks:t,runtimeMode:l="local",apiBaseUrl:m="",cloudAuthBaseUrl:s="",typeFilters:c,attachmentFilters:u,onTypeFiltersChange:w,onAttachmentFiltersChange:y,documentTrayOpen:v,onCloseDocumentTray:b,requestedDocPath:h=null,requestedDocAssetId:g=null,onRequestedDocHandled:O,onBackToTask:T,enableTaskGeneration:C=!1}){const{documentApiBaseUrl:D,filteredDocs:E,loading:I,error:z,selectedDoc:H,searchQuery:q,hasActiveFilters:Q,setSearchQuery:x,fetchDocuments:j,selectDoc:F,handleDeleteSelected:B}=pr({runtimeMode:l,apiBaseUrl:m,cloudAuthBaseUrl:s,typeFilters:c,attachmentFilters:u,onTypeFiltersChange:w,onAttachmentFiltersChange:y,requestedDocPath:h,requestedDocAssetId:g,onRequestedDocHandled:O}),G=ve.useRef(v);return ve.useEffect(()=>{const se=G.current===!0;G.current=v,!(v!==!0||se)&&j()},[v,j]),e.jsx(fr,{tasks:t,apiBaseUrl:D,documents:E,loading:I,error:z,selectedDoc:H,searchQuery:q,hasActiveFilters:Q,documentTrayOpen:v,onSearchChange:x,onSelectDoc:F,onRefresh:j,onCloseDocumentTray:b,onDeleteSelected:B,onBackToTask:T,enableTaskGeneration:C})}export{ln as DOCUMENT_ATTACHMENT_FILTER_OPTIONS,cn as DOCUMENT_TYPE_FILTER_OPTIONS,fr as DocumentWorkspace,br as DocumentWorkspaceShell};