@tickernelz/wardmote-ui 2026.1114.1 → 2026.1114.2

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 (124) hide show
  1. package/dist/assets/{ActiveAgentsPanel-CKzCe8AC.js → ActiveAgentsPanel-Budj8e9v.js} +1 -1
  2. package/dist/assets/{AdapterManager-DFPaPUUr.js → AdapterManager-DhiW44Eo.js} +1 -1
  3. package/dist/assets/{AdvancedToolsRoute-CN5fWS4T.js → AdvancedToolsRoute-CICI1XRd.js} +1 -1
  4. package/dist/assets/{AgentActionButtons-a9LacJPP.js → AgentActionButtons-DIhpv51Y.js} +1 -1
  5. package/dist/assets/{AgentChat-D5FDUYuV.js → AgentChat-CeuGtMXr.js} +1 -1
  6. package/dist/assets/{AgentChats-TN5SE_gN.js → AgentChats-CmDtTrMa.js} +1 -1
  7. package/dist/assets/{AgentDefaults-CiVVS_pQ.js → AgentDefaults-DpYaMGkf.js} +1 -1
  8. package/dist/assets/{AgentDetail-bCAmWRXs.js → AgentDetail-DFTeFc4-.js} +1 -1
  9. package/dist/assets/{AgentTodoCard-BpmvHEsm.js → AgentTodoCard-DRXZ7hmU.js} +1 -1
  10. package/dist/assets/{Agents-CToMMxGu.js → Agents-CClUUMUq.js} +3 -3
  11. package/dist/assets/{AppDetail-P807ou0a.js → AppDetail-DfHLFOtj.js} +1 -1
  12. package/dist/assets/{AppNotConnected-DuA4PukX.js → AppNotConnected-CcmXbFtD.js} +1 -1
  13. package/dist/assets/{ApprovalCard-BDdZDBMj.js → ApprovalCard-uT_9D_uH.js} +1 -1
  14. package/dist/assets/{ApprovalDetail-CVgy1uNi.js → ApprovalDetail-CE41WFbd.js} +1 -1
  15. package/dist/assets/{ApprovalPayload-H5zW6yQ4.js → ApprovalPayload-_zU9bukt.js} +1 -1
  16. package/dist/assets/{Approvals-DL6kx45P.js → Approvals-BXrjqpKc.js} +1 -1
  17. package/dist/assets/{AppsReview-Bf7oB0ES.js → AppsReview-C0Y3SxmZ.js} +1 -1
  18. package/dist/assets/{ArtifactCard-Cp4KPgZl.js → ArtifactCard-DKUUBZ0K.js} +1 -1
  19. package/dist/assets/{Artifacts-Dz3eHCaQ.js → Artifacts-Bsv5m0aU.js} +1 -1
  20. package/dist/assets/{AssistantConnection-5Y4fBVXq.js → AssistantConnection-Dm2PaSeU.js} +1 -1
  21. package/dist/assets/{AttentionInteractionResolver-DlP6a6AG.js → AttentionInteractionResolver-CBjNuhYo.js} +1 -1
  22. package/dist/assets/{AuditHub-Dz2UXl0c.js → AuditHub-DbUni0O_.js} +1 -1
  23. package/dist/assets/{BoardChat-DsMVXf5M.js → BoardChat-CgzCuFIL.js} +1 -1
  24. package/dist/assets/{BootstrapSetupUxLab-CWWisaHp.js → BootstrapSetupUxLab-D-niQCV5.js} +1 -1
  25. package/dist/assets/{Browse-Be6aSv-F.js → Browse-0bmB5mqw.js} +1 -1
  26. package/dist/assets/{BudgetPolicyCard-Dka022-Z.js → BudgetPolicyCard-CqFUHqOj.js} +1 -1
  27. package/dist/assets/{CaseDetail-DdJrlm0m.js → CaseDetail-DakrB2jI.js} +1 -1
  28. package/dist/assets/{Cases-Da1szfrr.js → Cases-DXbr4HJt.js} +1 -1
  29. package/dist/assets/{ChatEndpointDetail-DSOH-zfs.js → ChatEndpointDetail-BdDKo-Gq.js} +1 -1
  30. package/dist/assets/{ChatEndpointSetup-J23lq-xi.js → ChatEndpointSetup-BX3iDH7N.js} +1 -1
  31. package/dist/assets/{ChoiceControls-B9yrYshK.js → ChoiceControls-Bu-fd6qI.js} +1 -1
  32. package/dist/assets/{Companies-BkHWSxdB.js → Companies-FcUNLIkt.js} +1 -1
  33. package/dist/assets/{CompanyAccess-BaiGlxY1.js → CompanyAccess-BUcTNg7_.js} +1 -1
  34. package/dist/assets/{CompanyActivity-CMBXXwCw.js → CompanyActivity-ScpRBz1G.js} +1 -1
  35. package/dist/assets/{CompanyConnections-CVzsivTW.js → CompanyConnections-DMEwbZv7.js} +1 -1
  36. package/dist/assets/{CompanyEnvironments-K7piWRrx.js → CompanyEnvironments-EqXhVruZ.js} +1 -1
  37. package/dist/assets/{CompanyExport-Bo8tUPaY.js → CompanyExport-DQ9ffuua.js} +1 -1
  38. package/dist/assets/{CompanyImport-CBVjSXPA.js → CompanyImport-BhuZu4oc.js} +1 -1
  39. package/dist/assets/{CompanySettings-CuU9qSp5.js → CompanySettings-BSkg4ahA.js} +1 -1
  40. package/dist/assets/{CompanySettingsPluginPage-59_bMQQ3.js → CompanySettingsPluginPage-BzZkZqh-.js} +1 -1
  41. package/dist/assets/{CompanySkills-GBJMThWx.js → CompanySkills-BbA4RKIw.js} +1 -1
  42. package/dist/assets/{ConfigureBuiltInAgentModal-D8Xnl51H.js → ConfigureBuiltInAgentModal-BUJPbmWc.js} +1 -1
  43. package/dist/assets/{CopyableGatewayUrl-GuvA-DoQ.js → CopyableGatewayUrl-BZyE_jT9.js} +1 -1
  44. package/dist/assets/{Dashboard-Cgj9BeTt.js → Dashboard--lTwxjV-.js} +1 -1
  45. package/dist/assets/{DashboardLive-Ku1cHAj9.js → DashboardLive-BYyTgF5d.js} +1 -1
  46. package/dist/assets/{DecisionDateChips-Z97mgInq.js → DecisionDateChips-vXwAFdua.js} +1 -1
  47. package/dist/assets/{DecisionQueuePage-D8cyKm4V.js → DecisionQueuePage-BaaKuZBi.js} +1 -1
  48. package/dist/assets/{DesignGuide-DvO3NaE-.js → DesignGuide-DS6MuXWY.js} +1 -1
  49. package/dist/assets/{EmailEndpointSetup-Cm_KKjjw.js → EmailEndpointSetup-CJFYu2G0.js} +1 -1
  50. package/dist/assets/{ExecutionWorkspaceDetail-CVB4ZY8I.js → ExecutionWorkspaceDetail-CuD5xWOB.js} +1 -1
  51. package/dist/assets/{GatewayDetail-DB1J44bF.js → GatewayDetail-xNVOxSIs.js} +1 -1
  52. package/dist/assets/{GatewaysList-CKSwMmOi.js → GatewaysList-DsSKLm1h.js} +1 -1
  53. package/dist/assets/{GoalDetail-Bscma2qU.js → GoalDetail-oN5pyUUY.js} +1 -1
  54. package/dist/assets/{GoalTree-jEFB788p.js → GoalTree-DaFizciF.js} +1 -1
  55. package/dist/assets/{Goals-jLNZ4UKT.js → Goals-xgGKfQZi.js} +1 -1
  56. package/dist/assets/{ImageGalleryModal-CghUxjQC.js → ImageGalleryModal-CjHED0Lb.js} +1 -1
  57. package/dist/assets/{Inbox-DHwNNh-Z.js → Inbox-wHhHozfr.js} +1 -1
  58. package/dist/assets/{InstanceAdvanced-C5IIPBwh.js → InstanceAdvanced-Bdf2a4c_.js} +1 -1
  59. package/dist/assets/{InviteLanding-BHmCRaWY.js → InviteLanding-McBYpNeW.js} +1 -1
  60. package/dist/assets/{IssueChatLongThreadPerf-JH8rtLk0.js → IssueChatLongThreadPerf-DD3RLbBo.js} +1 -1
  61. package/dist/assets/{IssueChatThread-ByTyrsxz.js → IssueChatThread-BN-_8hT8.js} +1 -1
  62. package/dist/assets/{IssueDetail-BIif8Swu.js → IssueDetail-CsaD311l.js} +1 -1
  63. package/dist/assets/{IssueOutputSection-CFE6aU9L.js → IssueOutputSection-CDIMRaF0.js} +1 -1
  64. package/dist/assets/{IssueRecoveryActionCard-DBgE7aMm.js → IssueRecoveryActionCard-C9qJAHes.js} +1 -1
  65. package/dist/assets/{IssueThreadInteractionCard-C3LFe8cu.js → IssueThreadInteractionCard-BbigJB2U.js} +1 -1
  66. package/dist/assets/{Issues-B5QG33RC.js → Issues-BWoc80Y9.js} +1 -1
  67. package/dist/assets/{LiveNowTodoLine-D52WDE8-.js → LiveNowTodoLine-B9oTH2L0.js} +1 -1
  68. package/dist/assets/{ManagedAiConnectionDetails-C9nV0oIT.js → ManagedAiConnectionDetails-B0aWUPkf.js} +1 -1
  69. package/dist/assets/{McpConnect-Bk8Qskqw.js → McpConnect-Dzf7W2K6.js} +1 -1
  70. package/dist/assets/{MembershipAction-DjdBY6Bk.js → MembershipAction-oiLtxQm3.js} +1 -1
  71. package/dist/assets/{ModelsAndProviders-BtbhNxf_.js → ModelsAndProviders-BEb4Z38S.js} +1 -1
  72. package/dist/assets/{NewAgent-C4JqnMkp.js → NewAgent-C3MxIRJj.js} +1 -1
  73. package/dist/assets/{OmpAllSettings-aHENTYf5.js → OmpAllSettings-DBtL1qDL.js} +1 -1
  74. package/dist/assets/{PipelineSettings-CCoxV9Es.js → PipelineSettings-BcAtsehE.js} +1 -1
  75. package/dist/assets/{Pipelines-DaQPh688.js → Pipelines-CkiYUQS-.js} +1 -1
  76. package/dist/assets/{PixelsOffice-D1X7mdpk.js → PixelsOffice-BSlctoug.js} +1 -1
  77. package/dist/assets/{PluginPage-B4kdPADI.js → PluginPage-C6Qnf9ka.js} +1 -1
  78. package/dist/assets/{PluginSettings-yP8NX-sM.js → PluginSettings-Do37r6Zu.js} +1 -1
  79. package/dist/assets/{ProfileDetailRoute-DMdAvFmb.js → ProfileDetailRoute-DRFQNId6.js} +1 -1
  80. package/dist/assets/{ProfileSettings-DVm3Tqzs.js → ProfileSettings-BMwLBQDB.js} +1 -1
  81. package/dist/assets/{ProfileWizardRoute-CijS7-aN.js → ProfileWizardRoute-XnnvzH9S.js} +1 -1
  82. package/dist/assets/{ProjectDetail-DeLSGbmz.js → ProjectDetail-BW6Lr4Iq.js} +1 -1
  83. package/dist/assets/{ProjectWorkspaceDetail-DPajDjA-.js → ProjectWorkspaceDetail-DR4JCa1b.js} +1 -1
  84. package/dist/assets/{ProjectWorkspacesContent-BCATCcZI.js → ProjectWorkspacesContent-CadPZn0k.js} +1 -1
  85. package/dist/assets/{Projects-DPmo6PFV.js → Projects-DLBFbxcj.js} +1 -1
  86. package/dist/assets/{PublicIssueSharePage-B_W1Qpy_.js → PublicIssueSharePage-C9yRZOdP.js} +1 -1
  87. package/dist/assets/{ReviewQueueCard-DhfCjwYP.js → ReviewQueueCard-CIkiY-Lm.js} +1 -1
  88. package/dist/assets/{RichWorkProductCard-rJC8tWnB.js → RichWorkProductCard-JGHGU_RI.js} +1 -1
  89. package/dist/assets/{RoutineDetail-Cb0oYk5B.js → RoutineDetail-izWzADvA.js} +1 -1
  90. package/dist/assets/{RoutineRunVariablesDialog-CWNUGmiH.js → RoutineRunVariablesDialog-DiT_o5Dm.js} +1 -1
  91. package/dist/assets/{Routines-Ct6W3Ht-.js → Routines-CHtabiYj.js} +1 -1
  92. package/dist/assets/{ScrollToBottom-BvL4b3BQ.js → ScrollToBottom-pyHLjOjY.js} +1 -1
  93. package/dist/assets/{Search-CXiBakEC.js → Search-yNNB6kys.js} +1 -1
  94. package/dist/assets/{Secrets-XUpMCMhK.js → Secrets-BOyOk5BF.js} +1 -1
  95. package/dist/assets/{SkillSourceTree-Brg47aIX.js → SkillSourceTree-M58QwBFF.js} +1 -1
  96. package/dist/assets/{SkillSources-C3kuN9Hz.js → SkillSources-Cw4PU-Bz.js} +1 -1
  97. package/dist/assets/{SkillStudio-DVVVKjdn.js → SkillStudio-Cj_M3ZJa.js} +1 -1
  98. package/dist/assets/{SourceTrustBadge-D-MXuX_l.js → SourceTrustBadge-BZBQe5No.js} +1 -1
  99. package/dist/assets/{StatusCards-BmNOGr1d.js → StatusCards-DaJdQUN5.js} +1 -1
  100. package/dist/assets/{SummarySlotCard-DiTaQ4km.js → SummarySlotCard-DlSmN6PL.js} +1 -1
  101. package/dist/assets/{TaskChatLab-fOJfHKjI.js → TaskChatLab-CU5eA7nX.js} +1 -1
  102. package/dist/assets/{TaskChatMarker-Cgyrmeab.js → TaskChatMarker-wBVUFL3u.js} +1 -1
  103. package/dist/assets/{TaskChatProtocolCard-DrIe_IYV.js → TaskChatProtocolCard-D-Dwy2EL.js} +1 -1
  104. package/dist/assets/{TaskChatThreadView-DKqNA1fZ.js → TaskChatThreadView-Crlf9I05.js} +1 -1
  105. package/dist/assets/{TaskDetailRelationsPanel-C9mJfMvL.js → TaskDetailRelationsPanel-CkktN1EC.js} +1 -1
  106. package/dist/assets/{TaskTreeControls-B1CSnDVK.js → TaskTreeControls-B_ulMOi1.js} +1 -1
  107. package/dist/assets/{Terminal-CGmILZtz.js → Terminal-Bo-WuezO.js} +1 -1
  108. package/dist/assets/{TerminalView-BqCU9Vc3.js → TerminalView-AkFY5bLC.js} +1 -1
  109. package/dist/assets/{TrustPresetSection-D4qB_VZo.js → TrustPresetSection-DTc1Rj4q.js} +1 -1
  110. package/dist/assets/{UserProfile-Cavc3nhB.js → UserProfile-C6q55R0Q.js} +1 -1
  111. package/dist/assets/{WhatNeedsMe-B7BSt_wb.js → WhatNeedsMe-1igJA4gL.js} +1 -1
  112. package/dist/assets/{Workspaces-CDTiwIHd.js → Workspaces-rtQKliW0.js} +1 -1
  113. package/dist/assets/{connection-owner-Cx9obLlP.js → connection-owner-CZwxTEuM.js} +1 -1
  114. package/dist/assets/{index-B7mmhFG7.js → index-DDoARkPG.js} +3 -3
  115. package/dist/assets/{issue-properties-C_y5-tny.js → issue-properties-lmRBaUTG.js} +1 -1
  116. package/dist/assets/{issue-workspace-selection-ChtddJZC.js → issue-workspace-selection-4JI2Uh9p.js} +1 -1
  117. package/dist/assets/{pipeline-stage-presentation-jxAxpF6f.js → pipeline-stage-presentation-BSuBql6K.js} +1 -1
  118. package/dist/assets/{shared-hwt7Xn4W.js → shared-DDwmHbeD.js} +1 -1
  119. package/dist/assets/{tool-taxonomy-6170LibQ.js → tool-taxonomy-DR7Q8sVs.js} +1 -1
  120. package/dist/assets/{transcript-adapter-C9uEslxp.js → transcript-adapter-wiFIjKfq.js} +1 -1
  121. package/dist/assets/{useSummaryDraftStream-BulT3Wwh.js → useSummaryDraftStream-CWOQt25o.js} +1 -1
  122. package/dist/index.html +1 -1
  123. package/dist/sw.js +1 -1
  124. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- var As=Object.defineProperty;var n=(t,a)=>As(t,"name",{value:a,configurable:!0});import{i as zt}from"./rolldown-runtime-ZpX3ckPj.js";import{O as He,Vi as Ts,Wi as _e,l as $,na as Bs,t as Qt,ta as Ps}from"./createLucideIcon-DJi9suAC.js";import{h as Es,n as jt,v as Ks}from"./star-BZgQbzhV.js";import{X as Je,_ as ce,n as Vt,t as M,v as ae}from"./queryKeys-DYV5MhM_.js";import{n as Ls,t as _s}from"./IssueDocumentAnnotations-BVdH4RTa.js";import{n as Fs}from"./CompanyContext-CSrVsSze.js";import{a as Ze,ft as Os,r as Us,t as Ae,zt as J}from"./router-2UfGeejU.js";import{a as Ms,c as $e,i as be,n as $s,p as qt,r as Ht,t as Jt}from"./dropdown-menu-CqRAF7Oj.js";import{i as Fe,n as Oe,r as zs,t as Qs}from"./tabs-B2Os_leL.js";import{t as Nt}from"./MarkdownEditor-DXD-Cu3u.js";import{o as Ye,r as Ge,t as We}from"./popover-BhYHYj7q.js";import{t as Vs}from"./bot-C9arfJWx.js";import{t as ue}from"./check-Ctsrlfa-.js";import{t as Xe}from"./chevron-down-BCvxsWfI.js";import{t as qs}from"./MarkdownBody-BTjuUgFa.js";import{t as Zt}from"./copy-_wvZOjTe.js";import{t as Hs}from"./ellipsis-vertical-DWXPf6Ow.js";import{t as Js}from"./ellipsis-BTiLRUn4.js";import{t as Zs}from"./file-pen-line-DX6PZQXR.js";import{t as Yt}from"./file-text-Cw7ntqRx.js";import{i as ye,n as wt,r as Ys}from"./issue-properties-C_y5-tny.js";import{t as Gs}from"./list-filter-h7_mdWEH.js";import{t as I}from"./button-CMwV3L1P.js";import{t as ze}from"./plus-C6fnr28l.js";import{t as Ws}from"./thumbs-down-C2BkjZOy.js";import{t as Xs}from"./thumbs-up-OW2IsTL7.js";import{t as en}from"./trash-D7zTaHTj.js";import{t as tn}from"./user-Ccom_Ph0.js";import{t as sn}from"./x-DRDFdlYE.js";import{t as de}from"./badge-DuA2EgZC.js";import{a as Gt,i as nn,n as Wt,r as an,s as Xt,t as es}from"./dialog-CKUblzlR.js";import{t as Se}from"./input-DobnTAyB.js";import{n as rn}from"./BreadcrumbContext-BVZDZoC0.js";import{t as ln}from"./textarea-BRPEfJ-g.js";import{i as Ct,n as Dt,o as St,r as It,s as Rt}from"./select-V0Hm_q4f.js";import{t as At}from"./chip-DsDe6yck.js";import{t as et}from"./clipboard-CTLKYvRL.js";import{t as on}from"./card-Bru3x_SJ.js";import{t as cn}from"./StatusIcon-0GcYXDdN.js";import{Or as dn,Ra as un,_ as mn,pn as Qe,xa as xn}from"./index-B7mmhFG7.js";import{t as fn}from"./ImageGalleryModal-CghUxjQC.js";import{t as hn}from"./useAutosaveIndicator-DttGFwx7.js";import{t as pn}from"./FoldCurtain-DUAOdtCt.js";import{t as yn}from"./SourceTrustBadge-D-MXuX_l.js";import{t as ts}from"./IssueReferencePill-DAEplgLd.js";import{a as gn,i as ge,o as V,r as Tt,s as Bt,t as bn}from"./cases-m9RZ5Cym.js";import{n as vn,t as ss}from"./CaseIdentifierKey-D8Xi16PS.js";import{t as kn}from"./line-diff-DAcZgvm2.js";import{t as jn}from"./DocumentFrameHeader-DTSqcw4Q.js";var ns={name:"diff",size:24,node:[["path",{d:"M12 3v14",key:"7cf3v8"}],["path",{d:"M5 10h14",key:"elsbfy"}],["path",{d:"M5 21h14",key:"11awu3"}]]};ns.node;var Nn=Qt(ns),is={name:"lock-open",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],aliases:["unlock"]};is.node;var wn=Qt(is),o=zt(Bs(),1),e=zt(Ps(),1),Cn=/^https?:\/\/\S+$/i,Dn=/^[A-Z][A-Z0-9]*-C\d+$/,Sn=/^[A-Z][A-Z0-9]*-\d+$/,In=/\b[A-Z][A-Z0-9]*-\d+\b/g;function Rn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}n(Rn,"isPlainObject");function Ie(){return(0,e.jsx)("span",{className:"text-ink-3",children:"—"})}n(Ie,"EmptyValue");function An(t){if(!t)return!1;const a=t.toLowerCase().replace(/[^a-z0-9]/g,"");return a.includes("issueidentifier")||a.includes("taskidentifier")}n(An,"isIssueIdentifierField");function as(t){return typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t,null,2)}n(as,"stringifyCopyValue");function Tn(t,a){if(!An(a))return typeof t=="string"&&Sn.test(t.trim())?[t.trim()]:[];const r=[],m=n(x=>{if(typeof x=="string")for(const c of x.matchAll(In))r.push(c[0])},"add");return Array.isArray(t)?t.forEach(m):m(t),[...new Set(r)]}n(Tn,"extractIssueIdentifiers");function Bn({identifiers:t}){return(0,e.jsx)("span",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:t.map(a=>(0,e.jsx)(ts,{issue:{id:a,identifier:a,title:a}},a))})}n(Bn,"IssueIdentifierValue");function Re({value:t,children:a,className:r}){const m=as(t),[x,c]=(0,o.useState)(!1),h=(0,o.useRef)(void 0);(0,o.useEffect)(()=>()=>clearTimeout(h.current),[]);const d=(0,o.useCallback)(()=>{et(m).then(()=>{c(!0),clearTimeout(h.current),h.current=setTimeout(()=>c(!1),1500)})},[m]);return(0,e.jsxs)("span",{className:"relative inline-flex min-w-0 max-w-full",children:[(0,e.jsx)("button",{type:"button",className:$("min-w-0 max-w-full cursor-copy truncate text-left transition-colors hover:text-ink",r),title:m,onClick:d,children:a}),x?(0,e.jsxs)("span",{role:"status","aria-live":"polite",className:"pointer-events-none absolute bottom-full left-1/2 mb-1.5 inline-flex -translate-x-1/2 items-center gap-1 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-bg",children:[(0,e.jsx)(ue,{className:"h-3 w-3 shrink-0"}),"Copied"]}):null]})}n(Re,"CopyableCompactValue");function Pn({value:t,variant:a}){const r=Ze(),m=t.trim();return m===""?(0,e.jsx)(Ie,{}):Cn.test(m)?(0,e.jsxs)("a",{href:m,target:"_blank",rel:"noreferrer",className:$("inline-flex max-w-full items-center gap-0.5 text-sm text-accent hover:underline",a==="compact"?"truncate":"break-all"),title:m,children:[(0,e.jsx)("span",{className:a==="compact"?"truncate":"break-all",children:m}),(0,e.jsx)("span",{"aria-hidden":!0,children:"↗"})]}):Dn.test(m)?(0,e.jsx)(Ae,{to:r(m),className:"font-mono text-sm text-accent hover:underline",children:m}):a==="compact"?(0,e.jsx)(Re,{value:t,className:"text-sm",children:t}):(0,e.jsx)("span",{className:"text-sm break-words",children:t})}n(Pn,"StringValue");function rs({value:t,fieldKey:a,variant:r="full"}){if(t==null)return(0,e.jsx)(Ie,{});const m=Tn(t,a);if(m.length>0)return(0,e.jsx)(Bn,{identifiers:m});if(typeof t=="string")return(0,e.jsx)(Pn,{value:t,variant:r});if(typeof t=="number")return Number.isFinite(t)?r==="compact"?(0,e.jsx)(Re,{value:t,className:"text-sm tabular-nums",children:t.toLocaleString()}):(0,e.jsx)("span",{className:"text-sm tabular-nums",children:t.toLocaleString()}):(0,e.jsx)("span",{className:"text-sm",children:String(t)});if(typeof t=="boolean")return t?(0,e.jsx)(ue,{className:"h-4 w-4 text-green-600 dark:text-green-400","aria-label":"true"}):(0,e.jsx)(Ie,{});if(Array.isArray(t))return t.length===0?(0,e.jsx)(Ie,{}):r==="compact"?(0,e.jsx)(Re,{value:t,className:"text-sm text-ink-3",children:as(t)}):(0,e.jsx)("div",{className:"flex flex-wrap justify-start gap-1",children:t.map((x,c)=>(0,e.jsx)(de,{variant:"secondary",className:"font-normal",children:typeof x=="string"||typeof x=="number"||typeof x=="boolean"?String(x):JSON.stringify(x)},c))});if(Rn(t)){const x=JSON.stringify(t);return r==="compact"?(0,e.jsx)(Re,{value:t,className:"font-mono text-xs text-ink-3",children:x}):(0,e.jsx)("pre",{className:"max-w-full whitespace-pre-wrap break-words font-mono text-xs text-ink-3",children:JSON.stringify(t,null,2)})}return(0,e.jsx)("span",{className:"text-sm",children:String(t)})}n(rs,"CaseFieldValue");var Ve={created:"created",updated:"updated",fields_changed:"fields changed",status_changed:"status changed",issue_linked:"issue linked",issue_unlinked:"issue unlinked",document_revised:"document revised",child_linked:"child linked",attachment_added:"attachment added",label_added:"label added",label_removed:"label removed"};function En(t){return t.actorType==="agent"?t.actorAgentName??"Agent":t.actorType==="user"?"User":"System"}n(En,"actorLabel");function Kn({event:t}){const a=t.actorType==="agent"?Vs:t.actorType==="user"?tn:Os;return(0,e.jsx)(a,{className:"h-3.5 w-3.5 shrink-0 text-ink-3","aria-hidden":!0})}n(Kn,"ActorIcon");function Ln(t){return t.kind==="issue_linked"||t.kind==="issue_unlinked"?"issue":"via"}n(Ln,"issueRelationLabel");function _n({event:t,compact:a=!1}){const r=t.kind==="status_changed"&&t.payload?`${t.payload.previousStatus??"?"} → ${t.payload.status??"?"}`:"";return(0,e.jsxs)("div",{className:$("flex items-start gap-2 text-xs",a?"py-1.5":"py-2"),children:[(0,e.jsx)("span",{className:"mt-1",children:(0,e.jsx)(Kn,{event:t})}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-1.5",children:[(0,e.jsx)("span",{className:"font-medium",children:Ve[t.kind]??t.kind}),r&&(0,e.jsxs)("span",{className:"text-ink-3",children:["· ",r]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-x-1.5 text-ink-3",children:[(0,e.jsx)("span",{children:En(t)}),t.issue&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{"aria-hidden":!0,children:"·"}),(0,e.jsx)("span",{children:Ln(t)}),(0,e.jsxs)(Ae,{to:`/issues/${t.issue.identifier}`,className:"inline-flex min-w-0 items-center gap-1 text-ink/80 hover:underline",title:t.issue.title,children:[(0,e.jsx)(cn,{status:t.issue.status,size:"sm"}),(0,e.jsx)("span",{className:"shrink-0 font-mono",children:t.issue.identifier}),(0,e.jsx)("span",{className:"min-w-0 truncate",children:t.issue.title})]})]}),(0,e.jsx)("span",{"aria-hidden":!0,children:"·"}),(0,e.jsx)("span",{children:He(t.createdAt)})]})]})]})}n(_n,"CaseEventRow");function Fn({events:t}){const[a,r]=(0,o.useState)(new Set),m=(0,o.useMemo)(()=>{const d=[];for(const N of t)d.includes(N.kind)||d.push(N.kind);return d},[t]),x=(0,o.useMemo)(()=>a.size===0?t:t.filter(d=>a.has(d.kind)),[t,a]);function c(d){r(N=>{const g=new Set(N);return g.has(d)?g.delete(d):g.add(d),g})}n(c,"toggle");const h=a.size===0?"All activity":a.size===1?Ve[[...a][0]]??[...a][0]:`${a.size} filters`;return t.length===0?(0,e.jsx)("p",{className:"py-6 text-center text-sm text-ink-3",children:"No activity yet."}):(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsxs)("p",{className:"text-xs text-ink-3",children:[x.length," of ",t.length," events"]}),(0,e.jsxs)(Jt,{children:[(0,e.jsx)(qt,{asChild:!0,children:(0,e.jsxs)(I,{variant:"secondary",size:"sm",className:"h-8 gap-1.5",children:[(0,e.jsx)(Gs,{className:"h-3.5 w-3.5"}),h,(0,e.jsx)(Xe,{className:"h-3.5 w-3.5 text-ink-3"})]})}),(0,e.jsxs)(Ht,{align:"end",className:"w-56",children:[(0,e.jsx)(Ms,{children:"Activity filter"}),(0,e.jsx)(be,{onSelect:n(()=>r(new Set),"onSelect"),children:"All activity"}),(0,e.jsx)($e,{}),m.map(d=>(0,e.jsx)($s,{checked:a.has(d),onCheckedChange:n(()=>c(d),"onCheckedChange"),children:Ve[d]??d},d))]})]})]}),x.length===0?(0,e.jsx)("p",{className:"py-6 text-center text-sm text-ink-3",children:"No events match this filter."}):(0,e.jsx)("div",{className:"divide-y divide-line",children:x.map(d=>(0,e.jsx)(_n,{event:d},d.id))})]})}n(Fn,"CaseActivityFeed");function qe({children:t,maxVisible:a}){const r=Ze(),[m,x]=(0,o.useState)(!1);if(t.length===0)return(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"No child cases."});const c=a!=null&&t.length>a&&!m?t.slice(0,a):t,h=t.length-c.length;return(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("ul",{className:"space-y-1",children:c.map(d=>(0,e.jsx)("li",{children:(0,e.jsxs)(Ae,{to:r(d.identifier),className:"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-bg-3/50",children:[(0,e.jsx)(ss,{value:d.identifier,label:"case ID",className:"shrink-0 font-mono text-xs text-ink-3",containerClassName:"shrink-0",stopPropagation:!0}),(0,e.jsx)("span",{className:"min-w-0 flex-1 truncate",title:d.title,children:d.title}),(0,e.jsx)(de,{variant:"secondary",className:"shrink-0",children:d.caseType}),(0,e.jsx)(Qe,{status:d.status})]})},d.id))}),h>0?(0,e.jsxs)(I,{type:"button",variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-xs",onClick:n(()=>x(!0),"onClick"),children:[(0,e.jsx)(Xe,{className:"h-3.5 w-3.5"}),"Show ",h," more"]}):null]})}n(qe,"CaseChildrenTree");function On(t){return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(0)} KB`:`${(t/1048576).toFixed(1)} MB`}n(On,"humanBytes");function Un({attachments:t}){const[a,r]=(0,o.useState)(null),m=(0,o.useMemo)(()=>t.filter(Bt).map(x=>({id:x.id,contentPath:Tt(x),contentType:x.asset.contentType,originalFilename:x.asset.originalFilename})),[t]);return t.length===0?(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"No attachments."}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-4",children:t.map(x=>{const c=Bt(x),h=x.asset.originalFilename??"attachment",d=c?m.findIndex(N=>N.id===x.id):-1;return(0,e.jsxs)("button",{type:"button",onClick:n(()=>c&&d>=0&&r(d),"onClick"),disabled:!c,title:h,className:$("group relative flex aspect-square flex-col overflow-hidden rounded-lg border border-line bg-bg-3/40 text-left",c&&"cursor-pointer hover:border-accent/50"),children:[c?(0,e.jsx)("img",{src:Tt(x),alt:h,loading:"lazy",className:"h-full w-full object-cover transition-transform group-hover:scale-(--s-1_02)"}):(0,e.jsxs)("div",{className:"flex h-full w-full flex-col items-center justify-center gap-1 p-2 text-ink-3",children:[(0,e.jsx)(Yt,{className:"h-6 w-6","aria-hidden":!0}),(0,e.jsx)("span",{className:"w-full truncate text-center text-(length:--text-micro)",children:h})]}),(0,e.jsx)("span",{className:"pointer-events-none absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/60 to-transparent px-1.5 py-1 text-(length:--text-nano) text-white/90",children:On(x.asset.byteSize)})]},x.id)})}),a!==null&&(0,e.jsx)(fn,{items:m,initialIndex:a,open:a!==null,onOpenChange:n(x=>!x&&r(null),"onOpenChange")})]})}n(Un,"CaseAttachmentsGallery");function Pt(t){if(!t)return 0;const a=new Date(t).getTime();return Number.isNaN(a)?0:a}n(Pt,"toTimestamp");function Et(t){return[...t].sort((a,r)=>{if(a.revisionNumber!==r.revisionNumber)return r.revisionNumber-a.revisionNumber;const m=Pt(r.createdAt)-Pt(a.createdAt);return m!==0?m:r.id.localeCompare(a.id)})}n(Et,"sortRevisionsDescending");function Mn(t){return{id:t.latestRevisionId??`${t.id}-latest`,companyId:t.companyId,documentId:t.id,issueId:t.issueId,key:t.key,revisionNumber:t.latestRevisionNumber,title:t.title,format:t.format,body:t.body,changeSummary:null,createdByAgentId:t.updatedByAgentId??t.createdByAgentId,createdByUserId:t.updatedByUserId??t.createdByUserId,createdAt:t.updatedAt}}n(Mn,"createCurrentRevisionSnapshot");function Kt(t,a){const r=Et(a),m=Mn(t),x=r[0]??null,c=x&&x.revisionNumber>t.latestRevisionNumber?x:r.find(g=>g.id===t.latestRevisionId)??m,h=Et([c,...r]),d=[],N=new Set;for(const g of h)N.has(g.id)||(N.add(g.id),d.push(g));return{currentRevision:c,revisions:d}}n(Kt,"deriveDocumentRevisionState");function $n({activeVote:t,disabled:a=!1,sharingPreference:r="prompt",termsUrl:m=null,onVote:x,rightSlot:c,inline:h=!1}){const[d,N]=(0,o.useState)(null),[g,p]=(0,o.useState)(!1),[A,E]=(0,o.useState)(""),[K,L]=(0,o.useState)(!1),[B,b]=(0,o.useState)(void 0),[C,O]=(0,o.useState)(null),f=C??t??null;(0,o.useEffect)(()=>{C&&t===C&&O(null)},[t,C]);async function q(k,y,v){p(!0);try{await x(k,y),N(null),v?.keepReasonPromptOpen||(L(!1),E(""),b(void 0))}catch(R){throw O(null),R}finally{p(!1)}}n(q,"submitVote");function X(k,y,v){if(r==="prompt"){N({vote:k,...y?{reason:y}:{},...v?.keepReasonPromptOpen?{keepReasonPromptOpen:!0}:{}});return}const R=r==="allowed";k==="down"&&b(R),q(k,{...R?{allowSharing:!0}:{},...y?{reason:y}:{}},v)}n(X,"beginVote");function l(k){if(O(k),k==="down"){L(!0),E(""),b(void 0),X("down",void 0,{keepReasonPromptOpen:!0});return}X(k)}return n(l,"handleVote"),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:$("flex items-center gap-2",h?"justify-end":"mt-3 border-t border-line/60 pt-3"),children:[(0,e.jsxs)(At,{selected:f==="up",disabled:a||g,onClick:n(()=>l("up"),"onClick"),children:[(0,e.jsx)(Xs,{"aria-hidden":!0}),"Helpful"]}),(0,e.jsxs)(At,{selected:f==="down",disabled:a||g,onClick:n(()=>l("down"),"onClick"),children:[(0,e.jsx)(Ws,{"aria-hidden":!0}),"Needs work"]}),c?(0,e.jsx)("div",{className:"ml-auto",children:c}):null]}),K?(0,e.jsxs)("div",{className:"mt-2 rounded-md border border-line/60 bg-bg-3/20 p-3",children:[(0,e.jsx)("div",{className:"mb-2 text-sm font-medium",children:"What could have been better?"}),(0,e.jsx)(ln,{value:A,onChange:n(k=>E(k.target.value),"onChange"),placeholder:"Add a short note",className:"min-h-20 resize-y bg-bg",disabled:a||g}),(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-end gap-2",children:[(0,e.jsx)(I,{type:"button",size:"sm",variant:"secondary",disabled:a||g,onClick:n(()=>{L(!1),E(""),b(void 0)},"onClick"),children:"Dismiss"}),(0,e.jsx)(I,{type:"button",size:"sm",disabled:a||g||!A.trim(),onClick:n(()=>{q("down",{...B?{allowSharing:!0}:{},reason:A})},"onClick"),children:g?"Saving...":"Save note"})]})]}):null,(0,e.jsx)(es,{open:!!d,onOpenChange:n(k=>{!k&&!g&&(N(null),O(null))},"onOpenChange"),children:(0,e.jsxs)(Wt,{children:[(0,e.jsxs)(Gt,{children:[(0,e.jsx)(Xt,{children:"Save your feedback sharing preference"}),(0,e.jsx)(an,{children:"Choose whether voted AI outputs can be included in this instance's feedback export. This answer becomes the default for future thumbs up and thumbs down votes."})]}),(0,e.jsxs)("div",{className:"space-y-3 text-sm text-ink-3",children:[(0,e.jsx)("p",{children:"This vote is always saved locally."}),(0,e.jsxs)("p",{children:["Choose ",(0,e.jsx)("span",{className:"font-medium text-ink",children:"Always allow"})," to share this vote and future voted AI outputs. Choose"," ",(0,e.jsx)("span",{className:"font-medium text-ink",children:"Don't allow"})," to keep this vote and future votes local."]}),(0,e.jsx)("p",{children:"You can change this later in Settings > General."}),m?(0,e.jsx)("a",{href:m,target:"_blank",rel:"noreferrer",className:"inline-flex text-sm text-ink underline underline-offset-4",children:"Read our terms of service"}):null]}),(0,e.jsxs)(nn,{children:[(0,e.jsx)(I,{type:"button",variant:"secondary",disabled:!d||g,onClick:n(()=>{d&&(d.vote==="down"&&b(!1),q(d.vote,d.reason?{reason:d.reason}:void 0,{keepReasonPromptOpen:d.keepReasonPromptOpen}))},"onClick"),children:g?"Saving...":"Don't allow"}),(0,e.jsx)(I,{type:"button",disabled:!d||g,onClick:n(()=>{d&&(d.vote==="down"&&b(!0),q(d.vote,{allowSharing:!0,...d.reason?{reason:d.reason}:{}},{keepReasonPromptOpen:d.keepReasonPromptOpen}))},"onClick"),children:g?"Saving...":"Always allow"})]})]})})]})}n($n,"OutputFeedbackButtons");function Lt(t){const a=t.createdByUserId?"board":t.createdByAgentId?"agent":"system";return`rev ${t.revisionNumber} — ${He(t.createdAt)} • ${a}`}n(Lt,"getRevisionLabel");function zn({issueId:t,documentKey:a,latestRevisionNumber:r,open:m,onOpenChange:x,revisionsQueryKey:c,revisionsQueryFn:h}){const{data:d}=ae({queryKey:c??M.issues.documentRevisions(t??"",a),queryFn:n(()=>h?h():J.listDocumentRevisions(t??"",a),"queryFn"),enabled:m}),N=(0,o.useMemo)(()=>d?[...d].sort((l,k)=>k.revisionNumber-l.revisionNumber):[],[d]),[g,p]=(0,o.useState)(null),[A,E]=(0,o.useState)(null),K=g??N.find(l=>l.revisionNumber===r-1)?.id??null,L=A??N.find(l=>l.revisionNumber===r)?.id??null,B=N.find(l=>l.id===K)??null,b=N.find(l=>l.id===L)??null,C=B?.body??"",O=b?.body??"",f=(0,o.useMemo)(()=>kn(C,O),[C,O]),q={context:"bg-transparent",removed:"bg-red-500/10 text-red-900 dark:text-red-100",added:"bg-green-500/10 text-green-900 dark:text-green-100"},X={context:" ",removed:"-",added:"+"};return(0,e.jsx)(es,{open:m,onOpenChange:x,children:(0,e.jsxs)(Wt,{className:"!max-w-(--pct-90) w-full max-h-(--sz-85vh) overflow-hidden flex flex-col",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,e.jsx)(Gt,{className:"shrink-0",children:(0,e.jsxs)(Xt,{children:["Diff — ",(0,e.jsx)("span",{className:"font-mono text-sm",children:a})]})}),(0,e.jsxs)("div",{className:"flex items-center gap-4 shrink-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(de,{variant:"outline",className:"border-red-500/30 bg-red-500/10 text-(length:--text-nano) uppercase tracking-wider text-red-400",children:"Old"}),(0,e.jsxs)(Dt,{value:K??"",onValueChange:n(l=>p(l),"onValueChange"),children:[(0,e.jsx)(St,{className:"h-7 w-60 text-xs border-line/60",children:(0,e.jsx)(Rt,{placeholder:"Select revision"})}),(0,e.jsx)(It,{children:N.map(l=>(0,e.jsx)(Ct,{value:l.id,className:"text-xs",children:Lt(l)},l.id))})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(de,{variant:"outline",className:"border-green-500/30 bg-green-500/10 text-(length:--text-nano) uppercase tracking-wider text-green-400",children:"New"}),(0,e.jsxs)(Dt,{value:L??"",onValueChange:n(l=>E(l),"onValueChange"),children:[(0,e.jsx)(St,{className:"h-7 w-60 text-xs border-line/60",children:(0,e.jsx)(Rt,{placeholder:"Select revision"})}),(0,e.jsx)(It,{children:N.map(l=>(0,e.jsx)(Ct,{value:l.id,className:"text-xs",children:Lt(l)},l.id))})]})]})]})]}),(0,e.jsx)("div",{className:"overflow-auto flex-1 rounded-md border border-line text-xs",children:d?!B||!b?(0,e.jsx)("div",{className:"p-6 text-center text-ink-3 text-sm",children:"Select two revisions to compare."}):B.id===b.id?(0,e.jsx)("div",{className:"p-6 text-center text-ink-3 text-sm",children:"Both sides are the same revision."}):(0,e.jsxs)("div",{className:"font-mono text-xs leading-6",children:[(0,e.jsxs)("div",{className:"grid grid-cols-(--gtc-1) border-b border-line/60 bg-bg-3/30 px-3 py-2 text-(length:--text-micro) uppercase tracking-wide text-ink-3",children:[(0,e.jsx)("span",{children:"Old"}),(0,e.jsx)("span",{children:"New"}),(0,e.jsx)("span",{}),(0,e.jsx)("span",{children:"Content"})]}),f.map((l,k)=>(0,e.jsxs)("div",{className:`grid grid-cols-(--gtc-1) gap-0 border-b border-line/30 px-3 ${q[l.kind]}`,children:[(0,e.jsx)("span",{className:"select-none border-r border-line/30 pr-3 text-right text-ink-3",children:l.oldLineNumber??""}),(0,e.jsx)("span",{className:"select-none border-r border-line/30 px-3 text-right text-ink-3",children:l.newLineNumber??""}),(0,e.jsx)("span",{className:"select-none px-3 text-center text-ink-3",children:X[l.kind]}),(0,e.jsx)("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-3 py-0 text-inherit",children:l.text.length>0?l.text:" "})]},`${l.kind}-${k}-${l.oldLineNumber??"x"}-${l.newLineNumber??"x"}`))]}):(0,e.jsx)("div",{className:"p-6 text-center text-ink-3 text-sm",children:"Loading revisions..."})})]})})}n(zn,"DocumentDiffModal");var Qn=900,_t=/^[a-z0-9][a-z0-9_-]*$/,ls=n(t=>`wardmote:issue-document-folds:${t}`,"getFoldedDocumentsStorageKey");function Ft(t){if(typeof window>"u")return[];try{const a=window.localStorage.getItem(ls(t));if(!a)return[];const r=JSON.parse(a);return Array.isArray(r)?r.filter(m=>typeof m=="string"):[]}catch{return[]}}n(Ft,"loadFoldedDocumentKeys");function Ot(t,a){typeof window>"u"||window.localStorage.setItem(ls(t),JSON.stringify(a))}n(Ot,"saveFoldedDocumentKeys");function De(t,a,r){return(0,e.jsx)(pn,{children:(0,e.jsx)(qs,{className:a,softBreaks:!1,externalReferences:r,children:t})})}n(De,"renderFoldableBody");function ne(t){return t.trim().toLowerCase()==="plan"}n(ne,"isPlanKey");function Vn(t,a){return(t??"").trim().toLowerCase()===a.trim().toLowerCase()}n(Vn,"titlesMatchKey");function qn(t){return t instanceof Vt&&t.status===409}n(qn,"isDocumentConflictError");function Hn(t){return t instanceof Vt&&t.status===409&&t.message==="Document is locked"}n(Hn,"isLockedDocumentError");function Jn(t,a){const r=new Blob([a],{type:"text/markdown;charset=utf-8"}),m=URL.createObjectURL(r),x=document.createElement("a");x.href=m,x.download=`${t}.md`,document.body.appendChild(x),x.click(),x.remove(),URL.revokeObjectURL(m)}n(Jn,"downloadDocumentFile");function Zn(t,a){if(t.createdByAgentId){const r=a.agentMap?.get(t.createdByAgentId);return{kind:"agent",name:r?.name??t.createdByAgentId.slice(0,8),agentIcon:r?.icon??null,agent:r??{id:t.createdByAgentId}}}if(t.createdByUserId){const r=a.userProfileMap?.get(t.createdByUserId);return{kind:"user",name:r?.label??(t.createdByUserId==="local-board"?"Board":t.createdByUserId.slice(0,8)),imageUrl:r?.image??null}}return{kind:"system",name:"System"}}n(Zn,"getRevisionActor");function Ut(t,a){return!a||a.isNew||a.key!==t.key?!1:a.body!==t.body||(t.title??"")!==a.title}n(Ut,"documentHasUnsavedChanges");function Yn(t){return{id:t.id,companyId:t.companyId,issueId:t.issueId,key:t.key,title:t.title,format:t.format,latestRevisionId:t.latestRevisionId,latestRevisionNumber:t.latestRevisionNumber,createdByAgentId:t.createdByAgentId,createdByUserId:t.createdByUserId,updatedByAgentId:t.updatedByAgentId,updatedByUserId:t.updatedByUserId,lockedAt:t.lockedAt,lockedByAgentId:t.lockedByAgentId,lockedByUserId:t.lockedByUserId,sourceTrust:t.sourceTrust,createdAt:t.createdAt,updatedAt:t.updatedAt}}n(Yn,"toDocumentSummary");function Gn(t){return{id:t.id,detailQueryKey:M.issues.detail(t.id),documentsQueryKey:M.issues.documents(t.id),idleDocumentRevisionsQueryKey:["issues","document-revisions",t.id,"__idle__"],documentRevisionsQueryKey:n(a=>M.issues.documentRevisions(t.id,a),"documentRevisionsQueryKey"),listDocuments:n(()=>J.listDocuments(t.id),"listDocuments"),listDocumentRevisions:n(a=>J.listDocumentRevisions(t.id,a),"listDocumentRevisions"),getDocument:n(a=>J.getDocument(t.id,a),"getDocument"),upsertDocument:n((a,r)=>J.upsertDocument(t.id,a,r),"upsertDocument"),deleteDocument:n(a=>J.deleteDocument(t.id,a),"deleteDocument"),restoreDocumentRevision:n((a,r)=>J.restoreDocumentRevision(t.id,a,r),"restoreDocumentRevision"),setDocumentLock:n((a,r)=>r?J.lockDocument(t.id,a):J.unlockDocument(t.id,a),"setDocumentLock"),syncDetailCache:n((a,r)=>{a.setQueryData(M.issues.detail(t.id),m=>{if(!m)return m;const x=(()=>{const c=Yn(r),h=(m.documentSummaries??[]).findIndex(d=>d.key===r.key);return h===-1?[...m.documentSummaries??[],c]:(m.documentSummaries??[]).map((d,N)=>N===h?c:d)})();return{...m,planDocument:r.key==="plan"?r:m.planDocument??null,documentSummaries:x,legacyPlanDocument:r.key==="plan"?null:m.legacyPlanDocument??null}})},"syncDetailCache"),hideSystemDocuments:!0,legacyPlanDocument:t.legacyPlanDocument,annotations:{issueId:t.id}}}n(Gn,"makeIssueDocumentSubject");function Wn({issue:t,subject:a,canDeleteDocuments:r,canManageDocumentLocks:m=!1,feedbackVotes:x=[],feedbackDataSharingPreference:c="prompt",feedbackTermsUrl:h=null,mentions:d,imageUploadHandler:N,onVote:g,extraActions:p,agentMap:A,userProfileMap:E,defaultAnnotationPanelOpenKeys:K,defaultAnnotationFocusedThreadIds:L,forceEditDocumentKey:B,externalReferences:b}){const C=Je(),O=Es(),f=(0,o.useMemo)(()=>{if(a)return a;if(!t)throw new Error("IssueDocumentsSection requires either issue or subject");return Gn(t)},[t,a]),q=(0,o.useCallback)(s=>{const i=f.annotations?.target;if(i)return typeof i=="function"?i(s):i.kind==="issue"?{...i,documentKey:s}:i.kind==="case"?{...i,documentKey:s}:i},[f]),[X,l]=(0,o.useState)(null),[k,y]=(0,o.useState)(null),[v,R]=(0,o.useState)(null),[D,_]=(0,o.useState)(null),[me,Z]=(0,o.useState)(()=>Ft(f.id)),[tt,st]=(0,o.useState)(()=>K??[]),[nt,Te]=(0,o.useState)(null),[it,at]=(0,o.useState)(null),[rt,lt]=(0,o.useState)(null),[Y,os]=(0,o.useState)(null),[cs,Be]=(0,o.useState)({}),[ot,ct]=(0,o.useState)(null),z=(0,o.useRef)(null),xe=(0,o.useRef)(null),Pe=(0,o.useRef)(!1),{state:te,markDirty:dt,reset:ut,runSave:mt}=hn(),{data:ve}=ae({queryKey:f.documentsQueryKey,queryFn:f.listDocuments}),{data:xt,isFetching:ds}=ae({queryKey:Y?f.documentRevisionsQueryKey(Y):f.idleDocumentRevisionsQueryKey,queryFn:n(async()=>Y?f.listDocumentRevisions(Y):[],"queryFn"),enabled:!!Y}),re=(0,o.useCallback)(()=>{f.detailQueryKey&&C.invalidateQueries({queryKey:f.detailQueryKey}),C.invalidateQueries({queryKey:f.documentsQueryKey}),C.invalidateQueries({predicate:n(s=>Array.isArray(s.queryKey)&&s.queryKey.includes(f.id)&&(s.queryKey.includes("document-revisions")||s.queryKey.includes("document-annotations")||s.queryKey.includes("revisions")),"predicate")})},[f,C]),ke=(0,o.useCallback)(s=>{f.hideSystemDocuments&&_e(s.key)||(C.setQueryData(f.documentsQueryKey,i=>{if(!i)return[s];const u=i.findIndex(j=>j.key===s.key);return u===-1?[...i,s]:i.map((j,w)=>w===u?s:j)}),f.syncDetailCache?.(C,s))},[f,C]),se=ce({mutationFn:n(async s=>f.upsertDocument(s.key,{title:ne(s.key)?null:s.title.trim()||null,format:"markdown",body:s.body,baseRevisionId:s.baseRevisionId}),"mutationFn")}),je=ce({mutationFn:n(s=>f.deleteDocument?f.deleteDocument(s):Promise.reject(new Error("Document deletion is not available")),"mutationFn"),onSuccess:n(()=>{y(null),l(null),re()},"onSuccess"),onError:n(s=>{y(s instanceof Error?s.message:"Failed to delete document")},"onError")}),Ne=ce({mutationFn:n(({key:s,revisionId:i})=>f.restoreDocumentRevision?f.restoreDocumentRevision(s,i):Promise.reject(new Error("Document revision restore is not available")),"mutationFn"),onSuccess:n((s,i)=>{ke(s),Be(u=>({...u,[i.key]:null})),R(u=>u?.key===i.key?null:u),_(u=>u?.key===i.key?null:u),P(),y(null),re()},"onSuccess"),onError:n(s=>{y(s instanceof Error?s.message:"Failed to restore document revision")},"onError")}),fe=ce({mutationFn:n(({key:s,locked:i})=>f.setDocumentLock?f.setDocumentLock(s,i):Promise.reject(new Error("Document locking is not available")),"mutationFn"),onSuccess:n(s=>{ke(s),R(i=>i?.key===s.key?null:i),_(i=>i?.key===s.key?null:i),P(),y(null),re()},"onSuccess"),onError:n(s=>{y(s instanceof Error?s.message:"Failed to update document lock")},"onError")}),U=(0,o.useMemo)(()=>(ve??[]).filter(s=>!f.hideSystemDocuments||!_e(s.key)).sort((s,i)=>s.key==="plan"&&i.key!=="plan"?-1:s.key!=="plan"&&i.key==="plan"?1:new Date(i.updatedAt).getTime()-new Date(s.updatedAt).getTime()),[f.hideSystemDocuments,ve]),us=(0,o.useMemo)(()=>{const s=new Map;for(const i of x)i.targetType==="issue_document_revision"&&s.set(i.targetId,i.vote);return s},[x]),ms=U.some(s=>s.key==="plan"),xs=U.length===0&&!f.legacyPlanDocument,ft=v?.isNew&&v.key.trim().length>0&&!_t.test(v.key.trim())?"Use lowercase letters, numbers, -, or _, and start with a letter or number.":null,P=(0,o.useCallback)(()=>{Te(null),ut()},[ut]),we=(0,o.useCallback)(s=>{Te(s),dt()},[dt]),ht=n(()=>{P(),_(null),R({key:"",title:"",body:"",baseRevisionId:null,isNew:!0}),y(null)},"beginNewDocument"),pt=n(s=>{const i=U.find(j=>j.key===s);if(!i)return;const u=D?.key===s?D.localDraft:null;Z(j=>j.filter(w=>w!==s)),P(),_(j=>j?.key===s?j:null),R({key:u?.key??i.key,title:u?.title??i.title??"",body:u?.body??i.body,baseRevisionId:u?.baseRevisionId??i.latestRevisionId,isNew:!1}),y(null)},"beginEdit"),yt=(0,o.useRef)(!1);(0,o.useEffect)(()=>{B&&(yt.current||(ve??[]).find(s=>s.key===B)&&(yt.current=!0,pt(B)))},[B,ve]);const gt=n(()=>{z.current&&clearTimeout(z.current),P(),_(null),R(null),y(null)},"cancelDraft"),G=(0,o.useCallback)(async(s,i)=>{if(!s||se.isPending)return!1;const u=s.key.trim().toLowerCase(),j=s.body.trim(),w=s.title.trim(),ee=D?.key===u?D:null;if(ee&&!i?.overrideConflict)return i?.trackAutosave&&P(),!1;if(!u||!j)return s.isNew?y("Document key and body are required"):j||y("Document body cannot be empty"),i?.trackAutosave&&P(),!1;if(!_t.test(u))return y("Document key must start with a letter or number and use only lowercase letters, numbers, -, or _."),i?.trackAutosave&&P(),!1;const le=U.find(T=>T.key===u);if(!s.isNew&&le&&le.body===s.body&&(le.title??"")===s.title)return i?.clearAfterSave&&R(T=>T?.key===u?null:T),i?.trackAutosave&&P(),!0;const he=n(async()=>{const T=await se.mutateAsync({...s,key:u,title:ne(u)?"":w,body:s.body,baseRevisionId:i?.overrideConflict?ee?.serverDocument.latestRevisionId??s.baseRevisionId:s.baseRevisionId});y(null),_(Q=>Q?.key===u?null:Q),R(Q=>!Q||Q.key!==u?Q:i?.clearAfterSave?null:{key:T.key,title:T.title??"",body:T.body,baseRevisionId:T.latestRevisionId,isNew:!1}),ke(T),re()},"save");try{return i?.trackAutosave?(Te(u),await mt(he)):await he(),!0}catch(T){if(Hn(T))return y("Document is locked. Unlock it before editing."),P(),re(),!1;if(qn(T))try{const Q=await f.getDocument(u);return _({key:u,serverDocument:Q,localDraft:{key:u,title:ne(u)?"":w,body:s.body,baseRevisionId:s.baseRevisionId,isNew:!1},showRemote:!0}),Z(H=>H.filter(F=>F!==u)),y(null),P(),!1}catch{return y("Document changed remotely and the latest version could not be loaded"),!1}return y(T instanceof Error?T.message:"Failed to save document"),!1}},[D,f,re,P,mt,U,ke,se]),fs=(0,o.useCallback)(s=>{if(D?.key!==s)return;const i=D.serverDocument;R({key:i.key,title:i.title??"",body:i.body,baseRevisionId:i.latestRevisionId,isNew:!1}),_(null),P(),y(null)},[D,P]),hs=(0,o.useCallback)(async s=>{if(D?.key!==s)return;const i=v&&v.key===s&&!v.isNew?v:D.localDraft;await G({...i,baseRevisionId:D.serverDocument.latestRevisionId},{clearAfterSave:!1,trackAutosave:!0,overrideConflict:!0})},[G,D,v]),ps=(0,o.useCallback)(s=>{D?.key===s&&(R(D.localDraft),_(i=>i?.key===s?{...i,showRemote:!1}:i),y(null))},[D]),ys=(0,o.useCallback)(async(s,i)=>{try{await et(i),at(s),xe.current&&clearTimeout(xe.current),xe.current=setTimeout(()=>{at(u=>u===s?null:u)},1400)}catch{y("Could not copy document")}},[]),Ee=(0,o.useCallback)(s=>{const i=C.getQueryData(f.documentRevisionsQueryKey(s));return i||(Y===s?xt??[]:[])},[xt,f,C,Y]),Ke=(0,o.useCallback)(s=>{Be(i=>({...i,[s]:null})),y(null)},[]),gs=(0,o.useCallback)((s,i)=>{const u=Kt(s,Ee(s.key)),j=u.revisions.find(w=>w.id===i);if(j){if(j.id===u.currentRevision.id){Ke(s.key);return}if(D?.key===s.key||Ut(s,v)){y("Save or cancel your local changes before viewing an older revision.");return}P(),R(w=>w?.key===s.key?null:w),_(w=>w?.key===s.key?null:w),Z(w=>w.filter(ee=>ee!==s.key)),Be(w=>({...w,[s.key]:j.id})),y(null)}},[D,v,Ee,P,Ke]),bs=(0,o.useCallback)((s,i)=>{if(!(!m||fe.isPending)){if(i&&(D?.key===s.key||Ut(s,v))){y("Save or cancel local changes before changing the document lock.");return}fe.mutate({key:s.key,locked:i})}},[m,D,v,fe]),bt=n(async s=>{s.currentTarget.contains(s.relatedTarget)||(z.current&&clearTimeout(z.current),await G(v,{clearAfterSave:!0,trackAutosave:!0}))},"handleDraftBlur"),vt=n(async s=>{if(s.key==="Escape"){s.preventDefault(),gt();return}(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),z.current&&clearTimeout(z.current),await G(v,{clearAfterSave:!1,trackAutosave:!0}))},"handleDraftKeyDown");(0,o.useEffect)(()=>{Z(Ft(f.id))},[f.id]),(0,o.useEffect)(()=>{Pe.current=!1},[f.id,O.hash]),(0,o.useEffect)(()=>{const s=new Set(U.map(i=>i.key));Z(i=>{const u=i.filter(j=>s.has(j));return u.length!==i.length&&Ot(f.id,u),u})},[f.id,U]),(0,o.useEffect)(()=>{Ot(f.id,me)},[f.id,me]),(0,o.useEffect)(()=>{if(!D)return;const s=U.find(i=>i.key===D.key);!s||s.latestRevisionId===D.serverDocument.latestRevisionId||_(i=>i?.key===s.key?{...i,serverDocument:s}:i)},[D,U]),(0,o.useEffect)(()=>{const s=O.hash;if(!s.startsWith("#document-"))return;const i=decodeURIComponent(s.slice(10));if(!(U.some(w=>w.key===i)||i==="plan"&&f.legacyPlanDocument)||Pe.current)return;Z(w=>w.filter(ee=>ee!==i));const u=document.getElementById(`document-${i}`);if(!u)return;Pe.current=!0,lt(i),u.scrollIntoView({behavior:"smooth",block:"center"});const j=setTimeout(()=>lt(w=>w===i?null:w),3e3);return()=>clearTimeout(j)},[f.legacyPlanDocument,O.hash,U]),(0,o.useEffect)(()=>()=>{z.current&&clearTimeout(z.current),xe.current&&clearTimeout(xe.current)},[]),(0,o.useEffect)(()=>{if(!v||v.isNew||D?.key===v.key)return;const s=U.find(i=>i.key===v.key);if(s){if(!(s.body!==v.body||(s.title??"")!==v.title)){te!=="saved"&&P();return}return we(v.key),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{G(v,{clearAfterSave:!1,trackAutosave:!0})},Qn),()=>{z.current&&clearTimeout(z.current)}}},[te,G,D,v,we,P,U]);const vs="mt-3",ks="",Ce="wardmote-edit-in-place-content min-h-(--sz-220px) text-sm leading-7",js=n(s=>{Z(i=>i.includes(s)?i.filter(u=>u!==s):[...i,s])},"toggleFoldedDocument"),Ns=(0,o.useCallback)((s,i)=>{st(u=>{const j=u.includes(s);return i&&!j?[...u,s]:!i&&j?u.filter(w=>w!==s):u}),i&&Z(u=>u.filter(j=>j!==s))},[]),ws=(0,o.useCallback)(s=>{st(i=>i.includes(s)?i.filter(u=>u!==s):(Z(u=>u.filter(j=>j!==s)),[...i,s]))},[]);return(0,e.jsxs)("div",{className:"space-y-3",children:[xs&&!v?.isNew?(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2 min-w-0",children:[p,(0,e.jsxs)(I,{variant:"secondary",size:"sm",onClick:ht,className:"shrink-0",children:[(0,e.jsx)(ze,{className:"mr-1.5 h-3.5 w-3.5"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"New document"}),(0,e.jsx)("span",{className:"sm:hidden",children:"New"})]})]}):(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 min-w-0",children:[(0,e.jsx)("h3",{className:"w-full text-sm font-medium text-ink-3 shrink-0 sm:w-auto",children:"Documents"}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 min-w-0 sm:ml-auto",children:[p,(0,e.jsxs)(I,{variant:"secondary",size:"sm",onClick:ht,className:"shrink-0",children:[(0,e.jsx)(ze,{className:"mr-1.5 h-3.5 w-3.5"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"New document"}),(0,e.jsx)("span",{className:"sm:hidden",children:"New"})]})]})]}),k&&(0,e.jsx)("p",{className:"text-xs text-bad",children:k}),v?.isNew&&(0,e.jsxs)("div",{className:"space-y-3 rounded-lg border border-line bg-bg-3/10 p-3",onBlurCapture:bt,onKeyDown:vt,children:[(0,e.jsx)(Se,{autoFocus:!0,value:v.key,onChange:n(s=>R(i=>i&&{...i,key:s.target.value.toLowerCase()}),"onChange"),placeholder:"Document key"}),ft&&(0,e.jsx)("p",{className:"text-xs text-bad",children:ft}),!ne(v.key)&&(0,e.jsx)(Se,{value:v.title,onChange:n(s=>R(i=>i&&{...i,title:s.target.value}),"onChange"),placeholder:"Optional title"}),(0,e.jsx)(Nt,{value:v.body,onChange:n(s=>R(i=>i&&{...i,body:s}),"onChange"),placeholder:"Markdown body",bordered:!1,className:"bg-transparent",contentClassName:"min-h-(--sz-220px) text-sm leading-7",mentions:d,imageUploadHandler:N,onSubmit:n(()=>{G(v,{clearAfterSave:!1,trackAutosave:!1})},"onSubmit")}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsxs)(I,{variant:"secondary",size:"sm",onClick:gt,children:[(0,e.jsx)(sn,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel"]}),(0,e.jsx)(I,{size:"sm",onClick:n(()=>{G(v,{clearAfterSave:!1,trackAutosave:!1})},"onClick"),disabled:se.isPending,children:se.isPending?"Saving...":"Create document"})]})]}),!ms&&f.legacyPlanDocument?(0,e.jsxs)("div",{id:"document-plan",className:$("rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 transition-colors duration-1000",rt==="plan"&&"border-accent/50 bg-accent/5"),children:[(0,e.jsxs)("div",{className:"mb-2 flex items-center gap-2",children:[(0,e.jsx)(Yt,{className:"h-4 w-4 text-amber-600"}),(0,e.jsx)(de,{variant:"outline",className:"border-amber-500/30 font-mono text-(length:--text-nano) uppercase tracking-(--tracking-eyebrow) text-amber-700 dark:text-amber-300",children:"PLAN"})]}),(0,e.jsx)("div",{className:ks,children:De(f.legacyPlanDocument.body,Ce,b)})]}):null,(0,e.jsx)("div",{className:"space-y-3",children:U.map(s=>{const i=!!s.lockedAt,u=!i&&v?.key===s.key&&!v.isNew?v:null,j=!i&&D?.key===s.key?D:null,w=me.includes(s.key),ee=Ee(s.key),le=Kt(s,ee),he=le.revisions,T=le.currentRevision,Q=cs[s.key]??null,H=Q?he.find(S=>S.id===Q)??null:null,F=!!H,Le=H?H.title??"":u?.title??T.title??"",oe=H?.body??u?.body??T.body,Cs=H?.revisionNumber??T.revisionNumber,Ds=H?.createdAt??T.createdAt,Ss=!ne(s.key)&&!!Le.trim()&&!Vn(Le,s.key),Is=!!(s.latestRevisionId&&s.updatedByAgentId&&!s.updatedByUserId&&g),Rs=fe.isPending&&fe.variables?.key===s.key,kt=q(s.key);return(0,e.jsxs)("div",{id:`document-${s.key}`,className:$("rounded-lg border border-line p-3 transition-colors duration-1000",rt===s.key&&"border-accent/50 bg-accent/5"),children:[(0,e.jsx)(jn,{documentKey:s.key,folded:w,onToggleFolded:n(()=>js(s.key),"onToggleFolded"),sourceTrustSlot:(0,e.jsx)(yn,{sourceTrust:s.sourceTrust,artifactLabel:"document"}),revisionMenu:{open:Y===s.key,onOpenChange:n(S=>os(S?s.key:null),"onOpenChange"),loading:Y===s.key&&ds,revisions:he.map(S=>({id:S.id,revisionNumber:S.revisionNumber,createdAt:S.createdAt,actor:Zn(S,{agentMap:A,userProfileMap:E})})),selectedRevisionId:Q,currentRevisionId:T.id,displayedRevisionNumber:Cs,historicalPreview:F,onSelectRevision:n(S=>gs(s,S),"onSelectRevision")},updatedAt:Ds,annotationSlot:f.annotations&&!_e(s.key)?(0,e.jsx)(_s,{issueId:f.annotations.issueId,target:kt,docKey:s.key,panelOpen:tt.includes(s.key),onToggle:n(()=>ws(s.key),"onToggle")}):null,titleSlot:Ss?(0,e.jsx)("p",{className:"mt-2 text-sm font-medium",children:Le}):null,actionsSlot:(0,e.jsxs)(e.Fragment,{children:[m?(0,e.jsx)(I,{variant:"ghost",size:"icon-xs",className:$("transition-colors"),title:i?"Unlock document":"Lock document","aria-label":i?`Unlock ${s.key} document`:`Lock ${s.key} document`,onClick:n(()=>bs(s,!i),"onClick"),disabled:Rs,children:i?(0,e.jsx)(jt,{className:"h-3.5 w-3.5"}):(0,e.jsx)(wn,{className:"h-3.5 w-3.5"})}):i?(0,e.jsx)("span",{title:"Locked document","aria-label":"Locked document",className:"inline-flex h-6 w-6 items-center justify-center text-amber-700 dark:text-amber-300",children:(0,e.jsx)(jt,{className:"h-3.5 w-3.5"})}):null,(0,e.jsx)(I,{variant:"ghost",size:"icon-xs",className:$("transition-colors"),title:it===s.key?"Copied":"Copy document",onClick:n(()=>{ys(s.key,oe)},"onClick"),children:it===s.key?(0,e.jsx)(ue,{className:"h-3.5 w-3.5"}):(0,e.jsx)(Zt,{className:"h-3.5 w-3.5"})}),(0,e.jsxs)(Jt,{children:[(0,e.jsx)(qt,{asChild:!0,children:(0,e.jsx)(I,{variant:"ghost",size:"icon-xs",title:"Document actions",children:(0,e.jsx)(Js,{className:"h-3.5 w-3.5"})})}),(0,e.jsxs)(Ht,{align:"end",children:[!F&&!i?(0,e.jsxs)(be,{onClick:n(()=>pt(s.key),"onClick"),children:[(0,e.jsx)(Zs,{className:"h-3.5 w-3.5"}),"Edit document"]}):null,!F&&!i?(0,e.jsx)($e,{}):null,(0,e.jsxs)(be,{onClick:n(()=>Jn(s.key,oe),"onClick"),children:[(0,e.jsx)(un,{className:"h-3.5 w-3.5"}),"Download document"]}),s.latestRevisionNumber>1?(0,e.jsxs)(be,{onClick:n(()=>ct(s.key),"onClick"),children:[(0,e.jsx)(Nn,{className:"h-3.5 w-3.5"}),"View diff"]}):null,r&&!i?(0,e.jsx)($e,{}):null,r&&!i?(0,e.jsxs)(be,{variant:"destructive",onClick:n(()=>l(s.key),"onClick"),children:[(0,e.jsx)(en,{className:"h-3.5 w-3.5"}),"Delete document"]}):null]})]})]})}),w?null:(0,e.jsxs)("div",{className:"mt-3 space-y-3",onBlurCapture:F?void 0:async S=>{u&&await bt(S)},onKeyDown:F?void 0:async S=>{u&&await vt(S)},children:[F&&H&&(0,e.jsx)("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-3",children:(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsxs)("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:["Viewing revision ",H.revisionNumber]}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"This is a historical preview. Restoring it creates a new latest revision and keeps history append-only."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>Ke(s.key),"onClick"),children:"Return to latest"}),i?null:(0,e.jsx)(I,{size:"sm",onClick:n(()=>Ne.mutate({key:s.key,revisionId:H.id}),"onClick"),disabled:Ne.isPending,children:Ne.isPending&&Ne.variables?.key===s.key?"Restoring...":"Restore this revision"})]})]})}),j&&!F&&(0,e.jsxs)("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-3",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:"Out of date"}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"This document changed while you were editing. Your local draft is preserved and autosave is paused."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>_(S=>S?.key===s.key?{...S,showRemote:!S.showRemote}:S),"onClick"),children:j.showRemote?"Hide remote":"Review remote"}),(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>ps(s.key),"onClick"),children:"Keep my draft"}),(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>fs(s.key),"onClick"),children:"Reload remote"}),(0,e.jsx)(I,{size:"sm",onClick:n(()=>{hs(s.key)},"onClick"),disabled:se.isPending,children:se.isPending?"Saving...":"Overwrite remote"})]})]}),j.showRemote&&(0,e.jsxs)("div",{className:"mt-3 rounded-md border border-line/70 bg-bg/60 p-3",children:[(0,e.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-(length:--text-micro) text-ink-3",children:[(0,e.jsxs)("span",{children:["Remote revision ",j.serverDocument.latestRevisionNumber]}),(0,e.jsx)("span",{children:"•"}),(0,e.jsxs)("span",{children:["updated ",He(j.serverDocument.updatedAt)]})]}),!ne(s.key)&&j.serverDocument.title?(0,e.jsx)("p",{className:"mb-2 text-sm font-medium",children:j.serverDocument.title}):null,De(j.serverDocument.body,"text-sm leading-7",b)]})]}),u&&!ne(s.key)&&!F&&(0,e.jsx)(Se,{value:u.title,onChange:n(S=>{we(s.key),R(W=>W&&{...W,title:S.target.value})},"onChange"),placeholder:"Optional title"}),(0,e.jsx)("div",{className:`${vs} ${u||F?"":"rounded-md hover:bg-bg-3/10"}`,children:(()=>{const S=F?De(oe,Ce,b):u?(0,e.jsx)(Nt,{value:oe,onChange:n(W=>{we(s.key),R(pe=>pe&&pe.key===s.key&&!pe.isNew?{...pe,body:W}:pe)},"onChange"),placeholder:"Markdown body",bordered:!1,className:"bg-transparent",contentClassName:Ce,mentions:d,imageUploadHandler:N,onSubmit:n(()=>{G(u??v,{clearAfterSave:!1,trackAutosave:!0})},"onSubmit")}):De(oe,Ce,b);return f.annotations?(0,e.jsx)(Ls,{issueId:f.annotations.issueId,target:kt,doc:s,bodyMarkdown:oe,draftDirty:!!u&&((u?.body??s.body)!==s.body||nt===s.key&&te==="saving"),draftConflicted:!!j,historicalPreview:F,locationHash:O.hash,panelOpen:tt.includes(s.key),onPanelOpenChange:n(W=>Ns(s.key,W),"onPanelOpenChange"),agentMap:A,userProfileMap:E,defaultFocusedThreadId:L?.[s.key],children:S}):S})()}),(0,e.jsx)("div",{className:"flex min-h-4 items-center justify-end px-1",children:(0,e.jsx)("span",{className:`text-(length:--text-micro) transition-opacity duration-150 ${F||j?"text-amber-700 dark:text-amber-300":te==="error"?"text-bad":"text-ink-3"} ${u||F?"opacity-100":"opacity-0"}`,children:F?"Viewing historical revision":u?j?"Out of date":nt===s.key?te==="saving"?"Autosaving...":te==="saved"?"Saved":te==="error"?"Could not save":"":"":""})}),Is&&s.latestRevisionId?(0,e.jsx)($n,{activeVote:us.get(s.latestRevisionId)??null,sharingPreference:c,termsUrl:h,onVote:n((S,W)=>g?.(s.latestRevisionId,S,W)??Promise.resolve(),"onVote")}):null]}),X===s.key&&(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-md border border-bad/20 bg-bad/5 px-4 py-3",children:[(0,e.jsx)("p",{className:"text-sm text-bad font-medium",children:"Delete this document? This cannot be undone."}),(0,e.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,e.jsx)(I,{variant:"ghost",size:"sm",onClick:n(()=>l(null),"onClick"),disabled:je.isPending,children:"Cancel"}),(0,e.jsx)(I,{variant:"delete",size:"sm",onClick:n(()=>je.mutate(s.key),"onClick"),disabled:je.isPending,children:je.isPending?"Deleting...":"Delete"})]})]})]},s.id)})}),ot&&(()=>{const s=U.find(i=>i.key===ot);return s?(0,e.jsx)(zn,{documentKey:s.key,latestRevisionNumber:s.latestRevisionNumber,revisionsQueryKey:f.documentRevisionsQueryKey(s.key),revisionsQueryFn:n(()=>f.listDocumentRevisions(s.key),"revisionsQueryFn"),open:!0,onOpenChange:n(i=>{i||ct(null)},"onOpenChange")}):null})()]})}n(Wn,"IssueDocumentsSection");var Xn={draft:"Draft",in_progress:"In progress",in_review:"In review",approved:"Approved",done:"Done",cancelled:"Cancelled"},Mt=["name","title","body","description"],ei=["backlog","todo","in_progress","in_review","done","blocked","cancelled"];function ti(t){return ei.includes(t)?t:void 0}n(ti,"issueReferenceStatus");function Ue(t,a){return t[a]??t[a.charAt(0).toUpperCase()+a.slice(1)]}n(Ue,"fieldValueByName");function Me(t){return t?[t,t.charAt(0).toUpperCase()+t.slice(1),t.charAt(0).toLowerCase()+t.slice(1)]:[t]}n(Me,"caseFieldKeyVariants");function si(t){return t!=null&&!(typeof t=="string"&&t.trim()==="")}n(si,"hasFieldValue");function ni(t){const a=new Set(Mt.flatMap(c=>Me(c))),r=new Set(t.documents.flatMap(c=>Me(c.key))),m=Mt.map(c=>{if(Me(c).some(d=>r.has(d)))return null;let h;return c==="title"?h=Ue(t.fields,c)??t.title:h=Ue(t.fields,c),{key:c,label:c,value:h}}).filter(c=>c!==null&&si(c.value)),x=Object.entries(t.fields).filter(([c])=>!a.has(c)&&!r.has(c)).map(([c,h])=>({key:c,label:c,value:h}));return[...m,...x]}n(ni,"casePropertyRows");function ii(t){return{id:t.id,companyId:t.companyId,title:t.title,format:t.format,latestBody:t.body,latestRevisionId:t.latestRevisionId,latestRevisionNumber:t.latestRevisionNumber,createdByAgentId:t.createdByAgentId,createdByUserId:t.createdByUserId,updatedByAgentId:t.updatedByAgentId,updatedByUserId:t.updatedByUserId,lockedAt:t.lockedAt?new Date(t.lockedAt).toISOString():null,lockedByAgentId:t.lockedByAgentId,lockedByUserId:t.lockedByUserId,sourceTrust:t.sourceTrust,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString()}}n(ii,"issueDocumentToCaseDocument");function ai({parent:t,children:a}){return!t&&a.length===0?null:(0,e.jsxs)("section",{className:"space-y-3","aria-label":"Case relationships",children:[t?(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("h2",{className:"text-xs font-medium text-ink-3",children:"Parent"}),(0,e.jsx)(qe,{children:[t]})]}):null,a.length>0?(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsxs)("h2",{className:"text-xs font-medium text-ink-3",children:["Children ",a.length]}),(0,e.jsx)(qe,{children:a,maxVisible:5})]}):null]})}n(ai,"CaseRelationshipsSection");function ie({label:t,children:a,wrap:r,mode:m}){return m==="compact"?(0,e.jsx)(Ys,{label:t,wrap:r,children:a}):(0,e.jsxs)("div",{className:$("flex w-full min-w-0 gap-3 py-1",r?"items-start":"items-center"),"data-property-row":"true",children:[(0,e.jsx)("span",{className:$("w-40 shrink-0 break-words text-xs text-ink-3",r&&"mt-0.5"),"data-property-label":t,children:t}),(0,e.jsx)("div",{className:$("flex min-w-0 flex-1 items-center gap-1.5",r&&"flex-wrap"),children:a})]})}n(ie,"CasePropertyRow");function ri({status:t,onChange:a,disabled:r}){const[m,x]=(0,o.useState)(!1);return(0,e.jsxs)(We,{open:m,onOpenChange:x,children:[(0,e.jsx)(Ye,{asChild:!0,children:(0,e.jsxs)("button",{type:"button",disabled:r,className:"inline-flex items-center gap-1 rounded-md hover:bg-bg-3/50 disabled:opacity-50","aria-label":"Change case status",children:[(0,e.jsx)(Qe,{status:t}),(0,e.jsx)(Xe,{className:"h-3.5 w-3.5 text-ink-3"})]})}),(0,e.jsx)(Ge,{align:"end",className:"w-44 p-1",children:bn.map(c=>(0,e.jsxs)("button",{type:"button",onClick:n(()=>{x(!1),c!==t&&a(c)},"onClick"),className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-left hover:bg-bg-3",children:[(0,e.jsx)(Qe,{status:c}),c===t&&(0,e.jsx)(ue,{className:"h-4 w-4 text-ink-3"})]},c))})]})}n(ri,"CaseStatusPicker");function li({companyId:t,selected:a,onChange:r}){const[m,x]=(0,o.useState)(!1),[c,h]=(0,o.useState)(""),[d,N]=(0,o.useState)(Ts[0]),g=Je(),p=ae({queryKey:M.issues.labels(t),queryFn:n(()=>J.listLabels(t),"queryFn"),enabled:m}),A=new Set(a.map(b=>b.id)),E=ce({mutationFn:n(b=>J.createLabel(t,b),"mutationFn"),onSuccess:n(b=>{g.setQueryData(M.issues.labels(t),C=>C?[...C,b]:[b]),r([...A,b.id]),h("")},"onSuccess")}),K=p.data??[],L=c.trim()?K.filter(b=>b.name.toLowerCase().includes(c.trim().toLowerCase())):K;function B(b){const C=new Set(A);C.has(b)?C.delete(b):C.add(b),r([...C])}return n(B,"toggle"),(0,e.jsxs)(We,{open:m,onOpenChange:x,children:[(0,e.jsx)(Ye,{asChild:!0,children:(0,e.jsxs)(I,{variant:"ghost",size:"sm",className:"h-6 gap-1 px-2 text-xs",children:[(0,e.jsx)(ze,{className:"h-3.5 w-3.5"})," Labels"]})}),(0,e.jsxs)(Ge,{align:"start",className:"w-64 p-2",children:[(0,e.jsx)(Se,{value:c,onChange:n(b=>h(b.target.value),"onChange"),placeholder:"Search labels…",className:"mb-2 h-7 text-xs"}),(0,e.jsxs)("div",{className:"max-h-52 space-y-0.5 overflow-y-auto",children:[L.map(b=>(0,e.jsxs)("button",{type:"button",onClick:n(()=>B(b.id),"onClick"),className:"flex w-full items-center gap-2 rounded px-2 py-1 text-left text-sm hover:bg-bg-3",children:[(0,e.jsx)("span",{className:"h-3 w-3 shrink-0 rounded-full",style:{backgroundColor:b.color}}),(0,e.jsx)("span",{className:"flex-1 truncate",children:b.name}),A.has(b.id)&&(0,e.jsx)(ue,{className:"h-4 w-4 text-ink-3"})]},b.id)),L.length===0&&!c.trim()&&(0,e.jsx)("p",{className:"px-2 py-1 text-xs text-ink-3",children:"No labels yet."})]}),c.trim()&&!K.some(b=>b.name.toLowerCase()===c.trim().toLowerCase())&&(0,e.jsxs)("div",{className:"mt-2 flex items-center gap-2 border-t border-line pt-2",children:[(0,e.jsx)("input",{type:"color",value:d,onChange:n(b=>N(b.target.value),"onChange"),className:"h-6 w-6 shrink-0 cursor-pointer rounded border border-line bg-transparent","aria-label":"New label color"}),(0,e.jsxs)(I,{size:"sm",variant:"secondary",className:"h-7 flex-1 text-xs",disabled:E.isPending,onClick:n(()=>E.mutate({name:c.trim(),color:d}),"onClick"),children:["Create “",c.trim(),"”"]})]})]})]})}n(li,"CaseLabelsPicker");function $t({caseData:t,childCases:a,childrenError:r,companyId:m,labelsPending:x,onLabelIdsChange:c,mode:h}){const d=ni(t),N=h==="full";return(0,e.jsxs)("div",{className:$("space-y-4",N&&"space-y-6"),children:[(0,e.jsxs)(ye,{title:"Case",first:!0,children:[(0,e.jsx)(ie,{label:"Type",mode:h,children:(0,e.jsx)(wt,{children:t.caseType})}),t.key?(0,e.jsx)(ie,{label:"Key",mode:h,children:(0,e.jsx)(ss,{value:t.key,label:"case key",className:"font-mono text-xs text-ink-3",truncate:!N})}):null,(0,e.jsxs)(ie,{label:"Labels",wrap:!0,mode:h,children:[t.labels.length>0?t.labels.map(g=>(0,e.jsx)(wt,{style:{borderColor:g.color,color:g.color},className:"bg-transparent",children:g.name},g.id)):(0,e.jsx)("span",{className:"text-xs text-ink-3",children:"None"}),m?(0,e.jsx)(li,{companyId:m,selected:t.labels,onChange:c}):null,x?(0,e.jsx)("span",{className:"text-xs text-ink-3",children:"Saving..."}):null]})]}),d.length>0?(0,e.jsx)(ye,{title:"Fields",children:d.map(({key:g,label:p,value:A})=>(0,e.jsx)(ie,{label:p,wrap:N||Array.isArray(A)||typeof A=="object"&&A!==null,mode:h,children:(0,e.jsx)("span",{className:$("min-w-0 text-sm",!N&&"truncate"),children:(0,e.jsx)(rs,{value:A,fieldKey:g,variant:h})})},g))}):null,(0,e.jsx)(ye,{title:"Linked tasks",children:t.issueLinks.length===0?(0,e.jsx)(ie,{label:"Tasks",mode:h,children:(0,e.jsx)("span",{className:"text-xs text-ink-3",children:"None yet"})}):(0,e.jsx)(ie,{label:"Tasks",wrap:!0,mode:h,children:(0,e.jsx)("div",{className:"flex flex-wrap items-center gap-1.5",children:t.issueLinks.map(g=>(0,e.jsx)(ts,{issue:{id:g.issue.id,identifier:g.issue.identifier,title:g.issue.title,status:ti(g.issue.status)}},g.id))})})}),(0,e.jsx)(ye,{title:`Children${a.length>0?` ${a.length}`:""}`,children:r?(0,e.jsx)("p",{className:"text-xs text-bad",children:"Could not load child cases."}):(0,e.jsx)(qe,{children:a})}),t.attachments.length>0?(0,e.jsx)(ye,{title:"Attachments",children:(0,e.jsx)(ie,{label:"Files",mode:h,children:(0,e.jsxs)("span",{className:"text-xs text-ink-3",children:[t.attachments.length," ",t.attachments.length===1?"file":"files"]})})}):null]})}n($t,"CasePropertiesContent");function ia(){const{caseIdentifier:t}=Ks(),{selectedCompanyId:a}=Fs(),{setBreadcrumbs:r}=rn(),{openPanel:m,closePanel:x}=dn(),c=Je(),h=Ze(),[d,N]=(0,o.useState)(!1),g=ae({queryKey:M.cases.detail(t??""),queryFn:n(()=>V.get(t),"queryFn"),enabled:!!t}),p=g.data,A=M.cases.detail(t??""),E=ae({queryKey:M.cases.events(t??""),queryFn:n(()=>V.listEvents(t,100),"queryFn"),enabled:!!t}),K=ae({queryKey:M.cases.children(p?.id??""),queryFn:n(()=>V.listChildren(a,p.id),"queryFn"),enabled:!!a&&!!p?.id}),L=(0,o.useMemo)(()=>K.data??[],[K.data]),B=ce({mutationFn:n(l=>V.patch(t,l),"mutationFn"),onSuccess:n(l=>{c.setQueryData(M.cases.detail(t??""),l),c.invalidateQueries({queryKey:M.cases.events(t??"")})},"onSuccess")}),b=(0,o.useCallback)(l=>{B.mutate({labelIds:l})},[B.mutate]);(0,o.useEffect)(()=>{r([{label:"Cases",href:h()},{label:p?`${p.identifier} — ${p.title}`:t??"Case"}])},[r,p,t,h]);const C=(0,o.useMemo)(()=>E.data??[],[E.data]),O=(0,o.useMemo)(()=>!p||!t?null:{id:p.id,detailQueryKey:A,documentsQueryKey:M.cases.documents(p.id),idleDocumentRevisionsQueryKey:["cases","revisions",p.id,"__idle__"],documentRevisionsQueryKey:n(l=>M.cases.revisions(p.id,l),"documentRevisionsQueryKey"),listDocuments:n(async()=>{const l=c.getQueryData(A)??await V.get(t);return l.documents.map(k=>ge(l.id,k.key,k.document))},"listDocuments"),listDocumentRevisions:n(async l=>(await V.listRevisions(t,l)).revisions.map(k=>gn(p.id,l,k)),"listDocumentRevisions"),getDocument:n(async l=>{const k=await V.getDocument(t,l);return ge(p.id,k.key,k)},"getDocument"),upsertDocument:n(async(l,k)=>{const y=await V.upsertDocument(t,l,k);return ge(p.id,y.document.key,y.document)},"upsertDocument"),deleteDocument:n(l=>V.deleteDocument(t,l),"deleteDocument"),restoreDocumentRevision:n(async(l,k)=>{const y=await V.restoreDocumentRevision(t,l,k);return ge(p.id,y.document.key,y.document)},"restoreDocumentRevision"),setDocumentLock:n(async(l,k)=>{const y=k?await V.lockDocument(t,l):await V.unlockDocument(t,l);return ge(p.id,y.key,y)},"setDocumentLock"),syncDetailCache:n((l,k)=>{l.setQueryData(A,y=>{if(!y)return y;const v={key:k.key,document:ii(k)},R=y.documents.findIndex(_=>_.key===k.key),D=R===-1?[...y.documents,v]:y.documents.map((_,me)=>me===R?v:_);return{...y,documents:D,updatedAt:new Date(k.updatedAt).toISOString()}})},"syncDetailCache"),hideSystemDocuments:!1,legacyPlanDocument:null,annotations:{issueId:p.id,target:n(l=>({kind:"case",caseId:p.id,documentKey:l}),"target")}},[p,A,t,c]),f=(0,o.useMemo)(()=>p?(0,e.jsx)($t,{caseData:p,childCases:L,childrenError:K.isError,companyId:a,labelsPending:B.isPending,onLabelIdsChange:b,mode:"compact"}):null,[p,L,K.isError,a,B.isPending,b]);if((0,o.useEffect)(()=>{if(f)return m(f),()=>x()},[f,m,x]),!t)return(0,e.jsx)(Us,{to:h(),replace:!0});if(g.isLoading)return(0,e.jsx)(mn,{variant:"detail"});if(g.isError||!p)return(0,e.jsxs)("div",{className:"mx-auto max-w-md py-16 text-center",children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Case not found."}),(0,e.jsx)(Ae,{to:h(),className:"mt-2 inline-block text-sm text-accent hover:underline",children:"← Back to cases"})]});const q=p.fields.description??p.fields.Description??null;function X(l){const k=[`# ${l.identifier} ${l.title}`,"",`- Key: ${l.key??"none"}`,`- Type: ${l.caseType}`,`- Status: ${Xn[l.status]}`,l.labels.length>0?`- Labels: ${l.labels.map(y=>y.name).join(", ")}`:"- Labels: none"].join(`
1
+ var As=Object.defineProperty;var n=(t,a)=>As(t,"name",{value:a,configurable:!0});import{i as zt}from"./rolldown-runtime-ZpX3ckPj.js";import{O as He,Vi as Ts,Wi as _e,l as $,na as Bs,t as Qt,ta as Ps}from"./createLucideIcon-DJi9suAC.js";import{h as Es,n as jt,v as Ks}from"./star-BZgQbzhV.js";import{X as Je,_ as ce,n as Vt,t as M,v as ae}from"./queryKeys-DYV5MhM_.js";import{n as Ls,t as _s}from"./IssueDocumentAnnotations-BVdH4RTa.js";import{n as Fs}from"./CompanyContext-CSrVsSze.js";import{a as Ze,ft as Os,r as Us,t as Ae,zt as J}from"./router-2UfGeejU.js";import{a as Ms,c as $e,i as be,n as $s,p as qt,r as Ht,t as Jt}from"./dropdown-menu-CqRAF7Oj.js";import{i as Fe,n as Oe,r as zs,t as Qs}from"./tabs-B2Os_leL.js";import{t as Nt}from"./MarkdownEditor-DXD-Cu3u.js";import{o as Ye,r as Ge,t as We}from"./popover-BhYHYj7q.js";import{t as Vs}from"./bot-C9arfJWx.js";import{t as ue}from"./check-Ctsrlfa-.js";import{t as Xe}from"./chevron-down-BCvxsWfI.js";import{t as qs}from"./MarkdownBody-BTjuUgFa.js";import{t as Zt}from"./copy-_wvZOjTe.js";import{t as Hs}from"./ellipsis-vertical-DWXPf6Ow.js";import{t as Js}from"./ellipsis-BTiLRUn4.js";import{t as Zs}from"./file-pen-line-DX6PZQXR.js";import{t as Yt}from"./file-text-Cw7ntqRx.js";import{i as ye,n as wt,r as Ys}from"./issue-properties-lmRBaUTG.js";import{t as Gs}from"./list-filter-h7_mdWEH.js";import{t as I}from"./button-CMwV3L1P.js";import{t as ze}from"./plus-C6fnr28l.js";import{t as Ws}from"./thumbs-down-C2BkjZOy.js";import{t as Xs}from"./thumbs-up-OW2IsTL7.js";import{t as en}from"./trash-D7zTaHTj.js";import{t as tn}from"./user-Ccom_Ph0.js";import{t as sn}from"./x-DRDFdlYE.js";import{t as de}from"./badge-DuA2EgZC.js";import{a as Gt,i as nn,n as Wt,r as an,s as Xt,t as es}from"./dialog-CKUblzlR.js";import{t as Se}from"./input-DobnTAyB.js";import{n as rn}from"./BreadcrumbContext-BVZDZoC0.js";import{t as ln}from"./textarea-BRPEfJ-g.js";import{i as Ct,n as Dt,o as St,r as It,s as Rt}from"./select-V0Hm_q4f.js";import{t as At}from"./chip-DsDe6yck.js";import{t as et}from"./clipboard-CTLKYvRL.js";import{t as on}from"./card-Bru3x_SJ.js";import{t as cn}from"./StatusIcon-0GcYXDdN.js";import{Or as dn,Ra as un,_ as mn,pn as Qe,xa as xn}from"./index-DDoARkPG.js";import{t as fn}from"./ImageGalleryModal-CjHED0Lb.js";import{t as hn}from"./useAutosaveIndicator-DttGFwx7.js";import{t as pn}from"./FoldCurtain-DUAOdtCt.js";import{t as yn}from"./SourceTrustBadge-BZBQe5No.js";import{t as ts}from"./IssueReferencePill-DAEplgLd.js";import{a as gn,i as ge,o as V,r as Tt,s as Bt,t as bn}from"./cases-m9RZ5Cym.js";import{n as vn,t as ss}from"./CaseIdentifierKey-D8Xi16PS.js";import{t as kn}from"./line-diff-DAcZgvm2.js";import{t as jn}from"./DocumentFrameHeader-DTSqcw4Q.js";var ns={name:"diff",size:24,node:[["path",{d:"M12 3v14",key:"7cf3v8"}],["path",{d:"M5 10h14",key:"elsbfy"}],["path",{d:"M5 21h14",key:"11awu3"}]]};ns.node;var Nn=Qt(ns),is={name:"lock-open",size:24,node:[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],aliases:["unlock"]};is.node;var wn=Qt(is),o=zt(Bs(),1),e=zt(Ps(),1),Cn=/^https?:\/\/\S+$/i,Dn=/^[A-Z][A-Z0-9]*-C\d+$/,Sn=/^[A-Z][A-Z0-9]*-\d+$/,In=/\b[A-Z][A-Z0-9]*-\d+\b/g;function Rn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}n(Rn,"isPlainObject");function Ie(){return(0,e.jsx)("span",{className:"text-ink-3",children:"—"})}n(Ie,"EmptyValue");function An(t){if(!t)return!1;const a=t.toLowerCase().replace(/[^a-z0-9]/g,"");return a.includes("issueidentifier")||a.includes("taskidentifier")}n(An,"isIssueIdentifierField");function as(t){return typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t,null,2)}n(as,"stringifyCopyValue");function Tn(t,a){if(!An(a))return typeof t=="string"&&Sn.test(t.trim())?[t.trim()]:[];const r=[],m=n(x=>{if(typeof x=="string")for(const c of x.matchAll(In))r.push(c[0])},"add");return Array.isArray(t)?t.forEach(m):m(t),[...new Set(r)]}n(Tn,"extractIssueIdentifiers");function Bn({identifiers:t}){return(0,e.jsx)("span",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:t.map(a=>(0,e.jsx)(ts,{issue:{id:a,identifier:a,title:a}},a))})}n(Bn,"IssueIdentifierValue");function Re({value:t,children:a,className:r}){const m=as(t),[x,c]=(0,o.useState)(!1),h=(0,o.useRef)(void 0);(0,o.useEffect)(()=>()=>clearTimeout(h.current),[]);const d=(0,o.useCallback)(()=>{et(m).then(()=>{c(!0),clearTimeout(h.current),h.current=setTimeout(()=>c(!1),1500)})},[m]);return(0,e.jsxs)("span",{className:"relative inline-flex min-w-0 max-w-full",children:[(0,e.jsx)("button",{type:"button",className:$("min-w-0 max-w-full cursor-copy truncate text-left transition-colors hover:text-ink",r),title:m,onClick:d,children:a}),x?(0,e.jsxs)("span",{role:"status","aria-live":"polite",className:"pointer-events-none absolute bottom-full left-1/2 mb-1.5 inline-flex -translate-x-1/2 items-center gap-1 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-bg",children:[(0,e.jsx)(ue,{className:"h-3 w-3 shrink-0"}),"Copied"]}):null]})}n(Re,"CopyableCompactValue");function Pn({value:t,variant:a}){const r=Ze(),m=t.trim();return m===""?(0,e.jsx)(Ie,{}):Cn.test(m)?(0,e.jsxs)("a",{href:m,target:"_blank",rel:"noreferrer",className:$("inline-flex max-w-full items-center gap-0.5 text-sm text-accent hover:underline",a==="compact"?"truncate":"break-all"),title:m,children:[(0,e.jsx)("span",{className:a==="compact"?"truncate":"break-all",children:m}),(0,e.jsx)("span",{"aria-hidden":!0,children:"↗"})]}):Dn.test(m)?(0,e.jsx)(Ae,{to:r(m),className:"font-mono text-sm text-accent hover:underline",children:m}):a==="compact"?(0,e.jsx)(Re,{value:t,className:"text-sm",children:t}):(0,e.jsx)("span",{className:"text-sm break-words",children:t})}n(Pn,"StringValue");function rs({value:t,fieldKey:a,variant:r="full"}){if(t==null)return(0,e.jsx)(Ie,{});const m=Tn(t,a);if(m.length>0)return(0,e.jsx)(Bn,{identifiers:m});if(typeof t=="string")return(0,e.jsx)(Pn,{value:t,variant:r});if(typeof t=="number")return Number.isFinite(t)?r==="compact"?(0,e.jsx)(Re,{value:t,className:"text-sm tabular-nums",children:t.toLocaleString()}):(0,e.jsx)("span",{className:"text-sm tabular-nums",children:t.toLocaleString()}):(0,e.jsx)("span",{className:"text-sm",children:String(t)});if(typeof t=="boolean")return t?(0,e.jsx)(ue,{className:"h-4 w-4 text-green-600 dark:text-green-400","aria-label":"true"}):(0,e.jsx)(Ie,{});if(Array.isArray(t))return t.length===0?(0,e.jsx)(Ie,{}):r==="compact"?(0,e.jsx)(Re,{value:t,className:"text-sm text-ink-3",children:as(t)}):(0,e.jsx)("div",{className:"flex flex-wrap justify-start gap-1",children:t.map((x,c)=>(0,e.jsx)(de,{variant:"secondary",className:"font-normal",children:typeof x=="string"||typeof x=="number"||typeof x=="boolean"?String(x):JSON.stringify(x)},c))});if(Rn(t)){const x=JSON.stringify(t);return r==="compact"?(0,e.jsx)(Re,{value:t,className:"font-mono text-xs text-ink-3",children:x}):(0,e.jsx)("pre",{className:"max-w-full whitespace-pre-wrap break-words font-mono text-xs text-ink-3",children:JSON.stringify(t,null,2)})}return(0,e.jsx)("span",{className:"text-sm",children:String(t)})}n(rs,"CaseFieldValue");var Ve={created:"created",updated:"updated",fields_changed:"fields changed",status_changed:"status changed",issue_linked:"issue linked",issue_unlinked:"issue unlinked",document_revised:"document revised",child_linked:"child linked",attachment_added:"attachment added",label_added:"label added",label_removed:"label removed"};function En(t){return t.actorType==="agent"?t.actorAgentName??"Agent":t.actorType==="user"?"User":"System"}n(En,"actorLabel");function Kn({event:t}){const a=t.actorType==="agent"?Vs:t.actorType==="user"?tn:Os;return(0,e.jsx)(a,{className:"h-3.5 w-3.5 shrink-0 text-ink-3","aria-hidden":!0})}n(Kn,"ActorIcon");function Ln(t){return t.kind==="issue_linked"||t.kind==="issue_unlinked"?"issue":"via"}n(Ln,"issueRelationLabel");function _n({event:t,compact:a=!1}){const r=t.kind==="status_changed"&&t.payload?`${t.payload.previousStatus??"?"} → ${t.payload.status??"?"}`:"";return(0,e.jsxs)("div",{className:$("flex items-start gap-2 text-xs",a?"py-1.5":"py-2"),children:[(0,e.jsx)("span",{className:"mt-1",children:(0,e.jsx)(Kn,{event:t})}),(0,e.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-baseline gap-x-1.5",children:[(0,e.jsx)("span",{className:"font-medium",children:Ve[t.kind]??t.kind}),r&&(0,e.jsxs)("span",{className:"text-ink-3",children:["· ",r]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-x-1.5 text-ink-3",children:[(0,e.jsx)("span",{children:En(t)}),t.issue&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{"aria-hidden":!0,children:"·"}),(0,e.jsx)("span",{children:Ln(t)}),(0,e.jsxs)(Ae,{to:`/issues/${t.issue.identifier}`,className:"inline-flex min-w-0 items-center gap-1 text-ink/80 hover:underline",title:t.issue.title,children:[(0,e.jsx)(cn,{status:t.issue.status,size:"sm"}),(0,e.jsx)("span",{className:"shrink-0 font-mono",children:t.issue.identifier}),(0,e.jsx)("span",{className:"min-w-0 truncate",children:t.issue.title})]})]}),(0,e.jsx)("span",{"aria-hidden":!0,children:"·"}),(0,e.jsx)("span",{children:He(t.createdAt)})]})]})]})}n(_n,"CaseEventRow");function Fn({events:t}){const[a,r]=(0,o.useState)(new Set),m=(0,o.useMemo)(()=>{const d=[];for(const N of t)d.includes(N.kind)||d.push(N.kind);return d},[t]),x=(0,o.useMemo)(()=>a.size===0?t:t.filter(d=>a.has(d.kind)),[t,a]);function c(d){r(N=>{const g=new Set(N);return g.has(d)?g.delete(d):g.add(d),g})}n(c,"toggle");const h=a.size===0?"All activity":a.size===1?Ve[[...a][0]]??[...a][0]:`${a.size} filters`;return t.length===0?(0,e.jsx)("p",{className:"py-6 text-center text-sm text-ink-3",children:"No activity yet."}):(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsxs)("p",{className:"text-xs text-ink-3",children:[x.length," of ",t.length," events"]}),(0,e.jsxs)(Jt,{children:[(0,e.jsx)(qt,{asChild:!0,children:(0,e.jsxs)(I,{variant:"secondary",size:"sm",className:"h-8 gap-1.5",children:[(0,e.jsx)(Gs,{className:"h-3.5 w-3.5"}),h,(0,e.jsx)(Xe,{className:"h-3.5 w-3.5 text-ink-3"})]})}),(0,e.jsxs)(Ht,{align:"end",className:"w-56",children:[(0,e.jsx)(Ms,{children:"Activity filter"}),(0,e.jsx)(be,{onSelect:n(()=>r(new Set),"onSelect"),children:"All activity"}),(0,e.jsx)($e,{}),m.map(d=>(0,e.jsx)($s,{checked:a.has(d),onCheckedChange:n(()=>c(d),"onCheckedChange"),children:Ve[d]??d},d))]})]})]}),x.length===0?(0,e.jsx)("p",{className:"py-6 text-center text-sm text-ink-3",children:"No events match this filter."}):(0,e.jsx)("div",{className:"divide-y divide-line",children:x.map(d=>(0,e.jsx)(_n,{event:d},d.id))})]})}n(Fn,"CaseActivityFeed");function qe({children:t,maxVisible:a}){const r=Ze(),[m,x]=(0,o.useState)(!1);if(t.length===0)return(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"No child cases."});const c=a!=null&&t.length>a&&!m?t.slice(0,a):t,h=t.length-c.length;return(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("ul",{className:"space-y-1",children:c.map(d=>(0,e.jsx)("li",{children:(0,e.jsxs)(Ae,{to:r(d.identifier),className:"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-bg-3/50",children:[(0,e.jsx)(ss,{value:d.identifier,label:"case ID",className:"shrink-0 font-mono text-xs text-ink-3",containerClassName:"shrink-0",stopPropagation:!0}),(0,e.jsx)("span",{className:"min-w-0 flex-1 truncate",title:d.title,children:d.title}),(0,e.jsx)(de,{variant:"secondary",className:"shrink-0",children:d.caseType}),(0,e.jsx)(Qe,{status:d.status})]})},d.id))}),h>0?(0,e.jsxs)(I,{type:"button",variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-xs",onClick:n(()=>x(!0),"onClick"),children:[(0,e.jsx)(Xe,{className:"h-3.5 w-3.5"}),"Show ",h," more"]}):null]})}n(qe,"CaseChildrenTree");function On(t){return t<1024?`${t} B`:t<1048576?`${(t/1024).toFixed(0)} KB`:`${(t/1048576).toFixed(1)} MB`}n(On,"humanBytes");function Un({attachments:t}){const[a,r]=(0,o.useState)(null),m=(0,o.useMemo)(()=>t.filter(Bt).map(x=>({id:x.id,contentPath:Tt(x),contentType:x.asset.contentType,originalFilename:x.asset.originalFilename})),[t]);return t.length===0?(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"No attachments."}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-4",children:t.map(x=>{const c=Bt(x),h=x.asset.originalFilename??"attachment",d=c?m.findIndex(N=>N.id===x.id):-1;return(0,e.jsxs)("button",{type:"button",onClick:n(()=>c&&d>=0&&r(d),"onClick"),disabled:!c,title:h,className:$("group relative flex aspect-square flex-col overflow-hidden rounded-lg border border-line bg-bg-3/40 text-left",c&&"cursor-pointer hover:border-accent/50"),children:[c?(0,e.jsx)("img",{src:Tt(x),alt:h,loading:"lazy",className:"h-full w-full object-cover transition-transform group-hover:scale-(--s-1_02)"}):(0,e.jsxs)("div",{className:"flex h-full w-full flex-col items-center justify-center gap-1 p-2 text-ink-3",children:[(0,e.jsx)(Yt,{className:"h-6 w-6","aria-hidden":!0}),(0,e.jsx)("span",{className:"w-full truncate text-center text-(length:--text-micro)",children:h})]}),(0,e.jsx)("span",{className:"pointer-events-none absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/60 to-transparent px-1.5 py-1 text-(length:--text-nano) text-white/90",children:On(x.asset.byteSize)})]},x.id)})}),a!==null&&(0,e.jsx)(fn,{items:m,initialIndex:a,open:a!==null,onOpenChange:n(x=>!x&&r(null),"onOpenChange")})]})}n(Un,"CaseAttachmentsGallery");function Pt(t){if(!t)return 0;const a=new Date(t).getTime();return Number.isNaN(a)?0:a}n(Pt,"toTimestamp");function Et(t){return[...t].sort((a,r)=>{if(a.revisionNumber!==r.revisionNumber)return r.revisionNumber-a.revisionNumber;const m=Pt(r.createdAt)-Pt(a.createdAt);return m!==0?m:r.id.localeCompare(a.id)})}n(Et,"sortRevisionsDescending");function Mn(t){return{id:t.latestRevisionId??`${t.id}-latest`,companyId:t.companyId,documentId:t.id,issueId:t.issueId,key:t.key,revisionNumber:t.latestRevisionNumber,title:t.title,format:t.format,body:t.body,changeSummary:null,createdByAgentId:t.updatedByAgentId??t.createdByAgentId,createdByUserId:t.updatedByUserId??t.createdByUserId,createdAt:t.updatedAt}}n(Mn,"createCurrentRevisionSnapshot");function Kt(t,a){const r=Et(a),m=Mn(t),x=r[0]??null,c=x&&x.revisionNumber>t.latestRevisionNumber?x:r.find(g=>g.id===t.latestRevisionId)??m,h=Et([c,...r]),d=[],N=new Set;for(const g of h)N.has(g.id)||(N.add(g.id),d.push(g));return{currentRevision:c,revisions:d}}n(Kt,"deriveDocumentRevisionState");function $n({activeVote:t,disabled:a=!1,sharingPreference:r="prompt",termsUrl:m=null,onVote:x,rightSlot:c,inline:h=!1}){const[d,N]=(0,o.useState)(null),[g,p]=(0,o.useState)(!1),[A,E]=(0,o.useState)(""),[K,L]=(0,o.useState)(!1),[B,b]=(0,o.useState)(void 0),[C,O]=(0,o.useState)(null),f=C??t??null;(0,o.useEffect)(()=>{C&&t===C&&O(null)},[t,C]);async function q(k,y,v){p(!0);try{await x(k,y),N(null),v?.keepReasonPromptOpen||(L(!1),E(""),b(void 0))}catch(R){throw O(null),R}finally{p(!1)}}n(q,"submitVote");function X(k,y,v){if(r==="prompt"){N({vote:k,...y?{reason:y}:{},...v?.keepReasonPromptOpen?{keepReasonPromptOpen:!0}:{}});return}const R=r==="allowed";k==="down"&&b(R),q(k,{...R?{allowSharing:!0}:{},...y?{reason:y}:{}},v)}n(X,"beginVote");function l(k){if(O(k),k==="down"){L(!0),E(""),b(void 0),X("down",void 0,{keepReasonPromptOpen:!0});return}X(k)}return n(l,"handleVote"),(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)("div",{className:$("flex items-center gap-2",h?"justify-end":"mt-3 border-t border-line/60 pt-3"),children:[(0,e.jsxs)(At,{selected:f==="up",disabled:a||g,onClick:n(()=>l("up"),"onClick"),children:[(0,e.jsx)(Xs,{"aria-hidden":!0}),"Helpful"]}),(0,e.jsxs)(At,{selected:f==="down",disabled:a||g,onClick:n(()=>l("down"),"onClick"),children:[(0,e.jsx)(Ws,{"aria-hidden":!0}),"Needs work"]}),c?(0,e.jsx)("div",{className:"ml-auto",children:c}):null]}),K?(0,e.jsxs)("div",{className:"mt-2 rounded-md border border-line/60 bg-bg-3/20 p-3",children:[(0,e.jsx)("div",{className:"mb-2 text-sm font-medium",children:"What could have been better?"}),(0,e.jsx)(ln,{value:A,onChange:n(k=>E(k.target.value),"onChange"),placeholder:"Add a short note",className:"min-h-20 resize-y bg-bg",disabled:a||g}),(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-end gap-2",children:[(0,e.jsx)(I,{type:"button",size:"sm",variant:"secondary",disabled:a||g,onClick:n(()=>{L(!1),E(""),b(void 0)},"onClick"),children:"Dismiss"}),(0,e.jsx)(I,{type:"button",size:"sm",disabled:a||g||!A.trim(),onClick:n(()=>{q("down",{...B?{allowSharing:!0}:{},reason:A})},"onClick"),children:g?"Saving...":"Save note"})]})]}):null,(0,e.jsx)(es,{open:!!d,onOpenChange:n(k=>{!k&&!g&&(N(null),O(null))},"onOpenChange"),children:(0,e.jsxs)(Wt,{children:[(0,e.jsxs)(Gt,{children:[(0,e.jsx)(Xt,{children:"Save your feedback sharing preference"}),(0,e.jsx)(an,{children:"Choose whether voted AI outputs can be included in this instance's feedback export. This answer becomes the default for future thumbs up and thumbs down votes."})]}),(0,e.jsxs)("div",{className:"space-y-3 text-sm text-ink-3",children:[(0,e.jsx)("p",{children:"This vote is always saved locally."}),(0,e.jsxs)("p",{children:["Choose ",(0,e.jsx)("span",{className:"font-medium text-ink",children:"Always allow"})," to share this vote and future voted AI outputs. Choose"," ",(0,e.jsx)("span",{className:"font-medium text-ink",children:"Don't allow"})," to keep this vote and future votes local."]}),(0,e.jsx)("p",{children:"You can change this later in Settings > General."}),m?(0,e.jsx)("a",{href:m,target:"_blank",rel:"noreferrer",className:"inline-flex text-sm text-ink underline underline-offset-4",children:"Read our terms of service"}):null]}),(0,e.jsxs)(nn,{children:[(0,e.jsx)(I,{type:"button",variant:"secondary",disabled:!d||g,onClick:n(()=>{d&&(d.vote==="down"&&b(!1),q(d.vote,d.reason?{reason:d.reason}:void 0,{keepReasonPromptOpen:d.keepReasonPromptOpen}))},"onClick"),children:g?"Saving...":"Don't allow"}),(0,e.jsx)(I,{type:"button",disabled:!d||g,onClick:n(()=>{d&&(d.vote==="down"&&b(!0),q(d.vote,{allowSharing:!0,...d.reason?{reason:d.reason}:{}},{keepReasonPromptOpen:d.keepReasonPromptOpen}))},"onClick"),children:g?"Saving...":"Always allow"})]})]})})]})}n($n,"OutputFeedbackButtons");function Lt(t){const a=t.createdByUserId?"board":t.createdByAgentId?"agent":"system";return`rev ${t.revisionNumber} — ${He(t.createdAt)} • ${a}`}n(Lt,"getRevisionLabel");function zn({issueId:t,documentKey:a,latestRevisionNumber:r,open:m,onOpenChange:x,revisionsQueryKey:c,revisionsQueryFn:h}){const{data:d}=ae({queryKey:c??M.issues.documentRevisions(t??"",a),queryFn:n(()=>h?h():J.listDocumentRevisions(t??"",a),"queryFn"),enabled:m}),N=(0,o.useMemo)(()=>d?[...d].sort((l,k)=>k.revisionNumber-l.revisionNumber):[],[d]),[g,p]=(0,o.useState)(null),[A,E]=(0,o.useState)(null),K=g??N.find(l=>l.revisionNumber===r-1)?.id??null,L=A??N.find(l=>l.revisionNumber===r)?.id??null,B=N.find(l=>l.id===K)??null,b=N.find(l=>l.id===L)??null,C=B?.body??"",O=b?.body??"",f=(0,o.useMemo)(()=>kn(C,O),[C,O]),q={context:"bg-transparent",removed:"bg-red-500/10 text-red-900 dark:text-red-100",added:"bg-green-500/10 text-green-900 dark:text-green-100"},X={context:" ",removed:"-",added:"+"};return(0,e.jsx)(es,{open:m,onOpenChange:x,children:(0,e.jsxs)(Wt,{className:"!max-w-(--pct-90) w-full max-h-(--sz-85vh) overflow-hidden flex flex-col",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,e.jsx)(Gt,{className:"shrink-0",children:(0,e.jsxs)(Xt,{children:["Diff — ",(0,e.jsx)("span",{className:"font-mono text-sm",children:a})]})}),(0,e.jsxs)("div",{className:"flex items-center gap-4 shrink-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(de,{variant:"outline",className:"border-red-500/30 bg-red-500/10 text-(length:--text-nano) uppercase tracking-wider text-red-400",children:"Old"}),(0,e.jsxs)(Dt,{value:K??"",onValueChange:n(l=>p(l),"onValueChange"),children:[(0,e.jsx)(St,{className:"h-7 w-60 text-xs border-line/60",children:(0,e.jsx)(Rt,{placeholder:"Select revision"})}),(0,e.jsx)(It,{children:N.map(l=>(0,e.jsx)(Ct,{value:l.id,className:"text-xs",children:Lt(l)},l.id))})]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(de,{variant:"outline",className:"border-green-500/30 bg-green-500/10 text-(length:--text-nano) uppercase tracking-wider text-green-400",children:"New"}),(0,e.jsxs)(Dt,{value:L??"",onValueChange:n(l=>E(l),"onValueChange"),children:[(0,e.jsx)(St,{className:"h-7 w-60 text-xs border-line/60",children:(0,e.jsx)(Rt,{placeholder:"Select revision"})}),(0,e.jsx)(It,{children:N.map(l=>(0,e.jsx)(Ct,{value:l.id,className:"text-xs",children:Lt(l)},l.id))})]})]})]})]}),(0,e.jsx)("div",{className:"overflow-auto flex-1 rounded-md border border-line text-xs",children:d?!B||!b?(0,e.jsx)("div",{className:"p-6 text-center text-ink-3 text-sm",children:"Select two revisions to compare."}):B.id===b.id?(0,e.jsx)("div",{className:"p-6 text-center text-ink-3 text-sm",children:"Both sides are the same revision."}):(0,e.jsxs)("div",{className:"font-mono text-xs leading-6",children:[(0,e.jsxs)("div",{className:"grid grid-cols-(--gtc-1) border-b border-line/60 bg-bg-3/30 px-3 py-2 text-(length:--text-micro) uppercase tracking-wide text-ink-3",children:[(0,e.jsx)("span",{children:"Old"}),(0,e.jsx)("span",{children:"New"}),(0,e.jsx)("span",{}),(0,e.jsx)("span",{children:"Content"})]}),f.map((l,k)=>(0,e.jsxs)("div",{className:`grid grid-cols-(--gtc-1) gap-0 border-b border-line/30 px-3 ${q[l.kind]}`,children:[(0,e.jsx)("span",{className:"select-none border-r border-line/30 pr-3 text-right text-ink-3",children:l.oldLineNumber??""}),(0,e.jsx)("span",{className:"select-none border-r border-line/30 px-3 text-right text-ink-3",children:l.newLineNumber??""}),(0,e.jsx)("span",{className:"select-none px-3 text-center text-ink-3",children:X[l.kind]}),(0,e.jsx)("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-3 py-0 text-inherit",children:l.text.length>0?l.text:" "})]},`${l.kind}-${k}-${l.oldLineNumber??"x"}-${l.newLineNumber??"x"}`))]}):(0,e.jsx)("div",{className:"p-6 text-center text-ink-3 text-sm",children:"Loading revisions..."})})]})})}n(zn,"DocumentDiffModal");var Qn=900,_t=/^[a-z0-9][a-z0-9_-]*$/,ls=n(t=>`wardmote:issue-document-folds:${t}`,"getFoldedDocumentsStorageKey");function Ft(t){if(typeof window>"u")return[];try{const a=window.localStorage.getItem(ls(t));if(!a)return[];const r=JSON.parse(a);return Array.isArray(r)?r.filter(m=>typeof m=="string"):[]}catch{return[]}}n(Ft,"loadFoldedDocumentKeys");function Ot(t,a){typeof window>"u"||window.localStorage.setItem(ls(t),JSON.stringify(a))}n(Ot,"saveFoldedDocumentKeys");function De(t,a,r){return(0,e.jsx)(pn,{children:(0,e.jsx)(qs,{className:a,softBreaks:!1,externalReferences:r,children:t})})}n(De,"renderFoldableBody");function ne(t){return t.trim().toLowerCase()==="plan"}n(ne,"isPlanKey");function Vn(t,a){return(t??"").trim().toLowerCase()===a.trim().toLowerCase()}n(Vn,"titlesMatchKey");function qn(t){return t instanceof Vt&&t.status===409}n(qn,"isDocumentConflictError");function Hn(t){return t instanceof Vt&&t.status===409&&t.message==="Document is locked"}n(Hn,"isLockedDocumentError");function Jn(t,a){const r=new Blob([a],{type:"text/markdown;charset=utf-8"}),m=URL.createObjectURL(r),x=document.createElement("a");x.href=m,x.download=`${t}.md`,document.body.appendChild(x),x.click(),x.remove(),URL.revokeObjectURL(m)}n(Jn,"downloadDocumentFile");function Zn(t,a){if(t.createdByAgentId){const r=a.agentMap?.get(t.createdByAgentId);return{kind:"agent",name:r?.name??t.createdByAgentId.slice(0,8),agentIcon:r?.icon??null,agent:r??{id:t.createdByAgentId}}}if(t.createdByUserId){const r=a.userProfileMap?.get(t.createdByUserId);return{kind:"user",name:r?.label??(t.createdByUserId==="local-board"?"Board":t.createdByUserId.slice(0,8)),imageUrl:r?.image??null}}return{kind:"system",name:"System"}}n(Zn,"getRevisionActor");function Ut(t,a){return!a||a.isNew||a.key!==t.key?!1:a.body!==t.body||(t.title??"")!==a.title}n(Ut,"documentHasUnsavedChanges");function Yn(t){return{id:t.id,companyId:t.companyId,issueId:t.issueId,key:t.key,title:t.title,format:t.format,latestRevisionId:t.latestRevisionId,latestRevisionNumber:t.latestRevisionNumber,createdByAgentId:t.createdByAgentId,createdByUserId:t.createdByUserId,updatedByAgentId:t.updatedByAgentId,updatedByUserId:t.updatedByUserId,lockedAt:t.lockedAt,lockedByAgentId:t.lockedByAgentId,lockedByUserId:t.lockedByUserId,sourceTrust:t.sourceTrust,createdAt:t.createdAt,updatedAt:t.updatedAt}}n(Yn,"toDocumentSummary");function Gn(t){return{id:t.id,detailQueryKey:M.issues.detail(t.id),documentsQueryKey:M.issues.documents(t.id),idleDocumentRevisionsQueryKey:["issues","document-revisions",t.id,"__idle__"],documentRevisionsQueryKey:n(a=>M.issues.documentRevisions(t.id,a),"documentRevisionsQueryKey"),listDocuments:n(()=>J.listDocuments(t.id),"listDocuments"),listDocumentRevisions:n(a=>J.listDocumentRevisions(t.id,a),"listDocumentRevisions"),getDocument:n(a=>J.getDocument(t.id,a),"getDocument"),upsertDocument:n((a,r)=>J.upsertDocument(t.id,a,r),"upsertDocument"),deleteDocument:n(a=>J.deleteDocument(t.id,a),"deleteDocument"),restoreDocumentRevision:n((a,r)=>J.restoreDocumentRevision(t.id,a,r),"restoreDocumentRevision"),setDocumentLock:n((a,r)=>r?J.lockDocument(t.id,a):J.unlockDocument(t.id,a),"setDocumentLock"),syncDetailCache:n((a,r)=>{a.setQueryData(M.issues.detail(t.id),m=>{if(!m)return m;const x=(()=>{const c=Yn(r),h=(m.documentSummaries??[]).findIndex(d=>d.key===r.key);return h===-1?[...m.documentSummaries??[],c]:(m.documentSummaries??[]).map((d,N)=>N===h?c:d)})();return{...m,planDocument:r.key==="plan"?r:m.planDocument??null,documentSummaries:x,legacyPlanDocument:r.key==="plan"?null:m.legacyPlanDocument??null}})},"syncDetailCache"),hideSystemDocuments:!0,legacyPlanDocument:t.legacyPlanDocument,annotations:{issueId:t.id}}}n(Gn,"makeIssueDocumentSubject");function Wn({issue:t,subject:a,canDeleteDocuments:r,canManageDocumentLocks:m=!1,feedbackVotes:x=[],feedbackDataSharingPreference:c="prompt",feedbackTermsUrl:h=null,mentions:d,imageUploadHandler:N,onVote:g,extraActions:p,agentMap:A,userProfileMap:E,defaultAnnotationPanelOpenKeys:K,defaultAnnotationFocusedThreadIds:L,forceEditDocumentKey:B,externalReferences:b}){const C=Je(),O=Es(),f=(0,o.useMemo)(()=>{if(a)return a;if(!t)throw new Error("IssueDocumentsSection requires either issue or subject");return Gn(t)},[t,a]),q=(0,o.useCallback)(s=>{const i=f.annotations?.target;if(i)return typeof i=="function"?i(s):i.kind==="issue"?{...i,documentKey:s}:i.kind==="case"?{...i,documentKey:s}:i},[f]),[X,l]=(0,o.useState)(null),[k,y]=(0,o.useState)(null),[v,R]=(0,o.useState)(null),[D,_]=(0,o.useState)(null),[me,Z]=(0,o.useState)(()=>Ft(f.id)),[tt,st]=(0,o.useState)(()=>K??[]),[nt,Te]=(0,o.useState)(null),[it,at]=(0,o.useState)(null),[rt,lt]=(0,o.useState)(null),[Y,os]=(0,o.useState)(null),[cs,Be]=(0,o.useState)({}),[ot,ct]=(0,o.useState)(null),z=(0,o.useRef)(null),xe=(0,o.useRef)(null),Pe=(0,o.useRef)(!1),{state:te,markDirty:dt,reset:ut,runSave:mt}=hn(),{data:ve}=ae({queryKey:f.documentsQueryKey,queryFn:f.listDocuments}),{data:xt,isFetching:ds}=ae({queryKey:Y?f.documentRevisionsQueryKey(Y):f.idleDocumentRevisionsQueryKey,queryFn:n(async()=>Y?f.listDocumentRevisions(Y):[],"queryFn"),enabled:!!Y}),re=(0,o.useCallback)(()=>{f.detailQueryKey&&C.invalidateQueries({queryKey:f.detailQueryKey}),C.invalidateQueries({queryKey:f.documentsQueryKey}),C.invalidateQueries({predicate:n(s=>Array.isArray(s.queryKey)&&s.queryKey.includes(f.id)&&(s.queryKey.includes("document-revisions")||s.queryKey.includes("document-annotations")||s.queryKey.includes("revisions")),"predicate")})},[f,C]),ke=(0,o.useCallback)(s=>{f.hideSystemDocuments&&_e(s.key)||(C.setQueryData(f.documentsQueryKey,i=>{if(!i)return[s];const u=i.findIndex(j=>j.key===s.key);return u===-1?[...i,s]:i.map((j,w)=>w===u?s:j)}),f.syncDetailCache?.(C,s))},[f,C]),se=ce({mutationFn:n(async s=>f.upsertDocument(s.key,{title:ne(s.key)?null:s.title.trim()||null,format:"markdown",body:s.body,baseRevisionId:s.baseRevisionId}),"mutationFn")}),je=ce({mutationFn:n(s=>f.deleteDocument?f.deleteDocument(s):Promise.reject(new Error("Document deletion is not available")),"mutationFn"),onSuccess:n(()=>{y(null),l(null),re()},"onSuccess"),onError:n(s=>{y(s instanceof Error?s.message:"Failed to delete document")},"onError")}),Ne=ce({mutationFn:n(({key:s,revisionId:i})=>f.restoreDocumentRevision?f.restoreDocumentRevision(s,i):Promise.reject(new Error("Document revision restore is not available")),"mutationFn"),onSuccess:n((s,i)=>{ke(s),Be(u=>({...u,[i.key]:null})),R(u=>u?.key===i.key?null:u),_(u=>u?.key===i.key?null:u),P(),y(null),re()},"onSuccess"),onError:n(s=>{y(s instanceof Error?s.message:"Failed to restore document revision")},"onError")}),fe=ce({mutationFn:n(({key:s,locked:i})=>f.setDocumentLock?f.setDocumentLock(s,i):Promise.reject(new Error("Document locking is not available")),"mutationFn"),onSuccess:n(s=>{ke(s),R(i=>i?.key===s.key?null:i),_(i=>i?.key===s.key?null:i),P(),y(null),re()},"onSuccess"),onError:n(s=>{y(s instanceof Error?s.message:"Failed to update document lock")},"onError")}),U=(0,o.useMemo)(()=>(ve??[]).filter(s=>!f.hideSystemDocuments||!_e(s.key)).sort((s,i)=>s.key==="plan"&&i.key!=="plan"?-1:s.key!=="plan"&&i.key==="plan"?1:new Date(i.updatedAt).getTime()-new Date(s.updatedAt).getTime()),[f.hideSystemDocuments,ve]),us=(0,o.useMemo)(()=>{const s=new Map;for(const i of x)i.targetType==="issue_document_revision"&&s.set(i.targetId,i.vote);return s},[x]),ms=U.some(s=>s.key==="plan"),xs=U.length===0&&!f.legacyPlanDocument,ft=v?.isNew&&v.key.trim().length>0&&!_t.test(v.key.trim())?"Use lowercase letters, numbers, -, or _, and start with a letter or number.":null,P=(0,o.useCallback)(()=>{Te(null),ut()},[ut]),we=(0,o.useCallback)(s=>{Te(s),dt()},[dt]),ht=n(()=>{P(),_(null),R({key:"",title:"",body:"",baseRevisionId:null,isNew:!0}),y(null)},"beginNewDocument"),pt=n(s=>{const i=U.find(j=>j.key===s);if(!i)return;const u=D?.key===s?D.localDraft:null;Z(j=>j.filter(w=>w!==s)),P(),_(j=>j?.key===s?j:null),R({key:u?.key??i.key,title:u?.title??i.title??"",body:u?.body??i.body,baseRevisionId:u?.baseRevisionId??i.latestRevisionId,isNew:!1}),y(null)},"beginEdit"),yt=(0,o.useRef)(!1);(0,o.useEffect)(()=>{B&&(yt.current||(ve??[]).find(s=>s.key===B)&&(yt.current=!0,pt(B)))},[B,ve]);const gt=n(()=>{z.current&&clearTimeout(z.current),P(),_(null),R(null),y(null)},"cancelDraft"),G=(0,o.useCallback)(async(s,i)=>{if(!s||se.isPending)return!1;const u=s.key.trim().toLowerCase(),j=s.body.trim(),w=s.title.trim(),ee=D?.key===u?D:null;if(ee&&!i?.overrideConflict)return i?.trackAutosave&&P(),!1;if(!u||!j)return s.isNew?y("Document key and body are required"):j||y("Document body cannot be empty"),i?.trackAutosave&&P(),!1;if(!_t.test(u))return y("Document key must start with a letter or number and use only lowercase letters, numbers, -, or _."),i?.trackAutosave&&P(),!1;const le=U.find(T=>T.key===u);if(!s.isNew&&le&&le.body===s.body&&(le.title??"")===s.title)return i?.clearAfterSave&&R(T=>T?.key===u?null:T),i?.trackAutosave&&P(),!0;const he=n(async()=>{const T=await se.mutateAsync({...s,key:u,title:ne(u)?"":w,body:s.body,baseRevisionId:i?.overrideConflict?ee?.serverDocument.latestRevisionId??s.baseRevisionId:s.baseRevisionId});y(null),_(Q=>Q?.key===u?null:Q),R(Q=>!Q||Q.key!==u?Q:i?.clearAfterSave?null:{key:T.key,title:T.title??"",body:T.body,baseRevisionId:T.latestRevisionId,isNew:!1}),ke(T),re()},"save");try{return i?.trackAutosave?(Te(u),await mt(he)):await he(),!0}catch(T){if(Hn(T))return y("Document is locked. Unlock it before editing."),P(),re(),!1;if(qn(T))try{const Q=await f.getDocument(u);return _({key:u,serverDocument:Q,localDraft:{key:u,title:ne(u)?"":w,body:s.body,baseRevisionId:s.baseRevisionId,isNew:!1},showRemote:!0}),Z(H=>H.filter(F=>F!==u)),y(null),P(),!1}catch{return y("Document changed remotely and the latest version could not be loaded"),!1}return y(T instanceof Error?T.message:"Failed to save document"),!1}},[D,f,re,P,mt,U,ke,se]),fs=(0,o.useCallback)(s=>{if(D?.key!==s)return;const i=D.serverDocument;R({key:i.key,title:i.title??"",body:i.body,baseRevisionId:i.latestRevisionId,isNew:!1}),_(null),P(),y(null)},[D,P]),hs=(0,o.useCallback)(async s=>{if(D?.key!==s)return;const i=v&&v.key===s&&!v.isNew?v:D.localDraft;await G({...i,baseRevisionId:D.serverDocument.latestRevisionId},{clearAfterSave:!1,trackAutosave:!0,overrideConflict:!0})},[G,D,v]),ps=(0,o.useCallback)(s=>{D?.key===s&&(R(D.localDraft),_(i=>i?.key===s?{...i,showRemote:!1}:i),y(null))},[D]),ys=(0,o.useCallback)(async(s,i)=>{try{await et(i),at(s),xe.current&&clearTimeout(xe.current),xe.current=setTimeout(()=>{at(u=>u===s?null:u)},1400)}catch{y("Could not copy document")}},[]),Ee=(0,o.useCallback)(s=>{const i=C.getQueryData(f.documentRevisionsQueryKey(s));return i||(Y===s?xt??[]:[])},[xt,f,C,Y]),Ke=(0,o.useCallback)(s=>{Be(i=>({...i,[s]:null})),y(null)},[]),gs=(0,o.useCallback)((s,i)=>{const u=Kt(s,Ee(s.key)),j=u.revisions.find(w=>w.id===i);if(j){if(j.id===u.currentRevision.id){Ke(s.key);return}if(D?.key===s.key||Ut(s,v)){y("Save or cancel your local changes before viewing an older revision.");return}P(),R(w=>w?.key===s.key?null:w),_(w=>w?.key===s.key?null:w),Z(w=>w.filter(ee=>ee!==s.key)),Be(w=>({...w,[s.key]:j.id})),y(null)}},[D,v,Ee,P,Ke]),bs=(0,o.useCallback)((s,i)=>{if(!(!m||fe.isPending)){if(i&&(D?.key===s.key||Ut(s,v))){y("Save or cancel local changes before changing the document lock.");return}fe.mutate({key:s.key,locked:i})}},[m,D,v,fe]),bt=n(async s=>{s.currentTarget.contains(s.relatedTarget)||(z.current&&clearTimeout(z.current),await G(v,{clearAfterSave:!0,trackAutosave:!0}))},"handleDraftBlur"),vt=n(async s=>{if(s.key==="Escape"){s.preventDefault(),gt();return}(s.metaKey||s.ctrlKey)&&s.key==="Enter"&&(s.preventDefault(),z.current&&clearTimeout(z.current),await G(v,{clearAfterSave:!1,trackAutosave:!0}))},"handleDraftKeyDown");(0,o.useEffect)(()=>{Z(Ft(f.id))},[f.id]),(0,o.useEffect)(()=>{Pe.current=!1},[f.id,O.hash]),(0,o.useEffect)(()=>{const s=new Set(U.map(i=>i.key));Z(i=>{const u=i.filter(j=>s.has(j));return u.length!==i.length&&Ot(f.id,u),u})},[f.id,U]),(0,o.useEffect)(()=>{Ot(f.id,me)},[f.id,me]),(0,o.useEffect)(()=>{if(!D)return;const s=U.find(i=>i.key===D.key);!s||s.latestRevisionId===D.serverDocument.latestRevisionId||_(i=>i?.key===s.key?{...i,serverDocument:s}:i)},[D,U]),(0,o.useEffect)(()=>{const s=O.hash;if(!s.startsWith("#document-"))return;const i=decodeURIComponent(s.slice(10));if(!(U.some(w=>w.key===i)||i==="plan"&&f.legacyPlanDocument)||Pe.current)return;Z(w=>w.filter(ee=>ee!==i));const u=document.getElementById(`document-${i}`);if(!u)return;Pe.current=!0,lt(i),u.scrollIntoView({behavior:"smooth",block:"center"});const j=setTimeout(()=>lt(w=>w===i?null:w),3e3);return()=>clearTimeout(j)},[f.legacyPlanDocument,O.hash,U]),(0,o.useEffect)(()=>()=>{z.current&&clearTimeout(z.current),xe.current&&clearTimeout(xe.current)},[]),(0,o.useEffect)(()=>{if(!v||v.isNew||D?.key===v.key)return;const s=U.find(i=>i.key===v.key);if(s){if(!(s.body!==v.body||(s.title??"")!==v.title)){te!=="saved"&&P();return}return we(v.key),z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{G(v,{clearAfterSave:!1,trackAutosave:!0})},Qn),()=>{z.current&&clearTimeout(z.current)}}},[te,G,D,v,we,P,U]);const vs="mt-3",ks="",Ce="wardmote-edit-in-place-content min-h-(--sz-220px) text-sm leading-7",js=n(s=>{Z(i=>i.includes(s)?i.filter(u=>u!==s):[...i,s])},"toggleFoldedDocument"),Ns=(0,o.useCallback)((s,i)=>{st(u=>{const j=u.includes(s);return i&&!j?[...u,s]:!i&&j?u.filter(w=>w!==s):u}),i&&Z(u=>u.filter(j=>j!==s))},[]),ws=(0,o.useCallback)(s=>{st(i=>i.includes(s)?i.filter(u=>u!==s):(Z(u=>u.filter(j=>j!==s)),[...i,s]))},[]);return(0,e.jsxs)("div",{className:"space-y-3",children:[xs&&!v?.isNew?(0,e.jsxs)("div",{className:"flex flex-wrap items-center justify-end gap-2 min-w-0",children:[p,(0,e.jsxs)(I,{variant:"secondary",size:"sm",onClick:ht,className:"shrink-0",children:[(0,e.jsx)(ze,{className:"mr-1.5 h-3.5 w-3.5"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"New document"}),(0,e.jsx)("span",{className:"sm:hidden",children:"New"})]})]}):(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 min-w-0",children:[(0,e.jsx)("h3",{className:"w-full text-sm font-medium text-ink-3 shrink-0 sm:w-auto",children:"Documents"}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2 min-w-0 sm:ml-auto",children:[p,(0,e.jsxs)(I,{variant:"secondary",size:"sm",onClick:ht,className:"shrink-0",children:[(0,e.jsx)(ze,{className:"mr-1.5 h-3.5 w-3.5"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"New document"}),(0,e.jsx)("span",{className:"sm:hidden",children:"New"})]})]})]}),k&&(0,e.jsx)("p",{className:"text-xs text-bad",children:k}),v?.isNew&&(0,e.jsxs)("div",{className:"space-y-3 rounded-lg border border-line bg-bg-3/10 p-3",onBlurCapture:bt,onKeyDown:vt,children:[(0,e.jsx)(Se,{autoFocus:!0,value:v.key,onChange:n(s=>R(i=>i&&{...i,key:s.target.value.toLowerCase()}),"onChange"),placeholder:"Document key"}),ft&&(0,e.jsx)("p",{className:"text-xs text-bad",children:ft}),!ne(v.key)&&(0,e.jsx)(Se,{value:v.title,onChange:n(s=>R(i=>i&&{...i,title:s.target.value}),"onChange"),placeholder:"Optional title"}),(0,e.jsx)(Nt,{value:v.body,onChange:n(s=>R(i=>i&&{...i,body:s}),"onChange"),placeholder:"Markdown body",bordered:!1,className:"bg-transparent",contentClassName:"min-h-(--sz-220px) text-sm leading-7",mentions:d,imageUploadHandler:N,onSubmit:n(()=>{G(v,{clearAfterSave:!1,trackAutosave:!1})},"onSubmit")}),(0,e.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,e.jsxs)(I,{variant:"secondary",size:"sm",onClick:gt,children:[(0,e.jsx)(sn,{className:"mr-1.5 h-3.5 w-3.5"}),"Cancel"]}),(0,e.jsx)(I,{size:"sm",onClick:n(()=>{G(v,{clearAfterSave:!1,trackAutosave:!1})},"onClick"),disabled:se.isPending,children:se.isPending?"Saving...":"Create document"})]})]}),!ms&&f.legacyPlanDocument?(0,e.jsxs)("div",{id:"document-plan",className:$("rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 transition-colors duration-1000",rt==="plan"&&"border-accent/50 bg-accent/5"),children:[(0,e.jsxs)("div",{className:"mb-2 flex items-center gap-2",children:[(0,e.jsx)(Yt,{className:"h-4 w-4 text-amber-600"}),(0,e.jsx)(de,{variant:"outline",className:"border-amber-500/30 font-mono text-(length:--text-nano) uppercase tracking-(--tracking-eyebrow) text-amber-700 dark:text-amber-300",children:"PLAN"})]}),(0,e.jsx)("div",{className:ks,children:De(f.legacyPlanDocument.body,Ce,b)})]}):null,(0,e.jsx)("div",{className:"space-y-3",children:U.map(s=>{const i=!!s.lockedAt,u=!i&&v?.key===s.key&&!v.isNew?v:null,j=!i&&D?.key===s.key?D:null,w=me.includes(s.key),ee=Ee(s.key),le=Kt(s,ee),he=le.revisions,T=le.currentRevision,Q=cs[s.key]??null,H=Q?he.find(S=>S.id===Q)??null:null,F=!!H,Le=H?H.title??"":u?.title??T.title??"",oe=H?.body??u?.body??T.body,Cs=H?.revisionNumber??T.revisionNumber,Ds=H?.createdAt??T.createdAt,Ss=!ne(s.key)&&!!Le.trim()&&!Vn(Le,s.key),Is=!!(s.latestRevisionId&&s.updatedByAgentId&&!s.updatedByUserId&&g),Rs=fe.isPending&&fe.variables?.key===s.key,kt=q(s.key);return(0,e.jsxs)("div",{id:`document-${s.key}`,className:$("rounded-lg border border-line p-3 transition-colors duration-1000",rt===s.key&&"border-accent/50 bg-accent/5"),children:[(0,e.jsx)(jn,{documentKey:s.key,folded:w,onToggleFolded:n(()=>js(s.key),"onToggleFolded"),sourceTrustSlot:(0,e.jsx)(yn,{sourceTrust:s.sourceTrust,artifactLabel:"document"}),revisionMenu:{open:Y===s.key,onOpenChange:n(S=>os(S?s.key:null),"onOpenChange"),loading:Y===s.key&&ds,revisions:he.map(S=>({id:S.id,revisionNumber:S.revisionNumber,createdAt:S.createdAt,actor:Zn(S,{agentMap:A,userProfileMap:E})})),selectedRevisionId:Q,currentRevisionId:T.id,displayedRevisionNumber:Cs,historicalPreview:F,onSelectRevision:n(S=>gs(s,S),"onSelectRevision")},updatedAt:Ds,annotationSlot:f.annotations&&!_e(s.key)?(0,e.jsx)(_s,{issueId:f.annotations.issueId,target:kt,docKey:s.key,panelOpen:tt.includes(s.key),onToggle:n(()=>ws(s.key),"onToggle")}):null,titleSlot:Ss?(0,e.jsx)("p",{className:"mt-2 text-sm font-medium",children:Le}):null,actionsSlot:(0,e.jsxs)(e.Fragment,{children:[m?(0,e.jsx)(I,{variant:"ghost",size:"icon-xs",className:$("transition-colors"),title:i?"Unlock document":"Lock document","aria-label":i?`Unlock ${s.key} document`:`Lock ${s.key} document`,onClick:n(()=>bs(s,!i),"onClick"),disabled:Rs,children:i?(0,e.jsx)(jt,{className:"h-3.5 w-3.5"}):(0,e.jsx)(wn,{className:"h-3.5 w-3.5"})}):i?(0,e.jsx)("span",{title:"Locked document","aria-label":"Locked document",className:"inline-flex h-6 w-6 items-center justify-center text-amber-700 dark:text-amber-300",children:(0,e.jsx)(jt,{className:"h-3.5 w-3.5"})}):null,(0,e.jsx)(I,{variant:"ghost",size:"icon-xs",className:$("transition-colors"),title:it===s.key?"Copied":"Copy document",onClick:n(()=>{ys(s.key,oe)},"onClick"),children:it===s.key?(0,e.jsx)(ue,{className:"h-3.5 w-3.5"}):(0,e.jsx)(Zt,{className:"h-3.5 w-3.5"})}),(0,e.jsxs)(Jt,{children:[(0,e.jsx)(qt,{asChild:!0,children:(0,e.jsx)(I,{variant:"ghost",size:"icon-xs",title:"Document actions",children:(0,e.jsx)(Js,{className:"h-3.5 w-3.5"})})}),(0,e.jsxs)(Ht,{align:"end",children:[!F&&!i?(0,e.jsxs)(be,{onClick:n(()=>pt(s.key),"onClick"),children:[(0,e.jsx)(Zs,{className:"h-3.5 w-3.5"}),"Edit document"]}):null,!F&&!i?(0,e.jsx)($e,{}):null,(0,e.jsxs)(be,{onClick:n(()=>Jn(s.key,oe),"onClick"),children:[(0,e.jsx)(un,{className:"h-3.5 w-3.5"}),"Download document"]}),s.latestRevisionNumber>1?(0,e.jsxs)(be,{onClick:n(()=>ct(s.key),"onClick"),children:[(0,e.jsx)(Nn,{className:"h-3.5 w-3.5"}),"View diff"]}):null,r&&!i?(0,e.jsx)($e,{}):null,r&&!i?(0,e.jsxs)(be,{variant:"destructive",onClick:n(()=>l(s.key),"onClick"),children:[(0,e.jsx)(en,{className:"h-3.5 w-3.5"}),"Delete document"]}):null]})]})]})}),w?null:(0,e.jsxs)("div",{className:"mt-3 space-y-3",onBlurCapture:F?void 0:async S=>{u&&await bt(S)},onKeyDown:F?void 0:async S=>{u&&await vt(S)},children:[F&&H&&(0,e.jsx)("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-3",children:(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsxs)("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:["Viewing revision ",H.revisionNumber]}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"This is a historical preview. Restoring it creates a new latest revision and keeps history append-only."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>Ke(s.key),"onClick"),children:"Return to latest"}),i?null:(0,e.jsx)(I,{size:"sm",onClick:n(()=>Ne.mutate({key:s.key,revisionId:H.id}),"onClick"),disabled:Ne.isPending,children:Ne.isPending&&Ne.variables?.key===s.key?"Restoring...":"Restore this revision"})]})]})}),j&&!F&&(0,e.jsxs)("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-3",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:"Out of date"}),(0,e.jsx)("p",{className:"text-xs text-ink-3",children:"This document changed while you were editing. Your local draft is preserved and autosave is paused."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>_(S=>S?.key===s.key?{...S,showRemote:!S.showRemote}:S),"onClick"),children:j.showRemote?"Hide remote":"Review remote"}),(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>ps(s.key),"onClick"),children:"Keep my draft"}),(0,e.jsx)(I,{variant:"secondary",size:"sm",onClick:n(()=>fs(s.key),"onClick"),children:"Reload remote"}),(0,e.jsx)(I,{size:"sm",onClick:n(()=>{hs(s.key)},"onClick"),disabled:se.isPending,children:se.isPending?"Saving...":"Overwrite remote"})]})]}),j.showRemote&&(0,e.jsxs)("div",{className:"mt-3 rounded-md border border-line/70 bg-bg/60 p-3",children:[(0,e.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-(length:--text-micro) text-ink-3",children:[(0,e.jsxs)("span",{children:["Remote revision ",j.serverDocument.latestRevisionNumber]}),(0,e.jsx)("span",{children:"•"}),(0,e.jsxs)("span",{children:["updated ",He(j.serverDocument.updatedAt)]})]}),!ne(s.key)&&j.serverDocument.title?(0,e.jsx)("p",{className:"mb-2 text-sm font-medium",children:j.serverDocument.title}):null,De(j.serverDocument.body,"text-sm leading-7",b)]})]}),u&&!ne(s.key)&&!F&&(0,e.jsx)(Se,{value:u.title,onChange:n(S=>{we(s.key),R(W=>W&&{...W,title:S.target.value})},"onChange"),placeholder:"Optional title"}),(0,e.jsx)("div",{className:`${vs} ${u||F?"":"rounded-md hover:bg-bg-3/10"}`,children:(()=>{const S=F?De(oe,Ce,b):u?(0,e.jsx)(Nt,{value:oe,onChange:n(W=>{we(s.key),R(pe=>pe&&pe.key===s.key&&!pe.isNew?{...pe,body:W}:pe)},"onChange"),placeholder:"Markdown body",bordered:!1,className:"bg-transparent",contentClassName:Ce,mentions:d,imageUploadHandler:N,onSubmit:n(()=>{G(u??v,{clearAfterSave:!1,trackAutosave:!0})},"onSubmit")}):De(oe,Ce,b);return f.annotations?(0,e.jsx)(Ls,{issueId:f.annotations.issueId,target:kt,doc:s,bodyMarkdown:oe,draftDirty:!!u&&((u?.body??s.body)!==s.body||nt===s.key&&te==="saving"),draftConflicted:!!j,historicalPreview:F,locationHash:O.hash,panelOpen:tt.includes(s.key),onPanelOpenChange:n(W=>Ns(s.key,W),"onPanelOpenChange"),agentMap:A,userProfileMap:E,defaultFocusedThreadId:L?.[s.key],children:S}):S})()}),(0,e.jsx)("div",{className:"flex min-h-4 items-center justify-end px-1",children:(0,e.jsx)("span",{className:`text-(length:--text-micro) transition-opacity duration-150 ${F||j?"text-amber-700 dark:text-amber-300":te==="error"?"text-bad":"text-ink-3"} ${u||F?"opacity-100":"opacity-0"}`,children:F?"Viewing historical revision":u?j?"Out of date":nt===s.key?te==="saving"?"Autosaving...":te==="saved"?"Saved":te==="error"?"Could not save":"":"":""})}),Is&&s.latestRevisionId?(0,e.jsx)($n,{activeVote:us.get(s.latestRevisionId)??null,sharingPreference:c,termsUrl:h,onVote:n((S,W)=>g?.(s.latestRevisionId,S,W)??Promise.resolve(),"onVote")}):null]}),X===s.key&&(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-between gap-3 rounded-md border border-bad/20 bg-bad/5 px-4 py-3",children:[(0,e.jsx)("p",{className:"text-sm text-bad font-medium",children:"Delete this document? This cannot be undone."}),(0,e.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,e.jsx)(I,{variant:"ghost",size:"sm",onClick:n(()=>l(null),"onClick"),disabled:je.isPending,children:"Cancel"}),(0,e.jsx)(I,{variant:"delete",size:"sm",onClick:n(()=>je.mutate(s.key),"onClick"),disabled:je.isPending,children:je.isPending?"Deleting...":"Delete"})]})]})]},s.id)})}),ot&&(()=>{const s=U.find(i=>i.key===ot);return s?(0,e.jsx)(zn,{documentKey:s.key,latestRevisionNumber:s.latestRevisionNumber,revisionsQueryKey:f.documentRevisionsQueryKey(s.key),revisionsQueryFn:n(()=>f.listDocumentRevisions(s.key),"revisionsQueryFn"),open:!0,onOpenChange:n(i=>{i||ct(null)},"onOpenChange")}):null})()]})}n(Wn,"IssueDocumentsSection");var Xn={draft:"Draft",in_progress:"In progress",in_review:"In review",approved:"Approved",done:"Done",cancelled:"Cancelled"},Mt=["name","title","body","description"],ei=["backlog","todo","in_progress","in_review","done","blocked","cancelled"];function ti(t){return ei.includes(t)?t:void 0}n(ti,"issueReferenceStatus");function Ue(t,a){return t[a]??t[a.charAt(0).toUpperCase()+a.slice(1)]}n(Ue,"fieldValueByName");function Me(t){return t?[t,t.charAt(0).toUpperCase()+t.slice(1),t.charAt(0).toLowerCase()+t.slice(1)]:[t]}n(Me,"caseFieldKeyVariants");function si(t){return t!=null&&!(typeof t=="string"&&t.trim()==="")}n(si,"hasFieldValue");function ni(t){const a=new Set(Mt.flatMap(c=>Me(c))),r=new Set(t.documents.flatMap(c=>Me(c.key))),m=Mt.map(c=>{if(Me(c).some(d=>r.has(d)))return null;let h;return c==="title"?h=Ue(t.fields,c)??t.title:h=Ue(t.fields,c),{key:c,label:c,value:h}}).filter(c=>c!==null&&si(c.value)),x=Object.entries(t.fields).filter(([c])=>!a.has(c)&&!r.has(c)).map(([c,h])=>({key:c,label:c,value:h}));return[...m,...x]}n(ni,"casePropertyRows");function ii(t){return{id:t.id,companyId:t.companyId,title:t.title,format:t.format,latestBody:t.body,latestRevisionId:t.latestRevisionId,latestRevisionNumber:t.latestRevisionNumber,createdByAgentId:t.createdByAgentId,createdByUserId:t.createdByUserId,updatedByAgentId:t.updatedByAgentId,updatedByUserId:t.updatedByUserId,lockedAt:t.lockedAt?new Date(t.lockedAt).toISOString():null,lockedByAgentId:t.lockedByAgentId,lockedByUserId:t.lockedByUserId,sourceTrust:t.sourceTrust,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString()}}n(ii,"issueDocumentToCaseDocument");function ai({parent:t,children:a}){return!t&&a.length===0?null:(0,e.jsxs)("section",{className:"space-y-3","aria-label":"Case relationships",children:[t?(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("h2",{className:"text-xs font-medium text-ink-3",children:"Parent"}),(0,e.jsx)(qe,{children:[t]})]}):null,a.length>0?(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsxs)("h2",{className:"text-xs font-medium text-ink-3",children:["Children ",a.length]}),(0,e.jsx)(qe,{children:a,maxVisible:5})]}):null]})}n(ai,"CaseRelationshipsSection");function ie({label:t,children:a,wrap:r,mode:m}){return m==="compact"?(0,e.jsx)(Ys,{label:t,wrap:r,children:a}):(0,e.jsxs)("div",{className:$("flex w-full min-w-0 gap-3 py-1",r?"items-start":"items-center"),"data-property-row":"true",children:[(0,e.jsx)("span",{className:$("w-40 shrink-0 break-words text-xs text-ink-3",r&&"mt-0.5"),"data-property-label":t,children:t}),(0,e.jsx)("div",{className:$("flex min-w-0 flex-1 items-center gap-1.5",r&&"flex-wrap"),children:a})]})}n(ie,"CasePropertyRow");function ri({status:t,onChange:a,disabled:r}){const[m,x]=(0,o.useState)(!1);return(0,e.jsxs)(We,{open:m,onOpenChange:x,children:[(0,e.jsx)(Ye,{asChild:!0,children:(0,e.jsxs)("button",{type:"button",disabled:r,className:"inline-flex items-center gap-1 rounded-md hover:bg-bg-3/50 disabled:opacity-50","aria-label":"Change case status",children:[(0,e.jsx)(Qe,{status:t}),(0,e.jsx)(Xe,{className:"h-3.5 w-3.5 text-ink-3"})]})}),(0,e.jsx)(Ge,{align:"end",className:"w-44 p-1",children:bn.map(c=>(0,e.jsxs)("button",{type:"button",onClick:n(()=>{x(!1),c!==t&&a(c)},"onClick"),className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-left hover:bg-bg-3",children:[(0,e.jsx)(Qe,{status:c}),c===t&&(0,e.jsx)(ue,{className:"h-4 w-4 text-ink-3"})]},c))})]})}n(ri,"CaseStatusPicker");function li({companyId:t,selected:a,onChange:r}){const[m,x]=(0,o.useState)(!1),[c,h]=(0,o.useState)(""),[d,N]=(0,o.useState)(Ts[0]),g=Je(),p=ae({queryKey:M.issues.labels(t),queryFn:n(()=>J.listLabels(t),"queryFn"),enabled:m}),A=new Set(a.map(b=>b.id)),E=ce({mutationFn:n(b=>J.createLabel(t,b),"mutationFn"),onSuccess:n(b=>{g.setQueryData(M.issues.labels(t),C=>C?[...C,b]:[b]),r([...A,b.id]),h("")},"onSuccess")}),K=p.data??[],L=c.trim()?K.filter(b=>b.name.toLowerCase().includes(c.trim().toLowerCase())):K;function B(b){const C=new Set(A);C.has(b)?C.delete(b):C.add(b),r([...C])}return n(B,"toggle"),(0,e.jsxs)(We,{open:m,onOpenChange:x,children:[(0,e.jsx)(Ye,{asChild:!0,children:(0,e.jsxs)(I,{variant:"ghost",size:"sm",className:"h-6 gap-1 px-2 text-xs",children:[(0,e.jsx)(ze,{className:"h-3.5 w-3.5"})," Labels"]})}),(0,e.jsxs)(Ge,{align:"start",className:"w-64 p-2",children:[(0,e.jsx)(Se,{value:c,onChange:n(b=>h(b.target.value),"onChange"),placeholder:"Search labels…",className:"mb-2 h-7 text-xs"}),(0,e.jsxs)("div",{className:"max-h-52 space-y-0.5 overflow-y-auto",children:[L.map(b=>(0,e.jsxs)("button",{type:"button",onClick:n(()=>B(b.id),"onClick"),className:"flex w-full items-center gap-2 rounded px-2 py-1 text-left text-sm hover:bg-bg-3",children:[(0,e.jsx)("span",{className:"h-3 w-3 shrink-0 rounded-full",style:{backgroundColor:b.color}}),(0,e.jsx)("span",{className:"flex-1 truncate",children:b.name}),A.has(b.id)&&(0,e.jsx)(ue,{className:"h-4 w-4 text-ink-3"})]},b.id)),L.length===0&&!c.trim()&&(0,e.jsx)("p",{className:"px-2 py-1 text-xs text-ink-3",children:"No labels yet."})]}),c.trim()&&!K.some(b=>b.name.toLowerCase()===c.trim().toLowerCase())&&(0,e.jsxs)("div",{className:"mt-2 flex items-center gap-2 border-t border-line pt-2",children:[(0,e.jsx)("input",{type:"color",value:d,onChange:n(b=>N(b.target.value),"onChange"),className:"h-6 w-6 shrink-0 cursor-pointer rounded border border-line bg-transparent","aria-label":"New label color"}),(0,e.jsxs)(I,{size:"sm",variant:"secondary",className:"h-7 flex-1 text-xs",disabled:E.isPending,onClick:n(()=>E.mutate({name:c.trim(),color:d}),"onClick"),children:["Create “",c.trim(),"”"]})]})]})]})}n(li,"CaseLabelsPicker");function $t({caseData:t,childCases:a,childrenError:r,companyId:m,labelsPending:x,onLabelIdsChange:c,mode:h}){const d=ni(t),N=h==="full";return(0,e.jsxs)("div",{className:$("space-y-4",N&&"space-y-6"),children:[(0,e.jsxs)(ye,{title:"Case",first:!0,children:[(0,e.jsx)(ie,{label:"Type",mode:h,children:(0,e.jsx)(wt,{children:t.caseType})}),t.key?(0,e.jsx)(ie,{label:"Key",mode:h,children:(0,e.jsx)(ss,{value:t.key,label:"case key",className:"font-mono text-xs text-ink-3",truncate:!N})}):null,(0,e.jsxs)(ie,{label:"Labels",wrap:!0,mode:h,children:[t.labels.length>0?t.labels.map(g=>(0,e.jsx)(wt,{style:{borderColor:g.color,color:g.color},className:"bg-transparent",children:g.name},g.id)):(0,e.jsx)("span",{className:"text-xs text-ink-3",children:"None"}),m?(0,e.jsx)(li,{companyId:m,selected:t.labels,onChange:c}):null,x?(0,e.jsx)("span",{className:"text-xs text-ink-3",children:"Saving..."}):null]})]}),d.length>0?(0,e.jsx)(ye,{title:"Fields",children:d.map(({key:g,label:p,value:A})=>(0,e.jsx)(ie,{label:p,wrap:N||Array.isArray(A)||typeof A=="object"&&A!==null,mode:h,children:(0,e.jsx)("span",{className:$("min-w-0 text-sm",!N&&"truncate"),children:(0,e.jsx)(rs,{value:A,fieldKey:g,variant:h})})},g))}):null,(0,e.jsx)(ye,{title:"Linked tasks",children:t.issueLinks.length===0?(0,e.jsx)(ie,{label:"Tasks",mode:h,children:(0,e.jsx)("span",{className:"text-xs text-ink-3",children:"None yet"})}):(0,e.jsx)(ie,{label:"Tasks",wrap:!0,mode:h,children:(0,e.jsx)("div",{className:"flex flex-wrap items-center gap-1.5",children:t.issueLinks.map(g=>(0,e.jsx)(ts,{issue:{id:g.issue.id,identifier:g.issue.identifier,title:g.issue.title,status:ti(g.issue.status)}},g.id))})})}),(0,e.jsx)(ye,{title:`Children${a.length>0?` ${a.length}`:""}`,children:r?(0,e.jsx)("p",{className:"text-xs text-bad",children:"Could not load child cases."}):(0,e.jsx)(qe,{children:a})}),t.attachments.length>0?(0,e.jsx)(ye,{title:"Attachments",children:(0,e.jsx)(ie,{label:"Files",mode:h,children:(0,e.jsxs)("span",{className:"text-xs text-ink-3",children:[t.attachments.length," ",t.attachments.length===1?"file":"files"]})})}):null]})}n($t,"CasePropertiesContent");function ia(){const{caseIdentifier:t}=Ks(),{selectedCompanyId:a}=Fs(),{setBreadcrumbs:r}=rn(),{openPanel:m,closePanel:x}=dn(),c=Je(),h=Ze(),[d,N]=(0,o.useState)(!1),g=ae({queryKey:M.cases.detail(t??""),queryFn:n(()=>V.get(t),"queryFn"),enabled:!!t}),p=g.data,A=M.cases.detail(t??""),E=ae({queryKey:M.cases.events(t??""),queryFn:n(()=>V.listEvents(t,100),"queryFn"),enabled:!!t}),K=ae({queryKey:M.cases.children(p?.id??""),queryFn:n(()=>V.listChildren(a,p.id),"queryFn"),enabled:!!a&&!!p?.id}),L=(0,o.useMemo)(()=>K.data??[],[K.data]),B=ce({mutationFn:n(l=>V.patch(t,l),"mutationFn"),onSuccess:n(l=>{c.setQueryData(M.cases.detail(t??""),l),c.invalidateQueries({queryKey:M.cases.events(t??"")})},"onSuccess")}),b=(0,o.useCallback)(l=>{B.mutate({labelIds:l})},[B.mutate]);(0,o.useEffect)(()=>{r([{label:"Cases",href:h()},{label:p?`${p.identifier} — ${p.title}`:t??"Case"}])},[r,p,t,h]);const C=(0,o.useMemo)(()=>E.data??[],[E.data]),O=(0,o.useMemo)(()=>!p||!t?null:{id:p.id,detailQueryKey:A,documentsQueryKey:M.cases.documents(p.id),idleDocumentRevisionsQueryKey:["cases","revisions",p.id,"__idle__"],documentRevisionsQueryKey:n(l=>M.cases.revisions(p.id,l),"documentRevisionsQueryKey"),listDocuments:n(async()=>{const l=c.getQueryData(A)??await V.get(t);return l.documents.map(k=>ge(l.id,k.key,k.document))},"listDocuments"),listDocumentRevisions:n(async l=>(await V.listRevisions(t,l)).revisions.map(k=>gn(p.id,l,k)),"listDocumentRevisions"),getDocument:n(async l=>{const k=await V.getDocument(t,l);return ge(p.id,k.key,k)},"getDocument"),upsertDocument:n(async(l,k)=>{const y=await V.upsertDocument(t,l,k);return ge(p.id,y.document.key,y.document)},"upsertDocument"),deleteDocument:n(l=>V.deleteDocument(t,l),"deleteDocument"),restoreDocumentRevision:n(async(l,k)=>{const y=await V.restoreDocumentRevision(t,l,k);return ge(p.id,y.document.key,y.document)},"restoreDocumentRevision"),setDocumentLock:n(async(l,k)=>{const y=k?await V.lockDocument(t,l):await V.unlockDocument(t,l);return ge(p.id,y.key,y)},"setDocumentLock"),syncDetailCache:n((l,k)=>{l.setQueryData(A,y=>{if(!y)return y;const v={key:k.key,document:ii(k)},R=y.documents.findIndex(_=>_.key===k.key),D=R===-1?[...y.documents,v]:y.documents.map((_,me)=>me===R?v:_);return{...y,documents:D,updatedAt:new Date(k.updatedAt).toISOString()}})},"syncDetailCache"),hideSystemDocuments:!1,legacyPlanDocument:null,annotations:{issueId:p.id,target:n(l=>({kind:"case",caseId:p.id,documentKey:l}),"target")}},[p,A,t,c]),f=(0,o.useMemo)(()=>p?(0,e.jsx)($t,{caseData:p,childCases:L,childrenError:K.isError,companyId:a,labelsPending:B.isPending,onLabelIdsChange:b,mode:"compact"}):null,[p,L,K.isError,a,B.isPending,b]);if((0,o.useEffect)(()=>{if(f)return m(f),()=>x()},[f,m,x]),!t)return(0,e.jsx)(Us,{to:h(),replace:!0});if(g.isLoading)return(0,e.jsx)(mn,{variant:"detail"});if(g.isError||!p)return(0,e.jsxs)("div",{className:"mx-auto max-w-md py-16 text-center",children:[(0,e.jsx)("p",{className:"text-sm text-ink-3",children:"Case not found."}),(0,e.jsx)(Ae,{to:h(),className:"mt-2 inline-block text-sm text-accent hover:underline",children:"← Back to cases"})]});const q=p.fields.description??p.fields.Description??null;function X(l){const k=[`# ${l.identifier} ${l.title}`,"",`- Key: ${l.key??"none"}`,`- Type: ${l.caseType}`,`- Status: ${Xn[l.status]}`,l.labels.length>0?`- Labels: ${l.labels.map(y=>y.name).join(", ")}`:"- Labels: none"].join(`
2
2
  `);et(k).then(()=>{N(!0),window.setTimeout(()=>N(!1),1500)})}return n(X,"copyCaseToClipboard"),(0,e.jsxs)("div",{className:"mx-auto max-w-3xl space-y-6",children:[(0,e.jsxs)("header",{className:"space-y-3",children:[(0,e.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,e.jsxs)("div",{className:"min-w-0 space-y-1",children:[(0,e.jsx)(vn,{identifier:p.identifier,caseKey:p.key}),(0,e.jsx)("h1",{className:"text-xl font-bold",children:p.title})]}),(0,e.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[(0,e.jsx)(ri,{status:p.status,disabled:B.isPending,onChange:n(l=>B.mutate({status:l}),"onChange")}),(0,e.jsxs)(We,{children:[(0,e.jsx)(Ye,{asChild:!0,children:(0,e.jsx)(I,{variant:"ghost",size:"icon-xs","aria-label":"More case actions",title:"More case actions",children:(0,e.jsx)(Hs,{className:"h-4 w-4"})})}),(0,e.jsxs)(Ge,{align:"end",className:"w-48 p-1",children:[(0,e.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs hover:bg-bg-3/50",onClick:n(()=>X(p),"onClick"),children:[d?(0,e.jsx)(ue,{className:"h-3 w-3"}):(0,e.jsx)(Zt,{className:"h-3 w-3"}),"Copy as markdown"]}),(0,e.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs hover:bg-bg-3/50",onClick:n(()=>{f&&m(f)},"onClick"),children:[(0,e.jsx)(xn,{className:"h-3 w-3"}),"Properties"]})]})]})]})]}),(0,e.jsx)("div",{className:"flex flex-wrap items-center gap-2",children:(0,e.jsx)(de,{variant:"secondary",children:p.caseType})}),(0,e.jsx)(ai,{parent:p.parent,children:L})]}),(0,e.jsxs)(Qs,{defaultValue:"overview",className:"space-y-4",children:[(0,e.jsxs)(zs,{variant:"line",className:"w-full justify-start gap-1",children:[(0,e.jsx)(Fe,{value:"overview",children:"Overview"}),(0,e.jsx)(Fe,{value:"properties",children:"Properties"}),(0,e.jsxs)(Fe,{value:"activity",children:["Activity",C.length>0&&(0,e.jsx)("span",{className:"ml-1 text-ink-3",children:C.length})]})]}),(0,e.jsxs)(Oe,{value:"overview",className:"space-y-6",children:[O?(0,e.jsx)(Wn,{subject:O,canDeleteDocuments:!0,canManageDocumentLocks:!0}):null,q?(0,e.jsxs)("section",{className:"space-y-2",children:[(0,e.jsx)("h2",{className:"text-sm font-semibold",children:"Description"}),(0,e.jsx)(on,{className:"px-4 py-3",children:(0,e.jsx)(rs,{value:q})})]}):null,p.attachments.length>0&&(0,e.jsxs)("section",{className:"space-y-2",children:[(0,e.jsxs)("h2",{className:"text-sm font-semibold",children:["Attachments (",p.attachments.length,")"]}),(0,e.jsx)(Un,{attachments:p.attachments})]})]}),(0,e.jsx)(Oe,{value:"properties",children:(0,e.jsx)($t,{caseData:p,childCases:L,childrenError:K.isError,companyId:a,labelsPending:B.isPending,onLabelIdsChange:b,mode:"full"})}),(0,e.jsx)(Oe,{value:"activity",children:E.isError?(0,e.jsx)("p",{className:"py-6 text-center text-sm text-bad",children:"Could not load case activity."}):(0,e.jsx)(Fn,{events:C})})]})]})}n(ia,"CaseDetail");export{ia as CaseDetail};
@@ -1,2 +1,2 @@
1
- var Xe=Object.defineProperty;var i=(s,l)=>Xe(s,"name",{value:l,configurable:!0});import{i as Te}from"./rolldown-runtime-ZpX3ckPj.js";import{O as fe,l as A,na as We,t as Ye,ta as Ze}from"./createLucideIcon-DJi9suAC.js";import{X as et,_ as tt,t as G,v as pe}from"./queryKeys-DYV5MhM_.js";import{n as st}from"./CompanyContext-CSrVsSze.js";import{a as _e,o as rt,t as at,tt as De,zt as nt}from"./router-2UfGeejU.js";import{t as it}from"./checkbox-BHQhs41k.js";import{o as Pe,r as Q,t as Ee}from"./popover-BhYHYj7q.js";import{t as lt}from"./arrow-up-down-Bpe9xqCo.js";import{t as he}from"./check-Ctsrlfa-.js";import{t as Le}from"./chevron-down-BCvxsWfI.js";import{t as ct}from"./columns-3-CqC5nP-p.js";import{t as ot}from"./funnel-DWwD2WCu.js";import{t as Y}from"./button-CMwV3L1P.js";import{t as dt}from"./search-04O7m-IF.js";import{t as ut}from"./badge-DuA2EgZC.js";import{t as pt}from"./projects-mixWrT5q.js";import{t as mt}from"./input-DobnTAyB.js";import{n as ft}from"./BreadcrumbContext-BVZDZoC0.js";import{Bt as xt,T as ht,_ as yt,ja as gt,pn as we,w as jt,zt as bt}from"./index-B7mmhFG7.js";import{n as kt,o as ve,t as Z}from"./cases-m9RZ5Cym.js";import{t as ee}from"./CaseIdentifierKey-D8Xi16PS.js";import{t as Ct}from"./FilterBar-5ta25FCb.js";var Be={name:"search-x",size:24,node:[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]};Be.node;var wt=Ye(Be),f=Te(We(),1),t=Te(Ze(),1),xe=[{value:"draft",label:"Draft"},{value:"in_progress",label:"In progress"},{value:"in_review",label:"In review"},{value:"approved",label:"Approved"},{value:"done",label:"Done"},{value:"cancelled",label:"Cancelled"}],j="__all__",R=Z.filter(s=>!kt.includes(s)),q=["id","title","status","updated"],ye=["id","key","title","type","status","updated","created","project","parent"],Me={id:"ID",key:"Key",title:"Title",status:"Status",updated:"Updated",created:"Created at",type:"Type",project:"Project",parent:"Parent case"},Ne={updated:"Last updated",created:"Created at",title:"Title",status:"Status",id:"ID",type:"Type",project:"Project"},B={search:"",typeFilters:[],statusFilters:R,projectFilters:[],labelFilter:j,groupBy:"type",sortField:"updated",sortDir:"desc",columns:q,treeView:!1};function vt(s){return s?`wardmote:cases:${s}:view`:null}i(vt,"getCaseViewStorageKey");function H(s){if(!Array.isArray(s))return q;const l=ye.filter(c=>s.includes(c));return l.length>0?l:q}i(H,"normalizeCaseColumns");function Ve(s){if(!Array.isArray(s))return R;const l=Z.filter(c=>s.includes(c));return l.length>0?l:R}i(Ve,"normalizeCaseStatuses");function Fe(s){return Array.isArray(s)?s.filter(l=>typeof l=="string"):[]}i(Fe,"normalizeStringArray");function Nt(s){return s==="project"||s==="status"||s==="type"||s==="none"?s:B.groupBy}i(Nt,"normalizeGroupBy");function Ft(s){return s==="created"||s==="title"||s==="status"||s==="id"||s==="type"||s==="project"||s==="updated"?s:B.sortField}i(Ft,"normalizeSortField");function Se(s){if(typeof window>"u"||!s)return{...B};try{const l=JSON.parse(window.localStorage.getItem(s)??"null");if(!l||typeof l!="object")return{...B};const c=l,u=c.treeView===!0,g=H(u?[...H(c.columns),"type"]:c.columns);return{search:typeof c.search=="string"?c.search:B.search,typeFilters:Fe(c.typeFilters),statusFilters:Ve(c.statusFilters),projectFilters:Fe(c.projectFilters),labelFilter:typeof c.labelFilter=="string"?c.labelFilter:B.labelFilter,groupBy:u?"none":Nt(c.groupBy),sortField:Ft(c.sortField),sortDir:c.sortDir==="asc"?"asc":"desc",columns:g,treeView:u}}catch{return{...B}}}i(Se,"loadCaseViewState");function St(s,l){if(!(typeof window>"u"||!s))try{window.localStorage.setItem(s,JSON.stringify(l))}catch{}}i(St,"saveCaseViewState");function Ke(s){return s.map(l=>l==="title"?"minmax(12rem, 1fr)":l==="id"?"max-content":l==="key"?"minmax(8rem, 12rem)":l==="status"?"minmax(6rem, 7rem)":l==="type"||l==="project"?"minmax(5rem, 8rem)":l==="parent"?"minmax(4rem, 6rem)":"minmax(5rem, 6rem)").join(" ")}i(Ke,"caseTrailingGridTemplate");function It(s,l){return s.length===l.length&&s.every(c=>l.includes(c))}i(It,"sameStringSet");function At(s,l){return s.length===l.length&&s.every(c=>l.includes(c))}i(At,"sameStatusSet");function Ie(s,l){return s.includes(l)?[...s]:H([...s,l])}i(Ie,"ensureCaseColumn");function Tt(s,l){if(s.matchesListFilters===!1||l.typeFilters.length>0&&!l.typeFilters.includes(s.caseType)||!l.statusFilters.includes(s.status))return!1;if(l.projectFilters.length>0){const c=s.projectId??j;if(!l.projectFilters.includes(c))return!1}return!0}i(Tt,"caseMatchesViewFilters");function _t(s){return s<=0?"":s===1?"pl-4":s===2?"pl-8":s===3?"pl-12":"pl-16"}i(_t,"treeTitleIndentClass");function Re({status:s,onChange:l,disabled:c}){const[u,g]=(0,f.useState)(!1);return(0,t.jsxs)(Ee,{open:u,onOpenChange:g,children:[(0,t.jsx)(Pe,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",disabled:c,className:"inline-flex items-center gap-1 rounded-md hover:bg-bg-3/50 disabled:opacity-50","aria-label":"Change case status",onClick:i(x=>{x.preventDefault(),x.stopPropagation()},"onClick"),children:[(0,t.jsx)(we,{status:s}),(0,t.jsx)(Le,{className:"h-3.5 w-3.5 text-ink-3"})]})}),(0,t.jsx)(Q,{align:"start",className:"w-44 p-1",onClick:i(x=>{x.preventDefault(),x.stopPropagation()},"onClick"),children:xe.map(x=>(0,t.jsxs)("button",{type:"button",onClick:i(()=>{g(!1),x.value!==s&&l(x.value)},"onClick"),className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-left hover:bg-bg-3",children:[(0,t.jsx)(we,{status:x.value}),x.value===s&&(0,t.jsx)(he,{className:"h-4 w-4 text-ink-3"})]},x.value))})]})}i(Re,"CaseStatusPicker");function Dt({row:s,columns:l,projectName:c,onStatusChange:u,statusPending:g,treeDepth:x=0,childCount:C=0,treeView:a=!1,treeCollapsed:T=!1,onTreeToggle:M}){return(0,t.jsx)("span",{className:"grid min-w-0 flex-1 items-center gap-2",style:{gridTemplateColumns:Ke(l)},children:l.map(m=>m==="id"?(0,t.jsx)(ee,{value:s.identifier,label:"case ID",className:"font-mono text-xs text-ink-3",containerClassName:"shrink-0",stopPropagation:!0},m):m==="key"?s.key?(0,t.jsx)(ee,{value:s.key,label:"case key",className:"font-mono text-xs text-ink-3",stopPropagation:!0},m):(0,t.jsx)("span",{className:"min-w-0 truncate text-xs text-ink-3",children:"None"},m):m==="title"?(0,t.jsxs)("span",{className:A("min-w-0",a?"flex items-center gap-1.5":"truncate text-sm",a&&_t(x)),children:[a?(0,t.jsx)("span",{className:"flex w-4 shrink-0 items-center text-ink-3",children:C>0?(0,t.jsx)("button",{type:"button",className:"flex h-4 w-4 items-center justify-center rounded-sm transition-colors hover:bg-bg-3/50","aria-label":`${T?"Expand":"Collapse"} ${s.title}`,"aria-expanded":!T,onClick:i(w=>{w.preventDefault(),w.stopPropagation(),M?.(s.id)},"onClick"),children:(0,t.jsx)(Le,{className:A("h-3.5 w-3.5 transition-transform",T&&"-rotate-90")})}):x>0?(0,t.jsx)("span",{className:"h-px w-3 bg-line"}):null}):null,(0,t.jsx)("span",{className:"min-w-0 truncate text-sm",children:s.title})]},m):m==="status"?(0,t.jsx)("span",{className:"min-w-0",children:(0,t.jsx)(Re,{status:s.status,disabled:g,onChange:i(w=>u(s.id,w),"onChange")})},m):m==="type"?(0,t.jsx)("span",{className:"min-w-0 truncate text-xs text-ink-3",children:s.caseType},m):m==="project"?(0,t.jsx)("span",{className:"min-w-0 truncate text-xs text-ink-3",children:c??"No project"},m):m==="parent"?(0,t.jsx)("span",{className:"min-w-0 truncate font-mono text-xs text-ink-3",children:s.parentCaseId?"Parent":"None"},m):m==="created"?(0,t.jsx)("span",{className:"text-right text-xs text-ink-3 tabular-nums",children:fe(s.createdAt)},m):(0,t.jsx)("span",{className:"text-right text-xs text-ink-3 tabular-nums",children:fe(s.updatedAt)},m))})}i(Dt,"CaseTrailingColumns");function me({row:s,projectName:l,visibleColumnSet:c,trailingColumns:u,onStatusChange:g,statusPending:x,treeDepth:C,childCount:a,treeView:T,treeCollapsed:M,onTreeToggle:m,selected:w=!1,onSelect:U}){const h=_e();return(0,t.jsxs)(at,{"data-case-item":!0,to:h(s.identifier),className:A("group flex items-start gap-2 border-b border-line py-2.5 pl-2 pr-3 text-sm no-underline text-inherit transition-colors last:border-b-0 hover:bg-bg-3/50 sm:items-center sm:py-2 sm:pl-1",w&&"bg-bg-3/50"),onMouseEnter:U,children:[(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[(0,t.jsx)("span",{className:"line-clamp-2 text-sm sm:hidden",children:c.has("title")?s.title:s.identifier}),(0,t.jsxs)("span",{className:"flex items-center gap-2 sm:hidden",children:[c.has("status")?(0,t.jsx)(Re,{status:s.status,disabled:x,onChange:i(v=>g(s.id,v),"onChange")}):null,c.has("id")?(0,t.jsx)(ee,{value:s.identifier,label:"case ID",className:"font-mono text-xs text-ink-3",containerClassName:"shrink-0",stopPropagation:!0}):null,c.has("key")&&s.key?(0,t.jsx)(ee,{value:s.key,label:"case key",className:"shrink-0 font-mono text-xs text-ink-3",stopPropagation:!0}):null,(0,t.jsx)("span",{className:"text-xs text-ink-3 sm:hidden",children:fe(s.updatedAt)})]})]}),u.length>0?(0,t.jsx)("span",{className:"hidden min-w-0 flex-1 items-center gap-3 sm:order-3 sm:flex",children:(0,t.jsx)(Dt,{row:s,columns:u,projectName:l,statusPending:x,onStatusChange:g,treeDepth:C,childCount:a,treeView:T,treeCollapsed:M,onTreeToggle:m})}):null]})}i(me,"CaseListRow");function Pt({visibleColumnSet:s,trailingColumns:l}){return(0,t.jsx)("div",{className:"hidden border-b border-line px-2 py-1 text-(length:--text-micro) font-medium uppercase tracking-(--tracking-caps) text-ink-3 sm:flex sm:items-center",children:l.length>0?(0,t.jsx)("span",{className:"grid min-w-0 flex-1 items-center gap-2",style:{gridTemplateColumns:Ke(l)},children:l.map(c=>(0,t.jsx)("span",{className:A("truncate",(c==="updated"||c==="created")&&"text-right"),children:Me[c]},c))}):null})}i(Pt,"CaseColumnHeader");function Et({label:s,count:l,collapsed:c,selected:u,onToggle:g,onSelect:x,children:C}){return(0,t.jsxs)("div",{className:"mt-6 first:mt-0",children:[(0,t.jsx)("div",{"data-case-item":!0,className:A("transition-colors",u&&"bg-bg-3/50"),onMouseEnter:x,children:(0,t.jsx)(jt,{label:s,collapsible:!0,collapsed:c,onToggle:g,trailing:(0,t.jsxs)("span",{className:"text-xs text-ink-3 tabular-nums",children:[l," ",l===1?"case":"cases"]})})}),!c&&(0,t.jsx)("div",{children:C})]})}i(Et,"CaseGroup");function Ae(s,l,c){return l===0?-1:s<0?0:c==="next"?Math.min(s+1,l-1):Math.max(s-1,0)}i(Ae,"getCaseKeyboardSelectionIndex");function te({icon:s,title:l,active:c,children:u}){return(0,t.jsxs)(Ee,{children:[(0,t.jsx)(Pe,{asChild:!0,children:(0,t.jsx)(Y,{active:c,type:"button",variant:"secondary",size:"icon",className:A("h-8 w-8 shrink-0"),title:l,"aria-label":l,children:(0,t.jsx)(s,{className:"h-3.5 w-3.5"})})}),u]})}i(te,"CaseToolbarButton");function W({label:s,children:l}){return(0,t.jsxs)("div",{className:"grid gap-1",children:[(0,t.jsx)("div",{className:"text-xs font-medium text-ink-3",children:s}),l]})}i(W,"FilterField");function K({label:s,checked:l,onCheckedChange:c}){return(0,t.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 text-sm hover:bg-bg-3/50",children:[(0,t.jsx)(it,{checked:l,onCheckedChange:i(u=>c(u===!0),"onCheckedChange"),onClick:i(u=>u.stopPropagation(),"onClick")}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:s})]})}i(K,"FilterCheckboxRow");function Lt({visibleColumns:s,onToggle:l,onReset:c}){return(0,t.jsx)(te,{icon:ct,title:"Columns",active:!It([...s],q),children:(0,t.jsxs)(Q,{align:"end",className:"w-(--sz-300px) p-1.5",children:[(0,t.jsxs)("div",{className:"px-2 pb-1 pt-1.5",children:[(0,t.jsx)("div",{className:"text-(length:--text-nano) font-semibold uppercase tracking-(--tracking-caps) text-ink-3",children:"Desktop case rows"}),(0,t.jsx)("div",{className:"text-sm font-medium text-ink",children:"Choose visible columns"})]}),(0,t.jsx)("div",{className:"space-y-0.5",children:ye.map(u=>(0,t.jsxs)("button",{type:"button",className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-sm hover:bg-bg-3/50",onClick:i(()=>l(u,!s.has(u)),"onClick"),children:[(0,t.jsx)("span",{children:Me[u]}),s.has(u)?(0,t.jsx)(he,{className:"h-3.5 w-3.5 text-ink-3"}):null]},u))}),(0,t.jsx)("div",{className:"mt-1 border-t border-line pt-1",children:(0,t.jsx)("button",{type:"button",className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-sm text-ink-3 hover:bg-bg-3/50",onClick:c,children:"Reset defaults"})})]})})}i(Lt,"CaseColumnPicker");function Bt({sortField:s,sortDir:l,onChange:c}){return(0,t.jsx)(te,{icon:lt,title:"Sort",active:s!=="updated"||l!=="desc",children:(0,t.jsx)(Q,{align:"end",className:"w-48 p-2",children:Object.keys(Ne).map(u=>(0,t.jsxs)("button",{type:"button",className:A("flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm",s===u?"bg-bg-3/50 text-ink":"text-ink-3 hover:bg-bg-3/50"),onClick:i(()=>{c(s===u?{sortField:s,sortDir:l==="asc"?"desc":"asc"}:{sortField:u,sortDir:u==="updated"||u==="created"?"desc":"asc"})},"onClick"),children:[(0,t.jsx)("span",{children:Ne[u]}),s===u?(0,t.jsx)("span",{className:"text-xs text-ink-3",children:l==="asc"?"↑":"↓"}):null]},u))})})}i(Bt,"CaseSortPicker");function Mt(){return(0,t.jsxs)("div",{className:"mx-auto flex max-w-xl flex-col items-center gap-4 py-16 text-center",children:[(0,t.jsx)(De,{className:"h-10 w-10 text-ink-3"}),(0,t.jsx)("h2",{className:"text-lg font-semibold",children:"No cases yet"}),(0,t.jsx)("p",{className:"text-sm text-ink-3",children:"Cases are durable work products — blog posts, tweet storms, docs pages — that tasks create and iterate on. In v1 they're created by agents, not from the UI."}),(0,t.jsxs)("div",{className:"w-full space-y-2 rounded-lg border border-line bg-bg-3/50 p-4 text-left",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"To start creating cases, add this to a skill:"}),(0,t.jsx)("pre",{className:"overflow-x-auto rounded bg-bg/60 p-3 font-mono text-xs text-ink-3",children:`"Create a case of type blog_post with fields
1
+ var Xe=Object.defineProperty;var i=(s,l)=>Xe(s,"name",{value:l,configurable:!0});import{i as Te}from"./rolldown-runtime-ZpX3ckPj.js";import{O as fe,l as A,na as We,t as Ye,ta as Ze}from"./createLucideIcon-DJi9suAC.js";import{X as et,_ as tt,t as G,v as pe}from"./queryKeys-DYV5MhM_.js";import{n as st}from"./CompanyContext-CSrVsSze.js";import{a as _e,o as rt,t as at,tt as De,zt as nt}from"./router-2UfGeejU.js";import{t as it}from"./checkbox-BHQhs41k.js";import{o as Pe,r as Q,t as Ee}from"./popover-BhYHYj7q.js";import{t as lt}from"./arrow-up-down-Bpe9xqCo.js";import{t as he}from"./check-Ctsrlfa-.js";import{t as Le}from"./chevron-down-BCvxsWfI.js";import{t as ct}from"./columns-3-CqC5nP-p.js";import{t as ot}from"./funnel-DWwD2WCu.js";import{t as Y}from"./button-CMwV3L1P.js";import{t as dt}from"./search-04O7m-IF.js";import{t as ut}from"./badge-DuA2EgZC.js";import{t as pt}from"./projects-mixWrT5q.js";import{t as mt}from"./input-DobnTAyB.js";import{n as ft}from"./BreadcrumbContext-BVZDZoC0.js";import{Bt as xt,T as ht,_ as yt,ja as gt,pn as we,w as jt,zt as bt}from"./index-DDoARkPG.js";import{n as kt,o as ve,t as Z}from"./cases-m9RZ5Cym.js";import{t as ee}from"./CaseIdentifierKey-D8Xi16PS.js";import{t as Ct}from"./FilterBar-5ta25FCb.js";var Be={name:"search-x",size:24,node:[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]};Be.node;var wt=Ye(Be),f=Te(We(),1),t=Te(Ze(),1),xe=[{value:"draft",label:"Draft"},{value:"in_progress",label:"In progress"},{value:"in_review",label:"In review"},{value:"approved",label:"Approved"},{value:"done",label:"Done"},{value:"cancelled",label:"Cancelled"}],j="__all__",R=Z.filter(s=>!kt.includes(s)),q=["id","title","status","updated"],ye=["id","key","title","type","status","updated","created","project","parent"],Me={id:"ID",key:"Key",title:"Title",status:"Status",updated:"Updated",created:"Created at",type:"Type",project:"Project",parent:"Parent case"},Ne={updated:"Last updated",created:"Created at",title:"Title",status:"Status",id:"ID",type:"Type",project:"Project"},B={search:"",typeFilters:[],statusFilters:R,projectFilters:[],labelFilter:j,groupBy:"type",sortField:"updated",sortDir:"desc",columns:q,treeView:!1};function vt(s){return s?`wardmote:cases:${s}:view`:null}i(vt,"getCaseViewStorageKey");function H(s){if(!Array.isArray(s))return q;const l=ye.filter(c=>s.includes(c));return l.length>0?l:q}i(H,"normalizeCaseColumns");function Ve(s){if(!Array.isArray(s))return R;const l=Z.filter(c=>s.includes(c));return l.length>0?l:R}i(Ve,"normalizeCaseStatuses");function Fe(s){return Array.isArray(s)?s.filter(l=>typeof l=="string"):[]}i(Fe,"normalizeStringArray");function Nt(s){return s==="project"||s==="status"||s==="type"||s==="none"?s:B.groupBy}i(Nt,"normalizeGroupBy");function Ft(s){return s==="created"||s==="title"||s==="status"||s==="id"||s==="type"||s==="project"||s==="updated"?s:B.sortField}i(Ft,"normalizeSortField");function Se(s){if(typeof window>"u"||!s)return{...B};try{const l=JSON.parse(window.localStorage.getItem(s)??"null");if(!l||typeof l!="object")return{...B};const c=l,u=c.treeView===!0,g=H(u?[...H(c.columns),"type"]:c.columns);return{search:typeof c.search=="string"?c.search:B.search,typeFilters:Fe(c.typeFilters),statusFilters:Ve(c.statusFilters),projectFilters:Fe(c.projectFilters),labelFilter:typeof c.labelFilter=="string"?c.labelFilter:B.labelFilter,groupBy:u?"none":Nt(c.groupBy),sortField:Ft(c.sortField),sortDir:c.sortDir==="asc"?"asc":"desc",columns:g,treeView:u}}catch{return{...B}}}i(Se,"loadCaseViewState");function St(s,l){if(!(typeof window>"u"||!s))try{window.localStorage.setItem(s,JSON.stringify(l))}catch{}}i(St,"saveCaseViewState");function Ke(s){return s.map(l=>l==="title"?"minmax(12rem, 1fr)":l==="id"?"max-content":l==="key"?"minmax(8rem, 12rem)":l==="status"?"minmax(6rem, 7rem)":l==="type"||l==="project"?"minmax(5rem, 8rem)":l==="parent"?"minmax(4rem, 6rem)":"minmax(5rem, 6rem)").join(" ")}i(Ke,"caseTrailingGridTemplate");function It(s,l){return s.length===l.length&&s.every(c=>l.includes(c))}i(It,"sameStringSet");function At(s,l){return s.length===l.length&&s.every(c=>l.includes(c))}i(At,"sameStatusSet");function Ie(s,l){return s.includes(l)?[...s]:H([...s,l])}i(Ie,"ensureCaseColumn");function Tt(s,l){if(s.matchesListFilters===!1||l.typeFilters.length>0&&!l.typeFilters.includes(s.caseType)||!l.statusFilters.includes(s.status))return!1;if(l.projectFilters.length>0){const c=s.projectId??j;if(!l.projectFilters.includes(c))return!1}return!0}i(Tt,"caseMatchesViewFilters");function _t(s){return s<=0?"":s===1?"pl-4":s===2?"pl-8":s===3?"pl-12":"pl-16"}i(_t,"treeTitleIndentClass");function Re({status:s,onChange:l,disabled:c}){const[u,g]=(0,f.useState)(!1);return(0,t.jsxs)(Ee,{open:u,onOpenChange:g,children:[(0,t.jsx)(Pe,{asChild:!0,children:(0,t.jsxs)("button",{type:"button",disabled:c,className:"inline-flex items-center gap-1 rounded-md hover:bg-bg-3/50 disabled:opacity-50","aria-label":"Change case status",onClick:i(x=>{x.preventDefault(),x.stopPropagation()},"onClick"),children:[(0,t.jsx)(we,{status:s}),(0,t.jsx)(Le,{className:"h-3.5 w-3.5 text-ink-3"})]})}),(0,t.jsx)(Q,{align:"start",className:"w-44 p-1",onClick:i(x=>{x.preventDefault(),x.stopPropagation()},"onClick"),children:xe.map(x=>(0,t.jsxs)("button",{type:"button",onClick:i(()=>{g(!1),x.value!==s&&l(x.value)},"onClick"),className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-left hover:bg-bg-3",children:[(0,t.jsx)(we,{status:x.value}),x.value===s&&(0,t.jsx)(he,{className:"h-4 w-4 text-ink-3"})]},x.value))})]})}i(Re,"CaseStatusPicker");function Dt({row:s,columns:l,projectName:c,onStatusChange:u,statusPending:g,treeDepth:x=0,childCount:C=0,treeView:a=!1,treeCollapsed:T=!1,onTreeToggle:M}){return(0,t.jsx)("span",{className:"grid min-w-0 flex-1 items-center gap-2",style:{gridTemplateColumns:Ke(l)},children:l.map(m=>m==="id"?(0,t.jsx)(ee,{value:s.identifier,label:"case ID",className:"font-mono text-xs text-ink-3",containerClassName:"shrink-0",stopPropagation:!0},m):m==="key"?s.key?(0,t.jsx)(ee,{value:s.key,label:"case key",className:"font-mono text-xs text-ink-3",stopPropagation:!0},m):(0,t.jsx)("span",{className:"min-w-0 truncate text-xs text-ink-3",children:"None"},m):m==="title"?(0,t.jsxs)("span",{className:A("min-w-0",a?"flex items-center gap-1.5":"truncate text-sm",a&&_t(x)),children:[a?(0,t.jsx)("span",{className:"flex w-4 shrink-0 items-center text-ink-3",children:C>0?(0,t.jsx)("button",{type:"button",className:"flex h-4 w-4 items-center justify-center rounded-sm transition-colors hover:bg-bg-3/50","aria-label":`${T?"Expand":"Collapse"} ${s.title}`,"aria-expanded":!T,onClick:i(w=>{w.preventDefault(),w.stopPropagation(),M?.(s.id)},"onClick"),children:(0,t.jsx)(Le,{className:A("h-3.5 w-3.5 transition-transform",T&&"-rotate-90")})}):x>0?(0,t.jsx)("span",{className:"h-px w-3 bg-line"}):null}):null,(0,t.jsx)("span",{className:"min-w-0 truncate text-sm",children:s.title})]},m):m==="status"?(0,t.jsx)("span",{className:"min-w-0",children:(0,t.jsx)(Re,{status:s.status,disabled:g,onChange:i(w=>u(s.id,w),"onChange")})},m):m==="type"?(0,t.jsx)("span",{className:"min-w-0 truncate text-xs text-ink-3",children:s.caseType},m):m==="project"?(0,t.jsx)("span",{className:"min-w-0 truncate text-xs text-ink-3",children:c??"No project"},m):m==="parent"?(0,t.jsx)("span",{className:"min-w-0 truncate font-mono text-xs text-ink-3",children:s.parentCaseId?"Parent":"None"},m):m==="created"?(0,t.jsx)("span",{className:"text-right text-xs text-ink-3 tabular-nums",children:fe(s.createdAt)},m):(0,t.jsx)("span",{className:"text-right text-xs text-ink-3 tabular-nums",children:fe(s.updatedAt)},m))})}i(Dt,"CaseTrailingColumns");function me({row:s,projectName:l,visibleColumnSet:c,trailingColumns:u,onStatusChange:g,statusPending:x,treeDepth:C,childCount:a,treeView:T,treeCollapsed:M,onTreeToggle:m,selected:w=!1,onSelect:U}){const h=_e();return(0,t.jsxs)(at,{"data-case-item":!0,to:h(s.identifier),className:A("group flex items-start gap-2 border-b border-line py-2.5 pl-2 pr-3 text-sm no-underline text-inherit transition-colors last:border-b-0 hover:bg-bg-3/50 sm:items-center sm:py-2 sm:pl-1",w&&"bg-bg-3/50"),onMouseEnter:U,children:[(0,t.jsxs)("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[(0,t.jsx)("span",{className:"line-clamp-2 text-sm sm:hidden",children:c.has("title")?s.title:s.identifier}),(0,t.jsxs)("span",{className:"flex items-center gap-2 sm:hidden",children:[c.has("status")?(0,t.jsx)(Re,{status:s.status,disabled:x,onChange:i(v=>g(s.id,v),"onChange")}):null,c.has("id")?(0,t.jsx)(ee,{value:s.identifier,label:"case ID",className:"font-mono text-xs text-ink-3",containerClassName:"shrink-0",stopPropagation:!0}):null,c.has("key")&&s.key?(0,t.jsx)(ee,{value:s.key,label:"case key",className:"shrink-0 font-mono text-xs text-ink-3",stopPropagation:!0}):null,(0,t.jsx)("span",{className:"text-xs text-ink-3 sm:hidden",children:fe(s.updatedAt)})]})]}),u.length>0?(0,t.jsx)("span",{className:"hidden min-w-0 flex-1 items-center gap-3 sm:order-3 sm:flex",children:(0,t.jsx)(Dt,{row:s,columns:u,projectName:l,statusPending:x,onStatusChange:g,treeDepth:C,childCount:a,treeView:T,treeCollapsed:M,onTreeToggle:m})}):null]})}i(me,"CaseListRow");function Pt({visibleColumnSet:s,trailingColumns:l}){return(0,t.jsx)("div",{className:"hidden border-b border-line px-2 py-1 text-(length:--text-micro) font-medium uppercase tracking-(--tracking-caps) text-ink-3 sm:flex sm:items-center",children:l.length>0?(0,t.jsx)("span",{className:"grid min-w-0 flex-1 items-center gap-2",style:{gridTemplateColumns:Ke(l)},children:l.map(c=>(0,t.jsx)("span",{className:A("truncate",(c==="updated"||c==="created")&&"text-right"),children:Me[c]},c))}):null})}i(Pt,"CaseColumnHeader");function Et({label:s,count:l,collapsed:c,selected:u,onToggle:g,onSelect:x,children:C}){return(0,t.jsxs)("div",{className:"mt-6 first:mt-0",children:[(0,t.jsx)("div",{"data-case-item":!0,className:A("transition-colors",u&&"bg-bg-3/50"),onMouseEnter:x,children:(0,t.jsx)(jt,{label:s,collapsible:!0,collapsed:c,onToggle:g,trailing:(0,t.jsxs)("span",{className:"text-xs text-ink-3 tabular-nums",children:[l," ",l===1?"case":"cases"]})})}),!c&&(0,t.jsx)("div",{children:C})]})}i(Et,"CaseGroup");function Ae(s,l,c){return l===0?-1:s<0?0:c==="next"?Math.min(s+1,l-1):Math.max(s-1,0)}i(Ae,"getCaseKeyboardSelectionIndex");function te({icon:s,title:l,active:c,children:u}){return(0,t.jsxs)(Ee,{children:[(0,t.jsx)(Pe,{asChild:!0,children:(0,t.jsx)(Y,{active:c,type:"button",variant:"secondary",size:"icon",className:A("h-8 w-8 shrink-0"),title:l,"aria-label":l,children:(0,t.jsx)(s,{className:"h-3.5 w-3.5"})})}),u]})}i(te,"CaseToolbarButton");function W({label:s,children:l}){return(0,t.jsxs)("div",{className:"grid gap-1",children:[(0,t.jsx)("div",{className:"text-xs font-medium text-ink-3",children:s}),l]})}i(W,"FilterField");function K({label:s,checked:l,onCheckedChange:c}){return(0,t.jsxs)("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 text-sm hover:bg-bg-3/50",children:[(0,t.jsx)(it,{checked:l,onCheckedChange:i(u=>c(u===!0),"onCheckedChange"),onClick:i(u=>u.stopPropagation(),"onClick")}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children:s})]})}i(K,"FilterCheckboxRow");function Lt({visibleColumns:s,onToggle:l,onReset:c}){return(0,t.jsx)(te,{icon:ct,title:"Columns",active:!It([...s],q),children:(0,t.jsxs)(Q,{align:"end",className:"w-(--sz-300px) p-1.5",children:[(0,t.jsxs)("div",{className:"px-2 pb-1 pt-1.5",children:[(0,t.jsx)("div",{className:"text-(length:--text-nano) font-semibold uppercase tracking-(--tracking-caps) text-ink-3",children:"Desktop case rows"}),(0,t.jsx)("div",{className:"text-sm font-medium text-ink",children:"Choose visible columns"})]}),(0,t.jsx)("div",{className:"space-y-0.5",children:ye.map(u=>(0,t.jsxs)("button",{type:"button",className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-sm hover:bg-bg-3/50",onClick:i(()=>l(u,!s.has(u)),"onClick"),children:[(0,t.jsx)("span",{children:Me[u]}),s.has(u)?(0,t.jsx)(he,{className:"h-3.5 w-3.5 text-ink-3"}):null]},u))}),(0,t.jsx)("div",{className:"mt-1 border-t border-line pt-1",children:(0,t.jsx)("button",{type:"button",className:"flex w-full items-center justify-between rounded px-2 py-1.5 text-sm text-ink-3 hover:bg-bg-3/50",onClick:c,children:"Reset defaults"})})]})})}i(Lt,"CaseColumnPicker");function Bt({sortField:s,sortDir:l,onChange:c}){return(0,t.jsx)(te,{icon:lt,title:"Sort",active:s!=="updated"||l!=="desc",children:(0,t.jsx)(Q,{align:"end",className:"w-48 p-2",children:Object.keys(Ne).map(u=>(0,t.jsxs)("button",{type:"button",className:A("flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm",s===u?"bg-bg-3/50 text-ink":"text-ink-3 hover:bg-bg-3/50"),onClick:i(()=>{c(s===u?{sortField:s,sortDir:l==="asc"?"desc":"asc"}:{sortField:u,sortDir:u==="updated"||u==="created"?"desc":"asc"})},"onClick"),children:[(0,t.jsx)("span",{children:Ne[u]}),s===u?(0,t.jsx)("span",{className:"text-xs text-ink-3",children:l==="asc"?"↑":"↓"}):null]},u))})})}i(Bt,"CaseSortPicker");function Mt(){return(0,t.jsxs)("div",{className:"mx-auto flex max-w-xl flex-col items-center gap-4 py-16 text-center",children:[(0,t.jsx)(De,{className:"h-10 w-10 text-ink-3"}),(0,t.jsx)("h2",{className:"text-lg font-semibold",children:"No cases yet"}),(0,t.jsx)("p",{className:"text-sm text-ink-3",children:"Cases are durable work products — blog posts, tweet storms, docs pages — that tasks create and iterate on. In v1 they're created by agents, not from the UI."}),(0,t.jsxs)("div",{className:"w-full space-y-2 rounded-lg border border-line bg-bg-3/50 p-4 text-left",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"To start creating cases, add this to a skill:"}),(0,t.jsx)("pre",{className:"overflow-x-auto rounded bg-bg/60 p-3 font-mono text-xs text-ink-3",children:`"Create a case of type blog_post with fields
2
2
  {slug, target_audience, publish_url} and key <release>/<slug>."`}),(0,t.jsxs)("p",{className:"text-xs text-ink-3",children:["See the wardmote skill → ",(0,t.jsx)("code",{className:"font-mono",children:"references/cases.md"})," for the API."]})]}),(0,t.jsx)("p",{className:"text-xs text-ink-3",children:"Turn Cases on or off in Settings → Features."})]})}i(Mt,"CasesEmptyHero");function ls(){const{selectedCompanyId:s}=st(),{setBreadcrumbs:l}=ft(),c=et(),u=rt(),g=_e(),x=(0,f.useRef)(null),C=vt(s),[a,T]=(0,f.useState)(()=>Se(C)),[M,m]=(0,f.useState)(()=>new Set),[w,U]=(0,f.useState)(()=>new Set),[h,v]=(0,f.useState)(-1);(0,f.useEffect)(()=>{l([{label:"Cases"}])},[l]),(0,f.useEffect)(()=>{T(Se(C)),U(new Set),m(new Set),v(-1)},[C]);function y(e){T(r=>{const n={...r,...e};return r.treeView&&e.groupBy&&e.groupBy!=="none"&&(n.treeView=!1),e.treeView===!0?(n.groupBy="none",n.columns=Ie(n.columns,"type")):n.treeView&&(n.groupBy="none"),St(C,n),n})}i(y,"updateView");const $=At(a.statusFilters,R),se=(0,f.useMemo)(()=>{const e=a.projectFilters.filter(n=>n!==j),r=$||a.statusFilters.length===Z.length?void 0:a.statusFilters;return{types:a.typeFilters.length>0?a.typeFilters:void 0,status:$?"active":void 0,statuses:r,projectIds:e.length>0?e:void 0,includeNoProject:a.projectFilters.includes(j)||void 0,labelId:a.labelFilter===j?void 0:a.labelFilter,q:a.search.trim()||void 0,includeAncestors:a.treeView?!0:void 0,limit:200}},[$,a.labelFilter,a.projectFilters,a.search,a.statusFilters,a.treeView,a.typeFilters]),D=pe({queryKey:[...G.cases.list(s??""),se],queryFn:i(()=>ve.list(s,se),"queryFn"),enabled:!!s}),re=pe({queryKey:G.projects.list(s??"",{includeArchived:!0}),queryFn:i(()=>pt.list(s,{includeArchived:!0}),"queryFn"),enabled:!!s}),ge=pe({queryKey:G.issues.labels(s??""),queryFn:i(()=>nt.listLabels(s),"queryFn"),enabled:!!s}),S=tt({mutationFn:i(({caseId:e,status:r})=>ve.patch(e,{status:r}),"mutationFn"),onSuccess:i(e=>{c.setQueryData([...G.cases.list(s??""),se],r=>r?.map(n=>n.id===e.id?{...n,...e}:n)),c.invalidateQueries({queryKey:G.cases.list(s??"")})},"onSuccess")}),P=(0,f.useMemo)(()=>D.data??[],[D.data]),I=(0,f.useMemo)(()=>{const e=new Map;for(const r of re.data??[])e.set(r.id,r.name);return e},[re.data]),je=(0,f.useMemo)(()=>[...new Set([...P.map(e=>e.caseType),...a.typeFilters])].sort(),[P,a.typeFilters]),V=(0,f.useMemo)(()=>P.filter(e=>Tt(e,a)),[P,a]),J=(0,f.useMemo)(()=>(e,r)=>{let n=0;if(a.sortField==="updated")n=Date.parse(e.updatedAt)-Date.parse(r.updatedAt);else if(a.sortField==="created")n=Date.parse(e.createdAt)-Date.parse(r.createdAt);else if(a.sortField==="title")n=e.title.localeCompare(r.title);else if(a.sortField==="status")n=e.status.localeCompare(r.status);else if(a.sortField==="id")n=e.identifier.localeCompare(r.identifier);else if(a.sortField==="type")n=e.caseType.localeCompare(r.caseType);else{const d=e.projectId?I.get(e.projectId)??"":"",p=r.projectId?I.get(r.projectId)??"":"";n=d.localeCompare(p)}return a.sortDir==="desc"?-n:n},[I,a.sortDir,a.sortField]),ae=(0,f.useMemo)(()=>{const e=[...V];return e.sort(J),e},[J,V]),z=(0,f.useMemo)(()=>{const e=[...P];return e.sort(J),e},[P,J]),E=(0,f.useMemo)(()=>new Set(a.columns),[a.columns]),X=(0,f.useMemo)(()=>ye.filter(e=>E.has(e)),[E]),ne=(0,f.useMemo)(()=>{if(a.groupBy==="none")return[{key:"__all__",label:null,rows:ae}];const e=new Map;for(const r of ae){let n;a.groupBy==="type"?n=r.caseType:a.groupBy==="status"?n=r.status:n=r.projectId?I.get(r.projectId)??"Unknown project":"No project";const d=e.get(n);d?d.push(r):e.set(n,[r])}return[...e.entries()].sort((r,n)=>r[0].localeCompare(n[0])).map(([r,n])=>({key:r,label:r,rows:n}))},[ae,a.groupBy,I]),ie=(0,f.useMemo)(()=>{const e=new Map(z.map(o=>[o.id,o])),r=new Set(V.map(o=>o.id));for(const o of V){const k=new Set([o.id]);let N=o.parentCaseId;for(;N&&!k.has(N);){const F=e.get(N);if(!F)break;r.add(F.id),k.add(F.id),N=F.parentCaseId}}const n=new Map;for(const o of z){if(!r.has(o.id)||!o.parentCaseId||!r.has(o.parentCaseId)||!e.has(o.parentCaseId))continue;const k=n.get(o.parentCaseId)??[];k.push(o),n.set(o.parentCaseId,k)}const d=z.filter(o=>r.has(o.id)&&(!o.parentCaseId||!r.has(o.parentCaseId)||!e.has(o.parentCaseId))),p=[],L=new Set,O=new Set;function ke(o,k){if(O.has(o.id)||k.has(o.id))return;O.add(o.id);const N=new Set(k);N.add(o.id);for(const F of n.get(o.id)??[])ke(F,N)}i(ke,"markHidden");function oe(o,k,N){if(L.has(o.id)||O.has(o.id))return;L.add(o.id);const F=n.get(o.id)??[],Ce=M.has(o.id);if(p.push({row:o,depth:k,childCount:F.length,collapsed:Ce}),N.has(o.id))return;const de=new Set(N);if(de.add(o.id),Ce){for(const ue of F)ke(ue,de);return}for(const ue of F)oe(ue,k+1,de)}i(oe,"walk");for(const o of d)oe(o,0,new Set);for(const o of z)r.has(o.id)&&oe(o,0,new Set);return p},[M,V,z]),b=(0,f.useMemo)(()=>{if(a.treeView)return ie.map(({row:r,childCount:n,collapsed:d})=>({type:"case",row:r,childCount:n,collapsed:d}));const e=[];for(const r of ne){const n=w.has(r.key);if(r.label&&e.push({type:"group",groupKey:r.key,collapsed:n}),!n)for(const d of r.rows)e.push({type:"case",row:d,childCount:0,collapsed:!1})}return e},[w,ne,ie,a.treeView]);(0,f.useEffect)(()=>{v(e=>b.length===0||e<0?-1:Math.min(e,b.length-1))},[b.length]),(0,f.useEffect)(()=>{h<0||!x.current||x.current.querySelectorAll("[data-case-item]")[h]?.scrollIntoView({block:"nearest"})},[h]);const _=[];if(a.search.trim()&&_.push({key:"search",label:"Search",value:a.search.trim()}),a.typeFilters.length>0&&_.push({key:"type",label:"Type",value:a.typeFilters.join(", ")}),$||_.push({key:"status",label:"Status",value:a.statusFilters.length===Z.length?"All":a.statusFilters.map(e=>xe.find(r=>r.value===e)?.label??e).join(", ")}),a.projectFilters.length>0&&_.push({key:"project",label:"Project",value:a.projectFilters.map(e=>e===j?"No project":I.get(e)??"Project").join(", ")}),a.labelFilter!==j){const e=(ge.data??[]).find(r=>r.id===a.labelFilter)?.name??"Label";_.push({key:"label",label:"Label",value:e})}function qe(e){e==="search"?y({search:""}):e==="type"?y({typeFilters:[]}):e==="status"?y({statusFilters:R}):e==="project"?y({projectFilters:[]}):e==="label"&&y({labelFilter:j})}i(qe,"removeFilter");function le(){y({search:"",typeFilters:[],statusFilters:R,projectFilters:[],labelFilter:j})}i(le,"clearFilters");function Ue(e,r){y({columns:H(r?[...a.columns,e]:a.columns.filter(n=>n!==e))})}i(Ue,"toggleColumn");function ze(){y({columns:a.treeView?Ie(q,"type"):q})}i(ze,"resetColumns");function Oe(e){m(r=>{const n=new Set(r);return n.has(e)?n.delete(e):n.add(e),n})}i(Oe,"toggleTreeRow");function Ge(e,r){m(n=>{const d=new Set(n);return r?d.add(e):d.delete(e),d})}i(Ge,"setTreeRowCollapsed");function He(e){U(r=>{const n=new Set(r);return n.has(e)?n.delete(e):n.add(e),n})}i(He,"toggleGroup");function Qe(e,r){U(n=>{const d=new Set(n);return r?d.add(e):d.delete(e),d})}i(Qe,"setGroupCollapsed");function ce(e,r,n){const d=a[e];y({[e]:n?[...d,r]:d.filter(p=>p!==r)})}i(ce,"toggleStringFilter");function $e(e,r){y({statusFilters:Ve(r?[...a.statusFilters,e]:a.statusFilters.filter(n=>n!==e))})}if(i($e,"toggleStatusFilter"),(0,f.useEffect)(()=>{function e(r){if(r.defaultPrevented)return;const n=r.target;if(!(n instanceof HTMLElement)||xt(n)||bt(document)||r.metaKey||r.ctrlKey||r.altKey)return;const d=b.length;if(d!==0)switch(r.key){case"j":case"ArrowDown":r.preventDefault(),v(p=>Ae(p,d,"next"));break;case"k":case"ArrowUp":r.preventDefault(),v(p=>Ae(p,d,"previous"));break;case"ArrowLeft":case"ArrowRight":{if(h<0||h>=d)return;const p=b[h];if(!p)return;if(p.type==="group"){r.preventDefault(),Qe(p.groupKey,r.key==="ArrowLeft");return}a.treeView&&p.childCount>0&&(r.preventDefault(),Ge(p.row.id,r.key==="ArrowLeft"));break}case"Enter":{if(h<0||h>=d)return;const p=b[h];if(!p||p.type!=="case")return;r.preventDefault(),u(g(p.row.identifier));break}default:return}}return i(e,"handleKeyDown"),window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[g,b,u,h,a.treeView]),D.isLoading)return(0,t.jsx)(yt,{variant:"list"});if(D.isError)return(0,t.jsxs)("div",{className:"mx-auto max-w-md space-y-2 py-16 text-center",children:[(0,t.jsx)("p",{className:"text-sm text-bad",children:D.error instanceof Error?D.error.message:"Cases could not be loaded."}),(0,t.jsx)(Y,{type:"button",variant:"secondary",size:"sm",onClick:i(()=>{D.refetch()},"onClick"),children:"Retry"})]});const Je=P.length===0&&_.length===0,be=_.length>0;return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("h1",{className:"text-xl font-bold",children:"Cases"}),(0,t.jsx)(ut,{variant:"secondary",children:"Beta"})]})}),Je?(0,t.jsx)(Mt,{}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 sm:gap-3",children:[(0,t.jsxs)("div",{className:"relative w-48 sm:w-64 md:w-80",children:[(0,t.jsx)(dt,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-ink-3"}),(0,t.jsx)(mt,{value:a.search,onChange:i(e=>y({search:e.target.value}),"onChange"),placeholder:"Search cases...",className:"pl-7 text-xs sm:text-sm","aria-label":"Search cases","data-page-search-target":"true"})]}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5 sm:gap-1",children:[(0,t.jsx)(Y,{active:a.treeView,type:"button",variant:"secondary",size:"icon",className:A("h-8 w-8 shrink-0"),title:a.treeView?"Show flat case list":"Show parent/children tree","aria-label":a.treeView?"Show flat case list":"Show parent/children tree","aria-pressed":a.treeView,onClick:i(()=>y({treeView:!a.treeView}),"onClick"),children:(0,t.jsx)(gt,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(Lt,{visibleColumns:E,onToggle:Ue,onReset:ze}),(0,t.jsx)(te,{icon:ot,title:"Filters",active:be,children:(0,t.jsx)(Q,{align:"end",className:"w-72 p-3",children:(0,t.jsxs)("div",{className:"grid gap-3",children:[(0,t.jsx)(W,{label:"Type",children:(0,t.jsx)("div",{className:"max-h-40 overflow-y-auto",children:je.length===0?(0,t.jsx)("p",{className:"px-1 py-1 text-xs text-ink-3",children:"No types yet"}):je.map(e=>(0,t.jsx)(K,{label:e,checked:a.typeFilters.includes(e),onCheckedChange:i(r=>ce("typeFilters",e,r),"onCheckedChange")},e))})}),(0,t.jsx)(W,{label:"Status",children:(0,t.jsx)("div",{children:xe.map(e=>(0,t.jsx)(K,{label:e.label,checked:a.statusFilters.includes(e.value),onCheckedChange:i(r=>$e(e.value,r),"onCheckedChange")},e.value))})}),(0,t.jsx)(W,{label:"Project",children:(0,t.jsxs)("div",{className:"max-h-40 overflow-y-auto",children:[(0,t.jsx)(K,{label:"No project",checked:a.projectFilters.includes(j),onCheckedChange:i(e=>ce("projectFilters",j,e),"onCheckedChange")}),(re.data??[]).filter(e=>!e.archivedAt).map(e=>(0,t.jsx)(K,{label:e.name,checked:a.projectFilters.includes(e.id),onCheckedChange:i(r=>ce("projectFilters",e.id,r),"onCheckedChange")},e.id))]})}),(0,t.jsx)(W,{label:"Label",children:(0,t.jsxs)("div",{className:"max-h-40 overflow-y-auto",children:[(0,t.jsx)(K,{label:"All labels",checked:a.labelFilter===j,onCheckedChange:i(e=>{e&&y({labelFilter:j})},"onCheckedChange")}),(ge.data??[]).map(e=>(0,t.jsx)(K,{label:e.name,checked:a.labelFilter===e.id,onCheckedChange:i(r=>y({labelFilter:r?e.id:j}),"onCheckedChange")},e.id))]})}),(0,t.jsx)(Y,{type:"button",variant:"ghost",size:"sm",onClick:le,disabled:!be,children:"Clear filters"})]})})}),(0,t.jsx)(Bt,{sortField:a.sortField,sortDir:a.sortDir,onChange:y}),(0,t.jsx)(te,{icon:De,title:"Group",active:a.groupBy!=="type",children:(0,t.jsx)(Q,{align:"end",className:"w-44 p-2",children:[["type","Type"],["project","Project"],["status","Status"],["none","None"]].map(([e,r])=>(0,t.jsxs)("button",{type:"button",className:A("flex w-full items-center justify-between rounded-sm px-2 py-1.5 text-sm",a.groupBy===e?"bg-bg-3/50 text-ink":"text-ink-3 hover:bg-bg-3/50"),onClick:i(()=>y({groupBy:e}),"onClick"),children:[(0,t.jsx)("span",{children:r}),a.groupBy===e&&(0,t.jsx)(he,{className:"h-3.5 w-3.5"})]},e))})})]})]}),(0,t.jsx)(Ct,{filters:_,onRemove:qe,onClear:le}),V.length===0?(0,t.jsx)(ht,{icon:wt,message:"No cases match these filters.",action:"Clear filters",onAction:le}):(0,t.jsxs)("div",{ref:x,children:[(0,t.jsx)(Pt,{visibleColumnSet:E,trailingColumns:X}),a.treeView?ie.map(({row:e,depth:r,childCount:n,collapsed:d})=>{const p=b.findIndex(L=>L.type==="case"&&L.row.id===e.id);return(0,t.jsx)(me,{row:e,projectName:e.projectId?I.get(e.projectId)??null:null,visibleColumnSet:E,trailingColumns:X,statusPending:S.isPending&&S.variables?.caseId===e.id,onStatusChange:i((L,O)=>S.mutate({caseId:L,status:O}),"onStatusChange"),treeDepth:r,childCount:n,treeCollapsed:d,onTreeToggle:Oe,selected:h===p,onSelect:i(()=>v(p),"onSelect"),treeView:!0},e.id)}):ne.map(e=>e.label?(0,t.jsx)(Et,{label:e.label,count:e.rows.length,collapsed:w.has(e.key),selected:h===b.findIndex(r=>r.type==="group"&&r.groupKey===e.key),onToggle:i(()=>He(e.key),"onToggle"),onSelect:i(()=>v(b.findIndex(r=>r.type==="group"&&r.groupKey===e.key)),"onSelect"),children:e.rows.map(r=>{const n=b.findIndex(d=>d.type==="case"&&d.row.id===r.id);return(0,t.jsx)(me,{row:r,projectName:r.projectId?I.get(r.projectId)??null:null,visibleColumnSet:E,trailingColumns:X,statusPending:S.isPending&&S.variables?.caseId===r.id,onStatusChange:i((d,p)=>S.mutate({caseId:d,status:p}),"onStatusChange"),selected:h===n,onSelect:i(()=>v(n),"onSelect")},r.id)})},e.key):(0,t.jsx)("div",{children:e.rows.map(r=>{const n=b.findIndex(d=>d.type==="case"&&d.row.id===r.id);return(0,t.jsx)(me,{row:r,projectName:r.projectId?I.get(r.projectId)??null:null,visibleColumnSet:E,trailingColumns:X,statusPending:S.isPending&&S.variables?.caseId===r.id,onStatusChange:i((d,p)=>S.mutate({caseId:d,status:p}),"onStatusChange"),selected:h===n,onSelect:i(()=>v(n),"onSelect")},r.id)})},e.key))]})]})]})}i(ls,"Cases");export{ls as Cases};