@growthub/cli 0.3.12 → 0.3.14

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 (93) hide show
  1. package/dist/index.js +4 -1
  2. package/dist/index.js.map +2 -2
  3. package/dist/runtime/server/dist/app.d.ts.map +1 -1
  4. package/dist/runtime/server/dist/app.js +61 -1
  5. package/dist/runtime/server/dist/app.js.map +1 -1
  6. package/dist/runtime/server/dist/routes/gtm.d.ts.map +1 -1
  7. package/dist/runtime/server/dist/routes/gtm.js +83 -6
  8. package/dist/runtime/server/dist/routes/gtm.js.map +1 -1
  9. package/dist/runtime/server/node_modules/@paperclipai/shared/dist/config-schema.d.ts +30 -0
  10. package/dist/runtime/server/node_modules/@paperclipai/shared/dist/config-schema.d.ts.map +1 -1
  11. package/dist/runtime/server/node_modules/@paperclipai/shared/dist/config-schema.js +3 -0
  12. package/dist/runtime/server/node_modules/@paperclipai/shared/dist/config-schema.js.map +1 -1
  13. package/dist/runtime/server/ui-dist/assets/{OnboardingWizard-BiZHH3vY.js → OnboardingWizard-DQqBk_u-.js} +230 -225
  14. package/dist/runtime/server/ui-dist/assets/{_basePickBy-DOJDGGWo.js → _basePickBy-CycqvnCH.js} +1 -1
  15. package/dist/runtime/server/ui-dist/assets/{_baseUniq-DjoWC9VG.js → _baseUniq-jJI66QE5.js} +1 -1
  16. package/dist/runtime/server/ui-dist/assets/{arc-DzAhgPuQ.js → arc-DAfOGkhs.js} +1 -1
  17. package/dist/runtime/server/ui-dist/assets/{architectureDiagram-VXUJARFQ-CFxoZ9U1.js → architectureDiagram-VXUJARFQ-Bseplhn_.js} +1 -1
  18. package/dist/runtime/server/ui-dist/assets/{blockDiagram-VD42YOAC-CmcNReYb.js → blockDiagram-VD42YOAC-CImRkHxE.js} +1 -1
  19. package/dist/runtime/server/ui-dist/assets/{c4Diagram-YG6GDRKO-62g03z24.js → c4Diagram-YG6GDRKO-DocRJ0-4.js} +1 -1
  20. package/dist/runtime/server/ui-dist/assets/channel-BBXTGjGr.js +1 -0
  21. package/dist/runtime/server/ui-dist/assets/{chunk-4BX2VUAB-DdKgkZWf.js → chunk-4BX2VUAB-C_QZ3yOc.js} +1 -1
  22. package/dist/runtime/server/ui-dist/assets/{chunk-55IACEB6-BG61sDBH.js → chunk-55IACEB6-B83lcfpC.js} +1 -1
  23. package/dist/runtime/server/ui-dist/assets/{chunk-B4BG7PRW-jHjDOzs3.js → chunk-B4BG7PRW-_ZGkSCBB.js} +1 -1
  24. package/dist/runtime/server/ui-dist/assets/{chunk-DI55MBZ5-QWOEgAft.js → chunk-DI55MBZ5-D84JXXQK.js} +1 -1
  25. package/dist/runtime/server/ui-dist/assets/{chunk-FMBD7UC4-BTtsDCBm.js → chunk-FMBD7UC4-MA5md7TF.js} +1 -1
  26. package/dist/runtime/server/ui-dist/assets/{chunk-QN33PNHL-DQ0G5mTp.js → chunk-QN33PNHL-pBntDM8z.js} +1 -1
  27. package/dist/runtime/server/ui-dist/assets/{chunk-QZHKN3VN-CwD654Gq.js → chunk-QZHKN3VN-BaIMiSo-.js} +1 -1
  28. package/dist/runtime/server/ui-dist/assets/{chunk-TZMSLE5B-BW4AfItk.js → chunk-TZMSLE5B-CrjyhaCL.js} +1 -1
  29. package/dist/runtime/server/ui-dist/assets/classDiagram-2ON5EDUG-BNttVhse.js +1 -0
  30. package/dist/runtime/server/ui-dist/assets/classDiagram-v2-WZHVMYZB-BNttVhse.js +1 -0
  31. package/dist/runtime/server/ui-dist/assets/clone-dcpmW7Wd.js +1 -0
  32. package/dist/runtime/server/ui-dist/assets/{cose-bilkent-S5V4N54A-Cl5X2jL8.js → cose-bilkent-S5V4N54A-mNFISgZf.js} +1 -1
  33. package/dist/runtime/server/ui-dist/assets/{dagre-6UL2VRFP-B2u9a5zG.js → dagre-6UL2VRFP-BW8ACip_.js} +1 -1
  34. package/dist/runtime/server/ui-dist/assets/{diagram-PSM6KHXK-DsSVNioI.js → diagram-PSM6KHXK-ByQfKnwU.js} +1 -1
  35. package/dist/runtime/server/ui-dist/assets/{diagram-QEK2KX5R-C2oaCik_.js → diagram-QEK2KX5R-CVMlaNLR.js} +1 -1
  36. package/dist/runtime/server/ui-dist/assets/{diagram-S2PKOQOG-CuEvUbkw.js → diagram-S2PKOQOG-CfBIwKQh.js} +1 -1
  37. package/dist/runtime/server/ui-dist/assets/dx-root-DH9to-bY.js +280 -0
  38. package/dist/runtime/server/ui-dist/assets/{erDiagram-Q2GNP2WA-_1lFdkqV.js → erDiagram-Q2GNP2WA-DjZOGwrs.js} +1 -1
  39. package/dist/runtime/server/ui-dist/assets/{flowDiagram-NV44I4VS-DUoF0DLT.js → flowDiagram-NV44I4VS-BpGnGwpO.js} +1 -1
  40. package/dist/runtime/server/ui-dist/assets/{ganttDiagram-JELNMOA3-CruQ7D3m.js → ganttDiagram-JELNMOA3-CpTGtCqK.js} +1 -1
  41. package/dist/runtime/server/ui-dist/assets/{gitGraphDiagram-V2S2FVAM-BDuS9ljz.js → gitGraphDiagram-V2S2FVAM-BQaWuAZj.js} +1 -1
  42. package/dist/runtime/server/ui-dist/assets/{graph-BFy59M3M.js → graph-DXdHsjCL.js} +1 -1
  43. package/dist/runtime/server/ui-dist/assets/gtm-root-Bz1qVp9E.js +11 -0
  44. package/dist/runtime/server/ui-dist/assets/{index-BzNjBEzf.js → index-B8I0xKWu.js} +1 -1
  45. package/dist/runtime/server/ui-dist/assets/{index-DfnTp5y6.js → index-B8TKmcyb.js} +1 -1
  46. package/dist/runtime/server/ui-dist/assets/{index-DcoQC6ia.js → index-BMSNv6QN.js} +1 -1
  47. package/dist/runtime/server/ui-dist/assets/{index-DL95rih-.js → index-BYHJbnHR.js} +1 -1
  48. package/dist/runtime/server/ui-dist/assets/{index-BMwN19Gi.js → index-BgVlUrJs.js} +1 -1
  49. package/dist/runtime/server/ui-dist/assets/{index-DY60bSWi.js → index-Bq-1_kyP.js} +1 -1
  50. package/dist/runtime/server/ui-dist/assets/{index-D2MHxpCH.js → index-BqPQYsKl.js} +2 -2
  51. package/dist/runtime/server/ui-dist/assets/{index-BKO_Nk8c.js → index-BzMyBmxt.js} +1 -1
  52. package/dist/runtime/server/ui-dist/assets/{index-WuexBBBr.js → index-CFpWwIka.js} +1 -1
  53. package/dist/runtime/server/ui-dist/assets/{index-BCphYMJ8.js → index-CKSID6Zp.js} +1 -1
  54. package/dist/runtime/server/ui-dist/assets/{index-CLWYCHoS.js → index-CQebjpNv.js} +1 -1
  55. package/dist/runtime/server/ui-dist/assets/{index-ClbnJMz6.css → index-CmOpk52T.css} +1 -1
  56. package/dist/runtime/server/ui-dist/assets/{index-DFUgoz9_.js → index-CmWaG74-.js} +1 -1
  57. package/dist/runtime/server/ui-dist/assets/{index-B9Xd_vMV.js → index-CpAx3Tjk.js} +1 -1
  58. package/dist/runtime/server/ui-dist/assets/{index-Bz0rSFov.js → index-Crtq9e3P.js} +1 -1
  59. package/dist/runtime/server/ui-dist/assets/{index-D3MPbMGr.js → index-D5QPPm5h.js} +1 -1
  60. package/dist/runtime/server/ui-dist/assets/{index-CZVyxyFA.js → index-D8pJptAs.js} +1 -1
  61. package/dist/runtime/server/ui-dist/assets/{index-A_Utfb1G.js → index-DKPn8Zd0.js} +1 -1
  62. package/dist/runtime/server/ui-dist/assets/{index-Fb7iEaRG.js → index-DRwidkWV.js} +1 -1
  63. package/dist/runtime/server/ui-dist/assets/{index-Cpqm25YS.js → index-DwTdFnM5.js} +1 -1
  64. package/dist/runtime/server/ui-dist/assets/{index-AaLnuKvn.js → index-KhE_p8qv.js} +1 -1
  65. package/dist/runtime/server/ui-dist/assets/{index-TPJ_0VD8.js → index-LPZbBYTO.js} +1 -1
  66. package/dist/runtime/server/ui-dist/assets/{index-Cv5ClxEP.js → index-mMQEcPHs.js} +1 -1
  67. package/dist/runtime/server/ui-dist/assets/{index--dv-yDMD.js → index-nPSc8Rbx.js} +1 -1
  68. package/dist/runtime/server/ui-dist/assets/{infoDiagram-HS3SLOUP-CiI6r25R.js → infoDiagram-HS3SLOUP-Du9idGhC.js} +1 -1
  69. package/dist/runtime/server/ui-dist/assets/{journeyDiagram-XKPGCS4Q-BMmOHrov.js → journeyDiagram-XKPGCS4Q-DQHmnv0N.js} +1 -1
  70. package/dist/runtime/server/ui-dist/assets/{kanban-definition-3W4ZIXB7-BxeYeVi1.js → kanban-definition-3W4ZIXB7-D1us-ZVV.js} +1 -1
  71. package/dist/runtime/server/ui-dist/assets/{layout-anG6DZ8y.js → layout-CLyzF__I.js} +1 -1
  72. package/dist/runtime/server/ui-dist/assets/{linear-CDTAlHE-.js → linear-DCEHrHNY.js} +1 -1
  73. package/dist/runtime/server/ui-dist/assets/{mermaid.core-DNt7uRm5.js → mermaid.core-DPCeJESB.js} +4 -4
  74. package/dist/runtime/server/ui-dist/assets/{mindmap-definition-VGOIOE7T-DTO5b9so.js → mindmap-definition-VGOIOE7T-BmEem54z.js} +1 -1
  75. package/dist/runtime/server/ui-dist/assets/{pieDiagram-ADFJNKIX-BteTAzPn.js → pieDiagram-ADFJNKIX-DjIZtNwx.js} +1 -1
  76. package/dist/runtime/server/ui-dist/assets/{quadrantDiagram-AYHSOK5B-_gG2aKm4.js → quadrantDiagram-AYHSOK5B-ba-xD4cb.js} +1 -1
  77. package/dist/runtime/server/ui-dist/assets/{requirementDiagram-UZGBJVZJ-CcOvI4e8.js → requirementDiagram-UZGBJVZJ-CB358t-a.js} +1 -1
  78. package/dist/runtime/server/ui-dist/assets/{sankeyDiagram-TZEHDZUN-C1Rbdzvp.js → sankeyDiagram-TZEHDZUN-B0oPaNiW.js} +1 -1
  79. package/dist/runtime/server/ui-dist/assets/{sequenceDiagram-WL72ISMW-DPx4fWtG.js → sequenceDiagram-WL72ISMW-D7n_ZO5c.js} +1 -1
  80. package/dist/runtime/server/ui-dist/assets/{stateDiagram-FKZM4ZOC-CID-77J9.js → stateDiagram-FKZM4ZOC-MkMtXK-v.js} +1 -1
  81. package/dist/runtime/server/ui-dist/assets/stateDiagram-v2-4FDKWEC3-Cah7upY-.js +1 -0
  82. package/dist/runtime/server/ui-dist/assets/{timeline-definition-IT6M3QCI-CyA1h3jY.js → timeline-definition-IT6M3QCI-CjBjKaYS.js} +1 -1
  83. package/dist/runtime/server/ui-dist/assets/{treemap-GDKQZRPO-nqrXf2kh.js → treemap-GDKQZRPO-JNjc1ydw.js} +1 -1
  84. package/dist/runtime/server/ui-dist/assets/{xychartDiagram-PRI3JC2R-CS0bUj41.js → xychartDiagram-PRI3JC2R-DU-mF_06.js} +1 -1
  85. package/dist/runtime/server/ui-dist/index.html +2 -2
  86. package/package.json +1 -7
  87. package/dist/runtime/server/ui-dist/assets/channel-CyMiLt_6.js +0 -1
  88. package/dist/runtime/server/ui-dist/assets/classDiagram-2ON5EDUG-Bpt4jbt_.js +0 -1
  89. package/dist/runtime/server/ui-dist/assets/classDiagram-v2-WZHVMYZB-Bpt4jbt_.js +0 -1
  90. package/dist/runtime/server/ui-dist/assets/clone-C1pAl4cM.js +0 -1
  91. package/dist/runtime/server/ui-dist/assets/dx-root-B5r5o3mh.js +0 -280
  92. package/dist/runtime/server/ui-dist/assets/gtm-root-bgiNL285.js +0 -11
  93. package/dist/runtime/server/ui-dist/assets/stateDiagram-v2-4FDKWEC3-DF70krIP.js +0 -1
@@ -0,0 +1,280 @@
1
+ var Qi=t=>{throw TypeError(t)};var Na=(t,s,n)=>s.has(t)||Qi("Cannot "+n);var we=(t,s,n)=>(Na(t,s,"read from private field"),n?n.call(t):s.get(t)),_t=(t,s,n)=>s.has(t)?Qi("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,n),ot=(t,s,n,r)=>(Na(t,s,"write to private field"),r?r.call(t,n):s.set(t,n),n),Kt=(t,s,n)=>(Na(t,s,"access private method"),n);import{r as c,j as e,a as be,t as Vs,b as Qn,s as cl,R as jd}from"./index-BqPQYsKl.js";import{be as vd,bf as Ba,bg as yd,bh as Nd,bi as dl,al as Le,bj as wd,bk as kd,bl as Cd,bm as Sd,bn as Id,bo as Ad,bp as Yi,bq as Td,br as Pd,bs as Ed,bt as Bt,bu as Rd,bv as ul,bw as Ji,bx as Md,by as _d,bz as Dd,K as me,bA as qn,bB as Te,W as he,Z as Ve,bC as Mt,X as bt,aN as Ht,aH as E,a5 as $d,bD as as,bE as is,bF as Pe,bG as os,af as z,ab as ml,a4 as Tn,bH as ir,aj as V,bI as xi,bJ as Fd,bK as Zr,bL as ea,bM as Js,bN as ta,bO as xl,bP as sa,bQ as lt,aY as na,bR as Er,bS as Yn,bT as Xs,aL as Ee,bU as mn,bV as hl,bW as ht,$ as F,bX as gs,a8 as ys,bY as Rr,a6 as za,bZ as Ct,b_ as ls,aa as cs,b$ as zn,c0 as mt,c1 as ra,c2 as St,c3 as pl,c4 as xn,c5 as Ld,c6 as Od,c7 as qd,c8 as Bd,c9 as Jn,ax as fs,az as hn,aA as pn,aB as Kn,ay as bs,ca as zd,cb as Nn,cc as qt,cd as qe,ce as hi,am as se,aJ as or,cf as gl,cg as fl,ch as bl,ci as Xi,cj as jl,ck as pt,cl as gt,aT as Se,cm as ft,cn as vl,co as Ka,cp as Et,cq as yl,cr as Nl,cs as pi,ct as gi,cu as Kd,cv as Ud,cw as Gd,cx as Wd,cy as Vd,a7 as Ua,cz as Hd,cA as wl,cB as Mr,a3 as Qd,_ as $s,ae as xe,ac as Zi,ad as eo,ag as Yd,V as wn,ah as kl,ba as Jd,ai as Xd,aX as Cl,aP as Lt,cC as Zd,aM as Xn,cD as Ga,cE as Ns,aE as Es,cF as aa,aS as Pn,cG as Sl,aG as En,cH as Me,cI as Il,cJ as re,cK as pr,cL as eu,cM as tu,cN as su,cO as nu,aR as wt,aQ as Nt,cP as Al,aI as As,aC as Ot,cQ as to,cR as ia,cS as oa,cT as Tl,cU as la,cV as Us,cW as Pl,cX as js,aU as ca,cY as rt,cZ as Ut,c_ as Hs,c$ as ru,d0 as ps,d1 as El,d2 as fi,d3 as bi,d4 as Gs,d5 as tn,d6 as Rs,d7 as Rt,d8 as au,d9 as iu,da as ou,db as Wa,dc as so,dd as dn,aO as Rl,ak as ji,de as lu,df as Un,O as ke,dg as cu,dh as Ml,di as vi,dj as _l,dk as du,dl as _r,dm as kt,dn as Oe,dp as Dl,dq as uu,aF as yi,dr as Ni,ds as Va,dt as mu,aK as un,ao as $e,ap as Ze,ar as et,du as Gt,as as xt,dv as Ge,av as Fe,dw as wi,dx as Dr,dy as $l,aq as Ne,dz as xu,dA as da,dB as ki,dC as ts,dD as hu,dE as pu,dF as gu,dG as fu,dH as bu,dI as ju,dJ as vu,dK as yu,dL as Nu,dM as wu,dN as ku,dO as Cu,dP as Su,dQ as gn,dR as no,an as gr,dS as fr,dT as Iu,dU as Au,aw as Tu,aV as Pu,aW as Eu,dV as Ru,dW as Mu,dX as _u,dY as Du,dZ as $u,d_ as Fu,d$ as Lu,e0 as Ou,e1 as qu,e2 as Bu,e3 as zu,e4 as wa,e5 as ro,e6 as ao,e7 as Ku,e8 as Uu,e9 as Os,ea as qs,eb as Gu,ec as Wu,ed as Fl,aD as Ir,ee as io,ef as Vu,eg as Hu,eh as Qu,ei as oo,ej as Ci,ek as Ll,el as ka,em as Yu,en as Ju,eo as Xu,ep as Zu,eq as em,er as tm,es as sm,et as nm,R as rm,M as Y,Q as am,S as im,U as om,bb as lm,Y as Ol,a0 as Ca,a1 as cm,a2 as dm,aZ as um,a_ as mm,a$ as xm,b0 as hm,b1 as pm,b2 as gm,b3 as fm,b4 as bm,b5 as jm,b6 as vm,b7 as ym,b8 as Nm,b9 as wm,bc as km,bd as Cm}from"./OnboardingWizard-DQqBk_u-.js";function lo(t,s){const n=new Set(s);return t.filter(r=>!n.has(r))}function Sm(t,s,n){const r=t.slice(0);return r[s]=n,r}var jn,Tt,vn,yn,Dt,Ts,sr,nr,rr,ar,at,Ha,Qa,Ya,Ja,Xa,ll,Im=(ll=class extends vd{constructor(s,n,r){super();_t(this,at);_t(this,jn);_t(this,Tt);_t(this,vn);_t(this,yn);_t(this,Dt);_t(this,Ts);_t(this,sr);_t(this,nr);_t(this,rr);_t(this,ar,[]);ot(this,jn,s),ot(this,yn,r),ot(this,vn,[]),ot(this,Dt,[]),ot(this,Tt,[]),this.setQueries(n)}onSubscribe(){this.listeners.size===1&&we(this,Dt).forEach(s=>{s.subscribe(n=>{Kt(this,at,Ja).call(this,s,n)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,we(this,Dt).forEach(s=>{s.destroy()})}setQueries(s,n){ot(this,vn,s),ot(this,yn,n),Ba.batch(()=>{const r=we(this,Dt),a=Kt(this,at,Ya).call(this,we(this,vn));a.forEach(x=>x.observer.setOptions(x.defaultedQueryOptions));const i=a.map(x=>x.observer),o=i.map(x=>x.getCurrentResult()),l=r.length!==i.length,u=i.some((x,p)=>x!==r[p]),d=l||u,m=d?!0:o.some((x,p)=>{const h=we(this,Tt)[p];return!h||!yd(x,h)});!d&&!m||(d&&(ot(this,ar,a),ot(this,Dt,i)),ot(this,Tt,o),this.hasListeners()&&(d&&(lo(r,i).forEach(x=>{x.destroy()}),lo(i,r).forEach(x=>{x.subscribe(p=>{Kt(this,at,Ja).call(this,x,p)})})),Kt(this,at,Xa).call(this)))})}getCurrentResult(){return we(this,Tt)}getQueries(){return we(this,Dt).map(s=>s.getCurrentQuery())}getObservers(){return we(this,Dt)}getOptimisticResult(s,n){const r=Kt(this,at,Ya).call(this,s),a=r.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),i=r.map(o=>o.defaultedQueryOptions.queryHash);return[a,o=>Kt(this,at,Qa).call(this,o??a,n,i),()=>Kt(this,at,Ha).call(this,a,r)]}},jn=new WeakMap,Tt=new WeakMap,vn=new WeakMap,yn=new WeakMap,Dt=new WeakMap,Ts=new WeakMap,sr=new WeakMap,nr=new WeakMap,rr=new WeakMap,ar=new WeakMap,at=new WeakSet,Ha=function(s,n){return n.map((r,a)=>{const i=s[a];return r.defaultedQueryOptions.notifyOnChangeProps?i:r.observer.trackResult(i,o=>{n.forEach(l=>{l.observer.trackProp(o)})})})},Qa=function(s,n,r){if(n){const a=we(this,rr),i=r!==void 0&&a!==void 0&&(a.length!==r.length||r.some((o,l)=>o!==a[l]));return(!we(this,Ts)||we(this,Tt)!==we(this,nr)||i||n!==we(this,sr))&&(ot(this,sr,n),ot(this,nr,we(this,Tt)),r!==void 0&&ot(this,rr,r),ot(this,Ts,Nd(we(this,Ts),n(s)))),we(this,Ts)}return s},Ya=function(s){const n=new Map;we(this,Dt).forEach(a=>{const i=a.options.queryHash;if(!i)return;const o=n.get(i);o?o.push(a):n.set(i,[a])});const r=[];return s.forEach(a=>{var u;const i=we(this,jn).defaultQueryOptions(a),l=((u=n.get(i.queryHash))==null?void 0:u.shift())??new dl(we(this,jn),i);r.push({defaultedQueryOptions:i,observer:l})}),r},Ja=function(s,n){const r=we(this,Dt).indexOf(s);r!==-1&&(ot(this,Tt,Sm(we(this,Tt),r,n)),Kt(this,at,Xa).call(this))},Xa=function(){var s;if(this.hasListeners()){const n=we(this,Ts),r=Kt(this,at,Ha).call(this,we(this,Tt),we(this,ar)),a=Kt(this,at,Qa).call(this,r,(s=we(this,yn))==null?void 0:s.combine);n!==a&&Ba.batch(()=>{this.listeners.forEach(i=>{i(we(this,Tt))})})}},ll);function co({queries:t,...s},n){const r=Le(),a=wd(),i=kd(),o=c.useMemo(()=>t.map(y=>{const f=r.defaultQueryOptions(y);return f._optimisticResults=a?"isRestoring":"optimistic",f}),[t,r,a]);o.forEach(y=>{Cd(y);const f=r.getQueryCache().get(y.queryHash);Sd(y,i,f)}),Id(i);const[l]=c.useState(()=>new Im(r,o,s)),[u,d,m]=l.getOptimisticResult(o,s.combine),x=!a&&s.subscribed!==!1;c.useSyncExternalStore(c.useCallback(y=>x?l.subscribe(Ba.batchCalls(y)):Ad,[l,x]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),c.useEffect(()=>{l.setQueries(o,s)},[o,s,l]);const h=u.some((y,f)=>Yi(o[f],y))?u.flatMap((y,f)=>{const g=o[f];if(g&&Yi(g,y)){const A=new dl(r,g);return Td(g,A,i)}return[]}):[];if(h.length>0)throw Promise.all(h);const j=u.find((y,f)=>{const g=o[f];return g&&Pd({result:y,errorResetBoundary:i,throwOnError:g.throwOnError,query:r.getQueryCache().get(g.queryHash),suspense:g.suspense})});if(j!=null&&j.error)throw j.error;return d(m())}var ua="Checkbox",[Am]=Dd(ua),[Tm,Si]=Am(ua);function Pm(t){const{__scopeCheckbox:s,checked:n,children:r,defaultChecked:a,disabled:i,form:o,name:l,onCheckedChange:u,required:d,value:m="on",internal_do_not_use_render:x}=t,[p,h]=Rd({prop:n,defaultProp:a??!1,onChange:u,caller:ua}),[j,y]=c.useState(null),[f,g]=c.useState(null),A=c.useRef(!1),N=j?!!o||!!j.closest("form"):!0,C={checked:p,disabled:i,setChecked:h,control:j,setControl:y,name:l,form:o,value:m,hasConsumerStoppedPropagationRef:A,required:d,defaultChecked:Ms(a)?!1:a,isFormControl:N,bubbleInput:f,setBubbleInput:g};return e.jsx(Tm,{scope:s,...C,children:Em(x)?x(C):r})}var ql="CheckboxTrigger",Bl=c.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:n,...r},a)=>{const{control:i,value:o,disabled:l,checked:u,required:d,setControl:m,setChecked:x,hasConsumerStoppedPropagationRef:p,isFormControl:h,bubbleInput:j}=Si(ql,t),y=ul(a,m),f=c.useRef(u);return c.useEffect(()=>{const g=i==null?void 0:i.form;if(g){const A=()=>x(f.current);return g.addEventListener("reset",A),()=>g.removeEventListener("reset",A)}},[i,x]),e.jsx(Bt.button,{type:"button",role:"checkbox","aria-checked":Ms(u)?"mixed":u,"aria-required":d,"data-state":Vl(u),"data-disabled":l?"":void 0,disabled:l,value:o,...r,ref:y,onKeyDown:Ji(s,g=>{g.key==="Enter"&&g.preventDefault()}),onClick:Ji(n,g=>{x(A=>Ms(A)?!0:!A),j&&h&&(p.current=g.isPropagationStopped(),p.current||g.stopPropagation())})})});Bl.displayName=ql;var zl=c.forwardRef((t,s)=>{const{__scopeCheckbox:n,name:r,checked:a,defaultChecked:i,required:o,disabled:l,value:u,onCheckedChange:d,form:m,...x}=t;return e.jsx(Pm,{__scopeCheckbox:n,checked:a,defaultChecked:i,disabled:l,required:o,onCheckedChange:d,name:r,form:m,value:u,internal_do_not_use_render:({isFormControl:p})=>e.jsxs(e.Fragment,{children:[e.jsx(Bl,{...x,ref:s,__scopeCheckbox:n}),p&&e.jsx(Wl,{__scopeCheckbox:n})]})})});zl.displayName=ua;var Kl="CheckboxIndicator",Ul=c.forwardRef((t,s)=>{const{__scopeCheckbox:n,forceMount:r,...a}=t,i=Si(Kl,n);return e.jsx(Ed,{present:r||Ms(i.checked)||i.checked===!0,children:e.jsx(Bt.span,{"data-state":Vl(i.checked),"data-disabled":i.disabled?"":void 0,...a,ref:s,style:{pointerEvents:"none",...t.style}})})});Ul.displayName=Kl;var Gl="CheckboxBubbleInput",Wl=c.forwardRef(({__scopeCheckbox:t,...s},n)=>{const{control:r,hasConsumerStoppedPropagationRef:a,checked:i,defaultChecked:o,required:l,disabled:u,name:d,value:m,form:x,bubbleInput:p,setBubbleInput:h}=Si(Gl,t),j=ul(n,h),y=Md(i),f=_d(r);c.useEffect(()=>{const A=p;if(!A)return;const N=window.HTMLInputElement.prototype,S=Object.getOwnPropertyDescriptor(N,"checked").set,b=!a.current;if(y!==i&&S){const v=new Event("click",{bubbles:b});A.indeterminate=Ms(i),S.call(A,Ms(i)?!1:i),A.dispatchEvent(v)}},[p,y,i,a]);const g=c.useRef(Ms(i)?!1:i);return e.jsx(Bt.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??g.current,required:l,disabled:u,name:d,value:m,form:x,...s,tabIndex:-1,ref:j,style:{...s.style,...f,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Wl.displayName=Gl;function Em(t){return typeof t=="function"}function Ms(t){return t==="indeterminate"}function Vl(t){return Ms(t)?"indeterminate":t?"checked":"unchecked"}var Rm="Label",Hl=c.forwardRef((t,s)=>e.jsx(Bt.label,{...t,ref:s,onMouseDown:n=>{var a;n.target.closest("button, input, select, textarea")||((a=t.onMouseDown)==null||a.call(t,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Hl.displayName=Rm;var Mm=Hl;/**
2
+ * @license lucide-react v0.574.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const _m=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]],Dm=me("archive-restore",_m);/**
7
+ * @license lucide-react v0.574.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const $m=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],Fm=me("archive",$m);/**
12
+ * @license lucide-react v0.574.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const Lm=[["path",{d:"M17 7 7 17",key:"15tmo1"}],["path",{d:"M17 17H7V7",key:"1org7z"}]],Om=me("arrow-down-left",Lm);/**
17
+ * @license lucide-react v0.574.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const qm=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],Bm=me("arrow-up-down",qm);/**
22
+ * @license lucide-react v0.574.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const zm=[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]],Za=me("book-open",zm);/**
27
+ * @license lucide-react v0.574.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const Km=[["path",{d:"M16 14v2.2l1.6 1",key:"fo4ql5"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5",key:"1osxxc"}],["path",{d:"M3 10h5",key:"r794hk"}],["path",{d:"M8 2v4",key:"1cmpym"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]],Um=me("calendar-clock",Km);/**
32
+ * @license lucide-react v0.574.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const Gm=[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 18h.01",key:"lrp35t"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M16 18h.01",key:"kzsmim"}]],Wm=me("calendar-days",Gm);/**
37
+ * @license lucide-react v0.574.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const Vm=[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],Hm=me("circle-check-big",Vm);/**
42
+ * @license lucide-react v0.574.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */const Qm=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]],Ql=me("clock-3",Qm);/**
47
+ * @license lucide-react v0.574.0 - ISC
48
+ *
49
+ * This source code is licensed under the ISC license.
50
+ * See the LICENSE file in the root directory of this source tree.
51
+ */const Ym=[["path",{d:"M13.744 17.736a6 6 0 1 1-7.48-7.48",key:"bq4yh3"}],["path",{d:"M15 6h1v4",key:"11y1tn"}],["path",{d:"m6.134 14.768.866-.5 2 3.464",key:"17snzx"}],["circle",{cx:"16",cy:"8",r:"6",key:"14bfc9"}]],ei=me("coins",Ym);/**
52
+ * @license lucide-react v0.574.0 - ISC
53
+ *
54
+ * This source code is licensed under the ISC license.
55
+ * See the LICENSE file in the root directory of this source tree.
56
+ */const Jm=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Xm=me("columns-3",Jm);/**
57
+ * @license lucide-react v0.574.0 - ISC
58
+ *
59
+ * This source code is licensed under the ISC license.
60
+ * See the LICENSE file in the root directory of this source tree.
61
+ */const Zm=[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]],ex=me("command",Zm);/**
62
+ * @license lucide-react v0.574.0 - ISC
63
+ *
64
+ * This source code is licensed under the ISC license.
65
+ * See the LICENSE file in the root directory of this source tree.
66
+ */const tx=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],ns=me("dollar-sign",tx);/**
67
+ * @license lucide-react v0.574.0 - ISC
68
+ *
69
+ * This source code is licensed under the ISC license.
70
+ * See the LICENSE file in the root directory of this source tree.
71
+ */const sx=[["path",{d:"M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2",key:"18mbvz"}],["path",{d:"M6.453 15h11.094",key:"3shlmq"}],["path",{d:"M8.5 2h7",key:"csnxdl"}]],ma=me("flask-conical",sx);/**
72
+ * @license lucide-react v0.574.0 - ISC
73
+ *
74
+ * This source code is licensed under the ISC license.
75
+ * See the LICENSE file in the root directory of this source tree.
76
+ */const nx=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],rx=me("funnel",nx);/**
77
+ * @license lucide-react v0.574.0 - ISC
78
+ *
79
+ * This source code is licensed under the ISC license.
80
+ * See the LICENSE file in the root directory of this source tree.
81
+ */const ax=[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M13 6h3a2 2 0 0 1 2 2v7",key:"1yeb86"}],["line",{x1:"6",x2:"6",y1:"9",y2:"21",key:"rroup"}]],Ar=me("git-pull-request",ax);/**
82
+ * @license lucide-react v0.574.0 - ISC
83
+ *
84
+ * This source code is licensed under the ISC license.
85
+ * See the LICENSE file in the root directory of this source tree.
86
+ */const ix=[["path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4",key:"tonef"}],["path",{d:"M9 18c-4.51 2-5-2-7-2",key:"9comsn"}]],uo=me("github",ix);/**
87
+ * @license lucide-react v0.574.0 - ISC
88
+ *
89
+ * This source code is licensed under the ISC license.
90
+ * See the LICENSE file in the root directory of this source tree.
91
+ */const ox=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],kn=me("history",ox);/**
92
+ * @license lucide-react v0.574.0 - ISC
93
+ *
94
+ * This source code is licensed under the ISC license.
95
+ * See the LICENSE file in the root directory of this source tree.
96
+ */const lx=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],mo=me("house",lx);/**
97
+ * @license lucide-react v0.574.0 - ISC
98
+ *
99
+ * This source code is licensed under the ISC license.
100
+ * See the LICENSE file in the root directory of this source tree.
101
+ */const cx=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],Yl=me("layers",cx);/**
102
+ * @license lucide-react v0.574.0 - ISC
103
+ *
104
+ * This source code is licensed under the ISC license.
105
+ * See the LICENSE file in the root directory of this source tree.
106
+ */const dx=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],_s=me("layout-dashboard",dx);/**
107
+ * @license lucide-react v0.574.0 - ISC
108
+ *
109
+ * This source code is licensed under the ISC license.
110
+ * See the LICENSE file in the root directory of this source tree.
111
+ */const ux=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],mx=me("layout-grid",ux);/**
112
+ * @license lucide-react v0.574.0 - ISC
113
+ *
114
+ * This source code is licensed under the ISC license.
115
+ * See the LICENSE file in the root directory of this source tree.
116
+ */const xx=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],hx=me("link-2",xx);/**
117
+ * @license lucide-react v0.574.0 - ISC
118
+ *
119
+ * This source code is licensed under the ISC license.
120
+ * See the LICENSE file in the root directory of this source tree.
121
+ */const px=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],Ii=me("list",px);/**
122
+ * @license lucide-react v0.574.0 - ISC
123
+ *
124
+ * This source code is licensed under the ISC license.
125
+ * See the LICENSE file in the root directory of this source tree.
126
+ */const gx=[["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"m14.305 7.53.923-.382",key:"1mlnsw"}],["path",{d:"m15.228 4.852-.923-.383",key:"82mpwg"}],["path",{d:"m16.852 3.228-.383-.924",key:"ln4sir"}],["path",{d:"m16.852 8.772-.383.923",key:"1dejw0"}],["path",{d:"m19.148 3.228.383-.924",key:"192kgf"}],["path",{d:"m19.53 9.696-.382-.924",key:"fiavlr"}],["path",{d:"m20.772 4.852.924-.383",key:"1j8mgp"}],["path",{d:"m20.772 7.148.924.383",key:"zix9be"}],["path",{d:"M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7",key:"1tnzv8"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}]],fx=me("monitor-cog",gx);/**
127
+ * @license lucide-react v0.574.0 - ISC
128
+ *
129
+ * This source code is licensed under the ISC license.
130
+ * See the LICENSE file in the root directory of this source tree.
131
+ */const bx=[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]],ti=me("network",bx);/**
132
+ * @license lucide-react v0.574.0 - ISC
133
+ *
134
+ * This source code is licensed under the ISC license.
135
+ * See the LICENSE file in the root directory of this source tree.
136
+ */const jx=[["path",{d:"M12 16h.01",key:"1drbdi"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z",key:"1fd625"}]],vx=me("octagon-alert",jx);/**
137
+ * @license lucide-react v0.574.0 - ISC
138
+ *
139
+ * This source code is licensed under the ISC license.
140
+ * See the LICENSE file in the root directory of this source tree.
141
+ */const yx=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]],Nx=me("panels-top-left",yx);/**
142
+ * @license lucide-react v0.574.0 - ISC
143
+ *
144
+ * This source code is licensed under the ISC license.
145
+ * See the LICENSE file in the root directory of this source tree.
146
+ */const wx=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],kx=me("power",wx);/**
147
+ * @license lucide-react v0.574.0 - ISC
148
+ *
149
+ * This source code is licensed under the ISC license.
150
+ * See the LICENSE file in the root directory of this source tree.
151
+ */const Cx=[["path",{d:"M4.9 16.1C1 12.2 1 5.8 4.9 1.9",key:"s0qx1y"}],["path",{d:"M7.8 4.7a6.14 6.14 0 0 0-.8 7.5",key:"1idnkw"}],["circle",{cx:"12",cy:"9",r:"2",key:"1092wv"}],["path",{d:"M16.2 4.8c2 2 2.26 5.11.8 7.47",key:"ojru2q"}],["path",{d:"M19.1 1.9a9.96 9.96 0 0 1 0 14.1",key:"rhi7fg"}],["path",{d:"M9.5 18h5",key:"mfy3pd"}],["path",{d:"m8 22 4-11 4 11",key:"25yftu"}]],Sx=me("radio-tower",Cx);/**
152
+ * @license lucide-react v0.574.0 - ISC
153
+ *
154
+ * This source code is licensed under the ISC license.
155
+ * See the LICENSE file in the root directory of this source tree.
156
+ */const Ix=[["path",{d:"M13 16H8",key:"wsln4y"}],["path",{d:"M14 8H8",key:"1l3xfs"}],["path",{d:"M16 12H8",key:"1fr5h0"}],["path",{d:"M4 3a1 1 0 0 1 1-1 1.3 1.3 0 0 1 .7.2l.933.6a1.3 1.3 0 0 0 1.4 0l.934-.6a1.3 1.3 0 0 1 1.4 0l.933.6a1.3 1.3 0 0 0 1.4 0l.933-.6a1.3 1.3 0 0 1 1.4 0l.934.6a1.3 1.3 0 0 0 1.4 0l.933-.6A1.3 1.3 0 0 1 19 2a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1 1.3 1.3 0 0 1-.7-.2l-.933-.6a1.3 1.3 0 0 0-1.4 0l-.934.6a1.3 1.3 0 0 1-1.4 0l-.933-.6a1.3 1.3 0 0 0-1.4 0l-.933.6a1.3 1.3 0 0 1-1.4 0l-.934-.6a1.3 1.3 0 0 0-1.4 0l-.933.6a1.3 1.3 0 0 1-.7.2 1 1 0 0 1-1-1z",key:"ycz6yz"}]],si=me("receipt-text",Ix);/**
157
+ * @license lucide-react v0.574.0 - ISC
158
+ *
159
+ * This source code is licensed under the ISC license.
160
+ * See the LICENSE file in the root directory of this source tree.
161
+ */const Ax=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],Ai=me("shield-check",Ax);/**
162
+ * @license lucide-react v0.574.0 - ISC
163
+ *
164
+ * This source code is licensed under the ISC license.
165
+ * See the LICENSE file in the root directory of this source tree.
166
+ */const Tx=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M17 12h-2l-2 5-2-10-2 5H7",key:"15hlnc"}]],xo=me("square-activity",Tx);/**
167
+ * @license lucide-react v0.574.0 - ISC
168
+ *
169
+ * This source code is licensed under the ISC license.
170
+ * See the LICENSE file in the root directory of this source tree.
171
+ */const Px=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],$r=me("square-pen",Px);/**
172
+ * @license lucide-react v0.574.0 - ISC
173
+ *
174
+ * This source code is licensed under the ISC license.
175
+ * See the LICENSE file in the root directory of this source tree.
176
+ */const Ex=[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Rx=me("trash",Ex);/**
177
+ * @license lucide-react v0.574.0 - ISC
178
+ *
179
+ * This source code is licensed under the ISC license.
180
+ * See the LICENSE file in the root directory of this source tree.
181
+ */const Mx=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],ho=me("upload",Mx);/**
182
+ * @license lucide-react v0.574.0 - ISC
183
+ *
184
+ * This source code is licensed under the ISC license.
185
+ * See the LICENSE file in the root directory of this source tree.
186
+ */const _x=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],Dx=me("user-plus",_x);/**
187
+ * @license lucide-react v0.574.0 - ISC
188
+ *
189
+ * This source code is licensed under the ISC license.
190
+ * See the LICENSE file in the root directory of this source tree.
191
+ */const $x=[["path",{d:"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2",key:"q3hayz"}],["path",{d:"m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06",key:"1go1hn"}],["path",{d:"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8",key:"qlwsc0"}]],Fx=me("webhook",$x);function Lx(){for(var t=arguments.length,s=new Array(t),n=0;n<t;n++)s[n]=arguments[n];return c.useMemo(()=>r=>{s.forEach(a=>a(r))},s)}const xa=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Rn(t){const s=Object.prototype.toString.call(t);return s==="[object Window]"||s==="[object global]"}function Ti(t){return"nodeType"in t}function jt(t){var s,n;return t?Rn(t)?t:Ti(t)&&(s=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?s:window:window}function Pi(t){const{Document:s}=jt(t);return t instanceof s}function lr(t){return Rn(t)?!1:t instanceof jt(t).HTMLElement}function Jl(t){return t instanceof jt(t).SVGElement}function Mn(t){return t?Rn(t)?t.document:Ti(t)?Pi(t)?t:lr(t)||Jl(t)?t.ownerDocument:document:document:document}const Wt=xa?c.useLayoutEffect:c.useEffect;function ha(t){const s=c.useRef(t);return Wt(()=>{s.current=t}),c.useCallback(function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return s.current==null?void 0:s.current(...r)},[])}function Ox(){const t=c.useRef(null),s=c.useCallback((r,a)=>{t.current=setInterval(r,a)},[]),n=c.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[s,n]}function Zn(t,s){s===void 0&&(s=[t]);const n=c.useRef(t);return Wt(()=>{n.current!==t&&(n.current=t)},s),n}function cr(t,s){const n=c.useRef();return c.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...s])}function Fr(t){const s=ha(t),n=c.useRef(null),r=c.useCallback(a=>{a!==n.current&&(s==null||s(a,n.current)),n.current=a},[]);return[n,r]}function Lr(t){const s=c.useRef();return c.useEffect(()=>{s.current=t},[t]),s.current}let Sa={};function dr(t,s){return c.useMemo(()=>{if(s)return s;const n=Sa[t]==null?0:Sa[t]+1;return Sa[t]=n,t+"-"+n},[t,s])}function Xl(t){return function(s){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return r.reduce((i,o)=>{const l=Object.entries(o);for(const[u,d]of l){const m=i[u];m!=null&&(i[u]=m+t*d)}return i},{...s})}}const fn=Xl(1),Or=Xl(-1);function qx(t){return"clientX"in t&&"clientY"in t}function pa(t){if(!t)return!1;const{KeyboardEvent:s}=jt(t.target);return s&&t instanceof s}function Bx(t){if(!t)return!1;const{TouchEvent:s}=jt(t.target);return s&&t instanceof s}function qr(t){if(Bx(t)){if(t.touches&&t.touches.length){const{clientX:s,clientY:n}=t.touches[0];return{x:s,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:s,clientY:n}=t.changedTouches[0];return{x:s,y:n}}}return qx(t)?{x:t.clientX,y:t.clientY}:null}const ds=Object.freeze({Translate:{toString(t){if(!t)return;const{x:s,y:n}=t;return"translate3d("+(s?Math.round(s):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:s,scaleY:n}=t;return"scaleX("+s+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[ds.Translate.toString(t),ds.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:s,duration:n,easing:r}=t;return s+" "+n+"ms "+r}}}),po="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function zx(t){return t.matches(po)?t:t.querySelector(po)}const Kx={display:"none"};function Ux(t){let{id:s,value:n}=t;return be.createElement("div",{id:s,style:Kx},n)}function Gx(t){let{id:s,announcement:n,ariaLiveType:r="assertive"}=t;const a={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return be.createElement("div",{id:s,style:a,role:"status","aria-live":r,"aria-atomic":!0},n)}function Wx(){const[t,s]=c.useState("");return{announce:c.useCallback(r=>{r!=null&&s(r)},[]),announcement:t}}const Zl=c.createContext(null);function Vx(t){const s=c.useContext(Zl);c.useEffect(()=>{if(!s)throw new Error("useDndMonitor must be used within a children of <DndContext>");return s(t)},[t,s])}function Hx(){const[t]=c.useState(()=>new Set),s=c.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[c.useCallback(r=>{let{type:a,event:i}=r;t.forEach(o=>{var l;return(l=o[a])==null?void 0:l.call(o,i)})},[t]),s]}const Qx={draggable:`
192
+ To pick up a draggable item, press the space bar.
193
+ While dragging, use the arrow keys to move the item.
194
+ Press space again to drop the item in its new position, or press escape to cancel.
195
+ `},Yx={onDragStart(t){let{active:s}=t;return"Picked up draggable item "+s.id+"."},onDragOver(t){let{active:s,over:n}=t;return n?"Draggable item "+s.id+" was moved over droppable area "+n.id+".":"Draggable item "+s.id+" is no longer over a droppable area."},onDragEnd(t){let{active:s,over:n}=t;return n?"Draggable item "+s.id+" was dropped over droppable area "+n.id:"Draggable item "+s.id+" was dropped."},onDragCancel(t){let{active:s}=t;return"Dragging was cancelled. Draggable item "+s.id+" was dropped."}};function Jx(t){let{announcements:s=Yx,container:n,hiddenTextDescribedById:r,screenReaderInstructions:a=Qx}=t;const{announce:i,announcement:o}=Wx(),l=dr("DndLiveRegion"),[u,d]=c.useState(!1);if(c.useEffect(()=>{d(!0)},[]),Vx(c.useMemo(()=>({onDragStart(x){let{active:p}=x;i(s.onDragStart({active:p}))},onDragMove(x){let{active:p,over:h}=x;s.onDragMove&&i(s.onDragMove({active:p,over:h}))},onDragOver(x){let{active:p,over:h}=x;i(s.onDragOver({active:p,over:h}))},onDragEnd(x){let{active:p,over:h}=x;i(s.onDragEnd({active:p,over:h}))},onDragCancel(x){let{active:p,over:h}=x;i(s.onDragCancel({active:p,over:h}))}}),[i,s])),!u)return null;const m=be.createElement(be.Fragment,null,be.createElement(Ux,{id:r,value:a.draggable}),be.createElement(Gx,{id:l,announcement:o}));return n?qn.createPortal(m,n):m}var We;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(We||(We={}));function Br(){}function Ei(t,s){return c.useMemo(()=>({sensor:t,options:s??{}}),[t,s])}function Ri(){for(var t=arguments.length,s=new Array(t),n=0;n<t;n++)s[n]=arguments[n];return c.useMemo(()=>[...s].filter(r=>r!=null),[...s])}const Vt=Object.freeze({x:0,y:0});function Xx(t,s){return Math.sqrt(Math.pow(t.x-s.x,2)+Math.pow(t.y-s.y,2))}function Zx(t,s){const n=qr(t);if(!n)return"0 0";const r={x:(n.x-s.left)/s.width*100,y:(n.y-s.top)/s.height*100};return r.x+"% "+r.y+"%"}function eh(t,s){let{data:{value:n}}=t,{data:{value:r}}=s;return n-r}function th(t,s){let{data:{value:n}}=t,{data:{value:r}}=s;return r-n}function sh(t,s){if(!t||t.length===0)return null;const[n]=t;return n[s]}function go(t,s,n){return s===void 0&&(s=t.left),n===void 0&&(n=t.top),{x:s+t.width*.5,y:n+t.height*.5}}const ec=t=>{let{collisionRect:s,droppableRects:n,droppableContainers:r}=t;const a=go(s,s.left,s.top),i=[];for(const o of r){const{id:l}=o,u=n.get(l);if(u){const d=Xx(go(u),a);i.push({id:l,data:{droppableContainer:o,value:d}})}}return i.sort(eh)};function nh(t,s){const n=Math.max(s.top,t.top),r=Math.max(s.left,t.left),a=Math.min(s.left+s.width,t.left+t.width),i=Math.min(s.top+s.height,t.top+t.height),o=a-r,l=i-n;if(r<a&&n<i){const u=s.width*s.height,d=t.width*t.height,m=o*l,x=m/(u+d-m);return Number(x.toFixed(4))}return 0}const rh=t=>{let{collisionRect:s,droppableRects:n,droppableContainers:r}=t;const a=[];for(const i of r){const{id:o}=i,l=n.get(o);if(l){const u=nh(l,s);u>0&&a.push({id:o,data:{droppableContainer:i,value:u}})}}return a.sort(th)};function ah(t,s,n){return{...t,scaleX:s&&n?s.width/n.width:1,scaleY:s&&n?s.height/n.height:1}}function tc(t,s){return t&&s?{x:t.left-s.left,y:t.top-s.top}:Vt}function ih(t){return function(n){for(var r=arguments.length,a=new Array(r>1?r-1:0),i=1;i<r;i++)a[i-1]=arguments[i];return a.reduce((o,l)=>({...o,top:o.top+t*l.y,bottom:o.bottom+t*l.y,left:o.left+t*l.x,right:o.right+t*l.x}),{...n})}}const oh=ih(1);function sc(t){if(t.startsWith("matrix3d(")){const s=t.slice(9,-1).split(/, /);return{x:+s[12],y:+s[13],scaleX:+s[0],scaleY:+s[5]}}else if(t.startsWith("matrix(")){const s=t.slice(7,-1).split(/, /);return{x:+s[4],y:+s[5],scaleX:+s[0],scaleY:+s[3]}}return null}function lh(t,s,n){const r=sc(s);if(!r)return t;const{scaleX:a,scaleY:i,x:o,y:l}=r,u=t.left-o-(1-a)*parseFloat(n),d=t.top-l-(1-i)*parseFloat(n.slice(n.indexOf(" ")+1)),m=a?t.width/a:t.width,x=i?t.height/i:t.height;return{width:m,height:x,top:d,right:u+m,bottom:d+x,left:u}}const ch={ignoreTransform:!1};function _n(t,s){s===void 0&&(s=ch);let n=t.getBoundingClientRect();if(s.ignoreTransform){const{transform:d,transformOrigin:m}=jt(t).getComputedStyle(t);d&&(n=lh(n,d,m))}const{top:r,left:a,width:i,height:o,bottom:l,right:u}=n;return{top:r,left:a,width:i,height:o,bottom:l,right:u}}function fo(t){return _n(t,{ignoreTransform:!0})}function dh(t){const s=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:s,bottom:n,width:s,height:n}}function uh(t,s){return s===void 0&&(s=jt(t).getComputedStyle(t)),s.position==="fixed"}function mh(t,s){s===void 0&&(s=jt(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(a=>{const i=s[a];return typeof i=="string"?n.test(i):!1})}function Mi(t,s){const n=[];function r(a){if(s!=null&&n.length>=s||!a)return n;if(Pi(a)&&a.scrollingElement!=null&&!n.includes(a.scrollingElement))return n.push(a.scrollingElement),n;if(!lr(a)||Jl(a)||n.includes(a))return n;const i=jt(t).getComputedStyle(a);return a!==t&&mh(a,i)&&n.push(a),uh(a,i)?n:r(a.parentNode)}return t?r(t):n}function nc(t){const[s]=Mi(t,1);return s??null}function Ia(t){return!xa||!t?null:Rn(t)?t:Ti(t)?Pi(t)||t===Mn(t).scrollingElement?window:lr(t)?t:null:null}function rc(t){return Rn(t)?t.scrollX:t.scrollLeft}function ac(t){return Rn(t)?t.scrollY:t.scrollTop}function ni(t){return{x:rc(t),y:ac(t)}}var Xe;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(Xe||(Xe={}));function ic(t){return!xa||!t?!1:t===document.scrollingElement}function oc(t){const s={x:0,y:0},n=ic(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},r={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},a=t.scrollTop<=s.y,i=t.scrollLeft<=s.x,o=t.scrollTop>=r.y,l=t.scrollLeft>=r.x;return{isTop:a,isLeft:i,isBottom:o,isRight:l,maxScroll:r,minScroll:s}}const xh={x:.2,y:.2};function hh(t,s,n,r,a){let{top:i,left:o,right:l,bottom:u}=n;r===void 0&&(r=10),a===void 0&&(a=xh);const{isTop:d,isBottom:m,isLeft:x,isRight:p}=oc(t),h={x:0,y:0},j={x:0,y:0},y={height:s.height*a.y,width:s.width*a.x};return!d&&i<=s.top+y.height?(h.y=Xe.Backward,j.y=r*Math.abs((s.top+y.height-i)/y.height)):!m&&u>=s.bottom-y.height&&(h.y=Xe.Forward,j.y=r*Math.abs((s.bottom-y.height-u)/y.height)),!p&&l>=s.right-y.width?(h.x=Xe.Forward,j.x=r*Math.abs((s.right-y.width-l)/y.width)):!x&&o<=s.left+y.width&&(h.x=Xe.Backward,j.x=r*Math.abs((s.left+y.width-o)/y.width)),{direction:h,speed:j}}function ph(t){if(t===document.scrollingElement){const{innerWidth:i,innerHeight:o}=window;return{top:0,left:0,right:i,bottom:o,width:i,height:o}}const{top:s,left:n,right:r,bottom:a}=t.getBoundingClientRect();return{top:s,left:n,right:r,bottom:a,width:t.clientWidth,height:t.clientHeight}}function lc(t){return t.reduce((s,n)=>fn(s,ni(n)),Vt)}function gh(t){return t.reduce((s,n)=>s+rc(n),0)}function fh(t){return t.reduce((s,n)=>s+ac(n),0)}function cc(t,s){if(s===void 0&&(s=_n),!t)return;const{top:n,left:r,bottom:a,right:i}=s(t);nc(t)&&(a<=0||i<=0||n>=window.innerHeight||r>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const bh=[["x",["left","right"],gh],["y",["top","bottom"],fh]];class _i{constructor(s,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const r=Mi(n),a=lc(r);this.rect={...s},this.width=s.width,this.height=s.height;for(const[i,o,l]of bh)for(const u of o)Object.defineProperty(this,u,{get:()=>{const d=l(r),m=a[i]-d;return this.rect[u]+m},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class Gn{constructor(s){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=s}add(s,n,r){var a;(a=this.target)==null||a.addEventListener(s,n,r),this.listeners.push([s,n,r])}}function jh(t){const{EventTarget:s}=jt(t);return t instanceof s?t:Mn(t)}function Aa(t,s){const n=Math.abs(t.x),r=Math.abs(t.y);return typeof s=="number"?Math.sqrt(n**2+r**2)>s:"x"in s&&"y"in s?n>s.x&&r>s.y:"x"in s?n>s.x:"y"in s?r>s.y:!1}var Ft;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Ft||(Ft={}));function bo(t){t.preventDefault()}function vh(t){t.stopPropagation()}var ve;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(ve||(ve={}));const dc={start:[ve.Space,ve.Enter],cancel:[ve.Esc],end:[ve.Space,ve.Enter,ve.Tab]},yh=(t,s)=>{let{currentCoordinates:n}=s;switch(t.code){case ve.Right:return{...n,x:n.x+25};case ve.Left:return{...n,x:n.x-25};case ve.Down:return{...n,y:n.y+25};case ve.Up:return{...n,y:n.y-25}}};class uc{constructor(s){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=s;const{event:{target:n}}=s;this.props=s,this.listeners=new Gn(Mn(n)),this.windowListeners=new Gn(jt(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ft.Resize,this.handleCancel),this.windowListeners.add(Ft.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ft.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:s,onStart:n}=this.props,r=s.node.current;r&&cc(r),n(Vt)}handleKeyDown(s){if(pa(s)){const{active:n,context:r,options:a}=this.props,{keyboardCodes:i=dc,coordinateGetter:o=yh,scrollBehavior:l="smooth"}=a,{code:u}=s;if(i.end.includes(u)){this.handleEnd(s);return}if(i.cancel.includes(u)){this.handleCancel(s);return}const{collisionRect:d}=r.current,m=d?{x:d.left,y:d.top}:Vt;this.referenceCoordinates||(this.referenceCoordinates=m);const x=o(s,{active:n,context:r.current,currentCoordinates:m});if(x){const p=Or(x,m),h={x:0,y:0},{scrollableAncestors:j}=r.current;for(const y of j){const f=s.code,{isTop:g,isRight:A,isLeft:N,isBottom:C,maxScroll:S,minScroll:b}=oc(y),v=ph(y),M={x:Math.min(f===ve.Right?v.right-v.width/2:v.right,Math.max(f===ve.Right?v.left:v.left+v.width/2,x.x)),y:Math.min(f===ve.Down?v.bottom-v.height/2:v.bottom,Math.max(f===ve.Down?v.top:v.top+v.height/2,x.y))},k=f===ve.Right&&!A||f===ve.Left&&!N,_=f===ve.Down&&!C||f===ve.Up&&!g;if(k&&M.x!==x.x){const U=y.scrollLeft+p.x,w=f===ve.Right&&U<=S.x||f===ve.Left&&U>=b.x;if(w&&!p.y){y.scrollTo({left:U,behavior:l});return}w?h.x=y.scrollLeft-U:h.x=f===ve.Right?y.scrollLeft-S.x:y.scrollLeft-b.x,h.x&&y.scrollBy({left:-h.x,behavior:l});break}else if(_&&M.y!==x.y){const U=y.scrollTop+p.y,w=f===ve.Down&&U<=S.y||f===ve.Up&&U>=b.y;if(w&&!p.x){y.scrollTo({top:U,behavior:l});return}w?h.y=y.scrollTop-U:h.y=f===ve.Down?y.scrollTop-S.y:y.scrollTop-b.y,h.y&&y.scrollBy({top:-h.y,behavior:l});break}}this.handleMove(s,fn(Or(x,this.referenceCoordinates),h))}}}handleMove(s,n){const{onMove:r}=this.props;s.preventDefault(),r(n)}handleEnd(s){const{onEnd:n}=this.props;s.preventDefault(),this.detach(),n()}handleCancel(s){const{onCancel:n}=this.props;s.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}uc.activators=[{eventName:"onKeyDown",handler:(t,s,n)=>{let{keyboardCodes:r=dc,onActivation:a}=s,{active:i}=n;const{code:o}=t.nativeEvent;if(r.start.includes(o)){const l=i.activatorNode.current;return l&&t.target!==l?!1:(t.preventDefault(),a==null||a({event:t.nativeEvent}),!0)}return!1}}];function jo(t){return!!(t&&"distance"in t)}function vo(t){return!!(t&&"delay"in t)}class Di{constructor(s,n,r){var a;r===void 0&&(r=jh(s.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=s,this.events=n;const{event:i}=s,{target:o}=i;this.props=s,this.events=n,this.document=Mn(o),this.documentListeners=new Gn(this.document),this.listeners=new Gn(r),this.windowListeners=new Gn(jt(o)),this.initialCoordinates=(a=qr(i))!=null?a:Vt,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:s,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(s.move.name,this.handleMove,{passive:!1}),this.listeners.add(s.end.name,this.handleEnd),s.cancel&&this.listeners.add(s.cancel.name,this.handleCancel),this.windowListeners.add(Ft.Resize,this.handleCancel),this.windowListeners.add(Ft.DragStart,bo),this.windowListeners.add(Ft.VisibilityChange,this.handleCancel),this.windowListeners.add(Ft.ContextMenu,bo),this.documentListeners.add(Ft.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(vo(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(jo(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(s,n){const{active:r,onPending:a}=this.props;a(r,s,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:s}=this,{onStart:n}=this.props;s&&(this.activated=!0,this.documentListeners.add(Ft.Click,vh,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ft.SelectionChange,this.removeTextSelection),n(s))}handleMove(s){var n;const{activated:r,initialCoordinates:a,props:i}=this,{onMove:o,options:{activationConstraint:l}}=i;if(!a)return;const u=(n=qr(s))!=null?n:Vt,d=Or(a,u);if(!r&&l){if(jo(l)){if(l.tolerance!=null&&Aa(d,l.tolerance))return this.handleCancel();if(Aa(d,l.distance))return this.handleStart()}if(vo(l)&&Aa(d,l.tolerance))return this.handleCancel();this.handlePending(l,d);return}s.cancelable&&s.preventDefault(),o(u)}handleEnd(){const{onAbort:s,onEnd:n}=this.props;this.detach(),this.activated||s(this.props.active),n()}handleCancel(){const{onAbort:s,onCancel:n}=this.props;this.detach(),this.activated||s(this.props.active),n()}handleKeydown(s){s.code===ve.Esc&&this.handleCancel()}removeTextSelection(){var s;(s=this.document.getSelection())==null||s.removeAllRanges()}}const Nh={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class ur extends Di{constructor(s){const{event:n}=s,r=Mn(n.target);super(s,Nh,r)}}ur.activators=[{eventName:"onPointerDown",handler:(t,s)=>{let{nativeEvent:n}=t,{onActivation:r}=s;return!n.isPrimary||n.button!==0?!1:(r==null||r({event:n}),!0)}}];const wh={move:{name:"mousemove"},end:{name:"mouseup"}};var ri;(function(t){t[t.RightClick=2]="RightClick"})(ri||(ri={}));class kh extends Di{constructor(s){super(s,wh,Mn(s.event.target))}}kh.activators=[{eventName:"onMouseDown",handler:(t,s)=>{let{nativeEvent:n}=t,{onActivation:r}=s;return n.button===ri.RightClick?!1:(r==null||r({event:n}),!0)}}];const Ta={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Ch extends Di{constructor(s){super(s,Ta)}static setup(){return window.addEventListener(Ta.move.name,s,{capture:!1,passive:!1}),function(){window.removeEventListener(Ta.move.name,s)};function s(){}}}Ch.activators=[{eventName:"onTouchStart",handler:(t,s)=>{let{nativeEvent:n}=t,{onActivation:r}=s;const{touches:a}=n;return a.length>1?!1:(r==null||r({event:n}),!0)}}];var Wn;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(Wn||(Wn={}));var zr;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(zr||(zr={}));function Sh(t){let{acceleration:s,activator:n=Wn.Pointer,canScroll:r,draggingRect:a,enabled:i,interval:o=5,order:l=zr.TreeOrder,pointerCoordinates:u,scrollableAncestors:d,scrollableAncestorRects:m,delta:x,threshold:p}=t;const h=Ah({delta:x,disabled:!i}),[j,y]=Ox(),f=c.useRef({x:0,y:0}),g=c.useRef({x:0,y:0}),A=c.useMemo(()=>{switch(n){case Wn.Pointer:return u?{top:u.y,bottom:u.y,left:u.x,right:u.x}:null;case Wn.DraggableRect:return a}},[n,a,u]),N=c.useRef(null),C=c.useCallback(()=>{const b=N.current;if(!b)return;const v=f.current.x*g.current.x,M=f.current.y*g.current.y;b.scrollBy(v,M)},[]),S=c.useMemo(()=>l===zr.TreeOrder?[...d].reverse():d,[l,d]);c.useEffect(()=>{if(!i||!d.length||!A){y();return}for(const b of S){if((r==null?void 0:r(b))===!1)continue;const v=d.indexOf(b),M=m[v];if(!M)continue;const{direction:k,speed:_}=hh(b,M,A,s,p);for(const U of["x","y"])h[U][k[U]]||(_[U]=0,k[U]=0);if(_.x>0||_.y>0){y(),N.current=b,j(C,o),f.current=_,g.current=k;return}}f.current={x:0,y:0},g.current={x:0,y:0},y()},[s,C,r,y,i,o,JSON.stringify(A),JSON.stringify(h),j,d,S,m,JSON.stringify(p)])}const Ih={x:{[Xe.Backward]:!1,[Xe.Forward]:!1},y:{[Xe.Backward]:!1,[Xe.Forward]:!1}};function Ah(t){let{delta:s,disabled:n}=t;const r=Lr(s);return cr(a=>{if(n||!r||!a)return Ih;const i={x:Math.sign(s.x-r.x),y:Math.sign(s.y-r.y)};return{x:{[Xe.Backward]:a.x[Xe.Backward]||i.x===-1,[Xe.Forward]:a.x[Xe.Forward]||i.x===1},y:{[Xe.Backward]:a.y[Xe.Backward]||i.y===-1,[Xe.Forward]:a.y[Xe.Forward]||i.y===1}}},[n,s,r])}function Th(t,s){const n=s!=null?t.get(s):void 0,r=n?n.node.current:null;return cr(a=>{var i;return s==null?null:(i=r??a)!=null?i:null},[r,s])}function Ph(t,s){return c.useMemo(()=>t.reduce((n,r)=>{const{sensor:a}=r,i=a.activators.map(o=>({eventName:o.eventName,handler:s(o.handler,r)}));return[...n,...i]},[]),[t,s])}var er;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(er||(er={}));var ai;(function(t){t.Optimized="optimized"})(ai||(ai={}));const yo=new Map;function Eh(t,s){let{dragging:n,dependencies:r,config:a}=s;const[i,o]=c.useState(null),{frequency:l,measure:u,strategy:d}=a,m=c.useRef(t),x=f(),p=Zn(x),h=c.useCallback(function(g){g===void 0&&(g=[]),!p.current&&o(A=>A===null?g:A.concat(g.filter(N=>!A.includes(N))))},[p]),j=c.useRef(null),y=cr(g=>{if(x&&!n)return yo;if(!g||g===yo||m.current!==t||i!=null){const A=new Map;for(let N of t){if(!N)continue;if(i&&i.length>0&&!i.includes(N.id)&&N.rect.current){A.set(N.id,N.rect.current);continue}const C=N.node.current,S=C?new _i(u(C),C):null;N.rect.current=S,S&&A.set(N.id,S)}return A}return g},[t,i,n,x,u]);return c.useEffect(()=>{m.current=t},[t]),c.useEffect(()=>{x||h()},[n,x]),c.useEffect(()=>{i&&i.length>0&&o(null)},[JSON.stringify(i)]),c.useEffect(()=>{x||typeof l!="number"||j.current!==null||(j.current=setTimeout(()=>{h(),j.current=null},l))},[l,x,h,...r]),{droppableRects:y,measureDroppableContainers:h,measuringScheduled:i!=null};function f(){switch(d){case er.Always:return!1;case er.BeforeDragging:return n;default:return!n}}}function $i(t,s){return cr(n=>t?n||(typeof s=="function"?s(t):t):null,[s,t])}function Rh(t,s){return $i(t,s)}function Mh(t){let{callback:s,disabled:n}=t;const r=ha(s),a=c.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:i}=window;return new i(r)},[r,n]);return c.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function ga(t){let{callback:s,disabled:n}=t;const r=ha(s),a=c.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:i}=window;return new i(r)},[n]);return c.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function _h(t){return new _i(_n(t),t)}function No(t,s,n){s===void 0&&(s=_h);const[r,a]=c.useState(null);function i(){a(u=>{if(!t)return null;if(t.isConnected===!1){var d;return(d=u??n)!=null?d:null}const m=s(t);return JSON.stringify(u)===JSON.stringify(m)?u:m})}const o=Mh({callback(u){if(t)for(const d of u){const{type:m,target:x}=d;if(m==="childList"&&x instanceof HTMLElement&&x.contains(t)){i();break}}}}),l=ga({callback:i});return Wt(()=>{i(),t?(l==null||l.observe(t),o==null||o.observe(document.body,{childList:!0,subtree:!0})):(l==null||l.disconnect(),o==null||o.disconnect())},[t]),r}function Dh(t){const s=$i(t);return tc(t,s)}const wo=[];function $h(t){const s=c.useRef(t),n=cr(r=>t?r&&r!==wo&&t&&s.current&&t.parentNode===s.current.parentNode?r:Mi(t):wo,[t]);return c.useEffect(()=>{s.current=t},[t]),n}function Fh(t){const[s,n]=c.useState(null),r=c.useRef(t),a=c.useCallback(i=>{const o=Ia(i.target);o&&n(l=>l?(l.set(o,ni(o)),new Map(l)):null)},[]);return c.useEffect(()=>{const i=r.current;if(t!==i){o(i);const l=t.map(u=>{const d=Ia(u);return d?(d.addEventListener("scroll",a,{passive:!0}),[d,ni(d)]):null}).filter(u=>u!=null);n(l.length?new Map(l):null),r.current=t}return()=>{o(t),o(i)};function o(l){l.forEach(u=>{const d=Ia(u);d==null||d.removeEventListener("scroll",a)})}},[a,t]),c.useMemo(()=>t.length?s?Array.from(s.values()).reduce((i,o)=>fn(i,o),Vt):lc(t):Vt,[t,s])}function ko(t,s){s===void 0&&(s=[]);const n=c.useRef(null);return c.useEffect(()=>{n.current=null},s),c.useEffect(()=>{const r=t!==Vt;r&&!n.current&&(n.current=t),!r&&n.current&&(n.current=null)},[t]),n.current?Or(t,n.current):Vt}function Lh(t){c.useEffect(()=>{if(!xa)return;const s=t.map(n=>{let{sensor:r}=n;return r.setup==null?void 0:r.setup()});return()=>{for(const n of s)n==null||n()}},t.map(s=>{let{sensor:n}=s;return n}))}function Oh(t,s){return c.useMemo(()=>t.reduce((n,r)=>{let{eventName:a,handler:i}=r;return n[a]=o=>{i(o,s)},n},{}),[t,s])}function mc(t){return c.useMemo(()=>t?dh(t):null,[t])}const Co=[];function qh(t,s){s===void 0&&(s=_n);const[n]=t,r=mc(n?jt(n):null),[a,i]=c.useState(Co);function o(){i(()=>t.length?t.map(u=>ic(u)?r:new _i(s(u),u)):Co)}const l=ga({callback:o});return Wt(()=>{l==null||l.disconnect(),o(),t.forEach(u=>l==null?void 0:l.observe(u))},[t]),a}function xc(t){if(!t)return null;if(t.children.length>1)return t;const s=t.children[0];return lr(s)?s:t}function Bh(t){let{measure:s}=t;const[n,r]=c.useState(null),a=c.useCallback(d=>{for(const{target:m}of d)if(lr(m)){r(x=>{const p=s(m);return x?{...x,width:p.width,height:p.height}:p});break}},[s]),i=ga({callback:a}),o=c.useCallback(d=>{const m=xc(d);i==null||i.disconnect(),m&&(i==null||i.observe(m)),r(m?s(m):null)},[s,i]),[l,u]=Fr(o);return c.useMemo(()=>({nodeRef:l,rect:n,setRef:u}),[n,l,u])}const zh=[{sensor:ur,options:{}},{sensor:uc,options:{}}],Kh={current:{}},Tr={draggable:{measure:fo},droppable:{measure:fo,strategy:er.WhileDragging,frequency:ai.Optimized},dragOverlay:{measure:_n}};class Vn extends Map{get(s){var n;return s!=null&&(n=super.get(s))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(s=>{let{disabled:n}=s;return!n})}getNodeFor(s){var n,r;return(n=(r=this.get(s))==null?void 0:r.node.current)!=null?n:void 0}}const Uh={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Vn,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Br},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:Tr,measureDroppableContainers:Br,windowRect:null,measuringScheduled:!1},hc={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Br,draggableNodes:new Map,over:null,measureDroppableContainers:Br},mr=c.createContext(hc),pc=c.createContext(Uh);function Gh(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Vn}}}function Wh(t,s){switch(s.type){case We.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:s.initialCoordinates,active:s.active}};case We.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:s.coordinates.x-t.draggable.initialCoordinates.x,y:s.coordinates.y-t.draggable.initialCoordinates.y}}};case We.DragEnd:case We.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case We.RegisterDroppable:{const{element:n}=s,{id:r}=n,a=new Vn(t.droppable.containers);return a.set(r,n),{...t,droppable:{...t.droppable,containers:a}}}case We.SetDroppableDisabled:{const{id:n,key:r,disabled:a}=s,i=t.droppable.containers.get(n);if(!i||r!==i.key)return t;const o=new Vn(t.droppable.containers);return o.set(n,{...i,disabled:a}),{...t,droppable:{...t.droppable,containers:o}}}case We.UnregisterDroppable:{const{id:n,key:r}=s,a=t.droppable.containers.get(n);if(!a||r!==a.key)return t;const i=new Vn(t.droppable.containers);return i.delete(n),{...t,droppable:{...t.droppable,containers:i}}}default:return t}}function Vh(t){let{disabled:s}=t;const{active:n,activatorEvent:r,draggableNodes:a}=c.useContext(mr),i=Lr(r),o=Lr(n==null?void 0:n.id);return c.useEffect(()=>{if(!s&&!r&&i&&o!=null){if(!pa(i)||document.activeElement===i.target)return;const l=a.get(o);if(!l)return;const{activatorNode:u,node:d}=l;if(!u.current&&!d.current)return;requestAnimationFrame(()=>{for(const m of[u.current,d.current]){if(!m)continue;const x=zx(m);if(x){x.focus();break}}})}},[r,s,a,o,i]),null}function gc(t,s){let{transform:n,...r}=s;return t!=null&&t.length?t.reduce((a,i)=>i({transform:a,...r}),n):n}function Hh(t){return c.useMemo(()=>({draggable:{...Tr.draggable,...t==null?void 0:t.draggable},droppable:{...Tr.droppable,...t==null?void 0:t.droppable},dragOverlay:{...Tr.dragOverlay,...t==null?void 0:t.dragOverlay}}),[t==null?void 0:t.draggable,t==null?void 0:t.droppable,t==null?void 0:t.dragOverlay])}function Qh(t){let{activeNode:s,measure:n,initialRect:r,config:a=!0}=t;const i=c.useRef(!1),{x:o,y:l}=typeof a=="boolean"?{x:a,y:a}:a;Wt(()=>{if(!o&&!l||!s){i.current=!1;return}if(i.current||!r)return;const d=s==null?void 0:s.node.current;if(!d||d.isConnected===!1)return;const m=n(d),x=tc(m,r);if(o||(x.x=0),l||(x.y=0),i.current=!0,Math.abs(x.x)>0||Math.abs(x.y)>0){const p=nc(d);p&&p.scrollBy({top:x.y,left:x.x})}},[s,o,l,r,n])}const fa=c.createContext({...Vt,scaleX:1,scaleY:1});var Is;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Is||(Is={}));const Fi=c.memo(function(s){var n,r,a,i;let{id:o,accessibility:l,autoScroll:u=!0,children:d,sensors:m=zh,collisionDetection:x=rh,measuring:p,modifiers:h,...j}=s;const y=c.useReducer(Wh,void 0,Gh),[f,g]=y,[A,N]=Hx(),[C,S]=c.useState(Is.Uninitialized),b=C===Is.Initialized,{draggable:{active:v,nodes:M,translate:k},droppable:{containers:_}}=f,U=v!=null?M.get(v):null,w=c.useRef({initial:null,translated:null}),T=c.useMemo(()=>{var Ye;return v!=null?{id:v,data:(Ye=U==null?void 0:U.data)!=null?Ye:Kh,rect:w}:null},[v,U]),W=c.useRef(null),[H,B]=c.useState(null),[D,Z]=c.useState(null),G=Zn(j,Object.values(j)),ie=dr("DndDescribedBy",o),ce=c.useMemo(()=>_.getEnabled(),[_]),q=Hh(p),{droppableRects:J,measureDroppableContainers:I,measuringScheduled:P}=Eh(ce,{dragging:b,dependencies:[k.x,k.y],config:q.droppable}),O=Th(M,v),te=c.useMemo(()=>D?qr(D):null,[D]),oe=Dn(),ue=Rh(O,q.draggable.measure);Qh({activeNode:v!=null?M.get(v):null,config:oe.layoutShiftCompensation,initialRect:ue,measure:q.draggable.measure});const L=No(O,q.draggable.measure,ue),ae=No(O?O.parentElement:null),le=c.useRef({activatorEvent:null,active:null,activeNode:O,collisionRect:null,collisions:null,droppableRects:J,draggableNodes:M,draggingNode:null,draggingNodeRect:null,droppableContainers:_,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),Re=_.getNodeFor((n=le.current.over)==null?void 0:n.id),ee=Bh({measure:q.dragOverlay.measure}),ye=(r=ee.nodeRef.current)!=null?r:O,Ce=b?(a=ee.rect)!=null?a:L:null,He=!!(ee.nodeRef.current&&ee.rect),K=Dh(He?null:L),de=mc(ye?jt(ye):null),fe=$h(b?Re??O:null),Ie=qh(fe),ze=gc(h,{transform:{x:k.x-K.x,y:k.y-K.y,scaleX:1,scaleY:1},activatorEvent:D,active:T,activeNodeRect:L,containerNodeRect:ae,draggingNodeRect:Ce,over:le.current.over,overlayNodeRect:ee.rect,scrollableAncestors:fe,scrollableAncestorRects:Ie,windowRect:de}),Qt=te?fn(te,k):null,Fs=Fh(fe),us=ko(Fs),Ls=ko(Fs,[L]),ct=fn(ze,us),Qe=Ce?oh(Ce,ze):null,Yt=T&&Qe?x({active:T,collisionRect:Qe,droppableRects:J,droppableContainers:ce,pointerCoordinates:Qt}):null,zt=sh(Yt,"id"),[It,ms]=c.useState(null),R=He?ze:fn(ze,Ls),X=ah(R,(i=It==null?void 0:It.rect)!=null?i:null,L),$=c.useRef(null),Q=c.useCallback((Ye,it)=>{let{sensor:dt,options:Jt}=it;if(W.current==null)return;const vt=M.get(W.current);if(!vt)return;const At=Ye.nativeEvent,Xt=new dt({active:W.current,activeNode:vt,event:At,options:Jt,context:le,onAbort(st){if(!M.get(st))return;const{onDragAbort:Zt}=G.current,xs={id:st};Zt==null||Zt(xs),A({type:"onDragAbort",event:xs})},onPending(st,ws,Zt,xs){if(!M.get(st))return;const{onDragPending:Fn}=G.current,ks={id:st,constraint:ws,initialCoordinates:Zt,offset:xs};Fn==null||Fn(ks),A({type:"onDragPending",event:ks})},onStart(st){const ws=W.current;if(ws==null)return;const Zt=M.get(ws);if(!Zt)return;const{onDragStart:xs}=G.current,$n={activatorEvent:At,active:{id:ws,data:Zt.data,rect:w}};qn.unstable_batchedUpdates(()=>{xs==null||xs($n),S(Is.Initializing),g({type:We.DragStart,initialCoordinates:st,active:ws}),A({type:"onDragStart",event:$n}),B($.current),Z(At)})},onMove(st){g({type:We.DragMove,coordinates:st})},onEnd:en(We.DragEnd),onCancel:en(We.DragCancel)});$.current=Xt;function en(st){return async function(){const{active:Zt,collisions:xs,over:$n,scrollAdjustedTranslate:Fn}=le.current;let ks=null;if(Zt&&Fn){const{cancelDrop:Ln}=G.current;ks={activatorEvent:At,active:Zt,collisions:xs,delta:Fn,over:$n},st===We.DragEnd&&typeof Ln=="function"&&await Promise.resolve(Ln(ks))&&(st=We.DragCancel)}W.current=null,qn.unstable_batchedUpdates(()=>{g({type:st}),S(Is.Uninitialized),ms(null),B(null),Z(null),$.current=null;const Ln=st===We.DragEnd?"onDragEnd":"onDragCancel";if(ks){const ya=G.current[Ln];ya==null||ya(ks),A({type:Ln,event:ks})}})}}},[M]),ne=c.useCallback((Ye,it)=>(dt,Jt)=>{const vt=dt.nativeEvent,At=M.get(Jt);if(W.current!==null||!At||vt.dndKit||vt.defaultPrevented)return;const Xt={active:At};Ye(dt,it.options,Xt)===!0&&(vt.dndKit={capturedBy:it.sensor},W.current=Jt,Q(dt,it))},[M,Q]),je=Ph(m,ne);Lh(m),Wt(()=>{L&&C===Is.Initializing&&S(Is.Initialized)},[L,C]),c.useEffect(()=>{const{onDragMove:Ye}=G.current,{active:it,activatorEvent:dt,collisions:Jt,over:vt}=le.current;if(!it||!dt)return;const At={active:it,activatorEvent:dt,collisions:Jt,delta:{x:ct.x,y:ct.y},over:vt};qn.unstable_batchedUpdates(()=>{Ye==null||Ye(At),A({type:"onDragMove",event:At})})},[ct.x,ct.y]),c.useEffect(()=>{const{active:Ye,activatorEvent:it,collisions:dt,droppableContainers:Jt,scrollAdjustedTranslate:vt}=le.current;if(!Ye||W.current==null||!it||!vt)return;const{onDragOver:At}=G.current,Xt=Jt.get(zt),en=Xt&&Xt.rect.current?{id:Xt.id,rect:Xt.rect.current,data:Xt.data,disabled:Xt.disabled}:null,st={active:Ye,activatorEvent:it,collisions:dt,delta:{x:vt.x,y:vt.y},over:en};qn.unstable_batchedUpdates(()=>{ms(en),At==null||At(st),A({type:"onDragOver",event:st})})},[zt]),Wt(()=>{le.current={activatorEvent:D,active:T,activeNode:O,collisionRect:Qe,collisions:Yt,droppableRects:J,draggableNodes:M,draggingNode:ye,draggingNodeRect:Ce,droppableContainers:_,over:It,scrollableAncestors:fe,scrollAdjustedTranslate:ct},w.current={initial:Ce,translated:Qe}},[T,O,Yt,Qe,M,ye,Ce,J,_,It,fe,ct]),Sh({...oe,delta:k,draggingRect:Qe,pointerCoordinates:Qt,scrollableAncestors:fe,scrollableAncestorRects:Ie});const _e=c.useMemo(()=>({active:T,activeNode:O,activeNodeRect:L,activatorEvent:D,collisions:Yt,containerNodeRect:ae,dragOverlay:ee,draggableNodes:M,droppableContainers:_,droppableRects:J,over:It,measureDroppableContainers:I,scrollableAncestors:fe,scrollableAncestorRects:Ie,measuringConfiguration:q,measuringScheduled:P,windowRect:de}),[T,O,L,D,Yt,ae,ee,M,_,J,It,I,fe,Ie,q,P,de]),tt=c.useMemo(()=>({activatorEvent:D,activators:je,active:T,activeNodeRect:L,ariaDescribedById:{draggable:ie},dispatch:g,draggableNodes:M,over:It,measureDroppableContainers:I}),[D,je,T,L,g,ie,M,It,I]);return be.createElement(Zl.Provider,{value:N},be.createElement(mr.Provider,{value:tt},be.createElement(pc.Provider,{value:_e},be.createElement(fa.Provider,{value:X},d)),be.createElement(Vh,{disabled:(l==null?void 0:l.restoreFocus)===!1})),be.createElement(Jx,{...l,hiddenTextDescribedById:ie}));function Dn(){const Ye=(H==null?void 0:H.autoScrollEnabled)===!1,it=typeof u=="object"?u.enabled===!1:u===!1,dt=b&&!Ye&&!it;return typeof u=="object"?{...u,enabled:dt}:{enabled:dt}}}),Yh=c.createContext(null),So="button",Jh="Draggable";function Xh(t){let{id:s,data:n,disabled:r=!1,attributes:a}=t;const i=dr(Jh),{activators:o,activatorEvent:l,active:u,activeNodeRect:d,ariaDescribedById:m,draggableNodes:x,over:p}=c.useContext(mr),{role:h=So,roleDescription:j="draggable",tabIndex:y=0}=a??{},f=(u==null?void 0:u.id)===s,g=c.useContext(f?fa:Yh),[A,N]=Fr(),[C,S]=Fr(),b=Oh(o,s),v=Zn(n);Wt(()=>(x.set(s,{id:s,key:i,node:A,activatorNode:C,data:v}),()=>{const k=x.get(s);k&&k.key===i&&x.delete(s)}),[x,s]);const M=c.useMemo(()=>({role:h,tabIndex:y,"aria-disabled":r,"aria-pressed":f&&h===So?!0:void 0,"aria-roledescription":j,"aria-describedby":m.draggable}),[r,h,y,f,j,m.draggable]);return{active:u,activatorEvent:l,activeNodeRect:d,attributes:M,isDragging:f,listeners:r?void 0:b,node:A,over:p,setNodeRef:N,setActivatorNodeRef:S,transform:g}}function fc(){return c.useContext(pc)}const Zh="Droppable",ep={timeout:25};function bc(t){let{data:s,disabled:n=!1,id:r,resizeObserverConfig:a}=t;const i=dr(Zh),{active:o,dispatch:l,over:u,measureDroppableContainers:d}=c.useContext(mr),m=c.useRef({disabled:n}),x=c.useRef(!1),p=c.useRef(null),h=c.useRef(null),{disabled:j,updateMeasurementsFor:y,timeout:f}={...ep,...a},g=Zn(y??r),A=c.useCallback(()=>{if(!x.current){x.current=!0;return}h.current!=null&&clearTimeout(h.current),h.current=setTimeout(()=>{d(Array.isArray(g.current)?g.current:[g.current]),h.current=null},f)},[f]),N=ga({callback:A,disabled:j||!o}),C=c.useCallback((M,k)=>{N&&(k&&(N.unobserve(k),x.current=!1),M&&N.observe(M))},[N]),[S,b]=Fr(C),v=Zn(s);return c.useEffect(()=>{!N||!S.current||(N.disconnect(),x.current=!1,N.observe(S.current))},[S,N]),c.useEffect(()=>(l({type:We.RegisterDroppable,element:{id:r,key:i,disabled:n,node:S,rect:p,data:v}}),()=>l({type:We.UnregisterDroppable,key:i,id:r})),[r]),c.useEffect(()=>{n!==m.current.disabled&&(l({type:We.SetDroppableDisabled,id:r,key:i,disabled:n}),m.current.disabled=n)},[r,i,n,l]),{active:o,rect:p,isOver:(u==null?void 0:u.id)===r,node:S,over:u,setNodeRef:b}}function tp(t){let{animation:s,children:n}=t;const[r,a]=c.useState(null),[i,o]=c.useState(null),l=Lr(n);return!n&&!r&&l&&a(l),Wt(()=>{if(!i)return;const u=r==null?void 0:r.key,d=r==null?void 0:r.props.id;if(u==null||d==null){a(null);return}Promise.resolve(s(d,i)).then(()=>{a(null)})},[s,r,i]),be.createElement(be.Fragment,null,n,r?c.cloneElement(r,{ref:o}):null)}const sp={x:0,y:0,scaleX:1,scaleY:1};function np(t){let{children:s}=t;return be.createElement(mr.Provider,{value:hc},be.createElement(fa.Provider,{value:sp},s))}const rp={position:"fixed",touchAction:"none"},ap=t=>pa(t)?"transform 250ms ease":void 0,ip=c.forwardRef((t,s)=>{let{as:n,activatorEvent:r,adjustScale:a,children:i,className:o,rect:l,style:u,transform:d,transition:m=ap}=t;if(!l)return null;const x=a?d:{...d,scaleX:1,scaleY:1},p={...rp,width:l.width,height:l.height,top:l.top,left:l.left,transform:ds.Transform.toString(x),transformOrigin:a&&r?Zx(r,l):void 0,transition:typeof m=="function"?m(r):m,...u};return be.createElement(n,{className:o,style:p,ref:s},i)}),op=t=>s=>{let{active:n,dragOverlay:r}=s;const a={},{styles:i,className:o}=t;if(i!=null&&i.active)for(const[l,u]of Object.entries(i.active))u!==void 0&&(a[l]=n.node.style.getPropertyValue(l),n.node.style.setProperty(l,u));if(i!=null&&i.dragOverlay)for(const[l,u]of Object.entries(i.dragOverlay))u!==void 0&&r.node.style.setProperty(l,u);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(const[u,d]of Object.entries(a))n.node.style.setProperty(u,d);o!=null&&o.active&&n.node.classList.remove(o.active)}},lp=t=>{let{transform:{initial:s,final:n}}=t;return[{transform:ds.Transform.toString(s)},{transform:ds.Transform.toString(n)}]},cp={duration:250,easing:"ease",keyframes:lp,sideEffects:op({styles:{active:{opacity:"0"}}})};function dp(t){let{config:s,draggableNodes:n,droppableContainers:r,measuringConfiguration:a}=t;return ha((i,o)=>{if(s===null)return;const l=n.get(i);if(!l)return;const u=l.node.current;if(!u)return;const d=xc(o);if(!d)return;const{transform:m}=jt(o).getComputedStyle(o),x=sc(m);if(!x)return;const p=typeof s=="function"?s:up(s);return cc(u,a.draggable.measure),p({active:{id:i,data:l.data,node:u,rect:a.draggable.measure(u)},draggableNodes:n,dragOverlay:{node:o,rect:a.dragOverlay.measure(d)},droppableContainers:r,measuringConfiguration:a,transform:x})})}function up(t){const{duration:s,easing:n,sideEffects:r,keyframes:a}={...cp,...t};return i=>{let{active:o,dragOverlay:l,transform:u,...d}=i;if(!s)return;const m={x:l.rect.left-o.rect.left,y:l.rect.top-o.rect.top},x={scaleX:u.scaleX!==1?o.rect.width*u.scaleX/l.rect.width:1,scaleY:u.scaleY!==1?o.rect.height*u.scaleY/l.rect.height:1},p={x:u.x-m.x,y:u.y-m.y,...x},h=a({...d,active:o,dragOverlay:l,transform:{initial:u,final:p}}),[j]=h,y=h[h.length-1];if(JSON.stringify(j)===JSON.stringify(y))return;const f=r==null?void 0:r({active:o,dragOverlay:l,...d}),g=l.node.animate(h,{duration:s,easing:n,fill:"forwards"});return new Promise(A=>{g.onfinish=()=>{f==null||f(),A()}})}}let Io=0;function mp(t){return c.useMemo(()=>{if(t!=null)return Io++,Io},[t])}const xp=be.memo(t=>{let{adjustScale:s=!1,children:n,dropAnimation:r,style:a,transition:i,modifiers:o,wrapperElement:l="div",className:u,zIndex:d=999}=t;const{activatorEvent:m,active:x,activeNodeRect:p,containerNodeRect:h,draggableNodes:j,droppableContainers:y,dragOverlay:f,over:g,measuringConfiguration:A,scrollableAncestors:N,scrollableAncestorRects:C,windowRect:S}=fc(),b=c.useContext(fa),v=mp(x==null?void 0:x.id),M=gc(o,{activatorEvent:m,active:x,activeNodeRect:p,containerNodeRect:h,draggingNodeRect:f.rect,over:g,overlayNodeRect:f.rect,scrollableAncestors:N,scrollableAncestorRects:C,transform:b,windowRect:S}),k=$i(p),_=dp({config:r,draggableNodes:j,droppableContainers:y,measuringConfiguration:A}),U=k?f.setRef:void 0;return be.createElement(np,null,be.createElement(tp,{animation:_},x&&v?be.createElement(ip,{key:v,id:x.id,ref:U,as:l,activatorEvent:m,adjustScale:s,className:u,transition:i,rect:k,style:{zIndex:d,...a},transform:M},n):null))});function ba(t,s,n){const r=t.slice();return r.splice(n<0?r.length+n:n,0,r.splice(s,1)[0]),r}function hp(t,s){return t.reduce((n,r,a)=>{const i=s.get(r);return i&&(n[a]=i),n},Array(t.length))}function br(t){return t!==null&&t>=0}function pp(t,s){if(t===s)return!0;if(t.length!==s.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==s[n])return!1;return!0}function gp(t){return typeof t=="boolean"?{draggable:t,droppable:t}:t}const jc=t=>{let{rects:s,activeIndex:n,overIndex:r,index:a}=t;const i=ba(s,r,n),o=s[a],l=i[a];return!l||!o?null:{x:l.left-o.left,y:l.top-o.top,scaleX:l.width/o.width,scaleY:l.height/o.height}},jr={scaleX:1,scaleY:1},Li=t=>{var s;let{activeIndex:n,activeNodeRect:r,index:a,rects:i,overIndex:o}=t;const l=(s=i[n])!=null?s:r;if(!l)return null;if(a===n){const d=i[o];return d?{x:0,y:n<o?d.top+d.height-(l.top+l.height):d.top-l.top,...jr}:null}const u=fp(i,a,n);return a>n&&a<=o?{x:0,y:-l.height-u,...jr}:a<n&&a>=o?{x:0,y:l.height+u,...jr}:{x:0,y:0,...jr}};function fp(t,s,n){const r=t[s],a=t[s-1],i=t[s+1];return r?n<s?a?r.top-(a.top+a.height):i?i.top-(r.top+r.height):0:i?i.top-(r.top+r.height):a?r.top-(a.top+a.height):0:0}const vc="Sortable",yc=be.createContext({activeIndex:-1,containerId:vc,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:jc,disabled:{draggable:!1,droppable:!1}});function Oi(t){let{children:s,id:n,items:r,strategy:a=jc,disabled:i=!1}=t;const{active:o,dragOverlay:l,droppableRects:u,over:d,measureDroppableContainers:m}=fc(),x=dr(vc,n),p=l.rect!==null,h=c.useMemo(()=>r.map(b=>typeof b=="object"&&"id"in b?b.id:b),[r]),j=o!=null,y=o?h.indexOf(o.id):-1,f=d?h.indexOf(d.id):-1,g=c.useRef(h),A=!pp(h,g.current),N=f!==-1&&y===-1||A,C=gp(i);Wt(()=>{A&&j&&m(h)},[A,h,j,m]),c.useEffect(()=>{g.current=h},[h]);const S=c.useMemo(()=>({activeIndex:y,containerId:x,disabled:C,disableTransforms:N,items:h,overIndex:f,useDragOverlay:p,sortedRects:hp(h,u),strategy:a}),[y,x,C.draggable,C.droppable,N,h,f,u,p,a]);return be.createElement(yc.Provider,{value:S},s)}const bp=t=>{let{id:s,items:n,activeIndex:r,overIndex:a}=t;return ba(n,r,a).indexOf(s)},jp=t=>{let{containerId:s,isSorting:n,wasDragging:r,index:a,items:i,newIndex:o,previousItems:l,previousContainerId:u,transition:d}=t;return!d||!r||l!==i&&a===o?!1:n?!0:o!==a&&s===u},vp={duration:200,easing:"ease"},Nc="transform",yp=ds.Transition.toString({property:Nc,duration:0,easing:"linear"}),Np={roleDescription:"sortable"};function wp(t){let{disabled:s,index:n,node:r,rect:a}=t;const[i,o]=c.useState(null),l=c.useRef(n);return Wt(()=>{if(!s&&n!==l.current&&r.current){const u=a.current;if(u){const d=_n(r.current,{ignoreTransform:!0}),m={x:u.left-d.left,y:u.top-d.top,scaleX:u.width/d.width,scaleY:u.height/d.height};(m.x||m.y)&&o(m)}}n!==l.current&&(l.current=n)},[s,n,r,a]),c.useEffect(()=>{i&&o(null)},[i]),i}function qi(t){let{animateLayoutChanges:s=jp,attributes:n,disabled:r,data:a,getNewIndex:i=bp,id:o,strategy:l,resizeObserverConfig:u,transition:d=vp}=t;const{items:m,containerId:x,activeIndex:p,disabled:h,disableTransforms:j,sortedRects:y,overIndex:f,useDragOverlay:g,strategy:A}=c.useContext(yc),N=kp(r,h),C=m.indexOf(o),S=c.useMemo(()=>({sortable:{containerId:x,index:C,items:m},...a}),[x,a,C,m]),b=c.useMemo(()=>m.slice(m.indexOf(o)),[m,o]),{rect:v,node:M,isOver:k,setNodeRef:_}=bc({id:o,data:S,disabled:N.droppable,resizeObserverConfig:{updateMeasurementsFor:b,...u}}),{active:U,activatorEvent:w,activeNodeRect:T,attributes:W,setNodeRef:H,listeners:B,isDragging:D,over:Z,setActivatorNodeRef:G,transform:ie}=Xh({id:o,data:S,attributes:{...Np,...n},disabled:N.draggable}),ce=Lx(_,H),q=!!U,J=q&&!j&&br(p)&&br(f),I=!g&&D,P=I&&J?ie:null,te=J?P??(l??A)({rects:y,activeNodeRect:T,activeIndex:p,overIndex:f,index:C}):null,oe=br(p)&&br(f)?i({id:o,items:m,activeIndex:p,overIndex:f}):C,ue=U==null?void 0:U.id,L=c.useRef({activeId:ue,items:m,newIndex:oe,containerId:x}),ae=m!==L.current.items,le=s({active:U,containerId:x,isDragging:D,isSorting:q,id:o,index:C,items:m,newIndex:L.current.newIndex,previousItems:L.current.items,previousContainerId:L.current.containerId,transition:d,wasDragging:L.current.activeId!=null}),Re=wp({disabled:!le,index:C,node:M,rect:v});return c.useEffect(()=>{q&&L.current.newIndex!==oe&&(L.current.newIndex=oe),x!==L.current.containerId&&(L.current.containerId=x),m!==L.current.items&&(L.current.items=m)},[q,oe,x,m]),c.useEffect(()=>{if(ue===L.current.activeId)return;if(ue!=null&&L.current.activeId==null){L.current.activeId=ue;return}const ye=setTimeout(()=>{L.current.activeId=ue},50);return()=>clearTimeout(ye)},[ue]),{active:U,activeIndex:p,attributes:W,data:S,rect:v,index:C,newIndex:oe,items:m,isOver:k,isSorting:q,isDragging:D,listeners:B,node:M,overIndex:f,over:Z,setNodeRef:ce,setActivatorNodeRef:G,setDroppableNodeRef:_,setDraggableNodeRef:H,transform:Re??te,transition:ee()};function ee(){if(Re||ae&&L.current.newIndex===C)return yp;if(!(I&&!pa(w)||!d)&&(q||le))return ds.Transition.toString({...d,property:Nc})}}function kp(t,s){var n,r;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t==null?void 0:t.draggable)!=null?n:s.draggable,droppable:(r=t==null?void 0:t.droppable)!=null?r:s.droppable}}ve.Down,ve.Right,ve.Up,ve.Left;const Cp={get:t=>Te.get(`/companies/${t}/sidebar-badges`)},Bi="paperclip.companyOrder";function Sp(){try{const t=localStorage.getItem(Bi);if(t)return JSON.parse(t)}catch{}return[]}function Ip(t){localStorage.setItem(Bi,JSON.stringify(t))}function Ao(t){const s=Sp();if(s.length===0)return t;const n=new Map(t.map(a=>[a.id,a])),r=[];for(const a of s){const i=n.get(a);i&&(r.push(i),n.delete(a))}for(const a of n.values())r.push(a);return r}function Ap({company:t,isSelected:s,hasLiveAgents:n,hasUnreadInbox:r,onSelect:a}){const{attributes:i,listeners:o,setNodeRef:l,transform:u,transition:d,isDragging:m}=qi({id:t.id}),x={transform:ds.Transform.toString(u),transition:d,zIndex:m?10:void 0,opacity:m?.8:1};return e.jsx("div",{ref:l,style:x,...i,...o,className:"overflow-visible",children:e.jsxs(as,{delayDuration:300,children:[e.jsx(is,{asChild:!0,children:e.jsxs("a",{href:`/${t.issuePrefix}/dashboard`,onClick:p=>{p.preventDefault(),a()},className:"relative flex items-center justify-center group overflow-visible",children:[e.jsx("div",{className:z("absolute left-[-14px] w-1 rounded-r-full bg-foreground transition-[height] duration-150",s?"h-5":"h-0 group-hover:h-2")}),e.jsxs("div",{className:z("relative overflow-visible transition-transform duration-150",m&&"scale-105"),children:[e.jsx(ml,{companyName:t.name,logoUrl:t.logoUrl,brandColor:t.brandColor,className:z(s?"rounded-[14px]":"rounded-[22px] group-hover:rounded-[14px]",m&&"shadow-lg")}),n&&e.jsx("span",{className:"pointer-events-none absolute -right-0.5 -top-0.5 z-10",children:e.jsxs("span",{className:"relative flex h-2.5 w-2.5",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-blue-400 opacity-80"}),e.jsx("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-blue-500 ring-2 ring-background"})]})}),r&&e.jsx("span",{className:"pointer-events-none absolute -bottom-0.5 -right-0.5 z-10 h-2.5 w-2.5 rounded-full bg-red-500 ring-2 ring-background"})]})]})}),e.jsx(os,{side:"right",sideOffset:8,children:e.jsx("p",{children:t.name})})]})})}function To(){const{companies:t,selectedCompanyId:s,setSelectedCompanyId:n}=he(),{openOnboarding:r}=Ve(),a=Mt(),o=bt().pathname.startsWith("/instance/"),l=o?null:s,u=c.useMemo(()=>t.filter(N=>N.status!=="archived"),[t]),d=c.useMemo(()=>u.map(N=>N.id),[u]),m=co({queries:d.map(N=>({queryKey:E.liveRuns(N),queryFn:()=>Ht.liveRunsForCompany(N),refetchInterval:1e4}))}),x=co({queries:d.map(N=>({queryKey:E.sidebarBadges(N),queryFn:()=>Cp.get(N),refetchInterval:15e3}))}),p=c.useMemo(()=>{const N=new Map;return d.forEach((C,S)=>{var b,v;N.set(C,(((v=(b=m[S])==null?void 0:b.data)==null?void 0:v.length)??0)>0)}),N},[d,m]),h=c.useMemo(()=>{const N=new Map;return d.forEach((C,S)=>{var b,v;N.set(C,(((v=(b=x[S])==null?void 0:b.data)==null?void 0:v.inbox)??0)>0)}),N},[d,x]),[j,y]=c.useState(()=>Ao(u).map(N=>N.id));c.useEffect(()=>{if(u.length===0){y([]);return}y(Ao(u).map(N=>N.id))},[u]),c.useEffect(()=>{const N=C=>{if(C.key===Bi)try{const S=C.newValue?JSON.parse(C.newValue):[];y(S)}catch{}};return window.addEventListener("storage",N),()=>window.removeEventListener("storage",N)},[]);const f=c.useMemo(()=>{const N=new Map(u.map(S=>[S.id,S])),C=[];for(const S of j){const b=N.get(S);b&&(C.push(b),N.delete(S))}for(const S of N.values())C.push(S);return C},[u,j]),g=Ri(Ei(ur,{activationConstraint:{distance:8}})),A=c.useCallback(N=>{const{active:C,over:S}=N;if(!S||C.id===S.id)return;const b=f.map(_=>_.id),v=b.indexOf(C.id),M=b.indexOf(S.id);if(v===-1||M===-1)return;const k=ba(b,v,M);y(k),Ip(k)},[f]);return e.jsxs("div",{className:"flex flex-col items-center w-[72px] shrink-0 h-full bg-background border-r border-border",children:[e.jsx("div",{className:"flex items-center justify-center h-12 w-full shrink-0",children:e.jsx($d,{className:"h-5 w-5 text-foreground"})}),e.jsx("div",{className:"flex-1 flex flex-col items-center gap-2 py-3 w-full overflow-y-auto overflow-x-hidden scrollbar-none",children:e.jsx(Fi,{sensors:g,collisionDetection:ec,onDragEnd:A,children:e.jsx(Oi,{items:f.map(N=>N.id),strategy:Li,children:f.map(N=>e.jsx(Ap,{company:N,isSelected:N.id===l,hasLiveAgents:p.get(N.id)??!1,hasUnreadInbox:h.get(N.id)??!1,onSelect:()=>{n(N.id),o&&a(Vs(`${N.issuePrefix}/${Qn==="gtm"?"workspace":"dashboard"}`))}},N.id))})})}),e.jsx("div",{className:"w-8 h-px bg-border mx-auto shrink-0"}),e.jsx("div",{className:"flex items-center justify-center py-2 shrink-0",children:e.jsxs(as,{delayDuration:300,children:[e.jsx(is,{asChild:!0,children:e.jsx("button",{onClick:()=>r(),className:"flex items-center justify-center w-11 h-11 rounded-[22px] hover:rounded-[14px] border-2 border-dashed border-border text-muted-foreground hover:border-foreground/30 hover:text-foreground transition-[border-color,color,border-radius] duration-150","aria-label":"Add company",children:e.jsx(Pe,{className:"h-5 w-5"})})}),e.jsx(os,{side:"right",sideOffset:8,children:e.jsx("p",{children:"Add company"})})]})})]})}function vr({label:t,children:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1.5 text-[10px] font-medium uppercase tracking-widest font-mono text-muted-foreground/60",children:t}),e.jsx("div",{className:"flex flex-col gap-0.5 mt-0.5",children:s})]})}function Ue({to:t,label:s,icon:n,end:r,className:a,badge:i,badgeTone:o="default",alert:l=!1,liveCount:u}){const{isMobile:d,setSidebarOpen:m}=Tn();return e.jsxs(ir,{to:t,end:r,onClick:()=>{d&&m(!1)},className:({isActive:x})=>z("flex items-center gap-2.5 px-3 py-2 text-[13px] font-medium transition-colors",x?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground",a),children:[e.jsxs("span",{className:"relative shrink-0",children:[e.jsx(n,{className:"h-4 w-4"}),l&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-red-500 shadow-[0_0_0_2px_hsl(var(--background))]"})]}),e.jsx("span",{className:"flex-1 truncate",children:s}),u!=null&&u>0&&e.jsxs("span",{className:"ml-auto flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),e.jsxs("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:[u," live"]})]}),i!=null&&i>0&&e.jsx("span",{className:z("ml-auto rounded-full px-1.5 py-0.5 text-xs leading-none",o==="danger"?"bg-red-600/90 text-red-50":"bg-primary text-primary-foreground"),children:i})]})}function wc({title:t="Paused by budget"}){return e.jsx("span",{title:t,"aria-label":t,className:"ml-auto inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-red-500/90 text-white shadow-[0_0_0_1px_rgba(255,255,255,0.08)]",children:e.jsx(ns,{className:"h-3 w-3"})})}function Tp({activeProjectRef:t,companyId:s,companyPrefix:n,isMobile:r,project:a,projectSidebarSlots:i,setSidebarOpen:o}){const{attributes:l,listeners:u,setNodeRef:d,transform:m,transition:x,isDragging:p}=qi({id:a.id}),h=xl(a);return e.jsx("div",{ref:d,style:{transform:ds.Transform.toString(m),transition:x,zIndex:p?10:void 0},className:z(p&&"opacity-80"),...l,...u,children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs(ir,{to:`/projects/${h}/issues`,onClick:()=>{r&&o(!1)},className:z("flex items-center gap-2.5 px-3 py-1.5 text-[13px] font-medium transition-colors",t===h||t===a.id?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground"),children:[e.jsx("span",{className:"shrink-0 h-3.5 w-3.5 rounded-sm",style:{backgroundColor:a.color??"#6366f1"}}),e.jsx("span",{className:"flex-1 truncate",children:a.name}),a.pauseReason==="budget"?e.jsx(wc,{title:"Project paused by budget"}):null]}),i.length>0&&e.jsx("div",{className:"ml-5 flex flex-col gap-0.5",children:i.map(j=>e.jsx(sa,{slot:j,context:{companyId:s,companyPrefix:n,projectId:a.id,projectRef:h,entityId:a.id,entityType:"project"},missingBehavior:"placeholder"},`${a.id}:${j.pluginKey}:${j.id}`))})]})})}function Pp(){var N,C;const[t,s]=c.useState(!0),{selectedCompany:n,selectedCompanyId:r}=he(),{openNewProject:a}=Ve(),{isMobile:i,setSidebarOpen:o}=Tn(),l=bt(),{data:u}=V({queryKey:E.projects.list(r),queryFn:()=>lt.list(r),enabled:!!r}),{data:d}=V({queryKey:E.auth.session,queryFn:()=>na.getSession()}),{slots:m}=xi({slotTypes:["projectSidebarItem"],entityType:"project",enabled:!!r}),x=((N=d==null?void 0:d.user)==null?void 0:N.id)??((C=d==null?void 0:d.session)==null?void 0:C.userId)??null,p=c.useMemo(()=>(u??[]).filter(S=>!S.archivedAt),[u]),{orderedProjects:h,persistOrder:j}=Fd({projects:p,companyId:r,userId:x}),y=l.pathname.match(/^\/(?:[^/]+\/)?projects\/([^/]+)/),f=(y==null?void 0:y[1])??null,g=Ri(Ei(ur,{activationConstraint:{distance:8}})),A=c.useCallback(S=>{const{active:b,over:v}=S;if(!v||b.id===v.id)return;const M=h.map(U=>U.id),k=M.indexOf(b.id),_=M.indexOf(v.id);k===-1||_===-1||j(ba(M,k,_))},[h,j]);return e.jsxs(Zr,{open:t,onOpenChange:s,children:[e.jsx("div",{className:"group",children:e.jsxs("div",{className:"flex items-center px-3 py-1.5",children:[e.jsxs(ea,{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx(Js,{className:z("h-3 w-3 text-muted-foreground/60 transition-transform opacity-0 group-hover:opacity-100",t&&"rotate-90")}),e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-widest font-mono text-muted-foreground/60",children:"Projects"})]}),e.jsx("button",{onClick:S=>{S.stopPropagation(),a()},className:"flex items-center justify-center h-4 w-4 rounded text-muted-foreground/60 hover:text-foreground hover:bg-accent/50 transition-colors","aria-label":"New project",children:e.jsx(Pe,{className:"h-3 w-3"})})]})}),e.jsx(ta,{children:e.jsx(Fi,{sensors:g,collisionDetection:ec,onDragEnd:A,children:e.jsx(Oi,{items:h.map(S=>S.id),strategy:Li,children:e.jsx("div",{className:"flex flex-col gap-0.5 mt-0.5",children:h.map(S=>e.jsx(Tp,{activeProjectRef:f,companyId:r,companyPrefix:(n==null?void 0:n.issuePrefix)??null,isMobile:i,project:S,projectSidebarSlots:m,setSidebarOpen:o},S.id))})})})})]})}function Ep(t){const s=new Map(t.map(i=>[i.id,i])),n=new Map;for(const i of t){const o=i.reportsTo&&s.has(i.reportsTo)?i.reportsTo:null,l=n.get(o)??[];l.push(i),n.set(o,l)}const r=[],a=n.get(null)??[];for(;a.length>0;){const i=a.shift();r.push(i);const o=n.get(i.id);o&&a.push(...o)}return r}function Po(){const[t,s]=c.useState(!0),{selectedCompanyId:n}=he(),{openNewAgent:r}=Ve(),{isMobile:a,setSidebarOpen:i}=Tn(),o=bt(),{data:l}=V({queryKey:E.agents.list(n),queryFn:()=>Ee.list(n),enabled:!!n}),{data:u}=V({queryKey:E.liveRuns(n),queryFn:()=>Ht.liveRunsForCompany(n),enabled:!!n,refetchInterval:1e4}),d=c.useMemo(()=>{const h=new Map;for(const j of u??[])j.status!=="running"&&j.status!=="queued"||h.set(j.agentId,(h.get(j.agentId)??0)+1);return h},[u]),m=c.useMemo(()=>{const h=(l??[]).filter(j=>j.status!=="terminated");return Ep(h)},[l]),x=o.pathname.match(/^\/(?:[^/]+\/)?agents\/([^/]+)/),p=(x==null?void 0:x[1])??null;return e.jsxs(Zr,{open:t,onOpenChange:s,children:[e.jsx("div",{className:"group",children:e.jsxs("div",{className:"flex items-center px-3 py-1.5",children:[e.jsxs(ea,{className:"flex items-center gap-1 flex-1 min-w-0",children:[e.jsx(Js,{className:z("h-3 w-3 text-muted-foreground/60 transition-transform opacity-0 group-hover:opacity-100",t&&"rotate-90")}),e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-widest font-mono text-muted-foreground/60",children:"Agents"})]}),e.jsx("button",{onClick:h=>{h.stopPropagation(),r()},className:"flex items-center justify-center h-4 w-4 rounded text-muted-foreground/60 hover:text-foreground hover:bg-accent/50 transition-colors","aria-label":"New agent",children:e.jsx(Pe,{className:"h-3 w-3"})})]})}),e.jsx(ta,{children:e.jsx("div",{className:"flex flex-col gap-0.5 mt-0.5",children:m.map(h=>{const j=d.get(h.id)??0;return e.jsxs(ir,{to:Xs(h),onClick:()=>{a&&i(!1)},className:z("flex items-center gap-2.5 px-3 py-1.5 text-[13px] font-medium transition-colors",p===Yn(h)?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50 hover:text-foreground"),children:[e.jsx(Er,{icon:h.icon,className:"shrink-0 h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:h.name}),(h.pauseReason==="budget"||j>0)&&e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 shrink-0",children:[h.pauseReason==="budget"?e.jsx(wc,{title:"Agent paused by budget"}):null,j>0?e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}):null,j>0?e.jsxs("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:[j," live"]}):null]})]},h.id)})})})]})}const ut={list:(t,s)=>Te.get(`/companies/${t}/approvals${s?`?status=${encodeURIComponent(s)}`:""}`),create:(t,s)=>Te.post(`/companies/${t}/approvals`,s),get:t=>Te.get(`/approvals/${t}`),approve:(t,s)=>Te.post(`/approvals/${t}/approve`,{decisionNote:s}),reject:(t,s)=>Te.post(`/approvals/${t}/reject`,{decisionNote:s}),requestRevision:(t,s)=>Te.post(`/approvals/${t}/request-revision`,{decisionNote:s}),resubmit:(t,s)=>Te.post(`/approvals/${t}/resubmit`,{payload:s}),listComments:t=>Te.get(`/approvals/${t}/comments`),addComment:(t,s)=>Te.post(`/approvals/${t}/comments`,{body:s}),listIssues:t=>Te.get(`/approvals/${t}/issues`)},zi={summary:t=>Te.get(`/companies/${t}/dashboard`)},Rp=100,Mp=new Set(["failed","timed_out"]),Kr=new Set(["pending","revision_requested"]),kc="paperclip:inbox:dismissed",Cc="paperclip:inbox:last-tab";function Eo(){try{const t=localStorage.getItem(kc);return t?new Set(JSON.parse(t)):new Set}catch{return new Set}}function _p(t){try{localStorage.setItem(kc,JSON.stringify([...t]))}catch{}}function Dp(){try{const t=localStorage.getItem(Cc);return t==="all"||t==="unread"||t==="recent"?t:"recent"}catch{return"recent"}}function $p(t){try{localStorage.setItem(Cc,t)}catch{}}function Sc(t){const s=[...t].sort((r,a)=>new Date(a.createdAt).getTime()-new Date(r.createdAt).getTime()),n=new Map;for(const r of s)n.has(r.agentId)||n.set(r.agentId,r);return Array.from(n.values()).filter(r=>Mp.has(r.status))}function rs(t){if(!t)return 0;const s=new Date(t).getTime();return Number.isFinite(s)?s:0}function ii(t){const s=rs(t.lastExternalCommentAt);if(s>0)return s;const n=rs(t.updatedAt),r=rs(t.myLastTouchAt);return r>0&&n<=r?0:n}function Ic(t,s){const n=ii(s)-ii(t);return n!==0?n:rs(s.updatedAt)-rs(t.updatedAt)}function Ac(t){return[...t].sort(Ic).slice(0,Rp)}function Fp(t){return t.filter(s=>s.isUnreadForMe)}function Lp(t,s,n){const r=[...t].sort((a,i)=>rs(i.updatedAt)-rs(a.updatedAt));return s==="recent"?r:s==="unread"?r.filter(a=>Kr.has(a.status)):n==="all"?r:r.filter(a=>{const i=Kr.has(a.status);return n==="actionable"?i:!i})}function Pa(t){const s=rs(t.updatedAt);return s>0?s:rs(t.createdAt)}function Op({issues:t,approvals:s,failedRuns:n=[]}){return[...t.map(r=>({kind:"issue",timestamp:ii(r),issue:r})),...s.map(r=>({kind:"approval",timestamp:Pa(r),approval:r})),...n.map(r=>({kind:"failed_run",timestamp:rs(r.createdAt),run:r}))].sort((r,a)=>{const i=a.timestamp-r.timestamp;return i!==0?i:r.kind==="issue"&&a.kind==="issue"?Ic(r.issue,a.issue):r.kind==="approval"&&a.kind==="approval"?Pa(a.approval)-Pa(r.approval):r.kind==="approval"?-1:1})}function qp({tab:t,hasItems:s,showOnRecent:n,showOnUnread:r,showOnAll:a}){return s?t==="recent"?n:t==="unread"?r:a:!1}function Bp({approvals:t,joinRequests:s,dashboard:n,heartbeatRuns:r,unreadIssues:a,dismissed:i}){const o=t.filter(y=>Kr.has(y.status)).length,l=Sc(r).filter(y=>!i.has(`run:${y.id}`)).length,u=a.length,d=(n==null?void 0:n.agents.error)??0,m=(n==null?void 0:n.costs.monthBudgetCents)??0,x=(n==null?void 0:n.costs.monthUtilizationPercent)??0,p=d>0&&l===0&&!i.has("alert:agent-errors"),h=m>0&&x>=80&&!i.has("alert:budget"),j=Number(p)+Number(h);return{inbox:o+s.length+l+u+j,approvals:o,failedRuns:l,joinRequests:s.length,unreadTouchedIssues:u,alerts:j}}const zp="backlog,todo,in_progress,in_review,blocked,done";function Tc(){const[t,s]=c.useState(Eo);return c.useEffect(()=>{const r=a=>{a.key==="paperclip:inbox:dismissed"&&s(Eo())};return window.addEventListener("storage",r),()=>window.removeEventListener("storage",r)},[]),{dismissed:t,dismiss:r=>{s(a=>{const i=new Set(a);return i.add(r),_p(i),i})}}}function Pc(t){const{dismissed:s}=Tc(),{data:n=[]}=V({queryKey:E.approvals.list(t),queryFn:()=>ut.list(t),enabled:!!t}),{data:r=[]}=V({queryKey:E.access.joinRequests(t),queryFn:async()=>{try{return await mn.listJoinRequests(t,"pending_approval")}catch(u){if(u instanceof hl&&(u.status===401||u.status===403))return[];throw u}},enabled:!!t,retry:!1}),{data:a}=V({queryKey:E.dashboard(t),queryFn:()=>zi.summary(t),enabled:!!t}),{data:i=[]}=V({queryKey:E.issues.listTouchedByMe(t),queryFn:()=>ht.list(t,{touchedByUserId:"me",status:zp}),enabled:!!t}),o=c.useMemo(()=>Fp(Ac(i)),[i]),{data:l=[]}=V({queryKey:E.heartbeats(t),queryFn:()=>Ht.list(t),enabled:!!t});return c.useMemo(()=>Bp({approvals:n,joinRequests:r,dashboard:a,heartbeatRuns:l,unreadIssues:o,dismissed:s}),[n,r,a,l,o,s])}function Ro(){const{openNewIssue:t}=Ve(),{selectedCompanyId:s,selectedCompany:n}=he(),r=Pc(s),{data:a}=V({queryKey:E.liveRuns(s),queryFn:()=>Ht.liveRunsForCompany(s),enabled:!!s,refetchInterval:1e4}),i=(a??[]).filter(u=>u.status==="running"||u.status==="queued").length;function o(){document.dispatchEvent(new KeyboardEvent("keydown",{key:"k",metaKey:!0}))}const l={companyId:s,companyPrefix:(n==null?void 0:n.issuePrefix)??null};return e.jsxs("aside",{className:"w-60 h-full min-h-0 border-r border-border bg-background flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 px-3 h-12 shrink-0",children:[(n==null?void 0:n.brandColor)&&e.jsx("div",{className:"w-4 h-4 rounded-sm shrink-0 ml-1",style:{backgroundColor:n.brandColor}}),e.jsx("span",{className:"flex-1 text-sm font-bold text-foreground truncate pl-1",children:(n==null?void 0:n.name)??"Select company"}),e.jsx(F,{variant:"ghost",size:"icon-sm",className:"text-muted-foreground shrink-0",onClick:o,children:e.jsx(gs,{className:"h-4 w-4"})})]}),e.jsxs("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide flex flex-col gap-4 px-3 py-2",children:[e.jsx("div",{className:"flex flex-col gap-0.5",children:Qn==="gtm"?e.jsxs(e.Fragment,{children:[e.jsx(Ue,{to:"/workspace",label:"Workspace",icon:_s,liveCount:i}),e.jsx(Ue,{to:"/inbox",label:"Inbox",icon:ys,badge:r.inbox,badgeTone:r.failedRuns>0?"danger":"default",alert:r.failedRuns>0})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>t(),className:"flex items-center gap-2.5 px-3 py-2 text-[13px] font-medium text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors",children:[e.jsx($r,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:"New Issue"})]}),e.jsx(Ue,{to:"/dashboard",label:"Dashboard",icon:_s,liveCount:i}),e.jsx(Ue,{to:"/inbox",label:"Inbox",icon:ys,badge:r.inbox,badgeTone:r.failedRuns>0?"danger":"default",alert:r.failedRuns>0}),e.jsx(Rr,{slotTypes:["sidebar"],context:l,className:"flex flex-col gap-0.5",itemClassName:"text-[13px] font-medium",missingBehavior:"placeholder"})]})}),Qn==="gtm"?e.jsxs(e.Fragment,{children:[e.jsxs(vr,{label:"Go To Market",children:[e.jsx(Ue,{to:"/tickets",label:"Campaigns",icon:za}),e.jsx(Ue,{to:"/issues",label:"Work Queue",icon:Ct})]}),e.jsx(Po,{}),e.jsxs(vr,{label:"Workspace",children:[e.jsx(Ue,{to:"/companies",label:"Companies",icon:ls}),e.jsx(Ue,{to:"/activity",label:"Activity",icon:kn}),e.jsx(Ue,{to:"/company/settings",label:"Settings",icon:cs})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(vr,{label:"Work",children:[e.jsx(Ue,{to:"/tickets",label:"Tickets",icon:za}),e.jsx(Ue,{to:"/issues",label:"Issues",icon:Ct}),e.jsx(Ue,{to:"/goals",label:"Goals",icon:ls})]}),e.jsx(Pp,{}),e.jsx(Po,{}),e.jsxs(vr,{label:"Company",children:[e.jsx(Ue,{to:"/org",label:"Org",icon:ti}),e.jsx(Ue,{to:"/costs",label:"Costs",icon:ns}),e.jsx(Ue,{to:"/activity",label:"Activity",icon:kn}),e.jsx(Ue,{to:"/company/settings",label:"Settings",icon:cs})]}),e.jsx(Rr,{slotTypes:["sidebarPanel"],context:l,className:"flex flex-col gap-3",itemClassName:"rounded-lg border border-border p-3",missingBehavior:"placeholder"})]})]})]})}function Mo(){const{data:t}=V({queryKey:E.plugins.all,queryFn:()=>mt.list()});return e.jsxs("aside",{className:"w-60 h-full min-h-0 border-r border-border bg-background flex flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 h-12 shrink-0",children:[e.jsx(cs,{className:"h-4 w-4 text-muted-foreground shrink-0 ml-1"}),e.jsx("span",{className:"flex-1 text-sm font-bold text-foreground truncate",children:"Instance Settings"})]}),e.jsx("nav",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto-hide flex flex-col gap-4 px-3 py-2",children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx(Ue,{to:"/instance/settings/heartbeats",label:"Heartbeats",icon:Ql,end:!0}),e.jsx(Ue,{to:"/instance/settings/experimental",label:"Experimental",icon:ma}),e.jsx(Ue,{to:"/instance/settings/plugins",label:"Plugins",icon:zn}),(t??[]).length>0?e.jsx("div",{className:"ml-4 mt-1 flex flex-col gap-0.5 border-l border-border/70 pl-3",children:(t??[]).map(s=>e.jsx(ir,{to:`/instance/settings/plugins/${s.id}`,className:({isActive:n})=>["rounded-md px-2 py-1.5 text-xs transition-colors",n?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"].join(" "),children:s.manifestJson.displayName??s.packageName},s.id))}):null]})})]})}function Kp(){const{panelContent:t,panelVisible:s,setPanelVisible:n}=ra();return t?e.jsx("aside",{className:"hidden md:flex border-l border-border bg-card flex-col shrink-0 overflow-hidden transition-[width,opacity] duration-200 ease-in-out",style:{width:s?320:0,opacity:s?1:0},children:e.jsxs("div",{className:"w-80 flex-1 flex flex-col min-w-[320px]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border",children:[e.jsx("span",{className:"text-sm font-medium",children:"Properties"}),e.jsx(F,{variant:"ghost",size:"icon-xs",onClick:()=>n(!1),children:e.jsx(St,{className:"h-4 w-4"})})]}),e.jsx(pl,{className:"flex-1",children:e.jsx("div",{className:"p-4",children:t})})]})}):null}var _o=1,Up=.9,Gp=.8,Wp=.17,Ea=.1,Ra=.999,Vp=.9999,Hp=.99,Qp=/[\\\/_+.#"@\[\(\{&]/,Yp=/[\\\/_+.#"@\[\(\{&]/g,Jp=/[\s-]/,Ec=/[\s-]/g;function oi(t,s,n,r,a,i,o){if(i===s.length)return a===t.length?_o:Hp;var l=`${a},${i}`;if(o[l]!==void 0)return o[l];for(var u=r.charAt(i),d=n.indexOf(u,a),m=0,x,p,h,j;d>=0;)x=oi(t,s,n,r,d+1,i+1,o),x>m&&(d===a?x*=_o:Qp.test(t.charAt(d-1))?(x*=Gp,h=t.slice(a,d-1).match(Yp),h&&a>0&&(x*=Math.pow(Ra,h.length))):Jp.test(t.charAt(d-1))?(x*=Up,j=t.slice(a,d-1).match(Ec),j&&a>0&&(x*=Math.pow(Ra,j.length))):(x*=Wp,a>0&&(x*=Math.pow(Ra,d-a))),t.charAt(d)!==s.charAt(i)&&(x*=Vp)),(x<Ea&&n.charAt(d-1)===r.charAt(i+1)||r.charAt(i+1)===r.charAt(i)&&n.charAt(d-1)!==r.charAt(i))&&(p=oi(t,s,n,r,d+1,i+2,o),p*Ea>x&&(x=p*Ea)),x>m&&(m=x),d=n.indexOf(u,d+1);return o[l]=m,m}function Do(t){return t.toLowerCase().replace(Ec," ")}function Xp(t,s,n){return t=n&&n.length>0?`${t+" "+n.join(" ")}`:t,oi(t,s,Do(t),Do(s),0,0,{})}var On='[cmdk-group=""]',Ma='[cmdk-group-items=""]',Zp='[cmdk-group-heading=""]',Rc='[cmdk-item=""]',$o=`${Rc}:not([aria-disabled="true"])`,li="cmdk-item-select",ln="data-value",eg=(t,s,n)=>Xp(t,s,n),Mc=c.createContext(void 0),xr=()=>c.useContext(Mc),_c=c.createContext(void 0),Ki=()=>c.useContext(_c),Dc=c.createContext(void 0),$c=c.forwardRef((t,s)=>{let n=cn(()=>{var q,J;return{search:"",value:(J=(q=t.value)!=null?q:t.defaultValue)!=null?J:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=cn(()=>new Set),a=cn(()=>new Map),i=cn(()=>new Map),o=cn(()=>new Set),l=Fc(t),{label:u,children:d,value:m,onValueChange:x,filter:p,shouldFilter:h,loop:j,disablePointerSelection:y=!1,vimBindings:f=!0,...g}=t,A=xn(),N=xn(),C=xn(),S=c.useRef(null),b=ug();Qs(()=>{if(m!==void 0){let q=m.trim();n.current.value=q,v.emit()}},[m]),Qs(()=>{b(6,T)},[]);let v=c.useMemo(()=>({subscribe:q=>(o.current.add(q),()=>o.current.delete(q)),snapshot:()=>n.current,setState:(q,J,I)=>{var P,O,te,oe;if(!Object.is(n.current[q],J)){if(n.current[q]=J,q==="search")w(),_(),b(1,U);else if(q==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let ue=document.getElementById(C);ue?ue.focus():(P=document.getElementById(A))==null||P.focus()}if(b(7,()=>{var ue;n.current.selectedItemId=(ue=W())==null?void 0:ue.id,v.emit()}),I||b(5,T),((O=l.current)==null?void 0:O.value)!==void 0){let ue=J??"";(oe=(te=l.current).onValueChange)==null||oe.call(te,ue);return}}v.emit()}},emit:()=>{o.current.forEach(q=>q())}}),[]),M=c.useMemo(()=>({value:(q,J,I)=>{var P;J!==((P=i.current.get(q))==null?void 0:P.value)&&(i.current.set(q,{value:J,keywords:I}),n.current.filtered.items.set(q,k(J,I)),b(2,()=>{_(),v.emit()}))},item:(q,J)=>(r.current.add(q),J&&(a.current.has(J)?a.current.get(J).add(q):a.current.set(J,new Set([q]))),b(3,()=>{w(),_(),n.current.value||U(),v.emit()}),()=>{i.current.delete(q),r.current.delete(q),n.current.filtered.items.delete(q);let I=W();b(4,()=>{w(),(I==null?void 0:I.getAttribute("id"))===q&&U(),v.emit()})}),group:q=>(a.current.has(q)||a.current.set(q,new Set),()=>{i.current.delete(q),a.current.delete(q)}),filter:()=>l.current.shouldFilter,label:u||t["aria-label"],getDisablePointerSelection:()=>l.current.disablePointerSelection,listId:A,inputId:C,labelId:N,listInnerRef:S}),[]);function k(q,J){var I,P;let O=(P=(I=l.current)==null?void 0:I.filter)!=null?P:eg;return q?O(q,n.current.search,J):0}function _(){if(!n.current.search||l.current.shouldFilter===!1)return;let q=n.current.filtered.items,J=[];n.current.filtered.groups.forEach(P=>{let O=a.current.get(P),te=0;O.forEach(oe=>{let ue=q.get(oe);te=Math.max(ue,te)}),J.push([P,te])});let I=S.current;H().sort((P,O)=>{var te,oe;let ue=P.getAttribute("id"),L=O.getAttribute("id");return((te=q.get(L))!=null?te:0)-((oe=q.get(ue))!=null?oe:0)}).forEach(P=>{let O=P.closest(Ma);O?O.appendChild(P.parentElement===O?P:P.closest(`${Ma} > *`)):I.appendChild(P.parentElement===I?P:P.closest(`${Ma} > *`))}),J.sort((P,O)=>O[1]-P[1]).forEach(P=>{var O;let te=(O=S.current)==null?void 0:O.querySelector(`${On}[${ln}="${encodeURIComponent(P[0])}"]`);te==null||te.parentElement.appendChild(te)})}function U(){let q=H().find(I=>I.getAttribute("aria-disabled")!=="true"),J=q==null?void 0:q.getAttribute(ln);v.setState("value",J||void 0)}function w(){var q,J,I,P;if(!n.current.search||l.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let O=0;for(let te of r.current){let oe=(J=(q=i.current.get(te))==null?void 0:q.value)!=null?J:"",ue=(P=(I=i.current.get(te))==null?void 0:I.keywords)!=null?P:[],L=k(oe,ue);n.current.filtered.items.set(te,L),L>0&&O++}for(let[te,oe]of a.current)for(let ue of oe)if(n.current.filtered.items.get(ue)>0){n.current.filtered.groups.add(te);break}n.current.filtered.count=O}function T(){var q,J,I;let P=W();P&&(((q=P.parentElement)==null?void 0:q.firstChild)===P&&((I=(J=P.closest(On))==null?void 0:J.querySelector(Zp))==null||I.scrollIntoView({block:"nearest"})),P.scrollIntoView({block:"nearest"}))}function W(){var q;return(q=S.current)==null?void 0:q.querySelector(`${Rc}[aria-selected="true"]`)}function H(){var q;return Array.from(((q=S.current)==null?void 0:q.querySelectorAll($o))||[])}function B(q){let J=H()[q];J&&v.setState("value",J.getAttribute(ln))}function D(q){var J;let I=W(),P=H(),O=P.findIndex(oe=>oe===I),te=P[O+q];(J=l.current)!=null&&J.loop&&(te=O+q<0?P[P.length-1]:O+q===P.length?P[0]:P[O+q]),te&&v.setState("value",te.getAttribute(ln))}function Z(q){let J=W(),I=J==null?void 0:J.closest(On),P;for(;I&&!P;)I=q>0?cg(I,On):dg(I,On),P=I==null?void 0:I.querySelector($o);P?v.setState("value",P.getAttribute(ln)):D(q)}let G=()=>B(H().length-1),ie=q=>{q.preventDefault(),q.metaKey?G():q.altKey?Z(1):D(1)},ce=q=>{q.preventDefault(),q.metaKey?B(0):q.altKey?Z(-1):D(-1)};return c.createElement(Bt.div,{ref:s,tabIndex:-1,...g,"cmdk-root":"",onKeyDown:q=>{var J;(J=g.onKeyDown)==null||J.call(g,q);let I=q.nativeEvent.isComposing||q.keyCode===229;if(!(q.defaultPrevented||I))switch(q.key){case"n":case"j":{f&&q.ctrlKey&&ie(q);break}case"ArrowDown":{ie(q);break}case"p":case"k":{f&&q.ctrlKey&&ce(q);break}case"ArrowUp":{ce(q);break}case"Home":{q.preventDefault(),B(0);break}case"End":{q.preventDefault(),G();break}case"Enter":{q.preventDefault();let P=W();if(P){let O=new Event(li);P.dispatchEvent(O)}}}}},c.createElement("label",{"cmdk-label":"",htmlFor:M.inputId,id:M.labelId,style:xg},u),ja(t,q=>c.createElement(_c.Provider,{value:v},c.createElement(Mc.Provider,{value:M},q))))}),tg=c.forwardRef((t,s)=>{var n,r;let a=xn(),i=c.useRef(null),o=c.useContext(Dc),l=xr(),u=Fc(t),d=(r=(n=u.current)==null?void 0:n.forceMount)!=null?r:o==null?void 0:o.forceMount;Qs(()=>{if(!d)return l.item(a,o==null?void 0:o.id)},[d]);let m=Lc(a,i,[t.value,t.children,i],t.keywords),x=Ki(),p=Ds(b=>b.value&&b.value===m.current),h=Ds(b=>d||l.filter()===!1?!0:b.search?b.filtered.items.get(a)>0:!0);c.useEffect(()=>{let b=i.current;if(!(!b||t.disabled))return b.addEventListener(li,j),()=>b.removeEventListener(li,j)},[h,t.onSelect,t.disabled]);function j(){var b,v;y(),(v=(b=u.current).onSelect)==null||v.call(b,m.current)}function y(){x.setState("value",m.current,!0)}if(!h)return null;let{disabled:f,value:g,onSelect:A,forceMount:N,keywords:C,...S}=t;return c.createElement(Bt.div,{ref:Jn(i,s),...S,id:a,"cmdk-item":"",role:"option","aria-disabled":!!f,"aria-selected":!!p,"data-disabled":!!f,"data-selected":!!p,onPointerMove:f||l.getDisablePointerSelection()?void 0:y,onClick:f?void 0:j},t.children)}),sg=c.forwardRef((t,s)=>{let{heading:n,children:r,forceMount:a,...i}=t,o=xn(),l=c.useRef(null),u=c.useRef(null),d=xn(),m=xr(),x=Ds(h=>a||m.filter()===!1?!0:h.search?h.filtered.groups.has(o):!0);Qs(()=>m.group(o),[]),Lc(o,l,[t.value,t.heading,u]);let p=c.useMemo(()=>({id:o,forceMount:a}),[a]);return c.createElement(Bt.div,{ref:Jn(l,s),...i,"cmdk-group":"",role:"presentation",hidden:x?void 0:!0},n&&c.createElement("div",{ref:u,"cmdk-group-heading":"","aria-hidden":!0,id:d},n),ja(t,h=>c.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?d:void 0},c.createElement(Dc.Provider,{value:p},h))))}),ng=c.forwardRef((t,s)=>{let{alwaysRender:n,...r}=t,a=c.useRef(null),i=Ds(o=>!o.search);return!n&&!i?null:c.createElement(Bt.div,{ref:Jn(a,s),...r,"cmdk-separator":"",role:"separator"})}),rg=c.forwardRef((t,s)=>{let{onValueChange:n,...r}=t,a=t.value!=null,i=Ki(),o=Ds(d=>d.search),l=Ds(d=>d.selectedItemId),u=xr();return c.useEffect(()=>{t.value!=null&&i.setState("search",t.value)},[t.value]),c.createElement(Bt.input,{ref:s,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":u.listId,"aria-labelledby":u.labelId,"aria-activedescendant":l,id:u.inputId,type:"text",value:a?t.value:o,onChange:d=>{a||i.setState("search",d.target.value),n==null||n(d.target.value)}})}),ag=c.forwardRef((t,s)=>{let{children:n,label:r="Suggestions",...a}=t,i=c.useRef(null),o=c.useRef(null),l=Ds(d=>d.selectedItemId),u=xr();return c.useEffect(()=>{if(o.current&&i.current){let d=o.current,m=i.current,x,p=new ResizeObserver(()=>{x=requestAnimationFrame(()=>{let h=d.offsetHeight;m.style.setProperty("--cmdk-list-height",h.toFixed(1)+"px")})});return p.observe(d),()=>{cancelAnimationFrame(x),p.unobserve(d)}}},[]),c.createElement(Bt.div,{ref:Jn(i,s),...a,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":l,"aria-label":r,id:u.listId},ja(t,d=>c.createElement("div",{ref:Jn(o,u.listInnerRef),"cmdk-list-sizer":""},d)))}),ig=c.forwardRef((t,s)=>{let{open:n,onOpenChange:r,overlayClassName:a,contentClassName:i,container:o,...l}=t;return c.createElement(Ld,{open:n,onOpenChange:r},c.createElement(Od,{container:o},c.createElement(qd,{"cmdk-overlay":"",className:a}),c.createElement(Bd,{"aria-label":t.label,"cmdk-dialog":"",className:i},c.createElement($c,{ref:s,...l}))))}),og=c.forwardRef((t,s)=>Ds(n=>n.filtered.count===0)?c.createElement(Bt.div,{ref:s,...t,"cmdk-empty":"",role:"presentation"}):null),lg=c.forwardRef((t,s)=>{let{progress:n,children:r,label:a="Loading...",...i}=t;return c.createElement(Bt.div,{ref:s,...i,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":a},ja(t,o=>c.createElement("div",{"aria-hidden":!0},o)))}),Zs=Object.assign($c,{List:ag,Item:tg,Input:rg,Group:sg,Separator:ng,Dialog:ig,Empty:og,Loading:lg});function cg(t,s){let n=t.nextElementSibling;for(;n;){if(n.matches(s))return n;n=n.nextElementSibling}}function dg(t,s){let n=t.previousElementSibling;for(;n;){if(n.matches(s))return n;n=n.previousElementSibling}}function Fc(t){let s=c.useRef(t);return Qs(()=>{s.current=t}),s}var Qs=typeof window>"u"?c.useEffect:c.useLayoutEffect;function cn(t){let s=c.useRef();return s.current===void 0&&(s.current=t()),s}function Ds(t){let s=Ki(),n=()=>t(s.snapshot());return c.useSyncExternalStore(s.subscribe,n,n)}function Lc(t,s,n,r=[]){let a=c.useRef(),i=xr();return Qs(()=>{var o;let l=(()=>{var d;for(let m of n){if(typeof m=="string")return m.trim();if(typeof m=="object"&&"current"in m)return m.current?(d=m.current.textContent)==null?void 0:d.trim():a.current}})(),u=r.map(d=>d.trim());i.value(t,l,u),(o=s.current)==null||o.setAttribute(ln,l),a.current=l}),a}var ug=()=>{let[t,s]=c.useState(),n=cn(()=>new Map);return Qs(()=>{n.current.forEach(r=>r()),n.current=new Map},[t]),(r,a)=>{n.current.set(r,a),s({})}};function mg(t){let s=t.type;return typeof s=="function"?s(t.props):"render"in s?s.render(t.props):t}function ja({asChild:t,children:s},n){return t&&c.isValidElement(s)?c.cloneElement(mg(s),{ref:s.ref},n(s.props.children)):n(s)}var xg={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};function Oc({className:t,...s}){return e.jsx(Zs,{"data-slot":"command",className:z("bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",t),...s})}function hg({title:t="Command Palette",description:s="Search for a command to run...",children:n,className:r,showCloseButton:a=!0,...i}){return e.jsxs(fs,{...i,children:[e.jsxs(hn,{className:"sr-only",children:[e.jsx(pn,{children:t}),e.jsx(Kn,{children:s})]}),e.jsxs(bs,{className:z("overflow-hidden p-0",r),showCloseButton:!1,children:[e.jsx(Oc,{className:"[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:n}),a&&e.jsxs(zd,{"data-slot":"dialog-close",className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-0 right-2 flex h-12 items-center rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(St,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function qc({className:t,...s}){return e.jsxs("div",{"data-slot":"command-input-wrapper",className:"flex h-9 items-center gap-2 border-b px-3",children:[e.jsx(gs,{className:"size-4 shrink-0 opacity-50"}),e.jsx(Zs.Input,{"data-slot":"command-input",className:z("placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",t),...s})]})}function Bc({className:t,...s}){return e.jsx(Zs.List,{"data-slot":"command-list",className:z("max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",t),...s})}function zc({...t}){return e.jsx(Zs.Empty,{"data-slot":"command-empty",className:"py-6 text-center text-sm",...t})}function zs({className:t,...s}){return e.jsx(Zs.Group,{"data-slot":"command-group",className:z("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",t),...s})}function Bn({className:t,...s}){return e.jsx(Zs.Separator,{"data-slot":"command-separator",className:z("bg-border -mx-1 h-px",t),...s})}function Je({className:t,...s}){return e.jsx(Zs.Item,{"data-slot":"command-item",className:z("data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...s})}function pg(){const[t,s]=c.useState(!1),[n,r]=c.useState(""),a=Mt(),{selectedCompanyId:i}=he(),{openNewIssue:o,openNewAgent:l}=Ve(),{isMobile:u,setSidebarOpen:d}=Tn(),m=n.trim();c.useEffect(()=>{function N(C){C.key==="k"&&(C.metaKey||C.ctrlKey)&&(C.preventDefault(),s(!0),u&&d(!1))}return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[u,d]),c.useEffect(()=>{t||r("")},[t]);const{data:x=[]}=V({queryKey:E.issues.list(i),queryFn:()=>ht.list(i),enabled:!!i&&t}),{data:p=[]}=V({queryKey:E.issues.search(i,m),queryFn:()=>ht.list(i,{q:m}),enabled:!!i&&t&&m.length>0}),{data:h=[]}=V({queryKey:E.agents.list(i),queryFn:()=>Ee.list(i),enabled:!!i&&t}),{data:j=[]}=V({queryKey:E.projects.list(i),queryFn:()=>lt.list(i),enabled:!!i&&t}),y=c.useMemo(()=>j.filter(N=>!N.archivedAt),[j]);function f(N){s(!1),a(N)}const g=N=>{var C;return N?((C=h.find(S=>S.id===N))==null?void 0:C.name)??null:null},A=c.useMemo(()=>m.length>0?p:x,[x,p,m]);return e.jsxs(hg,{open:t,onOpenChange:N=>{s(N),N&&u&&d(!1)},children:[e.jsx(qc,{placeholder:"Search issues, agents, projects...",value:n,onValueChange:r}),e.jsxs(Bc,{children:[e.jsx(zc,{children:"No results found."}),e.jsxs(zs,{heading:"Actions",children:[e.jsxs(Je,{onSelect:()=>{s(!1),o()},children:[e.jsx($r,{className:"mr-2 h-4 w-4"}),"Create new issue",e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:"C"})]}),e.jsxs(Je,{onSelect:()=>{s(!1),l()},children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"Create new agent"]}),e.jsxs(Je,{onSelect:()=>f("/projects"),children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),"Create new project"]})]}),e.jsx(Bn,{}),e.jsxs(zs,{heading:"Pages",children:[e.jsxs(Je,{onSelect:()=>f("/dashboard"),children:[e.jsx(_s,{className:"mr-2 h-4 w-4"}),"Dashboard"]}),e.jsxs(Je,{onSelect:()=>f("/inbox"),children:[e.jsx(ys,{className:"mr-2 h-4 w-4"}),"Inbox"]}),e.jsxs(Je,{onSelect:()=>f("/issues"),children:[e.jsx(Ct,{className:"mr-2 h-4 w-4"}),"Issues"]}),e.jsxs(Je,{onSelect:()=>f("/projects"),children:[e.jsx(Nn,{className:"mr-2 h-4 w-4"}),"Projects"]}),e.jsxs(Je,{onSelect:()=>f("/goals"),children:[e.jsx(ls,{className:"mr-2 h-4 w-4"}),"Goals"]}),e.jsxs(Je,{onSelect:()=>f("/agents"),children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),"Agents"]}),e.jsxs(Je,{onSelect:()=>f("/costs"),children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"Costs"]}),e.jsxs(Je,{onSelect:()=>f("/activity"),children:[e.jsx(kn,{className:"mr-2 h-4 w-4"}),"Activity"]})]}),A.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Bn,{}),e.jsx(zs,{heading:"Issues",children:A.slice(0,10).map(N=>e.jsxs(Je,{value:m.length>0?`${m} ${N.identifier??""} ${N.title}`:void 0,onSelect:()=>f(`/issues/${N.identifier??N.id}`),children:[e.jsx(Ct,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"text-muted-foreground mr-2 font-mono text-xs",children:N.identifier??N.id.slice(0,8)}),e.jsx("span",{className:"flex-1 truncate",children:N.title}),N.assigneeAgentId&&(()=>{const C=g(N.assigneeAgentId);return C?e.jsx(qe,{name:C,size:"sm",className:"ml-2 hidden sm:inline-flex"}):null})()]},N.id))})]}),h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Bn,{}),e.jsx(zs,{heading:"Agents",children:h.slice(0,10).map(N=>e.jsxs(Je,{onSelect:()=>f(Xs(N)),children:[e.jsx(qt,{className:"mr-2 h-4 w-4"}),N.name,e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:N.role})]},N.id))})]}),y.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Bn,{}),e.jsx(zs,{heading:"Projects",children:y.slice(0,10).map(N=>e.jsxs(Je,{onSelect:()=>f(hi(N)),children:[e.jsx(Nn,{className:"mr-2 h-4 w-4"}),N.name]},N.id))})]})]})]})}const gg=[{value:"backlog",label:"Backlog"},{value:"planned",label:"Planned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}];function fg(){const{newProjectOpen:t,closeNewProject:s}=Ve(),{selectedCompanyId:n,selectedCompany:r}=he(),a=Le(),[i,o]=c.useState(""),[l,u]=c.useState(""),[d,m]=c.useState("planned"),[x,p]=c.useState([]),[h,j]=c.useState(""),[y,f]=c.useState(!1),[g,A]=c.useState(""),[N,C]=c.useState(""),[S,b]=c.useState(null),[v,M]=c.useState(!1),[k,_]=c.useState(!1),U=c.useRef(null),{data:w}=V({queryKey:E.goals.list(n),queryFn:()=>Et.list(n),enabled:!!n&&t}),T=se({mutationFn:I=>lt.create(n,I)}),W=se({mutationFn:async I=>{if(!n)throw new Error("No company selected");return or.uploadImage(n,I,"projects/drafts")}});function H(){o(""),u(""),m("planned"),p([]),j(""),f(!1),A(""),C(""),b(null)}const B=I=>I.startsWith("/")||/^[A-Za-z]:[\\/]/.test(I),D=I=>{try{const P=new URL(I),O=P.hostname.toLowerCase();return O!=="github.com"&&O!=="www.github.com"?!1:P.pathname.split("/").filter(Boolean).length>=2}catch{return!1}},Z=I=>{const O=I.trim().replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean);return O[O.length-1]??"Local folder"},G=I=>{var P;try{const te=new URL(I).pathname.split("/").filter(Boolean);return(((P=te[te.length-1])==null?void 0:P.replace(/\.git$/i,""))??"")||"GitHub repo"}catch{return"GitHub repo"}};async function ie(){if(!n||!i.trim())return;const I=g.trim(),P=N.trim();if(I&&!B(I)){b("Local folder must be a full absolute path.");return}if(P&&!D(P)){b("Repo must use a valid GitHub repo URL.");return}b(null);try{const O=await T.mutateAsync({name:i.trim(),description:l.trim()||void 0,status:d,color:Ka[Math.floor(Math.random()*Ka.length)],...x.length>0?{goalIds:x}:{},...h?{targetDate:h}:{}});if(I||P){const te={name:I?Z(I):G(P),...I?{cwd:I}:{},...P?{repoUrl:P}:{}};await lt.createWorkspace(O.id,te)}a.invalidateQueries({queryKey:E.projects.list(n)}),a.invalidateQueries({queryKey:E.projects.detail(O.id)}),H(),s()}catch{}}function ce(I){I.key==="Enter"&&(I.metaKey||I.ctrlKey)&&(I.preventDefault(),ie())}const q=(w??[]).filter(I=>x.includes(I.id)),J=(w??[]).filter(I=>!x.includes(I.id));return e.jsx(fs,{open:t,onOpenChange:I=>{I||(H(),s())},children:e.jsxs(bs,{showCloseButton:!1,className:z("p-0 gap-0",y?"sm:max-w-2xl":"sm:max-w-lg"),onKeyDown:ce,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[r&&e.jsx("span",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-medium",children:r.name.slice(0,3).toUpperCase()}),e.jsx("span",{className:"text-muted-foreground/60",children:"›"}),e.jsx("span",{children:"New project"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>f(!y),children:y?e.jsx(gl,{className:"h-3.5 w-3.5"}):e.jsx(fl,{className:"h-3.5 w-3.5"})}),e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>{H(),s()},children:e.jsx("span",{className:"text-lg leading-none",children:"×"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2 shrink-0",children:e.jsx("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Project name",value:i,onChange:I=>o(I.target.value),onKeyDown:I=>{var P;I.key==="Tab"&&!I.shiftKey&&(I.preventDefault(),(P=U.current)==null||P.focus())},autoFocus:!0})}),e.jsx("div",{className:"px-4 pb-2",children:e.jsx(bl,{ref:U,value:l,onChange:u,placeholder:"Add description...",bordered:!1,contentClassName:z("text-sm text-muted-foreground",y?"min-h-[220px]":"min-h-[120px]"),imageUploadHandler:async I=>(await W.mutateAsync(I)).contentPath})}),e.jsxs("div",{className:"px-4 pt-3 pb-3 space-y-3 border-t border-border",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5",children:[e.jsx("label",{className:"block text-xs text-muted-foreground",children:"Repo URL"}),e.jsx("span",{className:"text-xs text-muted-foreground/50",children:"optional"}),e.jsxs(as,{delayDuration:300,children:[e.jsx(is,{asChild:!0,children:e.jsx(Xi,{className:"h-3 w-3 text-muted-foreground/50 cursor-help"})}),e.jsx(os,{side:"top",className:"max-w-[240px] text-xs",children:"Link a GitHub repository so agents can clone, read, and push code for this project."})]})]}),e.jsx("input",{className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs outline-none",value:N,onChange:I=>{C(I.target.value),b(null)},placeholder:"https://github.com/org/repo"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5",children:[e.jsx("label",{className:"block text-xs text-muted-foreground",children:"Local folder"}),e.jsx("span",{className:"text-xs text-muted-foreground/50",children:"optional"}),e.jsxs(as,{delayDuration:300,children:[e.jsx(is,{asChild:!0,children:e.jsx(Xi,{className:"h-3 w-3 text-muted-foreground/50 cursor-help"})}),e.jsx(os,{side:"top",className:"max-w-[240px] text-xs",children:"Set an absolute path on this machine where local agents will read and write files for this project."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",value:g,onChange:I=>{A(I.target.value),b(null)},placeholder:"/absolute/path/to/workspace"}),e.jsx(jl,{})]})]}),S&&e.jsx("p",{className:"text-xs text-destructive",children:S})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[e.jsxs(pt,{open:v,onOpenChange:M,children:[e.jsx(gt,{asChild:!0,children:e.jsx("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:e.jsx(Se,{status:d})})}),e.jsx(ft,{className:"w-40 p-1",align:"start",children:gg.map(I=>e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",I.value===d&&"bg-accent"),onClick:()=>{m(I.value),M(!1)},children:I.label},I.value))})]}),q.map(I=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs",children:[e.jsx(ls,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("span",{className:"max-w-[160px] truncate",children:I.title}),e.jsx("button",{className:"text-muted-foreground hover:text-foreground",onClick:()=>p(P=>P.filter(O=>O!==I.id)),"aria-label":`Remove goal ${I.title}`,type:"button",children:e.jsx(St,{className:"h-3 w-3"})})]},I.id)),e.jsxs(pt,{open:k,onOpenChange:_,children:[e.jsx(gt,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors disabled:opacity-60",disabled:q.length>0&&J.length===0,children:[q.length>0?e.jsx(Pe,{className:"h-3 w-3 text-muted-foreground"}):e.jsx(ls,{className:"h-3 w-3 text-muted-foreground"}),q.length>0?"+ Goal":"Goal"]})}),e.jsxs(ft,{className:"w-56 p-1",align:"start",children:[q.length===0&&e.jsx("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-muted-foreground",onClick:()=>_(!1),children:"No goal"}),J.map(I=>e.jsx("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",onClick:()=>{p(P=>[...P,I.id]),_(!1)},children:I.title},I.id)),q.length>0&&J.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"All goals already selected."})]})]}),e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs",children:[e.jsx(vl,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{type:"date",className:"bg-transparent outline-none text-xs w-24",value:h,onChange:I=>j(I.target.value),placeholder:"Target date"})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-t border-border",children:[T.isError?e.jsx("p",{className:"text-xs text-destructive",children:"Failed to create project."}):e.jsx("span",{}),e.jsx(F,{size:"sm",disabled:!i.trim()||T.isPending,onClick:ie,children:T.isPending?"Creating…":"Create project"})]})]})})}const Fo={company:"Company",team:"Team",agent:"Agent",task:"Task"};function bg(){const{newGoalOpen:t,newGoalDefaults:s,closeNewGoal:n}=Ve(),{selectedCompanyId:r,selectedCompany:a}=he(),i=Le(),[o,l]=c.useState(""),[u,d]=c.useState(""),[m,x]=c.useState("planned"),[p,h]=c.useState("task"),[j,y]=c.useState(""),[f,g]=c.useState(!1),[A,N]=c.useState(!1),[C,S]=c.useState(!1),[b,v]=c.useState(!1),M=c.useRef(null),k=j||s.parentId||"",{data:_}=V({queryKey:E.goals.list(r),queryFn:()=>Et.list(r),enabled:!!r&&t}),U=se({mutationFn:D=>Et.create(r,D),onSuccess:()=>{i.invalidateQueries({queryKey:E.goals.list(r)}),T(),n()}}),w=se({mutationFn:async D=>{if(!r)throw new Error("No company selected");return or.uploadImage(r,D,"goals/drafts")}});function T(){l(""),d(""),x("planned"),h("task"),y(""),g(!1)}function W(){!r||!o.trim()||U.mutate({title:o.trim(),description:u.trim()||void 0,status:m,level:p,...k?{parentId:k}:{}})}function H(D){D.key==="Enter"&&(D.metaKey||D.ctrlKey)&&(D.preventDefault(),W())}const B=(_??[]).find(D=>D.id===k);return e.jsx(fs,{open:t,onOpenChange:D=>{D||(T(),n())},children:e.jsxs(bs,{showCloseButton:!1,className:z("p-0 gap-0",f?"sm:max-w-2xl":"sm:max-w-lg"),onKeyDown:H,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[a&&e.jsx("span",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-medium",children:a.name.slice(0,3).toUpperCase()}),e.jsx("span",{className:"text-muted-foreground/60",children:"›"}),e.jsx("span",{children:s.parentId?"New sub-goal":"New goal"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>g(!f),children:f?e.jsx(gl,{className:"h-3.5 w-3.5"}):e.jsx(fl,{className:"h-3.5 w-3.5"})}),e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>{T(),n()},children:e.jsx("span",{className:"text-lg leading-none",children:"×"})})]})]}),e.jsx("div",{className:"px-4 pt-4 pb-2 shrink-0",children:e.jsx("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Goal title",value:o,onChange:D=>l(D.target.value),onKeyDown:D=>{var Z;D.key==="Tab"&&!D.shiftKey&&(D.preventDefault(),(Z=M.current)==null||Z.focus())},autoFocus:!0})}),e.jsx("div",{className:"px-4 pb-2",children:e.jsx(bl,{ref:M,value:u,onChange:d,placeholder:"Add description...",bordered:!1,contentClassName:z("text-sm text-muted-foreground",f?"min-h-[220px]":"min-h-[120px]"),imageUploadHandler:async D=>(await w.mutateAsync(D)).contentPath})}),e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[e.jsxs(pt,{open:A,onOpenChange:N,children:[e.jsx(gt,{asChild:!0,children:e.jsx("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:e.jsx(Se,{status:m})})}),e.jsx(ft,{className:"w-40 p-1",align:"start",children:yl.map(D=>e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 capitalize",D===m&&"bg-accent"),onClick:()=>{x(D),N(!1)},children:D},D))})]}),e.jsxs(pt,{open:C,onOpenChange:S,children:[e.jsx(gt,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:[e.jsx(Yl,{className:"h-3 w-3 text-muted-foreground"}),Fo[p]??p]})}),e.jsx(ft,{className:"w-40 p-1",align:"start",children:Nl.map(D=>e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",D===p&&"bg-accent"),onClick:()=>{h(D),S(!1)},children:Fo[D]??D},D))})]}),e.jsxs(pt,{open:b,onOpenChange:v,children:[e.jsx(gt,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",children:[e.jsx(ls,{className:"h-3 w-3 text-muted-foreground"}),B?B.title:"Parent goal"]})}),e.jsxs(ft,{className:"w-48 p-1",align:"start",children:[e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!k&&"bg-accent"),onClick:()=>{y(""),v(!1)},children:"No parent"}),(_??[]).map(D=>e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",D.id===k&&"bg-accent"),onClick:()=>{y(D.id),v(!1)},children:D.title},D.id))]})]})]}),e.jsx("div",{className:"flex items-center justify-end px-4 py-2.5 border-t border-border",children:e.jsx(F,{size:"sm",disabled:!o.trim()||U.isPending,onClick:W,children:U.isPending?"Creating…":s.parentId?"Create sub-goal":"Create goal"})})]})})}const jg=[{value:"claude_local",label:"Claude Code",icon:pi,desc:"Local Claude agent",recommended:!0},{value:"codex_local",label:"Codex",icon:Kd,desc:"Local Codex agent",recommended:!0},{value:"gemini_local",label:"Gemini CLI",icon:Ud,desc:"Local Gemini agent"},{value:"opencode_local",label:"OpenCode",icon:Gd,desc:"Local multi-provider agent"},{value:"pi_local",label:"Pi",icon:Wd,desc:"Local Pi agent"},{value:"cursor",label:"Cursor",icon:Vd,desc:"Local Cursor agent"},{value:"openclaw_gateway",label:"OpenClaw Gateway",icon:qt,desc:"Invoke OpenClaw via gateway protocol"}];function vg(){const{newAgentOpen:t,closeNewAgent:s,openNewIssue:n}=Ve(),{selectedCompanyId:r}=he(),a=Mt(),[i,o]=c.useState(!1),{data:l}=V({queryKey:E.agents.list(r),queryFn:()=>Ee.list(r),enabled:!!r&&t}),u=(l??[]).find(p=>p.role==="ceo");function d(){s(),n({assigneeAgentId:u==null?void 0:u.id,title:"Create a new agent",description:"(type in what kind of agent you want here)"})}function m(){o(!0)}function x(p){s(),o(!1),a(`/agents/new?adapterType=${encodeURIComponent(p)}`)}return e.jsx(fs,{open:t,onOpenChange:p=>{p||(o(!1),s())},children:e.jsxs(bs,{showCloseButton:!1,className:"sm:max-w-md p-0 gap-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-border",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Add a new agent"}),e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>{o(!1),s()},children:e.jsx("span",{className:"text-lg leading-none",children:"×"})})]}),e.jsx("div",{className:"p-6 space-y-6",children:i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{className:"inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>o(!1),children:[e.jsx(gi,{className:"h-3.5 w-3.5"}),"Back"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose your adapter type for advanced setup."})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:jg.map(p=>e.jsxs("button",{className:z("flex flex-col items-center gap-1.5 rounded-md border border-border p-3 text-xs transition-colors hover:bg-accent/50 relative"),onClick:()=>x(p.value),children:[p.recommended&&e.jsx("span",{className:"absolute -top-1.5 right-1.5 bg-green-500 text-white text-[9px] font-semibold px-1.5 py-0.5 rounded-full leading-none",children:"Recommended"}),e.jsx(p.icon,{className:"h-4 w-4"}),e.jsx("span",{className:"font-medium",children:p.label}),e.jsx("span",{className:"text-muted-foreground text-[10px]",children:p.desc})]},p.value))})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-accent",children:e.jsx(pi,{className:"h-6 w-6 text-foreground"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"We recommend letting your CEO handle agent setup — they know the org structure and can configure reporting, permissions, and adapters."})]}),e.jsxs(F,{className:"w-full",size:"lg",onClick:d,children:[e.jsx(qt,{className:"h-4 w-4 mr-2"}),"Ask the CEO to create a new agent"]}),e.jsx("div",{className:"text-center",children:e.jsx("button",{className:"text-xs text-muted-foreground hover:text-foreground underline underline-offset-2 transition-colors",onClick:m,children:"I want advanced configuration myself"})})]})})]})})}function yg({visible:t}){const s=bt(),{selectedCompanyId:n}=he(),{openNewIssue:r}=Ve(),a=Pc(n),i=c.useMemo(()=>Qn==="gtm"?[{type:"link",to:"/workspace",label:"Workspace",icon:mo},{type:"link",to:"/tickets",label:"Campaigns",icon:Ct},{type:"action",label:"Create",icon:$r,onClick:()=>r()},{type:"link",to:"/agents/all",label:"Agents",icon:Ua},{type:"link",to:"/inbox",label:"Inbox",icon:ys,badge:a.inbox}]:[{type:"link",to:"/dashboard",label:"Home",icon:mo},{type:"link",to:"/issues",label:"Issues",icon:Ct},{type:"action",label:"Create",icon:$r,onClick:()=>r()},{type:"link",to:"/agents/all",label:"Agents",icon:Ua},{type:"link",to:"/inbox",label:"Inbox",icon:ys,badge:a.inbox}],[r,a.inbox]);return e.jsx("nav",{className:z("fixed bottom-0 left-0 right-0 z-30 border-t border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85 transition-transform duration-200 ease-out md:hidden pb-[env(safe-area-inset-bottom)]",t?"translate-y-0":"translate-y-full"),"aria-label":"Mobile navigation",children:e.jsx("div",{className:"grid h-16 grid-cols-5 px-1",children:i.map(o=>{if(o.type==="action"){const u=o.icon,d=/\/issues\/new(?:\/|$)/.test(s.pathname);return e.jsxs("button",{type:"button",onClick:o.onClick,className:z("relative flex min-w-0 flex-col items-center justify-center gap-1 rounded-md text-[10px] font-medium transition-colors",d?"text-foreground":"text-muted-foreground hover:text-foreground"),children:[e.jsx(u,{className:"h-[18px] w-[18px]"}),e.jsx("span",{className:"truncate",children:o.label})]},o.label)}const l=o.icon;return e.jsx(ir,{to:o.to,className:({isActive:u})=>z("relative flex min-w-0 flex-col items-center justify-center gap-1 rounded-md text-[10px] font-medium transition-colors",u?"text-foreground":"text-muted-foreground hover:text-foreground"),children:({isActive:u})=>e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"relative",children:[e.jsx(l,{className:z("h-[18px] w-[18px]",u&&"stroke-[2.3]")}),o.badge!=null&&o.badge>0&&e.jsx("span",{className:"absolute -right-2 -top-2 rounded-full bg-primary px-1.5 py-0.5 text-[10px] leading-none text-primary-foreground",children:o.badge>99?"99+":o.badge})]}),e.jsx("span",{className:"truncate",children:o.label})]})},o.label)})})})}function yr(t){var r;if(typeof document>"u")return null;const s=document.querySelector(`meta[name="${t}"]`),n=(r=s==null?void 0:s.getAttribute("content"))==null?void 0:r.trim();return n||null}function ci(t){if(!t)return null;const s=t.startsWith("#")?t.slice(1):t;return/^[0-9a-fA-F]{3}$/.test(s)?`#${s.split("").map(n=>`${n}${n}`).join("").toLowerCase()}`:/^[0-9a-fA-F]{6}$/.test(s)?`#${s.toLowerCase()}`:null}function Ng(t){const s=ci(t)??"#000000";return{r:Number.parseInt(s.slice(1,3),16),g:Number.parseInt(s.slice(3,5),16),b:Number.parseInt(s.slice(5,7),16)}}function _a(t){const s=t/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4}function wg(t){const{r:s,g:n,b:r}=Ng(t),a=.2126*_a(s)+.7152*_a(n)+.0722*_a(r),i=1.05/(a+.05),o=(a+.05)/.05;return i>=o?"#f8fafc":"#111827"}function kg(){if(yr("paperclip-worktree-enabled")!=="true")return null;const t=yr("paperclip-worktree-name"),s=ci(yr("paperclip-worktree-color"));return!t||!s?null:{enabled:!0,name:t,color:s,textColor:ci(yr("paperclip-worktree-text-color"))??wg(s)}}function Cg(){const t=kg();return t?e.jsx("div",{className:"relative overflow-hidden border-b px-3 py-1.5 text-[11px] font-medium tracking-[0.2em] uppercase",style:{backgroundColor:t.color,color:t.textColor,borderColor:`${t.textColor}22`,boxShadow:`inset 0 -1px 0 ${t.textColor}18`,backgroundImage:`linear-gradient(90deg, ${t.textColor}14, transparent 28%, transparent 72%, ${t.textColor}12), repeating-linear-gradient(135deg, transparent 0 10px, ${t.textColor}08 10px 20px)`},children:e.jsxs("div",{className:"flex items-center gap-2 overflow-hidden whitespace-nowrap",children:[e.jsx("span",{className:"shrink-0 opacity-70",children:"Worktree"}),e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-current opacity-70","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-semibold tracking-[0.12em]",children:t.name})]})}):null}function Sg({onNewIssue:t,onToggleSidebar:s,onTogglePanel:n}){c.useEffect(()=>{function r(a){const i=a.target;i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable||(a.key==="c"&&!a.metaKey&&!a.ctrlKey&&!a.altKey&&(a.preventDefault(),t==null||t()),a.key==="["&&!a.metaKey&&!a.ctrlKey&&(a.preventDefault(),s==null||s()),a.key==="]"&&!a.metaKey&&!a.ctrlKey&&(a.preventDefault(),n==null||n()))}return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[t,s,n])}const Ig=new Set(["auth","invite","board-claim","docs"]);function Kc(t){const n=(t.split("?")[0]??"").split("/").filter(Boolean);if(n.length===0)return!0;const[r]=n;return!Ig.has(r)}function Ag(t){const s=Mr(t.companyPrefix);return t.companies.find(n=>Mr(n.issuePrefix)===s)??null}function Tg(t){var n;const s=Hd(t.pathname);return s?((n=Ag({companies:t.companies,companyPrefix:s}))==null?void 0:n.id)??null:t.fallbackCompanyId}function Pg(t){const s=t.path?wl(t.path):"/dashboard";if(!Kc(s))return"/dashboard";const r=(s.split("?")[0]??"").split("/").filter(Boolean),[a,i]=r;if(a==="issues"&&i){const o=/^([A-Za-z]+)-\d+$/.exec(i);if(o&&Mr(o[1]??"")!==Mr(t.companyPrefix))return"/dashboard"}return s}const Uc="paperclip.companyPaths";function Gc(){try{const t=localStorage.getItem(Uc);if(t)return JSON.parse(t)}catch{}return{}}function Eg(t,s){const n=Gc();n[t]=s,localStorage.setItem(Uc,JSON.stringify(n))}function Rg(){const{companies:t,selectedCompanyId:s,selectedCompany:n,selectionSource:r}=he(),a=bt(),i=Mt(),o=c.useRef(s),l=c.useMemo(()=>Tg({companies:t,pathname:a.pathname,fallbackCompanyId:o.current}),[t,a.pathname]),u=a.pathname+a.search;c.useEffect(()=>{const d=l,m=wl(u);d&&Kc(m)&&Eg(d,m)},[u,l]),c.useEffect(()=>{if(s){if(o.current!==null&&s!==o.current&&r!=="route_sync"&&n){const d=Gc(),m=Pg({path:d[s],companyPrefix:n.issuePrefix});i(`/${n.issuePrefix}${m}`,{replace:!0})}o.current=s}},[n,s,r,i])}function Mg(t){const{selectionSource:s,selectedCompanyId:n,routeCompanyId:r}=t;return!(n===r||s==="manual"&&n)}const Ur="/instance/settings/heartbeats";function Wc(t){if(!t)return Ur;const s=t.match(/^([^?#]*)(\?[^#]*)?(#.*)?$/),n=(s==null?void 0:s[1])??t,r=(s==null?void 0:s[2])??"",a=(s==null?void 0:s[3])??"";return n==="/instance/settings/heartbeats"||n==="/instance/settings/plugins"||n==="/instance/settings/experimental"?`${n}${r}${a}`:/^\/instance\/settings\/plugins\/[^/?#]+$/.test(n)?`${n}${r}${a}`:Ur}const Vc="paperclip.lastInstanceSettingsPath";function _g(){if(typeof window>"u")return Ur;try{return Wc(window.localStorage.getItem(Vc))}catch{return Ur}}function Lo(){const{sidebarOpen:t,setSidebarOpen:s,toggleSidebar:n,isMobile:r}=Tn(),{openNewIssue:a,openOnboarding:i}=Ve(),{togglePanelVisible:o}=ra(),{companies:l,loading:u,selectedCompany:d,selectedCompanyId:m,selectionSource:x,setSelectedCompanyId:p}=he(),{theme:h,toggleTheme:j}=Qd(),{companyPrefix:y}=$s(),f=Mt(),g=bt(),A=g.pathname.startsWith("/instance/"),N=c.useRef(!1),C=c.useRef(0),[S,b]=c.useState(!0),[v,M]=c.useState(()=>_g()),k=h==="dark"?"light":"dark",_=c.useMemo(()=>{if(!y)return null;const H=y.toUpperCase();return l.find(B=>B.issuePrefix.toUpperCase()===H)??null},[l,y]),U=!!y&&!u&&l.length>0&&!_,{data:w}=V({queryKey:E.health,queryFn:()=>Cl.get(),retry:!1});c.useEffect(()=>{u||N.current||(w==null?void 0:w.deploymentMode)!=="authenticated"&&l.length===0&&(N.current=!0,i())},[l,u,i,w==null?void 0:w.deploymentMode]),c.useEffect(()=>{if(!(!y||u||l.length===0)){if(!_){const H=(m?l.find(B=>B.id===m):null)??l[0]??null;H&&m!==H.id&&p(H.id,{source:"route_sync"});return}if(y!==_.issuePrefix){const H=g.pathname.replace(/^\/[^/]+/,"");f(`/${_.issuePrefix}${H}${g.search}`,{replace:!0});return}Mg({selectionSource:x,selectedCompanyId:m,routeCompanyId:_.id})&&p(_.id,{source:"route_sync"})}},[y,l,u,_,g.pathname,g.search,f,x,m,p]);const T=o;Rg(),Sg({onNewIssue:()=>a(),onToggleSidebar:n,onTogglePanel:T}),c.useEffect(()=>{if(!r){b(!0);return}C.current=0,b(!0)},[r]),c.useEffect(()=>{if(!r)return;const H=30,B=50,D=75;let Z=0,G=0;const ie=q=>{const J=q.touches[0];Z=J.clientX,G=J.clientY},ce=q=>{const J=q.changedTouches[0],I=J.clientX-Z;if(!(Math.abs(J.clientY-G)>D)){if(!t&&Z<H&&I>B){s(!0);return}t&&I<-B&&s(!1)}};return document.addEventListener("touchstart",ie,{passive:!0}),document.addEventListener("touchend",ce,{passive:!0}),()=>{document.removeEventListener("touchstart",ie),document.removeEventListener("touchend",ce)}},[r,t,s]);const W=c.useCallback(H=>{const B=H-C.current;H<=24?b(!0):B>8?b(!1):B<-8&&b(!0),C.current=H},[]);return c.useEffect(()=>{if(!r){b(!0),C.current=0;return}const H=()=>{W(window.scrollY||document.documentElement.scrollTop||0)};return H(),window.addEventListener("scroll",H,{passive:!0}),()=>{window.removeEventListener("scroll",H)}},[r,W]),c.useEffect(()=>{const H=document.body.style.overflow;return document.body.style.overflow=r?"visible":"hidden",()=>{document.body.style.overflow=H}},[r]),c.useEffect(()=>{if(!g.pathname.startsWith("/instance/settings/"))return;const H=Wc(`${g.pathname}${g.search}${g.hash}`);M(H);try{window.localStorage.setItem(Vc,H)}catch{}},[g.hash,g.pathname,g.search]),e.jsxs("div",{className:z("bg-background text-foreground pt-[env(safe-area-inset-top)]",r?"min-h-dvh":"flex h-dvh flex-col overflow-hidden"),children:[e.jsx("a",{href:"#main-content",className:"sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-[200] focus:rounded-md focus:bg-background focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Skip to Main Content"}),e.jsx(Cg,{}),e.jsxs("div",{className:z("min-h-0 flex-1",r?"w-full":"flex overflow-hidden"),children:[r&&t&&e.jsx("button",{type:"button",className:"fixed inset-0 z-40 bg-black/50",onClick:()=>s(!1),"aria-label":"Close sidebar"}),r?e.jsxs("div",{className:z("fixed inset-y-0 left-0 z-50 flex flex-col overflow-hidden pt-[env(safe-area-inset-top)] transition-transform duration-100 ease-out",t?"translate-x-0":"-translate-x-full"),children:[e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[e.jsx(To,{}),A?e.jsx(Mo,{}):e.jsx(Ro,{})]}),e.jsx("div",{className:"border-t border-r border-border px-3 py-2 bg-background",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("a",{href:"https://github.com/antonioromero1220/growthub-core#readme",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2.5 px-3 py-2 text-[13px] font-medium transition-colors text-foreground/80 hover:bg-accent/50 hover:text-foreground flex-1 min-w-0",children:[e.jsx(Za,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:"Documentation"})]}),(w==null?void 0:w.version)&&e.jsxs(as,{children:[e.jsx(is,{asChild:!0,children:e.jsx("span",{className:"px-2 text-xs text-muted-foreground shrink-0 cursor-default",children:"v"})}),e.jsxs(os,{children:["v",w.version]})]}),e.jsx(F,{variant:"ghost",size:"icon-sm",className:"text-muted-foreground shrink-0",asChild:!0,children:e.jsx(xe,{to:v,"aria-label":"Instance settings",title:"Instance settings",onClick:()=>{r&&s(!1)},children:e.jsx(cs,{className:"h-4 w-4"})})}),e.jsx(F,{type:"button",variant:"ghost",size:"icon-sm",className:"text-muted-foreground shrink-0",onClick:j,"aria-label":`Switch to ${k} mode`,title:`Switch to ${k} mode`,children:h==="dark"?e.jsx(Zi,{className:"h-4 w-4"}):e.jsx(eo,{className:"h-4 w-4"})})]})})]}):e.jsxs("div",{className:"flex h-full flex-col shrink-0",children:[e.jsxs("div",{className:"flex flex-1 min-h-0",children:[e.jsx(To,{}),e.jsx("div",{className:z("overflow-hidden transition-[width] duration-100 ease-out",t?"w-60":"w-0"),children:A?e.jsx(Mo,{}):e.jsx(Ro,{})})]}),e.jsx("div",{className:"border-t border-r border-border px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("a",{href:"https://github.com/antonioromero1220/growthub-core#readme",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2.5 px-3 py-2 text-[13px] font-medium transition-colors text-foreground/80 hover:bg-accent/50 hover:text-foreground flex-1 min-w-0",children:[e.jsx(Za,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:"Documentation"})]}),(w==null?void 0:w.version)&&e.jsxs(as,{children:[e.jsx(is,{asChild:!0,children:e.jsx("span",{className:"px-2 text-xs text-muted-foreground shrink-0 cursor-default",children:"v"})}),e.jsxs(os,{children:["v",w.version]})]}),e.jsx(F,{variant:"ghost",size:"icon-sm",className:"text-muted-foreground shrink-0",asChild:!0,children:e.jsx(xe,{to:v,"aria-label":"Instance settings",title:"Instance settings",onClick:()=>{r&&s(!1)},children:e.jsx(cs,{className:"h-4 w-4"})})}),e.jsx(F,{type:"button",variant:"ghost",size:"icon-sm",className:"text-muted-foreground shrink-0",onClick:j,"aria-label":`Switch to ${k} mode`,title:`Switch to ${k} mode`,children:h==="dark"?e.jsx(Zi,{className:"h-4 w-4"}):e.jsx(eo,{className:"h-4 w-4"})})]})})]}),e.jsxs("div",{className:z("flex min-w-0 flex-col",r?"w-full":"h-full flex-1"),children:[e.jsx("div",{className:z(r&&"sticky top-0 z-20 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/85"),children:e.jsx(Yd,{})}),e.jsxs("div",{className:z(r?"block":"flex flex-1 min-h-0"),children:[e.jsx("main",{id:"main-content",tabIndex:-1,className:z("flex-1 p-4 md:p-6",r?"overflow-visible pb-[calc(5rem+env(safe-area-inset-bottom))]":"overflow-auto"),children:U?e.jsx(wn,{scope:"invalid_company_prefix",requestedPrefix:y??(d==null?void 0:d.issuePrefix)}):e.jsx(kl,{})}),e.jsx(Kp,{})]})]})]}),r&&e.jsx(yg,{visible:S}),e.jsx(pg,{}),e.jsx(Jd,{}),e.jsx(fg,{}),e.jsx(bg,{}),e.jsx(vg,{}),e.jsx(Xd,{})]})}function Ps({icon:t,value:s,label:n,description:r,to:a,onClick:i}){const o=!!(a||i),l=e.jsx("div",{className:`h-full px-4 py-4 sm:px-5 sm:py-5 rounded-lg transition-colors${o?" hover:bg-accent/50 cursor-pointer":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-2xl sm:text-3xl font-semibold tracking-tight tabular-nums",children:s}),e.jsx("p",{className:"text-xs sm:text-sm font-medium text-muted-foreground mt-1",children:n}),r&&e.jsx("div",{className:"text-xs text-muted-foreground/70 mt-1.5 hidden sm:block",children:r})]}),e.jsx(t,{className:"h-4 w-4 text-muted-foreground/50 shrink-0 mt-1.5"})]})});return a?e.jsx(xe,{to:a,className:"no-underline text-inherit h-full",onClick:i,children:l}):i?e.jsx("div",{className:"h-full",onClick:i,children:l}):l}function Be({icon:t,message:s,action:n,onAction:r}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"bg-muted/50 p-4 mb-4",children:e.jsx(t,{className:"h-10 w-10 text-muted-foreground/50"})}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:s}),n&&r&&e.jsxs(F,{onClick:r,children:[e.jsx(Pe,{className:"h-4 w-4 mr-1.5"}),n]})]})}const Dg={"issue.created":"created","issue.updated":"updated","issue.checked_out":"checked out","issue.released":"released","issue.comment_added":"commented on","issue.attachment_added":"attached file to","issue.attachment_removed":"removed attachment from","issue.document_created":"created document for","issue.document_updated":"updated document on","issue.document_deleted":"deleted document from","issue.commented":"commented on","issue.deleted":"deleted","agent.created":"created","agent.updated":"updated","agent.paused":"paused","agent.resumed":"resumed","agent.terminated":"terminated","agent.key_created":"created API key for","agent.budget_updated":"updated budget for","agent.runtime_session_reset":"reset session for","heartbeat.invoked":"invoked heartbeat for","heartbeat.cancelled":"cancelled heartbeat for","approval.created":"requested approval","approval.approved":"approved","approval.rejected":"rejected","project.created":"created","project.updated":"updated","project.deleted":"deleted","goal.created":"created","goal.updated":"updated","goal.deleted":"deleted","cost.reported":"reported cost for","cost.recorded":"recorded cost for","company.created":"created company","company.updated":"updated company","company.archived":"archived","company.budget_updated":"updated budget for"};function sn(t){return typeof t!="string"?String(t??"none"):t.replace(/_/g," ")}function $g(t,s){if(t==="issue.updated"&&s){const n=s._previous??{};if(s.status!==void 0){const r=n.status;return r?`changed status from ${sn(r)} to ${sn(s.status)} on`:`changed status to ${sn(s.status)} on`}if(s.priority!==void 0){const r=n.priority;return r?`changed priority from ${sn(r)} to ${sn(s.priority)} on`:`changed priority to ${sn(s.priority)} on`}}return Dg[t]??t.replace(/[._]/g," ")}function Fg(t,s,n){switch(t){case"issue":return`/issues/${n??s}`;case"agent":return`/agents/${s}`;case"project":return`/projects/${Zd(n,s)}`;case"goal":return`/goals/${s}`;case"approval":return`/approvals/${s}`;default:return null}}function Hc({event:t,agentMap:s,entityNameMap:n,entityTitleMap:r,className:a}){var y;const i=$g(t.action,t.details),o=t.entityType==="heartbeat_run",l=o?(y=t.details)==null?void 0:y.agentId:void 0,u=o?l?n.get(`agent:${l}`):null:n.get(`${t.entityType}:${t.entityId}`),d=r==null?void 0:r.get(`${t.entityType}:${t.entityId}`),m=o&&l?`/agents/${l}/runs/${t.entityId}`:Fg(t.entityType,t.entityId,u),x=t.actorType==="agent"?s.get(t.actorId):null,p=(x==null?void 0:x.name)??(t.actorType==="system"?"System":t.actorType==="user"?"Board":t.actorId||"Unknown"),h=e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("p",{className:"flex-1 min-w-0 truncate",children:[e.jsx(qe,{name:p,size:"xs",className:"align-baseline"}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:[i," "]}),u&&e.jsx("span",{className:"font-medium",children:u}),d&&e.jsxs("span",{className:"text-muted-foreground ml-1",children:["— ",d]})]}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:Lt(t.createdAt)})]}),j=z("px-4 py-2 text-sm",m&&"cursor-pointer hover:bg-accent/50 transition-colors",a);return m?e.jsx(xe,{to:m,className:z(j,"no-underline text-inherit block"),children:h}):e.jsx("div",{className:j,children:h})}const Oo=[{dot:"bg-violet-500",text:"text-violet-500",bg:"bg-violet-500/10",border:"border-violet-500/30"},{dot:"bg-blue-500",text:"text-blue-500",bg:"bg-blue-500/10",border:"border-blue-500/30"},{dot:"bg-amber-500",text:"text-amber-500",bg:"bg-amber-500/10",border:"border-amber-500/30"},{dot:"bg-orange-500",text:"text-orange-500",bg:"bg-orange-500/10",border:"border-orange-500/30"},{dot:"bg-green-500",text:"text-green-500",bg:"bg-green-500/10",border:"border-green-500/30"},{dot:"bg-pink-500",text:"text-pink-500",bg:"bg-pink-500/10",border:"border-pink-500/30"},{dot:"bg-cyan-500",text:"text-cyan-500",bg:"bg-cyan-500/10",border:"border-cyan-500/30"}];function Lg(t){return Oo[t%Oo.length]}function Og(t){return t.charAt(0).toUpperCase()+t.slice(1)}const qo=["planning","execution","review","qa","human"];function nn({label:t,children:s,className:n}){return e.jsxs("div",{className:z("space-y-2",n),children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:t}),s]})}function qg({companyId:t,selectedPr:s,onSelect:n}){const[r,a]=c.useState(""),[i,o]=c.useState(""),[l,u]=c.useState(!1),{data:d=[]}=V({queryKey:["github-repos",t],queryFn:()=>Xn.githubRepos(t),staleTime:6e4}),{data:m=[],isFetching:x}=V({queryKey:["github-prs",t,r],queryFn:()=>Xn.githubPrs(t,r),staleTime:3e4,enabled:l&&!!r});c.useEffect(()=>{!r&&d.length>0&&a(d[0].fullName)},[r,d]);const p=m.filter(h=>!i||h.title.toLowerCase().includes(i.toLowerCase())||String(h.number).includes(i));return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:r,onChange:h=>{a(h.target.value),o(""),u(!0)},className:"flex-1 text-xs bg-background border border-border rounded-md px-2 py-1.5 outline-none text-foreground",children:[e.jsx("option",{value:"",disabled:!0,children:d.length>0?"Select repository":"No repositories available"}),d.slice(0,25).map(h=>e.jsx("option",{value:h.fullName,children:h.fullName},h.fullName))]}),e.jsxs("button",{type:"button",onClick:()=>{r&&u(h=>!h)},disabled:!r,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md border border-border hover:bg-accent transition-colors",children:[e.jsx(Ar,{className:"h-3.5 w-3.5"}),x?e.jsx(Es,{className:"h-3 w-3 animate-spin"}):"Browse PRs",e.jsx(Pn,{className:z("h-3 w-3 transition-transform",l&&"rotate-180")})]})]}),s&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-blue-500/30 bg-blue-500/5 px-3 py-2",children:[e.jsx(Ar,{className:"h-3.5 w-3.5 text-blue-500 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:s.title}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["#",s.number," · ",e.jsx(Sl,{className:"inline h-2.5 w-2.5"})," ",s.branch]})]}),e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground",onClick:h=>h.stopPropagation(),children:e.jsx(En,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>n(null),className:"text-muted-foreground hover:text-foreground",children:e.jsx(St,{className:"h-3.5 w-3.5"})})]}),l&&e.jsxs("div",{className:"rounded-lg border border-border bg-card shadow-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[e.jsx(gs,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("input",{autoFocus:!0,value:i,onChange:h=>o(h.target.value),placeholder:"Search PRs…",className:"flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground",onKeyDown:h=>h.key==="Escape"&&u(!1)}),x&&e.jsx(Es,{className:"h-3 w-3 animate-spin text-muted-foreground"})]}),e.jsx("div",{className:"max-h-52 overflow-y-auto divide-y divide-border",children:p.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:x?"Loading…":"No open PRs found"}):p.map(h=>e.jsxs("button",{type:"button",onClick:()=>{n(h),u(!1),o("")},className:z("flex items-start gap-3 w-full px-3 py-2.5 text-left hover:bg-accent/50 transition-colors",(s==null?void 0:s.number)===h.number&&"bg-blue-500/5"),children:[e.jsx(Ar,{className:z("h-3.5 w-3.5 mt-0.5 shrink-0",h.draft?"text-muted-foreground":"text-green-500")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate leading-snug",children:h.title}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:["#",h.number," · ",h.branch," · ",h.user,h.draft&&" · Draft"]})]}),(s==null?void 0:s.number)===h.number&&e.jsx(Ns,{className:"h-3.5 w-3.5 text-blue-500 shrink-0 mt-0.5"})]},h.number))})]})]})}function Qc({open:t,onClose:s,companyId:n,onSuccess:r}){const a=Le(),i=c.useRef(null),[o,l]=c.useState(""),[u,d]=c.useState(""),[m,x]=c.useState(""),[p,h]=c.useState([...qo]),[j,y]=c.useState(""),[f,g]=c.useState(!1),[A,N]=c.useState(""),[C,S]=c.useState(null),b=Qn==="gtm";c.useEffect(()=>{t&&(l(""),d(""),x(""),h([...qo]),N(""),S(null),y(""),g(!1),setTimeout(()=>{var W;return(W=i.current)==null?void 0:W.focus()},80))},[t]);const{data:v=[]}=V({queryKey:E.agents.list(n),queryFn:()=>Ee.list(n),enabled:t}),{mutate:M,isPending:k}=se({mutationFn:()=>Xn.create(n,{title:o.trim(),description:u.trim()||void 0,stageOrder:p,instructions:m.trim()||void 0,leadAgentId:A||void 0,metadata:C?{linkedPr:{number:C.number,title:C.title,url:C.url,branch:C.branch,repo:C.repo}}:void 0}),onSuccess:W=>{a.invalidateQueries({queryKey:E.tickets.list(n)}),r==null||r(W.id),s()}});function _(){const W=j.trim().toLowerCase().replace(/\s+/g,"_");!W||p.includes(W)||(h(H=>[...H,W]),y(""),g(!1))}function U(W){p.length<=1||h(H=>H.filter(B=>B!==W))}const w={active:"bg-green-500",running:"bg-cyan-500",paused:"bg-amber-500",error:"bg-red-500"},T=v.find(W=>W.id===A);return e.jsx(fs,{open:t,onOpenChange:W=>{W||s()},children:e.jsxs(bs,{showCloseButton:!0,className:"max-h-[90vh] overflow-y-auto p-0 gap-0",style:{width:"75vw",maxWidth:"75vw"},children:[e.jsxs(hn,{className:"px-6 pt-6 pb-4 border-b border-border",children:[e.jsxs(pn,{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(Ga,{className:"h-4 w-4 text-primary"}),b?"New Workflow Ticket":"New Ticket"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:b?"Define scope, assign agents, and configure the workflow.":"Define scope, bind a PR, assign agents, and configure the pipeline."})]}),e.jsxs("div",{className:"px-6 py-5 space-y-6",children:[e.jsx(nn,{label:"Title",children:e.jsx("input",{ref:i,value:o,onChange:W=>l(W.target.value),placeholder:"e.g. Winning Ads Image Mutation — GH MAX Mode",className:"w-full bg-background border border-border rounded-lg px-3 py-2.5 text-sm font-medium outline-none focus:border-primary/60 transition-colors placeholder:text-muted-foreground/50",onKeyDown:W=>W.key==="Enter"&&W.preventDefault()})}),e.jsx(nn,{label:"Scope & Description",children:e.jsx("textarea",{value:u,onChange:W=>d(W.target.value),rows:3,placeholder:"Describe what needs to be built, the problem being solved, and any constraints…",className:"w-full bg-background border border-border rounded-lg px-3 py-2.5 text-sm outline-none focus:border-primary/60 transition-colors resize-none placeholder:text-muted-foreground/50"})}),b?null:e.jsxs(nn,{label:"Linked GitHub PR",children:[e.jsx(qg,{companyId:n,selectedPr:C,onSelect:S}),!C&&e.jsx("p",{className:"text-[11px] text-muted-foreground/60",children:"Bind an open PR from your repos to give agents direct context on the active branch."})]}),e.jsx(nn,{label:"Pipeline Stages",children:e.jsxs("div",{className:"flex items-center flex-wrap gap-1.5",children:[p.map((W,H)=>{const B=Lg(H);return e.jsxs("span",{className:z("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full border text-xs font-medium",B.bg,B.border,B.text),children:[e.jsx("span",{className:z("h-1.5 w-1.5 rounded-full shrink-0",B.dot)}),Og(W),p.length>1&&e.jsx("button",{type:"button",onClick:()=>U(W),className:"opacity-60 hover:opacity-100 transition-opacity",children:e.jsx(St,{className:"h-2.5 w-2.5"})})]},W)}),f?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("input",{autoFocus:!0,value:j,onChange:W=>y(W.target.value),placeholder:"stage",onKeyDown:W=>{W.key==="Enter"&&(W.preventDefault(),_()),W.key==="Escape"&&g(!1)},className:"text-xs bg-background border border-border rounded-full px-2.5 py-1 outline-none w-24"}),e.jsx("button",{type:"button",onClick:_,className:"text-xs text-foreground/60 hover:text-foreground px-1",children:"+"}),e.jsx("button",{type:"button",onClick:()=>g(!1),children:e.jsx(St,{className:"h-3 w-3 text-muted-foreground"})})]}):e.jsxs("button",{type:"button",onClick:()=>g(!0),className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-full border border-dashed border-border text-xs text-muted-foreground hover:text-foreground hover:border-border/80 transition-colors",children:[e.jsx(Pe,{className:"h-3 w-3"})," Add stage"]})]})}),e.jsxs(nn,{label:"Lead Agent",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-48 overflow-y-auto",children:v.map(W=>e.jsxs("button",{type:"button",onClick:()=>N(H=>H===W.id?"":W.id),className:z("flex items-center gap-2.5 px-3 py-2.5 rounded-lg border text-left transition-all",A===W.id?"border-primary/60 bg-primary/5":"border-border hover:border-border/80 hover:bg-accent/40"),children:[e.jsx("span",{className:z("h-2 w-2 rounded-full shrink-0",w[W.status]??"bg-border")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:W.name}),e.jsx("p",{className:"text-[11px] text-muted-foreground truncate",children:W.role})]}),A===W.id&&e.jsx(Ns,{className:"h-3.5 w-3.5 text-primary shrink-0"})]},W.id))}),v.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground/60",children:"No agents configured yet."})]}),e.jsx(nn,{label:"Agent Instructions",children:e.jsx("textarea",{value:m,onChange:W=>x(W.target.value),rows:3,placeholder:`Specific instructions for agents working this ticket…
196
+ e.g. "Follow the videoMutation pipeline pattern. Do not modify stable registry files. Use the brand kit ref images."`,className:"w-full bg-background border border-border rounded-lg px-3 py-2.5 text-sm outline-none focus:border-primary/60 transition-colors resize-none placeholder:text-muted-foreground/50 font-mono text-[13px]"})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-border flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground min-w-0",children:[C&&e.jsxs("span",{className:"flex items-center gap-1 text-blue-500",children:[e.jsx(Ar,{className:"h-3 w-3"})," PR #",C.number]}),T&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(qt,{className:"h-3 w-3"})," ",T.name]}),e.jsxs("span",{className:"flex items-center gap-1",children:[p.length," stage",p.length!==1?"s":""]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{variant:"outline",size:"sm",onClick:s,disabled:k,children:"Cancel"}),e.jsx(F,{size:"sm",onClick:()=>M(),disabled:!o.trim()||k,className:"gap-1.5",children:k?e.jsxs(e.Fragment,{children:[e.jsx(Es,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(aa,{className:"h-3.5 w-3.5"}),"Create Ticket"]})})]})]})]})})}function va(t){return t.charAt(0).toUpperCase()+t.slice(1)}function Bg(t){const s=new Set,n=[];for(const r of t)for(const a of r.stageOrder)s.has(a)||(s.add(a),n.push(a));for(const r of t)s.has(r.currentStage)||(s.add(r.currentStage),n.push(r.currentStage));return n}function zg({ticket:t}){const s=t.stageOrder.indexOf(t.currentStage),n=t.stageOrder.length>1?Math.round(s/(t.stageOrder.length-1)*100):0;return e.jsxs(xe,{to:`/tickets/${t.id}`,className:"block rounded-lg border border-border bg-card p-3 hover:border-primary/30 hover:shadow-sm transition-all no-underline text-inherit group",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsx("p",{className:"text-sm font-medium leading-snug line-clamp-2 flex-1",children:t.title}),e.jsx(aa,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0 mt-0.5 opacity-0 group-hover:opacity-100 transition-opacity"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsx("span",{className:"text-xs font-mono text-muted-foreground",children:t.identifier}),e.jsx("span",{className:"text-[10px] text-muted-foreground border border-border rounded px-1.5 py-0.5 shrink-0",children:va(t.currentStage)})]}),t.stageOrder.length>1&&e.jsxs("div",{className:"flex items-center gap-0.5 mb-2",children:[t.stageOrder.map((r,a)=>e.jsxs("div",{className:"flex items-center gap-0.5",children:[a>0&&e.jsx("div",{className:z("h-px w-2",a<=s?"bg-primary/40":"bg-border")}),e.jsx("div",{className:z("h-1.5 w-1.5 rounded-full transition-colors",a<s&&"bg-primary/50",a===s&&"bg-primary",a>s&&"bg-border")})]},r)),e.jsxs("span",{className:"text-[10px] text-muted-foreground ml-1.5",children:[s+1,"/",t.stageOrder.length]})]}),t.stageOrder.length>1&&e.jsx("div",{className:"h-1 rounded-full bg-border overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary/40 transition-all",style:{width:`${n}%`}})})]})}function Kg({tickets:t,stageOrder:s}){const n=c.useMemo(()=>{const r=new Map;for(const a of s)r.set(a,[]);for(const a of t){const i=r.get(a.currentStage)??[];i.push(a),r.set(a.currentStage,i)}return r},[t,s]);return s.length===0?e.jsx("div",{className:"flex items-center justify-center h-32 border border-dashed border-border rounded-lg",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No active tickets. ",e.jsx(xe,{to:"/tickets",className:"underline",children:"Create one"})]})}):e.jsx("div",{className:"overflow-x-auto pb-2",children:e.jsx("div",{className:"flex gap-3 min-w-max",children:s.map(r=>{const a=n.get(r)??[];return e.jsxs("div",{className:"w-64 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:va(r)}),e.jsx("span",{className:"text-xs text-muted-foreground ml-auto",children:a.length})]}),e.jsx("div",{className:"space-y-2",children:a.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-3 text-center",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Empty"})}):a.map(i=>e.jsx(zg,{ticket:i,stageOrder:s},i.id))})]},r)})})})}function Ug({tickets:t,stageOrder:s}){if(t.length===0)return e.jsx("div",{className:"flex items-center justify-center h-24 border border-dashed border-border rounded-lg",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No active tickets. ",e.jsx(xe,{to:"/tickets",className:"underline",children:"Create one"})]})});const n=[...t].sort((r,a)=>new Date(a.updatedAt).getTime()-new Date(r.updatedAt).getTime());return e.jsx("div",{className:"border border-border divide-y divide-border overflow-hidden rounded-lg",children:n.map(r=>{const a=r.stageOrder.indexOf(r.currentStage),i=r.stageOrder.length>1?a+1:1;return e.jsxs(xe,{to:`/tickets/${r.id}`,className:"flex items-center gap-3 px-4 py-3 text-sm hover:bg-accent/50 transition-colors no-underline text-inherit",children:[e.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:r.stageOrder.map((o,l)=>e.jsxs("div",{className:"flex items-center gap-0.5",children:[l>0&&e.jsx("div",{className:z("h-px w-2",l<=a?"bg-primary/40":"bg-border")}),e.jsx("div",{className:z("h-1.5 w-1.5 rounded-full",l<a&&"bg-primary/50",l===a&&"bg-primary",l>a&&"bg-border")})]},o))}),e.jsx("span",{className:"flex-1 truncate font-medium",children:r.title}),e.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:[i,"/",r.stageOrder.length," stages"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground border border-border rounded px-1.5 py-0.5 shrink-0",children:va(r.currentStage)}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:Lt(r.updatedAt)}),e.jsx("span",{className:"text-xs font-mono text-muted-foreground shrink-0",children:r.identifier}),e.jsx(aa,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"})]},r.id)})})}function Gg({tickets:t,stageOrder:s}){const[n,r]=c.useState("week"),a=new Date;function i(){const l=new Date(a);l.setDate(a.getDate()-a.getDay());const u=Array.from({length:7},(h,j)=>{const y=new Date(l);return y.setDate(l.getDate()+j),y}),d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],m=h=>h.toISOString().slice(0,10),x=m(a),p=new Map;for(const h of u)p.set(m(h),[]);for(const h of t){const j=m(new Date(h.updatedAt));p.has(j)&&p.get(j).push(h)}return e.jsx("div",{className:"grid grid-cols-7 gap-1.5",children:u.map(h=>{const j=m(h),y=j===x,f=p.get(j)??[];return e.jsxs("div",{className:"min-h-[120px]",children:[e.jsxs("div",{className:z("text-center py-1.5 mb-2 rounded text-xs font-medium",y?"bg-primary/10 text-primary":"text-muted-foreground"),children:[e.jsx("div",{children:d[h.getDay()]}),e.jsx("div",{className:z("font-semibold tabular-nums",y&&"text-primary"),children:h.getDate()})]}),e.jsx("div",{className:"space-y-1",children:f.map(g=>e.jsxs(xe,{to:`/tickets/${g.id}`,className:"block rounded border border-border bg-card px-2 py-1.5 hover:border-primary/30 transition-colors no-underline text-inherit",children:[e.jsx("p",{className:"text-[11px] font-medium truncate leading-snug",children:g.title}),e.jsx("span",{className:"text-[10px] text-muted-foreground truncate",children:va(g.currentStage)})]},g.id))})]},j)})})}function o(){var N;const l=a.getFullYear(),u=a.getMonth(),d=new Date(l,u,1),m=new Date(l,u+1,0),x=d.getDay(),p=m.getDate(),h=C=>C.toISOString().slice(0,10),j=h(a),y=["January","February","March","April","May","June","July","August","September","October","November","December"],f=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],g=new Map;for(let C=1;C<=p;C++)g.set(C,[]);for(const C of t){const S=new Date(C.updatedAt);S.getFullYear()===l&&S.getMonth()===u&&((N=g.get(S.getDate()))==null||N.push(C))}const A=[...Array(x).fill(null),...Array.from({length:p},(C,S)=>S+1)];for(;A.length%7!==0;)A.push(null);return e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold text-muted-foreground mb-3",children:[y[u]," ",l]}),e.jsxs("div",{className:"grid grid-cols-7 gap-px bg-border rounded-lg overflow-hidden border border-border",children:[f.map(C=>e.jsx("div",{className:"bg-background text-center text-[10px] font-medium text-muted-foreground py-1.5",children:C},C)),A.map((C,S)=>{if(!C)return e.jsx("div",{className:"bg-background h-20"},`pad-${S}`);const b=new Date(l,u,C),M=h(b)===j,k=g.get(C)??[];return e.jsxs("div",{className:z("bg-background h-20 p-1 overflow-hidden",M&&"bg-primary/5"),children:[e.jsx("span",{className:z("inline-flex h-5 w-5 items-center justify-center rounded-full text-[11px] font-medium mb-0.5",M?"bg-primary text-primary-foreground":"text-muted-foreground"),children:C}),e.jsxs("div",{className:"space-y-0.5",children:[k.slice(0,2).map(_=>e.jsx(xe,{to:`/tickets/${_.id}`,className:"block rounded px-1 py-0.5 text-[10px] truncate font-medium no-underline border border-border bg-card text-foreground hover:border-primary/30 transition-colors",children:_.title},_.id)),k.length>2&&e.jsxs("span",{className:"text-[9px] text-muted-foreground pl-1",children:["+",k.length-2," more"]})]})]},C)})]})]})}return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-1 border border-border rounded-md overflow-hidden w-fit",children:["week","month"].map(l=>e.jsx("button",{onClick:()=>r(l),className:z("px-3 py-1.5 text-xs transition-colors capitalize",n===l?"bg-accent text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-accent/50"),children:l},l))}),n==="week"?e.jsx(i,{}):e.jsx(o,{})]})}function Wg({companyId:t}){const[s,n]=c.useState("kanban"),[r,a]=c.useState(!1),{data:i,isLoading:o}=V({queryKey:E.tickets.list(t),queryFn:()=>Xn.list(t),refetchInterval:5e3,staleTime:0}),l=c.useMemo(()=>(i??[]).filter(m=>m.status==="active"),[i]),u=c.useMemo(()=>Bg(l),[l]),d=[{id:"kanban",label:"Kanban",icon:mx},{id:"list",label:"List",icon:Ii},{id:"roadmap",label:"Roadmap",icon:Wm}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Tickets"}),i!==void 0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[l.length," active",i.length-l.length>0&&` · ${i.length-l.length} closed`]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"flex items-center border border-border rounded-md overflow-hidden",children:d.map(m=>{const x=m.icon;return e.jsxs("button",{onClick:()=>n(m.id),className:z("flex items-center gap-1.5 px-2.5 py-1.5 text-xs transition-colors",s===m.id?"bg-accent text-foreground font-medium":"text-muted-foreground hover:text-foreground hover:bg-accent/50"),title:m.label,children:[e.jsx(x,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:m.label})]},m.id)})}),e.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex items-center gap-1 px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground border border-border rounded-md hover:bg-accent/50 transition-colors",children:[e.jsx(Pe,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"New Ticket"})]})]})]}),o?e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[1,2,3].map(m=>e.jsx("div",{className:"h-32 rounded-lg bg-accent/30 animate-pulse"},m))}):e.jsxs(e.Fragment,{children:[s==="kanban"&&e.jsx(Kg,{tickets:l,stageOrder:u}),s==="list"&&e.jsx(Ug,{tickets:l,stageOrder:u}),s==="roadmap"&&e.jsx(Gg,{tickets:i??[],stageOrder:u})]}),e.jsx(Qc,{open:r,onClose:()=>a(!1),companyId:t})]})}function Vg(t){return[...t].sort((s,n)=>new Date(n.updatedAt).getTime()-new Date(s.updatedAt).getTime())}function Hg(){const{selectedCompanyId:t,companies:s}=he(),{openOnboarding:n}=Ve(),{setBreadcrumbs:r}=Me(),[a,i]=c.useState(new Set),o=c.useRef(new Set),l=c.useRef(!1),u=c.useRef([]),{data:d}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t});c.useEffect(()=>{r([{label:"Dashboard"}])},[r]);const{data:m}=V({queryKey:E.dashboard(t),queryFn:()=>zi.summary(t),enabled:!!t,retry:!1,staleTime:3e4}),{data:x}=V({queryKey:E.activity(t),queryFn:()=>Al.list(t),enabled:!!t}),{data:p}=V({queryKey:E.issues.list(t),queryFn:()=>ht.list(t),enabled:!!t}),{data:h}=V({queryKey:E.projects.list(t),queryFn:()=>lt.list(t),enabled:!!t}),{data:j}=V({queryKey:E.heartbeats(t),queryFn:()=>Ht.list(t),enabled:!!t}),y=p?Vg(p):[],f=c.useMemo(()=>(x??[]).slice(0,10),[x]);c.useEffect(()=>{for(const b of u.current)window.clearTimeout(b);u.current=[],o.current=new Set,l.current=!1,i(new Set)},[t]),c.useEffect(()=>{if(f.length===0)return;const b=o.current,v=f.map(_=>_.id);if(!l.current){for(const _ of v)b.add(_);l.current=!0;return}const M=v.filter(_=>!b.has(_));if(M.length===0){for(const _ of v)b.add(_);return}i(_=>{const U=new Set(_);for(const w of M)U.add(w);return U});for(const _ of M)b.add(_);const k=window.setTimeout(()=>{i(_=>{const U=new Set(_);for(const w of M)U.delete(w);return U}),u.current=u.current.filter(_=>_!==k)},980);u.current.push(k)},[f]),c.useEffect(()=>()=>{for(const b of u.current)window.clearTimeout(b)},[]);const g=c.useMemo(()=>{const b=new Map;for(const v of d??[])b.set(v.id,v);return b},[d]),A=c.useMemo(()=>{const b=new Map;for(const v of p??[])b.set(`issue:${v.id}`,v.identifier??v.id.slice(0,8));for(const v of d??[])b.set(`agent:${v.id}`,v.name);for(const v of h??[])b.set(`project:${v.id}`,v.name);return b},[p,d,h]),N=c.useMemo(()=>{const b=new Map;for(const v of p??[])b.set(`issue:${v.id}`,v.title);return b},[p]),C=b=>{var v;return!b||!d?null:((v=d.find(M=>M.id===b))==null?void 0:v.name)??null};if(!t)return s.length===0?e.jsx(Be,{icon:_s,message:"Welcome to Growthub. Set up your first company and agent to get started.",action:"Get Started",onAction:n}):e.jsx(Be,{icon:_s,message:"Create or select a company to view the dashboard."});const S=d!==void 0&&d.length===0;return e.jsxs("div",{className:"space-y-6",children:[S&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-amber-300 bg-amber-50 px-4 py-3 dark:border-amber-500/25 dark:bg-amber-950/60",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(qt,{className:"h-4 w-4 text-amber-600 dark:text-amber-400 shrink-0"}),e.jsx("p",{className:"text-sm text-amber-900 dark:text-amber-100",children:"You have no agents."})]}),e.jsx("button",{onClick:()=>n({initialStep:2,companyId:t}),className:"text-sm font-medium text-amber-700 hover:text-amber-900 dark:text-amber-300 dark:hover:text-amber-100 underline underline-offset-2 shrink-0",children:"Create one here"})]}),e.jsx(Wg,{companyId:t}),m&&e.jsxs(e.Fragment,{children:[m.budgets.activeIncidents>0?e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-xl border border-red-500/20 bg-[linear-gradient(180deg,rgba(255,80,80,0.12),rgba(255,255,255,0.02))] px-4 py-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(Il,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-300"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-red-50",children:[m.budgets.activeIncidents," active budget incident",m.budgets.activeIncidents===1?"":"s"]}),e.jsxs("p",{className:"text-xs text-red-100/70",children:[m.budgets.pausedAgents," agents paused · ",m.budgets.pausedProjects," projects paused · ",m.budgets.pendingApprovals," pending budget approvals"]})]})]}),e.jsx(xe,{to:"/costs",className:"text-sm underline underline-offset-2 text-red-100",children:"Open budgets"})]}):null,e.jsxs("div",{className:"grid grid-cols-2 xl:grid-cols-4 gap-1 sm:gap-2",children:[e.jsx(Ps,{icon:qt,value:m.agents.active+m.agents.running+m.agents.paused+m.agents.error,label:"Agents Enabled",to:"/agents",description:e.jsxs("span",{children:[m.agents.running," running",", ",m.agents.paused," paused",", ",m.agents.error," errors"]})}),e.jsx(Ps,{icon:Ct,value:m.tasks.inProgress,label:"Tasks In Progress",to:"/issues",description:e.jsxs("span",{children:[m.tasks.open," open",", ",m.tasks.blocked," blocked"]})}),e.jsx(Ps,{icon:ns,value:re(m.costs.monthSpendCents),label:"Month Spend",to:"/costs",description:e.jsx("span",{children:m.costs.monthBudgetCents>0?`${m.costs.monthUtilizationPercent}% of ${re(m.costs.monthBudgetCents)} budget`:"Unlimited budget"})}),e.jsx(Ps,{icon:Ai,value:m.pendingApprovals+m.budgets.pendingApprovals,label:"Pending Approvals",to:"/approvals",description:e.jsx("span",{children:m.budgets.pendingApprovals>0?`${m.budgets.pendingApprovals} budget overrides awaiting board review`:"Awaiting board review"})})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(pr,{title:"Run Activity",subtitle:"Last 14 days",children:e.jsx(eu,{runs:j??[]})}),e.jsx(pr,{title:"Issues by Priority",subtitle:"Last 14 days",children:e.jsx(tu,{issues:p??[]})}),e.jsx(pr,{title:"Issues by Status",subtitle:"Last 14 days",children:e.jsx(su,{issues:p??[]})}),e.jsx(pr,{title:"Success Rate",subtitle:"Last 14 days",children:e.jsx(nu,{runs:j??[]})})]}),e.jsx(Rr,{slotTypes:["dashboardWidget"],context:{companyId:t},className:"grid gap-4 md:grid-cols-2",itemClassName:"rounded-lg border bg-card p-4 shadow-sm"}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[f.length>0&&e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3",children:"Recent Activity"}),e.jsx("div",{className:"border border-border divide-y divide-border overflow-hidden",children:f.map(b=>e.jsx(Hc,{event:b,agentMap:g,entityNameMap:A,entityTitleMap:N,className:a.has(b.id)?"activity-row-enter":void 0},b.id))})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3",children:"Recent Tasks"}),y.length===0?e.jsx("div",{className:"border border-border p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"No tasks yet."})}):e.jsx("div",{className:"border border-border divide-y divide-border overflow-hidden",children:y.slice(0,10).map(b=>e.jsx(xe,{to:`/issues/${b.identifier??b.id}`,className:"px-4 py-3 text-sm cursor-pointer hover:bg-accent/50 transition-colors no-underline text-inherit block",children:e.jsxs("div",{className:"flex items-start gap-2 sm:items-center sm:gap-3",children:[e.jsx("span",{className:"shrink-0 sm:hidden",children:e.jsx(wt,{status:b.status})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[e.jsx("span",{className:"line-clamp-2 text-sm sm:order-2 sm:flex-1 sm:min-w-0 sm:line-clamp-none sm:truncate",children:b.title}),e.jsxs("span",{className:"flex items-center gap-2 sm:order-1 sm:shrink-0",children:[e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(Nt,{priority:b.priority})}),e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(wt,{status:b.status})}),e.jsx("span",{className:"text-xs font-mono text-muted-foreground",children:b.identifier??b.id.slice(0,8)}),b.assigneeAgentId&&(()=>{const v=C(b.assigneeAgentId);return v?e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(qe,{name:v,size:"sm"})}):null})(),e.jsx("span",{className:"text-xs text-muted-foreground sm:hidden",children:"·"}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0 sm:order-last",children:Lt(b.updatedAt)})]})]})]})},b.id))})]})]})]})]})}function Qg(){const{companies:t,selectedCompanyId:s,setSelectedCompanyId:n,loading:r,error:a}=he(),{openOnboarding:i}=Ve(),{setBreadcrumbs:o}=Me(),l=Le(),{data:u}=V({queryKey:E.companies.stats,queryFn:()=>As.stats()}),[d,m]=c.useState(null),[x,p]=c.useState(""),[h,j]=c.useState(null),y=se({mutationFn:({id:C,newName:S})=>As.update(C,{name:S}),onSuccess:()=>{l.invalidateQueries({queryKey:E.companies.all}),m(null)}}),f=se({mutationFn:C=>As.remove(C),onSuccess:()=>{l.invalidateQueries({queryKey:E.companies.all}),l.invalidateQueries({queryKey:E.companies.stats}),j(null)}});c.useEffect(()=>{o([{label:"Companies"}])},[o]);function g(C,S){m(C),p(S)}function A(){!d||!x.trim()||y.mutate({id:d,newName:x.trim()})}function N(){m(null),p("")}return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs(F,{size:"sm",onClick:()=>i(),children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-1.5"}),"New Company"]})}),e.jsxs("div",{className:"h-6",children:[r&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading companies..."}),a&&e.jsx("p",{className:"text-sm text-destructive",children:a.message})]}),e.jsx("div",{className:"grid gap-4",children:t.map(C=>{const S=C.id===s,b=d===C.id,v=h===C.id,M=u==null?void 0:u[C.id],k=(M==null?void 0:M.agentCount)??0,_=(M==null?void 0:M.issueCount)??0,U=C.budgetMonthlyCents>0?Math.round(C.spentMonthlyCents/C.budgetMonthlyCents*100):0;return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>n(C.id),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),n(C.id))},className:`group text-left bg-card border rounded-lg p-5 transition-colors cursor-pointer ${S?"border-primary ring-1 ring-primary":"border-border hover:border-muted-foreground/30"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[b?e.jsxs("div",{className:"flex items-center gap-2",onClick:w=>w.stopPropagation(),children:[e.jsx(Ot,{value:x,onChange:w=>p(w.target.value),className:"h-7 text-sm",autoFocus:!0,onKeyDown:w=>{w.key==="Enter"&&A(),w.key==="Escape"&&N()}}),e.jsx(F,{variant:"ghost",size:"icon-xs",onClick:A,disabled:y.isPending,children:e.jsx(Ns,{className:"h-3.5 w-3.5 text-green-500"})}),e.jsx(F,{variant:"ghost",size:"icon-xs",onClick:N,children:e.jsx(St,{className:"h-3.5 w-3.5 text-muted-foreground"})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-base",children:C.name}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium ${C.status==="active"?"bg-green-500/10 text-green-600 dark:text-green-400":C.status==="paused"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":"bg-muted text-muted-foreground"}`,children:C.status}),e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground opacity-0 group-hover:opacity-100",onClick:w=>{w.stopPropagation(),g(C.id,C.name)},children:e.jsx(to,{className:"h-3 w-3"})})]}),C.description&&!b&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:C.description})]}),e.jsx("div",{onClick:w=>w.stopPropagation(),children:e.jsxs(ia,{children:[e.jsx(oa,{asChild:!0,children:e.jsx(F,{variant:"ghost",size:"icon-xs",className:"text-muted-foreground opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100",children:e.jsx(Tl,{className:"h-4 w-4"})})}),e.jsxs(la,{align:"end",children:[e.jsxs(Us,{onClick:()=>g(C.id,C.name),children:[e.jsx(to,{className:"h-3.5 w-3.5"}),"Rename"]}),e.jsx(Pl,{}),e.jsxs(Us,{variant:"destructive",onClick:()=>j(C.id),children:[e.jsx(js,{className:"h-3.5 w-3.5"}),"Delete Company"]})]})]})})]}),e.jsxs("div",{className:"flex items-center gap-3 sm:gap-5 mt-4 text-sm text-muted-foreground flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ua,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:[k," ",k===1?"agent":"agents"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ct,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:[_," ",_===1?"issue":"issues"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 tabular-nums",children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:[re(C.spentMonthlyCents),C.budgetMonthlyCents>0?e.jsxs(e.Fragment,{children:[" / ",re(C.budgetMonthlyCents)," ",e.jsxs("span",{className:"text-xs",children:["(",U,"%)"]})]}):e.jsx("span",{className:"text-xs ml-1",children:"Unlimited budget"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto",children:[e.jsx(vl,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:["Created ",ca(C.createdAt)]})]})]}),v&&e.jsxs("div",{className:"mt-4 flex items-center justify-between bg-destructive/5 border border-destructive/20 rounded-md px-4 py-3",onClick:w=>w.stopPropagation(),children:[e.jsx("p",{className:"text-sm text-destructive font-medium",children:"Delete this company and all its data? This cannot be undone."}),e.jsxs("div",{className:"flex items-center gap-2 ml-4 shrink-0",children:[e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>j(null),disabled:f.isPending,children:"Cancel"}),e.jsx(F,{variant:"destructive",size:"sm",onClick:()=>f.mutate(C.id),disabled:f.isPending,children:f.isPending?"Deleting…":"Delete"})]})]})]},C.id)})})]})}const Yc={claude_local:"Claude",codex_local:"Codex",gemini_local:"Gemini",opencode_local:"OpenCode",cursor:"Cursor",openclaw_gateway:"OpenClaw Gateway",process:"Process",http:"HTTP"},Jc=El;function Xc(t,s,n){return t==="terminated"?n:s==="all"?!0:s==="active"?t==="active"||t==="running"||t==="idle":s==="paused"?t==="paused":s==="error"?t==="error":!0}function Yg(t,s,n){return t.filter(r=>Xc(r.status,s,n))}function Zc(t,s,n){return t.reduce((r,a)=>{const i=Zc(a.reports,s,n);return(Xc(a.status,s,n)||i.length>0)&&r.push({...a,reports:i}),r},[])}function Nr(){const{selectedCompanyId:t}=he(),{openNewAgent:s}=Ve(),{setBreadcrumbs:n}=Me(),r=Mt(),a=bt(),{isMobile:i}=Tn(),o=a.pathname.split("/").pop()??"all",l=o==="all"||o==="active"||o==="paused"||o==="error"?o:"all",[u,d]=c.useState("org"),m=i,x=m?"list":u,[p,h]=c.useState(!1),[j,y]=c.useState(!1),{data:f,isLoading:g,error:A}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t}),{data:N}=V({queryKey:E.org(t),queryFn:()=>Ee.org(t),enabled:!!t&&x==="org"}),{data:C}=V({queryKey:E.heartbeats(t),queryFn:()=>Ht.list(t),enabled:!!t,refetchInterval:15e3}),S=c.useMemo(()=>{const k=new Map;for(const _ of C??[]){if(_.status!=="running"&&_.status!=="queued")continue;const U=k.get(_.agentId);if(U){U.liveCount+=1;continue}k.set(_.agentId,{runId:_.id,liveCount:1})}return k},[C]),b=c.useMemo(()=>{const k=new Map;for(const _ of f??[])k.set(_.id,_);return k},[f]);if(c.useEffect(()=>{n([{label:"Agents"}])},[n]),!t)return e.jsx(Be,{icon:qt,message:"Select a company to view agents."});if(g)return e.jsx(rt,{variant:"list"});const v=Yg(f??[],l,p),M=Zc(N??[],l,p);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx(Ut,{value:l,onValueChange:k=>r(`/agents/${k}`),children:e.jsx(Hs,{items:[{value:"all",label:"All"},{value:"active",label:"Active"},{value:"paused",label:"Paused"},{value:"error",label:"Error"}],value:l,onValueChange:k=>r(`/agents/${k}`)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("button",{className:z("flex items-center gap-1.5 px-2 py-1.5 text-xs transition-colors border border-border",j||p?"text-foreground bg-accent":"text-muted-foreground hover:bg-accent/50"),onClick:()=>y(!j),children:[e.jsx(ru,{className:"h-3 w-3"}),"Filters",p&&e.jsx("span",{className:"ml-0.5 px-1 bg-foreground/10 rounded text-[10px]",children:"1"})]}),j&&e.jsx("div",{className:"absolute right-0 top-full mt-1 z-50 w-48 border border-border bg-popover shadow-md p-1",children:e.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs text-left hover:bg-accent/50 transition-colors",onClick:()=>h(!p),children:[e.jsx("span",{className:z("flex items-center justify-center h-3.5 w-3.5 border border-border rounded-sm",p&&"bg-foreground"),children:p&&e.jsx("span",{className:"text-background text-[10px] leading-none",children:"✓"})}),"Show terminated"]})})]}),!m&&e.jsxs("div",{className:"flex items-center border border-border",children:[e.jsx("button",{className:z("p-1.5 transition-colors",x==="list"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:()=>d("list"),children:e.jsx(Ii,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:z("p-1.5 transition-colors",x==="org"?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent/50"),onClick:()=>d("org"),children:e.jsx(Sl,{className:"h-3.5 w-3.5"})})]}),e.jsxs(F,{size:"sm",variant:"outline",onClick:s,children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-1.5"}),"New Agent"]})]})]}),v.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.length," agent",v.length!==1?"s":""]}),A&&e.jsx("p",{className:"text-sm text-destructive",children:A.message}),f&&f.length===0&&e.jsx(Be,{icon:qt,message:"Create your first agent to get started.",action:"New Agent",onAction:s}),x==="list"&&v.length>0&&e.jsx("div",{className:"border border-border",children:v.map(k=>e.jsx(ps,{title:k.name,subtitle:`${Jc[k.role]??k.role}${k.title?` - ${k.title}`:""}`,to:Xs(k),leading:e.jsx("span",{className:"relative flex h-2.5 w-2.5",children:e.jsx("span",{className:`absolute inline-flex h-full w-full rounded-full ${fi[k.status]??bi}`})}),trailing:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"sm:hidden",children:S.has(k.id)?e.jsx(Gr,{agentRef:Yn(k),runId:S.get(k.id).runId,liveCount:S.get(k.id).liveCount}):e.jsx(Se,{status:k.status})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-3",children:[S.has(k.id)&&e.jsx(Gr,{agentRef:Yn(k),runId:S.get(k.id).runId,liveCount:S.get(k.id).liveCount}),e.jsx("span",{className:"text-xs text-muted-foreground font-mono w-14 text-right",children:Yc[k.adapterType]??k.adapterType}),e.jsx("span",{className:"text-xs text-muted-foreground w-16 text-right",children:k.lastHeartbeatAt?ca(k.lastHeartbeatAt):"—"}),e.jsx("span",{className:"w-20 flex justify-end",children:e.jsx(Se,{status:k.status})})]})]})},k.id))}),x==="list"&&f&&f.length>0&&v.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No agents match the selected filter."}),x==="org"&&M.length>0&&e.jsx("div",{className:"border border-border py-1",children:M.map(k=>e.jsx(ed,{node:k,depth:0,agentMap:b,liveRunByAgent:S},k.id))}),x==="org"&&N&&N.length>0&&M.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No agents match the selected filter."}),x==="org"&&N&&N.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No organizational hierarchy defined."})]})}function ed({node:t,depth:s,agentMap:n,liveRunByAgent:r}){const a=n.get(t.id),i=fi[t.status]??bi;return e.jsxs("div",{style:{paddingLeft:s*24},children:[e.jsxs(xe,{to:a?Xs(a):`/agents/${t.id}`,className:"flex items-center gap-3 px-3 py-2 hover:bg-accent/30 transition-colors w-full text-left no-underline text-inherit",children:[e.jsx("span",{className:"relative flex h-2.5 w-2.5 shrink-0",children:e.jsx("span",{className:`absolute inline-flex h-full w-full rounded-full ${i}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium",children:t.name}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[Jc[t.role]??t.role,a!=null&&a.title?` - ${a.title}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsx("span",{className:"sm:hidden",children:r.has(t.id)?e.jsx(Gr,{agentRef:a?Yn(a):t.id,runId:r.get(t.id).runId,liveCount:r.get(t.id).liveCount}):e.jsx(Se,{status:t.status})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-3",children:[r.has(t.id)&&e.jsx(Gr,{agentRef:a?Yn(a):t.id,runId:r.get(t.id).runId,liveCount:r.get(t.id).liveCount}),a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs text-muted-foreground font-mono w-14 text-right",children:Yc[a.adapterType]??a.adapterType}),e.jsx("span",{className:"text-xs text-muted-foreground w-16 text-right",children:a.lastHeartbeatAt?ca(a.lastHeartbeatAt):"—"})]}),e.jsx("span",{className:"w-20 flex justify-end",children:e.jsx(Se,{status:t.status})})]})]})]}),t.reports&&t.reports.length>0&&e.jsx("div",{className:"border-l border-border/50 ml-4",children:t.reports.map(o=>e.jsx(ed,{node:o,depth:s+1,agentMap:n,liveRunByAgent:r},o.id))})]})}function Gr({agentRef:t,runId:s,liveCount:n}){return e.jsxs(xe,{to:`/agents/${t}/runs/${s}`,className:"flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-blue-500/10 hover:bg-blue-500/20 transition-colors no-underline",onClick:r=>r.stopPropagation(),children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),e.jsxs("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:["Live",n>1?` (${n})`:""]})]})}function Jg(){const{selectedCompanyId:t}=he(),{openNewProject:s}=Ve(),{setBreadcrumbs:n}=Me();c.useEffect(()=>{n([{label:"Projects"}])},[n]);const{data:r,isLoading:a,error:i}=V({queryKey:E.projects.list(t),queryFn:()=>lt.list(t),enabled:!!t}),o=c.useMemo(()=>(r??[]).filter(l=>!l.archivedAt),[r]);return t?a?e.jsx(rt,{variant:"list"}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs(F,{size:"sm",variant:"outline",onClick:s,children:[e.jsx(Pe,{className:"h-4 w-4 mr-1"}),"Add Project"]})}),i&&e.jsx("p",{className:"text-sm text-destructive",children:i.message}),!a&&o.length===0&&e.jsx(Be,{icon:Nn,message:"No projects yet.",action:"Add Project",onAction:s}),o.length>0&&e.jsx("div",{className:"border border-border",children:o.map(l=>e.jsx(ps,{title:l.name,subtitle:l.description??void 0,to:hi(l),trailing:e.jsxs("div",{className:"flex items-center gap-3",children:[l.targetDate&&e.jsx("span",{className:"text-xs text-muted-foreground",children:Gs(l.targetDate)}),e.jsx(Se,{status:l.status})]})},l.id))})]}):e.jsx(Be,{icon:Nn,message:"Select a company to view projects."})}const Xg=[{value:"backlog",label:"Backlog"},{value:"planned",label:"Planned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}];function Ss({state:t}){return t==="saving"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(Es,{className:"h-3 w-3 animate-spin"}),"Saving"]}):t==="saved"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-green-600 dark:text-green-400",children:[e.jsx(Ns,{className:"h-3 w-3"}),"Saved"]}):t==="error"?e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-destructive",children:[e.jsx(ou,{className:"h-3 w-3"}),"Failed"]}):null}function Bs({label:t,state:s}){return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t}),e.jsx(Ss,{state:s})]})}function Cs({label:t,children:s,alignStart:n=!1,valueClassName:r=""}){return e.jsxs("div",{className:z("flex gap-3 py-1.5",n?"items-start":"items-center"),children:[e.jsx("div",{className:"shrink-0 w-20",children:t}),e.jsx("div",{className:z("min-w-0 flex-1",n?"pt-0.5":"flex items-center gap-1.5",r),children:s})]})}function Zg({status:t,onChange:s}){const[n,r]=c.useState(!1),a=au[t]??iu;return e.jsxs(pt,{open:n,onOpenChange:r,children:[e.jsx(gt,{asChild:!0,children:e.jsx("button",{className:z("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0 cursor-pointer hover:opacity-80 transition-opacity",a),children:t.replace("_"," ")})}),e.jsx(ft,{className:"w-40 p-1",align:"start",children:Xg.map(i=>e.jsx(F,{variant:"ghost",size:"sm",className:z("w-full justify-start gap-2 text-xs",i.value===t&&"bg-accent"),onClick:()=>{s(i.value),r(!1)},children:i.label},i.value))})]})}function ef({project:t,onArchive:s,archivePending:n}){const[r,a]=c.useState(!1),i=!t.archivedAt,o=i?"Archive":"Unarchive";return e.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:i?"Archive this project to hide it from the sidebar and project selectors.":"Unarchive this project to restore it in the sidebar and project selectors."}),n?e.jsxs(F,{size:"sm",variant:"destructive",disabled:!0,children:[e.jsx(Es,{className:"h-3 w-3 animate-spin mr-1"}),i?"Archiving...":"Unarchiving..."]}):r?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm text-destructive font-medium",children:[o," “",t.name,"”?"]}),e.jsx(F,{size:"sm",variant:"destructive",onClick:()=>{a(!1),s(i)},children:"Confirm"}),e.jsx(F,{size:"sm",variant:"outline",onClick:()=>a(!1),children:"Cancel"})]}):e.jsx(F,{size:"sm",variant:"destructive",onClick:()=>a(!0),children:i?e.jsxs(e.Fragment,{children:[e.jsx(Fm,{className:"h-3 w-3 mr-1"}),o," project"]}):e.jsxs(e.Fragment,{children:[e.jsx(Dm,{className:"h-3 w-3 mr-1"}),o," project"]})})]})}function tf({project:t,onUpdate:s,onFieldUpdate:n,getFieldSaveState:r,onArchive:a,archivePending:i}){var He;const{selectedCompanyId:o}=he(),l=Le(),[u,d]=c.useState(!1),[m,x]=c.useState(!1),[p,h]=c.useState(null),[j,y]=c.useState(""),[f,g]=c.useState(""),[A,N]=c.useState(null),C=(K,de)=>{if(n){n(K,de);return}s==null||s(de)},S=K=>(r==null?void 0:r(K))??"idle",{data:b}=V({queryKey:E.goals.list(o),queryFn:()=>Et.list(o),enabled:!!o}),{data:v}=V({queryKey:E.instance.experimentalSettings,queryFn:()=>Wa.getExperimental()}),M=t.goalIds.length>0?t.goalIds:t.goalId?[t.goalId]:[],k=t.goals.length>0?t.goals:M.map(K=>{var de;return{id:K,title:((de=b==null?void 0:b.find(fe=>fe.id===K))==null?void 0:de.title)??K.slice(0,8)}}),_=(b??[]).filter(K=>!M.includes(K.id)),U=t.workspaces??[],w=t.codebase,T=t.primaryWorkspace??null,W=U.some(K=>K.id!==(T==null?void 0:T.id)),H=t.executionWorkspacePolicy??null,B=(H==null?void 0:H.enabled)===!0,D=(v==null?void 0:v.enableIsolatedWorkspaces)===!0,Z=(H==null?void 0:H.defaultMode)==="isolated_workspace"?"isolated_workspace":"shared_workspace",G=(H==null?void 0:H.workspaceStrategy)??{type:"git_worktree",baseRef:"",branchTemplate:"",worktreeParentDir:""},ie=()=>{l.invalidateQueries({queryKey:E.projects.detail(t.id)}),t.urlKey!==t.id&&l.invalidateQueries({queryKey:E.projects.detail(t.urlKey)}),o&&l.invalidateQueries({queryKey:E.projects.list(o)})},ce=se({mutationFn:K=>lt.createWorkspace(t.id,K),onSuccess:()=>{y(""),g(""),h(null),N(null),ie()}}),q=se({mutationFn:K=>lt.removeWorkspace(t.id,K),onSuccess:()=>{y(""),g(""),h(null),N(null),ie()}}),J=se({mutationFn:({workspaceId:K,data:de})=>lt.updateWorkspace(t.id,K,de),onSuccess:()=>{y(""),g(""),h(null),N(null),ie()}}),I=K=>{!s&&!n||C("goals",{goalIds:M.filter(de=>de!==K)})},P=K=>{!s&&!n||M.includes(K)||(C("goals",{goalIds:[...M,K]}),d(!1))},O=K=>{if(!(!s&&!n))return{executionWorkspacePolicy:{enabled:B,defaultMode:Z,allowIssueOverride:(H==null?void 0:H.allowIssueOverride)??!0,...H,...K}}},te=K=>K.startsWith("/")||/^[A-Za-z]:[\\/]/.test(K),oe=K=>{try{const de=new URL(K),fe=de.hostname.toLowerCase();return fe!=="github.com"&&fe!=="www.github.com"?!1:de.pathname.split("/").filter(Boolean).length>=2}catch{return!1}},ue=K=>{if(!K)return!1;try{const de=new URL(K);return de.protocol==="http:"||de.protocol==="https:"}catch{return!1}},L=K=>{var de;try{const fe=new URL(K),Ie=fe.pathname.split("/").filter(Boolean);if(Ie.length<2)return fe.host;const ze=Ie[0],Qt=(de=Ie[1])==null?void 0:de.replace(/\.git$/i,"");return!ze||!Qt?fe.host:`${fe.host}/${ze}/${Qt}`}catch{return K}},ae=(K,de)=>{if(de)return"git_repo";if(K)return"local_path"},le=K=>{const de=K.cwd!==void 0?K.cwd:w.localFolder,fe=K.repoUrl!==void 0?K.repoUrl:w.repoUrl;if(!de&&!fe){T&&q.mutate(T.id);return}const Ie={...K.cwd!==void 0?{cwd:K.cwd}:{},...K.repoUrl!==void 0?{repoUrl:K.repoUrl}:{},...ae(de,fe)?{sourceType:ae(de,fe)}:{},isPrimary:!0};if(T){J.mutate({workspaceId:T.id,data:Ie});return}ce.mutate(Ie)},Re=()=>{const K=j.trim();if(!K){N(null),le({cwd:null});return}if(!te(K)){N("Local folder must be a full absolute path.");return}N(null),le({cwd:K})},ee=()=>{const K=f.trim();if(!K){N(null),le({repoUrl:null});return}if(!oe(K)){N("Repo must use a valid GitHub repo URL.");return}N(null),le({repoUrl:K})},ye=()=>{window.confirm(w.repoUrl?"Clear local folder from this workspace?":"Delete this workspace local folder?")&&le({cwd:null})},Ce=()=>{const K=!!w.localFolder;if(window.confirm(K?"Clear repo from this workspace?":"Delete this workspace repo?")){if(T&&K){J.mutate({workspaceId:T.id,data:{repoUrl:null,repoRef:null,defaultRef:null,sourceType:ae(w.localFolder,null)}});return}le({repoUrl:null})}};return e.jsxs("div",{children:[e.jsxs("div",{className:"space-y-1 pb-4",children:[e.jsx(Cs,{label:e.jsx(Bs,{label:"Name",state:S("name")}),children:s||n?e.jsx(tn,{value:t.name,onCommit:K=>C("name",{name:K}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-sm outline-none",placeholder:"Project name"}):e.jsx("span",{className:"text-sm",children:t.name})}),e.jsx(Cs,{label:e.jsx(Bs,{label:"Description",state:S("description")}),alignStart:!0,valueClassName:"space-y-0.5",children:s||n?e.jsx(Rs,{value:t.description??"",onSave:K=>C("description",{description:K}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:((He=t.description)==null?void 0:He.trim())||"No description"})}),e.jsx(Cs,{label:e.jsx(Bs,{label:"Status",state:S("status")}),children:s||n?e.jsx(Zg,{status:t.status,onChange:K=>C("status",{status:K})}):e.jsx(Se,{status:t.status})}),t.leadAgentId&&e.jsx(Cs,{label:"Lead",children:e.jsx("span",{className:"text-sm font-mono",children:t.leadAgentId.slice(0,8)})}),e.jsxs(Cs,{label:e.jsx(Bs,{label:"Goals",state:S("goals")}),alignStart:!0,valueClassName:"space-y-2",children:[k.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(K=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs",children:[e.jsx(xe,{to:`/goals/${K.id}`,className:"hover:underline max-w-[220px] truncate",children:K.title}),(s||n)&&e.jsx("button",{className:"text-muted-foreground hover:text-foreground",type:"button",onClick:()=>I(K.id),"aria-label":`Remove goal ${K.title}`,children:e.jsx(St,{className:"h-3 w-3"})})]},K.id))}),(s||n)&&e.jsxs(pt,{open:u,onOpenChange:d,children:[e.jsx(gt,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"xs",className:z("h-6 w-fit px-2",k.length>0&&"ml-1"),disabled:_.length===0,children:[e.jsx(Pe,{className:"h-3 w-3 mr-1"}),"Goal"]})}),e.jsx(ft,{className:"w-56 p-1",align:"start",children:_.length===0?e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"All goals linked."}):_.map(K=>e.jsx("button",{className:"flex items-center w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>P(K.id),children:K.title},K.id))})]})]}),e.jsx(Cs,{label:e.jsx(Bs,{label:"Created",state:"idle"}),children:e.jsx("span",{className:"text-sm",children:Gs(t.createdAt)})}),e.jsx(Cs,{label:e.jsx(Bs,{label:"Updated",state:"idle"}),children:e.jsx("span",{className:"text-sm",children:Gs(t.updatedAt)})}),t.targetDate&&e.jsx(Cs,{label:e.jsx(Bs,{label:"Target Date",state:"idle"}),children:e.jsx("span",{className:"text-sm",children:Gs(t.targetDate)})})]}),e.jsx(Rt,{className:"my-4"}),e.jsxs("div",{className:"space-y-1 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Codebase"}),e.jsxs(as,{children:[e.jsx(is,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-border text-[10px] text-muted-foreground hover:text-foreground","aria-label":"Codebase help",children:"?"})}),e.jsx(os,{side:"top",children:"Repo identifies the source of truth. Local folder is the default place agents write code."})]})]}),e.jsxs("div",{className:"space-y-2 rounded-md border border-border/70 p-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Repo"}),w.repoUrl?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[ue(w.repoUrl)?e.jsxs("a",{href:w.repoUrl,target:"_blank",rel:"noreferrer",className:"inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground hover:underline",children:[e.jsx(uo,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:L(w.repoUrl)}),e.jsx(En,{className:"h-3 w-3 shrink-0"})]}):e.jsxs("div",{className:"inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(uo,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:w.repoUrl})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{variant:"outline",size:"xs",className:"h-6 px-2",onClick:()=>{h("repo"),g(w.repoUrl??""),N(null)},children:"Change repo"}),e.jsx(F,{variant:"ghost",size:"icon-xs",onClick:Ce,"aria-label":"Clear repo",children:e.jsx(js,{className:"h-3 w-3"})})]})]}):e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Not set."}),e.jsx(F,{variant:"outline",size:"xs",className:"h-6 px-2",onClick:()=>{h("repo"),g(w.repoUrl??""),N(null)},children:"Set repo"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Local folder"}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("div",{className:"min-w-0 truncate font-mono text-xs text-muted-foreground",children:w.effectiveLocalFolder}),w.origin==="managed_checkout"&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Growthub-managed folder."})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(F,{variant:"outline",size:"xs",className:"h-6 px-2",onClick:()=>{h("local"),y(w.localFolder??""),N(null)},children:w.localFolder?"Change local folder":"Set local folder"}),w.localFolder?e.jsx(F,{variant:"ghost",size:"icon-xs",onClick:ye,"aria-label":"Clear local folder",children:e.jsx(js,{className:"h-3 w-3"})}):null]})]})]}),W&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Additional legacy workspace records exist on this project. Growthub is using the primary workspace as the codebase view."}),T!=null&&T.runtimeServices&&T.runtimeServices.length>0?e.jsx("div",{className:"space-y-1",children:T.runtimeServices.map(K=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border/60 px-2 py-1",children:[e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-medium",children:K.serviceName}),e.jsx("span",{className:z("rounded-full px-1.5 py-0.5 text-[10px] uppercase tracking-wide",K.status==="running"?"bg-green-500/15 text-green-700 dark:text-green-300":K.status==="failed"?"bg-red-500/15 text-red-700 dark:text-red-300":"bg-muted text-muted-foreground"),children:K.status})]}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:K.url?e.jsx("a",{href:K.url,target:"_blank",rel:"noreferrer",className:"hover:text-foreground hover:underline",children:K.url}):K.command??"No URL"})]}),e.jsx("div",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:K.lifecycle})]},K.id))}):null]}),p==="local"&&e.jsxs("div",{className:"space-y-1.5 rounded-md border border-border p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",value:j,onChange:K=>y(K.target.value),placeholder:"/absolute/path/to/workspace"}),e.jsx(jl,{})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{variant:"outline",size:"xs",className:"h-6 px-2",disabled:!j.trim()&&!T||ce.isPending||J.isPending,onClick:Re,children:"Save"}),e.jsx(F,{variant:"ghost",size:"xs",className:"h-6 px-2",onClick:()=>{h(null),y(""),N(null)},children:"Cancel"})]})]}),p==="repo"&&e.jsxs("div",{className:"space-y-1.5 rounded-md border border-border p-2",children:[e.jsx("input",{className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs outline-none",value:f,onChange:K=>g(K.target.value),placeholder:"https://github.com/org/repo"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{variant:"outline",size:"xs",className:"h-6 px-2",disabled:!f.trim()&&!T||ce.isPending||J.isPending,onClick:ee,children:"Save"}),e.jsx(F,{variant:"ghost",size:"xs",className:"h-6 px-2",onClick:()=>{h(null),g(""),N(null)},children:"Cancel"})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),ce.isError&&e.jsx("p",{className:"text-xs text-destructive",children:"Failed to save workspace."}),q.isError&&e.jsx("p",{className:"text-xs text-destructive",children:"Failed to delete workspace."}),J.isError&&e.jsx("p",{className:"text-xs text-destructive",children:"Failed to update workspace."})]}),D?e.jsxs(e.Fragment,{children:[e.jsx(Rt,{className:"my-4"}),e.jsxs("div",{className:"py-1.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Execution Workspaces"}),e.jsxs(as,{children:[e.jsx(is,{asChild:!0,children:e.jsx("button",{type:"button",className:"inline-flex h-4 w-4 items-center justify-center rounded-full border border-border text-[10px] text-muted-foreground hover:text-foreground","aria-label":"Execution workspaces help",children:"?"})}),e.jsx(os,{side:"top",children:"Project-owned defaults for isolated issue checkouts and execution workspace behavior."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx("span",{children:"Enable isolated issue checkouts"}),e.jsx(Ss,{state:S("execution_workspace_enabled")})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Let issues choose between the project's primary checkout and an isolated execution workspace."})]}),s||n?e.jsx("button",{className:z("relative inline-flex h-5 w-9 items-center rounded-full transition-colors",B?"bg-green-600":"bg-muted"),type:"button",onClick:()=>C("execution_workspace_enabled",O({enabled:!B})),children:e.jsx("span",{className:z("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",B?"translate-x-4.5":"translate-x-0.5")})}):e.jsx("span",{className:"text-xs text-muted-foreground",children:B?"Enabled":"Disabled"})]}),B?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{children:"New issues default to isolated checkout"}),e.jsx(Ss,{state:S("execution_workspace_default_mode")})]}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"If disabled, new issues stay on the project's primary checkout unless someone opts in."})]}),e.jsx("button",{className:z("relative inline-flex h-5 w-9 items-center rounded-full transition-colors",Z==="isolated_workspace"?"bg-green-600":"bg-muted"),type:"button",onClick:()=>C("execution_workspace_default_mode",O({defaultMode:Z==="isolated_workspace"?"shared_workspace":"isolated_workspace"})),children:e.jsx("span",{className:z("inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform",Z==="isolated_workspace"?"translate-x-4.5":"translate-x-0.5")})})]}),e.jsx("div",{className:"border-t border-border/60 pt-2",children:e.jsx("button",{type:"button",className:"flex w-full items-center gap-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:text-foreground",onClick:()=>x(K=>!K),children:m?"Hide advanced checkout settings":"Show advanced checkout settings"})}),m?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Host-managed implementation: ",e.jsx("span",{className:"text-foreground",children:"Git worktree"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 flex items-center gap-1.5",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Base ref"}),e.jsx(Ss,{state:S("execution_workspace_base_ref")})]})}),e.jsx(tn,{value:G.baseRef??"",onCommit:K=>C("execution_workspace_base_ref",{...O({workspaceStrategy:{...G,type:"git_worktree",baseRef:K||null}})}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",placeholder:"origin/main"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 flex items-center gap-1.5",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Branch template"}),e.jsx(Ss,{state:S("execution_workspace_branch_template")})]})}),e.jsx(tn,{value:G.branchTemplate??"",onCommit:K=>C("execution_workspace_branch_template",{...O({workspaceStrategy:{...G,type:"git_worktree",branchTemplate:K||null}})}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",placeholder:"{{issue.identifier}}-{{slug}}"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 flex items-center gap-1.5",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Worktree parent dir"}),e.jsx(Ss,{state:S("execution_workspace_worktree_parent_dir")})]})}),e.jsx(tn,{value:G.worktreeParentDir??"",onCommit:K=>C("execution_workspace_worktree_parent_dir",{...O({workspaceStrategy:{...G,type:"git_worktree",worktreeParentDir:K||null}})}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",placeholder:".paperclip/worktrees"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 flex items-center gap-1.5",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Provision command"}),e.jsx(Ss,{state:S("execution_workspace_provision_command")})]})}),e.jsx(tn,{value:G.provisionCommand??"",onCommit:K=>C("execution_workspace_provision_command",{...O({workspaceStrategy:{...G,type:"git_worktree",provisionCommand:K||null}})}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",placeholder:"bash ./scripts/provision-worktree.sh"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 flex items-center gap-1.5",children:e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:"Teardown command"}),e.jsx(Ss,{state:S("execution_workspace_teardown_command")})]})}),e.jsx(tn,{value:G.teardownCommand??"",onCommit:K=>C("execution_workspace_teardown_command",{...O({workspaceStrategy:{...G,type:"git_worktree",teardownCommand:K||null}})}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-xs font-mono outline-none",placeholder:"bash ./scripts/teardown-worktree.sh"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Provision runs inside the derived worktree before agent execution. Teardown is stored here for future cleanup flows."})]}):null]}):null]})]})]}):null]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Rt,{className:"my-4"}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsx("div",{className:"text-xs font-medium text-destructive uppercase tracking-wide",children:"Danger Zone"}),e.jsx(ef,{project:t,onArchive:a,archivePending:i})]})]})]})}function Da(t,s){const n={};for(const r of t){const a=s(r);n[a]||(n[a]=[]),n[a].push(r)}return n}function ss({className:t,...s}){return e.jsx(zl,{"data-slot":"checkbox",className:z("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",t),...s,children:e.jsx(Ul,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:e.jsx(Ns,{className:"size-3.5"})})})}const $a=["backlog","todo","in_progress","in_review","blocked","done","cancelled"];function sf(t){return t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase())}function nf({status:t,issues:s,agents:n,liveIssueIds:r}){const{setNodeRef:a,isOver:i}=bc({id:t});return e.jsxs("div",{className:"flex flex-col min-w-[260px] w-[260px] shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 mb-1",children:[e.jsx(wt,{status:t}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:sf(t)}),e.jsx("span",{className:"text-xs text-muted-foreground/60 ml-auto tabular-nums",children:s.length})]}),e.jsx("div",{ref:a,className:`flex-1 min-h-[120px] rounded-md p-1 space-y-1 transition-colors ${i?"bg-accent/40":"bg-muted/20"}`,children:e.jsx(Oi,{items:s.map(o=>o.id),strategy:Li,children:s.map(o=>e.jsx(td,{issue:o,agents:n,isLive:r==null?void 0:r.has(o.id)},o.id))})})]})}function td({issue:t,agents:s,isLive:n,isOverlay:r}){const{attributes:a,listeners:i,setNodeRef:o,transform:l,transition:u,isDragging:d}=qi({id:t.id,data:{issue:t}}),m={transform:ds.Transform.toString(l),transition:u},x=p=>{var h;return!p||!s?null:((h=s.find(j=>j.id===p))==null?void 0:h.name)??null};return e.jsx("div",{ref:o,style:m,...a,...i,className:`rounded-md border bg-card p-2.5 cursor-grab active:cursor-grabbing transition-shadow ${d&&!r?"opacity-30":""} ${r?"shadow-lg ring-1 ring-primary/20":"hover:shadow-sm"}`,children:e.jsxs(xe,{to:`/issues/${t.identifier??t.id}`,className:"block no-underline text-inherit",onClick:p=>{d&&p.preventDefault()},children:[e.jsxs("div",{className:"flex items-start gap-1.5 mb-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground font-mono shrink-0",children:t.identifier??t.id.slice(0,8)}),n&&e.jsxs("span",{className:"relative flex h-2 w-2 shrink-0 mt-0.5",children:[e.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]})]}),e.jsx("p",{className:"text-sm leading-snug line-clamp-2 mb-2",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Nt,{priority:t.priority}),t.assigneeAgentId&&(()=>{const p=x(t.assigneeAgentId);return p?e.jsx(qe,{name:p,size:"xs"}):e.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:t.assigneeAgentId.slice(0,8)})})()]})]})})}function rf({issues:t,agents:s,liveIssueIds:n,onUpdateIssue:r}){const[a,i]=c.useState(null),o=Ri(Ei(ur,{activationConstraint:{distance:5}})),l=c.useMemo(()=>{const p={};for(const h of $a)p[h]=[];for(const h of t)p[h.status]&&p[h.status].push(h);return p},[t]),u=c.useMemo(()=>a?t.find(p=>p.id===a):null,[a,t]);function d(p){i(p.active.id)}function m(p){i(null);const{active:h,over:j}=p;if(!j)return;const y=h.id,f=t.find(A=>A.id===y);if(!f)return;let g=null;if($a.includes(j.id))g=j.id;else{const A=t.find(N=>N.id===j.id);A&&(g=A.status)}g&&g!==f.status&&r(y,{status:g})}function x(p){}return e.jsxs(Fi,{sensors:o,onDragStart:d,onDragOver:x,onDragEnd:m,children:[e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-4 -mx-2 px-2",children:$a.map(p=>e.jsx(nf,{status:p,issues:l[p]??[],agents:s,liveIssueIds:n},p))}),e.jsx(xp,{children:u?e.jsx(td,{issue:u,agents:s,isOverlay:!0}):null})]})}const Wr=["in_progress","todo","backlog","in_review","blocked","done","cancelled"],Vr=["critical","high","medium","low"];function wr(t){return t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase())}const Hr={statuses:[],priorities:[],assignees:[],labels:[],sortField:"updated",sortDir:"desc",groupBy:"none",viewMode:"list",collapsedGroups:[]},af=[{label:"All",statuses:[]},{label:"Active",statuses:["todo","in_progress","in_review","blocked"]},{label:"Backlog",statuses:["backlog"]},{label:"Done",statuses:["done","cancelled"]}];function Bo(t){try{const s=localStorage.getItem(t);if(s)return{...Hr,...JSON.parse(s)}}catch{}return{...Hr}}function of(t,s){localStorage.setItem(t,JSON.stringify(s))}function lf(t,s){if(t.length!==s.length)return!1;const n=[...t].sort(),r=[...s].sort();return n.every((a,i)=>a===r[i])}function rn(t,s){return t.includes(s)?t.filter(n=>n!==s):[...t,s]}function cf(t,s,n){let r=t;return s.statuses.length>0&&(r=r.filter(a=>s.statuses.includes(a.status))),s.priorities.length>0&&(r=r.filter(a=>s.priorities.includes(a.priority))),s.assignees.length>0&&(r=r.filter(a=>{for(const i of s.assignees)if(i==="__unassigned"&&!a.assigneeAgentId&&!a.assigneeUserId||i==="__me"&&n&&a.assigneeUserId===n||a.assigneeAgentId===i)return!0;return!1})),s.labels.length>0&&(r=r.filter(a=>(a.labelIds??[]).some(i=>s.labels.includes(i)))),r}function df(t,s){const n=[...t],r=s.sortDir==="asc"?1:-1;return n.sort((a,i)=>{switch(s.sortField){case"status":return r*(Wr.indexOf(a.status)-Wr.indexOf(i.status));case"priority":return r*(Vr.indexOf(a.priority)-Vr.indexOf(i.priority));case"title":return r*a.title.localeCompare(i.title);case"created":return r*(new Date(a.createdAt).getTime()-new Date(i.createdAt).getTime());case"updated":return r*(new Date(a.updatedAt).getTime()-new Date(i.updatedAt).getTime());default:return 0}}),n}function uf(t){let s=0;return t.statuses.length>0&&s++,t.priorities.length>0&&s++,t.assignees.length>0&&s++,t.labels.length>0&&s++,s}function sd({issues:t,isLoading:s,error:n,agents:r,liveIssueIds:a,projectId:i,viewStateKey:o,issueLinkState:l,initialAssignees:u,initialSearch:d,onSearchChange:m,onUpdateIssue:x}){var q,J;const{selectedCompanyId:p}=he(),{openNewIssue:h}=Ve(),{data:j}=V({queryKey:E.auth.session,queryFn:()=>na.getSession()}),y=((q=j==null?void 0:j.user)==null?void 0:q.id)??((J=j==null?void 0:j.session)==null?void 0:J.userId)??null,f=p?`${o}:${p}`:o,[g,A]=c.useState(()=>u?{...Hr,assignees:u,statuses:[]}:Bo(f)),[N,C]=c.useState(null),[S,b]=c.useState(""),[v,M]=c.useState(d??""),[k,_]=c.useState(v),U=k.trim();c.useEffect(()=>{M(d??"")},[d]),c.useEffect(()=>{const I=window.setTimeout(()=>{_(v)},300);return()=>window.clearTimeout(I)},[v]);const w=c.useRef(f);c.useEffect(()=>{w.current!==f&&(w.current=f,A(u?{...Hr,assignees:u,statuses:[]}:Bo(f)))},[f,u]);const T=c.useCallback(I=>{A(P=>{const O={...P,...I};return of(f,O),O})},[f]),{data:W=[]}=V({queryKey:E.issues.search(p,U,i),queryFn:()=>ht.list(p,{q:U,projectId:i}),enabled:!!p&&U.length>0}),H=c.useCallback(I=>{var P;return!I||!r?null:((P=r.find(O=>O.id===I))==null?void 0:P.name)??null},[r]),B=c.useMemo(()=>{const I=U.length>0?W:t,P=cf(I,g,y);return df(P,g)},[t,W,g,U,y]),{data:D}=V({queryKey:E.issues.labels(p),queryFn:()=>ht.listLabels(p),enabled:!!p}),Z=uf(g),G=c.useMemo(()=>{if(g.groupBy==="none")return[{key:"__all",label:null,items:B}];if(g.groupBy==="status"){const P=Da(B,O=>O.status);return Wr.filter(O=>{var te;return(te=P[O])==null?void 0:te.length}).map(O=>({key:O,label:wr(O),items:P[O]}))}if(g.groupBy==="priority"){const P=Da(B,O=>O.priority);return Vr.filter(O=>{var te;return(te=P[O])==null?void 0:te.length}).map(O=>({key:O,label:wr(O),items:P[O]}))}const I=Da(B,P=>P.assigneeAgentId??(P.assigneeUserId?`__user:${P.assigneeUserId}`:"__unassigned"));return Object.keys(I).map(P=>({key:P,label:P==="__unassigned"?"Unassigned":P.startsWith("__user:")?so(P.slice(7),y)??"User":H(P)??P.slice(0,8),items:I[P]}))},[B,g.groupBy,r,H,y]),ie=I=>{const P={};return i&&(P.projectId=i),I&&(g.groupBy==="status"?P.status=I:g.groupBy==="priority"?P.priority=I:g.groupBy==="assignee"&&I!=="__unassigned"&&(I.startsWith("__user:")?P.assigneeUserId=I.slice(7):P.assigneeAgentId=I)),P},ce=(I,P,O=null)=>{x(I,{assigneeAgentId:P,assigneeUserId:O}),C(null),b("")};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 sm:gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 sm:gap-3",children:[e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>h(ie()),children:[e.jsx(Pe,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"New Issue"})]}),e.jsxs("div",{className:"relative w-48 sm:w-64 md:w-80",children:[e.jsx(gs,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(Ot,{value:v,onChange:I=>{M(I.target.value),m==null||m(I.target.value)},placeholder:"Search issues...",className:"pl-7 text-xs sm:text-sm","aria-label":"Search issues"})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 shrink-0",children:[e.jsxs("div",{className:"flex items-center border border-border rounded-md overflow-hidden mr-1",children:[e.jsx("button",{className:`p-1.5 transition-colors ${g.viewMode==="list"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>T({viewMode:"list"}),title:"List view",children:e.jsx(Ii,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:`p-1.5 transition-colors ${g.viewMode==="board"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>T({viewMode:"board"}),title:"Board view",children:e.jsx(Xm,{className:"h-3.5 w-3.5"})})]}),e.jsxs(pt,{children:[e.jsx(gt,{asChild:!0,children:e.jsxs(F,{variant:"ghost",size:"sm",className:`text-xs ${Z>0?"text-blue-600 dark:text-blue-400":""}`,children:[e.jsx(rx,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:Z>0?`Filters: ${Z}`:"Filter"}),Z>0&&e.jsx("span",{className:"sm:hidden text-[10px] font-medium ml-0.5",children:Z}),Z>0&&e.jsx(St,{className:"h-3 w-3 ml-1 hidden sm:block",onClick:I=>{I.stopPropagation(),T({statuses:[],priorities:[],assignees:[],labels:[]})}})]})}),e.jsx(ft,{align:"end",className:"w-[min(480px,calc(100vw-2rem))] p-0",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:"Filters"}),Z>0&&e.jsx("button",{className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>T({statuses:[],priorities:[],assignees:[],labels:[]}),children:"Clear"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Quick filters"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:af.map(I=>{const P=lf(g.statuses,I.statuses);return e.jsx("button",{className:`px-2.5 py-1 text-xs rounded-full border transition-colors ${P?"bg-primary text-primary-foreground border-primary":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,onClick:()=>T({statuses:P?[]:[...I.statuses]}),children:I.label},I.label)})})]}),e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),e.jsx("div",{className:"space-y-0.5",children:Wr.map(I=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[e.jsx(ss,{checked:g.statuses.includes(I),onCheckedChange:()=>T({statuses:rn(g.statuses,I)})}),e.jsx(wt,{status:I}),e.jsx("span",{className:"text-sm",children:wr(I)})]},I))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),e.jsx("div",{className:"space-y-0.5",children:Vr.map(I=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[e.jsx(ss,{checked:g.priorities.includes(I),onCheckedChange:()=>T({priorities:rn(g.priorities,I)})}),e.jsx(Nt,{priority:I}),e.jsx("span",{className:"text-sm",children:wr(I)})]},I))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),e.jsxs("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:[e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[e.jsx(ss,{checked:g.assignees.includes("__unassigned"),onCheckedChange:()=>T({assignees:rn(g.assignees,"__unassigned")})}),e.jsx("span",{className:"text-sm",children:"No assignee"})]}),y&&e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[e.jsx(ss,{checked:g.assignees.includes("__me"),onCheckedChange:()=>T({assignees:rn(g.assignees,"__me")})}),e.jsx(dn,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:"Me"})]}),(r??[]).map(I=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[e.jsx(ss,{checked:g.assignees.includes(I.id),onCheckedChange:()=>T({assignees:rn(g.assignees,I.id)})}),e.jsx("span",{className:"text-sm",children:I.name})]},I.id))]})]}),D&&D.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Labels"}),e.jsx("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:D.map(I=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[e.jsx(ss,{checked:g.labels.includes(I.id),onCheckedChange:()=>T({labels:rn(g.labels,I.id)})}),e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:I.color}}),e.jsx("span",{className:"text-sm",children:I.name})]},I.id))})]})]})]})]})})]}),g.viewMode==="list"&&e.jsxs(pt,{children:[e.jsx(gt,{asChild:!0,children:e.jsxs(F,{variant:"ghost",size:"sm",className:"text-xs",children:[e.jsx(Bm,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),e.jsx(ft,{align:"end",className:"w-48 p-0",children:e.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["title","Title"],["created","Created"],["updated","Updated"]].map(([I,P])=>e.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${g.sortField===I?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>{g.sortField===I?T({sortDir:g.sortDir==="asc"?"desc":"asc"}):T({sortField:I,sortDir:"asc"})},children:[e.jsx("span",{children:P}),g.sortField===I&&e.jsx("span",{className:"text-xs text-muted-foreground",children:g.sortDir==="asc"?"↑":"↓"})]},I))})})]}),g.viewMode==="list"&&e.jsxs(pt,{children:[e.jsx(gt,{asChild:!0,children:e.jsxs(F,{variant:"ghost",size:"sm",className:"text-xs",children:[e.jsx(Yl,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Group"})]})}),e.jsx(ft,{align:"end",className:"w-44 p-0",children:e.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["assignee","Assignee"],["none","None"]].map(([I,P])=>e.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${g.groupBy===I?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>T({groupBy:I}),children:[e.jsx("span",{children:P}),g.groupBy===I&&e.jsx(Ns,{className:"h-3.5 w-3.5"})]},I))})})]})]})]}),s&&e.jsx(rt,{variant:"issues-list"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n.message}),!s&&B.length===0&&g.viewMode==="list"&&e.jsx(Be,{icon:Ct,message:"No issues match the current filters or search.",action:"Create Issue",onAction:()=>h(ie())}),g.viewMode==="board"?e.jsx(rf,{issues:B,agents:r,liveIssueIds:a,onUpdateIssue:x}):G.map(I=>e.jsxs(Zr,{open:!g.collapsedGroups.includes(I.key),onOpenChange:P=>{T({collapsedGroups:P?g.collapsedGroups.filter(O=>O!==I.key):[...g.collapsedGroups,I.key]})},children:[I.label&&e.jsxs("div",{className:"flex items-center py-1.5 pl-1 pr-3",children:[e.jsxs(ea,{className:"flex items-center gap-1.5",children:[e.jsx(Js,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),e.jsx("span",{className:"text-sm font-semibold uppercase tracking-wide",children:I.label})]}),e.jsx(F,{variant:"ghost",size:"icon-xs",className:"ml-auto text-muted-foreground",onClick:()=>h(ie(I.key)),children:e.jsx(Pe,{className:"h-3 w-3"})})]}),e.jsx(ta,{children:I.items.map(P=>e.jsx(Rl,{issue:P,issueLinkState:l,desktopLeadingSpacer:!0,mobileLeading:e.jsx("span",{onClick:O=>{O.preventDefault(),O.stopPropagation()},children:e.jsx(wt,{status:P.status,onChange:O=>x(P.id,{status:O})})}),desktopMetaLeading:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(Nt,{priority:P.priority})}),e.jsx("span",{className:"hidden shrink-0 sm:inline-flex",onClick:O=>{O.preventDefault(),O.stopPropagation()},children:e.jsx(wt,{status:P.status,onChange:O=>x(P.id,{status:O})})}),e.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:P.identifier??P.id.slice(0,8)}),(a==null?void 0:a.has(P.id))&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-500/10 px-1.5 py-0.5 sm:gap-1.5 sm:px-2",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-blue-500"})]}),e.jsx("span",{className:"hidden text-[11px] font-medium text-blue-600 dark:text-blue-400 sm:inline",children:"Live"})]})]}),mobileMeta:Lt(P.updatedAt),desktopTrailing:e.jsxs(e.Fragment,{children:[(P.labels??[]).length>0&&e.jsxs("span",{className:"hidden items-center gap-1 overflow-hidden md:flex md:max-w-[240px]",children:[(P.labels??[]).slice(0,3).map(O=>e.jsx("span",{className:"inline-flex items-center rounded-full border px-1.5 py-0.5 text-[10px] font-medium",style:{borderColor:O.color,color:O.color,backgroundColor:`${O.color}1f`},children:O.name},O.id)),(P.labels??[]).length>3&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(P.labels??[]).length-3]})]}),e.jsxs(pt,{open:N===P.id,onOpenChange:O=>{C(O?P.id:null),O||b("")},children:[e.jsx(gt,{asChild:!0,children:e.jsx("button",{className:"flex w-[180px] shrink-0 items-center rounded-md px-2 py-1 transition-colors hover:bg-accent/50",onClick:O=>{O.preventDefault(),O.stopPropagation()},children:P.assigneeAgentId&&H(P.assigneeAgentId)?e.jsx(qe,{name:H(P.assigneeAgentId),size:"sm"}):P.assigneeUserId?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-muted-foreground/35 bg-muted/30",children:e.jsx(dn,{className:"h-3 w-3"})}),so(P.assigneeUserId,y)??"User"]}):e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:"inline-flex h-5 w-5 items-center justify-center rounded-full border border-dashed border-muted-foreground/35 bg-muted/30",children:e.jsx(dn,{className:"h-3 w-3"})}),"Assignee"]})})}),e.jsxs(ft,{className:"w-56 p-1",align:"end",onClick:O=>O.stopPropagation(),onPointerDownOutside:()=>b(""),children:[e.jsx("input",{className:"mb-1 w-full border-b border-border bg-transparent px-2 py-1.5 text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search assignees...",value:S,onChange:O=>b(O.target.value),autoFocus:!0}),e.jsxs("div",{className:"max-h-48 overflow-y-auto overscroll-contain",children:[e.jsx("button",{className:z("flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs hover:bg-accent/50",!P.assigneeAgentId&&!P.assigneeUserId&&"bg-accent"),onClick:O=>{O.preventDefault(),O.stopPropagation(),ce(P.id,null,null)},children:"No assignee"}),y&&e.jsxs("button",{className:z("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",P.assigneeUserId===y&&"bg-accent"),onClick:O=>{O.preventDefault(),O.stopPropagation(),ce(P.id,null,y)},children:[e.jsx(dn,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{children:"Me"})]}),(r??[]).filter(O=>S.trim()?O.name.toLowerCase().includes(S.toLowerCase()):!0).map(O=>e.jsx("button",{className:z("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",P.assigneeAgentId===O.id&&"bg-accent"),onClick:te=>{te.preventDefault(),te.stopPropagation(),ce(P.id,O.id,null)},children:e.jsx(qe,{name:O.name,size:"sm",className:"min-w-0"})},O.id))]})]})]})]}),trailingMeta:Gs(P.createdAt)},P.id))})]},I.key))]})}function nd({goal:t,children:s,allGoals:n,depth:r,goalLink:a,onSelect:i,onDelete:o}){const[l,u]=c.useState(!0),d=s.length>0,m=a==null?void 0:a(t),x=e.jsxs(e.Fragment,{children:[d?e.jsx("button",{className:"p-0.5",onClick:h=>{h.preventDefault(),h.stopPropagation(),u(!l)},children:e.jsx(Js,{className:z("h-3 w-3 transition-transform",l&&"rotate-90")})}):e.jsx("span",{className:"w-4"}),e.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:t.level}),e.jsx("span",{className:"flex-1 truncate",children:t.title}),e.jsx(Se,{status:t.status}),o&&e.jsxs(ia,{children:[e.jsx(oa,{asChild:!0,children:e.jsx("button",{className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-accent",onClick:h=>{h.preventDefault(),h.stopPropagation()},children:e.jsx(Tl,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),e.jsx(la,{align:"end",children:e.jsxs(Us,{className:"text-destructive focus:text-destructive gap-2",onClick:h=>{h.stopPropagation(),o(t)},children:[e.jsx(js,{className:"h-3.5 w-3.5"}),"Delete goal"]})})]})]}),p=z("group flex items-center gap-2 px-3 py-1.5 text-sm transition-colors cursor-pointer hover:bg-accent/50");return e.jsxs("div",{children:[m?e.jsx(xe,{to:m,className:z(p,"no-underline text-inherit"),style:{paddingLeft:`${r*16+12}px`},children:x}):e.jsx("div",{className:p,style:{paddingLeft:`${r*16+12}px`},onClick:()=>i==null?void 0:i(t),children:x}),d&&l&&e.jsx("div",{children:s.map(h=>e.jsx(nd,{goal:h,children:n.filter(j=>j.parentId===h.id),allGoals:n,depth:r+1,goalLink:a,onSelect:i,onDelete:o},h.id))})]})}function Ui({goals:t,goalLink:s,onSelect:n,onDelete:r}){const a=new Set(t.map(o=>o.id)),i=t.filter(o=>!o.parentId||!a.has(o.parentId));return t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No goals."}):e.jsx("div",{className:"border border-border py-1",children:i.map(o=>e.jsx(nd,{goal:o,children:t.filter(l=>l.parentId===o.id),allGoals:t,depth:0,goalLink:s,onSelect:n,onDelete:r},o.id))})}function kr(t){return typeof t=="string"&&t.startsWith("plugin:")}function mf(t,s){const n=t.split("/").filter(Boolean),r=n.indexOf("projects");if(r===-1||n[r+1]!==s)return null;const a=n[r+2];return a==="overview"?"overview":a==="configuration"?"configuration":a==="budget"?"budget":a==="issues"?"list":null}function xf({project:t,goals:s,onUpdate:n,imageUploadHandler:r}){return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Rs,{value:t.description??"",onSave:a=>n({description:a}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0,imageUploadHandler:r}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),e.jsx("div",{className:"mt-1",children:e.jsx(Se,{status:t.status})})]}),t.targetDate&&e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Target Date"}),e.jsx("p",{children:t.targetDate})]})]}),s&&s.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:"Goals"}),e.jsx(Ui,{goals:s,goalLink:a=>`/goals/${a.id}`})]})]})}function hf({currentColor:t,onSelect:s}){const[n,r]=c.useState(!1),a=c.useRef(null);return c.useEffect(()=>{if(!n)return;function i(o){a.current&&!a.current.contains(o.target)&&r(!1)}return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[n]),e.jsxs("div",{className:"relative",ref:a,children:[e.jsx("button",{onClick:()=>r(!n),className:"shrink-0 h-5 w-5 rounded-md cursor-pointer hover:ring-2 hover:ring-foreground/20 transition-[box-shadow]",style:{backgroundColor:t},"aria-label":"Change project color"}),n&&e.jsx("div",{className:"absolute top-full left-0 mt-2 p-2 bg-popover border border-border rounded-lg shadow-lg z-50 w-max",children:e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Ka.map(i=>e.jsx("button",{onClick:()=>{s(i),r(!1)},className:`h-6 w-6 rounded-md cursor-pointer transition-[transform,box-shadow] duration-150 hover:scale-110 ${i===t?"ring-2 ring-foreground ring-offset-1 ring-offset-background":"hover:ring-2 hover:ring-foreground/30"}`,style:{backgroundColor:i},"aria-label":`Select color ${i}`},i))})})]})}function pf({projectId:t,companyId:s}){const n=Le(),{data:r}=V({queryKey:E.agents.list(s),queryFn:()=>Ee.list(s),enabled:!!s}),{data:a}=V({queryKey:E.liveRuns(s),queryFn:()=>Ht.liveRunsForCompany(s),enabled:!!s,refetchInterval:5e3}),i=c.useMemo(()=>{const m=new Set;for(const x of a??[])x.issueId&&m.add(x.issueId);return m},[a]),{data:o,isLoading:l,error:u}=V({queryKey:E.issues.listByProject(s,t),queryFn:()=>ht.list(s,{projectId:t}),enabled:!!s}),d=se({mutationFn:({id:m,data:x})=>ht.update(m,x),onSuccess:()=>{n.invalidateQueries({queryKey:E.issues.listByProject(s,t)}),n.invalidateQueries({queryKey:E.issues.list(s)})}});return e.jsx(sd,{issues:o??[],isLoading:l,error:u,agents:r,liveIssueIds:i,projectId:t,viewStateKey:`paperclip:project-view:${t}`,onUpdateIssue:(m,x)=>d.mutate({id:m,data:x})})}function an(){const{companyPrefix:t,projectId:s,filter:n}=$s(),{companies:r,selectedCompanyId:a,setSelectedCompanyId:i}=he(),{closePanel:o}=ra(),{setBreadcrumbs:l}=Me(),{pushToast:u}=ji(),d=Le(),m=Mt(),x=bt(),[p,h]=c.useState({}),j=c.useRef({}),y=c.useRef({}),f=s??"",A=c.useMemo(()=>{var ae;if(!t)return null;const L=t.toUpperCase();return((ae=r.find(le=>le.issuePrefix.toUpperCase()===L))==null?void 0:ae.id)??null},[r,t])??a??void 0,N=f.length>0&&(lu(f)||!!A),C=f?mf(x.pathname,f):null,S=c.useMemo(()=>{const L=new URLSearchParams(x.search).get("tab");return kr(L)?L:null},[x.search]),b=C??S,{data:v,isLoading:M,error:k}=V({queryKey:[...E.projects.detail(f),A??null],queryFn:()=>lt.get(f,A),enabled:N}),_=v?xl(v):f,U=(v==null?void 0:v.id)??f,w=(v==null?void 0:v.companyId)??a,{slots:T,isLoading:W}=xi({slotTypes:["detailTab"],entityType:"project",enabled:!!w}),H=c.useMemo(()=>T.map(L=>({value:`plugin:${L.pluginKey}:${L.id}`,label:L.displayName,slot:L})),[T]),B=H.find(L=>L.value===b)??null;c.useEffect(()=>{!(v!=null&&v.companyId)||v.companyId===a||i(v.companyId,{source:"route_sync"})},[v==null?void 0:v.companyId,a,i]);const D=()=>{d.invalidateQueries({queryKey:E.projects.detail(f)}),d.invalidateQueries({queryKey:E.projects.detail(U)}),w&&d.invalidateQueries({queryKey:E.projects.list(w)})},Z=se({mutationFn:L=>lt.update(U,L,w??A),onSuccess:D}),G=se({mutationFn:L=>lt.update(U,{archivedAt:L?new Date().toISOString():null},w??A),onSuccess:(L,ae)=>{D();const le=(L==null?void 0:L.name)??(v==null?void 0:v.name)??"Project";ae?(u({title:`"${le}" has been archived`,tone:"success"}),m("/dashboard")):u({title:`"${le}" has been unarchived`,tone:"success"})},onError:(L,ae)=>{u({title:ae?"Failed to archive project":"Failed to unarchive project",tone:"error"})}}),ie=se({mutationFn:async L=>{if(!w)throw new Error("No company selected");return or.uploadImage(w,L,`projects/${U||"draft"}`)}}),{data:ce}=V({queryKey:E.budgets.overview(w??"__none__"),queryFn:()=>Un.overview(w),enabled:!!w,refetchInterval:3e4,staleTime:5e3}),{data:q}=V({queryKey:E.goals.list(w??"__none__"),queryFn:()=>Et.list(w),enabled:!!w&&b==="overview",staleTime:3e4}),J=c.useMemo(()=>{const L=new Set((v==null?void 0:v.goalIds)??[]);return(q??[]).filter(ae=>L.has(ae.id))},[q,v]);c.useEffect(()=>{l([{label:"Projects",href:"/projects"},{label:(v==null?void 0:v.name)??f??"Project"}])},[l,v,f]),c.useEffect(()=>{if(v&&f!==_){if(kr(b)){m(`/projects/${_}?tab=${encodeURIComponent(b)}`,{replace:!0});return}if(b==="overview"){m(`/projects/${_}/overview`,{replace:!0});return}if(b==="configuration"){m(`/projects/${_}/configuration`,{replace:!0});return}if(b==="budget"){m(`/projects/${_}/budget`,{replace:!0});return}if(b==="list"){if(n){m(`/projects/${_}/issues/${n}`,{replace:!0});return}m(`/projects/${_}/issues`,{replace:!0});return}m(`/projects/${_}`,{replace:!0})}},[v,f,_,b,n,m]),c.useEffect(()=>(o(),()=>o()),[o]),c.useEffect(()=>()=>{Object.values(y.current).forEach(L=>{L&&clearTimeout(L)})},[]);const I=c.useCallback((L,ae)=>{h(le=>({...le,[L]:ae}))},[]),P=c.useCallback((L,ae)=>{const le=y.current[L];le&&clearTimeout(le),y.current[L]=setTimeout(()=>{h(Re=>{const ee={...Re};return delete ee[L],ee}),delete y.current[L]},ae)},[]),O=c.useCallback(async(L,ae)=>{const le=(j.current[L]??0)+1;j.current[L]=le,I(L,"saving");try{if(await lt.update(U,ae,w??A),D(),j.current[L]!==le)return;I(L,"saved"),P(L,1800)}catch(Re){if(j.current[L]!==le)return;throw I(L,"error"),P(L,3e3),Re}},[D,A,U,w,P,I]),te=c.useMemo(()=>{const L=ce==null?void 0:ce.policies.find(ae=>ae.scopeType==="project"&&ae.scopeId===((v==null?void 0:v.id)??f));return L||{policyId:"",companyId:w??"",scopeType:"project",scopeId:(v==null?void 0:v.id)??f,scopeName:(v==null?void 0:v.name)??"Project",metric:"billed_cents",windowKind:"lifetime",amount:0,observedAmount:0,remainingAmount:0,utilizationPercent:0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:!1,status:"ok",paused:!!(v!=null&&v.pausedAt),pauseReason:(v==null?void 0:v.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[ce==null?void 0:ce.policies,v,w,f]),oe=se({mutationFn:L=>Un.upsertPolicy(w,{scopeType:"project",scopeId:(v==null?void 0:v.id)??f,amount:L,windowKind:"lifetime"}),onSuccess:()=>{w&&(d.invalidateQueries({queryKey:E.budgets.overview(w)}),d.invalidateQueries({queryKey:E.projects.detail(f)}),d.invalidateQueries({queryKey:E.projects.detail(U)}),d.invalidateQueries({queryKey:E.projects.list(w)}),d.invalidateQueries({queryKey:E.dashboard(w)}))}});if(S&&!W&&!B)return e.jsx(ke,{to:`/projects/${_}/issues`,replace:!0});if(f&&b===null){let L=null;if(v!=null&&v.id)try{L=localStorage.getItem(`paperclip:project-tab:${v.id}`)}catch{}return L==="overview"?e.jsx(ke,{to:`/projects/${_}/overview`,replace:!0}):L==="configuration"?e.jsx(ke,{to:`/projects/${_}/configuration`,replace:!0}):L==="budget"?e.jsx(ke,{to:`/projects/${_}/budget`,replace:!0}):kr(L)?e.jsx(ke,{to:`/projects/${_}?tab=${encodeURIComponent(L)}`,replace:!0}):e.jsx(ke,{to:`/projects/${_}/overview`,replace:!0})}if(M)return e.jsx(rt,{variant:"detail"});if(k)return e.jsx("p",{className:"text-sm text-destructive",children:k.message});if(!v)return null;const ue=L=>{if(v!=null&&v.id)try{localStorage.setItem(`paperclip:project-tab:${v.id}`,L)}catch{}if(kr(L)){m(`/projects/${_}?tab=${encodeURIComponent(L)}`);return}m(L==="overview"?`/projects/${_}/overview`:L==="budget"?`/projects/${_}/budget`:L==="configuration"?`/projects/${_}/configuration`:`/projects/${_}/issues`)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-7 flex items-center",children:e.jsx(hf,{currentColor:v.color??"#6366f1",onSelect:L=>Z.mutate({color:L})})}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx(Rs,{value:v.name,onSave:L=>Z.mutate({name:L}),as:"h2",className:"text-xl font-bold"}),v.pauseReason==="budget"?e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-red-500/30 bg-red-500/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-red-200",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-red-400"}),"Paused by budget hard stop"]}):null]})]}),e.jsx(Rr,{slotTypes:["toolbarButton","contextMenuItem"],entityType:"project",context:{companyId:w??null,companyPrefix:t??null,projectId:v.id,projectRef:_,entityId:v.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex",missingBehavior:"placeholder"}),e.jsx(cu,{placementZones:["toolbarButton"],entityType:"project",context:{companyId:w??null,companyPrefix:t??null,projectId:v.id,projectRef:_,entityId:v.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex"}),e.jsx(Ut,{value:b??"overview",onValueChange:L=>ue(L),children:e.jsx(Hs,{items:[{value:"overview",label:"Overview"},{value:"list",label:"Issues"},{value:"configuration",label:"Configuration"},{value:"budget",label:"Budget"},...H.map(L=>({value:L.value,label:L.label}))],align:"start",value:b??"overview",onValueChange:L=>ue(L)})}),b==="overview"&&e.jsx(xf,{project:v,goals:J,onUpdate:L=>Z.mutate(L),imageUploadHandler:async L=>(await ie.mutateAsync(L)).contentPath}),b==="list"&&(v==null?void 0:v.id)&&w&&e.jsx(pf,{projectId:v.id,companyId:w}),b==="configuration"&&e.jsx("div",{className:"max-w-4xl",children:e.jsx(tf,{project:v,onUpdate:L=>Z.mutate(L),onFieldUpdate:O,getFieldSaveState:L=>p[L]??"idle",onArchive:L=>G.mutate(L),archivePending:G.isPending})}),b==="budget"&&w?e.jsx("div",{className:"max-w-3xl",children:e.jsx(Ml,{summary:te,variant:"plain",isSaving:oe.isPending,onSave:L=>oe.mutate(L)})}):null,B&&e.jsx(sa,{slot:B.slot,context:{companyId:w,companyPrefix:t??null,projectId:v.id,projectRef:_,entityId:v.id,entityType:"project"},missingBehavior:"placeholder"})]})}function gf(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),n=bt(),[r]=vi(),a=Le(),i=r.get("q")??"",o=c.useRef(void 0),l=c.useCallback(f=>{clearTimeout(o.current),o.current=setTimeout(()=>{const g=f.trim();if((new URLSearchParams(window.location.search).get("q")??"")===g)return;const N=new URL(window.location.href);g?N.searchParams.set("q",g):N.searchParams.delete("q");const C=`${N.pathname}${N.search}${N.hash}`;window.history.replaceState(window.history.state,"",C)},300)},[]);c.useEffect(()=>()=>clearTimeout(o.current),[]);const{data:u}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t}),{data:d}=V({queryKey:E.liveRuns(t),queryFn:()=>Ht.liveRunsForCompany(t),enabled:!!t,refetchInterval:5e3}),m=c.useMemo(()=>{const f=new Set;for(const g of d??[])g.issueId&&f.add(g.issueId);return f},[d]),x=c.useMemo(()=>_l("Issues",`${n.pathname}${n.search}${n.hash}`),[n.pathname,n.search,n.hash]);c.useEffect(()=>{s([{label:"Issues"}])},[s]);const{data:p,isLoading:h,error:j}=V({queryKey:E.issues.list(t),queryFn:()=>ht.list(t),enabled:!!t}),y=se({mutationFn:({id:f,data:g})=>ht.update(f,g),onSuccess:()=>{a.invalidateQueries({queryKey:E.issues.list(t)})}});return t?e.jsx(sd,{issues:p??[],isLoading:h,error:j,agents:u,liveIssueIds:m,viewStateKey:"paperclip:issues-view",issueLinkState:x,initialAssignees:r.get("assignee")?[r.get("assignee")]:void 0,initialSearch:i,onSearchChange:l,onUpdateIssue:(f,g)=>y.mutate({id:f,data:g})}):e.jsx(Be,{icon:Ct,message:"Select a company to view issues."})}function ff(t){if(!t)return!1;try{const s=new URL(t);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}}function es({label:t,children:s}){return e.jsxs("div",{className:"flex items-start gap-3 py-1.5",children:[e.jsx("div",{className:"w-28 shrink-0 text-xs text-muted-foreground",children:t}),e.jsx("div",{className:"min-w-0 flex-1 text-sm",children:s})]})}function bf(){const{workspaceId:t}=$s(),{data:s,isLoading:n,error:r}=V({queryKey:E.executionWorkspaces.detail(t),queryFn:()=>du.get(t),enabled:!!t});return n?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading..."}):r?e.jsx("p",{className:"text-sm text-destructive",children:r instanceof Error?r.message:"Failed to load workspace"}):s?e.jsxs("div",{className:"max-w-2xl space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Execution workspace"}),e.jsx("h1",{className:"text-2xl font-semibold",children:s.name}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.status," · ",s.mode," · ",s.providerType]})]}),e.jsxs("div",{className:"rounded-lg border border-border p-4",children:[e.jsx(es,{label:"Project",children:s.projectId?e.jsx(xe,{to:`/projects/${s.projectId}`,className:"hover:underline",children:s.projectId}):"None"}),e.jsx(es,{label:"Source issue",children:s.sourceIssueId?e.jsx(xe,{to:`/issues/${s.sourceIssueId}`,className:"hover:underline",children:s.sourceIssueId}):"None"}),e.jsx(es,{label:"Branch",children:s.branchName??"None"}),e.jsx(es,{label:"Base ref",children:s.baseRef??"None"}),e.jsx(es,{label:"Working dir",children:e.jsx("span",{className:"break-all font-mono text-xs",children:s.cwd??"None"})}),e.jsx(es,{label:"Provider ref",children:e.jsx("span",{className:"break-all font-mono text-xs",children:s.providerRef??"None"})}),e.jsx(es,{label:"Repo URL",children:s.repoUrl&&ff(s.repoUrl)?e.jsxs("a",{href:s.repoUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 hover:underline",children:[s.repoUrl,e.jsx(En,{className:"h-3 w-3"})]}):s.repoUrl?e.jsx("span",{className:"break-all font-mono text-xs",children:s.repoUrl}):"None"}),e.jsx(es,{label:"Opened",children:new Date(s.openedAt).toLocaleString()}),e.jsx(es,{label:"Last used",children:new Date(s.lastUsedAt).toLocaleString()}),e.jsx(es,{label:"Cleanup",children:s.cleanupEligibleAt?`${new Date(s.cleanupEligibleAt).toLocaleString()}${s.cleanupReason?` · ${s.cleanupReason}`:""}`:"Not scheduled"})]})]}):null}function jf(){const{selectedCompanyId:t}=he(),{openNewGoal:s}=Ve(),{setBreadcrumbs:n}=Me(),r=Le();c.useEffect(()=>{n([{label:"Goals"}])},[n]);const{data:a,isLoading:i,error:o}=V({queryKey:E.goals.list(t),queryFn:()=>Et.list(t),enabled:!!t}),l=se({mutationFn:d=>Et.remove(d.id),onSuccess:()=>{r.invalidateQueries({queryKey:E.goals.list(t)})}}),u=d=>{confirm(`Delete "${d.title}"? This cannot be undone.`)&&l.mutate(d)};return t?i?e.jsx(rt,{variant:"list"}):e.jsxs("div",{className:"space-y-4",children:[o&&e.jsx("p",{className:"text-sm text-destructive",children:o.message}),a&&a.length===0&&e.jsx(Be,{icon:ls,message:"No goals yet.",action:"Add Goal",onAction:()=>s()}),a&&a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-start",children:e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>s(),children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-1.5"}),"New Goal"]})}),e.jsx(Ui,{goals:a,goalLink:d=>`/goals/${d.id}`,onDelete:u})]})]}):e.jsx(Be,{icon:ls,message:"Select a company to view goals."})}function on({label:t,children:s}){return e.jsxs("div",{className:"flex items-center gap-3 py-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground shrink-0 w-20",children:t}),e.jsx("div",{className:"flex items-center gap-1.5 min-w-0",children:s})]})}function vf(t){return t.replace(/_/g," ").replace(/\b\w/g,s=>s.toUpperCase())}function zo({current:t,options:s,onChange:n,children:r}){const[a,i]=c.useState(!1);return e.jsxs(pt,{open:a,onOpenChange:i,children:[e.jsx(gt,{asChild:!0,children:e.jsx("button",{className:"cursor-pointer hover:opacity-80 transition-opacity",children:r})}),e.jsx(ft,{className:"w-40 p-1",align:"end",children:s.map(o=>e.jsx(F,{variant:"ghost",size:"sm",className:z("w-full justify-start text-xs",o===t&&"bg-accent"),onClick:()=>{n(o),i(!1)},children:vf(o)},o))})]})}function yf({goal:t,onUpdate:s}){const{selectedCompanyId:n}=he(),{data:r}=V({queryKey:E.agents.list(n),queryFn:()=>Ee.list(n),enabled:!!n}),{data:a}=V({queryKey:E.goals.list(n),queryFn:()=>Et.list(n),enabled:!!n}),i=t.ownerAgentId?r==null?void 0:r.find(l=>l.id===t.ownerAgentId):null,o=t.parentId?a==null?void 0:a.find(l=>l.id===t.parentId):null;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(on,{label:"Status",children:s?e.jsx(zo,{current:t.status,options:yl,onChange:l=>s({status:l}),children:e.jsx(Se,{status:t.status})}):e.jsx(Se,{status:t.status})}),e.jsx(on,{label:"Level",children:s?e.jsx(zo,{current:t.level,options:Nl,onChange:l=>s({level:l}),children:e.jsx("span",{className:"text-sm capitalize",children:t.level})}):e.jsx("span",{className:"text-sm capitalize",children:t.level})}),e.jsx(on,{label:"Owner",children:i?e.jsx(xe,{to:Xs(i),className:"text-sm hover:underline",children:i.name}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"None"})}),t.parentId&&e.jsx(on,{label:"Parent Goal",children:e.jsx(xe,{to:`/goals/${t.parentId}`,className:"text-sm hover:underline",children:(o==null?void 0:o.title)??t.parentId.slice(0,8)})})]}),e.jsx(Rt,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(on,{label:"Created",children:e.jsx("span",{className:"text-sm",children:Gs(t.createdAt)})}),e.jsx(on,{label:"Updated",children:e.jsx("span",{className:"text-sm",children:Gs(t.updatedAt)})})]})]})}function Nf(){const{goalId:t}=$s(),{selectedCompanyId:s,setSelectedCompanyId:n}=he(),{openNewGoal:r}=Ve(),{openPanel:a,closePanel:i}=ra(),{setBreadcrumbs:o}=Me(),l=Le(),u=Mt(),{data:d,isLoading:m,error:x}=V({queryKey:E.goals.detail(t),queryFn:()=>Et.get(t),enabled:!!t}),p=(d==null?void 0:d.companyId)??s,{data:h}=V({queryKey:E.goals.list(p),queryFn:()=>Et.list(p),enabled:!!p}),{data:j}=V({queryKey:E.projects.list(p),queryFn:()=>lt.list(p),enabled:!!p});c.useEffect(()=>{!(d!=null&&d.companyId)||d.companyId===s||n(d.companyId,{source:"route_sync"})},[d==null?void 0:d.companyId,s,n]);const y=se({mutationFn:S=>Et.update(t,S),onSuccess:()=>{l.invalidateQueries({queryKey:E.goals.detail(t)}),p&&l.invalidateQueries({queryKey:E.goals.list(p)})}}),f=se({mutationFn:()=>Et.remove(t),onSuccess:()=>{p&&l.invalidateQueries({queryKey:E.goals.list(p)}),u("/goals")}}),g=se({mutationFn:S=>lt.update(S.id,{goalIds:[...S.goalIds??[],t]}),onSuccess:()=>{p&&l.invalidateQueries({queryKey:E.projects.list(p)})}}),A=se({mutationFn:async S=>{if(!p)throw new Error("No company selected");return or.uploadImage(p,S,`goals/${t??"draft"}`)}}),N=(h??[]).filter(S=>S.parentId===t),C=(j??[]).filter(S=>t?S.goalIds.includes(t)||S.goals.some(b=>b.id===t)?!0:S.goalId===t:!1);return c.useEffect(()=>{o([{label:"Goals",href:"/goals"},{label:(d==null?void 0:d.title)??t??"Goal"}])},[o,d,t]),c.useEffect(()=>(d&&a(e.jsx(yf,{goal:d,onUpdate:S=>y.mutate(S)})),()=>i()),[d]),m?e.jsx(rt,{variant:"detail"}):x?e.jsx("p",{className:"text-sm text-destructive",children:x.message}):d?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs uppercase text-muted-foreground",children:d.level}),e.jsx(Se,{status:d.status})]}),e.jsx(F,{size:"sm",variant:"ghost",className:"text-muted-foreground hover:text-destructive hover:bg-destructive/10 h-7 w-7 p-0",onClick:()=>{confirm("Delete this goal? This cannot be undone.")&&f.mutate()},disabled:f.isPending,children:e.jsx(js,{className:"h-3.5 w-3.5"})})]}),e.jsx(Rs,{value:d.title,onSave:S=>y.mutate({title:S}),as:"h2",className:"text-xl font-bold"}),e.jsx(Rs,{value:d.description??"",onSave:S=>y.mutate({description:S}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0,imageUploadHandler:async S=>(await A.mutateAsync(S)).contentPath})]}),e.jsxs(Ut,{defaultValue:"children",children:[e.jsxs(_r,{children:[e.jsxs(kt,{value:"children",children:["Sub-Goals (",N.length,")"]}),e.jsxs(kt,{value:"projects",children:["Projects (",C.length,")"]})]}),e.jsxs(Oe,{value:"children",className:"mt-4 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-start",children:e.jsxs(F,{size:"sm",variant:"outline",onClick:()=>r({parentId:t}),children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-1.5"}),"Sub Goal"]})}),N.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No sub-goals."}):e.jsx(Ui,{goals:N,goalLink:S=>`/goals/${S.id}`})]}),e.jsxs(Oe,{value:"projects",className:"mt-4 space-y-3",children:[(()=>{const S=new Set(C.map(v=>v.id)),b=(j??[]).filter(v=>!S.has(v.id));return e.jsx("div",{className:"flex items-center justify-start",children:e.jsxs(ia,{children:[e.jsx(oa,{asChild:!0,children:e.jsxs(F,{size:"sm",variant:"outline",disabled:b.length===0,children:[e.jsx(hx,{className:"h-3.5 w-3.5 mr-1.5"}),"Link Project"]})}),e.jsx(la,{align:"start",className:"max-h-64 overflow-y-auto",children:b.map(v=>e.jsx(Us,{onClick:()=>g.mutate(v),children:v.name},v.id))})]})})})(),C.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No linked projects."}):e.jsx("div",{className:"border border-border",children:C.map(S=>e.jsx(ps,{title:S.name,subtitle:S.description??void 0,to:hi(S),trailing:e.jsx(Se,{status:S.status})},S.id))})]})]})]}):null}const wf={hire_agent:"Hire Agent",approve_ceo_strategy:"CEO Strategy",budget_override_required:"Budget Override"};function Gi(t,s){const n=wf[t]??t;return t==="hire_agent"&&(s!=null&&s.name)?`${n}: ${String(s.name)}`:n}const Wi={hire_agent:Dx,approve_ceo_strategy:uu,budget_override_required:Dl},Vi=Ai;function Ws({label:t,value:s}){return s?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs",children:t}),e.jsx("span",{children:String(s)})]}):null}function kf({payload:t}){return e.jsxs("div",{className:"mt-3 space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs",children:"Name"}),e.jsx("span",{className:"font-medium",children:String(t.name??"—")})]}),e.jsx(Ws,{label:"Role",value:t.role}),e.jsx(Ws,{label:"Title",value:t.title}),e.jsx(Ws,{label:"Icon",value:t.icon}),!!t.capabilities&&e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs pt-0.5",children:"Capabilities"}),e.jsx("span",{className:"text-muted-foreground",children:String(t.capabilities)})]}),!!t.adapterType&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground w-20 sm:w-24 shrink-0 text-xs",children:"Adapter"}),e.jsx("span",{className:"font-mono text-xs bg-muted px-1.5 py-0.5 rounded",children:String(t.adapterType)})]})]})}function Cf({payload:t}){const s=t.plan??t.description??t.strategy??t.text;return e.jsxs("div",{className:"mt-3 space-y-1.5 text-sm",children:[e.jsx(Ws,{label:"Title",value:t.title}),!!s&&e.jsx("div",{className:"mt-2 rounded-md bg-muted/40 px-3 py-2 text-sm text-muted-foreground whitespace-pre-wrap font-mono text-xs max-h-48 overflow-y-auto",children:String(s)}),!s&&e.jsx("pre",{className:"mt-2 rounded-md bg-muted/40 px-3 py-2 text-xs text-muted-foreground overflow-x-auto max-h-48",children:JSON.stringify(t,null,2)})]})}function Sf({payload:t}){const s=typeof t.budgetAmount=="number"?t.budgetAmount:null,n=typeof t.observedAmount=="number"?t.observedAmount:null;return e.jsxs("div",{className:"mt-3 space-y-1.5 text-sm",children:[e.jsx(Ws,{label:"Scope",value:t.scopeName??t.scopeType}),e.jsx(Ws,{label:"Window",value:t.windowKind}),e.jsx(Ws,{label:"Metric",value:t.metric}),s!==null||n!==null?e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2 text-xs text-muted-foreground",children:["Limit ",s!==null?re(s):"—"," · Observed ",n!==null?re(n):"—"]}):null,!!t.guidance&&e.jsx("p",{className:"text-muted-foreground",children:String(t.guidance)})]})}function rd({type:t,payload:s}){return t==="hire_agent"?e.jsx(kf,{payload:s}):t==="budget_override_required"?e.jsx(Sf,{payload:s}):e.jsx(Cf,{payload:s})}function If(t){return t==="approved"?e.jsx(yi,{className:"h-3.5 w-3.5 text-green-600 dark:text-green-400"}):t==="rejected"?e.jsx(Ni,{className:"h-3.5 w-3.5 text-red-600 dark:text-red-400"}):t==="revision_requested"?e.jsx(Va,{className:"h-3.5 w-3.5 text-amber-600 dark:text-amber-400"}):t==="pending"?e.jsx(Va,{className:"h-3.5 w-3.5 text-yellow-600 dark:text-yellow-400"}):null}function Af({approval:t,requesterAgent:s,onApprove:n,onReject:r,onOpen:a,detailLink:i,isPending:o}){const l=Wi[t.type]??Vi,u=Gi(t.type,t.payload),d=t.type!=="budget_override_required"&&(t.status==="pending"||t.status==="revision_requested");return e.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(l,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:u}),s&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["requested by ",e.jsx(qe,{name:s.name,size:"sm",className:"inline-flex"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[If(t.status),e.jsx("span",{className:"text-xs text-muted-foreground capitalize",children:t.status}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",Lt(t.createdAt)]})]})]}),e.jsx(rd,{type:t.type,payload:t.payload}),t.decisionNote&&e.jsxs("div",{className:"mt-3 text-xs text-muted-foreground italic border-t border-border pt-2",children:["Note: ",t.decisionNote]}),d&&e.jsxs("div",{className:"flex gap-2 mt-4 pt-3 border-t border-border",children:[e.jsx(F,{size:"sm",className:"bg-green-700 hover:bg-green-600 text-white",onClick:n,disabled:o,children:"Approve"}),e.jsx(F,{variant:"destructive",size:"sm",onClick:r,disabled:o,children:"Reject"})]}),e.jsx("div",{className:"mt-3",children:i?e.jsx(F,{variant:"ghost",size:"sm",className:"text-xs px-0",asChild:!0,children:e.jsx(xe,{to:i,children:"View details"})}):e.jsx(F,{variant:"ghost",size:"sm",className:"text-xs px-0",onClick:a,children:"View details"})})]})}function Ko(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),n=Le(),r=Mt(),o=(bt().pathname.split("/").pop()??"pending")==="all"?"all":"pending",[l,u]=c.useState(null);c.useEffect(()=>{s([{label:"Approvals"}])},[s]);const{data:d,isLoading:m,error:x}=V({queryKey:E.approvals.list(t),queryFn:()=>ut.list(t),enabled:!!t}),{data:p}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t}),h=se({mutationFn:g=>ut.approve(g),onSuccess:(g,A)=>{u(null),n.invalidateQueries({queryKey:E.approvals.list(t)}),r(`/approvals/${A}?resolved=approved`)},onError:g=>{u(g instanceof Error?g.message:"Failed to approve")}}),j=se({mutationFn:g=>ut.reject(g),onSuccess:()=>{u(null),n.invalidateQueries({queryKey:E.approvals.list(t)})},onError:g=>{u(g instanceof Error?g.message:"Failed to reject")}}),y=(d??[]).filter(g=>o==="all"||g.status==="pending"||g.status==="revision_requested").sort((g,A)=>new Date(A.createdAt).getTime()-new Date(g.createdAt).getTime()),f=(d??[]).filter(g=>g.status==="pending"||g.status==="revision_requested").length;return t?m?e.jsx(rt,{variant:"approvals"}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(Ut,{value:o,onValueChange:g=>r(`/approvals/${g}`),children:e.jsx(Hs,{items:[{value:"pending",label:e.jsxs(e.Fragment,{children:["Pending",f>0&&e.jsx("span",{className:z("ml-1.5 rounded-full px-1.5 py-0.5 text-[10px] font-medium","bg-yellow-500/20 text-yellow-500"),children:f})]})},{value:"all",label:"All"}]})})}),x&&e.jsx("p",{className:"text-sm text-destructive",children:x.message}),l&&e.jsx("p",{className:"text-sm text-destructive",children:l}),y.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(Ai,{className:"h-8 w-8 text-muted-foreground/30 mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o==="pending"?"No pending approvals.":"No approvals yet."})]}),y.length>0&&e.jsx("div",{className:"grid gap-3",children:y.map(g=>e.jsx(Af,{approval:g,requesterAgent:g.requestedByAgentId?(p??[]).find(A=>A.id===g.requestedByAgentId)??null:null,onApprove:()=>h.mutate(g.id),onReject:()=>j.mutate(g.id),detailLink:`/approvals/${g.id}`,isPending:h.isPending||j.isPending},g.id))})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a company first."})}function Tf(){const{approvalId:t}=$s(),{selectedCompanyId:s,setSelectedCompanyId:n}=he(),{setBreadcrumbs:r}=Me(),a=Mt(),[i]=vi(),o=Le(),[l,u]=c.useState(""),[d,m]=c.useState(null),[x,p]=c.useState(!1),{data:h,isLoading:j}=V({queryKey:E.approvals.detail(t),queryFn:()=>ut.get(t),enabled:!!t}),y=(h==null?void 0:h.companyId)??s,{data:f}=V({queryKey:E.approvals.comments(t),queryFn:()=>ut.listComments(t),enabled:!!t}),{data:g}=V({queryKey:E.approvals.issues(t),queryFn:()=>ut.listIssues(t),enabled:!!t}),{data:A}=V({queryKey:E.agents.list(y??""),queryFn:()=>Ee.list(y??""),enabled:!!y});c.useEffect(()=>{!(h!=null&&h.companyId)||h.companyId===s||n(h.companyId,{source:"route_sync"})},[h==null?void 0:h.companyId,s,n]);const N=c.useMemo(()=>{const G=new Map;for(const ie of A??[])G.set(ie.id,ie.name);return G},[A]);c.useEffect(()=>{var G;r([{label:"Approvals",href:"/approvals"},{label:((G=h==null?void 0:h.id)==null?void 0:G.slice(0,8))??t??"Approval"}])},[r,h,t]);const C=()=>{t&&(o.invalidateQueries({queryKey:E.approvals.detail(t)}),o.invalidateQueries({queryKey:E.approvals.comments(t)}),o.invalidateQueries({queryKey:E.approvals.issues(t)}),h!=null&&h.companyId&&(o.invalidateQueries({queryKey:E.approvals.list(h.companyId)}),o.invalidateQueries({queryKey:E.approvals.list(h.companyId,"pending")}),o.invalidateQueries({queryKey:E.agents.list(h.companyId)})))},S=se({mutationFn:()=>ut.approve(t),onSuccess:()=>{m(null),C(),a(`/approvals/${t}?resolved=approved`,{replace:!0})},onError:G=>m(G instanceof Error?G.message:"Approve failed")}),b=se({mutationFn:()=>ut.reject(t),onSuccess:()=>{m(null),C()},onError:G=>m(G instanceof Error?G.message:"Reject failed")}),v=se({mutationFn:()=>ut.requestRevision(t),onSuccess:()=>{m(null),C()},onError:G=>m(G instanceof Error?G.message:"Revision request failed")}),M=se({mutationFn:()=>ut.resubmit(t),onSuccess:()=>{m(null),C()},onError:G=>m(G instanceof Error?G.message:"Resubmit failed")}),k=se({mutationFn:()=>ut.addComment(t,l.trim()),onSuccess:()=>{u(""),m(null),C()},onError:G=>m(G instanceof Error?G.message:"Comment failed")}),_=se({mutationFn:G=>Ee.remove(G),onSuccess:()=>{m(null),C(),a("/approvals")},onError:G=>m(G instanceof Error?G.message:"Delete failed")});if(j)return e.jsx(rt,{variant:"detail"});if(!h)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"Approval not found."});const U=h.payload,w=typeof U.agentId=="string"?U.agentId:null,T=h.status==="pending"||h.status==="revision_requested",W=h.type==="budget_override_required",H=Wi[h.type]??Vi,B=i.get("resolved")==="approved"&&h.status==="approved",D=(g==null?void 0:g[0])??null,Z=D?{label:((g==null?void 0:g.length)??0)>1?"Review linked issues":"Review linked issue",to:`/issues/${D.identifier??D.id}`}:w?{label:"Open hired agent",to:`/agents/${w}`}:{label:"Back to approvals",to:"/approvals"};return e.jsxs("div",{className:"space-y-6 max-w-3xl",children:[B&&e.jsx("div",{className:"border border-green-300 dark:border-green-700/40 bg-green-50 dark:bg-green-900/20 rounded-lg px-4 py-3 animate-in fade-in zoom-in-95 duration-300",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"relative mt-0.5",children:[e.jsx(yi,{className:"h-4 w-4 text-green-600 dark:text-green-300"}),e.jsx(pi,{className:"h-3 w-3 text-green-500 dark:text-green-200 absolute -right-2 -top-1 animate-pulse"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-green-800 dark:text-green-100 font-medium",children:"Approval confirmed"}),e.jsx("p",{className:"text-xs text-green-700 dark:text-green-200/90",children:"Requesting agent was notified to review this approval and linked issues."})]})]}),e.jsx(F,{size:"sm",variant:"outline",className:"border-green-400 dark:border-green-600/50 text-green-800 dark:text-green-100 hover:bg-green-100 dark:hover:bg-green-900/30",onClick:()=>a(Z.to),children:Z.label})]})}),e.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"h-5 w-5 text-muted-foreground shrink-0"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:Gi(h.type,h.payload)}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:h.id})]})]}),e.jsx(Se,{status:h.status})]}),e.jsxs("div",{className:"text-sm space-y-1",children:[h.requestedByAgentId&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Requested by"}),e.jsx(qe,{name:N.get(h.requestedByAgentId)??h.requestedByAgentId.slice(0,8),size:"sm"})]}),e.jsx(rd,{type:h.type,payload:U}),e.jsxs("button",{type:"button",className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors mt-2",onClick:()=>p(G=>!G),children:[e.jsx(Js,{className:`h-3 w-3 transition-transform ${x?"rotate-90":""}`}),"See full request"]}),x&&e.jsx("pre",{className:"text-xs bg-muted/40 rounded-md p-3 overflow-x-auto",children:JSON.stringify(U,null,2)}),h.decisionNote&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Decision note: ",h.decisionNote]})]}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),g&&g.length>0&&e.jsxs("div",{className:"pt-2 border-t border-border/60",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1.5",children:"Linked Issues"}),e.jsx("div",{className:"space-y-1.5",children:g.map(G=>e.jsxs(xe,{to:`/issues/${G.identifier??G.id}`,className:"block text-xs rounded border border-border/70 px-2 py-1.5 hover:bg-accent/20",children:[e.jsx("span",{className:"font-mono text-muted-foreground mr-2",children:G.identifier??G.id.slice(0,8)}),e.jsx("span",{children:G.title})]},G.id))}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-2",children:"Linked issues remain open until the requesting agent follows up and closes them."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[T&&!W&&e.jsxs(e.Fragment,{children:[e.jsx(F,{size:"sm",className:"bg-green-700 hover:bg-green-600 text-white",onClick:()=>S.mutate(),disabled:S.isPending,children:"Approve"}),e.jsx(F,{variant:"destructive",size:"sm",onClick:()=>b.mutate(),disabled:b.isPending,children:"Reject"})]}),W&&h.status==="pending"&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Resolve this budget stop from the budget controls on ",e.jsx(xe,{to:"/costs",className:"underline underline-offset-2",children:"/costs"}),"."]}),h.status==="pending"&&e.jsx(F,{size:"sm",variant:"outline",onClick:()=>v.mutate(),disabled:v.isPending,children:"Request revision"}),h.status==="revision_requested"&&e.jsx(F,{size:"sm",variant:"outline",onClick:()=>M.mutate(),disabled:M.isPending,children:"Mark resubmitted"}),h.status==="rejected"&&h.type==="hire_agent"&&w&&e.jsx(F,{size:"sm",variant:"outline",className:"text-destructive border-destructive/40",onClick:()=>{window.confirm("Delete this disapproved agent? This cannot be undone.")&&_.mutate(w)},disabled:_.isPending,children:"Delete disapproved agent"})]})]}),e.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[e.jsxs("h3",{className:"text-sm font-medium",children:["Comments (",(f==null?void 0:f.length)??0,")"]}),e.jsx("div",{className:"space-y-2",children:(f??[]).map(G=>e.jsxs("div",{className:"border border-border/60 rounded-md p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[G.authorAgentId?e.jsx(xe,{to:`/agents/${G.authorAgentId}`,className:"hover:underline",children:e.jsx(qe,{name:N.get(G.authorAgentId)??G.authorAgentId.slice(0,8),size:"sm"})}):e.jsx(qe,{name:"Board",size:"sm"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(G.createdAt).toLocaleString()})]}),e.jsx(mu,{className:"text-sm",children:G.body})]},G.id))}),e.jsx(un,{value:l,onChange:G=>u(G.target.value),placeholder:"Add a comment...",rows:3}),e.jsx("div",{className:"flex justify-end",children:e.jsx(F,{size:"sm",onClick:()=>k.mutate(),disabled:!l.trim()||k.isPending,children:k.isPending?"Posting…":"Post comment"})})]})]})}function hs(t,s){const n=new URLSearchParams;t&&n.set("from",t),s&&n.set("to",s);const r=n.toString();return r?`?${r}`:""}const yt={summary:(t,s,n)=>Te.get(`/companies/${t}/costs/summary${hs(s,n)}`),byAgent:(t,s,n)=>Te.get(`/companies/${t}/costs/by-agent${hs(s,n)}`),byAgentModel:(t,s,n)=>Te.get(`/companies/${t}/costs/by-agent-model${hs(s,n)}`),byProject:(t,s,n)=>Te.get(`/companies/${t}/costs/by-project${hs(s,n)}`),byProvider:(t,s,n)=>Te.get(`/companies/${t}/costs/by-provider${hs(s,n)}`),byBiller:(t,s,n)=>Te.get(`/companies/${t}/costs/by-biller${hs(s,n)}`),financeSummary:(t,s,n)=>Te.get(`/companies/${t}/costs/finance-summary${hs(s,n)}`),financeByBiller:(t,s,n)=>Te.get(`/companies/${t}/costs/finance-by-biller${hs(s,n)}`),financeByKind:(t,s,n)=>Te.get(`/companies/${t}/costs/finance-by-kind${hs(s,n)}`),financeEvents:(t,s,n,r=100)=>Te.get(`/companies/${t}/costs/finance-events${Pf(s,n,r)}`),windowSpend:t=>Te.get(`/companies/${t}/costs/window-spend`),quotaWindows:t=>Te.get(`/companies/${t}/costs/quota-windows`)};function Pf(t,s,n){const r=new URLSearchParams;t&&r.set("from",t),s&&r.set("to",s),n&&r.set("limit",String(n));const a=r.toString();return a?`?${a}`:""}function Ef(t){return t>90?"bg-red-400":t>70?"bg-yellow-400":"bg-green-400"}function di({label:t,percentUsed:s,leftLabel:n,rightLabel:r,showDeficitNotch:a=!1,className:i}){const o=Math.min(100,Math.max(0,s)),l=Math.min(o,97);return e.jsxs("div",{className:z("space-y-1.5",i),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-xs font-medium tabular-nums",children:n}),r&&e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:r})]})]}),e.jsxs("div",{className:"relative h-2 w-full border border-border overflow-hidden",children:[e.jsx("div",{className:z("absolute inset-y-0 left-0 transition-[width,background-color] duration-150",Ef(o)),style:{width:`${o}%`}}),a&&o>0&&e.jsx("div",{className:"absolute inset-y-0 w-[2px] bg-destructive z-10",style:{left:`${l}%`}})]})]})}function Uo({row:t,weekSpendCents:s,budgetMonthlyCents:n,totalCompanySpendCents:r,providerRows:a}){const i=c.useMemo(()=>{const d=new Map;for(const m of a){const x=d.get(m.provider)??{provider:m.provider,costCents:0,inputTokens:0,outputTokens:0};x.costCents+=m.costCents,x.inputTokens+=m.inputTokens+m.cachedInputTokens,x.outputTokens+=m.outputTokens,d.set(m.provider,x)}return Array.from(d.values()).sort((m,x)=>x.costCents-m.costCents)},[a]),o=c.useMemo(()=>{const d=new Map;for(const m of a)d.set(m.billingType,(d.get(m.billingType)??0)+m.costCents);return Array.from(d.entries()).sort((m,x)=>x[1]-m[1])},[a]),l=n>0&&r>0?t.costCents/r*n:n,u=l>0?Math.min(100,t.costCents/l*100):0;return e.jsxs($e,{children:[e.jsx(Ze,{className:"px-4 pt-4 pb-0 gap-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(et,{className:"text-sm font-semibold",children:Gt(t.biller)}),e.jsxs(xt,{className:"text-xs mt-0.5",children:[e.jsx("span",{className:"font-mono",children:Ge(t.inputTokens+t.cachedInputTokens)})," in"," · ",e.jsx("span",{className:"font-mono",children:Ge(t.outputTokens)})," out"," · ",t.providerCount," provider",t.providerCount===1?"":"s"," · ",t.modelCount," model",t.modelCount===1?"":"s"]})]}),e.jsx("span",{className:"text-xl font-bold tabular-nums shrink-0",children:re(t.costCents)})]})}),e.jsxs(Fe,{className:"px-4 pb-4 pt-3 space-y-4",children:[n>0&&e.jsx(di,{label:"Period spend",percentUsed:u,leftLabel:re(t.costCents),rightLabel:`${Math.round(u)}% of allocation`}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.apiRunCount>0?`${t.apiRunCount} metered run${t.apiRunCount===1?"":"s"}`:"0 metered runs"," · ",t.subscriptionRunCount>0?`${t.subscriptionRunCount} subscription run${t.subscriptionRunCount===1?"":"s"}`:"0 subscription runs"," · ",re(s)," this week"]}),o.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Billing types"}),e.jsx("div",{className:"space-y-1.5",children:o.map(([d,m])=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:wi(d)}),e.jsx("span",{className:"font-medium tabular-nums",children:re(m)})]},d))})]})]}),i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Upstream providers"}),e.jsx("div",{className:"space-y-1.5",children:i.map(d=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:Gt(d.provider)}),e.jsxs("div",{className:"text-right tabular-nums",children:[e.jsx("div",{className:"font-medium",children:re(d.costCents)}),e.jsxs("div",{className:"text-muted-foreground",children:[Ge(d.inputTokens+d.outputTokens)," tok"]})]})]},d.provider))})]})]})]})]})}function Rf(t){return(t/100).toFixed(2)}function Mf(t){const s=Number(t);return!Number.isFinite(s)||s<0?null:Math.round(s*100)}function Go({incident:t,onRaiseAndResume:s,onKeepPaused:n,isMutating:r}){const[a,i]=c.useState(Rf(Math.max(t.amountObserved+1e3,t.amountLimit))),o=Mf(a);return e.jsxs($e,{className:"overflow-hidden border-red-500/20 bg-[linear-gradient(180deg,rgba(255,70,70,0.10),rgba(255,255,255,0.02))]",children:[e.jsx(Ze,{className:"px-5 pt-5 pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.22em] text-red-200/80",children:[t.scopeType," hard stop"]}),e.jsx(et,{className:"mt-1 text-base text-red-50",children:t.scopeName}),e.jsxs(xt,{className:"mt-1 text-red-100/70",children:["Spending reached ",re(t.amountObserved)," against a limit of ",re(t.amountLimit),"."]})]}),e.jsx("div",{className:"rounded-full border border-red-400/30 bg-red-500/10 p-2 text-red-200",children:e.jsx(vx,{className:"h-4 w-4"})})]})}),e.jsxs(Fe,{className:"space-y-4 px-5 pb-5 pt-0",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-xl border border-red-400/20 bg-red-500/10 px-3 py-2 text-sm text-red-50/90",children:[e.jsx(Il,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("div",{children:t.scopeType==="project"?"Project execution is paused. New work in this project will not start until you resolve the budget incident.":"This scope is paused. New heartbeats will not start until you resolve the budget incident."})]}),e.jsxs("div",{className:"rounded-xl border border-border/60 bg-background/60 p-3",children:[e.jsx("label",{className:"text-[11px] uppercase tracking-[0.18em] text-muted-foreground",children:"New budget (USD)"}),e.jsxs("div",{className:"mt-2 flex flex-col gap-3 sm:flex-row",children:[e.jsx(Ot,{value:a,onChange:l=>i(l.target.value),inputMode:"decimal",placeholder:"0.00"}),e.jsxs(F,{className:"gap-2",disabled:r||o===null||o<=t.amountObserved,onClick:()=>{typeof o=="number"&&s(o)},children:[e.jsx(Dr,{className:"h-4 w-4"}),r?"Applying...":"Raise budget & resume"]})]}),o!==null&&o<=t.amountObserved?e.jsx("p",{className:"mt-2 text-xs text-red-200/80",children:"The new budget must exceed current observed spend."}):null]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(F,{variant:"ghost",className:"text-muted-foreground",disabled:r,onClick:n,children:"Keep paused"})})]})]})}function _f({row:t}){return e.jsxs($e,{children:[e.jsx(Ze,{className:"px-4 pt-4 pb-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(et,{className:"text-base",children:Gt(t.biller)}),e.jsxs(xt,{className:"mt-1 text-xs",children:[t.eventCount," event",t.eventCount===1?"":"s"," across ",t.kindCount," kind",t.kindCount===1?"":"s"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-lg font-semibold tabular-nums",children:re(t.netCents)}),e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:"net"})]})]})}),e.jsx(Fe,{className:"space-y-3 px-4 pb-4 pt-3",children:e.jsxs("div",{className:"grid gap-2 text-sm sm:grid-cols-3",children:[e.jsxs("div",{className:"border border-border p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:"debits"}),e.jsx("div",{className:"mt-1 font-medium tabular-nums",children:re(t.debitCents)})]}),e.jsxs("div",{className:"border border-border p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:"credits"}),e.jsx("div",{className:"mt-1 font-medium tabular-nums",children:re(t.creditCents)})]}),e.jsxs("div",{className:"border border-border p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:"estimated"}),e.jsx("div",{className:"mt-1 font-medium tabular-nums",children:re(t.estimatedDebitCents)})]})]})})]})}function Df({rows:t}){return e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-4 pt-4 pb-1",children:[e.jsx(et,{className:"text-base",children:"Financial event mix"}),e.jsx(xt,{children:"Account-level charges grouped by event kind."})]}),e.jsx(Fe,{className:"space-y-2 px-4 pb-4 pt-3",children:t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No finance events in this period."}):t.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border border-border px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:$l(s.eventKind)}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.eventCount," event",s.eventCount===1?"":"s"," · ",s.billerCount," biller",s.billerCount===1?"":"s"]})]}),e.jsxs("div",{className:"text-right tabular-nums",children:[e.jsx("div",{className:"text-sm font-medium",children:re(s.netCents)}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[re(s.debitCents)," debits"]})]})]},s.eventKind))})]})}function Wo({rows:t,emptyMessage:s="No financial events in this period."}){return e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-4 pt-4 pb-1",children:[e.jsx(et,{className:"text-base",children:"Recent financial events"}),e.jsx(xt,{children:"Top-ups, fees, credits, commitments, and other non-request charges."})]}),e.jsx(Fe,{className:"space-y-3 px-4 pb-4 pt-3",children:t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:s}):t.map(n=>e.jsx("div",{className:"border border-border p-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ne,{variant:"secondary",children:$l(n.eventKind)}),e.jsx(Ne,{variant:n.direction==="credit"?"outline":"secondary",children:xu(n.direction)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:da(n.occurredAt)})]}),e.jsxs("div",{className:"text-sm font-medium",children:[Gt(n.biller),n.provider?` -> ${Gt(n.provider)}`:"",n.model?e.jsx("span",{className:"ml-1 font-mono text-xs text-muted-foreground",children:n.model}):null]}),(n.description||n.externalInvoiceId||n.region||n.pricingTier)&&e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[n.description?e.jsx("div",{children:n.description}):null,n.externalInvoiceId?e.jsxs("div",{children:["invoice ",n.externalInvoiceId]}):null,n.region?e.jsxs("div",{children:["region ",n.region]}):null,n.pricingTier?e.jsxs("div",{children:["tier ",n.pricingTier]}):null]})]}),e.jsxs("div",{className:"text-right tabular-nums",children:[e.jsx("div",{className:"text-sm font-semibold",children:re(n.amountCents)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:n.currency}),n.estimated?e.jsx("div",{className:"text-[11px] uppercase tracking-[0.12em] text-amber-600",children:"estimated"}):null]})]})},n.id))})]})}const Cr=["currentsession","currentweekallmodels","currentweeksonnetonly","currentweeksonnet","currentweekopusonly","currentweekopus","extrausage"];function ui(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"")}function $f(t){return typeof t.detail=="string"&&t.detail.trim().length>0?t.detail.trim():t.resetsAt?`Resets ${new Date(t.resetsAt).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"})}`:null}function Ff(t){return[...t].sort((s,n)=>{const r=Cr.indexOf(ui(s.label)),a=Cr.indexOf(ui(n.label));return(r===-1?Cr.length:r)-(a===-1?Cr.length:a)})}function Lf(t){return t==null?"bg-zinc-700":t>=90?"bg-red-400":t>=70?"bg-amber-400":"bg-primary/70"}function Of({windows:t,source:s=null,error:n=null}){const r=Ff(t);return e.jsxs("div",{className:"border border-border px-4 py-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border pb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.2em] text-muted-foreground",children:"Anthropic subscription"}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"Live Claude quota windows."})]}),s?e.jsx("span",{className:"shrink-0 border border-border px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:ki(s)}):null]}),n?e.jsx("div",{className:"mt-4 border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:n}):null,e.jsx("div",{className:"mt-4 space-y-4",children:r.map(a=>{const i=ui(a.label),o=$f(a);if(i==="extrausage")return e.jsxs("div",{className:"border border-border px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:a.label}),a.valueLabel?e.jsx("div",{className:"text-sm font-medium text-foreground",children:a.valueLabel}):null]}),o?e.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:o}):null]},a.label);const l=Math.min(100,Math.max(0,a.usedPercent??0));return e.jsxs("div",{className:"border border-border px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:a.label}),o?e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:o}):null]}),a.usedPercent!=null?e.jsxs("div",{className:"shrink-0 text-sm font-semibold tabular-nums text-foreground",children:[a.usedPercent,"% used"]}):null]}),e.jsx("div",{className:"mt-3 h-2 overflow-hidden bg-muted",children:e.jsx("div",{className:z("h-full transition-[width] duration-200",Lf(a.usedPercent)),style:{width:`${l}%`}})})]},a.label)})})]})}const Sr=["5hlimit","weeklylimit","credits"];function mi(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"")}function qf(t){return[...t].sort((s,n)=>{const r=mi(s.label).replace(/^gpt53codexspark/,""),a=mi(n.label).replace(/^gpt53codexspark/,""),i=Sr.indexOf(r),o=Sr.indexOf(a);return(i===-1?Sr.length:i)-(o===-1?Sr.length:o)})}function Bf(t){return typeof t.detail=="string"&&t.detail.trim().length>0?t.detail.trim():t.resetsAt?`Resets ${new Date(t.resetsAt).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",timeZoneName:"short"})}`:null}function zf(t){return t==null?"bg-zinc-700":t>=90?"bg-red-400":t>=70?"bg-amber-400":"bg-primary/70"}function Vo(t){const s=mi(t);return s.includes("gpt53codexspark")||s.includes("gpt5")}function Kf({windows:t,source:s=null,error:n=null}){const r=qf(t),a=r.filter(o=>!Vo(o.label)),i=r.filter(o=>Vo(o.label));return e.jsxs("div",{className:"border border-border px-4 py-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border pb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.2em] text-muted-foreground",children:"Codex subscription"}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:"Live Codex quota windows."})]}),s?e.jsx("span",{className:"shrink-0 border border-border px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:ki(s)}):null]}),n?e.jsx("div",{className:"mt-4 border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:n}):null,e.jsxs("div",{className:"mt-4 space-y-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Account windows"}),e.jsx("div",{className:"space-y-3",children:a.map(o=>e.jsx(Ho,{window:o},o.label))})]}),i.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Model windows"}),e.jsx("div",{className:"space-y-3",children:i.map(o=>e.jsx(Ho,{window:o},o.label))})]}):null]})]})}function Ho({window:t}){const s=Bf(t);return t.usedPercent==null?e.jsxs("div",{className:"border border-border px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:t.label}),t.valueLabel?e.jsx("div",{className:"text-sm font-semibold tabular-nums text-foreground",children:t.valueLabel}):null]}),s?e.jsx("div",{className:"mt-2 text-xs text-muted-foreground",children:s}):null]}):e.jsxs("div",{className:"border border-border px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:t.label}),s?e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:s}):null]}),e.jsxs("div",{className:"shrink-0 text-sm font-semibold tabular-nums text-foreground",children:[t.usedPercent,"% used"]})]}),e.jsx("div",{className:"mt-3 h-2 overflow-hidden bg-muted",children:e.jsx("div",{className:z("h-full transition-[width] duration-200",zf(t.usedPercent)),style:{width:`${Math.max(0,Math.min(100,t.usedPercent))}%`}})})]})}const Uf=["5h","24h","7d"];function Qo({provider:t,rows:s,budgetMonthlyCents:n,totalCompanySpendCents:r,weekSpendCents:a,windowRows:i,showDeficitNotch:o,quotaWindows:l=[],quotaError:u=null,quotaSource:d=null,quotaLoading:m=!1}){const x=c.useMemo(()=>{let D=0,Z=0,G=0,ie=0,ce=0,q=0,J=0;for(const te of s)D+=te.inputTokens,Z+=te.outputTokens,G+=te.costCents,ie+=te.apiRunCount,ce+=te.subscriptionRunCount,q+=te.subscriptionInputTokens,J+=te.subscriptionOutputTokens;const I=D+Z,P=q+J,O=I+P;return{totalInputTokens:D,totalOutputTokens:Z,totalTokens:I,totalCostCents:G,totalApiRuns:ie,totalSubRuns:ce,totalSubInputTokens:q,totalSubOutputTokens:J,totalSubTokens:P,subSharePct:O>0?P/O*100:0}},[s]),{totalInputTokens:p,totalOutputTokens:h,totalTokens:j,totalCostCents:y,totalApiRuns:f,totalSubRuns:g,totalSubInputTokens:A,totalSubOutputTokens:N,totalSubTokens:C,subSharePct:S}=x,b=n>0&&r>0?y/r*n:n,v=b>0?Math.min(100,y/b*100):0,M=b>0?b/4.33:0,k=M>0?Math.min(100,a/M*100):0,_=n>0,U=c.useMemo(()=>new Map(i.map(D=>[D.window,D])),[i]),w=c.useMemo(()=>Math.max(...i.map(D=>D.costCents),0),[i]),T=t==="anthropic",W=t==="openai"&&(d==null?void 0:d.startsWith("codex-")),B=(t==="anthropic"||t==="openai")&&(m||l.length>0||u!=null);return e.jsxs($e,{children:[e.jsx(Ze,{className:"px-4 pt-4 pb-0 gap-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(et,{className:"text-sm font-semibold",children:Gt(t)}),e.jsxs(xt,{className:"text-xs mt-0.5",children:[e.jsx("span",{className:"font-mono",children:Ge(p)})," in"," · ",e.jsx("span",{className:"font-mono",children:Ge(h)})," out",(f>0||g>0)&&e.jsxs("span",{className:"ml-1.5",children:["·"," ",f>0&&`~${f} api`,f>0&&g>0&&" / ",g>0&&`~${g} sub`," runs"]})]})]}),e.jsx("span",{className:"text-xl font-bold tabular-nums shrink-0",children:re(y)})]})}),e.jsxs(Fe,{className:"px-4 pb-4 pt-3 space-y-4",children:[_&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(di,{label:"Period spend",percentUsed:v,leftLabel:re(y),rightLabel:`${Math.round(v)}% of allocation`,showDeficitNotch:o}),e.jsx(di,{label:"This week",percentUsed:k,leftLabel:re(a),rightLabel:`~${re(Math.round(M))} / wk`,showDeficitNotch:k>=100})]}),i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Rolling windows"}),e.jsx("div",{className:"space-y-2.5",children:Uf.map(D=>{const Z=U.get(D);if(!Z)return null;const G=Z.costCents,ie=Z.inputTokens+Z.outputTokens,ce=w>0?G/w*100:0;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground w-6 shrink-0",children:D}),e.jsxs("span",{className:"text-muted-foreground font-mono flex-1",children:[Ge(ie)," tok"]}),e.jsx("span",{className:"font-medium tabular-nums",children:re(G)})]}),e.jsx("div",{className:"h-2 w-full border border-border overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary/60 transition-[width] duration-150",style:{width:`${ce}%`}})})]},D)})})]})]}),g>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Subscription"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-mono text-foreground",children:g})," runs"," · ",C>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-foreground",children:Ge(C)})," total"," · "]}),e.jsx("span",{className:"font-mono text-foreground",children:Ge(A)})," in"," · ",e.jsx("span",{className:"font-mono text-foreground",children:Ge(N)})," out"]}),S>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-full border border-border overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary/60 transition-[width] duration-150",style:{width:`${S}%`}})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Math.round(S),"% of token usage via subscription"]})]})]})]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border"}),e.jsx("div",{className:"space-y-3",children:s.map(D=>{const Z=D.inputTokens+D.outputTokens,G=j>0?Z/j*100:0,ie=y>0?D.costCents/y*100:0;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-xs text-muted-foreground truncate font-mono block",children:D.model}),e.jsxs("span",{className:"text-[11px] text-muted-foreground truncate block",children:[Gt(D.biller)," · ",wi(D.billingType)]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 tabular-nums text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:[Ge(Z)," tok"]}),e.jsx("span",{className:"font-medium",children:re(D.costCents)})]})]}),e.jsxs("div",{className:"relative h-2 w-full border border-border overflow-hidden",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-primary/60 transition-[width] duration-150",style:{width:`${G}%`},title:`${Math.round(G)}% of provider tokens`}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-primary/85 transition-[width] duration-150",style:{width:`${ie}%`},title:`${Math.round(ie)}% of provider cost`})]})]},`${D.provider}:${D.model}`)})})]}),B&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:"Subscription quota"}),d&&!T&&!W?e.jsx("span",{className:"text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:ki(d)}):null]}),m?e.jsx(Gf,{}):T?e.jsx(Of,{windows:l,source:d,error:u}):W?e.jsx(Kf,{windows:l,source:d,error:u}):e.jsxs(e.Fragment,{children:[u?e.jsx("p",{className:"text-xs text-destructive",children:u}):null,e.jsx("div",{className:"space-y-2.5",children:l.map(D=>{const Z=D.usedPercent==null?null:D.usedPercent>=90?"bg-red-400":D.usedPercent>=70?"bg-yellow-400":"bg-green-400";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:D.label}),e.jsx("span",{className:"flex-1"}),D.valueLabel!=null?e.jsx("span",{className:"font-medium tabular-nums",children:D.valueLabel}):D.usedPercent!=null?e.jsxs("span",{className:"font-medium tabular-nums",children:[D.usedPercent,"% used"]}):null]}),D.usedPercent!=null&&Z!=null&&e.jsx("div",{className:"h-2 w-full border border-border overflow-hidden",children:e.jsx("div",{className:`h-full transition-[width] duration-150 ${Z}`,style:{width:`${D.usedPercent}%`}})}),D.detail?e.jsx("p",{className:"text-xs text-muted-foreground",children:D.detail}):D.resetsAt?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["resets ",new Date(D.resetsAt).toLocaleDateString(void 0,{month:"short",day:"numeric"})]}):null]},D.label)})})]})]})]})]})]})}function Gf(){return e.jsxs("div",{className:"border border-border px-4 py-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border pb-3",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx(ts,{className:"h-3 w-36"}),e.jsx(ts,{className:"h-4 w-64 max-w-full"})]}),e.jsx(ts,{className:"h-7 w-28"})]}),e.jsx("div",{className:"mt-4 space-y-3",children:Array.from({length:3}).map((t,s)=>e.jsxs("div",{className:"border border-border px-3.5 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx(ts,{className:"h-4 w-32"}),e.jsx(ts,{className:"h-3 w-44 max-w-full"})]}),e.jsx(ts,{className:"h-4 w-20"})]}),e.jsx(ts,{className:"mt-3 h-2 w-full"})]},s))})]})}const Wf={mtd:"Month to Date","7d":"Last 7 Days","30d":"Last 30 Days",ytd:"Year to Date",all:"All Time",custom:"Custom"},Vf=["mtd","7d","30d","ytd","all","custom"];function Hf(t){const s=new Date,n=s.toISOString();switch(t){case"mtd":return{from:new Date(s.getFullYear(),s.getMonth(),1).toISOString(),to:n};case"7d":return{from:new Date(s.getFullYear(),s.getMonth(),s.getDate()-7,0,0,0,0).toISOString(),to:n};case"30d":return{from:new Date(s.getFullYear(),s.getMonth(),s.getDate()-30,0,0,0,0).toISOString(),to:n};case"ytd":return{from:new Date(s.getFullYear(),0,1).toISOString(),to:n};case"all":case"custom":return{from:"",to:""}}}function Fa(t){const s=new Date(t);return s.setSeconds(0,0),s.toISOString()}function Qf(){const[t,s]=c.useState("mtd"),[n,r]=c.useState(""),[a,i]=c.useState(""),o=c.useRef(null),[l,u]=c.useState(()=>Fa(new Date));c.useEffect(()=>{const p=new Date,h=(60-p.getSeconds())*1e3-p.getMilliseconds(),j=setTimeout(()=>{u(Fa(new Date)),o.current=setInterval(()=>u(Fa(new Date)),6e4)},h);return()=>{clearTimeout(j),o.current!=null&&clearInterval(o.current)}},[]);const{from:d,to:m}=c.useMemo(()=>{if(t!=="custom")return Hf(t);const p=n?new Date(n+"T00:00:00"):null,h=a?new Date(a+"T23:59:59.999"):null;return{from:p?p.toISOString():"",to:h?h.toISOString():""}},[t,n,a,l]);return{preset:t,setPreset:s,customFrom:n,setCustomFrom:r,customTo:a,setCustomTo:i,from:d,to:m,customReady:t!=="custom"||!!n&&!!a}}const Yf="__none__";function Jf(){const t=new Date,s=t.getDay(),n=s===0?-6:1-s,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()+n,0,0,0,0),a=new Date(r.getFullYear(),r.getMonth(),r.getDate()+6,23,59,59,999);return{from:r.toISOString(),to:a.toISOString()}}function Xf({provider:t,rows:s}){const n=s.reduce((a,i)=>a+i.inputTokens+i.cachedInputTokens+i.outputTokens,0),r=s.reduce((a,i)=>a+i.costCents,0);return e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:Gt(t)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:Ge(n)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:re(r)})]})}function Zf({biller:t,rows:s}){const n=s.reduce((a,i)=>a+i.inputTokens+i.cachedInputTokens+i.outputTokens,0),r=s.reduce((a,i)=>a+i.costCents,0);return e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:Gt(t)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:Ge(n)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:re(r)})]})}function $t({label:t,value:s,subtitle:n,icon:r}){return e.jsx("div",{className:"border border-border p-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:t}),e.jsx("div",{className:"mt-2 text-2xl font-semibold tabular-nums",children:s}),e.jsx("div",{className:"mt-1 text-xs leading-5 text-muted-foreground",children:n})]}),e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center border border-border",children:e.jsx(r,{className:"h-4 w-4 text-muted-foreground"})})]})})}function Yo({debitCents:t,creditCents:s,netCents:n,estimatedDebitCents:r,eventCount:a}){return e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-5 pt-5 pb-2",children:[e.jsx(et,{className:"text-base",children:"Finance ledger"}),e.jsx(xt,{children:"Account-level charges that do not map to a single inference request."})]}),e.jsxs(Fe,{className:"grid gap-3 px-5 pb-5 pt-2 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx($t,{label:"Debits",value:re(t),subtitle:`${a} total event${a===1?"":"s"} in range`,icon:Dr}),e.jsx($t,{label:"Credits",value:re(s),subtitle:"Refunds, offsets, and credit returns",icon:Om}),e.jsx($t,{label:"Net",value:re(n),subtitle:"Debit minus credit for the selected period",icon:si}),e.jsx($t,{label:"Estimated",value:re(r),subtitle:"Estimated debits that are not yet invoice-authoritative",icon:ei})]})]})}function eb(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),n=Le(),[r,a]=c.useState("overview"),[i,o]=c.useState("all"),[l,u]=c.useState("all"),{preset:d,setPreset:m,customFrom:x,setCustomFrom:p,customTo:h,setCustomTo:j,from:y,to:f,customReady:g}=Qf();c.useEffect(()=>{s([{label:"Costs"}])},[s]);const[A,N]=c.useState(()=>new Date().toDateString()),C=c.useRef(null);c.useEffect(()=>{const R=()=>{const X=new Date,$=new Date(X.getFullYear(),X.getMonth(),X.getDate()+1).getTime()-X.getTime();C.current=setTimeout(()=>{N(new Date().toDateString()),R()},$)};return R(),()=>{C.current!=null&&clearTimeout(C.current)}},[]);const S=c.useMemo(()=>Jf(),[A]),b=t??Yf,{data:v,isLoading:M,error:k}=V({queryKey:E.budgets.overview(b),queryFn:()=>Un.overview(b),enabled:!!t&&g,refetchInterval:3e4,staleTime:5e3}),_=()=>{t&&(n.invalidateQueries({queryKey:E.budgets.overview(t)}),n.invalidateQueries({queryKey:E.dashboard(t)}),n.invalidateQueries({queryKey:E.agents.list(t)}),n.invalidateQueries({queryKey:E.projects.list(t)}))},U=se({mutationFn:R=>Un.upsertPolicy(b,{scopeType:R.scopeType,scopeId:R.scopeId,amount:R.amount,windowKind:R.windowKind}),onSuccess:_}),w=se({mutationFn:R=>Un.resolveIncident(b,R.incidentId,R),onSuccess:_}),{data:T,isLoading:W,error:H}=V({queryKey:E.costs(b,y||void 0,f||void 0),queryFn:async()=>{const[R,X,$,Q]=await Promise.all([yt.summary(b,y||void 0,f||void 0),yt.byAgent(b,y||void 0,f||void 0),yt.byProject(b,y||void 0,f||void 0),yt.byAgentModel(b,y||void 0,f||void 0)]);return{summary:R,byAgent:X,byProject:$,byAgentModel:Q}},enabled:!!t&&g}),{data:B,isLoading:D,error:Z}=V({queryKey:[E.financeSummary(b,y||void 0,f||void 0),E.financeByBiller(b,y||void 0,f||void 0),E.financeByKind(b,y||void 0,f||void 0),E.financeEvents(b,y||void 0,f||void 0,18)],queryFn:async()=>{const[R,X,$,Q]=await Promise.all([yt.financeSummary(b,y||void 0,f||void 0),yt.financeByBiller(b,y||void 0,f||void 0),yt.financeByKind(b,y||void 0,f||void 0),yt.financeEvents(b,y||void 0,f||void 0,18)]);return{summary:R,byBiller:X,byKind:$,events:Q}},enabled:!!t&&g}),[G,ie]=c.useState(new Set);c.useEffect(()=>{ie(new Set)},[b,y,f]);function ce(R){ie(X=>{const $=new Set(X);return $.has(R)?$.delete(R):$.add(R),$})}const q=c.useMemo(()=>{const R=new Map;for(const X of(T==null?void 0:T.byAgentModel)??[]){const $=R.get(X.agentId)??[];$.push(X),R.set(X.agentId,$)}for(const[X,$]of R)R.set(X,$.slice().sort((Q,ne)=>ne.costCents-Q.costCents));return R},[T==null?void 0:T.byAgentModel]),{data:J}=V({queryKey:E.usageByProvider(b,y||void 0,f||void 0),queryFn:()=>yt.byProvider(b,y||void 0,f||void 0),enabled:!!t&&g&&(r==="providers"||r==="billers"),refetchInterval:3e4,staleTime:1e4}),{data:I}=V({queryKey:E.usageByBiller(b,y||void 0,f||void 0),queryFn:()=>yt.byBiller(b,y||void 0,f||void 0),enabled:!!t&&g&&r==="billers",refetchInterval:3e4,staleTime:1e4}),{data:P}=V({queryKey:E.usageByProvider(b,S.from,S.to),queryFn:()=>yt.byProvider(b,S.from,S.to),enabled:!!t&&(r==="providers"||r==="billers"),refetchInterval:3e4,staleTime:1e4}),{data:O}=V({queryKey:E.usageByBiller(b,S.from,S.to),queryFn:()=>yt.byBiller(b,S.from,S.to),enabled:!!t&&r==="billers",refetchInterval:3e4,staleTime:1e4}),{data:te}=V({queryKey:E.usageWindowSpend(b),queryFn:()=>yt.windowSpend(b),enabled:!!t&&r==="providers",refetchInterval:3e4,staleTime:1e4}),{data:oe,isLoading:ue}=V({queryKey:E.usageQuotaWindows(b),queryFn:()=>yt.quotaWindows(b),enabled:!!t&&r==="providers",refetchInterval:3e5,staleTime:6e4}),L=c.useMemo(()=>{const R=new Map;for(const X of J??[]){const $=R.get(X.provider)??[];$.push(X),R.set(X.provider,$)}return R},[J]),ae=c.useMemo(()=>{const R=new Map;for(const X of I??[]){const $=R.get(X.biller)??[];$.push(X),R.set(X.biller,$)}return R},[I]),le=c.useMemo(()=>{const R=new Map;for(const X of P??[])R.set(X.provider,(R.get(X.provider)??0)+X.costCents);return R},[P]),Re=c.useMemo(()=>{const R=new Map;for(const X of O??[])R.set(X.biller,(R.get(X.biller)??0)+X.costCents);return R},[O]),ee=c.useMemo(()=>{const R=new Map;for(const X of te??[]){const $=R.get(X.provider)??[];$.push(X),R.set(X.provider,$)}return R},[te]),ye=c.useMemo(()=>{const R=new Map;for(const X of oe??[])X.ok&&X.windows.length>0&&R.set(X.provider,X.windows);return R},[oe]),Ce=c.useMemo(()=>{const R=new Map;for(const X of oe??[])!X.ok&&X.error&&R.set(X.provider,X.error);return R},[oe]),He=c.useMemo(()=>{const R=new Map;for(const X of oe??[])typeof X.source=="string"&&X.source.length>0&&R.set(X.provider,X.source);return R},[oe]),K=c.useMemo(()=>{const R=new Map;if(d!=="mtd")return R;const X=(T==null?void 0:T.summary.budgetCents)??0;if(X<=0)return R;const $=(T==null?void 0:T.summary.spendCents)??0,Q=new Date,ne=Q.getDate(),je=new Date(Q.getFullYear(),Q.getMonth()+1,0).getDate();for(const[_e,tt]of L){const Dn=tt.reduce((Jt,vt)=>Jt+vt.costCents,0),Ye=$>0?Dn/$:0,it=X*Ye;if(it<=0){R.set(_e,!1);continue}const dt=Dn/Math.max(ne,1);R.set(_e,Dn+dt*(je-ne)>it)}return R},[d,T,L]),de=c.useMemo(()=>Array.from(L.keys()),[L]),fe=c.useMemo(()=>Array.from(ae.keys()),[ae]),Ie=i==="all"||de.includes(i)?i:"all";c.useEffect(()=>{Ie!==i&&o("all")},[Ie,i]);const ze=l==="all"||fe.includes(l)?l:"all";c.useEffect(()=>{ze!==l&&u("all")},[ze,l]);const Qt=c.useMemo(()=>{const R=Array.from(L.keys()),X=R.reduce((Q,ne)=>{var je;return Q+(((je=L.get(ne))==null?void 0:je.reduce((_e,tt)=>_e+tt.inputTokens+tt.cachedInputTokens+tt.outputTokens,0))??0)},0),$=R.reduce((Q,ne)=>{var je;return Q+(((je=L.get(ne))==null?void 0:je.reduce((_e,tt)=>_e+tt.costCents,0))??0)},0);return[{value:"all",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:"All providers"}),R.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:Ge(X)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:re($)})]}):null]})},...R.map(Q=>({value:Q,label:e.jsx(Xf,{provider:Q,rows:L.get(Q)??[]})}))]},[L]),Fs=c.useMemo(()=>{const R=Array.from(ae.keys()),X=R.reduce((Q,ne)=>{var je;return Q+(((je=ae.get(ne))==null?void 0:je.reduce((_e,tt)=>_e+tt.inputTokens+tt.cachedInputTokens+tt.outputTokens,0))??0)},0),$=R.reduce((Q,ne)=>{var je;return Q+(((je=ae.get(ne))==null?void 0:je.reduce((_e,tt)=>_e+tt.costCents,0))??0)},0);return[{value:"all",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{children:"All billers"}),R.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:Ge(X)}),e.jsx("span",{className:"text-xs text-muted-foreground",children:re($)})]}):null]})},...R.map(Q=>({value:Q,label:e.jsx(Zf,{biller:Q,rows:ae.get(Q)??[]})}))]},[ae]),us=((T==null?void 0:T.byAgent)??[]).reduce((R,X)=>R+X.inputTokens+X.cachedInputTokens+X.outputTokens,0),Ls=(B==null?void 0:B.events)??[],ct=(v==null?void 0:v.policies)??[],Qe=(v==null?void 0:v.activeIncidents)??[],Yt=c.useMemo(()=>({company:ct.filter(R=>R.scopeType==="company"),agent:ct.filter(R=>R.scopeType==="agent"),project:ct.filter(R=>R.scopeType==="project")}),[ct]);if(!t)return e.jsx(Be,{icon:ns,message:"Select a company to view costs."});const zt=d==="custom"&&!g,It=(W||D)&&g,ms=H??Z;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Costs"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-muted-foreground",children:"Inference spend, platform fees, credits, and live quota windows."})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:Vf.map(R=>e.jsx(F,{variant:d===R?"secondary":"ghost",size:"sm",onClick:()=>m(R),children:Wf[R]},R))})]}),d==="custom"?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border border-border p-3",children:[e.jsx("input",{type:"date",value:x,onChange:R=>p(R.target.value),className:"h-9 rounded-md border border-input bg-background px-3 text-sm text-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"to"}),e.jsx("input",{type:"date",value:h,onChange:R=>j(R.target.value),className:"h-9 rounded-md border border-input bg-background px-3 text-sm text-foreground"})]}):null,e.jsxs("div",{className:"grid gap-3 lg:grid-cols-4",children:[e.jsx($t,{label:"Inference spend",value:re((T==null?void 0:T.summary.spendCents)??0),subtitle:`${Ge(us)} tokens across request-scoped events`,icon:ns}),e.jsx($t,{label:"Budget",value:Qe.length>0?String(Qe.length):T!=null&&T.summary.budgetCents&&T.summary.budgetCents>0?`${T.summary.utilizationPercent}%`:"Open",subtitle:Qe.length>0?`${(v==null?void 0:v.pausedAgentCount)??0} agents paused · ${(v==null?void 0:v.pausedProjectCount)??0} projects paused`:T!=null&&T.summary.budgetCents&&T.summary.budgetCents>0?`${re(T.summary.spendCents)} of ${re(T.summary.budgetCents)}`:"No monthly cap configured",icon:ei}),e.jsx($t,{label:"Finance net",value:re((B==null?void 0:B.summary.netCents)??0),subtitle:`${re((B==null?void 0:B.summary.debitCents)??0)} debits · ${re((B==null?void 0:B.summary.creditCents)??0)} credits`,icon:si}),e.jsx($t,{label:"Finance events",value:String((B==null?void 0:B.summary.eventCount)??0),subtitle:`${re((B==null?void 0:B.summary.estimatedDebitCents)??0)} estimated in range`,icon:Dr})]})]}),e.jsxs(Ut,{value:r,onValueChange:R=>a(R),children:[e.jsxs(_r,{variant:"line",className:"justify-start",children:[e.jsx(kt,{value:"overview",children:"Overview"}),e.jsx(kt,{value:"budgets",children:"Budgets"}),e.jsx(kt,{value:"providers",children:"Providers"}),e.jsx(kt,{value:"billers",children:"Billers"}),e.jsx(kt,{value:"finance",children:"Finance"})]}),e.jsx(Oe,{value:"overview",className:"mt-4 space-y-4",children:zt?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a start and end date to load data."}):It?e.jsx(rt,{variant:"costs"}):ms?e.jsx("p",{className:"text-sm text-destructive",children:ms.message}):e.jsxs(e.Fragment,{children:[Qe.length>0?e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:Qe.slice(0,2).map(R=>e.jsx(Go,{incident:R,isMutating:w.isPending,onKeepPaused:()=>w.mutate({incidentId:R.id,action:"keep_paused"}),onRaiseAndResume:X=>w.mutate({incidentId:R.id,action:"raise_budget_and_resume",amount:X})},R.id))}):null,e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[1.3fr,1fr]",children:[e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-5 pt-5 pb-2",children:[e.jsx(et,{className:"text-base",children:"Inference ledger"}),e.jsx(xt,{children:"Request-scoped inference spend for the selected period."})]}),e.jsxs(Fe,{className:"space-y-4 px-5 pb-5 pt-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-3xl font-semibold tabular-nums",children:re((T==null?void 0:T.summary.spendCents)??0)}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:T!=null&&T.summary.budgetCents&&T.summary.budgetCents>0?`Budget ${re(T.summary.budgetCents)}`:"Unlimited budget"})]}),e.jsxs("div",{className:"border border-border px-4 py-3 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.14em] text-muted-foreground",children:"usage"}),e.jsx("div",{className:"mt-1 text-lg font-medium tabular-nums",children:Ge(us)})]})]}),T!=null&&T.summary.budgetCents&&T.summary.budgetCents>0?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-2 overflow-hidden bg-muted",children:e.jsx("div",{className:z("h-full transition-[width,background-color] duration-150",T.summary.utilizationPercent>90?"bg-red-400":T.summary.utilizationPercent>70?"bg-yellow-400":"bg-emerald-400"),style:{width:`${Math.min(100,T.summary.utilizationPercent)}%`}})}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[T.summary.utilizationPercent,"% of monthly budget consumed in this range."]})]}):null]})]}),e.jsx(Yo,{debitCents:(B==null?void 0:B.summary.debitCents)??0,creditCents:(B==null?void 0:B.summary.creditCents)??0,netCents:(B==null?void 0:B.summary.netCents)??0,estimatedDebitCents:(B==null?void 0:B.summary.estimatedDebitCents)??0,eventCount:(B==null?void 0:B.summary.eventCount)??0})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[1.25fr,0.95fr]",children:[e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-5 pt-5 pb-2",children:[e.jsx(et,{className:"text-base",children:"By agent"}),e.jsx(xt,{children:"What each agent consumed in the selected period."})]}),e.jsx(Fe,{className:"space-y-2 px-5 pb-5 pt-2",children:((T==null?void 0:T.byAgent.length)??0)===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No cost events yet."}):T==null?void 0:T.byAgent.map(R=>{const X=q.get(R.agentId)??[],$=G.has(R.agentId),Q=X.length>0;return e.jsxs("div",{className:"border border-border px-4 py-3",children:[e.jsxs("div",{className:z("flex items-start justify-between gap-3",Q?"cursor-pointer select-none":""),onClick:()=>Q&&ce(R.agentId),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[Q?$?e.jsx(Pn,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx(Js,{className:"h-3 w-3 shrink-0 text-muted-foreground"}):e.jsx("span",{className:"h-3 w-3 shrink-0"}),e.jsx(qe,{name:R.agentName??R.agentId,size:"sm"}),R.agentStatus==="terminated"?e.jsx(Se,{status:"terminated"}):null]}),e.jsxs("div",{className:"text-right text-sm tabular-nums",children:[e.jsx("div",{className:"font-medium",children:re(R.costCents)}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["in ",Ge(R.inputTokens+R.cachedInputTokens)," · out ",Ge(R.outputTokens)]}),R.apiRunCount>0||R.subscriptionRunCount>0?e.jsxs("div",{className:"text-xs text-muted-foreground",children:[R.apiRunCount>0?`${R.apiRunCount} api`:"0 api"," · ",R.subscriptionRunCount>0?`${R.subscriptionRunCount} subscription`:"0 subscription"]}):null]})]}),$&&X.length>0?e.jsx("div",{className:"mt-3 space-y-2 border-l border-border pl-4",children:X.map(ne=>{const je=R.costCents>0?Math.round(ne.costCents/R.costCents*100):0;return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-xs",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"truncate font-medium text-foreground",children:[Gt(ne.provider),e.jsx("span",{className:"mx-1 text-border",children:"/"}),e.jsx("span",{className:"font-mono",children:ne.model})]}),e.jsxs("div",{className:"truncate text-muted-foreground",children:[Gt(ne.biller)," · ",wi(ne.billingType)]})]}),e.jsxs("div",{className:"text-right tabular-nums",children:[e.jsxs("div",{className:"font-medium",children:[re(ne.costCents),e.jsxs("span",{className:"ml-1 font-normal text-muted-foreground",children:["(",je,"%)"]})]}),e.jsxs("div",{className:"text-muted-foreground",children:[Ge(ne.inputTokens+ne.cachedInputTokens+ne.outputTokens)," tok"]})]})]},`${ne.provider}:${ne.model}:${ne.billingType}`)})}):null]},R.agentId)})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-5 pt-5 pb-2",children:[e.jsx(et,{className:"text-base",children:"By project"}),e.jsx(xt,{children:"Run costs attributed through project-linked issues."})]}),e.jsx(Fe,{className:"space-y-2 px-5 pb-5 pt-2",children:((T==null?void 0:T.byProject.length)??0)===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No project-attributed run costs yet."}):T==null?void 0:T.byProject.map((R,X)=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border border-border px-3 py-2 text-sm",children:[e.jsx("span",{className:"truncate",children:R.projectName??R.projectId??"Unattributed"}),e.jsx("span",{className:"font-medium tabular-nums",children:re(R.costCents)})]},R.projectId??`unattributed-${X}`))})]}),e.jsx(Wo,{rows:Ls.slice(0,6),emptyMessage:"No finance events yet. Add account-level charges once biller invoices or credits land."})]})]})]})}),e.jsx(Oe,{value:"budgets",className:"mt-4 space-y-4",children:M?e.jsx(rt,{variant:"costs"}):k?e.jsx("p",{className:"text-sm text-destructive",children:k.message}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{className:"border-border/70 bg-[linear-gradient(180deg,rgba(255,255,255,0.05),rgba(255,255,255,0.02))]",children:[e.jsxs(Ze,{className:"px-5 pt-5 pb-3",children:[e.jsx(et,{className:"text-base",children:"Budget control plane"}),e.jsx(xt,{children:"Hard-stop spend limits for agents and projects. Provider subscription quota stays separate and appears under Providers."})]}),e.jsxs(Fe,{className:"grid gap-3 px-5 pb-5 pt-0 md:grid-cols-4",children:[e.jsx($t,{label:"Active incidents",value:String(Qe.length),subtitle:"Open soft or hard threshold crossings",icon:si}),e.jsx($t,{label:"Pending approvals",value:String((v==null?void 0:v.pendingApprovalCount)??0),subtitle:"Budget override approvals awaiting board action",icon:Dr}),e.jsx($t,{label:"Paused agents",value:String((v==null?void 0:v.pausedAgentCount)??0),subtitle:"Agent heartbeats blocked by budget",icon:ei}),e.jsx($t,{label:"Paused projects",value:String((v==null?void 0:v.pausedProjectCount)??0),subtitle:"Project execution blocked by budget",icon:ns})]})]}),Qe.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Active incidents"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Resolve hard stops here by raising the budget or explicitly keeping the scope paused."})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:Qe.map(R=>e.jsx(Go,{incident:R,isMutating:w.isPending,onKeepPaused:()=>w.mutate({incidentId:R.id,action:"keep_paused"}),onRaiseAndResume:X=>w.mutate({incidentId:R.id,action:"raise_budget_and_resume",amount:X})},R.id))})]}):null,e.jsxs("div",{className:"space-y-5",children:[["company","agent","project"].map(R=>{const X=Yt[R];return X.length===0?null:e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold capitalize",children:[R," budgets"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:R==="company"?"Company-wide monthly policy.":R==="agent"?"Recurring monthly spend policies for individual agents.":"Lifetime spend policies for execution-bound projects."})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:X.map($=>e.jsx(Ml,{summary:$,isSaving:U.isPending,onSave:Q=>U.mutate({scopeType:$.scopeType,scopeId:$.scopeId,amount:Q,windowKind:$.windowKind})},$.policyId))})]},R)}),ct.length===0?e.jsx($e,{children:e.jsx(Fe,{className:"px-5 py-8 text-sm text-muted-foreground",children:"No budget policies yet. Set agent and project budgets from their detail pages, or use the existing company monthly budget control."})}):null]})]})}),e.jsx(Oe,{value:"providers",className:"mt-4 space-y-4",children:zt?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a start and end date to load data."}):e.jsx(e.Fragment,{children:e.jsxs(Ut,{value:Ie,onValueChange:o,children:[e.jsx(Hs,{items:Qt,value:Ie}),e.jsx(Oe,{value:"all",className:"mt-4",children:de.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No cost events in this period."}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:de.map(R=>e.jsx(Qo,{provider:R,rows:L.get(R)??[],budgetMonthlyCents:(T==null?void 0:T.summary.budgetCents)??0,totalCompanySpendCents:(T==null?void 0:T.summary.spendCents)??0,weekSpendCents:le.get(R)??0,windowRows:ee.get(R)??[],showDeficitNotch:K.get(R)??!1,quotaWindows:ye.get(R)??[],quotaError:Ce.get(R)??null,quotaSource:He.get(R)??null,quotaLoading:ue},R))})}),de.map(R=>e.jsx(Oe,{value:R,className:"mt-4",children:e.jsx(Qo,{provider:R,rows:L.get(R)??[],budgetMonthlyCents:(T==null?void 0:T.summary.budgetCents)??0,totalCompanySpendCents:(T==null?void 0:T.summary.spendCents)??0,weekSpendCents:le.get(R)??0,windowRows:ee.get(R)??[],showDeficitNotch:K.get(R)??!1,quotaWindows:ye.get(R)??[],quotaError:Ce.get(R)??null,quotaSource:He.get(R)??null,quotaLoading:ue})},R))]})})}),e.jsx(Oe,{value:"billers",className:"mt-4 space-y-4",children:zt?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a start and end date to load data."}):e.jsx(e.Fragment,{children:e.jsxs(Ut,{value:ze,onValueChange:u,children:[e.jsx(Hs,{items:Fs,value:ze}),e.jsx(Oe,{value:"all",className:"mt-4",children:fe.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No billable events in this period."}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:fe.map(R=>{const X=(ae.get(R)??[])[0];if(!X)return null;const $=(J??[]).filter(Q=>Q.biller===R);return e.jsx(Uo,{row:X,weekSpendCents:Re.get(R)??0,budgetMonthlyCents:(T==null?void 0:T.summary.budgetCents)??0,totalCompanySpendCents:(T==null?void 0:T.summary.spendCents)??0,providerRows:$},R)})})}),fe.map(R=>{const X=(ae.get(R)??[])[0];if(!X)return null;const $=(J??[]).filter(Q=>Q.biller===R);return e.jsx(Oe,{value:R,className:"mt-4",children:e.jsx(Uo,{row:X,weekSpendCents:Re.get(R)??0,budgetMonthlyCents:(T==null?void 0:T.summary.budgetCents)??0,totalCompanySpendCents:(T==null?void 0:T.summary.spendCents)??0,providerRows:$})},R)})]})})}),e.jsx(Oe,{value:"finance",className:"mt-4 space-y-4",children:zt?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a start and end date to load data."}):D?e.jsx(rt,{variant:"costs"}):Z?e.jsx("p",{className:"text-sm text-destructive",children:Z.message}):e.jsxs(e.Fragment,{children:[e.jsx(Yo,{debitCents:(B==null?void 0:B.summary.debitCents)??0,creditCents:(B==null?void 0:B.summary.creditCents)??0,netCents:(B==null?void 0:B.summary.netCents)??0,estimatedDebitCents:(B==null?void 0:B.summary.estimatedDebitCents)??0,eventCount:(B==null?void 0:B.summary.eventCount)??0}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[1.2fr,0.95fr]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs($e,{children:[e.jsxs(Ze,{className:"px-5 pt-5 pb-2",children:[e.jsx(et,{className:"text-base",children:"By biller"}),e.jsx(xt,{children:"Account-level financial events grouped by who charged or credited them."})]}),e.jsx(Fe,{className:"grid gap-4 px-5 pb-5 pt-2 md:grid-cols-2",children:((B==null?void 0:B.byBiller.length)??0)===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No finance events yet."}):B==null?void 0:B.byBiller.map(R=>e.jsx(_f,{row:R},R.biller))})]}),e.jsx(Wo,{rows:Ls})]}),e.jsx(Df,{rows:(B==null?void 0:B.byKind)??[]})]})]})})]})]})}function Cn({...t}){return e.jsx(hu,{"data-slot":"select",...t})}function Sn({...t}){return e.jsx(fu,{"data-slot":"select-value",...t})}function In({className:t,size:s="default",children:n,...r}){return e.jsxs(pu,{"data-slot":"select-trigger","data-size":s,className:z("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",t),...r,children:[n,e.jsx(gu,{asChild:!0,children:e.jsx(Pn,{className:"size-4 opacity-50"})})]})}function An({className:t,children:s,position:n="item-aligned",align:r="center",...a}){return e.jsx(bu,{children:e.jsxs(ju,{"data-slot":"select-content",className:z("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:n,align:r,...a,children:[e.jsx(tb,{}),e.jsx(vu,{className:z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:s}),e.jsx(sb,{})]})})}function De({className:t,children:s,...n}){return e.jsxs(yu,{"data-slot":"select-item",className:z("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",t),...n,children:[e.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:e.jsx(Nu,{children:e.jsx(Ns,{className:"size-4"})})}),e.jsx(wu,{children:s})]})}function tb({className:t,...s}){return e.jsx(ku,{"data-slot":"select-scroll-up-button",className:z("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(Cu,{className:"size-4"})})}function sb({className:t,...s}){return e.jsx(Su,{"data-slot":"select-scroll-down-button",className:z("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(Pn,{className:"size-4"})})}function nb(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),[n,r]=c.useState("all");c.useEffect(()=>{s([{label:"Activity"}])},[s]);const{data:a,isLoading:i,error:o}=V({queryKey:E.activity(t),queryFn:()=>Al.list(t),enabled:!!t}),{data:l}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t}),{data:u}=V({queryKey:E.issues.list(t),queryFn:()=>ht.list(t),enabled:!!t}),{data:d}=V({queryKey:E.projects.list(t),queryFn:()=>lt.list(t),enabled:!!t}),{data:m}=V({queryKey:E.goals.list(t),queryFn:()=>Et.list(t),enabled:!!t}),x=c.useMemo(()=>{const f=new Map;for(const g of l??[])f.set(g.id,g);return f},[l]),p=c.useMemo(()=>{const f=new Map;for(const g of u??[])f.set(`issue:${g.id}`,g.identifier??g.id.slice(0,8));for(const g of l??[])f.set(`agent:${g.id}`,g.name);for(const g of d??[])f.set(`project:${g.id}`,g.name);for(const g of m??[])f.set(`goal:${g.id}`,g.title);return f},[u,l,d,m]),h=c.useMemo(()=>{const f=new Map;for(const g of u??[])f.set(`issue:${g.id}`,g.title);return f},[u]);if(!t)return e.jsx(Be,{icon:kn,message:"Select a company to view activity."});if(i)return e.jsx(rt,{variant:"list"});const j=a&&n!=="all"?a.filter(f=>f.entityType===n):a,y=a?[...new Set(a.map(f=>f.entityType))].sort():[];return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs(Cn,{value:n,onValueChange:r,children:[e.jsx(In,{className:"w-[140px] h-8 text-xs",children:e.jsx(Sn,{placeholder:"Filter by type"})}),e.jsxs(An,{children:[e.jsx(De,{value:"all",children:"All types"}),y.map(f=>e.jsx(De,{value:f,children:f.charAt(0).toUpperCase()+f.slice(1)},f))]})]})}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o.message}),j&&j.length===0&&e.jsx(Be,{icon:kn,message:"No activity yet."}),j&&j.length>0&&e.jsx("div",{className:"border border-border divide-y divide-border",children:j.map(f=>e.jsx(Hc,{event:f,agentMap:x,entityNameMap:p,entityTitleMap:h},f.id))})]})}function Jo(t){return t?t.split(`
197
+ `).map(n=>n.trim()).find(Boolean)??null:null}function rb(t){return Jo(t.error)??Jo(t.stderrExcerpt)??"Run exited with an error."}function ab(t){return t.replaceAll("_"," ")}function ad(t){const s=t.contextSnapshot;if(!s)return null;const n=s.issueId;if(typeof n=="string"&&n.length>0)return n;const r=s.taskId;return typeof r=="string"&&r.length>0?r:null}function ib({run:t,issueById:s,agentName:n,issueLinkState:r,onDismiss:a,onRetry:i,isRetrying:o}){const l=ad(t),u=l?s.get(l)??null:null,d=rb(t);return e.jsxs("div",{className:"group border-b border-border px-2 py-2.5 last:border-b-0 sm:px-1 sm:pr-3 sm:py-2",children:[e.jsxs("div",{className:"flex items-start gap-2 sm:items-center",children:[e.jsxs(xe,{to:`/agents/${t.agentId}/runs/${t.id}`,className:"flex min-w-0 flex-1 items-start gap-2 no-underline text-inherit transition-colors hover:bg-accent/50",children:[e.jsx("span",{className:"hidden h-2 w-2 shrink-0 sm:inline-flex","aria-hidden":"true"}),e.jsx("span",{className:"hidden h-3.5 w-3.5 shrink-0 sm:inline-flex","aria-hidden":"true"}),e.jsx("span",{className:"mt-0.5 shrink-0 rounded-md bg-red-500/20 p-1.5 sm:mt-0",children:e.jsx(Ni,{className:"h-4 w-4 text-red-600 dark:text-red-400"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"line-clamp-2 text-sm font-medium sm:truncate sm:line-clamp-none",children:u?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-muted-foreground mr-1.5",children:u.identifier??u.id.slice(0,8)}),u.title]}):e.jsxs(e.Fragment,{children:["Failed run",n?` — ${n}`:""]})}),e.jsxs("span",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground",children:[e.jsx(Se,{status:t.status}),n&&u?e.jsx("span",{children:n}):null,e.jsx("span",{className:"truncate max-w-[300px]",children:d}),e.jsx("span",{children:Lt(t.createdAt)})]})]})]}),e.jsxs("div",{className:"hidden shrink-0 items-center gap-2 sm:flex",children:[e.jsxs(F,{type:"button",variant:"outline",size:"sm",className:"h-8 shrink-0 px-2.5",onClick:i,disabled:o,children:[e.jsx(no,{className:"mr-1.5 h-3.5 w-3.5"}),o?"Retrying…":"Retry"]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100","aria-label":"Dismiss",children:e.jsx(St,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"mt-3 flex gap-2 sm:hidden",children:[e.jsxs(F,{type:"button",variant:"outline",size:"sm",className:"h-8 shrink-0 px-2.5",onClick:i,disabled:o,children:[e.jsx(no,{className:"mr-1.5 h-3.5 w-3.5"}),o?"Retrying…":"Retry"]}),e.jsx("button",{type:"button",onClick:a,className:"rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-foreground","aria-label":"Dismiss",children:e.jsx(St,{className:"h-4 w-4"})})]})]})}function ob({approval:t,requesterName:s,onApprove:n,onReject:r,isPending:a}){const i=Wi[t.type]??Vi,o=Gi(t.type,t.payload),l=t.type!=="budget_override_required"&&Kr.has(t.status);return e.jsxs("div",{className:"border-b border-border px-2 py-2.5 last:border-b-0 sm:px-1 sm:pr-3 sm:py-2",children:[e.jsxs("div",{className:"flex items-start gap-2 sm:items-center",children:[e.jsxs(xe,{to:`/approvals/${t.id}`,className:"flex min-w-0 flex-1 items-start gap-2 no-underline text-inherit transition-colors hover:bg-accent/50",children:[e.jsx("span",{className:"hidden h-2 w-2 shrink-0 sm:inline-flex","aria-hidden":"true"}),e.jsx("span",{className:"hidden h-3.5 w-3.5 shrink-0 sm:inline-flex","aria-hidden":"true"}),e.jsx("span",{className:"mt-0.5 shrink-0 rounded-md bg-muted p-1.5 sm:mt-0",children:e.jsx(i,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"line-clamp-2 text-sm font-medium sm:truncate sm:line-clamp-none",children:o}),e.jsxs("span",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground",children:[e.jsx("span",{className:"capitalize",children:ab(t.status)}),s?e.jsxs("span",{children:["requested by ",s]}):null,e.jsxs("span",{children:["updated ",Lt(t.updatedAt)]})]})]})]}),l?e.jsxs("div",{className:"hidden shrink-0 items-center gap-2 sm:flex",children:[e.jsx(F,{size:"sm",className:"h-8 bg-green-700 px-3 text-white hover:bg-green-600",onClick:n,disabled:a,children:"Approve"}),e.jsx(F,{variant:"destructive",size:"sm",className:"h-8 px-3",onClick:r,disabled:a,children:"Reject"})]}):null]}),l?e.jsxs("div",{className:"mt-3 flex gap-2 sm:hidden",children:[e.jsx(F,{size:"sm",className:"h-8 bg-green-700 px-3 text-white hover:bg-green-600",onClick:n,disabled:a,children:"Approve"}),e.jsx(F,{variant:"destructive",size:"sm",className:"h-8 px-3",onClick:r,disabled:a,children:"Reject"})]}):null]})}function La(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),n=Mt(),r=bt(),a=Le(),[i,o]=c.useState(null),[l,u]=c.useState("everything"),[d,m]=c.useState("all"),{dismissed:x,dismiss:p}=Tc(),h=r.pathname.split("/").pop()??"recent",j=h==="all"||h==="unread"?h:"recent",y=c.useMemo(()=>_l("Inbox",`${r.pathname}${r.search}${r.hash}`),[r.pathname,r.search,r.hash]),{data:f}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t});c.useEffect(()=>{s([{label:"Inbox"}])},[s]),c.useEffect(()=>{$p(j)},[j]);const{data:g,isLoading:A,error:N}=V({queryKey:E.approvals.list(t),queryFn:()=>ut.list(t),enabled:!!t}),{data:C=[],isLoading:S}=V({queryKey:E.access.joinRequests(t),queryFn:async()=>{try{return await mn.listJoinRequests(t,"pending_approval")}catch($){if($ instanceof hl&&($.status===403||$.status===401))return[];throw $}},enabled:!!t,retry:!1}),{data:b,isLoading:v}=V({queryKey:E.dashboard(t),queryFn:()=>zi.summary(t),enabled:!!t}),{data:M,isLoading:k}=V({queryKey:E.issues.list(t),queryFn:()=>ht.list(t),enabled:!!t}),{data:_=[],isLoading:U}=V({queryKey:E.issues.listTouchedByMe(t),queryFn:()=>ht.list(t,{touchedByUserId:"me",status:"backlog,todo,in_progress,in_review,blocked,done"}),enabled:!!t}),{data:w,isLoading:T}=V({queryKey:E.heartbeats(t),queryFn:()=>Ht.list(t),enabled:!!t}),W=c.useMemo(()=>Ac(_),[_]),H=c.useMemo(()=>W.filter($=>$.isUnreadForMe),[W]),B=c.useMemo(()=>j==="unread"?H:W,[j,W,H]),D=c.useMemo(()=>{const $=new Map;for(const Q of f??[])$.set(Q.id,Q.name);return $},[f]),Z=c.useMemo(()=>{const $=new Map;for(const Q of M??[])$.set(Q.id,Q);return $},[M]),G=c.useMemo(()=>Sc(w??[]).filter($=>!x.has(`run:${$.id}`)),[w,x]),ie=c.useMemo(()=>{const $=new Set;for(const Q of w??[]){if(Q.status!=="running"&&Q.status!=="queued")continue;const ne=ad(Q);ne&&$.add(ne)}return $},[w]),ce=c.useMemo(()=>Lp(g??[],j,d),[g,j,d]),q=l==="everything"||l==="join_requests",J=l==="everything"||l==="issues_i_touched",I=l==="everything"||l==="approvals",P=l==="everything"||l==="failed_runs",O=l==="everything"||l==="alerts",te=c.useMemo(()=>j==="all"&&!P?[]:G,[G,j,P]),oe=c.useMemo(()=>Op({issues:j==="all"&&!J?[]:B,approvals:j==="all"&&!I?[]:ce,failedRuns:te}),[ce,B,I,J,j,te]),ue=$=>$?D.get($)??null:null,L=se({mutationFn:$=>ut.approve($),onSuccess:($,Q)=>{o(null),a.invalidateQueries({queryKey:E.approvals.list(t)}),n(`/approvals/${Q}?resolved=approved`)},onError:$=>{o($ instanceof Error?$.message:"Failed to approve")}}),ae=se({mutationFn:$=>ut.reject($),onSuccess:()=>{o(null),a.invalidateQueries({queryKey:E.approvals.list(t)})},onError:$=>{o($ instanceof Error?$.message:"Failed to reject")}}),le=se({mutationFn:$=>mn.approveJoinRequest(t,$.id),onSuccess:()=>{o(null),a.invalidateQueries({queryKey:E.access.joinRequests(t)}),a.invalidateQueries({queryKey:E.sidebarBadges(t)}),a.invalidateQueries({queryKey:E.agents.list(t)}),a.invalidateQueries({queryKey:E.companies.all})},onError:$=>{o($ instanceof Error?$.message:"Failed to approve join request")}}),Re=se({mutationFn:$=>mn.rejectJoinRequest(t,$.id),onSuccess:()=>{o(null),a.invalidateQueries({queryKey:E.access.joinRequests(t)}),a.invalidateQueries({queryKey:E.sidebarBadges(t)})},onError:$=>{o($ instanceof Error?$.message:"Failed to reject join request")}}),[ee,ye]=c.useState(new Set),Ce=se({mutationFn:async $=>{const Q={},ne=$.contextSnapshot;ne&&(typeof ne.issueId=="string"&&ne.issueId&&(Q.issueId=ne.issueId),typeof ne.taskId=="string"&&ne.taskId&&(Q.taskId=ne.taskId),typeof ne.taskKey=="string"&&ne.taskKey&&(Q.taskKey=ne.taskKey));const je=await Ee.wakeup($.agentId,{source:"on_demand",triggerDetail:"manual",reason:"retry_failed_run",payload:Q});if(!("id"in je))throw new Error("Retry was skipped because the agent is not currently invokable.");return{newRun:je,originalRun:$}},onMutate:$=>{ye(Q=>new Set(Q).add($.id))},onSuccess:({newRun:$,originalRun:Q})=>{a.invalidateQueries({queryKey:E.heartbeats(Q.companyId)}),a.invalidateQueries({queryKey:E.heartbeats(Q.companyId,Q.agentId)}),n(`/agents/${Q.agentId}/runs/${$.id}`)},onSettled:($,Q,ne)=>{ne&&ye(je=>{const _e=new Set(je);return _e.delete(ne.id),_e})}}),[He,K]=c.useState(new Set),de=()=>{t&&(a.invalidateQueries({queryKey:E.issues.listTouchedByMe(t)}),a.invalidateQueries({queryKey:E.issues.listUnreadTouchedByMe(t)}),a.invalidateQueries({queryKey:E.sidebarBadges(t)}))},fe=se({mutationFn:$=>ht.markRead($),onMutate:$=>{K(Q=>new Set(Q).add($))},onSuccess:()=>{de()},onSettled:($,Q,ne)=>{setTimeout(()=>{K(je=>{const _e=new Set(je);return _e.delete(ne),_e})},300)}}),Ie=se({mutationFn:async $=>{await Promise.all($.map(Q=>ht.markRead(Q)))},onMutate:$=>{K(Q=>{const ne=new Set(Q);for(const je of $)ne.add(je);return ne})},onSuccess:()=>{de()},onSettled:($,Q,ne)=>{setTimeout(()=>{K(je=>{const _e=new Set(je);for(const tt of ne)_e.delete(tt);return _e})},300)}});if(!t)return e.jsx(Be,{icon:ys,message:"Select a company to view inbox."});const ze=G.length>0,Qt=!!b&&b.agents.error>0&&!ze&&!x.has("alert:agent-errors"),Fs=!!b&&b.costs.monthBudgetCents>0&&b.costs.monthUtilizationPercent>=80&&!x.has("alert:budget"),us=Qt||Fs,Ls=C.length>0,ct=oe.length>0,Qe=j==="all"?q&&Ls:j==="unread"&&Ls,Yt=qp({tab:j,hasItems:us,showOnRecent:us,showOnUnread:us,showOnAll:O&&us}),zt=[Yt?"alerts":null,Qe?"join_requests":null,ct?"work_items":null].filter($=>$!==null),It=!S&&!A&&!v&&!k&&!U&&!T,ms=$=>zt.indexOf($)>0,R=H.filter($=>!He.has($.id)).map($=>$.id),X=R.length>0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ut,{value:j,onValueChange:$=>n(`/inbox/${$}`),children:e.jsx(Hs,{items:[{value:"recent",label:"Recent"},{value:"unread",label:"Unread"},{value:"all",label:"All"}]})}),X&&e.jsx(F,{type:"button",variant:"outline",size:"sm",className:"h-8 shrink-0",onClick:()=>Ie.mutate(R),disabled:Ie.isPending,children:Ie.isPending?"Marking…":"Mark all as read"})]}),j==="all"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:justify-end",children:[e.jsxs(Cn,{value:l,onValueChange:$=>u($),children:[e.jsx(In,{className:"h-8 w-[170px] text-xs",children:e.jsx(Sn,{placeholder:"Category"})}),e.jsxs(An,{children:[e.jsx(De,{value:"everything",children:"All categories"}),e.jsx(De,{value:"issues_i_touched",children:"My recent issues"}),e.jsx(De,{value:"join_requests",children:"Join requests"}),e.jsx(De,{value:"approvals",children:"Approvals"}),e.jsx(De,{value:"failed_runs",children:"Failed runs"}),e.jsx(De,{value:"alerts",children:"Alerts"})]})]}),I&&e.jsxs(Cn,{value:d,onValueChange:$=>m($),children:[e.jsx(In,{className:"h-8 w-[170px] text-xs",children:e.jsx(Sn,{placeholder:"Approval status"})}),e.jsxs(An,{children:[e.jsx(De,{value:"all",children:"All approval statuses"}),e.jsx(De,{value:"actionable",children:"Needs action"}),e.jsx(De,{value:"resolved",children:"Resolved"})]})]})]})]}),N&&e.jsx("p",{className:"text-sm text-destructive",children:N.message}),i&&e.jsx("p",{className:"text-sm text-destructive",children:i}),!It&&zt.length===0&&e.jsx(rt,{variant:"inbox"}),It&&zt.length===0&&e.jsx(Be,{icon:ys,message:j==="unread"?"No new inbox items.":j==="recent"?"No recent inbox items.":"No inbox items match these filters."}),ct&&e.jsxs(e.Fragment,{children:[ms("work_items")&&e.jsx(Rt,{}),e.jsx("div",{children:e.jsx("div",{className:"overflow-hidden rounded-xl border border-border bg-card",children:oe.map($=>{if($.kind==="approval")return e.jsx(ob,{approval:$.approval,requesterName:ue($.approval.requestedByAgentId),onApprove:()=>L.mutate($.approval.id),onReject:()=>ae.mutate($.approval.id),isPending:L.isPending||ae.isPending},`approval:${$.approval.id}`);if($.kind==="failed_run")return e.jsx(ib,{run:$.run,issueById:Z,agentName:ue($.run.agentId),issueLinkState:y,onDismiss:()=>p(`run:${$.run.id}`),onRetry:()=>Ce.mutate($.run),isRetrying:ee.has($.run.id)},`run:${$.run.id}`);const Q=$.issue,ne=Q.isUnreadForMe&&!He.has(Q.id),je=He.has(Q.id);return e.jsx(Rl,{issue:Q,issueLinkState:y,desktopMetaLeading:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"hidden sm:inline-flex",children:e.jsx(Nt,{priority:Q.priority})}),e.jsx("span",{className:"hidden shrink-0 sm:inline-flex",children:e.jsx(wt,{status:Q.status})}),e.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:Q.identifier??Q.id.slice(0,8)}),ie.has(Q.id)&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-500/10 px-1.5 py-0.5 sm:gap-1.5 sm:px-2",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-blue-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-blue-500"})]}),e.jsx("span",{className:"hidden text-[11px] font-medium text-blue-600 dark:text-blue-400 sm:inline",children:"Live"})]})]}),mobileMeta:Q.lastExternalCommentAt?`commented ${Lt(Q.lastExternalCommentAt)}`:`updated ${Lt(Q.updatedAt)}`,unreadState:ne?"visible":je?"fading":"hidden",onMarkRead:()=>fe.mutate(Q.id),trailingMeta:Q.lastExternalCommentAt?`commented ${Lt(Q.lastExternalCommentAt)}`:`updated ${Lt(Q.updatedAt)}`},`issue:${Q.id}`)})})})]}),Qe&&e.jsxs(e.Fragment,{children:[ms("join_requests")&&e.jsx(Rt,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Join Requests"}),e.jsx("div",{className:"grid gap-3",children:C.map($=>e.jsx("div",{className:"rounded-xl border border-border bg-card p-4",children:e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:$.requestType==="human"?"Human join request":`Agent join request${$.agentName?`: ${$.agentName}`:""}`}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["requested ",Lt($.createdAt)," from IP ",$.requestIp]}),$.requestEmailSnapshot&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["email: ",$.requestEmailSnapshot]}),$.adapterType&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["adapter: ",$.adapterType]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{size:"sm",variant:"outline",disabled:le.isPending||Re.isPending,onClick:()=>Re.mutate($),children:"Reject"}),e.jsx(F,{size:"sm",disabled:le.isPending||Re.isPending,onClick:()=>le.mutate($),children:"Approve"})]})]})},$.id))})]})]}),Yt&&e.jsxs(e.Fragment,{children:[ms("alerts")&&e.jsx(Rt,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Alerts"}),e.jsxs("div",{className:"divide-y divide-border border border-border",children:[Qt&&e.jsxs("div",{className:"group/alert relative flex items-center gap-3 px-4 py-3 transition-colors hover:bg-accent/50",children:[e.jsxs(xe,{to:"/agents",className:"flex flex-1 cursor-pointer items-center gap-3 no-underline text-inherit",children:[e.jsx(gn,{className:"h-4 w-4 shrink-0 text-red-600 dark:text-red-400"}),e.jsxs("span",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:b.agents.error})," ",b.agents.error===1?"agent has":"agents have"," errors"]})]}),e.jsx("button",{type:"button",onClick:()=>p("alert:agent-errors"),className:"rounded-md p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover/alert:opacity-100","aria-label":"Dismiss",children:e.jsx(St,{className:"h-3.5 w-3.5"})})]}),Fs&&e.jsxs("div",{className:"group/alert relative flex items-center gap-3 px-4 py-3 transition-colors hover:bg-accent/50",children:[e.jsxs(xe,{to:"/costs",className:"flex flex-1 cursor-pointer items-center gap-3 no-underline text-inherit",children:[e.jsx(gn,{className:"h-4 w-4 shrink-0 text-yellow-400"}),e.jsxs("span",{className:"text-sm",children:["Budget at"," ",e.jsxs("span",{className:"font-medium",children:[b.costs.monthUtilizationPercent,"%"]})," ","utilization this month"]})]}),e.jsx("button",{type:"button",onClick:()=>p("alert:budget"),className:"rounded-md p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover/alert:opacity-100","aria-label":"Dismiss",children:e.jsx(St,{className:"h-3.5 w-3.5"})})]})]})]})]})]})}function lb(){var P,O,te,oe,ue,L,ae,le,Re;const{companies:t,selectedCompany:s,selectedCompanyId:n,setSelectedCompanyId:r}=he(),{setBreadcrumbs:a}=Me(),i=Le(),{pushToast:o}=ji(),[l,u]=c.useState(""),[d,m]=c.useState(""),[x,p]=c.useState(""),[h,j]=c.useState(""),[y,f]=c.useState(null);c.useEffect(()=>{s&&(u(s.name),m(s.description??""),p(s.brandColor??""),j(s.logoUrl??""))},[s]);const[g,A]=c.useState(null),[N,C]=c.useState(null),[S,b]=c.useState(!1),[v,M]=c.useState(0),k=!!s&&(l!==s.name||d!==(s.description??"")||x!==(s.brandColor??"")),_=se({mutationFn:ee=>As.update(n,ee),onSuccess:()=>{i.invalidateQueries({queryKey:E.companies.all})}}),U=se({mutationFn:ee=>As.update(n,{requireBoardApprovalForNewAgents:ee}),onSuccess:()=>{i.invalidateQueries({queryKey:E.companies.all})}}),w=se({mutationFn:()=>mn.createOpenClawInvitePrompt(n),onSuccess:async ee=>{var de,fe,Ie;A(null);const ye=window.location.origin.replace(/\/+$/,""),Ce=ee.onboardingTextUrl??ee.onboardingTextPath??`/api/invites/${ee.token}/onboarding.txt`,He=Ce.startsWith("http")?Ce:`${ye}${Ce}`;b(!1),M(0);let K;try{const ze=await mn.getInviteOnboarding(ee.token);K=Xo({onboardingTextUrl:He,connectionCandidates:((de=ze.onboarding.connectivity)==null?void 0:de.connectionCandidates)??null,testResolutionUrl:((Ie=(fe=ze.onboarding.connectivity)==null?void 0:fe.testResolutionEndpoint)==null?void 0:Ie.url)??null})}catch{K=Xo({onboardingTextUrl:He,connectionCandidates:null,testResolutionUrl:null})}C(K);try{await navigator.clipboard.writeText(K),b(!0),M(ze=>ze+1),setTimeout(()=>b(!1),2e3)}catch{}i.invalidateQueries({queryKey:E.sidebarBadges(n)})},onError:ee=>{A(ee instanceof Error?ee.message:"Failed to create invite")}}),T=ee=>{j(ee??""),i.invalidateQueries({queryKey:E.companies.all})},W=se({mutationFn:ee=>or.uploadCompanyLogo(n,ee).then(ye=>As.update(n,{logoAssetId:ye.assetId})),onSuccess:ee=>{T(ee.logoUrl),f(null)}}),H=se({mutationFn:()=>As.update(n,{logoAssetId:null}),onSuccess:ee=>{f(null),T(ee.logoUrl)}});function B(ee){var Ce;const ye=((Ce=ee.target.files)==null?void 0:Ce[0])??null;ee.currentTarget.value="",ye&&(f(null),W.mutate(ye))}function D(){H.mutate()}c.useEffect(()=>{A(null),C(null),b(!1),M(0)},[n]);const Z=se({mutationFn:({companyId:ee,nextCompanyId:ye})=>As.archive(ee).then(()=>({nextCompanyId:ye})),onSuccess:async({nextCompanyId:ee})=>{ee&&r(ee),await i.invalidateQueries({queryKey:E.companies.all}),await i.invalidateQueries({queryKey:E.companies.stats})}});c.useEffect(()=>{a([{label:(s==null?void 0:s.name)??"Company",href:"/dashboard"},{label:"Settings"}])},[a,s==null?void 0:s.name]);const G=V({queryKey:["gtm","connection"],queryFn:()=>gr.getConnection()}),ie=V({queryKey:["gtm","connectors"],queryFn:()=>gr.getConnectors()}),ce=V({queryKey:E.auth.session,queryFn:()=>na.getSession(),retry:!1}),q=se({mutationFn:()=>gr.testConnection(),onSuccess:async ee=>{await Promise.all([i.invalidateQueries({queryKey:["gtm","connection"]}),i.invalidateQueries({queryKey:["gtm","connectors"]})]),o({title:"Growthub pulse succeeded",body:ee.message,tone:"success"})},onError:ee=>{o({title:"Growthub pulse failed",body:ee instanceof Error?ee.message:"Failed to verify the Growthub local route handler",tone:"error"})}}),J=se({mutationFn:()=>gr.disconnectConnection(),onSuccess:async()=>{await Promise.all([i.invalidateQueries({queryKey:["gtm","connection"]}),i.invalidateQueries({queryKey:["gtm","connectors"]})]),o({title:"Growthub disconnected",body:"Local connection state was cleared for this installer.",tone:"success"})},onError:ee=>{o({title:"Disconnect failed",body:ee instanceof Error?ee.message:"Failed to disconnect Growthub locally",tone:"error"})}});if(!s)return e.jsx("div",{className:"text-sm text-muted-foreground",children:"No company selected. Select a company from the switcher above."});function I(){_.mutate({name:l.trim(),description:d.trim()||null,brandColor:x||null})}return e.jsxs("div",{className:"max-w-2xl space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h1",{className:"text-lg font-semibold",children:"Company Settings"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"General"}),e.jsxs("div",{className:"space-y-3 rounded-md border border-border px-4 py-4",children:[e.jsx(fr,{label:"Company name",hint:"The display name for your company.",children:e.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-2.5 py-1.5 text-sm outline-none",type:"text",value:l,onChange:ee=>u(ee.target.value)})}),e.jsx(fr,{label:"Description",hint:"Optional description shown in the company profile.",children:e.jsx("input",{className:"w-full rounded-md border border-border bg-transparent px-2.5 py-1.5 text-sm outline-none",type:"text",value:d,placeholder:"Optional company description",onChange:ee=>m(ee.target.value)})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Appearance"}),e.jsx("div",{className:"space-y-3 rounded-md border border-border px-4 py-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"shrink-0",children:e.jsx(ml,{companyName:l||s.name,logoUrl:h||null,brandColor:x||null,className:"rounded-[14px]"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(fr,{label:"Logo",hint:"Upload a PNG, JPEG, WEBP, GIF, or SVG logo image.",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp,image/gif,image/svg+xml",onChange:B,className:"w-full rounded-md border border-border bg-transparent px-2.5 py-1.5 text-sm outline-none file:mr-4 file:rounded-md file:border-0 file:bg-muted file:px-2.5 file:py-1 file:text-xs"}),h&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{size:"sm",variant:"outline",onClick:D,disabled:H.isPending,children:H.isPending?"Removing...":"Remove logo"})}),(W.isError||y)&&e.jsx("span",{className:"text-xs text-destructive",children:y??(W.error instanceof Error?W.error.message:"Logo upload failed")}),H.isError&&e.jsx("span",{className:"text-xs text-destructive",children:H.error.message}),W.isPending&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Uploading logo..."})]})}),e.jsx(fr,{label:"Brand color",hint:"Sets the hue for the company icon. Leave empty for auto-generated color.",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:x||"#6366f1",onChange:ee=>p(ee.target.value),className:"h-8 w-8 cursor-pointer rounded border border-border bg-transparent p-0"}),e.jsx("input",{type:"text",value:x,onChange:ee=>{const ye=ee.target.value;(ye===""||/^#[0-9a-fA-F]{0,6}$/.test(ye))&&p(ye)},placeholder:"Auto",className:"w-28 rounded-md border border-border bg-transparent px-2.5 py-1.5 text-sm font-mono outline-none"}),x&&e.jsx(F,{size:"sm",variant:"ghost",onClick:()=>p(""),className:"text-xs text-muted-foreground",children:"Clear"})]})})]})]})})]}),k&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{size:"sm",onClick:I,disabled:_.isPending||!l.trim(),children:_.isPending?"Saving...":"Save changes"}),_.isSuccess&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Saved"}),_.isError&&e.jsx("span",{className:"text-xs text-destructive",children:_.error instanceof Error?_.error.message:"Failed to save"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Hiring"}),e.jsx("div",{className:"rounded-md border border-border px-4 py-3",children:e.jsx(Iu,{label:"Require board approval for new hires",hint:"New agent hires stay pending until approved by board.",checked:!!s.requireBoardApprovalForNewAgents,onChange:ee=>U.mutate(ee)})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Invites"}),e.jsxs("div",{className:"space-y-3 rounded-md border border-border px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Generate an OpenClaw agent invite snippet."}),e.jsx(Au,{text:"Creates a short-lived OpenClaw agent invite and renders a copy-ready prompt."})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsx(F,{size:"sm",onClick:()=>w.mutate(),disabled:w.isPending,children:w.isPending?"Generating...":"Generate OpenClaw Invite Prompt"})}),g&&e.jsx("p",{className:"text-sm text-destructive",children:g}),N&&e.jsxs("div",{className:"rounded-md border border-border bg-muted/30 p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"OpenClaw Invite Prompt"}),S&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-600 animate-pulse",children:[e.jsx(Ns,{className:"h-3 w-3"}),"Copied"]},v)]}),e.jsxs("div",{className:"mt-1 space-y-1.5",children:[e.jsx("textarea",{className:"h-[28rem] w-full rounded-md border border-border bg-background px-2 py-1.5 font-mono text-xs outline-none",value:N,readOnly:!0}),e.jsx("div",{className:"flex justify-end",children:e.jsx(F,{size:"sm",variant:"ghost",onClick:async()=>{try{await navigator.clipboard.writeText(N),b(!0),M(ee=>ee+1),setTimeout(()=>b(!1),2e3)}catch{}},children:S?"Copied snippet":"Copy snippet"})})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Growthub Connection"}),G.isLoading?e.jsx("div",{className:"rounded-md border border-border px-4 py-4 text-sm text-muted-foreground",children:"Loading connection…"}):G.error?e.jsx("div",{className:"rounded-md border border-destructive/40 px-4 py-4 text-sm text-destructive",children:G.error instanceof Error?G.error.message:"Failed to load Growthub connection"}):e.jsx(Tu,{description:"Connect this local DX install to the hosted Growthub workspace.",connected:((P=G.data)==null?void 0:P.connected)??!1,baseUrl:((O=G.data)==null?void 0:O.baseUrl)??"",callbackUrl:((te=G.data)==null?void 0:te.callbackUrl)??"",portalBaseUrl:((oe=G.data)==null?void 0:oe.portalBaseUrl)??"",machineLabel:((ue=G.data)==null?void 0:ue.machineLabel)??"",workspaceLabel:((L=G.data)==null?void 0:L.workspaceLabel)??"",openDisabled:!(((ae=G.data)==null?void 0:ae.baseUrl)??"").trim(),onOpenConfiguration:()=>{var Ce;const ee=G.data;if(!((Ce=ee==null?void 0:ee.baseUrl)!=null&&Ce.trim())){o({title:"Growthub base URL missing",body:"Configure the hosted Growthub URL before opening the connection flow.",tone:"error"});return}if(!Pu(ce.data??null)){o({title:"Sign in required",body:"Sign in locally before opening the hosted Growthub configuration flow.",tone:"error"});return}window.open(Eu({baseUrl:ee.baseUrl,callbackUrl:ee.callbackUrl,workspaceLabel:s.name}),"_blank","noopener,noreferrer")},onRefresh:()=>{G.refetch(),ie.refetch()},onPulseConnection:(le=G.data)!=null&&le.connected?()=>q.mutate():void 0,onDisconnect:(Re=G.data)!=null&&Re.connected?()=>J.mutate():void 0,pulsePending:q.isPending,disconnectPending:J.isPending})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-destructive uppercase tracking-wide",children:"Danger Zone"}),e.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Archive this company to hide it from the sidebar. This persists in the database."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{size:"sm",variant:"destructive",disabled:Z.isPending||s.status==="archived",onClick:()=>{var Ce;if(!n||!window.confirm(`Archive company "${s.name}"? It will be hidden from the sidebar.`))return;const ye=((Ce=t.find(He=>He.id!==n&&He.status!=="archived"))==null?void 0:Ce.id)??null;Z.mutate({companyId:n,nextCompanyId:ye})},children:Z.isPending?"Archiving...":s.status==="archived"?"Already archived":"Archive company"}),Z.isError&&e.jsx("span",{className:"text-xs text-destructive",children:Z.error instanceof Error?Z.error.message:"Failed to archive company"})]})]})]})]})}function Xo(t){const s=cb(t),n=db(t),r=s.length>0?s.map(o=>`- ${o}`).join(`
198
+ `):"- (No candidate URLs available yet.)",a=s.length===0?`No candidate URLs are available. Ask your user to configure a reachable hostname in Growthub, then retry.
199
+ Suggested steps:
200
+ - choose a hostname that resolves to the Growthub host from your runtime
201
+ - run: pnpm growthub allowed-hostname <host>
202
+ - restart Growthub
203
+ - verify with: curl -fsS http://<host>:3100/api/health
204
+ - regenerate this invite snippet`:`If none are reachable, ask your user to add a reachable hostname in Growthub, restart, and retry.
205
+ Suggested command:
206
+ - pnpm growthub allowed-hostname <host>
207
+ Then verify with: curl -fsS <base-url>/api/health`,i=n?`
208
+ You MUST test Growthub-to-gateway reachability, call: ${n}?url=<urlencoded-gateway-url> (using the hostname that worked above). Do not assume your 172.x is necessarily reachable from Growthub. Test it. `:"";return`You're invited to join a Growthub organization.
209
+
210
+ The URLs you should try are:
211
+ ${r}
212
+
213
+ Connectivity guidance:
214
+ If you are running on a different machine than Growthub, Growthub must be reachable at one of the hostnames used above.
215
+ Verify the hostname works from your runtime with: GET <base-url>/api/health
216
+
217
+ ${a}
218
+
219
+ For your "agentName", just use your own agent name (OpenClaw or whatever your name is) and send it directly.
220
+ You also need to send a gateway URL that Growthub can access. Check your config and include that URL.${i}
221
+
222
+ ---
223
+
224
+ This onboarding flow is for OpenClaw Gateway.
225
+ When you submit the join request, use:
226
+ - \`adapterType: "openclaw_gateway"\`
227
+ - \`agentDefaultsPayload.url\` as your \`ws://\` or \`wss://\` gateway URL
228
+ - \`agentDefaultsPayload.headers["x-openclaw-token"]\` with your gateway token
229
+ - (legacy accepted) \`agentDefaultsPayload.headers["x-openclaw-auth"]\`
230
+ - Keep device auth enabled (recommended). If \`devicePrivateKeyPem\` is omitted, Growthub will generate and persist one during join so pairing approvals remain stable.
231
+ - Only use \`disableDeviceAuth=true\` for special environments where pairing cannot be completed.
232
+
233
+ Do NOT use \`/v1/responses\` or \`/hooks/*\` in this join flow.
234
+
235
+ Before you do anything, please respond to your user that you understand the instructions and you're going to work on them. Then do the step above in another session called "growthub-onboarding" and then tell your user when you're done. Update your user in intermediate steps along the way so they know what's going on.
236
+
237
+ Then after you've connected to Growthub (exchanged keys etc.) you MUST review and follow the onboarding instructions in onboarding.txt they give you.
238
+
239
+ `}function cb(t){const s=(t.connectionCandidates??[]).map(i=>i.trim()).filter(Boolean),n=new Set;let r=null;try{r=new URL(t.onboardingTextUrl),n.add(r.toString())}catch{const i=t.onboardingTextUrl.trim();i&&n.add(i)}if(!r){for(const i of s)n.add(i);return Array.from(n)}const a=`${r.pathname}${r.search}`;for(const i of s)try{const o=new URL(i);n.add(`${o.origin}${a}`)}catch{n.add(i)}return Array.from(n)}function db(t){var n;const s=(n=t.testResolutionUrl)==null?void 0:n.trim();if(s)return s;try{const r=new URL(t.onboardingTextUrl),a=r.pathname.replace(/\/onboarding\.txt$/,"/test-resolution");return`${r.origin}${a}`}catch{return null}}function Pt({className:t,...s}){return e.jsx(Mm,{"data-slot":"label",className:z("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",t),...s})}function ub({filters:t,onRemove:s,onClear:n}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.map(r=>e.jsxs(Ne,{variant:"secondary",className:"gap-1 pr-1",children:[e.jsxs("span",{className:"text-muted-foreground",children:[r.label,":"]}),e.jsx("span",{children:r.value}),e.jsx("button",{className:"ml-1 rounded-full hover:bg-accent p-0.5",onClick:()=>s(r.key),children:e.jsx(St,{className:"h-3 w-3"})})]},r.key)),e.jsx(F,{variant:"ghost",size:"sm",className:"text-xs h-6",onClick:n,children:"Clear all"})]})}function pe({title:t,children:s}){return e.jsxs("section",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:t}),e.jsx(Rt,{}),s]})}function ge({title:t,children:s}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium",children:t}),s]})}function Ke({name:t,cssVar:s}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-8 w-8 rounded-md border border-border shrink-0",style:{backgroundColor:`var(${s})`}}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-mono",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})]})}function mb(){const[t,s]=c.useState("todo"),[n,r]=c.useState("medium"),[a,i]=c.useState("in_progress"),[o,l]=c.useState(!0),[u,d]=c.useState(!1),[m,x]=c.useState("Click to edit this text"),[p,h]=c.useState("Editable Title"),[j,y]=c.useState("This is an editable description. Click to edit it — the textarea auto-sizes to fit the content without layout shift."),[f,g]=c.useState([{key:"status",label:"Status",value:"Active"},{key:"priority",label:"Priority",value:"High"}]);return e.jsxs("div",{className:"space-y-10 max-w-4xl",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold",children:"Design Guide"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Every component, style, and pattern used across Growthub."})]}),e.jsxs(pe,{title:"Component Coverage",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This page should be updated when new UI primitives or app-level patterns ship."}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(ge,{title:"UI primitives",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:["avatar","badge","breadcrumb","button","card","checkbox","collapsible","command","dialog","dropdown-menu","input","label","popover","scroll-area","select","separator","sheet","skeleton","tabs","textarea","tooltip"].map(A=>e.jsx(Ne,{variant:"outline",className:"font-mono text-[10px]",children:A},A))})}),e.jsx(ge,{title:"App components",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:["StatusBadge","StatusIcon","PriorityIcon","EntityRow","EmptyState","MetricCard","FilterBar","InlineEditor","PageSkeleton","Identity","CommentThread","MarkdownEditor","PropertiesPanel","Sidebar","CommandPalette"].map(A=>e.jsx(Ne,{variant:"ghost",className:"font-mono text-[10px]",children:A},A))})})]})]}),e.jsxs(pe,{title:"Colors",children:[e.jsx(ge,{title:"Core",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsx(Ke,{name:"Background",cssVar:"--background"}),e.jsx(Ke,{name:"Foreground",cssVar:"--foreground"}),e.jsx(Ke,{name:"Card",cssVar:"--card"}),e.jsx(Ke,{name:"Primary",cssVar:"--primary"}),e.jsx(Ke,{name:"Primary foreground",cssVar:"--primary-foreground"}),e.jsx(Ke,{name:"Secondary",cssVar:"--secondary"}),e.jsx(Ke,{name:"Muted",cssVar:"--muted"}),e.jsx(Ke,{name:"Muted foreground",cssVar:"--muted-foreground"}),e.jsx(Ke,{name:"Accent",cssVar:"--accent"}),e.jsx(Ke,{name:"Destructive",cssVar:"--destructive"}),e.jsx(Ke,{name:"Border",cssVar:"--border"}),e.jsx(Ke,{name:"Ring",cssVar:"--ring"})]})}),e.jsx(ge,{title:"Sidebar",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsx(Ke,{name:"Sidebar",cssVar:"--sidebar"}),e.jsx(Ke,{name:"Sidebar border",cssVar:"--sidebar-border"})]})}),e.jsx(ge,{title:"Chart",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[e.jsx(Ke,{name:"Chart 1",cssVar:"--chart-1"}),e.jsx(Ke,{name:"Chart 2",cssVar:"--chart-2"}),e.jsx(Ke,{name:"Chart 3",cssVar:"--chart-3"}),e.jsx(Ke,{name:"Chart 4",cssVar:"--chart-4"}),e.jsx(Ke,{name:"Chart 5",cssVar:"--chart-5"})]})})]}),e.jsx(pe,{title:"Typography",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-xl font-bold",children:"Page Title — text-xl font-bold"}),e.jsx("h2",{className:"text-lg font-semibold",children:"Section Title — text-lg font-semibold"}),e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Section Heading — text-sm font-semibold uppercase tracking-wide"}),e.jsx("p",{className:"text-sm font-medium",children:"Card Title — text-sm font-medium"}),e.jsx("p",{className:"text-sm font-semibold",children:"Card Title Alt — text-sm font-semibold"}),e.jsx("p",{className:"text-sm",children:"Body text — text-sm"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Muted description — text-sm text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tiny label — text-xs text-muted-foreground"}),e.jsx("p",{className:"text-sm font-mono text-muted-foreground",children:"Mono identifier — text-sm font-mono text-muted-foreground"}),e.jsx("p",{className:"text-2xl font-bold",children:"Large stat — text-2xl font-bold"}),e.jsx("p",{className:"font-mono text-xs",children:"Log/code text — font-mono text-xs"})]})}),e.jsx(pe,{title:"Radius",children:e.jsx("div",{className:"flex items-end gap-4 flex-wrap",children:[["sm","var(--radius-sm)"],["md","var(--radius-md)"],["lg","var(--radius-lg)"],["xl","var(--radius-xl)"],["full","9999px"]].map(([A,N])=>e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("div",{className:"h-12 w-12 bg-primary",style:{borderRadius:N}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:A})]},A))})}),e.jsxs(pe,{title:"Buttons",children:[e.jsx(ge,{title:"Variants",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(F,{variant:"default",children:"Default"}),e.jsx(F,{variant:"secondary",children:"Secondary"}),e.jsx(F,{variant:"outline",children:"Outline"}),e.jsx(F,{variant:"ghost",children:"Ghost"}),e.jsx(F,{variant:"destructive",children:"Destructive"}),e.jsx(F,{variant:"link",children:"Link"})]})}),e.jsx(ge,{title:"Sizes",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(F,{size:"xs",children:"Extra Small"}),e.jsx(F,{size:"sm",children:"Small"}),e.jsx(F,{size:"default",children:"Default"}),e.jsx(F,{size:"lg",children:"Large"})]})}),e.jsx(ge,{title:"Icon buttons",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(F,{variant:"ghost",size:"icon-xs",children:e.jsx(gs,{})}),e.jsx(F,{variant:"ghost",size:"icon-sm",children:e.jsx(gs,{})}),e.jsx(F,{variant:"outline",size:"icon",children:e.jsx(gs,{})}),e.jsx(F,{variant:"outline",size:"icon-lg",children:e.jsx(gs,{})})]})}),e.jsx(ge,{title:"With icons",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(F,{children:[e.jsx(Pe,{})," New Issue"]}),e.jsxs(F,{variant:"outline",children:[e.jsx(ho,{})," Upload"]}),e.jsxs(F,{variant:"destructive",children:[e.jsx(js,{})," Delete"]}),e.jsxs(F,{size:"sm",children:[e.jsx(Pe,{})," Add"]})]})}),e.jsx(ge,{title:"States",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(F,{disabled:!0,children:"Disabled"}),e.jsx(F,{variant:"outline",disabled:!0,children:"Disabled Outline"})]})})]}),e.jsx(pe,{title:"Badges",children:e.jsx(ge,{title:"Variants",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(Ne,{variant:"default",children:"Default"}),e.jsx(Ne,{variant:"secondary",children:"Secondary"}),e.jsx(Ne,{variant:"outline",children:"Outline"}),e.jsx(Ne,{variant:"destructive",children:"Destructive"}),e.jsx(Ne,{variant:"ghost",children:"Ghost"})]})})}),e.jsxs(pe,{title:"Status System",children:[e.jsx(ge,{title:"StatusBadge (all statuses)",children:e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:["active","running","paused","idle","archived","planned","achieved","completed","failed","timed_out","succeeded","error","pending_approval","backlog","todo","in_progress","in_review","blocked","done","terminated","cancelled","pending","revision_requested","approved","rejected"].map(A=>e.jsx(Se,{status:A},A))})}),e.jsxs(ge,{title:"StatusIcon (interactive)",children:[e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:["backlog","todo","in_progress","in_review","done","cancelled","blocked"].map(A=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(wt,{status:A}),e.jsx("span",{className:"text-xs text-muted-foreground",children:A})]},A))}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(wt,{status:t,onChange:s}),e.jsxs("span",{className:"text-sm",children:["Click the icon to change status (current: ",t,")"]})]})]}),e.jsxs(ge,{title:"PriorityIcon (interactive)",children:[e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:["critical","high","medium","low"].map(A=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Nt,{priority:A}),e.jsx("span",{className:"text-xs text-muted-foreground",children:A})]},A))}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(Nt,{priority:n,onChange:r}),e.jsxs("span",{className:"text-sm",children:["Click the icon to change (current: ",n,")"]})]})]}),e.jsx(ge,{title:"Agent status dots",children:e.jsx("div",{className:"flex items-center gap-4 flex-wrap",children:["running","active","paused","error","archived"].map(A=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"relative flex h-2.5 w-2.5",children:e.jsx("span",{className:`inline-flex h-full w-full rounded-full ${fi[A]??bi}`})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:A})]},A))})}),e.jsx(ge,{title:"Run invocation badges",children:e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:[["timer","bg-blue-100 text-blue-700 dark:bg-blue-900/50 dark:text-blue-300"],["assignment","bg-violet-100 text-violet-700 dark:bg-violet-900/50 dark:text-violet-300"],["on_demand","bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300"],["automation","bg-muted text-muted-foreground"]].map(([A,N])=>e.jsx("span",{className:`rounded-full px-1.5 py-0.5 text-[10px] font-medium ${N}`,children:A},A))})})]}),e.jsx(pe,{title:"Form Elements",children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(ge,{title:"Input",children:[e.jsx(Ot,{placeholder:"Default input"}),e.jsx(Ot,{placeholder:"Disabled input",disabled:!0,className:"mt-2"})]}),e.jsx(ge,{title:"Textarea",children:e.jsx(un,{placeholder:"Write something..."})}),e.jsx(ge,{title:"Checkbox & Label",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ss,{id:"check1",defaultChecked:!0}),e.jsx(Pt,{htmlFor:"check1",children:"Checked item"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ss,{id:"check2"}),e.jsx(Pt,{htmlFor:"check2",children:"Unchecked item"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ss,{id:"check3",disabled:!0}),e.jsx(Pt,{htmlFor:"check3",children:"Disabled item"})]})]})}),e.jsx(ge,{title:"Inline Editor",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Title (single-line)"}),e.jsx(Rs,{value:p,onSave:h,as:"h2",className:"text-xl font-bold"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Body text (single-line)"}),e.jsx(Rs,{value:m,onSave:x,as:"p",className:"text-sm"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Description (multiline, auto-sizing)"}),e.jsx(Rs,{value:j,onSave:y,as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0})]})]})})]})}),e.jsx(pe,{title:"Select",children:e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(ge,{title:"Default size",children:[e.jsxs(Cn,{value:a,onValueChange:i,children:[e.jsx(In,{className:"w-full",children:e.jsx(Sn,{placeholder:"Select status"})}),e.jsxs(An,{children:[e.jsx(De,{value:"backlog",children:"Backlog"}),e.jsx(De,{value:"todo",children:"Todo"}),e.jsx(De,{value:"in_progress",children:"In Progress"}),e.jsx(De,{value:"in_review",children:"In Review"}),e.jsx(De,{value:"done",children:"Done"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Current value: ",a]})]}),e.jsx(ge,{title:"Small trigger",children:e.jsxs(Cn,{defaultValue:"high",children:[e.jsx(In,{size:"sm",className:"w-full",children:e.jsx(Sn,{})}),e.jsxs(An,{children:[e.jsx(De,{value:"critical",children:"Critical"}),e.jsx(De,{value:"high",children:"High"}),e.jsx(De,{value:"medium",children:"Medium"}),e.jsx(De,{value:"low",children:"Low"})]})]})})]})}),e.jsx(pe,{title:"Dropdown Menu",children:e.jsxs(ia,{children:[e.jsx(oa,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",children:["Quick Actions",e.jsx(Pn,{className:"h-4 w-4"})]})}),e.jsxs(la,{align:"start",className:"w-56",children:[e.jsxs(Us,{children:[e.jsx(Ns,{className:"h-4 w-4"}),"Mark as done",e.jsx(Ru,{children:"⌘D"})]}),e.jsxs(Us,{children:[e.jsx(Za,{className:"h-4 w-4"}),"Open docs"]}),e.jsx(Pl,{}),e.jsx(Mu,{checked:o,onCheckedChange:A=>l(A===!0),children:"Watch issue"}),e.jsxs(Us,{variant:"destructive",children:[e.jsx(js,{className:"h-4 w-4"}),"Delete issue"]})]})]})}),e.jsx(pe,{title:"Popover",children:e.jsxs(pt,{children:[e.jsx(gt,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",children:"Open Popover"})}),e.jsxs(ft,{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Agent heartbeat"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Last run succeeded 24s ago. Next timer run in 9m."}),e.jsx(F,{size:"xs",children:"Wake now"})]})]})}),e.jsx(pe,{title:"Collapsible",children:e.jsxs(Zr,{open:u,onOpenChange:d,className:"space-y-2",children:[e.jsx(ea,{asChild:!0,children:e.jsxs(F,{variant:"outline",size:"sm",children:[u?"Hide":"Show"," advanced filters"]})}),e.jsx(ta,{className:"rounded-md border border-border p-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(Pt,{htmlFor:"owner-filter",children:"Owner"}),e.jsx(Ot,{id:"owner-filter",placeholder:"Filter by agent name"})]})})]})}),e.jsx(pe,{title:"Sheet",children:e.jsxs(_u,{children:[e.jsx(Du,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",children:"Open Side Panel"})}),e.jsxs($u,{side:"right",children:[e.jsxs(Fu,{children:[e.jsx(Lu,{children:"Issue Properties"}),e.jsx(Ou,{children:"Edit metadata without leaving the current page."})]}),e.jsxs("div",{className:"space-y-4 px-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Pt,{htmlFor:"sheet-title",children:"Title"}),e.jsx(Ot,{id:"sheet-title",defaultValue:"Improve onboarding docs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Pt,{htmlFor:"sheet-description",children:"Description"}),e.jsx(un,{id:"sheet-description",defaultValue:"Capture setup pitfalls and screenshots."})]})]}),e.jsxs(qu,{children:[e.jsx(F,{variant:"outline",children:"Cancel"}),e.jsx(F,{children:"Save"})]})]})]})}),e.jsx(pe,{title:"Scroll Area",children:e.jsx(pl,{className:"h-36 rounded-md border border-border",children:e.jsx("div",{className:"space-y-2 p-3",children:Array.from({length:12}).map((A,N)=>e.jsxs("div",{className:"rounded-md border border-border p-2 text-sm",children:["Heartbeat run #",N+1,": completed successfully"]},N))})})}),e.jsx(pe,{title:"Command (CMDK)",children:e.jsx("div",{className:"rounded-md border border-border",children:e.jsxs(Oc,{children:[e.jsx(qc,{placeholder:"Type a command or search..."}),e.jsxs(Bc,{children:[e.jsx(zc,{children:"No results found."}),e.jsxs(zs,{heading:"Pages",children:[e.jsxs(Je,{children:[e.jsx(_s,{className:"h-4 w-4"}),"Dashboard"]}),e.jsxs(Je,{children:[e.jsx(Ct,{className:"h-4 w-4"}),"Issues"]})]}),e.jsx(Bn,{}),e.jsxs(zs,{heading:"Actions",children:[e.jsxs(Je,{children:[e.jsx(ex,{className:"h-4 w-4"}),"Open command palette"]}),e.jsxs(Je,{children:[e.jsx(Pe,{className:"h-4 w-4"}),"Create new issue"]})]})]})]})})}),e.jsx(pe,{title:"Breadcrumb",children:e.jsx(Bu,{children:e.jsxs(zu,{children:[e.jsx(wa,{children:e.jsx(ro,{href:"#",children:"Projects"})}),e.jsx(ao,{}),e.jsx(wa,{children:e.jsx(ro,{href:"#",children:"Growthub App"})}),e.jsx(ao,{}),e.jsx(wa,{children:e.jsx(Ku,{children:"Issue List"})})]})})}),e.jsxs(pe,{title:"Cards",children:[e.jsx(ge,{title:"Standard Card",children:e.jsxs($e,{children:[e.jsxs(Ze,{children:[e.jsx(et,{children:"Card Title"}),e.jsx(xt,{children:"Card description with supporting text."})]}),e.jsx(Fe,{children:e.jsx("p",{className:"text-sm",children:"Card content goes here. This is the main body area."})}),e.jsxs(Uu,{className:"gap-2",children:[e.jsx(F,{size:"sm",children:"Action"}),e.jsx(F,{variant:"outline",size:"sm",children:"Cancel"})]})]})}),e.jsx(ge,{title:"Metric Cards",children:e.jsxs("div",{className:"grid md:grid-cols-2 xl:grid-cols-4 gap-4",children:[e.jsx(Ps,{icon:qt,value:12,label:"Active Agents",description:"+3 this week"}),e.jsx(Ps,{icon:Ct,value:48,label:"Open Issues"}),e.jsx(Ps,{icon:ns,value:"$1,234",label:"Monthly Cost",description:"Under budget"}),e.jsx(Ps,{icon:Ga,value:"99.9%",label:"Uptime"})]})})]}),e.jsxs(pe,{title:"Tabs",children:[e.jsx(ge,{title:"Default (pill) variant",children:e.jsxs(Ut,{defaultValue:"overview",children:[e.jsxs(_r,{children:[e.jsx(kt,{value:"overview",children:"Overview"}),e.jsx(kt,{value:"runs",children:"Runs"}),e.jsx(kt,{value:"config",children:"Config"}),e.jsx(kt,{value:"costs",children:"Costs"})]}),e.jsx(Oe,{value:"overview",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Overview tab content."})}),e.jsx(Oe,{value:"runs",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Runs tab content."})}),e.jsx(Oe,{value:"config",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Config tab content."})}),e.jsx(Oe,{value:"costs",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Costs tab content."})})]})}),e.jsx(ge,{title:"Line variant",children:e.jsxs(Ut,{defaultValue:"summary",children:[e.jsxs(_r,{variant:"line",children:[e.jsx(kt,{value:"summary",children:"Summary"}),e.jsx(kt,{value:"details",children:"Details"}),e.jsx(kt,{value:"comments",children:"Comments"})]}),e.jsx(Oe,{value:"summary",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Summary content with underline tabs."})}),e.jsx(Oe,{value:"details",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Details content."})}),e.jsx(Oe,{value:"comments",children:e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Comments content."})})]})})]}),e.jsx(pe,{title:"Entity Rows",children:e.jsxs("div",{className:"border border-border rounded-md",children:[e.jsx(ps,{leading:e.jsxs(e.Fragment,{children:[e.jsx(wt,{status:"in_progress"}),e.jsx(Nt,{priority:"high"})]}),identifier:"PAP-001",title:"Implement authentication flow",subtitle:"Assigned to Agent Alpha",trailing:e.jsx(Se,{status:"in_progress"}),onClick:()=>{}}),e.jsx(ps,{leading:e.jsxs(e.Fragment,{children:[e.jsx(wt,{status:"done"}),e.jsx(Nt,{priority:"medium"})]}),identifier:"PAP-002",title:"Set up CI/CD pipeline",subtitle:"Completed 2 days ago",trailing:e.jsx(Se,{status:"done"}),onClick:()=>{}}),e.jsx(ps,{leading:e.jsxs(e.Fragment,{children:[e.jsx(wt,{status:"todo"}),e.jsx(Nt,{priority:"low"})]}),identifier:"PAP-003",title:"Write API documentation",trailing:e.jsx(Se,{status:"todo"}),onClick:()=>{}}),e.jsx(ps,{leading:e.jsxs(e.Fragment,{children:[e.jsx(wt,{status:"blocked"}),e.jsx(Nt,{priority:"critical"})]}),identifier:"PAP-004",title:"Deploy to production",subtitle:"Blocked by PAP-001",trailing:e.jsx(Se,{status:"blocked"}),selected:!0})]})}),e.jsxs(pe,{title:"Filter Bar",children:[e.jsx(ub,{filters:f,onRemove:A=>g(N=>N.filter(C=>C.key!==A)),onClear:()=>g([])}),f.length===0&&e.jsx(F,{variant:"outline",size:"sm",onClick:()=>g([{key:"status",label:"Status",value:"Active"},{key:"priority",label:"Priority",value:"High"}]),children:"Reset filters"})]}),e.jsxs(pe,{title:"Avatars",children:[e.jsx(ge,{title:"Sizes",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Os,{size:"sm",children:e.jsx(qs,{children:"SM"})}),e.jsx(Os,{children:e.jsx(qs,{children:"DF"})}),e.jsx(Os,{size:"lg",children:e.jsx(qs,{children:"LG"})})]})}),e.jsx(ge,{title:"Group",children:e.jsxs(Gu,{children:[e.jsx(Os,{children:e.jsx(qs,{children:"A1"})}),e.jsx(Os,{children:e.jsx(qs,{children:"A2"})}),e.jsx(Os,{children:e.jsx(qs,{children:"A3"})}),e.jsx(Wu,{children:"+5"})]})})]}),e.jsxs(pe,{title:"Identity",children:[e.jsx(ge,{title:"Sizes",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(qe,{name:"Agent Alpha",size:"sm"}),e.jsx(qe,{name:"Agent Alpha"}),e.jsx(qe,{name:"Agent Alpha",size:"lg"})]})}),e.jsx(ge,{title:"Initials derivation",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(qe,{name:"CEO Agent",size:"sm"}),e.jsx(qe,{name:"Alpha",size:"sm"}),e.jsx(qe,{name:"Quality Assurance Lead",size:"sm"})]})}),e.jsx(ge,{title:"Custom initials",children:e.jsx(qe,{name:"Backend Service",initials:"BS",size:"sm"})})]}),e.jsx(pe,{title:"Tooltips",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(as,{children:[e.jsx(is,{asChild:!0,children:e.jsx(F,{variant:"outline",size:"sm",children:"Hover me"})}),e.jsx(os,{children:"This is a tooltip"})]}),e.jsxs(as,{children:[e.jsx(is,{asChild:!0,children:e.jsx(F,{variant:"ghost",size:"icon-sm",children:e.jsx(cs,{})})}),e.jsx(os,{children:"Settings"})]})]})}),e.jsx(pe,{title:"Dialog",children:e.jsxs(fs,{children:[e.jsx(Fl,{asChild:!0,children:e.jsx(F,{variant:"outline",children:"Open Dialog"})}),e.jsxs(bs,{children:[e.jsxs(hn,{children:[e.jsx(pn,{children:"Dialog Title"}),e.jsx(Kn,{children:"This is a sample dialog showing the standard layout with header, content, and footer."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(Pt,{children:"Name"}),e.jsx(Ot,{placeholder:"Enter a name",className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(Pt,{children:"Description"}),e.jsx(un,{placeholder:"Describe...",className:"mt-1.5"})]})]}),e.jsxs(Ir,{children:[e.jsx(F,{variant:"outline",children:"Cancel"}),e.jsx(F,{children:"Save"})]})]})]})}),e.jsx(pe,{title:"Empty State",children:e.jsx("div",{className:"border border-border rounded-md",children:e.jsx(Be,{icon:ys,message:"No items to show. Create your first one to get started.",action:"Create Item",onAction:()=>{}})})}),e.jsx(pe,{title:"Progress Bars (Budget)",children:e.jsx("div",{className:"space-y-3",children:[{label:"Under budget (40%)",pct:40,color:"bg-green-400"},{label:"Warning (75%)",pct:75,color:"bg-yellow-400"},{label:"Over budget (95%)",pct:95,color:"bg-red-400"}].map(({label:A,pct:N,color:C})=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:A}),e.jsxs("span",{className:"text-xs font-mono",children:[N,"%"]})]}),e.jsx("div",{className:"w-full h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-[width,background-color] duration-150 ${C}`,style:{width:`${N}%`}})})]},A))})}),e.jsx(pe,{title:"Log Viewer",children:e.jsxs("div",{className:"bg-neutral-950 rounded-lg p-3 font-mono text-xs max-h-80 overflow-y-auto",children:[e.jsx("div",{className:"text-foreground",children:"[12:00:01] INFO Agent started successfully"}),e.jsx("div",{className:"text-foreground",children:"[12:00:02] INFO Processing task PAP-001"}),e.jsx("div",{className:"text-yellow-400",children:"[12:00:05] WARN Rate limit approaching (80%)"}),e.jsx("div",{className:"text-foreground",children:"[12:00:08] INFO Task PAP-001 completed"}),e.jsx("div",{className:"text-red-400",children:"[12:00:12] ERROR Connection timeout to upstream service"}),e.jsx("div",{className:"text-blue-300",children:"[12:00:12] SYS Retrying connection in 5s..."}),e.jsx("div",{className:"text-foreground",children:"[12:00:17] INFO Reconnected successfully"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-cyan-400 animate-pulse"}),e.jsx("span",{className:"inline-flex h-full w-full rounded-full bg-cyan-400"})]}),e.jsx("span",{className:"text-cyan-400",children:"Live"})]})]})}),e.jsx(pe,{title:"Property Row Pattern",children:e.jsxs("div",{className:"border border-border rounded-md p-4 space-y-1 max-w-sm",children:[e.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),e.jsx(Se,{status:"active"})]}),e.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),e.jsx(Nt,{priority:"high"})]}),e.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Os,{size:"sm",children:e.jsx(qs,{children:"A"})}),e.jsx("span",{className:"text-xs",children:"Agent Alpha"})]})]}),e.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Created"}),e.jsx("span",{className:"text-xs",children:"Jan 15, 2025"})]})]})}),e.jsxs(pe,{title:"Navigation Patterns",children:[e.jsx(ge,{title:"Sidebar nav items",children:e.jsxs("div",{className:"w-60 border border-border rounded-md p-3 space-y-0.5 bg-card",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium bg-accent text-accent-foreground",children:[e.jsx(_s,{className:"h-4 w-4"}),"Dashboard"]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[e.jsx(Ct,{className:"h-4 w-4"}),"Issues",e.jsx("span",{className:"ml-auto text-xs bg-primary text-primary-foreground rounded-full px-1.5 py-0.5",children:"12"})]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[e.jsx(qt,{className:"h-4 w-4"}),"Agents"]}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground cursor-pointer",children:[e.jsx(Nn,{className:"h-4 w-4"}),"Projects"]})]})}),e.jsx(ge,{title:"View toggle",children:e.jsxs("div",{className:"flex items-center border border-border rounded-md w-fit",children:[e.jsxs("button",{className:"px-3 py-1.5 text-xs font-medium bg-accent text-foreground rounded-l-md",children:[e.jsx(io,{className:"h-3.5 w-3.5 inline mr-1"}),"List"]}),e.jsxs("button",{className:"px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-accent/50 rounded-r-md",children:[e.jsx(ls,{className:"h-3.5 w-3.5 inline mr-1"}),"Org"]})]})})]}),e.jsx(pe,{title:"Grouped List (Issues pattern)",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 bg-muted/50 rounded-t-md",children:[e.jsx(wt,{status:"in_progress"}),e.jsx("span",{className:"text-sm font-medium",children:"In Progress"}),e.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:"2"})]}),e.jsxs("div",{className:"border border-border rounded-b-md",children:[e.jsx(ps,{leading:e.jsx(Nt,{priority:"high"}),identifier:"PAP-101",title:"Build agent heartbeat system",onClick:()=>{}}),e.jsx(ps,{leading:e.jsx(Nt,{priority:"medium"}),identifier:"PAP-102",title:"Add cost tracking dashboard",onClick:()=>{}})]})]})}),e.jsx(pe,{title:"Comment Thread Pattern",children:e.jsxs("div",{className:"space-y-3 max-w-2xl",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Comments (2)"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Jan 15, 2025"})]}),e.jsx("p",{className:"text-sm",children:"Started working on the authentication module. Will need API keys configured."})]}),e.jsxs("div",{className:"rounded-md border border-border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Human"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Jan 16, 2025"})]}),e.jsx("p",{className:"text-sm",children:"API keys have been added to the vault. Please proceed."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(un,{placeholder:"Leave a comment...",rows:3}),e.jsx(F,{size:"sm",children:"Comment"})]})]})}),e.jsx(pe,{title:"Cost Table Pattern",children:e.jsx("div",{className:"border border-border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"border-b border-border bg-accent/20",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Model"}),e.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Tokens"}),e.jsx("th",{className:"text-left px-3 py-2 font-medium text-muted-foreground",children:"Cost"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("td",{className:"px-3 py-2",children:"claude-sonnet-4-20250514"}),e.jsx("td",{className:"px-3 py-2 font-mono",children:"1.2M"}),e.jsx("td",{className:"px-3 py-2 font-mono",children:"$18.00"})]}),e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("td",{className:"px-3 py-2",children:"claude-haiku-4-20250506"}),e.jsx("td",{className:"px-3 py-2 font-mono",children:"500k"}),e.jsx("td",{className:"px-3 py-2 font-mono",children:"$1.25"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:"Total"}),e.jsx("td",{className:"px-3 py-2 font-mono",children:"1.7M"}),e.jsx("td",{className:"px-3 py-2 font-mono font-medium",children:"$19.25"})]})]})]})})}),e.jsxs(pe,{title:"Skeletons",children:[e.jsx(ge,{title:"Individual",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(ts,{className:"h-4 w-48"}),e.jsx(ts,{className:"h-8 w-full max-w-sm"}),e.jsx(ts,{className:"h-20 w-full"})]})}),e.jsx(ge,{title:"Page Skeleton (list)",children:e.jsx("div",{className:"border border-border rounded-md p-4",children:e.jsx(rt,{variant:"list"})})}),e.jsx(ge,{title:"Page Skeleton (detail)",children:e.jsx("div",{className:"border border-border rounded-md p-4",children:e.jsx(rt,{variant:"detail"})})})]}),e.jsx(pe,{title:"Separator",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Horizontal"}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex items-center gap-4 h-8",children:[e.jsx("span",{className:"text-sm",children:"Left"}),e.jsx(Rt,{orientation:"vertical"}),e.jsx("span",{className:"text-sm",children:"Right"})]})]})}),e.jsx(pe,{title:"Common Icons (Lucide)",children:e.jsx("div",{className:"grid grid-cols-4 md:grid-cols-6 gap-4",children:[["Inbox",ys],["ListTodo",io],["CircleDot",Ct],["Hexagon",Nn],["Target",ls],["LayoutDashboard",_s],["Bot",qt],["DollarSign",ns],["History",kn],["Search",gs],["Plus",Pe],["Trash2",js],["Settings",cs],["User",dn],["Mail",Vu],["Upload",ho],["Zap",Ga]].map(([A,N])=>{const C=N;return e.jsxs("div",{className:"flex flex-col items-center gap-1.5 p-2",children:[e.jsx(C,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono",children:A})]},A)})})}),e.jsx(pe,{title:"Keyboard Shortcuts",children:e.jsx("div",{className:"border border-border rounded-md divide-y divide-border text-sm",children:[["Cmd+K / Ctrl+K","Open Command Palette"],["C","New Issue (outside inputs)"],["[","Toggle Sidebar"],["]","Toggle Properties Panel"],["Cmd+Enter / Ctrl+Enter","Submit markdown comment"]].map(([A,N])=>e.jsxs("div",{className:"flex items-center justify-between px-4 py-2",children:[e.jsx("span",{className:"text-muted-foreground",children:N}),e.jsx("kbd",{className:"px-2 py-0.5 text-xs font-mono bg-muted rounded border border-border",children:A})]},A))})})]})}function Zo(t){return typeof t!="object"||t===null||Array.isArray(t)?null:t}function xb(t){return t.replaceAll("_"," ")}function el(t){return`/${t.companyIssuePrefix}/agents/${encodeURIComponent(t.agentUrlKey)}`}function hb(){const{setBreadcrumbs:t}=Me(),s=Le(),[n,r]=c.useState(null);c.useEffect(()=>{t([{label:"Instance Settings"},{label:"Heartbeats"}])},[t]);const a=V({queryKey:E.instance.schedulerHeartbeats,queryFn:()=>Ht.listInstanceSchedulerAgents(),refetchInterval:15e3}),i=se({mutationFn:async m=>{const x=await Ee.get(m.id,m.companyId),p=Zo(x.runtimeConfig)??{},h=Zo(p.heartbeat)??{};return Ee.update(m.id,{runtimeConfig:{...p,heartbeat:{...h,enabled:!m.heartbeatEnabled}}},m.companyId)},onSuccess:async(m,x)=>{r(null),await Promise.all([s.invalidateQueries({queryKey:E.instance.schedulerHeartbeats}),s.invalidateQueries({queryKey:E.agents.list(x.companyId)}),s.invalidateQueries({queryKey:E.agents.detail(x.id)})])},onError:m=>{r(m instanceof Error?m.message:"Failed to update heartbeat.")}}),o=a.data??[],l=o.filter(m=>m.schedulerActive).length,u=o.length-l,d=c.useMemo(()=>{const m=new Map;for(const x of o){let p=m.get(x.companyId);p||(p={companyName:x.companyName,agents:[]},m.set(x.companyId,p)),p.agents.push(x)}return[...m.values()]},[o]);return a.isLoading?e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading scheduler heartbeats..."}):a.error?e.jsx("div",{className:"text-sm text-destructive",children:a.error instanceof Error?a.error.message:"Failed to load scheduler heartbeats."}):e.jsxs("div",{className:"max-w-5xl space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h1",{className:"text-lg font-semibold",children:"Scheduler Heartbeats"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Agents with a timer heartbeat enabled across all of your companies."})]}),e.jsxs("div",{className:"flex gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:l})," active"]}),e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:u})," disabled"]}),e.jsxs("span",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:d.length})," ",d.length===1?"company":"companies"]})]}),n&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:n}),o.length===0?e.jsx(Be,{icon:Ql,message:"No scheduler heartbeats match the current criteria."}):e.jsx("div",{className:"space-y-4",children:d.map(m=>e.jsx($e,{children:e.jsxs(Fe,{className:"p-0",children:[e.jsx("div",{className:"border-b px-3 py-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:m.companyName}),e.jsx("div",{className:"divide-y",children:m.agents.map(x=>{var h;const p=i.isPending&&((h=i.variables)==null?void 0:h.id)===x.id;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 text-sm",children:[e.jsx(Ne,{variant:x.schedulerActive?"default":"outline",className:"shrink-0 text-[10px] px-1.5 py-0",children:x.schedulerActive?"On":"Off"}),e.jsx(xe,{to:el(x),className:"font-medium truncate hover:underline",children:x.agentName}),e.jsx("span",{className:"hidden sm:inline text-muted-foreground truncate",children:xb(x.title??x.role)}),e.jsxs("span",{className:"text-muted-foreground tabular-nums shrink-0",children:[x.intervalSec,"s"]}),e.jsx("span",{className:"hidden md:inline text-muted-foreground truncate",title:x.lastHeartbeatAt?da(x.lastHeartbeatAt):void 0,children:x.lastHeartbeatAt?ca(x.lastHeartbeatAt):"never"}),e.jsxs("span",{className:"ml-auto flex items-center gap-1.5 shrink-0",children:[e.jsx(xe,{to:el(x),className:"text-muted-foreground hover:text-foreground",title:"Full agent config",children:e.jsx(En,{className:"h-3.5 w-3.5"})}),e.jsx(F,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",disabled:p,onClick:()=>i.mutate(x),children:p?"...":x.heartbeatEnabled?"Disable Timer Heartbeat":"Enable Timer Heartbeat"})]})]},x.id)})})]})},m.companyName))})]})}function pb(){var l;const{setBreadcrumbs:t}=Me(),s=Le(),[n,r]=c.useState(null);c.useEffect(()=>{t([{label:"Instance Settings"},{label:"Experimental"}])},[t]);const a=V({queryKey:E.instance.experimentalSettings,queryFn:()=>Wa.getExperimental()}),i=se({mutationFn:async u=>Wa.updateExperimental({enableIsolatedWorkspaces:u}),onSuccess:async()=>{r(null),await s.invalidateQueries({queryKey:E.instance.experimentalSettings})},onError:u=>{r(u instanceof Error?u.message:"Failed to update experimental settings.")}});if(a.isLoading)return e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading experimental settings..."});if(a.error)return e.jsx("div",{className:"text-sm text-destructive",children:a.error instanceof Error?a.error.message:"Failed to load experimental settings."});const o=((l=a.data)==null?void 0:l.enableIsolatedWorkspaces)===!0;return e.jsxs("div",{className:"max-w-4xl space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ma,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h1",{className:"text-lg font-semibold",children:"Experimental"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Opt into features that are still being evaluated before they become default behavior."})]}),n&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:n}),e.jsx("section",{className:"rounded-xl border border-border bg-card p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h2",{className:"text-sm font-semibold",children:"Enabled Isolated Workspaces"}),e.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Show execution workspace controls in project configuration and allow isolated workspace behavior for new and existing issue runs."})]}),e.jsx("button",{type:"button","aria-label":"Toggle isolated workspaces experimental setting",disabled:i.isPending,className:z("relative inline-flex h-6 w-11 items-center rounded-full transition-colors disabled:cursor-not-allowed disabled:opacity-60",o?"bg-green-600":"bg-muted"),onClick:()=>i.mutate(!o),children:e.jsx("span",{className:z("inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform",o?"translate-x-6":"translate-x-0.5")})})]})})]})}function gb(t){return t?t.split(/\r?\n/).map(n=>n.trim()).find(Boolean)??null:null}function tl(t){return gb(t.lastError)??"Plugin entered an error state without a stored error message."}function fb(){const{selectedCompany:t}=he(),{setBreadcrumbs:s}=Me(),n=Le(),{pushToast:r}=ji(),[a,i]=c.useState(""),[o,l]=c.useState(!1),[u,d]=c.useState(null),[m,x]=c.useState(""),[p,h]=c.useState(null);c.useEffect(()=>{s([{label:(t==null?void 0:t.name)??"Company",href:"/dashboard"},{label:"Settings",href:"/instance/settings/heartbeats"},{label:"Plugins"}])},[t==null?void 0:t.name,s]);const{data:j,isLoading:y,error:f}=V({queryKey:E.plugins.all,queryFn:()=>mt.list()}),g=V({queryKey:E.plugins.examples,queryFn:()=>mt.listExamples()}),A=()=>{n.invalidateQueries({queryKey:E.plugins.all}),n.invalidateQueries({queryKey:E.plugins.examples}),n.invalidateQueries({queryKey:E.plugins.uiContributions})},N=se({mutationFn:w=>mt.install(w),onSuccess:()=>{A(),l(!1),i(""),r({title:"Plugin installed successfully",tone:"success"})},onError:w=>{r({title:"Failed to install plugin",body:w.message,tone:"error"})}}),C=se({mutationFn:w=>mt.uninstall(w),onSuccess:()=>{A(),r({title:"Plugin uninstalled successfully",tone:"success"})},onError:w=>{r({title:"Failed to uninstall plugin",body:w.message,tone:"error"})}}),S=se({mutationFn:w=>mt.enable(w),onSuccess:()=>{A(),r({title:"Plugin enabled",tone:"success"})},onError:w=>{r({title:"Failed to enable plugin",body:w.message,tone:"error"})}}),b=se({mutationFn:w=>mt.disable(w),onSuccess:()=>{A(),r({title:"Plugin disabled",tone:"info"})},onError:w=>{r({title:"Failed to disable plugin",body:w.message,tone:"error"})}}),v=j??[],M=g.data??[],k=new Map(v.map(w=>[w.packageName,w])),_=new Set(M.map(w=>w.packageName)),U=c.useMemo(()=>new Map(v.map(w=>[w.id,tl(w)])),[v]);return y?e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading plugins..."}):f?e.jsx("div",{className:"p-4 text-sm text-destructive",children:"Failed to load plugins."}):e.jsxs("div",{className:"space-y-6 max-w-5xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zn,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("h1",{className:"text-xl font-semibold",children:"Plugin Manager"})]}),e.jsxs(fs,{open:o,onOpenChange:l,children:[e.jsx(Fl,{asChild:!0,children:e.jsxs(F,{size:"sm",className:"gap-2",children:[e.jsx(Pe,{className:"h-4 w-4"}),"Install Plugin"]})}),e.jsxs(bs,{children:[e.jsxs(hn,{children:[e.jsx(pn,{children:"Install Plugin"}),e.jsx(Kn,{children:"Enter the npm package name of the plugin you wish to install."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(Pt,{htmlFor:"packageName",children:"npm Package Name"}),e.jsx(Ot,{id:"packageName",placeholder:"@paperclipai/plugin-example",value:a,onChange:w=>i(w.target.value)})]})}),e.jsxs(Ir,{children:[e.jsx(F,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(F,{onClick:()=>N.mutate({packageName:a}),disabled:!a||N.isPending,children:N.isPending?"Installing...":"Install"})]})]})]})]}),e.jsx("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(gn,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-700"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Plugins are alpha."}),e.jsx("p",{className:"text-muted-foreground",children:"The plugin runtime and API surface are still changing. Expect breaking changes while this feature settles."})]})]})}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ma,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h2",{className:"text-base font-semibold",children:"Available Plugins"}),e.jsx(Ne,{variant:"outline",children:"Examples"})]}),g.isLoading?e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading bundled examples..."}):g.error?e.jsx("div",{className:"text-sm text-destructive",children:"Failed to load bundled examples."}):M.length===0?e.jsx("div",{className:"rounded-md border border-dashed px-4 py-3 text-sm text-muted-foreground",children:"No bundled example plugins were found in this checkout."}):e.jsx("ul",{className:"divide-y rounded-md border bg-card",children:M.map(w=>{var H;const T=k.get(w.packageName),W=N.isPending&&((H=N.variables)==null?void 0:H.isLocalPath)&&N.variables.packageName===w.localPath;return e.jsx("li",{children:e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:w.displayName}),e.jsx(Ne,{variant:"outline",children:"Example"}),T?e.jsx(Ne,{variant:T.status==="ready"?"default":"secondary",className:T.status==="ready"?"bg-green-600 hover:bg-green-700":"",children:T.status}):e.jsx(Ne,{variant:"secondary",children:"Not installed"})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:w.description}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:w.packageName})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:T?e.jsxs(e.Fragment,{children:[T.status!=="ready"&&e.jsx(F,{variant:"outline",size:"sm",disabled:S.isPending,onClick:()=>S.mutate(T.id),children:"Enable"}),e.jsx(F,{variant:"outline",size:"sm",asChild:!0,children:e.jsx(xe,{to:`/instance/settings/plugins/${T.id}`,children:T.status==="ready"?"Open Settings":"Review"})})]}):e.jsx(F,{size:"sm",disabled:W||N.isPending,onClick:()=>N.mutate({packageName:w.localPath,isLocalPath:!0}),children:W?"Installing...":"Install Example"})})]})},w.packageName)})})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zn,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h2",{className:"text-base font-semibold",children:"Installed Plugins"})]}),v.length?e.jsx("ul",{className:"divide-y rounded-md border bg-card",children:v.map(w=>e.jsx("li",{children:e.jsxs("div",{className:"flex items-start gap-4 px-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(xe,{to:`/instance/settings/plugins/${w.id}`,className:"font-medium hover:underline truncate block",title:w.manifestJson.displayName??w.packageName,children:w.manifestJson.displayName??w.packageName}),_.has(w.packageName)&&e.jsx(Ne,{variant:"outline",children:"Example"})]}),e.jsx("div",{children:e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",title:w.packageName,children:[w.packageName," · v",w.manifestJson.version??w.version]})}),e.jsx("p",{className:"text-sm text-muted-foreground truncate mt-0.5",title:w.manifestJson.description,children:w.manifestJson.description||"No description provided."}),w.status==="error"&&e.jsx("div",{className:"mt-3 rounded-md border border-red-500/25 bg-red-500/[0.06] px-3 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-start gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-red-700 dark:text-red-300",children:[e.jsx(gn,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:"Plugin error"})]}),e.jsx("p",{className:"mt-1 text-sm text-red-700/90 dark:text-red-200/90 break-words",title:w.lastError??void 0,children:U.get(w.id)})]}),e.jsx(F,{variant:"outline",size:"sm",className:"border-red-500/30 bg-background/60 text-red-700 hover:bg-red-500/10 hover:text-red-800 dark:text-red-200 dark:hover:text-red-100",onClick:()=>h(w),children:"View full error"})]})})]}),e.jsx("div",{className:"flex shrink-0 self-center",children:e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{variant:w.status==="ready"?"default":w.status==="error"?"destructive":"secondary",className:z("shrink-0",w.status==="ready"?"bg-green-600 hover:bg-green-700":""),children:w.status}),e.jsx(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8",title:w.status==="ready"?"Disable":"Enable",onClick:()=>{w.status==="ready"?b.mutate(w.id):S.mutate(w.id)},disabled:S.isPending||b.isPending,children:e.jsx(kx,{className:z("h-4 w-4",w.status==="ready"?"text-green-600":"")})}),e.jsx(F,{variant:"outline",size:"icon-sm",className:"h-8 w-8 text-destructive hover:text-destructive",title:"Uninstall",onClick:()=>{d(w.id),x(w.manifestJson.displayName??w.packageName)},disabled:C.isPending,children:e.jsx(Rx,{className:"h-4 w-4"})})]}),e.jsx(F,{variant:"outline",size:"sm",className:"mt-2 h-8",asChild:!0,children:e.jsxs(xe,{to:`/instance/settings/plugins/${w.id}`,children:[e.jsx(cs,{className:"h-4 w-4"}),"Configure"]})})]})})]})},w.id))}):e.jsx($e,{className:"bg-muted/30",children:e.jsxs(Fe,{className:"flex flex-col items-center justify-center py-10",children:[e.jsx(zn,{className:"h-10 w-10 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-sm font-medium",children:"No plugins installed"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Install a plugin to extend functionality."})]})})]}),e.jsx(fs,{open:u!==null,onOpenChange:w=>{w||d(null)},children:e.jsxs(bs,{children:[e.jsxs(hn,{children:[e.jsx(pn,{children:"Uninstall Plugin"}),e.jsxs(Kn,{children:["Are you sure you want to uninstall ",e.jsx("strong",{children:m}),"? This action cannot be undone."]})]}),e.jsxs(Ir,{children:[e.jsx(F,{variant:"outline",onClick:()=>d(null),children:"Cancel"}),e.jsx(F,{variant:"destructive",disabled:C.isPending,onClick:()=>{u&&C.mutate(u,{onSettled:()=>d(null)})},children:C.isPending?"Uninstalling...":"Uninstall"})]})]})}),e.jsx(fs,{open:p!==null,onOpenChange:w=>{w||h(null)},children:e.jsxs(bs,{className:"sm:max-w-2xl",children:[e.jsxs(hn,{children:[e.jsx(pn,{children:"Error Details"}),e.jsxs(Kn,{children:[(p==null?void 0:p.manifestJson.displayName)??(p==null?void 0:p.packageName)??"Plugin"," hit an error state."]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border border-red-500/25 bg-red-500/[0.06] px-4 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(gn,{className:"mt-0.5 h-4 w-4 shrink-0 text-red-700 dark:text-red-300"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("p",{className:"font-medium text-red-700 dark:text-red-300",children:"What errored"}),e.jsx("p",{className:"text-red-700/90 dark:text-red-200/90 break-words",children:p?tl(p):"No error summary available."})]})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Full error output"}),e.jsx("pre",{className:"max-h-[50vh] overflow-auto rounded-md border bg-muted/40 p-3 text-xs leading-5 whitespace-pre-wrap break-words",children:(p==null?void 0:p.lastError)??"No stored error message."})]})]}),e.jsx(Ir,{children:e.jsx(F,{variant:"outline",onClick:()=>h(null),children:"Close"})})]})})]})}const bb=200;function Ys(t){return t.enum?"enum":t.const!==void 0?"const":t.format==="secret-ref"?"secret-ref":Array.isArray(t.type)?t.type.find(s=>s!=="null")??"string":t.type??"string"}function jb(t,s){return s.title?s.title:t.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function Hi(t){var n;if(t.default!==void 0)return t.default;switch(Ys(t)){case"string":case"secret-ref":return"";case"number":case"integer":return t.minimum??0;case"boolean":return!1;case"enum":return((n=t.enum)==null?void 0:n[0])??"";case"array":return[];case"object":{if(!t.properties)return{};const r={};for(const[a,i]of Object.entries(t.properties))r[a]=Hi(i);return r}default:return""}}function sl(t,s,n){const r=Ys(s);if(n&&(t==null||t===""))return"This field is required";if(t==null||t==="")return null;if(r==="string"||r==="secret-ref"){const a=String(t);if(s.minLength!=null&&a.length<s.minLength)return`Must be at least ${s.minLength} characters`;if(s.maxLength!=null&&a.length>s.maxLength)return`Must be at most ${s.maxLength} characters`;if(s.pattern&&s.pattern.length<=512)try{if(!new RegExp(s.pattern).test(a))return`Must match pattern: ${s.pattern}`}catch{}}if(r==="number"||r==="integer"){const a=Number(t);if(isNaN(a))return"Must be a valid number";if(s.minimum!=null&&a<s.minimum)return`Must be at least ${s.minimum}`;if(s.maximum!=null&&a>s.maximum)return`Must be at most ${s.maximum}`;if(s.exclusiveMinimum!=null&&a<=s.exclusiveMinimum)return`Must be greater than ${s.exclusiveMinimum}`;if(s.exclusiveMaximum!=null&&a>=s.exclusiveMaximum)return`Must be less than ${s.exclusiveMaximum}`;if(r==="integer"&&!Number.isInteger(a))return"Must be a whole number";if(s.multipleOf!=null&&a%s.multipleOf!==0)return`Must be a multiple of ${s.multipleOf}`}if(r==="array"){const a=t;if(s.minItems!=null&&a.length<s.minItems)return`Must have at least ${s.minItems} items`;if(s.maxItems!=null&&a.length>s.maxItems)return`Must have at most ${s.maxItems} items`}return null}function Qr(t,s,n=[]){const r={},a=t.properties??{},i=new Set(t.required??[]);for(const[o,l]of Object.entries(a)){const u=[...n,o],d=`/${u.join("/")}`,m=s[o],x=i.has(o),p=Ys(l),h=sl(m,l,x);if(h&&(r[d]=h),p==="object"&&l.properties&&typeof m=="object"&&m!==null&&Object.assign(r,Qr(l,m,u)),p==="array"&&l.items&&Array.isArray(m)){const j=l.items,y=Ys(j)==="object";m.forEach((f,g)=>{const A=[...u,String(g)],N=`/${A.join("/")}`;if(y)Object.assign(r,Qr(j,f,A));else{const C=sl(f,j,!1);C&&(r[N]=C)}})}}return r}function Oa(t){const s={},n=t.properties??{};for(const[r,a]of Object.entries(n)){const i=Hi(a);i!==void 0&&(s[r]=i)}return s}const hr=be.memo(({label:t,description:s,required:n,error:r,disabled:a,children:i})=>e.jsxs("div",{className:z("space-y-2",a&&"opacity-60"),children:[e.jsx("div",{className:"flex items-center justify-between",children:t&&e.jsxs(Pt,{className:"text-sm font-medium",children:[t,n&&e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]})}),i,s&&e.jsx("p",{className:"text-[12px] text-muted-foreground leading-relaxed",children:s}),r&&e.jsx("p",{className:"text-[12px] font-medium text-destructive",children:r})]}));hr.displayName="FieldWrapper";const id=be.memo(({id:t,value:s,onChange:n,disabled:r,label:a,isRequired:i,description:o,error:l})=>e.jsxs("div",{className:"flex items-start space-x-3 space-y-0",children:[e.jsx(ss,{id:t,checked:!!s,onCheckedChange:n,disabled:r}),e.jsxs("div",{className:"grid gap-1.5 leading-none",children:[a&&e.jsxs(Pt,{htmlFor:t,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:[a,i&&e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),o&&e.jsx("p",{className:"text-xs text-muted-foreground",children:o}),l&&e.jsx("p",{className:"text-xs font-medium text-destructive",children:l})]})]}));id.displayName="BooleanField";const od=be.memo(({value:t,onChange:s,disabled:n,label:r,isRequired:a,description:i,error:o,options:l})=>e.jsx(hr,{label:r,description:i,required:a,error:o,disabled:n,children:e.jsxs(Cn,{value:String(t??""),onValueChange:s,disabled:n,children:[e.jsx(In,{className:"w-full",children:e.jsx(Sn,{placeholder:"Select an option"})}),e.jsx(An,{children:l.map(u=>e.jsx(De,{value:String(u),children:String(u)},String(u)))})]})}));od.displayName="EnumField";const ld=be.memo(({value:t,onChange:s,disabled:n,label:r,isRequired:a,description:i,error:o,defaultValue:l})=>{const[u,d]=c.useState(!1);return e.jsx(hr,{label:r,description:i||"This secret is stored securely via the Growthub secret provider.",required:a,error:o,disabled:n,children:e.jsxs("div",{className:"relative",children:[e.jsx(Ot,{type:u?"text":"password",value:String(t??""),onChange:m=>s(m.target.value),placeholder:String(l??""),disabled:n,className:"pr-10","aria-invalid":!!o}),e.jsxs(F,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>d(!u),disabled:n,children:[u?e.jsx(Hu,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Qu,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"sr-only",children:u?"Hide secret":"Show secret"})]})]})})});ld.displayName="SecretField";const cd=be.memo(({value:t,onChange:s,disabled:n,label:r,isRequired:a,description:i,error:o,defaultValue:l,type:u})=>e.jsx(hr,{label:r,description:i,required:a,error:o,disabled:n,children:e.jsx(Ot,{type:"number",step:u==="integer"?"1":"any",value:t!==void 0?String(t):"",onChange:d=>{const m=d.target.value;s(m===""?void 0:Number(m))},placeholder:String(l??""),disabled:n,"aria-invalid":!!o})}));cd.displayName="NumberField";const dd=be.memo(({value:t,onChange:s,disabled:n,label:r,isRequired:a,description:i,error:o,defaultValue:l,format:u,maxLength:d})=>{const m=u==="textarea"||d&&d>bb;return e.jsx(hr,{label:r,description:i,required:a,error:o,disabled:n,children:m?e.jsx(un,{value:String(t??""),onChange:x=>s(x.target.value),placeholder:String(l??""),disabled:n,className:"min-h-[100px]","aria-invalid":!!o}):e.jsx(Ot,{type:"text",value:String(t??""),onChange:x=>s(x.target.value),placeholder:String(l??""),disabled:n,"aria-invalid":!!o})})});dd.displayName="StringField";const ud=be.memo(({propSchema:t,value:s,onChange:n,error:r,disabled:a,label:i,errors:o,path:l})=>{const u=Array.isArray(s)?s:[],d=t.items,m=Ys(d)==="object";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Pt,{className:"text-sm font-medium",children:i}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.description})]}),e.jsxs(F,{type:"button",variant:"outline",size:"sm",disabled:a||t.maxItems!==void 0&&u.length>=t.maxItems,onClick:()=>{const x=Hi(d);n([...u,x])},children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),m?"Add item":"Add"]})]}),e.jsxs("div",{className:"space-y-3",children:[u.map((x,p)=>e.jsxs("div",{className:"group relative flex items-start space-x-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:["Item ",p+1]}),e.jsx(Yr,{propSchema:d,value:x,label:"",path:`${l}/${p}`,onChange:h=>{const j=[...u];j[p]=h,n(j)},disabled:a,errors:o})]}),e.jsxs(F,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",disabled:a||t.minItems!==void 0&&u.length<=t.minItems,onClick:()=>{const h=[...u];h.splice(p,1),n(h)},children:[e.jsx(js,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Remove item"})]})]},p)),u.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground",children:"No items added yet."})]}),r&&e.jsx("p",{className:"text-xs font-medium text-destructive",children:r})]})});ud.displayName="ArrayField";const md=be.memo(({propSchema:t,value:s,onChange:n,disabled:r,label:a,errors:i,path:o})=>{const[l,u]=c.useState(!1),d=m=>{n(m)};return e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between",onClick:()=>u(!l),children:[e.jsxs("div",{className:"text-left",children:[e.jsx(Pt,{className:"cursor-pointer text-sm font-semibold",children:a}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t.description})]}),l?e.jsx(Js,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Pn,{className:"h-4 w-4 text-muted-foreground"})]}),!l&&e.jsx("div",{className:"pt-2",children:e.jsx(xd,{schema:t,values:s??{},onChange:d,disabled:r,errors:Object.fromEntries(Object.entries(i).filter(([m])=>m.startsWith(`${o}/`)).map(([m,x])=>[m.replace(o,""),x]))})})]})});md.displayName="ObjectField";const Yr=be.memo(({propSchema:t,value:s,onChange:n,error:r,disabled:a,label:i,isRequired:o,errors:l,path:u})=>{const d=Ys(t),m=a||t.readOnly===!0;switch(d){case"boolean":return e.jsx(id,{id:u,value:s,onChange:n,disabled:m,label:i,isRequired:o,description:t.description,error:r});case"enum":return e.jsx(od,{value:s,onChange:n,disabled:m,label:i,isRequired:o,description:t.description,error:r,options:t.enum??[]});case"secret-ref":return e.jsx(ld,{value:s,onChange:n,disabled:m,label:i,isRequired:o,description:t.description,error:r,defaultValue:t.default});case"number":case"integer":return e.jsx(cd,{value:s,onChange:n,disabled:m,label:i,isRequired:o,description:t.description,error:r,defaultValue:t.default,type:d});case"array":return e.jsx(ud,{propSchema:t,value:s,onChange:n,error:r,disabled:m,label:i,errors:l,path:u});case"object":return e.jsx(md,{propSchema:t,value:s,onChange:n,disabled:m,label:i,errors:l,path:u});default:return e.jsx(dd,{value:s,onChange:n,disabled:m,label:i,isRequired:o,description:t.description,error:r,defaultValue:t.default,format:t.format,maxLength:t.maxLength})}});Yr.displayName="FormField";function xd({schema:t,values:s,onChange:n,errors:r={},disabled:a,className:i}){const o=Ys(t),l=c.useCallback(x=>{n(x)},[n]);if(o!=="object")return e.jsx("div",{className:i,children:e.jsx(Yr,{propSchema:t,value:s,label:"",path:"",onChange:l,disabled:a,errors:r})});const u=c.useMemo(()=>t.properties??{},[t.properties]),d=c.useMemo(()=>new Set(t.required??[]),[t.required]),m=c.useCallback((x,p)=>{n({...s,[x]:p})},[n,s]);return Object.keys(u).length===0?e.jsx("div",{className:z("py-4 text-center text-sm text-muted-foreground",i),children:"No configuration options available."}):e.jsx("div",{className:z("space-y-6",i),children:Object.entries(u).map(([x,p])=>{const h=s[x],j=d.has(x),y=r[`/${x}`],f=jb(x,p),g=`/${x}`;return e.jsx(Yr,{propSchema:p,value:h,onChange:A=>m(x,A),error:y,disabled:a,label:f,isRequired:j,errors:r,path:g},x)})})}function vb(){var M;const{selectedCompany:t,selectedCompanyId:s}=he(),{setBreadcrumbs:n}=Me(),{companyPrefix:r,pluginId:a}=$s(),[i,o]=c.useState("configuration"),{data:l,isLoading:u}=V({queryKey:E.plugins.detail(a),queryFn:()=>mt.get(a),enabled:!!a}),{data:d,isLoading:m}=V({queryKey:E.plugins.health(a),queryFn:()=>mt.health(a),enabled:!!a&&(l==null?void 0:l.status)==="ready",refetchInterval:3e4}),{data:x}=V({queryKey:E.plugins.dashboard(a),queryFn:()=>mt.dashboard(a),enabled:!!a,refetchInterval:3e4}),{data:p}=V({queryKey:E.plugins.logs(a),queryFn:()=>mt.logs(a,{limit:50}),enabled:!!a&&(l==null?void 0:l.status)==="ready",refetchInterval:3e4}),h=(M=l==null?void 0:l.manifestJson)==null?void 0:M.instanceConfigSchema,j=h&&h.properties&&Object.keys(h.properties).length>0,{data:y,isLoading:f}=V({queryKey:E.plugins.config(a),queryFn:()=>mt.getConfig(a),enabled:!!a&&!!j}),{slots:g}=xi({slotTypes:["settingsPage"],enabled:!!s}),A=g.filter(k=>k.pluginId===a),N=A.length>0;if(c.useEffect(()=>{var k;n([{label:(t==null?void 0:t.name)??"Company",href:"/dashboard"},{label:"Settings",href:"/instance/settings/heartbeats"},{label:"Plugins",href:"/instance/settings/plugins"},{label:((k=l==null?void 0:l.manifestJson)==null?void 0:k.displayName)??(l==null?void 0:l.packageName)??"Plugin Details"}])},[t==null?void 0:t.name,n,r,l]),c.useEffect(()=>{o("configuration")},[a]),u)return e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading plugin details..."});if(!l)return e.jsx(ke,{to:"/instance/settings/plugins",replace:!0});const C=l.status,S=l.status==="ready"?"default":l.status==="error"?"destructive":"secondary",b=l.manifestJson.description||"No description provided.",v=l.manifestJson.capabilities??[];return e.jsxs("div",{className:"space-y-6 max-w-5xl",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(xe,{to:"/instance/settings/plugins",children:e.jsx(F,{variant:"outline",size:"icon",className:"h-8 w-8",children:e.jsx(gi,{className:"h-4 w-4"})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zn,{className:"h-6 w-6 text-muted-foreground"}),e.jsx("h1",{className:"text-xl font-semibold",children:l.manifestJson.displayName??l.packageName}),e.jsx(Ne,{variant:S,className:"ml-2",children:C}),e.jsxs(Ne,{variant:"outline",className:"ml-1",children:["v",l.manifestJson.version??l.version]})]})]}),e.jsxs(Ut,{value:i,onValueChange:k=>o(k),className:"space-y-6",children:[e.jsx(Hs,{align:"start",items:[{value:"configuration",label:"Configuration"},{value:"status",label:"Status"}],value:i,onValueChange:k=>o(k)}),e.jsx(Oe,{value:"configuration",className:"space-y-6",children:e.jsxs("div",{className:"space-y-8",children:[e.jsxs("section",{className:"space-y-5",children:[e.jsx("h2",{className:"text-base font-semibold",children:"About"}),e.jsxs("div",{className:"grid gap-8 lg:grid-cols-[minmax(0,1.4fr)_minmax(220px,0.8fr)]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Description"}),e.jsx("p",{className:"text-sm leading-6 text-foreground/90",children:b})]}),e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h3",{className:"font-medium text-muted-foreground",children:"Author"}),e.jsx("p",{className:"text-foreground",children:l.manifestJson.author})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium text-muted-foreground",children:"Categories"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:l.categories.length>0?l.categories.map(k=>e.jsx(Ne,{variant:"outline",className:"capitalize",children:k},k)):e.jsx("span",{className:"text-foreground",children:"None"})})]})]})]})]}),e.jsx(Rt,{}),e.jsxs("section",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-1",children:e.jsx("h2",{className:"text-base font-semibold",children:"Settings"})}),N?e.jsx("div",{className:"space-y-3",children:A.map(k=>e.jsx(sa,{slot:k,context:{companyId:s,companyPrefix:r??null},missingBehavior:"placeholder"},`${k.pluginKey}:${k.id}`))}):j?e.jsx(yb,{pluginId:a,schema:h,initialValues:y==null?void 0:y.configJson,isLoading:f,pluginStatus:l.status,supportsConfigTest:l.supportsConfigTest===!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This plugin does not require any settings."})]})]})}),e.jsx(Oe,{value:"status",className:"space-y-6",children:e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_320px]",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs($e,{children:[e.jsxs(Ze,{children:[e.jsxs(et,{className:"text-base flex items-center gap-1.5",children:[e.jsx(oo,{className:"h-4 w-4"}),"Runtime Dashboard"]}),e.jsx(xt,{children:"Worker process, scheduled jobs, and webhook deliveries"})]}),e.jsx(Fe,{className:"space-y-6",children:x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-3 flex items-center gap-1.5",children:[e.jsx(oo,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Worker Process"]}),x.worker?e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Status"}),e.jsx(Ne,{variant:x.worker.status==="running"?"default":"secondary",children:x.worker.status})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"PID"}),e.jsx("span",{className:"font-mono text-xs",children:x.worker.pid??"—"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Uptime"}),e.jsx("span",{className:"text-xs",children:Nb(x.worker.uptime)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Pending RPCs"}),e.jsx("span",{className:"text-xs",children:x.worker.pendingRequests})]}),x.worker.totalCrashes>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between col-span-2",children:[e.jsxs("span",{className:"text-muted-foreground flex items-center gap-1",children:[e.jsx(gn,{className:"h-3 w-3 text-amber-500"}),"Crashes"]}),e.jsxs("span",{className:"text-xs",children:[x.worker.consecutiveCrashes," consecutive / ",x.worker.totalCrashes," total"]})]}),x.worker.lastCrashAt&&e.jsxs("div",{className:"flex justify-between col-span-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"Last Crash"}),e.jsx("span",{className:"text-xs",children:wb(x.worker.lastCrashAt)})]})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No worker process registered."})]}),e.jsx(Rt,{}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-3 flex items-center gap-1.5",children:[e.jsx(Um,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Recent Job Runs"]}),x.recentJobRuns.length>0?e.jsx("div",{className:"space-y-2",children:x.recentJobRuns.map(k=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md bg-muted/50 px-2 py-1.5 text-sm",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(kb,{status:k.status}),e.jsx("span",{className:"truncate font-mono text-xs",title:k.jobKey??k.jobId,children:k.jobKey??k.jobId.slice(0,8)}),e.jsx(Ne,{variant:"outline",className:"px-1 py-0 text-[10px]",children:k.trigger})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 text-xs text-muted-foreground",children:[k.durationMs!=null?e.jsx("span",{children:nl(k.durationMs)}):null,e.jsx("span",{title:k.createdAt,children:rl(k.createdAt)})]})]},k.id))}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No job runs recorded yet."})]}),e.jsx(Rt,{}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-3 flex items-center gap-1.5",children:[e.jsx(Fx,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Recent Webhook Deliveries"]}),x.recentWebhookDeliveries.length>0?e.jsx("div",{className:"space-y-2",children:x.recentWebhookDeliveries.map(k=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md bg-muted/50 px-2 py-1.5 text-sm",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Cb,{status:k.status}),e.jsx("span",{className:"truncate font-mono text-xs",title:k.webhookKey,children:k.webhookKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2 text-xs text-muted-foreground",children:[k.durationMs!=null?e.jsx("span",{children:nl(k.durationMs)}):null,e.jsx("span",{title:k.createdAt,children:rl(k.createdAt)})]})]},k.id))}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No webhook deliveries recorded yet."})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t border-border/50 pt-2 text-xs text-muted-foreground",children:[e.jsx(Va,{className:"h-3 w-3"}),"Last checked: ",new Date(x.checkedAt).toLocaleTimeString()]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Runtime diagnostics are unavailable right now."})})]}),p&&p.length>0?e.jsxs($e,{children:[e.jsxs(Ze,{children:[e.jsxs(et,{className:"text-base flex items-center gap-1.5",children:[e.jsx(xo,{className:"h-4 w-4"}),"Recent Logs"]}),e.jsxs(xt,{children:["Last ",p.length," log entries"]})]}),e.jsx(Fe,{children:e.jsx("div",{className:"max-h-64 space-y-1 overflow-y-auto font-mono text-xs",children:p.map(k=>e.jsxs("div",{className:`flex gap-2 py-0.5 ${k.level==="error"?"text-destructive":k.level==="warn"?"text-yellow-600 dark:text-yellow-400":k.level==="debug"?"text-muted-foreground/60":"text-muted-foreground"}`,children:[e.jsx("span",{className:"shrink-0 text-muted-foreground/50",children:new Date(k.createdAt).toLocaleTimeString()}),e.jsx(Ne,{variant:"outline",className:"h-4 shrink-0 px-1 text-[10px]",children:k.level}),e.jsx("span",{className:"truncate",title:k.message,children:k.message})]},k.id))})})]}):null]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs($e,{children:[e.jsx(Ze,{children:e.jsxs(et,{className:"text-base flex items-center gap-1.5",children:[e.jsx(xo,{className:"h-4 w-4"}),"Health Status"]})}),e.jsx(Fe,{children:m?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking health..."}):d?e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Overall"}),e.jsx(Ne,{variant:d.healthy?"default":"destructive",children:d.status})]}),d.checks.length>0?e.jsx("div",{className:"space-y-2 border-t border-border/50 pt-2",children:d.checks.map((k,_)=>e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:"truncate text-muted-foreground",title:k.name,children:k.name}),k.passed?e.jsx(Hm,{className:"h-4 w-4 shrink-0 text-green-500"}):e.jsx(Ni,{className:"h-4 w-4 shrink-0 text-destructive"})]},_))}):null,d.lastError?e.jsx("div",{className:"break-words rounded border border-destructive/20 bg-destructive/10 p-2 text-xs text-destructive",children:d.lastError}):null]}):e.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Lifecycle"}),e.jsx(Ne,{variant:S,children:C})]}),e.jsx("p",{children:"Health checks run once the plugin is ready."}),l.lastError?e.jsx("div",{className:"break-words rounded border border-destructive/20 bg-destructive/10 p-2 text-xs text-destructive",children:l.lastError}):null]})})]}),e.jsxs($e,{children:[e.jsx(Ze,{children:e.jsx(et,{className:"text-base",children:"Details"})}),e.jsxs(Fe,{className:"space-y-3 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{children:"Plugin ID"}),e.jsx("span",{className:"font-mono text-xs text-right",children:l.id})]}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{children:"Plugin Key"}),e.jsx("span",{className:"font-mono text-xs text-right",children:l.pluginKey})]}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{children:"NPM Package"}),e.jsx("span",{className:"max-w-[170px] truncate text-right text-xs",title:l.packageName,children:l.packageName})]}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{children:"Version"}),e.jsxs("span",{className:"text-right text-foreground",children:["v",l.manifestJson.version??l.version]})]})]})]}),e.jsxs($e,{children:[e.jsx(Ze,{children:e.jsxs(et,{className:"text-base flex items-center gap-1.5",children:[e.jsx(Dl,{className:"h-4 w-4"}),"Permissions"]})}),e.jsx(Fe,{children:v.length>0?e.jsx("ul",{className:"space-y-2 text-sm text-muted-foreground",children:v.map(k=>e.jsx("li",{className:"rounded-md bg-muted/40 px-2.5 py-2 font-mono text-xs text-foreground/85",children:k},k))}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No special permissions requested."})})]})]})]})})]})]})}function yb({pluginId:t,schema:s,initialValues:n,isLoading:r,pluginStatus:a,supportsConfigTest:i}){const o=Le(),[l,u]=c.useState(()=>({...Oa(s),...n??{}})),d=c.useRef(!1);c.useEffect(()=>{n&&!d.current&&(d.current=!0,u({...Oa(s),...n}))},[n,s]);const[m,x]=c.useState({}),[p,h]=c.useState(null),[j,y]=c.useState(null),f=JSON.stringify(l)!==JSON.stringify({...Oa(s),...n??{}}),g=se({mutationFn:b=>mt.saveConfig(t,b),onSuccess:()=>{h({type:"success",text:"Configuration saved."}),y(null),o.invalidateQueries({queryKey:E.plugins.config(t)}),setTimeout(()=>h(null),3e3)},onError:b=>{h({type:"error",text:b.message||"Failed to save configuration."})}}),A=se({mutationFn:b=>mt.testConfig(t,b),onSuccess:b=>{b.valid?y({type:"success",text:"Configuration test passed."}):y({type:"error",text:b.message||"Configuration test failed."})},onError:b=>{y({type:"error",text:b.message||"Configuration test failed."})}}),N=c.useCallback(b=>{u(b),x({}),h(null)},[]),C=c.useCallback(()=>{const b=Qr(s,l);if(Object.keys(b).length>0){x(b);return}x({}),g.mutate(l)},[s,l,g]),S=c.useCallback(()=>{const b=Qr(s,l);if(Object.keys(b).length>0){x(b);return}x({}),y(null),A.mutate(l)},[s,l,A]);return r?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-4",children:[e.jsx(Es,{className:"h-4 w-4 animate-spin"}),"Loading configuration..."]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(xd,{schema:s,values:l,onChange:N,errors:m,disabled:g.isPending}),p&&e.jsx("div",{className:`text-sm p-2 rounded border ${p.type==="success"?"text-green-700 bg-green-50 border-green-200 dark:text-green-400 dark:bg-green-950/30 dark:border-green-900":"text-destructive bg-destructive/10 border-destructive/20"}`,children:p.text}),j&&e.jsx("div",{className:`text-sm p-2 rounded border ${j.type==="success"?"text-green-700 bg-green-50 border-green-200 dark:text-green-400 dark:bg-green-950/30 dark:border-green-900":"text-destructive bg-destructive/10 border-destructive/20"}`,children:j.text}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsx(F,{onClick:C,disabled:g.isPending||!f,size:"sm",children:g.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Es,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):"Save Configuration"}),a==="ready"&&i&&e.jsx(F,{variant:"outline",onClick:S,disabled:A.isPending,size:"sm",children:A.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Es,{className:"h-3.5 w-3.5 animate-spin"}),"Testing..."]}):"Test Configuration"})]})]})}function Nb(t){if(t==null)return"—";const s=Math.floor(t/1e3);if(s<60)return`${s}s`;const n=Math.floor(s/60);if(n<60)return`${n}m ${s%60}s`;const r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function nl(t){return t<1e3?`${t}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${(t/6e4).toFixed(1)}m`}function rl(t){const s=Date.now(),n=new Date(t).getTime(),r=s-n;if(r<0)return"just now";const a=Math.floor(r/1e3);if(a<60)return`${a}s ago`;const i=Math.floor(a/60);if(i<60)return`${i}m ago`;const o=Math.floor(i/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}function wb(t){return new Date(t).toLocaleString()}function kb({status:t}){const s=t==="success"||t==="succeeded"?"bg-green-500":t==="failed"?"bg-red-500":t==="running"?"bg-blue-500 animate-pulse":t==="cancelled"?"bg-gray-400":"bg-amber-500";return e.jsx("span",{className:`inline-block h-2 w-2 rounded-full shrink-0 ${s}`,title:t})}function Cb({status:t}){const s=t==="processed"||t==="success"?"bg-green-500":t==="failed"?"bg-red-500":t==="received"?"bg-blue-500":"bg-amber-500";return e.jsx("span",{className:`inline-block h-2 w-2 rounded-full shrink-0 ${s}`,title:t})}function al(){const{companyPrefix:t,pluginId:s,pluginRoutePath:n}=$s(),{companies:r,selectedCompanyId:a}=he(),{setBreadcrumbs:i}=Me(),o=c.useMemo(()=>{if(!t)return null;const h=t.toUpperCase();return r.find(j=>j.issuePrefix.toUpperCase()===h)??null},[r,t]),l=!!t&&!o,u=c.useMemo(()=>o?o.id:t?null:a??null,[o,t,a]),d=c.useMemo(()=>{var h;return u?((h=r.find(j=>j.id===u))==null?void 0:h.issuePrefix)??null:null},[r,u]),{data:m}=V({queryKey:E.plugins.uiContributions,queryFn:()=>mt.listUiContributions(),enabled:!!u&&(!!s||!!n)}),x=c.useMemo(()=>{if(!m)return null;if(s){const j=m.find(f=>f.pluginId===s);if(!j)return null;const y=j.slots.find(f=>f.type==="page");return y?{...y,pluginId:j.pluginId,pluginKey:j.pluginKey,pluginDisplayName:j.displayName,pluginVersion:j.version}:null}if(!n)return null;const h=m.flatMap(j=>{const y=j.slots.find(f=>f.type==="page"&&f.routePath===n);return y?[{...y,pluginId:j.pluginId,pluginKey:j.pluginKey,pluginDisplayName:j.displayName,pluginVersion:j.version}]:[]});return h.length!==1?null:h[0]??null},[s,n,m]),p=c.useMemo(()=>({companyId:u??null,companyPrefix:d}),[u,d]);if(c.useEffect(()=>{x&&i([{label:"Plugins",href:"/instance/settings/plugins"},{label:x.pluginDisplayName}])},[x,d,i]),!u)return l?e.jsx(wn,{scope:"invalid_company_prefix",requestedPrefix:t}):e.jsx("div",{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a company to view this page."})});if(!m)return e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading…"});if(!s&&n&&m.filter(j=>j.slots.some(y=>y.type==="page"&&y.routePath===n)).length>1)return e.jsxs("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:["Multiple plugins declare the route ",e.jsx("code",{children:n}),". Use the plugin-id route until the conflict is resolved."]});if(!x){if(n)return e.jsx(wn,{scope:"board"});const h=s?`/instance/settings/plugins/${s}`:"/instance/settings/plugins";return e.jsx(ke,{to:h,replace:!0})}return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(xe,{to:d?`/${d}/dashboard`:"/dashboard",children:[e.jsx(gi,{className:"h-4 w-4 mr-1"}),"Back"]})})}),e.jsx(sa,{slot:x,context:p,className:"min-h-[200px]",missingBehavior:"placeholder"})]})}const vs={sourceRunId:"65a79d5d-5f85-4392-a5cc-8fb48beb9e71",agentName:"CodexCoder",issueIdentifier:"PAP-473",issueTitle:"Humanize run transcripts across run detail and live surfaces",startedAt:"2026-03-11T15:21:05.948Z"},Hn=[{kind:"stderr",ts:"2026-03-11T15:21:05.594Z",text:'[paperclip] Skipping saved session resume for task "PAP-473" because wake reason is issue_assigned.'},{kind:"init",ts:"2026-03-11T15:21:05.948Z",model:"codex",sessionId:"sess_fixture_01"},{kind:"system",ts:"2026-03-11T15:21:07.249Z",text:"turn started"},{kind:"assistant",ts:"2026-03-11T15:21:18.851Z",text:"I’m starting with the Paperclip heartbeat procedure and the repo-required docs so I can see what task is actually assigned and then work only on that scope."},{kind:"tool_call",ts:"2026-03-11T15:21:19.026Z",name:"command_execution",toolUseId:"item_1",input:{command:"sed -n '1,220p' doc/GOAL.md",cwd:"/workspace/paperclip"}},{kind:"tool_call",ts:"2026-03-11T15:21:19.026Z",name:"command_execution",toolUseId:"item_2",input:{command:"sed -n '1,320p' doc/SPEC-implementation.md",cwd:"/workspace/paperclip"}},{kind:"tool_result",ts:"2026-03-11T15:21:19.034Z",toolUseId:"item_1",content:`command: sed -n '1,220p' doc/GOAL.md
240
+ status: completed
241
+ exit_code: 0
242
+
243
+ # Paperclip
244
+
245
+ Paperclip is the backbone of the autonomous economy.`,isError:!1},{kind:"tool_result",ts:"2026-03-11T15:21:19.035Z",toolUseId:"item_2",content:`command: sed -n '1,320p' doc/SPEC-implementation.md
246
+ status: completed
247
+ exit_code: 0
248
+
249
+ # Paperclip V1 Implementation Spec
250
+
251
+ Paperclip V1 must provide a full control-plane loop for autonomous agents.`,isError:!1},{kind:"assistant",ts:"2026-03-11T15:22:08.806Z",text:"I’ve got the rendering entry points. I’m reading the existing transcript parser and the three UI surfaces together so I can collapse them onto one renderer instead of layering another one-off view."},{kind:"thinking",ts:"2026-03-11T15:22:12.044Z",text:"The current transcript UX duplicates parsing logic in multiple surfaces. A shared presentation layer will make the detail page and live surfaces behave the same way while keeping raw fallback available."},{kind:"tool_call",ts:"2026-03-11T15:22:15.401Z",name:"command_execution",toolUseId:"item_3",input:{command:'rg -n "LiveRunWidget|ActiveAgentsPanel|buildTranscript|TranscriptEntry|transcript" ui/src server/src packages',cwd:"/workspace/paperclip"}},{kind:"tool_result",ts:"2026-03-11T15:22:15.982Z",toolUseId:"item_3",content:`command: rg -n ...
252
+ status: completed
253
+ exit_code: 0
254
+
255
+ ui/src/components/ActiveAgentsPanel.tsx
256
+ ui/src/components/LiveRunWidget.tsx
257
+ ui/src/pages/AgentDetail.tsx`,isError:!1},{kind:"system",ts:"2026-03-11T15:22:21.617Z",text:"item started: web_search (id=ws_fixture_reasoning_ui)"},{kind:"system",ts:"2026-03-11T15:22:24.806Z",text:"item completed: web_search (id=ws_fixture_reasoning_ui)"},{kind:"assistant",ts:"2026-03-11T15:22:29.214Z",text:"I’ve confirmed the duplication: the run page has the only full transcript renderer, while live surfaces still collapse output into feed strings. I’m pulling markdown utilities and adapter shapes now so the new renderer can stay shared."},{kind:"tool_call",ts:"2026-03-11T15:23:04.251Z",name:"command_execution",toolUseId:"item_4",input:{command:"pnpm -r typecheck",cwd:"/workspace/paperclip"}},{kind:"tool_result",ts:"2026-03-11T15:23:26.903Z",toolUseId:"item_4",content:`command: pnpm -r typecheck
258
+ status: completed
259
+ exit_code: 0
260
+
261
+ packages/adapter-utils typecheck: Done
262
+ server typecheck: Done
263
+ ui typecheck: Done
264
+ cli typecheck: Done`,isError:!1},{kind:"assistant",ts:"2026-03-11T15:23:34.102Z",text:"Typecheck is clean. I’m running the remaining repo checks now so the transcript work is verified under the full workspace build, not just the UI package."},{kind:"tool_call",ts:"2026-03-11T15:23:40.511Z",name:"command_execution",toolUseId:"item_5",input:{command:"pnpm test:run",cwd:"/workspace/paperclip"}},{kind:"tool_result",ts:"2026-03-11T15:23:56.944Z",toolUseId:"item_5",content:`command: pnpm test:run
265
+ status: failed
266
+ exit_code: 1
267
+
268
+ FAIL packages/db/src/runtime-config.test.ts
269
+ FAIL src/__tests__/worktree.test.ts
270
+
271
+ All transcript-adapter tests passed after snapshot updates.`,isError:!0},{kind:"thinking",ts:"2026-03-11T15:24:02.188Z",text:"The remaining failures are unrelated to transcript rendering, so I should isolate them in the handoff and keep the UI change set focused."},{kind:"assistant",ts:"2026-03-11T15:24:08.490Z",text:"The new parser metadata changed a few adapter test snapshots exactly where expected, and the remaining red tests are outside this change set. I’m keeping the transcript patch focused and shipping with that caveat called out."},{kind:"tool_call",ts:"2026-03-11T15:24:21.327Z",name:"command_execution",toolUseId:"item_6",input:{command:"pnpm build",cwd:"/workspace/paperclip"}},{kind:"tool_result",ts:"2026-03-11T15:24:44.030Z",toolUseId:"item_6",content:`command: pnpm build
272
+ status: completed
273
+ exit_code: 0
274
+
275
+ ui build: built successfully
276
+ cli build: Done`,isError:!1},{kind:"tool_call",ts:"2026-03-11T15:24:52.504Z",name:"command_execution",toolUseId:"item_7",input:{command:'git commit -m "Humanize run transcripts across run detail and live surfaces"',cwd:"/workspace/paperclip"}},{kind:"tool_result",ts:"2026-03-11T15:24:53.104Z",toolUseId:"item_7",content:`command: git commit ...
277
+ status: completed
278
+ exit_code: 0
279
+
280
+ 87b8e21 Humanize run transcripts across run detail and live surfaces`,isError:!1},{kind:"assistant",ts:"2026-03-11T15:25:00.908Z",text:"Implemented the transcript UI refactor and switched the run detail page, issue live widget, and dashboard agent card onto the same rendering language."},{kind:"result",ts:"2026-03-11T15:25:05.440Z",text:"Transcript rollout complete with shared nice/raw rendering and compact live variants.",inputTokens:11240,outputTokens:3460,cachedTokens:520,costUsd:.048121,subtype:"success",isError:!1,errors:[]}],qa=[{id:"detail",label:"Run Detail",eyebrow:"Full transcript",description:"The long-form run page with the `Nice | Raw` toggle and the most inspectable transcript view.",icon:fx},{id:"live",label:"Issue Widget",eyebrow:"Live stream",description:"The issue-detail live run widget, optimized for following an active run without leaving the task page.",icon:Sx},{id:"dashboard",label:"Dashboard Card",eyebrow:"Dense card",description:"The active-agents dashboard card, tuned for compact scanning while keeping the same transcript language.",icon:Nx}];function hd(t){return t==="dashboard"?Hn.slice(-9):t==="live"?Hn.slice(-14):Hn}function Sb({mode:t,streaming:s,density:n}){return e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border/70 bg-background/80 shadow-[0_24px_60px_rgba(15,23,42,0.08)]",children:[e.jsxs("div",{className:"border-b border-border/60 bg-background/90 px-5 py-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ne,{variant:"outline",className:"uppercase tracking-[0.18em] text-[10px]",children:"Run Detail"}),e.jsx(Se,{status:s?"running":"succeeded"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:da(vs.startedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm font-medium",children:["Transcript (",Hn.length,")"]})]}),e.jsx("div",{className:"max-h-[720px] overflow-y-auto bg-[radial-gradient(circle_at_top_left,rgba(8,145,178,0.08),transparent_36%),radial-gradient(circle_at_bottom_right,rgba(245,158,11,0.10),transparent_28%)] p-5",children:e.jsx(Ci,{entries:Hn,mode:t,density:n,streaming:s})})]})}function Ib({streaming:t,mode:s,density:n}){return e.jsxs("div",{className:"overflow-hidden rounded-xl border border-cyan-500/25 bg-background/85 shadow-[0_20px_50px_rgba(6,182,212,0.10)]",children:[e.jsxs("div",{className:"border-b border-border/60 bg-cyan-500/[0.05] px-5 py-4",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-cyan-700 dark:text-cyan-300",children:"Live Runs"}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Compact live transcript stream for the issue detail page."})]}),e.jsxs("div",{className:"px-5 py-4",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(qe,{name:vs.agentName,size:"sm"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"rounded-full border border-border/70 bg-background/70 px-2 py-1 font-mono",children:vs.sourceRunId.slice(0,8)}),e.jsx(Se,{status:t?"running":"succeeded"}),e.jsx("span",{children:da(vs.startedAt)})]})]}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border/70 bg-background/70 px-2.5 py-1 text-[11px] text-muted-foreground",children:["Open run",e.jsx(En,{className:"h-3 w-3"})]})]}),e.jsx("div",{className:"max-h-[460px] overflow-y-auto pr-1",children:e.jsx(Ci,{entries:hd("live"),mode:s,density:n,limit:n==="compact"?10:12,streaming:t})})]})]})}function Ab({streaming:t,mode:s,density:n}){return e.jsx("div",{className:"max-w-md",children:e.jsxs("div",{className:z("flex h-[320px] flex-col overflow-hidden rounded-xl border shadow-[0_20px_40px_rgba(15,23,42,0.10)]",t?"border-cyan-500/25 bg-cyan-500/[0.04]":"border-border bg-background/75"),children:[e.jsxs("div",{className:"border-b border-border/60 px-4 py-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:z("inline-flex h-2.5 w-2.5 rounded-full",t?"bg-cyan-500 shadow-[0_0_0_6px_rgba(34,211,238,0.12)]":"bg-muted-foreground/35")}),e.jsx(qe,{name:vs.agentName,size:"sm"})]}),e.jsx("div",{className:"mt-2 text-[11px] text-muted-foreground",children:t?"Live now":"Finished 2m ago"})]}),e.jsx("span",{className:"rounded-full border border-border/70 bg-background/70 px-2 py-1 text-[10px] text-muted-foreground",children:e.jsx(En,{className:"h-2.5 w-2.5"})})]}),e.jsxs("div",{className:"mt-3 rounded-lg border border-border/60 bg-background/60 px-3 py-2 text-xs text-cyan-700 dark:text-cyan-300",children:[vs.issueIdentifier," - ",vs.issueTitle]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-4",children:e.jsx(Ci,{entries:hd("dashboard"),mode:s,density:n,limit:n==="compact"?6:8,streaming:t})})]})})}function Tb(){const[t,s]=c.useState("detail"),[n,r]=c.useState("nice"),[a,i]=c.useState(!0),[o,l]=c.useState("comfortable"),u=qa.find(d=>d.id===t)??qa[0];return e.jsx("div",{className:"space-y-6",children:e.jsx("div",{className:"overflow-hidden rounded-2xl border border-border/70 bg-[linear-gradient(135deg,rgba(8,145,178,0.08),transparent_28%),linear-gradient(180deg,rgba(245,158,11,0.08),transparent_40%),var(--background)] shadow-[0_28px_70px_rgba(15,23,42,0.10)]",children:e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[260px_minmax(0,1fr)]",children:[e.jsxs("aside",{className:"border-b border-border/60 bg-background/75 p-5 lg:border-b-0 lg:border-r",children:[e.jsxs("div",{className:"mb-5",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-cyan-500/25 bg-cyan-500/[0.08] px-3 py-1 text-[10px] font-semibold uppercase tracking-[0.24em] text-cyan-700 dark:text-cyan-300",children:[e.jsx(ma,{className:"h-3.5 w-3.5"}),"UX Lab"]}),e.jsx("h1",{className:"mt-4 text-2xl font-semibold tracking-tight",children:"Run Transcript Fixtures"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Built from a real Growthub development run, then sanitized so no secrets, local paths, or environment details survive into the fixture."})]}),e.jsx("div",{className:"space-y-2",children:qa.map(d=>{const m=d.icon;return e.jsx("button",{type:"button",onClick:()=>s(d.id),className:z("w-full rounded-xl border px-4 py-3 text-left transition-all",t===d.id?"border-cyan-500/35 bg-cyan-500/[0.10] shadow-[0_12px_24px_rgba(6,182,212,0.12)]":"border-border/70 bg-background/70 hover:border-cyan-500/20 hover:bg-cyan-500/[0.04]"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"rounded-lg border border-current/15 p-2 text-cyan-700 dark:text-cyan-300",children:e.jsx(m,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[10px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d.eyebrow}),e.jsx("span",{className:"mt-1 block text-sm font-medium",children:d.label}),e.jsx("span",{className:"mt-1 block text-xs text-muted-foreground",children:d.description})]})]})},d.id)})})]}),e.jsxs("main",{className:"min-w-0 p-5",children:[e.jsxs("div",{className:"mb-5 flex flex-col gap-4 xl:flex-row xl:items-end xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.22em] text-muted-foreground",children:u.eyebrow}),e.jsx("h2",{className:"mt-1 text-2xl font-semibold",children:u.label}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm text-muted-foreground",children:u.description})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Ne,{variant:"outline",className:"rounded-full px-3 py-1 text-[10px] uppercase tracking-[0.18em]",children:["Source run ",vs.sourceRunId.slice(0,8)]}),e.jsx(Ne,{variant:"outline",className:"rounded-full px-3 py-1 text-[10px] uppercase tracking-[0.18em]",children:vs.issueIdentifier})]})]}),e.jsxs("div",{className:"mb-5 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Controls"}),e.jsx("div",{className:"inline-flex rounded-full border border-border/70 bg-background/80 p-1",children:["nice","raw"].map(d=>e.jsx("button",{type:"button",className:z("rounded-full px-3 py-1 text-xs font-medium capitalize transition-colors",n===d?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>r(d),children:d},d))}),e.jsx("div",{className:"inline-flex rounded-full border border-border/70 bg-background/80 p-1",children:["comfortable","compact"].map(d=>e.jsx("button",{type:"button",className:z("rounded-full px-3 py-1 text-xs font-medium capitalize transition-colors",o===d?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>l(d),children:d},d))}),e.jsx(F,{variant:"outline",size:"sm",className:"rounded-full",onClick:()=>i(d=>!d),children:a?"Show settled state":"Show streaming state"})]}),t==="detail"?e.jsx("div",{className:z(o==="compact"&&"max-w-5xl"),children:e.jsx(Sb,{mode:n,streaming:a,density:o})}):t==="live"?e.jsx("div",{className:z(o==="compact"&&"max-w-4xl"),children:e.jsx(Ib,{streaming:a,mode:n,density:o})}):e.jsx(Ab,{streaming:a,mode:n,density:o})]})]})})})}const Ks=200,Pr=100,tr=32,Pb=80,Jr=60;function bn(t){if(t.reports.length===0)return Ks;const s=t.reports.reduce((r,a)=>r+bn(a),0),n=(t.reports.length-1)*tr;return Math.max(Ks,s+n)}function pd(t,s,n){const r=bn(t),a=[];if(t.reports.length>0){const i=t.reports.reduce((u,d)=>u+bn(d),0),o=(t.reports.length-1)*tr;let l=s+(r-i-o)/2;for(const u of t.reports){const d=bn(u);a.push(pd(u,l,n+Pr+Pb)),l+=d+tr}}return{id:t.id,name:t.name,role:t.role,status:t.status,x:s+(r-Ks)/2,y:n,children:a}}function Eb(t){if(t.length===0)return[];t.reduce((a,i)=>a+bn(i),0),(t.length-1)*tr;let s=Jr;const n=Jr,r=[];for(const a of t){const i=bn(a);r.push(pd(a,s,n)),s+=i+tr}return r}function Rb(t){const s=[];function n(r){s.push(r),r.children.forEach(n)}return t.forEach(n),s}function Mb(t){const s=[];function n(r){for(const a of r.children)s.push({parent:r,child:a}),n(a)}return t.forEach(n),s}const _b={claude_local:"Claude",codex_local:"Codex",gemini_local:"Gemini",opencode_local:"OpenCode",cursor:"Cursor",openclaw_gateway:"OpenClaw Gateway",process:"Process",http:"HTTP"},Db={running:"#22d3ee",active:"#4ade80",paused:"#facc15",idle:"#facc15",error:"#f87171",terminated:"#a3a3a3"},$b="#a3a3a3";function Fb(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),n=Mt(),{data:r,isLoading:a}=V({queryKey:E.org(t),queryFn:()=>Ee.org(t),enabled:!!t}),{data:i}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t}),o=c.useMemo(()=>{const M=new Map;for(const k of i??[])M.set(k.id,k);return M},[i]);c.useEffect(()=>{s([{label:"Org Chart"}])},[s]);const l=c.useMemo(()=>Eb(r??[]),[r]),u=c.useMemo(()=>Rb(l),[l]),d=c.useMemo(()=>Mb(l),[l]),m=c.useMemo(()=>{if(u.length===0)return{width:800,height:600};let M=0,k=0;for(const _ of u)M=Math.max(M,_.x+Ks),k=Math.max(k,_.y+Pr);return{width:M+Jr,height:k+Jr}},[u]),x=c.useRef(null),[p,h]=c.useState({x:0,y:0}),[j,y]=c.useState(1),[f,g]=c.useState(!1),A=c.useRef({x:0,y:0,panX:0,panY:0}),N=c.useRef(!1);c.useEffect(()=>{if(N.current||u.length===0||!x.current)return;N.current=!0;const M=x.current,k=M.clientWidth,_=M.clientHeight,U=(k-40)/m.width,w=(_-40)/m.height,T=Math.min(U,w,1),W=m.width*T,H=m.height*T;y(T),h({x:(k-W)/2,y:(_-H)/2})},[u,m]);const C=c.useCallback(M=>{M.button!==0||M.target.closest("[data-org-card]")||(g(!0),A.current={x:M.clientX,y:M.clientY,panX:p.x,panY:p.y})},[p]),S=c.useCallback(M=>{if(!f)return;const k=M.clientX-A.current.x,_=M.clientY-A.current.y;h({x:A.current.panX+k,y:A.current.panY+_})},[f]),b=c.useCallback(()=>{g(!1)},[]),v=c.useCallback(M=>{M.preventDefault();const k=x.current;if(!k)return;const _=k.getBoundingClientRect(),U=M.clientX-_.left,w=M.clientY-_.top,T=M.deltaY<0?1.1:.9,W=Math.min(Math.max(j*T,.2),2),H=W/j;h({x:U-H*(U-p.x),y:w-H*(w-p.y)}),y(W)},[j,p]);return t?a?e.jsx(rt,{variant:"org-chart"}):r&&r.length===0?e.jsx(Be,{icon:ti,message:"No organizational hierarchy defined."}):e.jsxs("div",{ref:x,className:"w-full h-[calc(100dvh-6rem)] overflow-hidden relative bg-muted/20 border border-border rounded-lg",style:{cursor:f?"grabbing":"grab"},onMouseDown:C,onMouseMove:S,onMouseUp:b,onMouseLeave:b,onWheel:v,children:[e.jsxs("div",{className:"absolute top-3 right-3 z-10 flex flex-col gap-1",children:[e.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-sm hover:bg-accent transition-colors",onClick:()=>{const M=Math.min(j*1.2,2),k=x.current;if(k){const _=k.clientWidth/2,U=k.clientHeight/2,w=M/j;h({x:_-w*(_-p.x),y:U-w*(U-p.y)})}y(M)},"aria-label":"Zoom in",children:"+"}),e.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-sm hover:bg-accent transition-colors",onClick:()=>{const M=Math.max(j*.8,.2),k=x.current;if(k){const _=k.clientWidth/2,U=k.clientHeight/2,w=M/j;h({x:_-w*(_-p.x),y:U-w*(U-p.y)})}y(M)},"aria-label":"Zoom out",children:"−"}),e.jsx("button",{className:"w-7 h-7 flex items-center justify-center bg-background border border-border rounded text-[10px] hover:bg-accent transition-colors",onClick:()=>{if(!x.current)return;const M=x.current.clientWidth,k=x.current.clientHeight,_=(M-40)/m.width,U=(k-40)/m.height,w=Math.min(_,U,1),T=m.width*w,W=m.height*w;y(w),h({x:(M-T)/2,y:(k-W)/2})},title:"Fit to screen","aria-label":"Fit chart to screen",children:"Fit"})]}),e.jsx("svg",{className:"absolute inset-0 pointer-events-none",style:{width:"100%",height:"100%"},children:e.jsx("g",{transform:`translate(${p.x}, ${p.y}) scale(${j})`,children:d.map(({parent:M,child:k})=>{const _=M.x+Ks/2,U=M.y+Pr,w=k.x+Ks/2,T=k.y,W=(U+T)/2;return e.jsx("path",{d:`M ${_} ${U} L ${_} ${W} L ${w} ${W} L ${w} ${T}`,fill:"none",stroke:"var(--border)",strokeWidth:1.5},`${M.id}-${k.id}`)})})}),e.jsx("div",{className:"absolute inset-0",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${j})`,transformOrigin:"0 0"},children:u.map(M=>{const k=o.get(M.id),_=Db[M.status]??$b;return e.jsx("div",{"data-org-card":!0,className:"absolute bg-card border border-border rounded-lg shadow-sm hover:shadow-md hover:border-foreground/20 transition-[box-shadow,border-color] duration-150 cursor-pointer select-none",style:{left:M.x,top:M.y,width:Ks,minHeight:Pr},onClick:()=>n(k?Xs(k):`/agents/${M.id}`),children:e.jsxs("div",{className:"flex items-center px-4 py-3 gap-3",children:[e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Er,{icon:k==null?void 0:k.icon,className:"h-4.5 w-4.5 text-foreground/70"})}),e.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-card",style:{backgroundColor:_}})]}),e.jsxs("div",{className:"flex flex-col items-start min-w-0 flex-1",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground leading-tight",children:M.name}),e.jsx("span",{className:"text-[11px] text-muted-foreground leading-tight mt-0.5",children:(k==null?void 0:k.title)??Ob(M.role)}),k&&e.jsx("span",{className:"text-[10px] text-muted-foreground/60 font-mono leading-tight mt-1",children:_b[k.adapterType]??k.adapterType})]})]})},M.id)})})]}):e.jsx(Be,{icon:ti,message:"Select a company to view the org chart."})}const Lb=El;function Ob(t){return Lb[t]??t}const qb=new Set(["claude_local","codex_local","gemini_local","opencode_local","pi_local","cursor","openclaw_gateway"]);function Bb(t){const{adapterType:s,...n}=Ll,r={...n,adapterType:t};return t==="codex_local"?(r.model=Zu,r.dangerouslyBypassSandbox=em):t==="gemini_local"?r.model=tm:t==="cursor"?r.model=sm:t==="opencode_local"&&(r.model=""),r}function zb(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),n=Le(),r=Mt(),[a]=vi(),i=a.get("adapterType"),[o,l]=c.useState(""),[u,d]=c.useState(""),[m,x]=c.useState("general"),[p,h]=c.useState(""),[j,y]=c.useState(Ll),[f,g]=c.useState(!1),[A,N]=c.useState(!1),[C,S]=c.useState(null),{data:b}=V({queryKey:E.agents.list(t),queryFn:()=>Ee.list(t),enabled:!!t}),{data:v,error:M,isLoading:k,isFetching:_}=V({queryKey:t?E.agents.adapterModels(t,j.adapterType):["agents","none","adapter-models",j.adapterType],queryFn:()=>Ee.adapterModels(t,j.adapterType),enabled:!!t}),U=!b||b.length===0,w=U?"ceo":m;c.useEffect(()=>{s([{label:"Agents",href:"/agents"},{label:"New Agent"}])},[s]),c.useEffect(()=>{U&&(o||l("CEO"),u||d("CEO"))},[U]),c.useEffect(()=>{const D=i;D&&qb.has(D)&&y(Z=>Z.adapterType===D?Z:Bb(D))},[i]);const T=se({mutationFn:D=>Ee.hire(t,D),onSuccess:D=>{n.invalidateQueries({queryKey:E.agents.list(t)}),n.invalidateQueries({queryKey:E.approvals.list(t)}),r(Xs(D.agent))},onError:D=>{S(D instanceof Error?D.message:"Failed to create agent")}});function W(){return nm(j.adapterType).buildAdapterConfig(j)}function H(){if(!(!t||!o.trim())){if(S(null),j.adapterType==="opencode_local"){const D=j.model.trim();if(!D){S("OpenCode requires an explicit model in provider/model format.");return}if(M){S(M instanceof Error?M.message:"Failed to load OpenCode models.");return}if(k||_){S("OpenCode models are still loading. Please wait and try again.");return}const Z=v??[];if(!Z.some(G=>G.id===D)){S(Z.length===0?"No OpenCode models discovered. Run `opencode models` and authenticate providers.":`Configured OpenCode model is unavailable: ${D}`);return}}T.mutate({name:o.trim(),role:w,...u.trim()?{title:u.trim()}:{},...p?{reportsTo:p}:{},adapterType:j.adapterType,adapterConfig:W(),runtimeConfig:{heartbeat:{enabled:j.heartbeatEnabled,intervalSec:j.intervalSec,wakeOnDemand:!0,cooldownSec:10,maxConcurrentRuns:1}},budgetMonthlyCents:0})}}const B=(b??[]).find(D=>D.id===p);return e.jsxs("div",{className:"mx-auto max-w-2xl space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",children:"New Agent"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Advanced agent configuration"})]}),e.jsxs("div",{className:"border border-border",children:[e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsx("input",{className:"w-full text-lg font-semibold bg-transparent outline-none placeholder:text-muted-foreground/50",placeholder:"Agent name",value:o,onChange:D=>l(D.target.value),autoFocus:!0})}),e.jsx("div",{className:"px-4 pb-2",children:e.jsx("input",{className:"w-full bg-transparent outline-none text-sm text-muted-foreground placeholder:text-muted-foreground/40",placeholder:"Title (e.g. VP of Engineering)",value:u,onChange:D=>d(D.target.value)})}),e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-2 border-t border-border flex-wrap",children:[e.jsxs(pt,{open:f,onOpenChange:g,children:[e.jsx(gt,{asChild:!0,children:e.jsxs("button",{className:z("inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",U&&"opacity-60 cursor-not-allowed"),disabled:U,children:[e.jsx(Yu,{className:"h-3 w-3 text-muted-foreground"}),ka[w]??w]})}),e.jsx(ft,{className:"w-36 p-1",align:"start",children:Ju.map(D=>e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",D===m&&"bg-accent"),onClick:()=>{x(D),g(!1)},children:ka[D]??D},D))})]}),e.jsxs(pt,{open:A,onOpenChange:N,children:[e.jsx(gt,{asChild:!0,children:e.jsx("button",{className:z("inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-xs hover:bg-accent/50 transition-colors",U&&"opacity-60 cursor-not-allowed"),disabled:U,children:B?e.jsxs(e.Fragment,{children:[e.jsx(Er,{icon:B.icon,className:"h-3 w-3 text-muted-foreground"}),`Reports to ${B.name}`]}):e.jsxs(e.Fragment,{children:[e.jsx(dn,{className:"h-3 w-3 text-muted-foreground"}),U?"Reports to: N/A (CEO)":"Reports to..."]})})}),e.jsxs(ft,{className:"w-48 p-1",align:"start",children:[e.jsx("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",!p&&"bg-accent"),onClick:()=>{h(""),N(!1)},children:"No manager"}),(b??[]).map(D=>e.jsxs("button",{className:z("flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 truncate",D.id===p&&"bg-accent"),onClick:()=>{h(D.id),N(!1)},children:[e.jsx(Er,{icon:D.icon,className:"shrink-0 h-3 w-3 text-muted-foreground"}),D.name,e.jsx("span",{className:"text-muted-foreground ml-auto",children:ka[D.role]??D.role})]},D.id))]})]})]}),e.jsx(Xu,{mode:"create",values:j,onChange:D=>y(Z=>({...Z,...D})),adapterModels:v}),e.jsxs("div",{className:"border-t border-border px-4 py-3",children:[U&&e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"This will be the CEO"}),C&&e.jsx("p",{className:"text-xs text-destructive mb-2",children:C}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{variant:"outline",size:"sm",onClick:()=>r("/agents"),children:"Cancel"}),e.jsx(F,{size:"sm",disabled:!o.trim()||T.isPending,onClick:H,children:T.isPending?"Creating…":"Create agent"})]})]})]})]})}const il=[{dot:"bg-violet-500",badge:"text-violet-500 bg-violet-500/10 border-violet-500/20"},{dot:"bg-blue-500",badge:"text-blue-500 bg-blue-500/10 border-blue-500/20"},{dot:"bg-amber-500",badge:"text-amber-500 bg-amber-500/10 border-amber-500/20"},{dot:"bg-orange-500",badge:"text-orange-500 bg-orange-500/10 border-orange-500/20"},{dot:"bg-green-500",badge:"text-green-500 bg-green-500/10 border-green-500/20"},{dot:"bg-pink-500",badge:"text-pink-500 bg-pink-500/10 border-pink-500/20"},{dot:"bg-cyan-500",badge:"text-cyan-500 bg-cyan-500/10 border-cyan-500/20"}];function Kb(t){return t.charAt(0).toUpperCase()+t.slice(1)}function gd(t,s){const n=s.indexOf(t);return il[(n>=0?n:0)%il.length]}function Ub({ticket:t}){const s=t.stageOrder,n=s.indexOf(t.currentStage);return e.jsx("div",{className:"flex items-center gap-0.5 shrink-0",children:s.map((r,a)=>{const i=gd(r,s);return e.jsxs("div",{className:"flex items-center gap-0.5",children:[a>0&&e.jsx("div",{className:z("h-px w-3",a<=n?"bg-green-500/50":"bg-border")}),e.jsx("div",{className:z("h-2 w-2 rounded-full",a<n&&"bg-green-500/70",a===n&&i.dot,a>n&&"bg-border")})]},r)})})}function ol({ticket:t,liveCount:s}){const n=gd(t.currentStage,t.stageOrder),r=t.status==="done"||t.status==="cancelled";return e.jsxs(xe,{to:`/tickets/${t.id}`,className:"flex items-center gap-4 px-4 py-3 text-sm hover:bg-accent/50 transition-colors no-underline text-inherit group",children:[e.jsx(Ub,{ticket:t}),e.jsx("span",{className:z("flex-1 truncate font-medium",r&&"text-muted-foreground line-through decoration-muted-foreground/40"),children:t.title}),s>0&&e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-cyan-600 dark:text-cyan-400 font-medium shrink-0",children:[e.jsxs("span",{className:"relative flex h-1.5 w-1.5",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-cyan-400 opacity-70"}),e.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-cyan-500"})]}),s," live"]}),r&&e.jsx(yi,{className:"h-3.5 w-3.5 text-muted-foreground/40 shrink-0"}),e.jsx("span",{className:z("text-xs border rounded px-1.5 py-0.5 shrink-0",n.badge),children:Kb(t.currentStage)}),e.jsx("span",{className:"text-xs font-mono text-muted-foreground/50 shrink-0",children:t.identifier}),e.jsx(aa,{className:"h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground transition-colors"})]})}function Gb(){const{selectedCompanyId:t}=he(),{setBreadcrumbs:s}=Me(),[n,r]=c.useState(!1),[a,i]=c.useState(!1);c.useEffect(()=>{s([{label:"Tickets"}])},[s]);const{data:o,isLoading:l}=V({queryKey:E.tickets.list(t),queryFn:()=>Xn.list(t),enabled:!!t,refetchInterval:5e3}),{data:u=[]}=V({queryKey:E.liveRuns(t),queryFn:()=>Ht.liveRunsForCompany(t,100),enabled:!!t,refetchInterval:5e3}),d=c.useMemo(()=>{const h=new Map;for(const j of u){if(j.status!=="running"&&j.status!=="queued")continue;const y=j.ticketId;y&&h.set(y,(h.get(y)??0)+1)}return h},[u]);if(l)return e.jsx(rt,{variant:"list"});const m=(o==null?void 0:o.filter(h=>h.status==="active"))??[],x=(o==null?void 0:o.filter(h=>h.status!=="active"))??[],p=m.reduce((h,j)=>h+(d.get(j.id)??0),0);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",children:"Tickets"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[m.length," active",p>0&&e.jsxs("span",{className:"ml-2 text-cyan-600 dark:text-cyan-400 font-medium",children:["· ",p," agent",p!==1?"s":""," live"]}),x.length>0&&` · ${x.length} closed`]})]}),e.jsxs(F,{size:"sm",onClick:()=>r(!0),children:[e.jsx(Pe,{className:"h-4 w-4 mr-1"})," New Ticket"]})]}),e.jsx(Qc,{open:n,onClose:()=>r(!1),companyId:t,onSuccess:h=>{r(!1),window.location.href=`/tickets/${h}`}}),!o||o.length===0?e.jsx(Be,{icon:za,message:"No tickets yet. Create one to group issues across your agent pipeline.",action:"New Ticket",onAction:()=>r(!0)}):e.jsxs("div",{className:"space-y-5",children:[m.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2",children:"Active"}),e.jsx("div",{className:"border border-border divide-y divide-border overflow-hidden rounded-lg",children:m.map(h=>e.jsx(ol,{ticket:h,liveCount:d.get(h.id)??0},h.id))})]}),x.length>0&&e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>i(h=>!h),className:"flex items-center gap-2 text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2 hover:text-foreground transition-colors",children:[a?"▾":"▸"," Closed (",x.length,")"]}),a&&e.jsx("div",{className:"border border-border divide-y divide-border overflow-hidden rounded-lg opacity-60",children:x.map(h=>e.jsx(ol,{ticket:h,liveCount:0},h.id))})]})]})]})}const Ae=cl.slice(1),Wb=new RegExp(`^${cl}(?=/|$)`);function Vb({hasActiveInvite:t=!1}){return e.jsx("div",{className:"mx-auto max-w-xl py-10",children:e.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Instance setup required"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:t?"No instance admin exists yet. A bootstrap invite is already active. Check your Growthub startup logs for the first admin invite URL, or run this command to rotate it:":"No instance admin exists yet. Run this command in your Growthub environment to generate the first admin invite URL:"}),e.jsx("pre",{className:"mt-4 overflow-x-auto rounded-md border border-border bg-muted/30 p-3 text-xs",children:"pnpm growthub auth bootstrap-ceo"})]})})}function Hb(){var a,i;const t=bt(),s=V({queryKey:E.health,queryFn:()=>Cl.get(),retry:!1,refetchInterval:o=>{const l=o.state.data;return(l==null?void 0:l.deploymentMode)==="authenticated"&&l.bootstrapStatus==="bootstrap_pending"?2e3:!1},refetchIntervalInBackground:!0}),n=((a=s.data)==null?void 0:a.deploymentMode)==="authenticated",r=V({queryKey:E.auth.session,queryFn:()=>na.getSession(),enabled:n,retry:!1});if(s.isLoading||n&&r.isLoading)return e.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});if(s.error)return e.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-destructive",children:s.error instanceof Error?s.error.message:"Failed to load app state"});if(n&&((i=s.data)==null?void 0:i.bootstrapStatus)==="bootstrap_pending")return e.jsx(Vb,{hasActiveInvite:s.data.bootstrapInviteActive});if(n&&!r.data){const o=encodeURIComponent(`${t.pathname}${t.search}`);return e.jsx(ke,{to:`/auth?next=${o}`,replace:!0})}return e.jsx(kl,{})}function Qb(){return e.jsxs(e.Fragment,{children:[e.jsx(Y,{index:!0,element:e.jsx(ke,{to:"dashboard",replace:!0})}),e.jsx(Y,{path:"dashboard",element:e.jsx(Hg,{})}),e.jsx(Y,{path:"onboarding",element:e.jsx(fd,{})}),e.jsx(Y,{path:"companies",element:e.jsx(Qg,{})}),e.jsx(Y,{path:"company/settings",element:e.jsx(lb,{})}),e.jsx(Y,{path:"settings",element:e.jsx(Xr,{})}),e.jsx(Y,{path:"settings/*",element:e.jsx(Xr,{})}),e.jsx(Y,{path:"plugins/:pluginId",element:e.jsx(al,{})}),e.jsx(Y,{path:"org",element:e.jsx(Fb,{})}),e.jsx(Y,{path:"agents",element:e.jsx(ke,{to:"/agents/all",replace:!0})}),e.jsx(Y,{path:"agents/all",element:e.jsx(Nr,{})}),e.jsx(Y,{path:"agents/active",element:e.jsx(Nr,{})}),e.jsx(Y,{path:"agents/paused",element:e.jsx(Nr,{})}),e.jsx(Y,{path:"agents/error",element:e.jsx(Nr,{})}),e.jsx(Y,{path:"agents/new",element:e.jsx(zb,{})}),e.jsx(Y,{path:"agents/:agentId",element:e.jsx(Ca,{})}),e.jsx(Y,{path:"agents/:agentId/:tab",element:e.jsx(Ca,{})}),e.jsx(Y,{path:"agents/:agentId/runs/:runId",element:e.jsx(Ca,{})}),e.jsx(Y,{path:"projects",element:e.jsx(Jg,{})}),e.jsx(Y,{path:"projects/:projectId",element:e.jsx(an,{})}),e.jsx(Y,{path:"projects/:projectId/overview",element:e.jsx(an,{})}),e.jsx(Y,{path:"projects/:projectId/issues",element:e.jsx(an,{})}),e.jsx(Y,{path:"projects/:projectId/issues/:filter",element:e.jsx(an,{})}),e.jsx(Y,{path:"projects/:projectId/configuration",element:e.jsx(an,{})}),e.jsx(Y,{path:"projects/:projectId/budget",element:e.jsx(an,{})}),e.jsx(Y,{path:"tickets",element:e.jsx(Gb,{})}),e.jsx(Y,{path:"tickets/:ticketId",element:e.jsx(cm,{})}),e.jsx(Y,{path:"issues",element:e.jsx(gf,{})}),e.jsx(Y,{path:"issues/all",element:e.jsx(ke,{to:"/issues",replace:!0})}),e.jsx(Y,{path:"issues/active",element:e.jsx(ke,{to:"/issues",replace:!0})}),e.jsx(Y,{path:"issues/backlog",element:e.jsx(ke,{to:"/issues",replace:!0})}),e.jsx(Y,{path:"issues/done",element:e.jsx(ke,{to:"/issues",replace:!0})}),e.jsx(Y,{path:"issues/recent",element:e.jsx(ke,{to:"/issues",replace:!0})}),e.jsx(Y,{path:"issues/:issueId",element:e.jsx(dm,{})}),e.jsx(Y,{path:"execution-workspaces/:workspaceId",element:e.jsx(bf,{})}),e.jsx(Y,{path:"goals",element:e.jsx(jf,{})}),e.jsx(Y,{path:"goals/:goalId",element:e.jsx(Nf,{})}),e.jsx(Y,{path:"approvals",element:e.jsx(ke,{to:"/approvals/pending",replace:!0})}),e.jsx(Y,{path:"approvals/pending",element:e.jsx(Ko,{})}),e.jsx(Y,{path:"approvals/all",element:e.jsx(Ko,{})}),e.jsx(Y,{path:"approvals/:approvalId",element:e.jsx(Tf,{})}),e.jsx(Y,{path:"costs",element:e.jsx(eb,{})}),e.jsx(Y,{path:"activity",element:e.jsx(nb,{})}),e.jsx(Y,{path:"inbox",element:e.jsx(Yb,{})}),e.jsx(Y,{path:"inbox/recent",element:e.jsx(La,{})}),e.jsx(Y,{path:"inbox/unread",element:e.jsx(La,{})}),e.jsx(Y,{path:"inbox/all",element:e.jsx(La,{})}),e.jsx(Y,{path:"inbox/new",element:e.jsx(ke,{to:"/inbox/recent",replace:!0})}),e.jsx(Y,{path:"design-guide",element:e.jsx(mb,{})}),e.jsx(Y,{path:"tests/ux/runs",element:e.jsx(Tb,{})}),e.jsx(Y,{path:":pluginRoutePath",element:e.jsx(al,{})}),e.jsx(Y,{path:"*",element:e.jsx(wn,{scope:"board"})})]})}function Yb(){return e.jsx(ke,{to:`/inbox/${Dp()}`,replace:!0})}function Xr(){const t=bt();return e.jsx(ke,{to:`/instance/settings/heartbeats${t.search}${t.hash}`,replace:!0})}function fd(){const{companies:t}=he(),{openOnboarding:s}=Ve(),{companyPrefix:n}=$s(),r=n?t.find(o=>o.issuePrefix.toUpperCase()===n.toUpperCase())??null:null,a=r?`Add another agent to ${r.name}`:t.length>0?"Create another company":"Create your first company",i=r?"Run onboarding again to add an agent and a starter task for this company.":t.length>0?"Run onboarding again to create another company and seed its first agent.":"Get started by creating a company and your first agent.";return e.jsx("div",{className:"mx-auto max-w-xl py-10",children:e.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[e.jsx("h1",{className:"text-xl font-semibold",children:a}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:i}),e.jsx("div",{className:"mt-4",children:e.jsx(F,{onClick:()=>r?s({initialStep:2,companyId:r.id}):s(),children:r?"Add Agent":"Start Onboarding"})})]})})}function Jb(){const{companies:t,selectedCompany:s,loading:n}=he(),r=bt();if(n)return e.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});const a=s??t[0]??null;return a?e.jsx(ke,{to:Vs(`${a.issuePrefix}/dashboard`),replace:!0}):Ol({pathname:r.pathname,hasCompanies:!1})?e.jsx(ke,{to:Vs("onboarding"),replace:!0}):e.jsx(bd,{})}function nt(){const t=bt(),{companies:s,selectedCompany:n,loading:r}=he();if(r)return e.jsx("div",{className:"mx-auto max-w-xl py-10 text-sm text-muted-foreground",children:"Loading..."});const a=n??s[0]??null;return a?e.jsx(ke,{to:Vs(`${a.issuePrefix}${t.pathname.replace(Wb,"")}${t.search}${t.hash}`),replace:!0}):Ol({pathname:t.pathname,hasCompanies:!1})?e.jsx(ke,{to:Vs("onboarding"),replace:!0}):e.jsx(bd,{})}function bd(){const{openOnboarding:t}=Ve();return e.jsx("div",{className:"mx-auto max-w-xl py-10",children:e.jsxs("div",{className:"rounded-lg border border-border bg-card p-6",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Create your first company"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Get started by creating a company."}),e.jsx("div",{className:"mt-4",children:e.jsx(F,{onClick:()=>t(),children:"New Company"})})]})})}function Xb(){return e.jsxs(e.Fragment,{children:[e.jsxs(rm,{children:[e.jsx(Y,{path:"/",element:e.jsx(ke,{to:Vs(),replace:!0})}),e.jsx(Y,{path:"auth",element:e.jsx(am,{})}),e.jsx(Y,{path:"board-claim/:token",element:e.jsx(im,{})}),e.jsx(Y,{path:"invite/:token",element:e.jsx(om,{})}),e.jsxs(Y,{element:e.jsx(Hb,{}),children:[e.jsx(Y,{path:Ae,element:e.jsx(Jb,{})}),e.jsx(Y,{path:`${Ae}/onboarding`,element:e.jsx(fd,{})}),e.jsx(Y,{path:`${Ae}/instance`,element:e.jsx(ke,{to:Vs("instance/settings/heartbeats"),replace:!0})}),e.jsxs(Y,{path:`${Ae}/instance/settings`,element:e.jsx(Lo,{}),children:[e.jsx(Y,{index:!0,element:e.jsx(ke,{to:"heartbeats",replace:!0})}),e.jsx(Y,{path:"heartbeats",element:e.jsx(hb,{})}),e.jsx(Y,{path:"experimental",element:e.jsx(pb,{})}),e.jsx(Y,{path:"plugins",element:e.jsx(fb,{})}),e.jsx(Y,{path:"plugins/:pluginId",element:e.jsx(vb,{})})]}),e.jsx(Y,{path:`${Ae}/companies`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/tickets`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/tickets/:ticketId`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/issues`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/issues/:issueId`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/settings`,element:e.jsx(Xr,{})}),e.jsx(Y,{path:`${Ae}/settings/*`,element:e.jsx(Xr,{})}),e.jsx(Y,{path:`${Ae}/agents`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/agents/new`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/agents/:agentId`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/agents/:agentId/:tab`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/agents/:agentId/runs/:runId`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/projects`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/projects/:projectId`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/projects/:projectId/overview`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/projects/:projectId/issues`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/projects/:projectId/issues/:filter`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/projects/:projectId/configuration`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/tests/ux/runs`,element:e.jsx(nt,{})}),e.jsx(Y,{path:`${Ae}/:companyPrefix`,element:e.jsx(Lo,{}),children:Qb()}),e.jsx(Y,{path:"gtm/*",element:e.jsx(wn,{scope:"global"})}),e.jsx(Y,{path:"*",element:e.jsx(wn,{scope:"global"})})]})]}),e.jsx(lm,{})]})}km(jd,Cm);const Zb=new mm({defaultOptions:{queries:{staleTime:3e4,refetchOnWindowFocus:!0}}});function nj(){return e.jsx(um,{client:Zb,children:e.jsx(xm,{children:e.jsx(hm,{children:e.jsx(pm,{children:e.jsx(gm,{children:e.jsx(fm,{children:e.jsx(bm,{children:e.jsx(jm,{children:e.jsx(vm,{children:e.jsx(ym,{children:e.jsx(Nm,{children:e.jsx(wm,{children:e.jsx(Xb,{})})})})})})})})})})})})})}export{nj as DxRoot};