@puddle-code/cli 0.5.6 → 0.5.7

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 (108) hide show
  1. package/CHANGELOG.md +14 -5
  2. package/dist/host-control.mjs +18 -1
  3. package/dist/index.js +48 -6
  4. package/dist/public/assets/App-CYkXXLs2.js +25 -0
  5. package/dist/public/assets/{CompilationCommandForm-DXHvwQ8Y.js → CompilationCommandForm-BkQcFUoa.js} +1 -1
  6. package/dist/public/assets/Dashboard-03re-W2v.js +1 -0
  7. package/dist/public/assets/{DraftRecovery-B8Ld4_1b.js → DraftRecovery-tIdw_B9k.js} +1 -1
  8. package/dist/public/assets/EditorTabClose-fs9t84tp.js +1 -0
  9. package/dist/public/assets/{FileCloseScope-DoZ0oLf8.js → FileCloseScope-BS5YFuzv.js} +1 -1
  10. package/dist/public/assets/{FileEditorSettingsMenu-BbRHII96.js → FileEditorSettingsMenu-DUpeKKAz.js} +1 -1
  11. package/dist/public/assets/{FindWidget-ET5pwkkB.js → FindWidget-FJWGUnZT.js} +1 -1
  12. package/dist/public/assets/HuddlePane-CFYGRv0M.js +219 -0
  13. package/dist/public/assets/{LazyTerminal-DnrWO9aI.js → LazyTerminal-DRIHw2iz.js} +2 -2
  14. package/dist/public/assets/{NotebookWidget-BDdx0BOy.js → NotebookWidget-O9o5XL61.js} +2 -2
  15. package/dist/public/assets/{PaneEditorBody-C1uu9cRG.js → PaneEditorBody-gYNeVTlY.js} +7 -7
  16. package/dist/public/assets/{PdfViewer-DLCPKybn.js → PdfViewer-BC-g7S60.js} +1 -1
  17. package/dist/public/assets/ReadOnlyDiff-DVzIKTvw.js +2 -0
  18. package/dist/public/assets/{ReleaseNotesDialog-B9fRaZNN.js → ReleaseNotesDialog-B1DpXA1c.js} +1 -1
  19. package/dist/public/assets/Ripple-B_d76mLT.js +11 -0
  20. package/dist/public/assets/SettingsDialog-BgmpTW4O.js +8 -0
  21. package/dist/public/assets/{Terminal-BP1tyPdf.js → Terminal-_I1S2ZXt.js} +6 -6
  22. package/dist/public/assets/Workspace-DjRRDhFc.js +20 -0
  23. package/dist/public/assets/api-BLc59FAZ.js +1 -0
  24. package/dist/public/assets/auth-tYM1depE.js +1 -0
  25. package/dist/public/assets/{button-D-qeQvl5.js → button-BNH9tKwf.js} +1 -1
  26. package/dist/public/assets/{chevron-right-DUkOv15w.js → chevron-right-6pjfw_yV.js} +1 -1
  27. package/dist/public/assets/{colour-picker-DZdAiaVI.js → colour-picker-cDlTcc8M.js} +1 -1
  28. package/dist/public/assets/{command-BeX8pm7h.js → command-RRKOl81e.js} +1 -1
  29. package/dist/public/assets/{content-state-CROLtMfN.js → content-state-BO1TLd_9.js} +1 -1
  30. package/dist/public/assets/{context-NsaMZKAN.js → context-C632GWyy.js} +1 -1
  31. package/dist/public/assets/{control-tray-CjoJunx1.js → control-tray-jUtkASPS.js} +1 -1
  32. package/dist/public/assets/dialog-DfdBRe6G.js +41 -0
  33. package/dist/public/assets/{disclosure-CpSwsC7J.js → disclosure-oYVpfMYO.js} +1 -1
  34. package/dist/public/assets/dist-CNoWjXWo.js +1 -0
  35. package/dist/public/assets/{dist-BcrNV8NP.js → dist-CaMNiZN8.js} +1 -1
  36. package/dist/public/assets/dist-DMpqv5CF.js +1 -0
  37. package/dist/public/assets/{drafts-CBbjQQbz.js → drafts-wug-3Dad.js} +1 -1
  38. package/dist/public/assets/editor-context-CR20pm26.js +5 -0
  39. package/dist/public/assets/editor-links-DFaQQsK-.js +1 -0
  40. package/dist/public/assets/{editor-sync-BOfDr2yY.js → editor-sync-CVFWKRes.js} +1 -1
  41. package/dist/public/assets/{errors-CviT-mvB.js → errors-CV02t999.js} +1 -1
  42. package/dist/public/assets/expanding-content-CQQYN3yg.js +1 -0
  43. package/dist/public/assets/{file-editor-settings-BXTs1F7S.js → file-editor-settings-DXGv9vrt.js} +1 -1
  44. package/dist/public/assets/{file-links-CgOYgoMC.js → file-links-JFyQw_0a.js} +1 -1
  45. package/dist/public/assets/forward-link-Kt311XAU.js +1 -0
  46. package/dist/public/assets/hotkeys-ChnvTHTH.js +1 -0
  47. package/dist/public/assets/index-Cif1X6lX.css +2 -0
  48. package/dist/public/assets/index-Dp1Lhq2t.js +10 -0
  49. package/dist/public/assets/{react-dom-cJyBB_A4.js → jsx-runtime-ffCh33zF.js} +1 -1
  50. package/dist/public/assets/local-store-3IuC2qMo.js +276 -0
  51. package/dist/public/assets/notification-delivery-DWIF1cHd.js +1 -0
  52. package/dist/public/assets/{popover-Okyclsx8.js → popover-CNEMQBFf.js} +1 -1
  53. package/dist/public/assets/{preferences-CvSHA-AA.js → preferences-sJF-HcJf.js} +1 -1
  54. package/dist/public/assets/{profile-icons-BI2xFWcB.js → profile-icons-CFPzzic1.js} +1 -1
  55. package/dist/public/assets/profile-store-BDrSK8Qs.js +1 -0
  56. package/dist/public/assets/project-actions-DsWg9uGZ.js +1 -0
  57. package/dist/public/assets/project-drag-B0ojbuY7.js +1 -0
  58. package/dist/public/assets/{protocol-support-iXloAH0N.js → protocol-support-C2shbX3-.js} +1 -1
  59. package/dist/public/assets/queries-essOjrjZ.js +1 -0
  60. package/dist/public/assets/{render-rich-content-fo4uQVWR.js → render-rich-content-DlSv3j1S.js} +2 -2
  61. package/dist/public/assets/{scroll-restoration-C_ly1bKS.js → scroll-restoration-Bt7-rGXy.js} +1 -1
  62. package/dist/public/assets/select-DHaYbZVV.js +1 -0
  63. package/dist/public/assets/selection-actions-Bis7oo_z.js +1 -0
  64. package/dist/public/assets/{session-display-BUDNzNmg.js → session-display-Bxz8xi3w.js} +1 -1
  65. package/dist/public/assets/{session-order-b3nCJcCG.js → session-order-DsJCcSqx.js} +1 -1
  66. package/dist/public/assets/state-BoqmEoqv.js +1 -0
  67. package/dist/public/assets/{switch-CGrhQUXr.js → switch-DZ2lisDt.js} +1 -1
  68. package/dist/public/assets/{tooltip-Ek-eHPZu.js → tooltip-CtT-5xHL.js} +1 -1
  69. package/dist/public/assets/use-arrangement-ready-CovEzBp-.js +1 -0
  70. package/dist/public/assets/use-desktop-state-CS5BxWes.js +2 -0
  71. package/dist/public/assets/view-state-store-gvFpSJG_.js +1 -0
  72. package/dist/public/assets/window-context-Euxqnh6S.js +2 -0
  73. package/dist/public/assets/{ws-CDXOuBYB.js → ws-Du8jZ4aQ.js} +1 -1
  74. package/dist/public/index.html +6 -6
  75. package/dist/pudl.js +18 -1
  76. package/package.json +1 -1
  77. package/dist/public/assets/App-nkMPe95U.js +0 -16
  78. package/dist/public/assets/Dashboard-CoGS2W82.js +0 -1
  79. package/dist/public/assets/EditorTabClose-CGYLU9GK.js +0 -1
  80. package/dist/public/assets/HuddlePane-LF3pjMQM.js +0 -219
  81. package/dist/public/assets/ReadOnlyDiff-C7ZSVRt-.js +0 -2
  82. package/dist/public/assets/Ripple-Dzg6tdOM.js +0 -11
  83. package/dist/public/assets/SettingsDialog-wkV1PX96.js +0 -8
  84. package/dist/public/assets/Workspace-BAWfBTc9.js +0 -20
  85. package/dist/public/assets/api-CrP4jl9e.js +0 -1
  86. package/dist/public/assets/auth-1SSLu56b.js +0 -1
  87. package/dist/public/assets/dialog-CTN-Lln6.js +0 -41
  88. package/dist/public/assets/dist-BOS6OKSE.js +0 -1
  89. package/dist/public/assets/dist-NuV8HBEc.js +0 -1
  90. package/dist/public/assets/editor-context-T5zIHY3K.js +0 -5
  91. package/dist/public/assets/expanding-content-91gc88rm.js +0 -1
  92. package/dist/public/assets/forward-link-qOyuWj08.js +0 -1
  93. package/dist/public/assets/hotkeys-nP8gYtE7.js +0 -1
  94. package/dist/public/assets/index-BB_BPKbu.css +0 -2
  95. package/dist/public/assets/index-CYyz1r9Q.js +0 -10
  96. package/dist/public/assets/jsx-runtime-By8HlURe.js +0 -1
  97. package/dist/public/assets/local-store-Dy1Cd8sn.js +0 -276
  98. package/dist/public/assets/notification-delivery-CtlAdV8W.js +0 -1
  99. package/dist/public/assets/profile-store-D4lZiXgL.js +0 -2
  100. package/dist/public/assets/project-actions-Ck504AFM.js +0 -1
  101. package/dist/public/assets/project-drag-BnkK15qk.js +0 -1
  102. package/dist/public/assets/queries-BSkHGZG8.js +0 -1
  103. package/dist/public/assets/select-DzQdQNsv.js +0 -1
  104. package/dist/public/assets/selection-actions-CWu4uTBo.js +0 -1
  105. package/dist/public/assets/state-CuUqRNo7.js +0 -1
  106. package/dist/public/assets/use-arrangement-ready-1vmV5np6.js +0 -1
  107. package/dist/public/assets/use-desktop-state-CBTzsmlz.js +0 -2
  108. package/dist/public/assets/view-state-store-Dqk7M5ei.js +0 -1
@@ -0,0 +1,20 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/buffer-store-OTFEYxTw.js","assets/rolldown-runtime-QTnfLwEv.js","assets/editor.api2-Cyagyq8b.js","assets/editor-Br_kD0ds.css","assets/languages-O6mK4sJI.js","assets/react-CZI7_Jkm.js","assets/theme-swfNLod9.js","assets/preload-helper-Czpn1I53.js","assets/workers-CqunsJhE.js","assets/monaco.contribution-DOhsxmke.js","assets/buffer-logic-D9FvoilV.js","assets/HuddlePane-CFYGRv0M.js","assets/jsx-runtime-ffCh33zF.js","assets/protocol-support-C2shbX3-.js","assets/local-store-3IuC2qMo.js","assets/auth-tYM1depE.js","assets/api-BLc59FAZ.js","assets/queries-essOjrjZ.js","assets/editor-links-DFaQQsK-.js","assets/client-settings-BdKglwtW.js","assets/window-context-Euxqnh6S.js","assets/editor-context-CR20pm26.js","assets/dist-DMpqv5CF.js","assets/createLucideIcon-DyMAgLa3.js","assets/square-terminal-CrlDquCd.js","assets/utils-B6KiDbIe.js","assets/dialog-DfdBRe6G.js","assets/x-CbfJFzGo.js","assets/dialog-BX0tebJL.css","assets/dist-CNoWjXWo.js","assets/select-DHaYbZVV.js","assets/chevron-down--sjpQEHH.js","assets/tooltip-CtT-5xHL.js","assets/button-BNH9tKwf.js","assets/chevron-right-6pjfw_yV.js","assets/colour-picker-cDlTcc8M.js","assets/profile-icons-CFPzzic1.js","assets/switch-DZ2lisDt.js","assets/shield-check-CY69Ons-.js","assets/code-DRWf9a5s.js","assets/ReadOnlyDiff-DVzIKTvw.js","assets/motion-Bd_MB9cH.js","assets/disclosure-oYVpfMYO.js","assets/profile-store-BDrSK8Qs.js","assets/hotkeys-ChnvTHTH.js","assets/content-state-BO1TLd_9.js","assets/file-editor-settings-DXGv9vrt.js","assets/view-state-store-gvFpSJG_.js","assets/source-anchor-map-BNxSa_bJ.js","assets/drafts-wug-3Dad.js","assets/debounce-B9DrqirV.js","assets/editor-sync-CVFWKRes.js","assets/state-BoqmEoqv.js","assets/rotate-ccw-CNjR2LSi.js","assets/save-BT7q_AMN.js","assets/settings-2-CInoy48z.js","assets/control-tray-jUtkASPS.js","assets/control-tray-CG26TqqQ.css","assets/popover-CNEMQBFf.js","assets/zoom-intent-vemBFIak.js","assets/PaneEditorBody-gYNeVTlY.js","assets/context-C632GWyy.js","assets/purify.es-D8QhFVkO.js","assets/katex.min-ZqdHjttS.js","assets/katex-Dz-67XSV.css","assets/DraftRecovery-tIdw_B9k.js","assets/dist-CaMNiZN8.js","assets/FindWidget-FJWGUnZT.js","assets/whole-word-2m2pmAFT.js","assets/copy-CGsu8426.js","assets/trash-2-WYPJMQLN.js","assets/ws-Du8jZ4aQ.js","assets/command-RRKOl81e.js","assets/search-Ct_rLLa4.js","assets/markdown-it-CWoG9_Dn.js","assets/preview-kind-CJ9RTgbs.js","assets/markdown-Dj7Cr7RL.js","assets/math-CSw6sgCC.js","assets/math-delimiters-BCnTi7Ii.js","assets/markdown-mermaid-TizVRNLQ.js","assets/ModelRefcount-CWfA9XXu.js","assets/EditorTabClose-fs9t84tp.js","assets/FileCloseScope-BS5YFuzv.js","assets/FileEditorSettingsMenu-DUpeKKAz.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{n,t as r}from"./jsx-runtime-ffCh33zF.js";import{C as i,S as a,a as o,b as s,d as c,f as l,i as u,l as d,r as f,s as p,t as m,x as h,y as g}from"./protocol-support-C2shbX3-.js";import{$ as _,B as v,Hn as y,I as b,In as x,J as S,Q as C,R as w,X as T,Z as E,d as D,en as O,et as k,fn as A,in as ee,l as j,n as M,o as N,r as P,s as F,tt as I,u as te,ut as ne,v as re,z as ie}from"./local-store-3IuC2qMo.js";import{i as ae,n as oe,o as L,r as se,s as ce,t as le}from"./LazyTerminal-DRIHw2iz.js";import{i as ue,r as de,t as fe}from"./client-settings-BdKglwtW.js";import{n as pe,r as me}from"./editor-links-DFaQQsK-.js";import{t as R}from"./preload-helper-Czpn1I53.js";import{n as he,t as ge}from"./api-BLc59FAZ.js";import{a as _e,i as ve,n as z,r as ye}from"./window-context-Euxqnh6S.js";import{n as be}from"./forward-link-Kt311XAU.js";import{$ as xe,G as Se,J as Ce,K as we,L as Te,M as Ee,O as De,Q as Oe,R as ke,S as Ae,U as je,V as Me,W as Ne,Y as Pe,Z as Fe,a as Ie,b as Le,d as Re,k as ze,l as Be,n as Ve,ot as He,q as Ue,rt as We,s as Ge,st as Ke,tt as qe,u as Je,vt as Ye,y as Xe}from"./queries-essOjrjZ.js";import{A as Ze,B as Qe,C as $e,D as et,E as tt,F as nt,G as rt,H as it,J as at,L as ot,M as st,N as ct,O as lt,T as ut,U as dt,W as ft,Y as pt,a as mt,b as ht,c as gt,j as _t,k as vt,l as yt,o as bt,q as xt,r as St,s as Ct,t as wt}from"./editor-context-CR20pm26.js";import{A as Tt,B as Et,C as Dt,D as Ot,E as kt,F as At,G as jt,H as Mt,I as Nt,J as Pt,K as Ft,L as It,M as Lt,N as Rt,O as zt,P as Bt,S as Vt,T as Ht,U as Ut,V as Wt,W as Gt,X as Kt,Y as B,_ as qt,b as Jt,c as Yt,f as Xt,i as Zt,j as Qt,k as $t,l as en,m as tn,n as nn,p as rn,q as an,r as on,v as sn,w as cn,x as ln,y as un}from"./use-desktop-state-CS5BxWes.js";import{c as dn,l as fn,r as pn,s as mn,t as hn}from"./square-terminal-CrlDquCd.js";import{t as gn}from"./motion-Bd_MB9cH.js";import{t as V}from"./utils-B6KiDbIe.js";import{a as _n,c as vn,d as yn,f as bn,g as xn,h as Sn,i as Cn,l as wn,m as Tn,n as En,o as Dn,p as On,r as kn,s as H,t as An,u as jn}from"./session-order-DsJCcSqx.js";import{a as Mn,i as Nn,o as Pn,r as Fn,s as In,t as Ln}from"./dialog-DfdBRe6G.js";import{n as U}from"./dist-DMpqv5CF.js";import{t as Rn}from"./x-CbfJFzGo.js";import{a as zn}from"./dist-CNoWjXWo.js";import{a as Bn,i as Vn,n as Hn,r as Un,t as Wn}from"./select-DHaYbZVV.js";import{i as W,n as G,t as K}from"./tooltip-CtT-5xHL.js";import{t as q}from"./button-BNH9tKwf.js";import{n as Gn,r as Kn,t as qn}from"./chevron-right-6pjfw_yV.js";import{a as Jn,n as Yn,o as Xn,r as Zn,t as Qn}from"./colour-picker-cDlTcc8M.js";import{t as $n}from"./createLucideIcon-DyMAgLa3.js";import{a as er,i as tr,n as nr,r as rr,t as ir}from"./use-arrangement-ready-CovEzBp-.js";import{A as ar,C as or,O as sr,S as cr,_ as lr,a as ur,b as dr,c as fr,d as pr,f as mr,g as hr,i as gr,j as _r,k as vr,l as yr,m as br,n as xr,o as Sr,s as Cr,t as wr,u as Tr,x as Er,y as Dr}from"./DraftRecovery-tIdw_B9k.js";import{a as Or,i as kr,n as Ar,r as jr,t as Mr}from"./switch-DZ2lisDt.js";import{n as Nr,r as Pr,t as Fr}from"./whole-word-2m2pmAFT.js";import{t as Ir}from"./chevron-down--sjpQEHH.js";import{c as Lr,f as Rr,l as zr,m as Br,o as Vr,p as Hr,r as Ur,s as Wr,t as Gr,u as Kr}from"./selection-actions-Bis7oo_z.js";import{S as qr,_ as Jr,a as Yr,b as Xr,d as Zr,f as Qr,g as $r,h as ei,i as ti,l as ni,m as ri,o as ii,p as ai,s as oi,t as si,u as ci,v as li,x as ui,y as di}from"./state-BoqmEoqv.js";import{n as fi,t as pi}from"./disclosure-oYVpfMYO.js";import{t as mi}from"./search-Ct_rLLa4.js";import{t as hi}from"./trash-2-WYPJMQLN.js";import{D as gi,S as _i,T as vi,a as yi,f as bi,k as xi,n as Si,p as Ci,s as wi,t as Ti,v as Ei,w as Di,x as Oi,y as ki}from"./project-drag-B0ojbuY7.js";import{r as Ai}from"./session-display-Bxz8xi3w.js";import{i as ji,t as Mi}from"./profile-store-BDrSK8Qs.js";import{d as Ni,h as Pi}from"./hotkeys-ChnvTHTH.js";import{i as Fi,n as Ii,r as Li,t as Ri}from"./control-tray-jUtkASPS.js";import{n as J,t as zi}from"./errors-CV02t999.js";import{t as Bi}from"./ws-Du8jZ4aQ.js";import{n as Vi,o as Y}from"./preview-kind-CJ9RTgbs.js";import{n as Hi,t as Ui}from"./content-state-BO1TLd_9.js";import{n as Wi,r as Gi}from"./view-state-store-gvFpSJG_.js";import{a as Ki,o as qi,t as Ji}from"./drafts-wug-3Dad.js";import{i as Yi}from"./buffer-logic-D9FvoilV.js";import{t as Xi}from"./scroll-restoration-Bt7-rGXy.js";import{a as Zi,i as Qi,o as $i,r as ea,s as ta,t as na}from"./FileCloseScope-BS5YFuzv.js";import{a as ra,c as ia,i as aa,l as oa,n as sa,s as ca,t as la,u as ua}from"./CompilationCommandForm-BkQcFUoa.js";import{a as da,n as fa}from"./file-links-JFyQw_0a.js";var pa=$n(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),ma=$n(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),ha=$n(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ga=$n(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),_a=$n(`eraser`,[[`path`,{d:`M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21`,key:`g5wo59`}],[`path`,{d:`m5.082 11.09 8.828 8.828`,key:`1wx5vj`}]]),va=$n(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),ya=$n(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),ba=$n(`folder-x`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}],[`path`,{d:`m9.5 10.5 5 5`,key:`ra9qjz`}],[`path`,{d:`m14.5 10.5-5 5`,key:`l2rkpq`}]]),xa=$n(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]),Sa=$n(`link-2`,[[`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`}]]),Ca=$n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),wa=$n(`message-circle-x`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Ta=$n(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),Ea=$n(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),Da=$n(`panel-right-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]),Oa=$n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),ka=$n(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),Aa=$n(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),ja=$n(`text-cursor-input`,[[`path`,{d:`M12 20h-1a2 2 0 0 1-2-2 2 2 0 0 1-2 2H6`,key:`1528k5`}],[`path`,{d:`M13 8h7a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-7`,key:`13ksps`}],[`path`,{d:`M5 16H4a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h1`,key:`1n9rhb`}],[`path`,{d:`M6 4h1a2 2 0 0 1 2 2 2 2 0 0 1 2-2h1`,key:`1mj8rg`}],[`path`,{d:`M9 6v12`,key:`velyjx`}]]),Ma=$n(`user-round-cog`,[[`path`,{d:`m14.305 19.53.923-.382`,key:`3m78fa`}],[`path`,{d:`m15.228 16.852-.923-.383`,key:`npixar`}],[`path`,{d:`m16.852 15.228-.383-.923`,key:`5xggr7`}],[`path`,{d:`m16.852 20.772-.383.924`,key:`dpfhf9`}],[`path`,{d:`m19.148 15.228.383-.923`,key:`1reyyz`}],[`path`,{d:`m19.53 21.696-.382-.924`,key:`1goivc`}],[`path`,{d:`M2 21a8 8 0 0 1 10.434-7.62`,key:`1yezr2`}],[`path`,{d:`m20.772 16.852.924-.383`,key:`htqkph`}],[`path`,{d:`m20.772 19.148.924.383`,key:`9w9pjp`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}],[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}]]),X=e(t(),1),Z=r();function Na({source:e,setSource:t,definitions:n,worktree:r,pending:i,canCopy:a,canStart:o,valid:s}){let c=n.filter(e=>`digest`in e),l=e.kind===`template`?ne.find(t=>t.id===e.template):void 0;return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(Xn,{htmlFor:`huddle-source`,children:`Start from`}),(0,Z.jsxs)(Wn,{value:e.kind===`copy`?e.id:e.kind===`template`?e.template:`blank`,disabled:i,onValueChange:e=>{if(e===`blank`)t({kind:`blank`});else{let n=o?ne.find(t=>t.id===e):void 0,i=a?c.find(t=>t.id===e):void 0;n?t({kind:`template`,template:n.id}):i&&t({kind:`copy`,id:i.id,digest:i.digest,name:i.name,worktree:r})}},children:[(0,Z.jsx)(Vn,{id:`huddle-source`,children:(0,Z.jsx)(Bn,{})}),(0,Z.jsxs)(Hn,{children:[(0,Z.jsx)(Un,{value:`blank`,children:`Blank graph`}),o&&ne.map(e=>(0,Z.jsx)(Un,{value:e.id,children:e.title},e.id)),a&&c.map(e=>(0,Z.jsxs)(Un,{value:e.id,children:[`Copy: `,e.name,` · `,e.id.slice(0,8)]},e.id)),e.kind===`copy`&&!c.some(t=>t.id===e.id)&&(0,Z.jsxs)(Un,{value:e.id,disabled:!0,children:[`Unavailable: `,e.name]})]})]}),l&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:l.description}),e.kind===`copy`&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Copies saved files only, with a new id. Review copied worktree, account and session settings before Start.`}),!s&&(0,Z.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:`The selected source changed or is unavailable. Select Blank graph, then choose the source again after reviewing its saved files.`})]})}function Pa({profile:e,project:t,repo:n,onClose:r,onOpened:a}){let[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)({kind:`blank`}),f=u.kind===`copy`?u:null,p=Le().data?.protocol,m=i(p,{major:28,minor:26}),h=i(p,{major:28,minor:27}),g=Ce(n),_=c??g.data?.worktrees.find(e=>e.is_primary)?.path??``,v=ci(),y=ii(e,!0),b=oi(e,t,_,!0),x=ni(e),S=b.data?.filter(e=>`digest`in e)??[],C=(u.kind!==`template`||h)&&(!f||m&&f.worktree===_&&S.some(e=>e.id===f.id&&e.digest===f.digest)),w=e=>{a(e),r()},T=v?y.error?.message??(y.data?.available===!1?y.data.reason:void 0):`Use a current Puddle desktop or browser over a local or SSH connection.`;return(0,Z.jsx)(Ln,{open:!0,onOpenChange:e=>{!e&&!x.isPending&&r()},children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`New huddle`}),(0,Z.jsx)(Nn,{children:m?`Choose a starting point or open a saved huddle. New graphs stay stopped.`:`Create a blank graph without running it, or open a saved huddle.`})]}),(0,Z.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),!(!_||!o.trim()||!C||!y.data?.available||x.isPending)&&x.mutate(f?{kind:`duplicate`,value:{project_id:t,worktree:_,name:o,huddle_id:f.id,expected_digest:f.digest}}:{kind:`create`,value:{project_id:t,worktree:_,name:o,...u.kind===`template`?{template:u.template}:{}}},{onSuccess:({session:e})=>w(e)})},children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(Xn,{htmlFor:`huddle-worktree`,children:`Definition worktree`}),(0,Z.jsxs)(Wn,{value:_,onValueChange:e=>{e&&(l(e),d({kind:`blank`}))},disabled:x.isPending,children:[(0,Z.jsx)(Vn,{id:`huddle-worktree`,children:(0,Z.jsx)(Bn,{placeholder:`Choose worktree`})}),(0,Z.jsx)(Hn,{children:g.data?.worktrees.map(e=>(0,Z.jsxs)(Un,{value:e.path,children:[e.branch??`Detached`,` · `,e.path]},e.path))})]})]}),(m||h)&&(0,Z.jsx)(Na,{source:u,setSource:d,definitions:b.data??[],worktree:_,pending:x.isPending,canCopy:m,canStart:h,valid:C}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsx)(Xn,{htmlFor:`huddle-name`,children:`Name`}),(0,Z.jsx)(Gn,{id:`huddle-name`,autoFocus:!0,value:o,maxLength:200,onChange:e=>s(e.target.value),disabled:x.isPending})]}),(T||g.error)&&(0,Z.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:T??g.error?.message}),y.data?.available&&y.data.lifetime===`host_session`&&(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`This host keeps runtimes alive only for the host session.`}),x.error&&(0,Z.jsxs)(`p`,{role:`alert`,className:`text-sm text-fg-muted`,children:[x.error.message,` Check saved huddles below before creating again.`]}),(0,Z.jsx)(q,{type:`submit`,disabled:!v||!y.data?.available||!_||!o.trim()||!C||x.isPending,children:f?`Copy saved huddle`:`Create huddle`})]}),(0,Z.jsxs)(`div`,{className:`flex max-h-56 flex-col gap-2 overflow-auto`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Saved huddles`}),b.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-fg-muted`,children:b.error.message}),b.data?.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`No huddles in this worktree.`}),b.data?.map(e=>`error`in e?(0,Z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[e.id,`: `,e.error]},e.id):(0,Z.jsx)(`button`,{type:`button`,disabled:x.isPending,className:`rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-elevated disabled:opacity-50`,onClick:()=>x.mutate({kind:`open`,value:{project_id:t,worktree:_,huddle_id:e.id}},{onSuccess:({session:e})=>w(e)}),children:e.name},e.id))]})]})})}var Fa=e(n(),1),Ia;function La(){let e=new Map;for(let t of document.querySelectorAll(`[data-sidebar-motion]`)){let n=t.querySelector(`.status-glyph`)??t,r=n.getBoundingClientRect();if(!r.width||!r.height)continue;let i=Math.max(0,r.left),a=Math.min(innerWidth,r.right),o=Math.max(0,r.top),s=Math.min(innerHeight,r.bottom);for(let e=n.parentElement;e;e=e.parentElement){let t=getComputedStyle(e),n=e.getBoundingClientRect();/(auto|scroll|hidden|clip)/.test(t.overflowX)&&(i=Math.max(i,n.left),a=Math.min(a,n.right)),/(auto|scroll|hidden|clip)/.test(t.overflowY)&&(o=Math.max(o,n.top),s=Math.min(s,n.bottom))}if(i>=a||o>=s)continue;let c=t.dataset.sidebarMotion;e.set(c,n)}let t=[];for(let[n,r]of e){let e=r.style.viewTransitionName,i=r.style.getPropertyValue(`view-transition-class`);r.style.viewTransitionName=`sidebar-${Array.from(n,e=>e.codePointAt(0).toString(16)).join(`-`)}`,r.style.setProperty(`view-transition-class`,`sidebar-item`),t.push(()=>{r.style.viewTransitionName=e,r.style.setProperty(`view-transition-class`,i)})}return()=>t.forEach(e=>e())}function Ra(e){if(!document.startViewTransition||gn()){e();return}if(Ia){Ia.skipTransition(),Ia.updateCallbackDone.then(()=>(0,Fa.flushSync)(e)).catch(()=>{});return}document.documentElement.classList.add(`sidebar-transition`);let t=La(),n=document.querySelector(`[data-sidebar-main]`),r=n?.getBoundingClientRect(),i,a=()=>{},o=()=>{},s=document.startViewTransition(()=>{if(t(),(0,Fa.flushSync)(e),!gn()){if(n?.isConnected&&r){let e=n.getBoundingClientRect(),t=n.parentElement,o=t.style.overflow;t.style.overflow=`visible`,a=()=>{t.style.overflow=o},i=n.animate([{width:`${r.width}px`,height:`${r.height}px`,transform:`translate(${r.x-e.x}px, ${r.y-e.y}px)`},{width:`${e.width}px`,height:`${e.height}px`,transform:`translate(0, 0)`}],{duration:280,easing:`ease-out`})}o=La()}});Ia=s;let c=new MutationObserver(()=>{gn()&&(i?.cancel(),s.skipTransition())});c.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-reduce-motion`]}),s.finished.finally(()=>{c.disconnect(),Ia===s&&(t(),o(),i?.cancel(),a(),Ia=void 0,document.documentElement.classList.remove(`sidebar-transition`))}).catch(()=>{})}async function za(e,t){try{return await e.accept(t)}catch(n){let r=await e.observe(t).catch(()=>null);if(r?.status===`committed`&&r.version)return r.version;throw n}}function Ba(e,t={}){let{id:n}=fn(),r=dn(),i=ji(),a=t.projectId??n,o=_e()?.windows?.transfers;if(!o?.focusPane||!e||!a||!i||e.type===`huddle`&&!_e()?.windows?.huddles)return;let s=n?`/project/${n}`:`/`;return()=>{(async()=>{if(await o.focusPane({profileId:i,ref:e}))return;let n=on(i);if(!n)throw Error(`Native window state is unavailable`);await n.load(async()=>(await Ve(i))?.ui_state??_.parse({})),await Xt(n,o,a,e,ve,t.paneId,s),await r(s,{replace:!0})})().catch(J)}}async function Va(e,t,n){let r=_e()?.windows?.transfers,i=on(e);if(!r||!i)throw Error(`Native pane windows are unavailable`);await en(i,r,t,n,ve)}async function Ha(e,t,n,r){let i=_e()?.windows?.transfers,a=on(e);if(!i||!a)throw Error(`Pane docking is unavailable`);await Yt(a,i,t,n,r,ve,ye)}var Ua=null;function Wa(e,t){(0,X.useEffect)(()=>{let n=z(),r=_e()?.windows?.transfers;if(!e||!t||!n?.stagingTransfer||!r||Ua===n.stagingTransfer)return;let i=on(e);if(!i?.loaded())return;let a=n.stagingTransfer;Ua=a,za(r,{id:a,profileId:e}).then(async e=>{await Zt.committed(a,e)||i.adopt(e),delete n.stagingTransfer,ve(!1)}).catch(J)},[e,t])}function Ga(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function Ka(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function qa(e){return e/100*window.innerHeight}function Ja(e){return e/100*window.innerWidth}function Ya(e){switch(typeof e){case`number`:return[e,`px`];case`string`:{let t=parseFloat(e);return e.endsWith(`%`)?[t,`%`]:e.endsWith(`px`)?[t,`px`]:e.endsWith(`rem`)?[t,`rem`]:e.endsWith(`em`)?[t,`em`]:e.endsWith(`vh`)?[t,`vh`]:e.endsWith(`vw`)?[t,`vw`]:[t,`%`]}}}function Xa({groupSize:e,panelElement:t,styleProp:n}){let r,[i,a]=Ya(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=Ka(t,i);break;case`em`:r=Ga(t,i);break;case`vh`:r=qa(i);break;case`vw`:r=Ja(i);break}return r}function Za(e){return parseFloat(e.toFixed(3))}function Qa({group:e}){let{orientation:t,panels:n}=e;return n.reduce((e,n)=>(e+=t===`horizontal`?n.element.offsetWidth:n.element.offsetHeight,e),0)}function $a(e){let{panels:t}=e,n=Qa({group:e});return n===0?t.map(e=>({groupResizeBehavior:e.panelConstraints.groupResizeBehavior,collapsedSize:0,collapsible:e.panelConstraints.collapsible===!0,defaultSize:void 0,disabled:e.panelConstraints.disabled,minSize:0,maxSize:100,panelId:e.id})):t.map(e=>{let{element:t,panelConstraints:r}=e,i=0;r.collapsedSize!==void 0&&(i=Za(Xa({groupSize:n,panelElement:t,styleProp:r.collapsedSize})/n*100));let a;r.defaultSize!==void 0&&(a=Za(Xa({groupSize:n,panelElement:t,styleProp:r.defaultSize})/n*100));let o=0;r.minSize!==void 0&&(o=Za(Xa({groupSize:n,panelElement:t,styleProp:r.minSize})/n*100));let s=100;return r.maxSize!==void 0&&(s=Za(Xa({groupSize:n,panelElement:t,styleProp:r.maxSize})/n*100)),{groupResizeBehavior:r.groupResizeBehavior,collapsedSize:i,collapsible:r.collapsible===!0,defaultSize:a,disabled:r.disabled,minSize:o,maxSize:s,panelId:e.id}})}function Q(e,t=`Assertion error`){if(!e)throw Error(t)}function eo(e,t){return Array.from(t).sort(e===`horizontal`?to:no)}function to(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function no(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function ro(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function io(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function ao({orientation:e,rects:t,targetRect:n}){let r={x:n.x+n.width/2,y:n.y+n.height/2},i,a=Number.MAX_VALUE;for(let n of t){let{x:t,y:o}=io(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return Q(i,`No rect found`),i}var oo;function so(){return oo===void 0&&(oo=typeof matchMedia==`function`&&!!matchMedia(`(pointer:coarse)`).matches),oo}function co(e){let{element:t,orientation:n,panels:r,separators:i}=e,a=eo(n,Array.from(t.children).filter(ro).map(e=>({element:e}))).map(({element:e})=>e),o=[],s=!1,c=!1,l=-1,u=-1,d=0,f,p=[];{let e=-1;for(let t of a)t.hasAttribute(`data-panel`)&&(e++,t.hasAttribute(`data-disabled`)||(d++,l===-1&&(l=e),u=e))}if(d>1){let t=-1;for(let d of a)if(d.hasAttribute(`data-panel`)){t++;let i=r.find(e=>e.element===d);if(i){if(f){let r=f.element.getBoundingClientRect(),a=d.getBoundingClientRect(),m;if(c){let e=n===`horizontal`?new DOMRect(r.right,r.top,0,r.height):new DOMRect(r.left,r.bottom,r.width,0),t=n===`horizontal`?new DOMRect(a.left,a.top,0,a.height):new DOMRect(a.left,a.top,a.width,0);switch(p.length){case 0:m=[e,t];break;case 1:{let i=p[0];m=[i,ao({orientation:n,rects:[r,a],targetRect:i.element.getBoundingClientRect()})===r?t:e];break}default:m=p;break}}else m=p.length?p:[n===`horizontal`?new DOMRect(r.right,a.top,a.left-r.right,a.height):new DOMRect(a.left,r.bottom,a.width,a.top-r.bottom)];for(let n of m){let r=`width`in n?n:n.element.getBoundingClientRect(),a=so()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(r.width<a){let e=a-r.width;r=new DOMRect(r.x-e/2,r.y,r.width+e,r.height)}if(r.height<a){let e=a-r.height;r=new DOMRect(r.x,r.y-e/2,r.width,r.height+e)}!s&&!(t<=l||t>u)&&o.push({group:e,groupSize:Qa({group:e}),panels:[f,i],separator:`width`in n?void 0:n,rect:r}),s=!1}}c=!1,f=i,p=[]}}else if(d.hasAttribute(`data-separator`)){d.ariaDisabled!==null&&(s=!0);let e=i.find(e=>e.element===d);e?p.push(e):(f=void 0,p=[])}else c=!0}return o}var lo=class{#e={};addListener(e,t){let n=this.#e[e];return n===void 0?this.#e[e]=[t]:n.includes(t)||n.push(t),()=>{this.removeListener(e,t)}}emit(e,t){let n=this.#e[e];if(n!==void 0)if(n.length===1)n[0].call(null,t);else{let e=!1,r=null,i=Array.from(n);for(let n=0;n<i.length;n++){let a=i[n];try{a.call(null,t)}catch(t){r===null&&(e=!0,r=t)}}if(e)throw r}}removeAllListeners(){this.#e={}}removeListener(e,t){let n=this.#e[e];if(n!==void 0){let e=n.indexOf(t);e>=0&&n.splice(e,1)}}},uo={cursorFlags:0,state:`inactive`},fo=new lo;function po(){return uo}function mo(e){return fo.addListener(`change`,e)}function ho(e){let t=uo,n={...uo};n.cursorFlags=e,uo=n,fo.emit(`change`,{prev:t,next:n})}function go(e){let t=uo;uo=e,fo.emit(`change`,{prev:t,next:e})}var _o=e=>e,vo=()=>{},yo=1,bo=2,xo=4,So=8,Co=3,wo=12,To;function Eo(){return To===void 0&&(To=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(To=!0)),To}function Do({cursorFlags:e,groups:t,state:n}){let r=0,i=0;switch(n){case`active`:case`hover`:t.forEach(e=>{if(!e.mutableState.disableCursor)switch(e.orientation){case`horizontal`:r++;break;case`vertical`:i++;break}})}if(!(r===0&&i===0)){switch(n){case`active`:if(e&&Eo()){let t=(e&yo)!==0,n=(e&bo)!==0,r=(e&xo)!==0,i=(e&So)!==0;if(t)return r?`se-resize`:i?`ne-resize`:`e-resize`;if(n)return r?`sw-resize`:i?`nw-resize`:`w-resize`;if(r)return`s-resize`;if(i)return`n-resize`}break}return Eo()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var Oo=new WeakMap;function ko(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=Oo.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));let r=po();switch(r.state){case`active`:case`hover`:{let e=Do({cursorFlags:r.cursorFlags,groups:r.hitRegions.map(e=>e.group),state:r.state}),i=`*, *:hover {cursor: ${e} !important; }`;if(t===i)return;t=i,e?n.cssRules.length===0?n.insertRule(i):n.replaceSync(i):n.cssRules.length===1&&n.deleteRule(0);break}case`inactive`:t=void 0,n.cssRules.length===1&&n.deleteRule(0);break}Oo.set(e,{prevStyle:t,styleSheet:n})}var Ao=new Map,jo=new lo;function Mo(e){Ao=new Map(Ao),Ao.delete(e)}function No(e,t){for(let[t]of Ao)if(t.id===e)return t}function Po(e,t){for(let[t,n]of Ao)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Fo(){return Ao}function Io(e,t){return jo.addListener(`groupChange`,n=>{n.group.id===e&&t(n)})}function Lo(e,t,n){let r=Ao.get(e);Ao=new Map(Ao),Ao.set(e,t),jo.emit(`groupChange`,{group:e,isUserInteraction:n?.isUserInteraction===!0,prev:r,next:t})}function Ro(e){let t=po(),n=!1;switch(t.state){case`active`:go({cursorFlags:0,state:`inactive`}),t.hitRegions.length>0&&(ko(e),n=!0,t.hitRegions.forEach(e=>{let t=Po(e.group.id,!0);Lo(e.group,t,{isUserInteraction:!0})}))}return n}function zo(e){e.defaultPrevented||Ro(e.currentTarget)}function Bo(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=io(n,a.rect);switch(e){case`horizontal`:t.x<=i.x&&(r=a,i=t);break;case`vertical`:t.y<=i.y&&(r=a,i=t);break}}return r?{distance:i,hitRegion:r}:void 0}function Vo(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function Ho(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:Jo(e),b:Jo(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();Q(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:qo(Ko(n.a)),b:qo(Ko(n.b))};if(i.a===i.b){let e=r.childNodes,t={a:n.a.at(-1),b:n.b.at(-1)},i=e.length;for(;i--;){let n=e[i];if(n===t.a)return 1;if(n===t.b)return-1}}return Math.sign(i.a-i.b)}var Uo=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Wo(e){let t=getComputedStyle(Yo(e)??e).display;return t===`flex`||t===`inline-flex`}function Go(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||Wo(e))||+t.opacity<1||`transform`in t&&t.transform!==`none`||`webkitTransform`in t&&t.webkitTransform!==`none`||`mixBlendMode`in t&&t.mixBlendMode!==`normal`||`filter`in t&&t.filter!==`none`||`webkitFilter`in t&&t.webkitFilter!==`none`||`isolation`in t&&t.isolation===`isolate`||Uo.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function Ko(e){let t=e.length;for(;t--;){let n=e[t];if(Q(n,`Missing node`),Go(n))return n}return null}function qo(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Jo(e){let t=[];for(;e;)t.push(e),e=Yo(e);return t}function Yo(e){let{parentNode:t}=e;return Vo(t)?t.host:t}function Xo(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Zo({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!ro(n)||n.contains(e)||e.contains(n))return!0;if(Ho(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Xo(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function Qo(e,t){let n=[];return t.forEach((t,r)=>{if(r.disabled)return;let i=co(r),a=Bo(r.orientation,i,{x:e.clientX,y:e.clientY});a&&a.distance.x<=0&&a.distance.y<=0&&Zo({groupElement:r.element,hitRegion:a.hitRegion.rect,pointerEventTarget:e.target})&&n.push(a.hitRegion)}),n}function $o(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function es(e,t,n=0){return Math.abs(Za(e)-Za(t))<=n}function ts(e,t){return es(e,t)?0:e>t?1:-1}function ns({overrideDisabledPanels:e,panelConstraints:t,prevSize:n,size:r}){let{collapsedSize:i=0,collapsible:a,disabled:o,maxSize:s=100,minSize:c=0}=t;if(o&&!e)return n;if(ts(r,c)<0)if(a){let e=(i+c)/2;r=ts(r,e)<0?i:c}else r=c;return r=Math.min(s,r),r=Za(r),r}function rs({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(es(e,0))return t;let o=a===`imperative-api`,s=Object.values(t),c=Object.values(i),l=[...s],[u,d]=r;Q(u!=null,`Invalid first pivot index`),Q(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];Q(r,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(Q(n!=null,`Previous layout not found for panel index ${t}`),es(n,i)){let t=o-n;ts(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];Q(r,`No panel constraints found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(Q(n!=null,`Previous layout not found for panel index ${t}`),es(n,o)){let t=n-i;ts(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];Q(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsible:a,collapsedSize:o,minSize:c}=r;if(a&&ts(i,c)<0)if(e>0){let t=c-o,n=t/2;ts(i+e,c)<0&&(e=ts(e,n)<=0?0:t)}else{let t=c-o,n=100-t/2;ts(i-e,c)<0&&(e=ts(100+e,n)>0?0:-t)}break}}{let t=e<0?1:-1,r=e<0?d:u,i=0;for(;;){let e=s[r];Q(e!=null,`Previous layout not found for panel index ${r}`);let a=ns({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:e,size:100})-e;if(i+=a,r+=t,r<0||r>=n.length)break}let a=Math.min(Math.abs(e),Math.abs(i));e=e<0?0-a:a}{let t=e<0?u:d;for(;t>=0&&t<n.length;){let r=Math.abs(e)-Math.abs(f),i=s[t];Q(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=ns({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:i,size:a});if(!es(i,c)&&(f+=i-c,l[t]=c,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?t--:t++}}if($o(c,l))return i;{let t=e<0?d:u,r=s[t];Q(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=ns({overrideDisabledPanels:o,panelConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!es(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];Q(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=ns({overrideDisabledPanels:o,panelConstraints:n[r],prevSize:i,size:a});if(es(i,s)||(t-=s-i,l[r]=s),es(t,0))break;e>0?r--:r++}}}if(!es(Object.values(l).reduce((e,t)=>t+e,0),100,.1))return i;let p=Object.keys(i);return l.reduce((e,t,n)=>(e[p[n]]=t,e),{})}function is(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||ts(e[n],t[n])!==0)return!1;return!0}function as({layout:e,panelConstraints:t}){let n=Object.values(e),r=[...n],i=r.reduce((e,t)=>e+t,0);if(r.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${r.map(e=>`${e}%`).join(`, `)}`);if(!es(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];Q(t!=null,`No layout data found for index ${e}`),r[e]=100/i*t}let a=0;for(let e=0;e<t.length;e++){let i=n[e];Q(i!=null,`No layout data found for index ${e}`);let o=r[e];Q(o!=null,`No layout data found for index ${e}`);let s=ns({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!es(a,0))for(let e=0;e<t.length;e++){let n=r[e];Q(n!=null,`No layout data found for index ${e}`);let i=n+a,o=ns({overrideDisabledPanels:!0,panelConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,es(a,0)))break}let o=Object.keys(e);return r.reduce((e,t,n)=>(e[o[n]]=t,e),{})}function os({groupId:e,panelId:t}){let n=()=>{let t=Fo();for(let[n,{defaultLayoutDeferred:r,derivedPanelConstraints:i,layout:a,groupSize:o,separatorToPanels:s}]of t)if(n.id===e)return{defaultLayoutDeferred:r,derivedPanelConstraints:i,group:n,groupSize:o,layout:a,separatorToPanels:s};throw Error(`Group ${e} not found`)},r=()=>{let e=n().derivedPanelConstraints.find(e=>e.panelId===t);if(e!==void 0)return e;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{let e=n().group.panels.find(e=>e.id===t);if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},a=()=>{let e=n().layout[t];if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},o=({nextSize:e,panels:n,prevLayout:r,derivedPanelConstraints:i})=>{let o=a(),s=n.findIndex(e=>e.id===t),c=s===0,l=s===n.length-1;if(l&&e<o&&(c||n.slice(0,s).every((e,t)=>{let n=i[t];return n?.collapsible&&es(n.collapsedSize,r[n.panelId])}))){let e=n.slice(0,s).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:Za(100-e)}}return rs({delta:l?o-e:e-o,initialLayout:r,panelConstraints:i,pivotIndices:l?[s-1,s]:[s,s+1],prevLayout:r,trigger:`imperative-api`})},s=e=>{if(e===a())return;let{defaultLayoutDeferred:t,derivedPanelConstraints:r,group:i,groupSize:s,layout:c,separatorToPanels:l}=n(),u=as({layout:o({nextSize:e,panels:i.panels,prevLayout:c,derivedPanelConstraints:r}),panelConstraints:r});is(c,u)||Lo(i,{defaultLayoutDeferred:t,derivedPanelConstraints:r,groupSize:s,layout:u,separatorToPanels:l})};return{collapse:()=>{let{collapsible:e,collapsedSize:t}=r(),{mutableValues:n}=i(),o=a();e&&o!==t&&(n.expandToSize=o,s(t))},expand:()=>{let{collapsible:e,collapsedSize:t,minSize:n}=r(),{mutableValues:o}=i(),c=a();if(e&&c===t){let e=o.expandToSize??n;e===0&&(e=1),s(e)}},getSize:()=>{let{group:e}=n(),t=a(),{element:r}=i();return{asPercentage:t,inPixels:e.orientation===`horizontal`?r.offsetWidth:r.offsetHeight}},isCollapsed:()=>{let{collapsible:e,collapsedSize:t}=r(),n=a();return e&&es(t,n)},resize:e=>{let{group:t}=n(),{element:r}=i(),a=Qa({group:t}),o=Za(Xa({groupSize:a,panelElement:r,styleProp:e})/a*100);s(o)}}}function ss(e){e.defaultPrevented||Qo(e,Fo()).forEach(t=>{if(t.separator&&!t.separator.disableDoubleClick){let n=t.panels.find(e=>e.panelConstraints.defaultSize!==void 0);if(n){let r=n.panelConstraints.defaultSize,i=os({groupId:t.group.id,panelId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function cs(e){let t=Fo();for(let[n]of t)if(n.separators.some(t=>t.element===e))return n;throw Error(`Could not find parent Group for separator element`)}function ls({groupId:e}){let t=()=>{let t=Fo();for(let[n,r]of t)if(n.id===e)return{group:n,...r};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){let{defaultLayoutDeferred:e,layout:n}=t();return e?{}:n},setLayout(e){let{defaultLayoutDeferred:n,derivedPanelConstraints:r,group:i,groupSize:a,layout:o,separatorToPanels:s}=t(),c=as({layout:e,panelConstraints:r});return n?o:(is(o,c)||Lo(i,{defaultLayoutDeferred:n,derivedPanelConstraints:r,groupSize:a,layout:c,separatorToPanels:s}),c)}}}function us(e,t){let n=cs(e),r=Po(n.id,!0),i=n.separators.find(t=>t.element===e);Q(i,`Matching separator not found`);let a=r.separatorToPanels.get(i);Q(a,`Matching panels not found`);let o=a.map(e=>n.panels.indexOf(e)),s=ls({groupId:n.id}).getLayout(),c=as({layout:rs({delta:t,initialLayout:s,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),panelConstraints:r.derivedPanelConstraints});is(s,c)||Lo(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels},{isUserInteraction:!0})}function ds(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=cs(t);if(!n.disabled)switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&us(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&us(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&us(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&us(t,-5);break;case`End`:e.preventDefault(),us(t,100);break;case`Enter`:{e.preventDefault();let n=cs(t),{derivedPanelConstraints:r,layout:i,separatorToPanels:a}=Po(n.id,!0),o=n.separators.find(e=>e.element===t);Q(o,`Matching separator not found`);let s=a.get(o);Q(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.panelId===c.id);if(Q(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];us(t,(l.collapsedSize===e?n.mutableState.expandedPanelSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let n=cs(t).separators.map(e=>e.element),r=Array.from(n).findIndex(t=>t===e.currentTarget);Q(r!==null,`Index not found`),n[e.shiftKey?r>0?r-1:n.length-1:r+1<n.length?r+1:0].focus({preventScroll:!0});break}case`Home`:e.preventDefault(),us(t,-100);break}}function fs(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=Fo(),n=Qo(e,t),r=new Map,i=!1;n.forEach(e=>{e.separator&&(i||(i=!0,e.separator.element.focus({focusVisible:!1,preventScroll:!0})));let n=t.get(e.group);n&&r.set(e.group,n.layout)}),go({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:`active`}),n.length&&e.preventDefault()}function ps({document:e,event:t,hitRegions:n,initialLayoutMap:r,mountedGroups:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0;n.forEach(e=>{let{group:n,groupSize:o}=e,{orientation:c,panels:l}=n,{disableCursor:u}=n.mutableState,d=0;d=a?c===`horizontal`?(t.clientX-a.x)/o*100:(t.clientY-a.y)/o*100:c===`horizontal`?t.clientX<0?-100:100:t.clientY<0?-100:100;let f=r.get(n),p=i.get(n);if(!f||!p)return;let{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:_,separatorToPanels:v}=p;if(h&&_&&v){let t=rs({delta:d,initialLayout:f,panelConstraints:h,pivotIndices:e.panels.map(e=>l.indexOf(e)),prevLayout:_,trigger:`mouse-or-touch`});if(is(t,_)){if(d!==0&&!u)switch(c){case`horizontal`:s|=d<0?yo:bo;break;case`vertical`:s|=d<0?xo:So;break}}else Lo(e.group,{defaultLayoutDeferred:m,derivedPanelConstraints:h,groupSize:g,layout:t,separatorToPanels:v})}});let c=0;t.movementX===0?c|=o&Co:c|=s&Co,t.movementY===0?c|=o&wo:c|=s&wo,ho(c),ko(e)}function ms(e){let t=Fo(),n=po();switch(n.state){case`active`:ps({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function hs(e){if(e.defaultPrevented)return;let t=po(),n=Fo();switch(t.state){case`active`:if(e.buttons===0){go({cursorFlags:0,state:`inactive`}),t.hitRegions.forEach(e=>{let t=Po(e.group.id,!0);Lo(e.group,t,{isUserInteraction:!0})});return}for(let n of t.hitRegions)if(n.separator){let{element:t}=n.separator;t.hasPointerCapture?.(e.pointerId)||t.setPointerCapture?.(e.pointerId)}ps({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break;default:{let r=Qo(e,n);r.length===0?t.state!==`inactive`&&go({cursorFlags:0,state:`inactive`}):go({cursorFlags:0,hitRegions:r,state:`hover`}),ko(e.currentTarget);break}}}function gs(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(po().state){case`hover`:go({cursorFlags:0,state:`inactive`})}}function _s(e){e.defaultPrevented||e.pointerType===`mouse`&&e.button>0||Ro(e.currentTarget)&&e.preventDefault()}function vs(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=Za(i.defaultSize);n+=e,r[i.panelId]=e}else r[i.panelId]=void 0;let i=e.length-t;if(i!==0){let t=Za((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.panelId]=t)}return r}function ys(e,t,n){if(!n[0])return;let r=e.panels.find(e=>e.element===t);if(!r||!r.onResize)return;let i=Qa({group:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:Za(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}function bs(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function xs({group:e,nextGroupSize:t,prevGroupSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,a=0,o=!1,s=new Map,c=[];for(let l of e.panels){let e=r[l.id]??0;switch(l.panelConstraints.groupResizeBehavior){case`preserve-pixel-size`:{o=!0;let r=Za(e/100*n/t*100);s.set(l.id,r),i+=r;break}default:c.push(l.id),a+=e;break}}if(!o||c.length===0)return r;let l=100-i,u={...r};if(s.forEach((e,t)=>{u[t]=e}),a>0)for(let e of c)u[e]=Za((r[e]??0)/a*l);else{let e=Za(l/c.length);for(let t of c)u[t]=e}return u}function Ss(e,t){let n=e.map(e=>e.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;return!0}var Cs=new Map;function ws(e){let t=!0;Q(e.element.ownerDocument.defaultView,`Cannot register an unmounted Group`);let n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,a=new n(n=>{for(let r of n){let{borderBoxSize:n,target:i}=r;if(i===e.element){if(t){let t=Qa({group:e});if(t===0)return;let n=Po(e.id);if(!n)return;let r=$a(e),i=n.defaultLayoutDeferred?vs(r):n.layout,a=as({layout:xs({group:e,nextGroupSize:t,prevGroupSize:n.groupSize,prevLayout:i}),panelConstraints:r});if(!n.defaultLayoutDeferred&&is(n.layout,a)&&bs(n.derivedPanelConstraints,r)&&n.groupSize===t)return;Lo(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:r,groupSize:t,layout:a,separatorToPanels:n.separatorToPanels})}}else ys(e,i,n)}});a.observe(e.element),e.panels.forEach(e=>{Q(!r.has(e.id),`Panel ids must be unique; id "${e.id}" was used more than once`),r.add(e.id),e.onResize&&a.observe(e.element)});let o=Qa({group:e}),s=$a(e),c=e.panels.map(({id:e})=>e).join(`,`),l=e.mutableState.defaultLayout;l&&(Ss(e.panels,l)||(l=void 0));let u=as({layout:e.mutableState.layouts[c]??l??vs(s),panelConstraints:s}),d=e.element.ownerDocument;Cs.set(d,(Cs.get(d)??0)+1);let f=new Map;return co(e).forEach(e=>{e.separator&&f.set(e.separator,e.panels)}),Lo(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:s,groupSize:o,layout:u,separatorToPanels:f}),e.separators.forEach(e=>{Q(!i.has(e.id),`Separator ids must be unique; id "${e.id}" was used more than once`),i.add(e.id),e.element.addEventListener(`keydown`,ds)}),Cs.get(d)===1&&(d.addEventListener(`contextmenu`,zo,!0),d.addEventListener(`dblclick`,ss,!0),d.addEventListener(`pointerdown`,fs,!0),d.addEventListener(`pointerleave`,ms),d.addEventListener(`pointermove`,hs),d.addEventListener(`pointerout`,gs),d.addEventListener(`pointerup`,_s,!0)),function(){t=!1,Cs.set(d,Math.max(0,(Cs.get(d)??0)-1)),Mo(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,ds)}),Cs.get(d)||(d.removeEventListener(`contextmenu`,zo,!0),d.removeEventListener(`dblclick`,ss,!0),d.removeEventListener(`pointerdown`,fs,!0),d.removeEventListener(`pointerleave`,ms),d.removeEventListener(`pointermove`,hs),d.removeEventListener(`pointerout`,gs),d.removeEventListener(`pointerup`,_s,!0)),a.disconnect()}}function Ts(){let[e,t]=(0,X.useState)({});return[e,(0,X.useCallback)(()=>t({}),[])]}function Es(e){let t=(0,X.useId)();return`${e??t}`}var Ds=typeof window<`u`?X.useLayoutEffect:X.useEffect;function Os(e){let t=(0,X.useRef)(e);return Ds(()=>{t.current=e},[e]),(0,X.useCallback)((...e)=>t.current?.(...e),[t])}function ks(...e){return Os(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t;break}})})}function As(e){let t=(0,X.useRef)({...e});return Ds(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var js=(0,X.createContext)(null);function Ms(e,t){let n=(0,X.useRef)({getLayout:()=>({}),setLayout:_o});(0,X.useImperativeHandle)(t,()=>n.current,[]),Ds(()=>{Object.assign(n.current,ls({groupId:e}))})}function Ns({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:a,groupRef:o,id:s,onLayoutChange:c,onLayoutChanged:l,orientation:u=`horizontal`,resizeTargetMinimumSize:d={coarse:20,fine:10},style:f,...p}){let m=(0,X.useRef)({onLayoutChange:{},onLayoutChanged:{}}),h=Os(e=>{is(m.current.onLayoutChange,e)||(m.current.onLayoutChange=e,c?.(e))}),g=Os((e,t)=>{is(m.current.onLayoutChanged,e)||(m.current.onLayoutChanged=e,l?.(e,{isUserInteraction:t}))}),_=Es(s),v=(0,X.useRef)(null),[y,b]=Ts(),x=(0,X.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),S=ks(v,a);Ms(_,o);let C=Os((e,t)=>{let r=po(),i=No(e),a=Po(e);if(a){let e=!1;switch(r.state){case`active`:e=r.hitRegions.some(e=>e.group===i);break}return{flexGrow:a.layout[t]??1,pointerEvents:e?`none`:void 0}}if(n?.[t])return{flexGrow:n?.[t]}}),w=As({defaultLayout:n,disableCursor:r}),T=(0,X.useMemo)(()=>({get disableCursor(){return!!w.disableCursor},getPanelStyles:C,id:_,orientation:u,registerPanel:e=>{let t=x.current;return t.panels=eo(u,[...t.panels,e]),b(),()=>{t.panels=t.panels.filter(t=>t!==e),b()}},registerSeparator:e=>{let t=x.current;return t.separators=eo(u,[...t.separators,e]),b(),()=>{t.separators=t.separators.filter(t=>t!==e),b()}},updatePanelProps:(e,{disabled:t})=>{let n=x.current.panels.find(t=>t.id===e);n&&(n.panelConstraints.disabled=t);let r=No(_),i=Po(_);r&&i&&Lo(r,{...i,derivedPanelConstraints:$a(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=x.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[C,_,b,u,w]),E=(0,X.useRef)(null);return Ds(()=>{let e=v.current;if(e===null)return;let t=x.current,n;if(w.defaultLayout!==void 0&&Object.keys(w.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=w.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:_,mutableState:{defaultLayout:n,disableCursor:!!w.disableCursor,expandedPanelSizes:x.current.lastExpandedPanelSizes,layouts:x.current.layouts},orientation:u,panels:t.panels,resizeTargetMinimumSize:t.resizeTargetMinimumSize,separators:t.separators};E.current=r;let a=ws(r),{defaultLayoutDeferred:o,derivedPanelConstraints:s,layout:c}=Po(r.id,!0);!o&&s.length>0&&(h(c),g(c,!1));let l=Io(_,e=>{let{defaultLayoutDeferred:t,derivedPanelConstraints:n,layout:i}=e.next;if(t||n.length===0)return;let a=r.panels.map(({id:e})=>e).join(`,`);r.mutableState.layouts[a]=i,n.forEach(t=>{if(t.collapsible){let{layout:n}=e.prev??{};if(n){let e=es(t.collapsedSize,i[t.panelId]),a=es(t.collapsedSize,n[t.panelId]);e&&!a&&(r.mutableState.expandedPanelSizes[t.panelId]=n[t.panelId])}}});let o=po().state!==`active`;h(i),o&&g(i,e.isUserInteraction)});return()=>{E.current=null,a(),l()}},[i,_,g,h,u,y,w]),(0,X.useEffect)(()=>{let e=E.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,Z.jsx)(js.Provider,{value:T,children:(0,Z.jsx)(`div`,{...p,className:t,"data-group":!0,"data-testid":_,id:_,ref:S,style:{height:`100%`,width:`100%`,overflow:`hidden`,...f,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:e})})}Ns.displayName=`Group`;function Ps(){let e=(0,X.useContext)(js);return Q(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function Fs(e,t){let{id:n}=Ps(),r=(0,X.useRef)({collapse:vo,expand:vo,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:vo});(0,X.useImperativeHandle)(t,()=>r.current,[]),Ds(()=>{Object.assign(r.current,os({groupId:n,panelId:e}))})}function Is({children:e,className:t,collapsedSize:n=`0%`,collapsible:r=!1,defaultSize:i,disabled:a,elementRef:o,groupResizeBehavior:s=`preserve-relative-size`,id:c,maxSize:l=`100%`,minSize:u=`0%`,onResize:d,panelRef:f,style:p,...m}){let h=!!c,g=Es(c),_=As({disabled:a}),v=(0,X.useRef)(null),y=ks(v,o),{getPanelStyles:b,id:x,orientation:S,registerPanel:C,updatePanelProps:w}=Ps(),T=d!==null,E=Os((e,t,n)=>{d?.(e,c,n)});Ds(()=>{let e=v.current;if(e!==null){let t={element:e,id:g,idIsStable:h,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:T?E:void 0,panelConstraints:{groupResizeBehavior:s,collapsedSize:n,collapsible:r,defaultSize:i,disabled:_.disabled,maxSize:l,minSize:u}};return C(t)}},[s,n,r,i,T,g,h,l,u,E,C,_]),(0,X.useEffect)(()=>{w(g,{disabled:a})},[a,g,w]),Fs(g,f);let D=()=>{let e=b(x,g);if(e)return JSON.stringify(e)},O=(0,X.useSyncExternalStore)(e=>Io(x,e),D,D),k;return k=O?JSON.parse(O):i===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:i},(0,Z.jsx)(`div`,{...m,"data-disabled":a||void 0,"data-panel":!0,"data-testid":g,id:g,ref:y,style:{...Ls,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...k},children:(0,Z.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...p,touchAction:S===`horizontal`?`pan-y`:`pan-x`},children:e})})}Is.displayName=`Panel`;var Ls={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function Rs({layout:e,panelConstraints:t,panelId:n,panelIndex:r}){let i,a,o=e[n],s=t.find(e=>e.panelId===n);if(s){let c=s.maxSize,l=s.collapsible?s.collapsedSize:s.minSize,u=[r,r+1];a=as({layout:rs({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=as({layout:rs({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function zs({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,style:o,...s}){let c=Es(a),l=As({disabled:n,disableDoubleClick:r}),[u,d]=(0,X.useState)({}),[f,p]=(0,X.useState)(`inactive`),[m,h]=(0,X.useState)(!1),g=(0,X.useRef)(null),_=ks(g,i),{disableCursor:v,id:y,orientation:b,registerSeparator:x,updateSeparatorProps:S}=Ps(),C=b===`horizontal`?`vertical`:`horizontal`;Ds(()=>{let e=g.current;if(e!==null){let t={disabled:l.disabled,disableDoubleClick:l.disableDoubleClick,element:e,id:c},n=x(t),r=mo(e=>{p(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===t)?e.next.state:`inactive`)}),i=Io(y,e=>{let{derivedPanelConstraints:n,layout:r,separatorToPanels:i}=e.next,a=i.get(t);if(a){let e=a[0],t=a.indexOf(e);d(Rs({layout:r,panelConstraints:n,panelId:e.id,panelIndex:t}))}});return()=>{r(),i(),n()}}},[y,c,x,l]),(0,X.useEffect)(()=>{S(c,{disabled:n,disableDoubleClick:r})},[n,r,c,S]);let w;n&&!v&&(w=`not-allowed`);let T;if(n)T=`disabled`;else switch(f){case`active`:T=`active`;break;default:T=m?`focus`:f}return(0,Z.jsx)(`div`,{...s,"aria-controls":u.valueControls,"aria-disabled":n||void 0,"aria-orientation":C,"aria-valuemax":u.valueMax,"aria-valuemin":u.valueMin,"aria-valuenow":u.valueNow,children:e,className:t,"data-separator":T,"data-testid":c,id:c,onBlur:()=>h(!1),onFocus:()=>h(!0),ref:_,role:`separator`,style:{flexBasis:`auto`,cursor:w,...o,flexGrow:0,flexShrink:0,touchAction:`none`},tabIndex:n?void 0:0})}zs.displayName=`Separator`;function Bs({separatorRef:e,vertical:t}){let[n,r]=(0,X.useState)([]);return(0,X.useEffect)(()=>{let n=e.current;if(!n)return;let i=[n.previousElementSibling,n.nextElementSibling],a=0,o=()=>{if(!(n.matches(`:hover, :focus-visible`)||n.dataset.separator===`active`)){r([]);return}let e=[];i.forEach((n,r)=>{if(!n)return;let i=n.getBoundingClientRect(),a=t?r===0?`right`:`left`:r===0?`bottom`:`top`,o=`.workspace-surface.island-outline`,s=[...n.querySelectorAll(o)];n instanceof HTMLElement&&n.matches(o)&&s.unshift(n);for(let t of s){let n=t.getBoundingClientRect();if(!n.width||!n.height||Math.abs(n[a]-i[a])>1)continue;let r=getComputedStyle(t).borderRadius;e.push({left:n.left,top:n.top,width:n.width,height:n.height,borderRadius:r,maskImage:`linear-gradient(to ${a}, transparent calc(100% - 2 * ${parseFloat(r)||0}px), black)`})}}),r(e)},s=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(o)},c=new ResizeObserver(s);i.forEach(e=>{e&&(c.observe(e),e.querySelectorAll(`.workspace-surface.island-outline`).forEach(e=>c.observe(e)))});let l=new MutationObserver(s);l.observe(n,{attributes:!0,attributeFilter:[`data-separator`]});for(let e of[`pointerenter`,`pointerleave`,`focus`,`blur`])n.addEventListener(e,s);return window.addEventListener(`resize`,s),window.addEventListener(`scroll`,s,!0),()=>{cancelAnimationFrame(a),c.disconnect(),l.disconnect();for(let e of[`pointerenter`,`pointerleave`,`focus`,`blur`])n.removeEventListener(e,s);window.removeEventListener(`resize`,s),window.removeEventListener(`scroll`,s,!0)}},[t,e]),(0,Fa.createPortal)(n.map((e,t)=>(0,Z.jsx)(`div`,{"aria-hidden":!0,className:`island-resize-edge`,style:e},t)),document.body)}function Vs({className:e}){let t=(0,X.useRef)(null);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(zs,{elementRef:t,className:e}),(0,Z.jsx)(Bs,{separatorRef:t,vertical:e===`workspace-divider-vertical`})]})}function Hs(){let e=z();if(!e)return null;let t=Mi();return t?{sourceId:e.identity.id,hostId:e.hostId,profileId:t}:null}function Us(e){let t=j.safeParse(e),n=Hs();return!!n&&t.success&&t.data.sourceId===n.sourceId&&t.data.hostId===n.hostId&&t.data.profileId===n.profileId}function Ws(e){return JSON.stringify(z()?{window:Hs(),payload:e}:e)}function Gs(e){if(e.length>4*1024*1024)return null;let t=JSON.parse(e);return z()?!t||typeof t!=`object`||!(`window`in t)||!(`payload`in t)?null:Us(t.window)?t.payload:null:t}function Ks(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function qs(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function Js(e){let t=e.split(`/`).filter(e=>e!==``);t.pop();let n=[];for(let e of t)n.push(Xs(n[n.length-1]??``,e));return n}function Ys(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n<=0?`/`:t.slice(0,n)}function Xs(e,t){return e===``?t:`${e}/${t}`}function Zs(e,t){return t===``?e:`${e.replace(/\/+$/,``)}/${t}`}function Qs(e,t){let n=e=>{let t=e.replaceAll(`\\`,`/`).replace(/\/+$/,``);return t===``?`/`:t},r=n(e),i=n(t),a=/^[A-Za-z]:($|\/)/.test(r),o=a?r.toLocaleLowerCase(`en-US`):r,s=a?i.toLocaleLowerCase(`en-US`):i;if(s===o)return``;let c=o===`/`?`/`:`${o}/`;return s.startsWith(c)?i.slice(c.length):null}function $s(e){let t=new Set(e);return e.filter(e=>{if(e===``)return!0;for(let n=qs(e);;n=qs(n)){if(t.has(n))return!1;if(n===``)return!0}})}var ec=`application/x-puddle-paths`;function tc(e){return Ws(e)}function nc(e){try{let t=Gs(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function rc(e,t){let n=[],r=(i,a)=>{let o=e(i);if(o)for(let e of o.entries){let o=Xs(i,e.name);n.push({path:o,name:e.name,type:e.type,depth:a,parentDir:i}),e.type===`dir`&&t.has(o)&&r(o,a+1)}};return r(``,0),n}function ic(e,t,n){let r=e.findIndex(e=>e.path===t),i=e.findIndex(e=>e.path===n);if(r===-1||i===-1)return n?[n]:[];let[a,o]=r<=i?[r,i]:[i,r];return e.slice(a,o+1).map(e=>e.path)}function ac(e,t){let n=e.current(),r=n.layout_tree,i=r&&t(r),a=i!==r,o=Object.fromEntries(Object.entries(n.project_layouts).map(([e,n])=>{let r=n.layout_tree?t(n.layout_tree):null;return r===n.layout_tree?[e,n]:(a=!0,[e,{...n,layout_tree:r}])}));a&&e.update({layout_tree:i,project_layouts:o})}function oc({layout:e,baseUiState:t,claimScrollDriver:n,onOpen:r}){let i=Ye(),a=ji(),o=(0,X.useRef)(a);o.current=a;let s=(0,X.useRef)(e);s.current=e;let[c,l]=(0,X.useState)(null),u=(0,X.useCallback)((e,t)=>{n(s.current.openEditorInLeaf(e,{session:t.session,path:t.path,...t.root===void 0?{kind:`file`}:{kind:`external`,root:t.root}},{dedupeAcrossTree:!0})),l({session:t.session,path:t.path,...t.root===void 0?{}:{root:t.root},line:t.line,column:t.column,nonce:Date.now()})},[n]),d=(0,X.useCallback)((e,t,i)=>{let a=s.current;n(a.focusedLeaf.id),a.openEditor(e,{preview:i?.preview}),r(),t&&[`file`,`external`].includes(e.kind??`file`)&&l({session:e.session,path:e.path,...e.root===void 0?{}:{root:e.root},line:t.line,column:t.column,nonce:Date.now()})},[n,r]),f=(0,X.useCallback)((e,t,n,r)=>d({...r?.root===void 0?{kind:`file`,session:e,path:t}:{kind:`external`,session:e,path:t,root:r.root},...r?.view?{view:r.view}:!n&&Vi(t)===`notebook`?{view:`preview`}:{}},n,r),[d]);return St(f),{openFile:f,openEditorTab:d,reveal:c,revealPreviewSource:(0,X.useCallback)((t,r,i)=>{n(e.revealSource(t,r)),l({session:r.session,path:r.path,...r.root===void 0?{}:{root:r.root},line:i.line,column:i.column,nonce:Date.now()})},[e,n]),revealCompiledSource:u,renameFileTab:(0,X.useCallback)(async(e,n)=>{let r=n.trim();if(r===``||r===Ks(e.path))return!0;let s=Xs(qs(e.path),r);try{let{rekeyBuffer:n}=await R(async()=>{let{rekeyBuffer:e}=await import(`./buffer-store-OTFEYxTw.js`).then(e=>e.n);return{rekeyBuffer:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),r=await vt(e.session,e.path,s,e.root),c=n(e.session,e.path,r.path,e.root),l=async()=>{if(c?.dirty)await qi(e.session,r.path,c.content,c.baseMtimeMs,e.root,c.baseRevision);else if(!c){let t=await Ki(e.session,e.path,e.root);t&&await qi(e.session,r.path,t.content,t.base_mtime_ms,e.root,t.baseRevision)}await Ji(e.session,e.path,e.root)};return c||await l(),o.current===a&&ac(t,t=>Ut(t,e,r.path)),i.invalidateQueries({queryKey:[`wt-tree`,e.session]}),i.invalidateQueries({queryKey:[`wt-git-status`,e.session]}),c&&setTimeout(()=>{l().catch(J)},0),!0}catch(e){return J(e),!1}},[i,t,a])}}function sc(e){if(e===null)return!1;if(Y(e)===`untitled`){let t=Er(e.path);return t===void 0?!1:(Dr({name:e.path,content:t}),!0)}return mt(Ct(e.session,e.path,e.root))}function cc(e,t,n){let r=uc(t);if(e.kind===`split`){let r=e.children.map(e=>cc(e,t,n));return r.every((t,n)=>t===e.children[n])?e:{...e,children:r}}if(!e.tabs.some(e=>B(e)===r))return e;let i={type:`editor`,tab:n};return{...e,tabs:e.tabs.map(e=>B(e)===r?i:e),activeKey:e.activeKey===r?B(i):e.activeKey,previewKey:e.previewKey===r?null:e.previewKey}}function lc(e,t){let n=uc(t);return Mt(e,e=>B(e)!==n)}function uc(e){return B({type:`editor`,tab:{kind:`untitled`,session:S,path:e}})}function dc({request:e,targetSession:t,targetRoot:n,targetLabel:r,profileId:i,onClose:a,onSaved:o}){let[s,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),p=(0,X.useRef)(!1),m=(0,X.useRef)(e);m.current=e;let h=(0,X.useRef)(!0);(0,X.useEffect)(()=>(h.current=!0,()=>{h.current=!1}),[]),(0,X.useEffect)(()=>{e&&(c(e.name),u(null))},[e]);let g=async()=>{if(!e||!t||p.current)return;let a=s.trim().replace(/^\/+/,``).replace(/\/+$/,``);if(a===``){u(`Give the file a path.`);return}p.current=!0,f(!0),u(null);try{let s=!0;try{await he(`GET`,`/api/worktrees/${t.id}/file?path=${encodeURIComponent(a)}${Ze(n)}`)}catch(e){if(e instanceof ge&&e.status===404)s=!1;else if(e instanceof ge&&e.status===413)s=!0;else throw e}if(!h.current||m.current!==e)return;if(s){u(`${a} already exists in ${r}.`);return}await he(`PUT`,`/api/worktrees/${t.id}/file?path=${encodeURIComponent(a)}${Ze(n)}`,{content:e.content}),i!==void 0&&await or(i,e.name).catch(()=>void 0),lr(e.name),o(e.name,t.id,a,n)}catch(t){h.current&&m.current===e&&u(t instanceof Error?t.message:`Save failed`)}finally{p.current=!1,h.current&&f(!1)}};return(0,Z.jsx)(Ln,{open:e!==null,onOpenChange:e=>!e&&a(),children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Save draft into the worktree`}),(0,Z.jsx)(Nn,{children:t?(0,Z.jsxs)(Z.Fragment,{children:[`Saves into `,(0,Z.jsx)(`span`,{className:`text-fg-secondary`,children:r}),` — what the sidebar is bound to.`]}):`No worktree is bound — open or focus a session first.`})]}),(0,Z.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),g()},children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(Xn,{htmlFor:`untitled-path`,children:`Worktree-relative path`}),(0,Z.jsx)(Gn,{id:`untitled-path`,placeholder:`docs/notes.md`,value:s,onChange:e=>c(e.target.value),autoFocus:!0})]}),l&&(0,Z.jsx)(`p`,{className:`text-xs text-danger`,children:l}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{type:`button`,variant:`ghost`,onClick:a,children:`Cancel`}),(0,Z.jsx)(q,{type:`submit`,disabled:d||!t,children:`Save`})]})]})]})})}function fc({baseUiState:e,scopeKey:t,projectId:n,targetSession:r,targetRoot:i,openEditorTab:o}){let s=ji(),c=Le().data?.protocol,l=Ye(),u=Pi(`editor.save`),d=`${s}:${n}:${t}`,f=(0,X.useRef)({identity:d,token:{}});f.current.identity!==d&&(f.current={identity:d,token:{}});let p=(0,X.useRef)(s);p.current=s;let m=(0,X.useRef)(!0);(0,X.useEffect)(()=>(m.current=!0,()=>{m.current=!1}),[]);let h=(0,X.useCallback)(async()=>{if(s===null)return;if(!a(c)){U.error(`Untitled drafts need a newer daemon — refresh the connection to update it`);return}let e=f.current.token;try{let{name:t}=await cr(s);if(!m.current||f.current.token!==e){await or(s,t);return}o({kind:`untitled`,session:S,path:t})}catch(e){J(e)}},[s,c,o]),[g,_]=(0,X.useState)(null);(0,X.useEffect)(()=>(dr(e=>_({request:e,session:r,root:i,profileId:s})),()=>dr(null)),[r,i,s]);let{review:v,pending:y}=ea(d),[b,x]=(0,X.useState)(!1),C=(0,X.useRef)(!1),w=(0,X.useCallback)((e,t,n)=>t.type!==`editor`||!s||C.current?Promise.resolve(!1):v.request(t.tab.path,{name:t.tab.path,profileId:s},n),[s,v]),T=async()=>{let t=y;if(!t||v.get()!==t||C.current)return;C.current=!0,x(!0);let{profileId:n,name:r}=t.value;try{if(await hr(n,r),!m.current||v.get()!==t||p.current!==n||(await or(n,r),!m.current||v.get()!==t||p.current!==n))return;Ui(n).discardBuffer({session:S,path:r}),lr(r),v.finish(t,!0),ac(e,e=>lc(e,r))}catch(e){J(e)}finally{C.current=!1,x(!1)}};return{create:h,requestDiscard:w,dialogs:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(dc,{request:g?.request??null,targetSession:g?.session??null,targetRoot:g?.root,targetLabel:g?.root??g?.session?.branch??``,profileId:g?.profileId??void 0,onClose:()=>_(null),onSaved:(t,n,r,i)=>{let a=g;if(_(e=>e===a?null:e),l.invalidateQueries({queryKey:[`wt-tree`,n]}),!m.current||p.current!==a?.profileId)return;let o=i===void 0?{kind:`file`,session:n,path:r}:{kind:`external`,session:n,path:r,root:i};ac(e,e=>cc(e,t,o))}}),(0,Z.jsx)(Ln,{open:y!==null,onOpenChange:e=>!e&&v.cancel(),children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Discard this draft?`}),(0,Z.jsxs)(Nn,{children:[`Closing `,y?.value.name,` deletes its draft — `,u,` saves it into the worktree instead.`]})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:v.cancel,disabled:b,children:`Keep editing`}),(0,Z.jsx)(q,{variant:`danger`,onClick:()=>void T(),disabled:b,children:`Discard`})]})]})})]})}}function pc(e){return JSON.stringify([`orphaned-draft`,Hi(e)])}function mc(e,t,n){ac(e,e=>zt(e,t,B(n)))}function hc(e){let t=ta(),n=(0,X.useRef)(t);n.current=t,(0,X.useEffect)(()=>{if(!e||z()?.identity.kind!==`pane`)return;let t=on(e),r=t?.subscribe(()=>{t.locked()&&rn()}),i=tn(async r=>{if(!t?.loaded()||t.locked())throw Error(`This pane is not ready to close`);let i=Ui(e);for(;!r.aborted&&!t.locked();){let e=t.get(),a={snapshot:e,...i.capture(e)},o=N(a),s=F(a)[0],c=o.targets[0];if(!c&&!s)break;if(!await n.current(s?pc(s):Zi(c.paneId,B(c.ref)),r,!0)||r.aborted||t.locked())return;await new Promise(e=>requestAnimationFrame(()=>e()))}if(!r.aborted&&!t.locked()){let e=_e()?.windows?.lifecycle?.closeReviewedPane;if(!e)throw Error(`This desktop shell cannot complete pane close review`);await e()}});return()=>{r?.(),i()}},[e])}function gc(e,t){return t??e.root??e.session?.worktree_path??null}function _c(e,t){return{...e,unpin(){t(),e.unpin()}}}function vc(e){return{id:S,project_id:e.projectId,account_id:null,worktree_path:e.path,base_branch:e.defaultBranch,branch:e.defaultBranch,separate_branch:!1,kind:`terminal`,agent_type:null,agent_session_ref:null,title:e.name,status:`exited`,skip_permissions:!1,created_at:`1970-01-01T00:00:00.000Z`,updated_at:`1970-01-01T00:00:00.000Z`,last_activity_at:null}}function yc(e,t,n,r=null){let i=n.snapshot.explorer_pin,a=i===null?null:e.find(e=>e.id===i&&e.status!==`archived`)??null,o=a??e.find(e=>e.id===t)??null,s=o===null&&r!==null;return{session:s?vc(r):o,root:s?r.path:void 0,isProjectDirectory:s,pinned:a!==null,pin(e){n.update({explorer_pin:e})},unpin(){n.update({explorer_pin:null})}}}function bc(e,t,n){let r=Zs(e.root??t,e.path);if(n!==null){let e=Qs(n,r);if(e!==null)return{directory:n,path:e}}if(e.root===void 0)return{directory:t,path:e.path};let i=Zs(e.root,qs(e.path));return{directory:i,path:Ks(e.path),browseRoot:i}}var xc=null,Sc=new Set;function Cc(e){xc=e,Sc.forEach(t=>t(e))}function wc(e){return Sc.add(e),xc&&e(xc),()=>Sc.delete(e)}function Tc(){xc=null}function Ec({uiState:e,sidebarTarget:t,tabSessions:n,openFile:r,scopeKey:i,isNarrow:a,showNavigator:o}){let s=t.session,c=t.root,l=`${i}:${s?.id}:${c}`,u=(0,X.useRef)({identity:l,token:{}});u.current.identity!==l&&(u.current={identity:l,token:{}});let d=(0,X.useRef)(!0);(0,X.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]);let[f,p]=(0,X.useState)(null),m=(0,X.useRef)(null),[h,g]=(0,X.useState)(null),_=(0,X.useCallback)(e=>{m.current=e,g(e)},[]),v=(0,X.useCallback)(r=>{let i=n.find(e=>e.id===r.session);if(r.root===void 0&&!i)return;let l=m.current??c??s?.worktree_path??null,u=bc(r,i?.worktree_path??r.root??``,l);if(a&&o(),e.update({sidebar_mode:`files`,...a?{}:{sidebar_collapsed:!1}}),u.browseRoot!==void 0){let e=i?.id??s?.id??r.session;p({session:e,root:u.browseRoot,nonce:Date.now()})}else l!==u.directory&&t.pin(r.session);Cc({path:u.path,directory:u.directory})},[t,n,c,s,e,a,o]),y=(0,X.useCallback)((t,n)=>{if(n.kind===`dir`){a&&o(),e.update({sidebar_mode:`files`,...a?{}:{sidebar_collapsed:!1}}),p({session:t,root:n.path,nonce:Date.now()});return}let i=fa(n,c);i!==null&&p({session:t,root:i,nonce:Date.now()}),r(t,n.path,n.line===void 0?void 0:{line:n.line,column:n.column},n.root===void 0?void 0:{root:n.root})},[r,e,c,a,o]),b=s?.id??null,x=(0,X.useCallback)(async t=>{if(b===null)throw Error(`No worktree is available for this project.`);let n=u.current.token,r=await da(b,t,{root:c});if(!d.current||u.current.token!==n)return;let i=r.kind===`file`&&r.root===void 0&&c!==void 0?{...r,root:c}:r;if(i.kind===`dir`&&i.relativePath!==void 0){a&&o(),e.update({sidebar_mode:`files`,...a?{}:{sidebar_collapsed:!1}}),Cc({path:i.relativePath,root:c,expandTarget:!0});return}y(b,i)},[b,c,y,e,a,o]);return(0,X.useEffect)(()=>Di(x),[x]),{browseRequest:f,filetreeRoot:h,rememberFiletreeRoot:_,revealFileTab:v,openFromTerminal:y}}function Dc(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n>0?t.slice(n+1).toLowerCase():null}function Oc(e,t){let n=Dc(e);return n!==null&&t.has(n)}function kc(e,t,n){return`${e}\0${n??``}\0${t}`}function Ac(e,t){let n=jc(t);yt(n.source?kc(n.source.session,n.source.path,n.source.root):e,n.diagnostics??[]);let r=Mc(n);return U.error(n.message,{id:`err:${n.message}`,duration:2e4,...r?{description:(0,Z.jsx)(pi,{summary:(n.diagnostics?.length?`${n.diagnostics.length} source diagnostic${n.diagnostics.length===1?``:`s`} · `:``)+`Show compiler output`,children:(0,Z.jsx)(`pre`,{className:`mt-2 max-h-52 overflow-auto whitespace-pre-wrap break-words font-mono text-2xs leading-snug text-fg-secondary`,children:r})})}:{}}),n}function jc(e){let t=I.safeParse(e);if(t.success)return t.data;if(e instanceof ge){let t=k.safeParse(e.details);return t.success?{message:e.message,...t.data}:{message:e.message}}return{message:e instanceof Error&&e.message.trim()!==``?e.message:typeof e==`string`&&e.trim()!==``?e:`Compilation failed`}}function Mc(e){return e.output?.trim()?e.output.trim():(e.diagnostics??[]).map(e=>`${e.source.path}:${e.line}${e.column?`:${e.column}`:``}: ${e.message}`).join(`
3
+ `)}function Nc({target:e,sourceKey:t,leafId:n,onResult:r,onError:i,onRunningChange:a,inputExtensions:o=[]}){let[s,c]=(0,X.useState)(!1),l=Ye(),u=(0,X.useRef)({leafId:n,onResult:r,onError:i,onRunningChange:a});u.current={leafId:n,onResult:r,onError:i,onRunningChange:a};let d=(0,X.useRef)(null),f=(0,X.useRef)(!1),p=(0,X.useRef)(-1),m=(0,X.useRef)(-1),h=(0,X.useSyncExternalStore)($e,()=>ht(e.source,o)),g=(0,X.useMemo)(()=>({source:{session:e.source.session,path:e.source.path,...e.source.root===void 0?{}:{root:e.source.root}},...e.provider===void 0?{}:{provider:e.provider},...e.profile_id===void 0?{}:{profile_id:e.profile_id},...e.project_id===void 0?{}:{project_id:e.project_id}}),[e.provider,e.profile_id,e.project_id,e.source.session,e.source.path,e.source.root]);(0,X.useEffect)(()=>{if(h){c(!1);return}let e=!1,n=!1,r=[`compilation-status`,g],i=()=>{e||n||(n=!0,c(!1),f.current=!1,p.current=-1,m.current=-1,u.current.onRunningChange(t,!0),l.cancelQueries({queryKey:r,exact:!0}).then(async()=>{if(!e)try{let n=await sa({...g,mode:`eager`});if(e)return;if(l.setQueryData(r,n),f.current=n.mode===`eager`,u.current.onRunningChange(t,n.state===`running`),n.result&&n.result.revision>p.current){p.current=n.result.revision;let e=u.current;e.onResult(t,e.leafId,n.result)}}catch(n){if(e)return;u.current.onRunningChange(t,!1),l.removeQueries({queryKey:r,exact:!0}),u.current.onError(t,jc(n))}finally{n=!1,e||c(!0)}}))};return d.current=i,i(),()=>{e=!0,d.current=null,u.current.onRunningChange(t,!1),sa({...g,mode:`on_demand`}).catch(()=>void 0)}},[g,t,l,h]);let _=ia(g,s).data;return(0,X.useEffect)(()=>{if(!(h||!s||!_)){if(_.mode===`eager`&&(f.current=!0),f.current&&_.mode===`on_demand`&&_.state===`idle`&&_.revision===0){d.current?.();return}a(t,_.state===`running`),_.result&&_.result.revision>p.current&&(p.current=_.result.revision,r(t,n,_.result)),_.state===`failed`&&_.error&&_.revision>m.current&&(m.current=_.revision,i(t,_.error))}},[h,s,_,t,n,r,i,a]),null}function Pc({request:e,onOpenChange:t}){let n=ca(e),r=Ye();return(0,Z.jsx)(Ln,{open:e!==null,onOpenChange:t,children:(0,Z.jsxs)(Fn,{className:`max-w-xl`,children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsxs)(In,{children:[n.data?.display_name??`Compilation`,` settings`]}),(0,Z.jsxs)(Nn,{children:[e?Ks(e.source.path):`This file`,` · overrides the language defaults for this file in this project.`]})]}),n.isLoading?(0,Z.jsx)(`p`,{className:`py-4 text-sm text-fg-muted`,children:`Loading commands…`}):n.isError?(0,Z.jsx)(`p`,{role:`alert`,className:`py-4 text-sm text-danger`,children:n.error instanceof Error?n.error.message:`Couldn’t load commands`}):n.data&&e?(0,Z.jsx)(la,{settings:n.data,onCancel:()=>t(!1),onSave:async n=>{for(let t of n){let n=await aa({...e,...t});r.setQueryData([`compilation-settings`,e],n)}t(!1)}},JSON.stringify(e)):null]})})}function Fc({layout:e,scopeKey:t,projectId:n,profileId:r,sessions:i,protocol:a}){let o=Ye(),s=dn(),c=(0,X.useRef)(e);c.current=e;let l=`${r??``}:${t}`,d=(0,X.useRef)({scope:l,projectId:n,epoch:0});(d.current.scope!==l||d.current.projectId!==n)&&(d.current={scope:l,projectId:n,epoch:d.current.epoch+1});let p=(0,X.useRef)(!0);(0,X.useEffect)(()=>(p.current=!0,()=>{p.current=!1,d.current.epoch++}),[]);let m=(0,X.useRef)(!1),h=(0,X.useRef)(new Map),g=ra(u(a)),_=f(a),v=oa(),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(()=>new Set),T=(0,X.useMemo)(()=>{let e=new Set(C);return x&&e.add(x),e},[C,x]),E=(0,X.useMemo)(()=>g.data?.providers.filter(e=>e.available)??[],[g.data]),D=(0,X.useMemo)(()=>new Set(E.flatMap(e=>e.extensions.map(e=>e.toLowerCase()))),[E]),O=(0,X.useCallback)(e=>{let t=Dc(e.path);return t===null?void 0:E.find(e=>e.extensions.includes(t))},[E]),k=(0,X.useCallback)(e=>O(e)?.id,[O]),A=(0,X.useCallback)(e=>r===void 0?null:{profile_id:r,project_id:i.find(t=>t.id===e)?.project_id??n},[r,n,i]),ee=(0,X.useCallback)(e=>{let t=k(e),n=A(e.session);return{source:{session:e.session,path:e.path,...e.root===void 0?{}:{root:e.root}},...t===void 0?{}:{provider:t},...n??{}}},[A,k]),j=(0,X.useCallback)(e=>{if(!_||r===void 0)return;let t=Dc(e.path),n=t===null?void 0:E.find(e=>e.extensions.includes(t)),i=A(e.session);!n||!i||b({source:e,provider:n.id,...i})},[E,_,A,r]),M=(0,X.useCallback)((e,t,n)=>{if(!p.current||d.current.scope!==l||!Lt(c.current.tree,e))return;let r=t.artifacts.find(e=>e.role===`preview`);r&&(xr(r.file.session,r.file.path,r.file.root),o.invalidateQueries({queryKey:r.file.root===void 0?[`wt-file`,r.file.session,r.file.path]:[`wt-file`,r.file.session,r.file.path,r.file.root],exact:!0}),c.current.openEditorInLeaf(e,{session:r.file.session,path:r.file.path,...r.file.root===void 0?{kind:`file`}:{kind:`external`,root:r.file.root},generated_by:t.provider,...Vi(r.file.path)?{view:`preview`}:{}},{dedupeAcrossTree:!0,activate:n}))},[o,l]),N=(0,X.useCallback)(async(e,t,n=!1)=>{if(!n&&t.path.toLowerCase().endsWith(`.ipynb`)&&br({session:t.session,path:t.path,...t.root?{root:t.root}:{}})||m.current)return;let r=ee(t),i=O(t);if(!i)return;let a=kc(t.session,t.path,t.root);m.current=!0;let l=d.current.epoch,u=()=>p.current&&l===d.current.epoch;S(a);try{let n=await bt(r.source,new Set(i.input_extensions));if(!u())return;if(!n){U.error(`Run cancelled because an input could not be saved`);return}if((t.compile_mode??`on_demand`)===`eager`&&(c.current.setCompileMode(t,`on_demand`),await sa({...r,mode:`on_demand`})),!u())return;let a=await v.mutateAsync(r);if(!u())return;if(gt(kc(a.source.session,a.source.path,a.source.root)),a.terminal){if(await o.invalidateQueries({queryKey:[`sessions`]}),!u())return;o.invalidateQueries({queryKey:[`project`,a.terminal.project_id]}),c.current.ensureSession(a.terminal),s(`/project/${a.terminal.project_id}/session/${a.terminal.id}`);return}M(e,a,!0),U.success(`${i.action===`run`?`Ran`:`Compiled`} ${Ks(a.source.path)}`)}catch(e){u()&&Ac(a,e)}finally{m.current=!1,p.current&&S(null)}},[O,ee,M,v,o,s]),P=(0,X.useCallback)(async(e,t)=>{let n=e.compile_mode??`on_demand`;if(n===t)return;let r=O(e);if(!r||t===`eager`&&!r.eager)return;let i=ee(e),a=kc(e.session,e.path,e.root),o=Symbol(),s=d.current.epoch;h.current.set(a,o);let l=()=>p.current&&s===d.current.epoch&&h.current.get(a)===o,u=!1;try{if(t===`eager`&&!await bt(i.source,new Set(r.input_extensions))){l()&&U.error(`Eager compilation was not enabled because an input could not be saved`);return}if(!l())return;c.current.setCompileMode(e,t),u=!0,t===`on_demand`&&await sa({...i,mode:t})}catch(t){if(!l())return;u&&c.current.setCompileMode(e,n),J(t)}finally{h.current.get(a)===o&&h.current.delete(a)}},[O,ee]),F=(0,X.useMemo)(()=>{let t=new Map;for(let n of Ht(e.tree))for(let e of n.tabs){if(e.type!==`editor`||e.tab.compile_mode!==`eager`||!k(e.tab)||!O(e.tab)?.eager)continue;let r=kc(e.tab.session,e.tab.path,e.tab.root);t.has(r)||t.set(r,{leafId:n.id,target:ee(e.tab)})}return[...t.entries()].map(([e,t])=>({key:e,...t}))},[e.tree,ee,k,O]),I=(0,X.useCallback)((e,t,n)=>{gt(kc(n.source.session,n.source.path,n.source.root)),M(t,n,!1)},[M]),te=(0,X.useCallback)((e,t)=>Ac(e,t),[]),ne=(0,X.useCallback)((e,t)=>{w(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]);return{providers:E,extensions:D,runningKeys:T,run:N,setMode:P,openSettings:_?j:void 0,watchers:F.map(({key:e,leafId:t,target:n})=>(0,Z.jsx)(Nc,{sourceKey:e,leafId:t,target:n,inputExtensions:E.find(e=>e.id===n.provider)?.input_extensions,onResult:I,onError:te,onRunningChange:ne},e)),settingsDialog:(0,Z.jsx)(Pc,{request:y,onOpenChange:e=>!e&&b(null)})}}var Ic=(0,X.lazy)(()=>R(()=>import(`./HuddlePane-CFYGRv0M.js`).then(e=>({default:e.HuddlePane})),__vite__mapDeps([11,1,5,12,13,14,15,16,17,18,19,20,7,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,2,3,41,42,43,44,45,4,6,8,9,46,47,48,49,50,51,10,0,52,53,54,55,56,57,58,59])));function Lc({session:e,focused:t=!0}){return(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`p`,{className:`p-4 text-sm text-fg-muted`,children:`Loading huddle…`}),children:(0,Z.jsx)(Ic,{session:e,focused:t})})}var Rc=(0,X.createContext)(null);function zc({tree:e,parked:t=[],onOpenFile:n,children:r}){let i=(0,X.useRef)(null),a=(0,X.useRef)(new Map).current,[o,s]=(0,X.useState)(()=>new Set),c=(0,X.useCallback)((e,t)=>{s(n=>{if(n.has(e)===t)return n;let r=new Set(n);return t?r.add(e):r.delete(e),r})},[]),l=[...t].sort().join(`,`),u=(0,X.useMemo)(()=>{let t=new Set;for(let n of Ht(e))for(let e of n.tabs)e.type===`terminal`&&t.add(e.session);for(let e of l===``?[]:l.split(`,`))t.add(e);return[...t].sort()},[e,l]),d=e=>{let t=`term:${e}`,n=a.get(t);return n||(n=document.createElement(`div`),n.className=`size-full`,a.set(t,n)),n};(0,X.useEffect)(()=>{let e=new Set(u.map(e=>`term:${e}`));for(let e of u){let t=a.get(`term:${e}`);t&&!t.parentElement&&i.current?.appendChild(t)}for(let[t,n]of[...a])e.has(t)||(n.remove(),a.delete(t))},[u,a]);let f=(0,X.useMemo)(()=>({parkingRef:i,containers:a,setAdopted:c}),[a,c]);return(0,Z.jsxs)(Rc.Provider,{value:f,children:[(0,Z.jsx)(`div`,{ref:i,className:`hidden`,"aria-hidden":!0}),u.map(e=>(0,Fa.createPortal)((0,Z.jsx)(le,{stream:e,paused:!o.has(`term:${e}`),onOpenFile:t=>n(e,t)}),d(e),e)),r]})}function Bc(e){let t=(0,X.useContext)(Rc),n=(0,X.useRef)(null);return(0,X.useEffect)(()=>{let r=n.current;if(!t||!e||!r)return;let i=t.containers.get(e);return i&&(r.appendChild(i),t.setAdopted(e,!0)),()=>{let n=t.parkingRef.current;i&&n&&i.parentElement===r&&n.appendChild(i),i&&t.setAdopted(e,!1)}},[t,e]),n}function Vc({session:e,term:t,ready:n,insertTarget:r}){let i=(0,X.useRef)(null),a=(0,X.useRef)(null),[o,s]=(0,X.useState)(null),c=o!==null;(0,X.useEffect)(()=>()=>a.current?.abort(),[e,t,n]);let l=o?.stage===`uploading`?Math.floor(o.received/o.total*100):void 0,u=o?.stage===`uploading`?`${l}%`:o?.stage===`saving`?`Saving…`:o?.stage===`inserting`?`Inserting…`:`Preparing…`,d=async i=>{if(!n||a.current)return;let o=new AbortController;a.current=o;let c=r?.();s({stage:`preparing`});try{let{resized:n}=await Rr(i,e,t,{signal:o.signal,onProgress:s,insert:c});n&&U(`Image resized for remote access`)}catch(e){o.signal.aborted||U.error(e instanceof Error?e.message:`Could not insert the image.`)}finally{a.current=null,s(null)}};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`input`,{ref:i,className:`hidden`,type:`file`,accept:Hr,"aria-label":`Choose image`,disabled:!n||c,onChange:e=>{let t=e.currentTarget.files?.[0];e.currentTarget.value=``,t&&d(t)}}),(0,Z.jsx)(q,{variant:`ghost`,"aria-label":c?`Cancel image upload`:`Insert image`,title:c?`Cancel image upload`:`Insert image`,"aria-busy":c,disabled:!n||o?.stage===`inserting`,onClick:()=>c?a.current?.abort():i.current?.click(),children:c?(0,Z.jsxs)(Z.Fragment,{children:[o.stage===`inserting`?(0,Z.jsx)(Ca,{className:`animate-spin`}):(0,Z.jsx)(Rn,{}),(0,Z.jsx)(`span`,{role:`progressbar`,"aria-label":`Image upload`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":l,"aria-valuetext":u,className:`text-xs`,children:u})]}):(0,Z.jsx)(xa,{})})]})}function Hc({activate:e,...t}){let n=(0,X.useRef)(null),r=(0,X.useRef)(-1/0);return(0,Z.jsx)(q,{...t,"data-terminal-key":``,onPointerDown:e=>{e.preventDefault(),e.pointerType!==`touch`&&(r.current=-1/0)},onTouchStart:e=>{let t=e.touches[0];n.current=t&&e.touches.length===1?{x:t.clientX,y:t.clientY,moved:!1}:null},onTouchMove:e=>{let t=e.touches[0];n.current&&(!t||e.touches.length!==1||Math.hypot(t.clientX-n.current.x,t.clientY-n.current.y)>8)&&(n.current.moved=!0)},onTouchCancel:()=>{n.current=null},onTouchEnd:i=>{let a=n.current;n.current=null,!(!a||a.moved||t.disabled)&&(i.preventDefault(),r.current=performance.now(),e())},onClick:t=>{t.detail!==0&&performance.now()-r.current<700||e()}})}function Uc(e){return t=>{t.target.closest(`button:not([data-terminal-key])`)||(t.cancelable&&t.preventDefault(),e())}}function Wc({session:e,term:t,connected:n,composing:r,toggleComposer:i,insertTarget:a}){let o=Lr(e,t)&&n,s=zr(e,t),[c,l]=(0,X.useState)(``),u=n=>{Ur(e,t),Vr(e,t,n).catch(e=>l(e.message))};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`phone-keys`,role:`toolbar`,"aria-label":`Terminal keys`,onTouchEnd:Uc(()=>Ur(e,t)),children:[(0,Z.jsx)(Vc,{session:e,term:t,ready:o,insertTarget:a}),(0,Z.jsx)(Hc,{variant:`ghost`,disabled:!o,activate:()=>u(`\x1B`),children:`Esc`}),[[`Control`,`⌃`,Kr.ctrl],[`Option`,`⌥`,Kr.alt],[`Shift`,`⇧`,Kr.shift]].map(([n,r,i])=>(0,Z.jsx)(Hc,{variant:`ghost`,disabled:!o,"aria-label":n,title:n,"aria-pressed":(s&i)!==0,activate:()=>{Wr(e,t,i),Ur(e,t)},children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:r})},i)),[{label:`Left`,icon:pa,data:`\x1B[D`},{label:`Down`,icon:_r,data:`\x1B[B`},{label:`Up`,icon:ar,data:`\x1B[A`},{label:`Right`,icon:ha,data:`\x1B[C`}].map(({label:e,icon:t,data:n})=>(0,Z.jsx)(Hc,{variant:`ghost`,"aria-label":e,disabled:!o,activate:()=>u(n),children:(0,Z.jsx)(t,{})},e)),(0,Z.jsx)(Hc,{variant:`ghost`,disabled:!o,activate:()=>u(` `),children:`Tab`}),(0,Z.jsx)(Hc,{variant:`ghost`,disabled:!o,activate:()=>u(`\r`),children:`Enter`}),(0,Z.jsx)(Hc,{variant:`ghost`,disabled:!o,activate:()=>u(``),children:`Ctrl-C`}),(0,Z.jsx)(q,{variant:`ghost`,"aria-label":`Compose prompt`,"aria-pressed":r,onClick:i,children:(0,Z.jsx)(ja,{})})]}),c&&(0,Z.jsx)(`p`,{role:`alert`,className:`px-2 text-xs text-danger`,children:c})]})}function Gc({session:e,term:t,connected:n,compact:r=!1}){let i=Lr(e,t)&&n,a=M(`puddle.phone.draft:${e}:${t}`),[o,s]=(0,X.useState)(()=>{try{return sessionStorage.getItem(a)??``}catch{return``}}),c=(0,X.useRef)(o),l=(0,X.useRef)(null),u=(0,X.useRef)(`terminal`);(0,X.useEffect)(()=>{let e=e=>{e.target.classList?.contains(`xterm-helper-textarea`)&&(u.current=`terminal`)};return document.addEventListener(`focusin`,e),()=>document.removeEventListener(`focusin`,e)},[]);let[d,f]=(0,X.useState)(!r||!!o),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(``),_=e=>{c.current=e,s(e);try{e?sessionStorage.setItem(a,e):sessionStorage.removeItem(a)}catch{}},v=e=>{let t=c.current,n=t.slice(0,l.current?.selectionStart??t.length),r=t.slice(l.current?.selectionEnd??t.length);/\S$/.test(n)&&(n+=` `),/^\s/.test(r)&&(e=e.trimEnd()),_(n+e+r);let i=n.length+e.length;requestAnimationFrame(()=>l.current?.setSelectionRange(i,i))},y=async(n,r=!1)=>{if(!(!i||p)){m(!0),g(``);try{await Vr(e,t,n,r),r&&_(``)}catch(e){g(e instanceof Error?e.message:`Delivery is uncertain. Check the terminal before resending.`)}finally{m(!1)}}};return(0,Z.jsxs)(`div`,{className:`phone-composer`,children:[(0,Z.jsx)(Wc,{session:e,term:t,connected:n,composing:d,toggleComposer:()=>f(!d),insertTarget:()=>d&&u.current===`prompt`?v:void 0}),d&&(0,Z.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),o&&y(o,!0)},children:[(0,Z.jsx)(Kn,{ref:l,onFocus:()=>u.current=`prompt`,className:`text-base`,"aria-label":`Prompt`,rows:2,value:o,onChange:e=>_(e.target.value),placeholder:`Write a prompt…`,autoCapitalize:`sentences`,autoCorrect:`on`,spellCheck:!0}),(0,Z.jsx)(q,{type:`submit`,disabled:!i||p||!o,children:p?`Sending…`:`Send`})]}),h&&(0,Z.jsx)(`p`,{role:`alert`,children:h})]})}var Kc=class{diff(e,t,n={}){let r;typeof n==`function`?(r=n,n={}):`callback`in n&&(r=n.callback);let i=this.castInput(e,n),a=this.castInput(t,n),o=this.removeEmpty(this.tokenize(i,n)),s=this.removeEmpty(this.tokenize(a,n));return this.diffWithOptionsObj(o,s,n,r)}diffWithOptionsObj(e,t,n,r){let i=e=>{if(e=this.postProcess(e,n),r){setTimeout(function(){r(e)},0);return}else return e},a=t.length,o=e.length,s=1,c=a+o;n.maxEditLength!=null&&(c=Math.min(c,n.maxEditLength));let l=n.timeout??1/0,u=Date.now()+l,d=[{oldPos:-1,lastComponent:void 0}],f=this.extractCommon(d[0],t,e,0,n);if(d[0].oldPos+1>=o&&f+1>=a)return i(this.buildValues(d[0].lastComponent,t,e));let p=-1/0,m=1/0,h=()=>{for(let r=Math.max(p,-s);r<=Math.min(m,s);r+=2){let s,c=d[r-1],l=d[r+1];c&&(d[r-1]=void 0);let u=!1;if(l){let e=l.oldPos-r;u=l&&0<=e&&e<a}let h=c&&c.oldPos+1<o;if(!u&&!h){d[r]=void 0;continue}if(s=!h||u&&c.oldPos<l.oldPos?this.addToPath(l,!0,!1,0,n):this.addToPath(c,!1,!0,1,n),f=this.extractCommon(s,t,e,r,n),s.oldPos+1>=o&&f+1>=a)return i(this.buildValues(s.lastComponent,t,e))||!0;d[r]=s,s.oldPos+1>=o&&(m=Math.min(m,r-1)),f+1>=a&&(p=Math.max(p,r+1))}s++};if(r)(function e(){setTimeout(function(){if(s>c||Date.now()>u)return r(void 0);h()||e()},0)})();else for(;s<=c&&Date.now()<=u;){let e=h();if(e)return e}}addToPath(e,t,n,r,i){let a=e.lastComponent;return a&&!i.oneChangePerToken&&a.added===t&&a.removed===n?{oldPos:e.oldPos+r,lastComponent:{count:a.count+1,added:t,removed:n,previousComponent:a.previousComponent}}:{oldPos:e.oldPos+r,lastComponent:{count:1,added:t,removed:n,previousComponent:a}}}extractCommon(e,t,n,r,i){let a=t.length,o=n.length,s=e.oldPos,c=s-r,l=0;for(;c+1<a&&s+1<o&&this.equals(n[s+1],t[c+1],i);)c++,s++,l++,i.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return l&&!i.oneChangePerToken&&(e.lastComponent={count:l,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=s,c}equals(e,t,n){return n.comparator?n.comparator(e,t):e===t||!!n.ignoreCase&&e.toLowerCase()===t.toLowerCase()}removeEmpty(e){let t=[];for(let n=0;n<e.length;n++)e[n]&&t.push(e[n]);return t}castInput(e,t){return e}tokenize(e,t){return Array.from(e)}join(e){return e.join(``)}postProcess(e,t){return e}get useLongestToken(){return!1}buildValues(e,t,n){let r=[],i;for(;e;)r.push(e),i=e.previousComponent,delete e.previousComponent,e=i;r.reverse();let a=r.length,o=0,s=0,c=0;for(;o<a;o++){let e=r[o];if(e.removed)e.value=this.join(n.slice(c,c+e.count)),c+=e.count;else{if(!e.added&&this.useLongestToken){let r=t.slice(s,s+e.count);r=r.map(function(e,t){let r=n[c+t];return r.length>e.length?r:e}),e.value=this.join(r)}else e.value=this.join(t.slice(s,s+e.count));s+=e.count,e.added||(c+=e.count)}}return r}};new class extends Kc{};function qc(e,t){let n;for(n=0;n<e.length&&n<t.length;n++)if(e[n]!=t[n])return e.slice(0,n);return e.slice(0,n)}function Jc(e,t){let n;if(!e||!t||e[e.length-1]!=t[t.length-1])return``;for(n=0;n<e.length&&n<t.length;n++)if(e[e.length-(n+1)]!=t[t.length-(n+1)])return e.slice(-n);return e.slice(-n)}function Yc(e,t,n){if(e.slice(0,t.length)!=t)throw Error(`string ${JSON.stringify(e)} doesn't start with prefix ${JSON.stringify(t)}; this is a bug`);return n+e.slice(t.length)}function Xc(e,t,n){if(!t)return e+n;if(e.slice(-t.length)!=t)throw Error(`string ${JSON.stringify(e)} doesn't end with suffix ${JSON.stringify(t)}; this is a bug`);return e.slice(0,-t.length)+n}function Zc(e,t){return Yc(e,t,``)}function Qc(e,t){return Xc(e,t,``)}function $c(e,t){return t.slice(0,el(e,t))}function el(e,t){let n=0;e.length>t.length&&(n=e.length-t.length);let r=t.length;e.length<t.length&&(r=e.length);let i=Array(r),a=0;i[0]=0;for(let e=1;e<r;e++){for(t[e]==t[a]?i[e]=i[a]:i[e]=a;a>0&&t[e]!=t[a];)a=i[a];t[e]==t[a]&&a++}a=0;for(let r=n;r<e.length;r++){for(;a>0&&e[r]!=t[a];)a=i[a];e[r]==t[a]&&a++}return a}function tl(e,t){let n=[];for(let r of Array.from(t.segment(e))){let e=r.segment;n.length&&/\s/.test(n[n.length-1])&&/\s/.test(e)?n[n.length-1]+=e:n.push(e)}return n}function nl(e,t){if(t)return il(e,t)[1];let n;for(n=e.length-1;n>=0&&e[n].match(/\s/);n--);return e.substring(n+1)}function rl(e,t){if(t)return il(e,t)[0];let n=e.match(/^\s*/);return n?n[0]:``}function il(e,t){if(!t)return[rl(e),nl(e)];if(t.resolvedOptions().granularity!=`word`)throw Error(`The segmenter passed must have a granularity of "word"`);let n=tl(e,t),r=n[0],i=n[n.length-1];return[/\s/.test(r)?r:``,/\s/.test(i)?i:``]}var al=`a-zA-Z0-9_\\u{AD}\\u{C0}-\\u{D6}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}`,ol=RegExp(`[${al}]+|\\s+|[^${al}]`,`ug`);new class extends Kc{equals(e,t,n){return n.ignoreCase&&(e=e.toLowerCase(),t=t.toLowerCase()),e.trim()===t.trim()}tokenize(e,t={}){let n;if(t.intlSegmenter){let r=t.intlSegmenter;if(r.resolvedOptions().granularity!=`word`)throw Error(`The segmenter passed must have a granularity of "word"`);n=tl(e,r)}else n=e.match(ol)||[];let r=[],i=null;return n.forEach(e=>{/\s/.test(e)?i==null?r.push(e):r.push(r.pop()+e):i!=null&&/\s/.test(i)?r[r.length-1]==i?r.push(r.pop()+e):r.push(i+e):r.push(e),i=e}),r}join(e){return e.map((e,t)=>t==0?e:e.replace(/^\s+/,``)).join(``)}postProcess(e,t){if(!e||t.oneChangePerToken)return e;let n=null,r=null,i=null;return e.forEach(e=>{e.added?r=e:e.removed?i=e:((r||i)&&sl(n,i,r,e,t.intlSegmenter),n=e,r=null,i=null)}),(r||i)&&sl(n,i,r,null,t.intlSegmenter),e}};function sl(e,t,n,r,i){if(t&&n){let[a,o]=il(t.value,i),[s,c]=il(n.value,i);if(e){let r=qc(a,s);e.value=Xc(e.value,s,r),t.value=Zc(t.value,r),n.value=Zc(n.value,r)}if(r){let e=Jc(o,c);r.value=Yc(r.value,c,e),t.value=Qc(t.value,e),n.value=Qc(n.value,e)}}else if(n){if(e){let e=rl(n.value,i);n.value=n.value.substring(e.length)}if(r){let e=rl(r.value,i);r.value=r.value.substring(e.length)}}else if(e&&r){let n=rl(r.value,i),[a,o]=il(t.value,i),s=qc(n,a);t.value=Zc(t.value,s);let c=Jc(Zc(n,s),o);t.value=Qc(t.value,c),r.value=Yc(r.value,n,c),e.value=Xc(e.value,n,n.slice(0,n.length-c.length))}else if(r){let e=rl(r.value,i),n=$c(nl(t.value,i),e);t.value=Qc(t.value,n)}else if(e){let n=$c(nl(e.value,i),rl(t.value,i));t.value=Zc(t.value,n)}}var cl=new class extends Kc{tokenize(e){let t=RegExp(`(\\r?\\n)|[${al}]+|[^\\S\\n\\r]+|[^${al}]`,`ug`);return e.match(t)||[]}};function ll(e,t,n){return cl.diff(e,t,n)}var ul=new class extends Kc{constructor(){super(...arguments),this.tokenize=fl}equals(e,t,n){return n.ignoreWhitespace?((!n.newlineIsToken||!e.includes(`
4
+ `))&&(e=e.trim()),(!n.newlineIsToken||!t.includes(`
5
+ `))&&(t=t.trim())):n.ignoreNewlineAtEof&&!n.newlineIsToken&&(e.endsWith(`
6
+ `)&&(e=e.slice(0,-1)),t.endsWith(`
7
+ `)&&(t=t.slice(0,-1))),super.equals(e,t,n)}};function dl(e,t,n){return ul.diff(e,t,n)}function fl(e,t){t.stripTrailingCr&&(e=e.replace(/\r\n/g,`
8
+ `));let n=[],r=e.split(/(\n|\r\n)/);r[r.length-1]||r.pop();for(let e=0;e<r.length;e++){let i=r[e];e%2&&!t.newlineIsToken?n[n.length-1]+=i:n.push(i)}return n}function pl(e){return e==`.`||e==`!`||e==`?`}new class extends Kc{tokenize(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(r==e.length-1){t.push(e.slice(n));break}if(pl(e[r])&&e[r+1].match(/\s/)){for(t.push(e.slice(n,r+1)),r=n=r+1;e[r+1]?.match(/\s/);)r++;t.push(e.slice(n,r+1)),n=r+1}}return t}},new class extends Kc{tokenize(e){return e.split(/([{}:;,]|\s+)/)}},new class extends Kc{constructor(){super(...arguments),this.tokenize=fl}get useLongestToken(){return!0}castInput(e,t){let{undefinedReplacement:n,stringifyReplacer:r=(e,t)=>t===void 0?n:t}=t;return typeof e==`string`?e:JSON.stringify(ml(e,null,null,r),null,` `)}equals(e,t,n){return super.equals(e.replace(/,([\r\n])/g,`$1`),t.replace(/,([\r\n])/g,`$1`),n)}};function ml(e,t,n,r,i){t||=[],n||=[],r&&(e=r(i===void 0?``:i,e));let a;for(a=0;a<t.length;a+=1)if(t[a]===e)return n[a];let o;if(Object.prototype.toString.call(e)===`[object Array]`){for(t.push(e),o=Array(e.length),n.push(o),a=0;a<e.length;a+=1)o[a]=ml(e[a],t,n,r,String(a));return t.pop(),n.pop(),o}if(e&&e.toJSON&&(e=e.toJSON()),typeof e==`object`&&e){t.push(e),o={},n.push(o);let i=[],s;for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&i.push(s);for(i.sort(),a=0;a<i.length;a+=1)s=i[a],o[s]=ml(e[s],t,n,r,s);t.pop(),n.pop()}else o=e;return o}new class extends Kc{tokenize(e){return e.slice()}join(e){return e}removeEmpty(e){return e}};function hl(e,t,n,r,i,a,o){let s;s=o?typeof o==`function`?{callback:o}:o:{},s.context===void 0&&(s.context=4);let c=s.context;if(s.newlineIsToken)throw Error(`newlineIsToken may not be used with patch-generation functions, only with diffing functions`);if(s.callback){let{callback:e}=s;dl(n,r,Object.assign(Object.assign({},s),{callback:t=>{let n=l(t);e(n)}}))}else return l(dl(n,r,s));function l(n){if(!n)return;n.push({value:``,lines:[]});function r(e){return e.map(function(e){return` `+e})}let o=[],s=0,l=0,u=[],d=1,f=1;for(let e=0;e<n.length;e++){let t=n[e],i=t.lines||gl(t.value);if(t.lines=i,t.added||t.removed){if(!s){let t=n[e-1];s=d,l=f,t&&(u=c>0?r(t.lines.slice(-c)):[],s-=u.length,l-=u.length)}for(let e of i)u.push((t.added?`+`:`-`)+e);t.added?f+=i.length:d+=i.length}else{if(s)if(i.length<=c*2&&e<n.length-2)for(let e of r(i))u.push(e);else{let e=Math.min(i.length,c);for(let t of r(i.slice(0,e)))u.push(t);let t={oldStart:s,oldLines:d-s+e,newStart:l,newLines:f-l+e,lines:u};o.push(t),s=0,l=0,u=[]}d+=i.length,f+=i.length}}for(let e of o)for(let t=0;t<e.lines.length;t++)e.lines[t].endsWith(`
9
+ `)?e.lines[t]=e.lines[t].slice(0,-1):(e.lines.splice(t+1,0,`\`),t++);return{oldFileName:e,newFileName:t,oldHeader:i,newHeader:a,hunks:o}}}function gl(e){let t=e.endsWith(`
10
+ `),n=e.split(`
11
+ `).map(e=>e+`
12
+ `);return t?n.pop():n.push(n.pop().slice(0,-1)),n}function _l(e,t){let n=hl(``,``,e,t,``,``,{context:3,timeout:100});if(!n||n.hunks.reduce((e,t)=>e+t.lines.length,0)>5e3)return null;let r=performance.now()+30,i=0,a=0;return{hunks:n.hunks.map(e=>{let t=e.oldStart,n=e.newStart,o=[],s=[],c=[],l=[],u=()=>{for(let e=0;e<Math.min(c.length,l.length);e++){let t=c[e],n=l[e],i=t.spans[0].text,a=n.spans[0].text;if(i.length+a.length>4e3||performance.now()>=r)continue;let o=ll(i,a,{timeout:5});o&&(t.spans=o.filter(e=>!e.added).map(e=>({text:e.value,changed:e.removed})),n.spans=o.filter(e=>!e.removed).map(e=>({text:e.value,changed:e.added})))}c=[],l=[]};for(let r of e.lines){let e=r[0];if(e===`\\`)continue;e===` `&&u();let d=(e,t)=>({number:e,changed:t,spans:[{text:r.slice(1),changed:t}]});if(e!==`+`){let n=d(t++,e===`-`);o.push(n),n.changed&&(c.push(n),a++)}if(e!==`-`){let t=d(n++,e===`+`);s.push(t),t.changed&&(l.push(t),i++)}}return u(),{before:o,after:s}}),additions:i,deletions:a}}function vl({before:e,after:t}){let n=(0,X.useMemo)(()=>_l(e,t),[e,t]);return n?n.hunks.length?(0,Z.jsxs)(`div`,{className:`phone-diff`,"aria-label":`File diff`,children:[(0,Z.jsxs)(`p`,{className:`mb-3 flex gap-3 text-xs`,children:[(0,Z.jsxs)(`span`,{className:`text-success`,children:[`+`,n.additions,` added`]}),(0,Z.jsxs)(`span`,{className:`text-danger`,children:[`−`,n.deletions,` removed`]})]}),n.hunks.map((e,t)=>(0,Z.jsxs)(`section`,{className:`phone-diff-hunk`,"aria-label":`Change ${t+1}`,children:[(0,Z.jsx)(yl,{label:`Before`,lines:e.before}),(0,Z.jsx)(yl,{label:`After`,lines:e.after})]},t)),e.length>0&&!e.endsWith(`
13
+ `)&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Before: no newline at end of file.`}),t.length>0&&!t.endsWith(`
14
+ `)&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`After: no newline at end of file.`})]}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`No text changes.`}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Diff is too large. Use Before and After to review the text.`})}function yl({label:e,lines:t}){let n=e===`Before`?`removed`:`added`;return(0,Z.jsxs)(`div`,{className:`phone-diff-pane`,"aria-label":e,children:[(0,Z.jsxs)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:[e,t.length>0&&` · ${t[0].number}–${t.at(-1).number}`]}),t.length===0?(0,Z.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:`No lines`}):(0,Z.jsx)(`div`,{className:`phone-diff-code`,tabIndex:0,children:t.map(t=>(0,Z.jsxs)(`div`,{className:`phone-diff-line`,"data-change":t.changed?n:void 0,children:[(0,Z.jsx)(`span`,{className:`phone-diff-number`,"aria-hidden":`true`,children:t.number}),(0,Z.jsx)(`span`,{className:`phone-diff-sign`,"aria-hidden":`true`,children:t.changed?e===`Before`?`−`:`+`:` `}),(0,Z.jsxs)(`code`,{children:[t.spans.map((e,t)=>e.changed?(0,Z.jsx)(`mark`,{children:e.text},t):e.text),`
15
+ `]})]},t.number))})]})}function bl(e,t){let n=e.parentElement,r,i=null,a=0,o=null,s=0,c=e.firstChild;if(!c||c.nodeType!==Node.TEXT_NODE)return()=>{};let l=(e,t)=>{let r=n.getBoundingClientRect(),i=Math.max(r.left+1,Math.min(r.right-1,e)),a=Math.max(r.top+1,Math.min(r.bottom-1,t)),o=document.caretPositionFromPoint?.(i,a);if(o?.offsetNode===c)return o.offset;let s=document.caretRangeFromPoint?.(i,a);return s?.startContainer===c?s.startOffset:null},u=(e,n)=>{let r=document.createRange();r.setStart(c,e),r.setEnd(c,n);let i=window.getSelection();i?.removeAllRanges(),i?.addRange(r),t(i?.toString()??``)},d=()=>{if(!i?.anchor||!o)return;let e=l(o.x,o.y);e!==null&&u(Math.min(i.anchor.start,e),Math.max(i.anchor.end,e))},f=t=>{if(a=0,!o)return;let r=n.getBoundingClientRect(),i=o.y<r.top?-1:+(o.y>=r.bottom),c=o.x<r.left?-1:+(o.x>=r.right);if((i||c)&&t-s>=50){s=t;let r=parseFloat(getComputedStyle(e).lineHeight);n.scrollBy(c*r,i*r),d()}a=requestAnimationFrame(f)},p=()=>{clearTimeout(r),cancelAnimationFrame(a),a=0,o=null,i=null},m=e=>{if(p(),e.touches.length!==1)return;let t=e.touches[0];i={id:t.identifier,x:t.clientX,y:t.clientY},r=setTimeout(()=>{if(!i)return;let e=l(i.x,i.y);if(e===null)return;let t=c.textContent??``,n=e,r=e;for(;n>0&&/\S/u.test(t[n-1]);)n--;for(;r<t.length&&/\S/u.test(t[r]);)r++;i.anchor={start:n,end:r},u(n,r)},450)},h=e=>{if(!i)return;let t=e.touches[0];if(e.touches.length!==1||t?.identifier!==i.id){p();return}i.anchor?(e.preventDefault(),o={x:t.clientX,y:t.clientY},d(),a||=requestAnimationFrame(f)):Math.hypot(t.clientX-i.x,t.clientY-i.y)>=8&&p()},g=e=>{i?.anchor&&e.preventDefault(),p()},_=e=>{i&&e.preventDefault()},v=()=>{let e=window.getSelection();t(e?.anchorNode===c&&e.focusNode===c?e.toString():``)};return e.addEventListener(`touchstart`,m,{passive:!0}),e.addEventListener(`touchmove`,h,{passive:!1}),e.addEventListener(`touchend`,g,{passive:!1}),e.addEventListener(`touchcancel`,p),e.addEventListener(`contextmenu`,_),document.addEventListener(`selectionchange`,v),()=>{p(),e.removeEventListener(`touchstart`,m),e.removeEventListener(`touchmove`,h),e.removeEventListener(`touchend`,g),e.removeEventListener(`touchcancel`,p),e.removeEventListener(`contextmenu`,_),document.removeEventListener(`selectionchange`,v)}}function xl({content:e,target:t}){let n=(0,X.useRef)(null),r=(0,X.useRef)(null),i=Gi(`phone-source`,t),[a,o]=(0,X.useState)(``);return(0,X.useLayoutEffect)(()=>{if(!(!r.current||!n.current))return Xi(r.current,n.current,i).dispose},[i,e]),(0,X.useEffect)(()=>{let e=n.current;if(e)return o(``),bl(e,o)},[e]),(0,Z.jsxs)(`div`,{className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(`div`,{ref:r,className:`h-full overflow-auto overscroll-contain`,children:(0,Z.jsx)(`pre`,{ref:n,className:`phone-file-source`,tabIndex:0,children:e})}),a&&(0,Z.jsx)(Gr,{label:`Selected file text`,text:a,clear:()=>{window.getSelection()?.removeAllRanges(),o(``)}})]})}function Sl({session:e}){let[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(`diff`),a=Ke({queryKey:[`phone-diff`,e],queryFn:async()=>w.parse(await he(`GET`,`/api/worktrees/${e}/diff?against=base`))}),o=a.data?.entries.find(e=>e.path===t),s=Ke({queryKey:[`phone-before`,e,t,o?.old_path,a.data?.against],queryFn:async()=>o?.status===`added`?{content:``,binary:!1}:ie.parse(await he(`GET`,`/api/worktrees/${e}/file-at?ref=${encodeURIComponent(a.data.against)}&path=${encodeURIComponent(o?.old_path??t)}`)),enabled:t!==null&&!!a.data}),c=Ke({queryKey:[`phone-after`,e,t,o?.status],queryFn:async()=>o?.status===`deleted`?{content:``,binary:!1}:v.parse(await he(`GET`,`/api/worktrees/${e}/file?path=${encodeURIComponent(t)}`)),enabled:t!==null&&!!a.data}),l=a.error??(t?s.error??c.error:null),u=r===`diff`?s.data?.binary||c.data?.binary:r===`before`?s.data?.binary:c.data?.binary;return(0,Z.jsxs)(`section`,{className:`phone-review`,"aria-label":`Changes`,children:[t===null?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`p`,{className:`mb-2 text-sm text-fg-muted`,children:[`Changes against `,a.data?.base_ref??`base`]}),a.isPending&&(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Loading changes…`}),a.data?.entries.map(e=>(0,Z.jsxs)(q,{variant:`ghost`,className:`phone-file`,onClick:()=>{n(e.path),i(`diff`)},children:[e.path,` · `,e.status]},e.path)),a.data?.entries.length===0&&(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`No changes.`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(q,{variant:`ghost`,size:`icon`,"aria-label":`Back to changes`,onClick:()=>n(null),children:(0,Z.jsx)(pa,{})}),(0,Z.jsxs)(`span`,{className:`min-w-0 break-all font-mono text-xs`,children:[t,` · read only`]})]}),(0,Z.jsx)(`nav`,{"aria-label":`Diff view`,children:[`diff`,`before`,`after`].map(e=>(0,Z.jsx)(q,{variant:`ghost`,size:`sm`,"aria-pressed":r===e,onClick:()=>i(e),children:e===`diff`?`Diff`:e===`before`?`Before`:`After`},e))}),u?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Binary file; preview unavailable.`}):r===`diff`?s.data&&c.data?(0,Z.jsx)(vl,{before:s.data.content??``,after:c.data.content??``}):!l&&(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Loading diff…`}):(r===`before`?s.data:c.data)?(0,Z.jsx)(xl,{target:[e,t,a.data?.against,r],content:(r===`before`?s.data?.content:c.data?.content)??``}):!l&&(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Loading file…`})]}),l&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:l.message})]})}function Cl({sessions:e,selected:t,select:n}){let r=e.find(e=>e.id===t&&e.kind===`huddle`),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(Bi.isConnected()),c=Bc(t&&!i&&!r?`term:${t}`:null);return(0,X.useEffect)(()=>Bi.onConnectionChange(s),[]),(0,Z.jsxs)(`div`,{className:`phone-workspace`,children:[(0,Z.jsxs)(`nav`,{className:`phone-selectors`,children:[(0,Z.jsxs)(`select`,{className:zn,"aria-label":`Session`,value:t??``,onChange:e=>n(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose session`}),e.map(e=>(0,Z.jsxs)(`option`,{value:e.id,children:[e.title??e.agent_title??e.osc_title??e.id.slice(0,8),` `,`· `,e.status]},e.id))]}),(0,Z.jsx)(q,{disabled:!!r,variant:`secondary`,"aria-pressed":i,onClick:()=>a(!i),children:i?`Terminal`:`Review`})]}),!o&&(0,Z.jsx)(`p`,{role:`status`,children:`Reconnecting… Your draft will stay here.`}),(0,Z.jsx)(`div`,{className:`phone-view`,children:r?(0,Z.jsx)(Lc,{session:r},r.id):i&&t?(0,Z.jsx)(Sl,{session:t},t):(0,Z.jsx)(`div`,{ref:c,className:`size-full`})}),t&&!i&&!r&&(0,Z.jsx)(Gc,{session:t,term:`agent`,connected:o},t)]})}var wl=20,Tl=new Map;function El(e,t){let n=Tl.get(e)??[];n.push(t),n.length>wl&&n.shift(),Tl.set(e,n)}function Dl(e,t){let n=Tl.get(e);for(;n&&n.length>0;){let e=n.pop();if(t(e.ref))return e}}function Ol(e,t){if(!e.layout_tree||e.active_session!==t)return!1;let n=Ht(e.layout_tree);return n.some(e=>e.tabs.some(e=>e.type!==`editor`&&e.session===t))&&!n.some(e=>e.tabs.some(n=>n.type!==`editor`&&n.session===t&&e.activeKey===B(n)))}function kl(e,t){let n=window.history.state;if(!n||typeof n!=`object`||!(`key`in n)||n.key!==t||!(`usr`in n)||!n.usr||typeof n.usr!=`object`||!(`notificationSession`in n.usr)||n.usr.notificationSession!==e)return;let r={...n.usr};delete r.notificationSession,window.history.replaceState({...n,usr:r},``)}function Al({layout:e,uiState:t,scopeKey:n,projectScoped:r,sessions:i,allSessions:a,projectReady:o,isNarrow:s,onNavigate:c,claimScrollDriver:l,requestDiscard:u}){let d=fn(),f=d.id??``,p=d.sid??null,m=dn(),h=mn(),g=h.state?.notificationSession===p?h.key:null,_=(0,X.useRef)({projectId:f,activeSessionId:p});_.current={projectId:f,activeSessionId:p};let v=(0,X.useRef)(e);v.current=e;let y=(0,X.useRef)(t);y.current=t;let b=(0,X.useRef)(a);b.current=a;let x=a??i,S=x.find(e=>e.id===p)?.kind,C=(0,X.useRef)(s);C.current=s;let w=(0,X.useRef)(c);w.current=c;let[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)([]),k=(0,X.useCallback)(e=>{E(e),O(t=>t.includes(e)?t:[...t,e])},[]),A=(0,X.useRef)(!0);(0,X.useEffect)(()=>(A.current=!0,()=>{A.current=!1}),[]);let[j,M]=(0,X.useState)(null),N=j===f,P=(0,X.useRef)(!0),F=(0,X.useRef)(null),I=(0,X.useRef)(null);(0,X.useEffect)(()=>Bi.onSessionSwitched(e=>{if(e.source_session!==p)return;let t=e.cause!==`resume`;I.current={session:e.target_session,pin:t},e.target_project===f&&v.current.ensureSession({id:e.target_session,kind:`agent`},{preview:!t,...t?{keepSession:e.source_session}:{}}),m(`/project/${e.target_project}/session/${e.target_session}`)}),[p,m,f]),(0,X.useEffect)(()=>{if(N||!t.loaded||!o)return;M(f);let e=t.snapshot.active_session,n=i.find(t=>t.id===e);!p&&n&&n.status!==`archived`&&!(z()&&Ol(t.snapshot,n.id))&&m(`/project/${f}/session/${n.id}`,{replace:!0})},[N,t,o,i,p,m,f]),(0,X.useEffect)(()=>{if(!N)return;let e=P.current;if(P.current=!1,C.current){p&&(E(p),O(e=>e.includes(p)?e:[...e,p])),w.current();return}if(w.current(),!p){F.current=null;return}if(e&&!g&&z()&&Ol(y.current.current(),p)||p===F.current&&!g)return;F.current=null;let t=I.current;I.current=null;let n=x.find(e=>e.id===p);if(!n||n.kind===`huddle`&&!Yr())return;v.current.ensureSession(n,{preview:t?.session!==p||!t.pin});let r=y.current;r.snapshot.active_session!==p&&r.update({active_session:p}),g&&z()&&kl(p,g)},[N,p,S,g,o]);let te=(0,X.useCallback)(n=>{let r=p===n,i=A.current&&_.current.projectId===f&&_.current.activeSessionId===n;r&&i&&(F.current=n);let a=x.find(e=>e.id===n);e.removeSession(n,a?.huddle_id?ee(a.huddle_id).map(e=>({session:n,path:e})):void 0),r&&(t.current().active_session===n&&t.update({active_session:null}),i&&m(`/project/${f}`))},[e,t,p,m,f,x]),ne=(0,X.useCallback)((t,n)=>{if(l(t),e.activate(t,n),n.type!==`editor`&&n.session!==p){let e=x.find(e=>e.id===n.session)?.project_id;e&&m(`/project/${e}/session/${n.session}`)}},[e,m,x,p,l]),re=(0,X.useCallback)((r,i,a)=>{if(i.type===`editor`&&Y(i.tab)===`untitled`)return u(r,i,a);let o=Lt(e.tree,r)?.tabs.findIndex(e=>B(e)===B(i))??-1;El(n,{leafId:r,index:Math.max(0,o),ref:i}),e.close(r,i);let s=i.type===`huddle`&&Ht(e.tree).some(e=>e.id!==r&&e.tabs.some(e=>e.type===`huddle`&&e.session===i.session));i.type!==`editor`&&i.session===p&&!s&&(F.current=i.session,t.update({active_session:null}),m(`/project/${f}`))},[e,p,t,m,f,n,u]),ie=(0,X.useCallback)(()=>{let t=b.current,r=t?new Set(t.filter(e=>e.status!==`archived`).map(e=>e.id)):null,i=Dl(n,e=>{if(r===null)return!0;let t=e.type===`editor`?e.tab.session:e.session;return r.has(t)});if(!i)return;let{ref:a}=i,o=Lt(e.tree,i.leafId),s=o?i.leafId:e.focusedLeaf.id,c=o?i.index:void 0;if(e.drop({ref:a,fromLeafId:s,toLeafId:s,edge:`center`,index:c}),a.type!==`editor`&&a.session!==p){let e=x.find(e=>e.id===a.session)?.project_id;e&&m(`/project/${e}/session/${a.session}`)}},[e,n,p,x,m]);return{closeTab:te,onActivateTab:ne,onCloseTab:re,onDropTab:(0,X.useCallback)((t,n,i,a)=>{if(a?.fromLeafId){e.drop({ref:n,fromLeafId:a.fromLeafId,toLeafId:t,edge:i,index:a.index});return}let o=n.type===`editor`?void 0:x.find(e=>e.id===n.session)?.project_id;if(r&&o!==void 0&&o!==f&&n.type!==`editor`){I.current={session:n.session,pin:!0},m(`/project/${o}/session/${n.session}`);return}e.drop({ref:n,fromLeafId:t,toLeafId:t,edge:i,copy:!0,index:a?.index}),n.type!==`editor`&&n.session!==p&&o!==void 0&&m(`/project/${o}/session/${n.session}`)},[e,p,x,m,r,f]),reopenClosedTab:ie,phoneSelection:T,phoneVisited:D,selectPhoneSession:k}}function jl(e){let[t,n]=(0,X.useState)(()=>window.matchMedia(e).matches);return(0,X.useEffect)(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return n(t.matches),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}var Ml=`(max-width: 767px)`;function Nl(e,t){let n={};for(let r of t){let t=e[r];if(typeof t!=`number`)return;n[r]=t}return n}var Pl=`puddle.pane-height.`;function Fl(e){try{let t=localStorage.getItem(`${Pl}${e}`);if(t===null)return null;let n=Number(t);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function Il(e,t,{sized:n,min:r=64}){let[i,a]=(0,X.useState)(()=>Fl(e)??t),[o,s]=(0,X.useState)(!1),c=(0,X.useRef)(i);return c.current=i,{height:i,handle:{dragging:o,height:i,min:r,onPointerDown:(0,X.useCallback)(t=>{if(t.button!==0)return;t.preventDefault();let i=t.currentTarget,o=t.clientY,l=c.current,u=i.parentElement?.getBoundingClientRect().height??window.innerHeight,d=Math.max(r,u-96);i.setPointerCapture(t.pointerId),s(!0);let f=e=>{let t=e.clientY-o,i=n===`below`?l-t:l+t;c.current=Math.round(Math.min(d,Math.max(r,i))),a(c.current)},p=()=>{i.removeEventListener(`pointermove`,f),i.removeEventListener(`pointerup`,p),i.removeEventListener(`pointercancel`,p),s(!1);try{localStorage.setItem(`${Pl}${e}`,String(c.current))}catch{}};i.addEventListener(`pointermove`,f),i.addEventListener(`pointerup`,p),i.addEventListener(`pointercancel`,p)},[e,r,n]),onKeyDown:t=>{if(![`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(t.key))return;t.preventDefault();let i=t.currentTarget.parentElement?.getBoundingClientRect().height??window.innerHeight,o=Math.max(r,i-96),s=(t.key===`ArrowUp`?-1:1)*(n===`below`?-1:1)*(t.shiftKey?40:10),l=t.key===`Home`?r:t.key===`End`?o:Math.min(o,Math.max(r,c.current+s));c.current=l,a(l);try{localStorage.setItem(`${Pl}${e}`,String(l))}catch{}}}}}function Ll({handle:e,label:t,className:n}){let r=(0,X.useRef)(null),[i,a]=(0,X.useState)(Math.max(e.min,window.innerHeight-96));return(0,X.useLayoutEffect)(()=>{let t=r.current?.parentElement;if(!t)return;let n=()=>a(Math.max(e.min,t.getBoundingClientRect().height-96));n();let i=new ResizeObserver(n);return i.observe(t),()=>i.disconnect()},[e.min]),(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{ref:r,"data-separator":e.dragging?`active`:`inactive`,role:`separator`,tabIndex:0,"aria-valuenow":Math.min(i,e.height),"aria-valuemax":i,"aria-valuemin":e.min,onKeyDown:e.onKeyDown,"aria-orientation":`horizontal`,"aria-label":t,onPointerDown:e.onPointerDown,className:V(`relative h-[var(--ui-surface-gap)] shrink-0 cursor-row-resize touch-none bg-transparent`,n),children:(0,Z.jsx)(`div`,{className:`absolute inset-x-0 top-1/2 h-[9px] -translate-y-1/2`})}),(0,Z.jsx)(Bs,{separatorRef:r,vertical:!1})]})}var Rl=80,zl=180;function Bl(e){return Math.max(zl,Math.round(e/Rl*1e3))}function Vl({text:e,hoverClass:t,className:n,containerClassName:r,title:i,children:a}){let o=(0,X.useRef)(null),[s,c]=(0,X.useState)(0);return(0,X.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>c(Math.max(0,e.scrollWidth-e.clientWidth));t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e]),(0,Z.jsx)(`span`,{className:V(`block min-w-0 flex-1 overflow-hidden`,r),children:(0,Z.jsx)(`span`,{ref:o,title:i,className:V(`block whitespace-nowrap transition-transform ease-linear`,n,s>0&&t),style:s>0?{"--tail":`-${s}px`,transitionDuration:`${Bl(s)}ms`}:void 0,children:a??e})})}var Hl={added:{letter:`A`,label:`added`,colourClass:`text-success`},modified:{letter:`M`,label:`modified`,colourClass:`text-fg-secondary`},deleted:{letter:`D`,label:`deleted`,colourClass:`text-interrupted`},renamed:{letter:`R`,label:`renamed`,colourClass:`text-warning`}};function Ul(e){return Hl[e]}var Wl=[`modified`,`added`,`deleted`,`renamed`];function Gl(e){let t=new Map;for(let n of e)t.set(n.status,(t.get(n.status)??0)+1);return Wl.filter(e=>t.has(e)).map(e=>`${t.get(e)} ${Hl[e].label}`).join(` · `)}var Kl=[`var(--accent)`,`var(--status-running)`,`var(--status-waiting)`,`var(--ansi-magenta)`,`var(--ansi-cyan)`,`var(--status-interrupted)`];function ql(e){return Kl[e%Kl.length]}function Jl(e){let t=[],n=0,r=0,i=()=>{let e=t.indexOf(null);return e===-1?t.length:e},a=()=>{let e=[];for(let n=0;n<t.length;n++){let r=t[n];r&&e.push({col:n,sha:r.sha,colour:ql(r.colourIdx)})}return e},o=[],s=[];for(let c of e){let e=c.parents??[],l=[];for(let e=0;e<t.length;e++)t[e]?.sha===c.sha&&l.push(e);let u,d;l.length>0?(u=l[0],d=t[u].colourIdx):(u=i(),d=n++);let f=ql(d);for(let e of l)t[e]=null;for(;t.length<=u;)t.push(null);let p=[];if(e.length>0){t[u]={sha:e[0],colourIdx:d},p.push(u);for(let r=1;r<e.length;r++){let a=e[r],o=t.findIndex(e=>e?.sha===a);if(o===-1){for(o=i();t.length<=o;)t.push(null);t[o]={sha:a,colourIdx:n++}}p.push(o)}}else t[u]=null;let m=a();o.push({sha:c.sha,col:u,colour:f,above:s,below:m,created:p}),s=m,r=Math.max(r,t.length)}return{rows:o,laneCount:r}}var Yl=4,Xl=1.5;function Zl(e){return e*14+14/2}function Ql(e,t,n,r){if(e===n)return`M ${e} ${t} L ${n} ${r}`;let i=(t+r)/2;return`M ${e} ${t} C ${e} ${i}, ${n} ${i}, ${n} ${r}`}function $l({row:e,width:t}){let n=Zl(e.col),r=new Set(e.created),i=[];for(let t of e.above){let r=Zl(t.col);t.sha===e.sha?i.push({d:Ql(r,0,n,20),colour:t.colour}):i.push({d:Ql(r,0,r,40),colour:t.colour})}for(let t of e.below){let e=Zl(t.col);r.has(t.col)&&i.push({d:Ql(n,20,e,40),colour:t.colour})}return(0,Z.jsxs)(`svg`,{width:t,height:40,className:`shrink-0`,"aria-hidden":!0,children:[i.map((e,t)=>(0,Z.jsx)(`path`,{d:e.d,fill:`none`,stroke:e.colour,strokeWidth:Xl},t)),(0,Z.jsx)(`circle`,{cx:n,cy:20,r:Yl,fill:`var(--bg-surface)`,stroke:e.colour,strokeWidth:Xl})]})}function eu({lanes:e,width:t}){return(0,Z.jsx)(`svg`,{width:t,height:22,className:`shrink-0`,"aria-hidden":!0,children:e.map(e=>{let t=Zl(e.col);return(0,Z.jsx)(`path`,{d:`M ${t} 0 L ${t} 22`,fill:`none`,stroke:e.colour,strokeWidth:Xl},e.col)})})}var tu=7,nu=`group-hover:[transform:translateX(var(--tail))]`;function ru({session:e,sha:t,root:n,lanes:r,gutterW:i,onOpen:a}){let o=ct(e,t,n),s=e=>(0,Z.jsxs)(`div`,{className:`flex items-center`,style:{height:22},children:[(0,Z.jsx)(eu,{lanes:r,width:i}),(0,Z.jsx)(`span`,{className:`px-2 text-2xs text-fg-muted`,children:e})]});return o.isPending?s(`…`):o.error?s(o.error instanceof Error?o.error.message:`Failed to load commit`):o.data.files.length===0?s(`No file changes.`):(0,Z.jsx)(Z.Fragment,{children:o.data.files.map(e=>{let o=Ul(e.status),s=e.status===`renamed`&&e.old_path?`${e.old_path} → ${e.path}`:e.path;return(0,Z.jsxs)(`button`,{type:`button`,title:s,onClick:()=>{a(e.path,t),Cc({path:e.path,root:n})},onDoubleClick:()=>a(e.path,t,{preview:!1}),className:`group flex w-full items-center text-left transition-colors hover:bg-elevated`,style:{height:22},children:[(0,Z.jsx)(eu,{lanes:r,width:i}),(0,Z.jsx)(`span`,{className:V(`mr-1.5 w-3 shrink-0 text-center font-mono text-xs`,o.colourClass),children:o.letter}),(0,Z.jsx)(Vl,{text:s,className:`pr-3 text-2xs text-fg`,hoverClass:nu})]},`${e.status}:${e.old_path??``}:${e.path}`)})})}function iu({session:e,root:t,onOpenCommitFile:n}){let r=dt(e,{root:t}),[i,a]=(0,X.useState)(null),o=(0,X.useMemo)(()=>r.data?.pages.flatMap(e=>e.commits)??[],[r.data]),s=(0,X.useMemo)(()=>Jl(o),[o]),c=Math.max(1,s.laneCount)*14+14/2;return r.isPending?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Loading history…`}):r.error?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:r.error instanceof Error?r.error.message:`Failed to load history`}):o.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No commits yet.`}):(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-2`,children:[s.rows.map((r,s)=>{let l=o[s],u=i===r.sha;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(u?null:r.sha),className:V(`group flex w-full items-center text-left transition-colors hover:bg-elevated`,u&&`bg-selection`),style:{height:40},children:[(0,Z.jsx)($l,{row:r,width:c}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5 pr-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-2xs text-fg-muted`,children:r.sha.slice(0,tu)}),(0,Z.jsx)(Vl,{text:l.subject,className:`text-xs text-fg`,hoverClass:nu})]}),(0,Z.jsxs)(`span`,{className:`truncate text-2xs text-fg-muted`,children:[l.author_name,` ·`,` `,(0,Z.jsx)(`span`,{className:`tabular-nums`,children:sr(l.authored_at)})]})]})]}),u&&(0,Z.jsx)(ru,{session:e,sha:r.sha,root:t,lanes:r.below,gutterW:c,onOpen:n})]},r.sha)}),r.hasNextPage&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>void r.fetchNextPage(),disabled:r.isFetchingNextPage,className:`px-3 py-2 text-left text-xs text-fg-muted transition-colors hover:bg-elevated`,children:r.isFetchingNextPage?`Loading…`:`Show more`})]})}var au={"package.json":`npm`,"package-lock.json":`npm`,".npmrc":`npm`,"pnpm-lock.yaml":`pnpm`,"pnpm-workspace.yaml":`pnpm`,"yarn.lock":`yarn`,dockerfile:`docker`,".dockerignore":`docker`,"compose.yaml":`docker`,"compose.yml":`docker`,"docker-compose.yml":`docker`,"docker-compose.yaml":`docker`,".gitignore":`git`,".gitattributes":`git`,".gitmodules":`git`,"readme.md":`readme`,license:`license`,licence:`license`,"license.md":`license`,"licence.md":`license`,".prettierignore":`prettier`,".prettierrc":`prettier`,".prettierrc.json":`prettier`,".eslintrc":`eslint`,".eslintrc.json":`eslint`,".eslintignore":`eslint`,".env":`tune`,"go.mod":`go-mod`,"go.sum":`go-mod`,"cargo.toml":`rust`,"cargo.lock":`rust`,"tsconfig.json":`typescript-def`},ou={ts:`typescript`,mts:`typescript`,cts:`typescript`,"d.ts":`typescript-def`,"d.mts":`typescript-def`,"d.cts":`typescript-def`,tsx:`react_ts`,js:`javascript`,mjs:`javascript`,cjs:`javascript`,jsx:`react`,py:`python`,pyi:`python`,pyw:`python`,rs:`rust`,go:`go`,rb:`ruby`,php:`php`,java:`java`,kt:`kotlin`,kts:`kotlin`,c:`c`,h:`h`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,hpp:`hpp`,hxx:`hpp`,cs:`csharp`,dart:`dart`,swift:`swift`,html:`html`,htm:`html`,xml:`xml`,plist:`xml`,vue:`vue`,svelte:`svelte`,astro:`astro`,sql:`database`,sqlite:`database`,db:`database`,json:`json`,jsonc:`json`,json5:`json`,yml:`yaml`,yaml:`yaml`,toml:`toml`,ini:`settings`,cfg:`settings`,conf:`settings`,env:`tune`,lock:`lock`,csv:`table`,tsv:`table`,xlsx:`table`,xls:`table`,md:`markdown`,mdx:`markdown`,markdown:`markdown`,txt:`document`,rtf:`document`,log:`document`,pdf:`pdf`,css:`css`,scss:`sass`,sass:`sass`,less:`less`,sh:`console`,bash:`console`,zsh:`console`,fish:`console`,svg:`svg`,png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,webp:`image`,bmp:`image`,ico:`image`,avif:`image`,heic:`image`,mp4:`video`,mov:`video`,webm:`video`,mkv:`video`,avi:`video`,mp3:`audio`,wav:`audio`,flac:`audio`,ogg:`audio`,m4a:`audio`,zip:`zip`,tar:`zip`,gz:`zip`,tgz:`zip`,rar:`zip`,"7z":`zip`,bz2:`zip`,xz:`zip`,woff:`font`,woff2:`font`,ttf:`font`,otf:`font`,ipynb:`jupyter`},su={"eslint.config.":`eslint`,".eslintrc.":`eslint`,"prettier.config.":`prettier`,".prettierrc.":`prettier`,"vite.config.":`vite`,"vitest.config.":`vitest`,"tsconfig.":`typescript-def`,".env.":`tune`,"dockerfile.":`docker`};function cu(e){let t=e.toLowerCase();if(Object.hasOwn(au,t))return au[t];for(let[e,n]of Object.entries(su))if(t.startsWith(e))return n;let n=t.split(`.`);for(let e=1;e<n.length;e++){let t=n.slice(e).join(`.`);if(Object.hasOwn(ou,t))return ou[t]}}function lu({name:e,dimmed:t,className:n}){let r=cu(e);return r?(0,Z.jsx)(`img`,{src:`/file-icons/material/${r}.svg`,alt:``,"aria-hidden":`true`,draggable:!1,className:V(`size-4.5 shrink-0`,t&&`opacity-50`,n)}):(0,Z.jsx)(ya,{"aria-hidden":`true`,className:V(`size-4.5 shrink-0 text-fg-muted`,n)})}function uu({open:e=!1,dimmed:t=!1,className:n}){return(0,Z.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":`true`,className:V(`size-4.5 shrink-0 text-explorer-folder`,t&&`opacity-50`,n),children:[(0,Z.jsx)(`path`,{d:`M3 3h5l2 2h11a1 1 0 0 1 1 1v2H2V4a1 1 0 0 1 1-1Z`}),(0,Z.jsx)(`path`,{d:e?`M2 9h21l-3 11H3a1 1 0 0 1-1-1Z`:`M2 9h20v10a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1Z`})]})}function du(){return{dirs:new Map,files:[]}}function fu(e){return e.path}function pu(e,t){let n=[];for(let[r,i]of e.dirs){let e=t?`${t}/${r}`:r,a={type:`dir`,name:r,path:e,children:pu(i,e)};for(;a.children.length===1&&a.children[0].type===`dir`;){let e=a.children[0];a={type:`dir`,name:`${a.name}/${e.name}`,path:e.path,children:e.children}}n.push(a)}n.sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}));let r=[...e.files].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}));return[...n,...r]}function mu(e){let t=du();for(let n of e){let e=fu(n),r=e.split(`/`),i=r.pop(),a=t;for(let e of r){let t=a.dirs.get(e);t||(t=du(),a.dirs.set(e,t)),a=t}a.files.push({type:`file`,name:i,path:e,entry:n})}return pu(t,``)}function hu(e){return e.map(e=>({type:`file`,name:fu(e).split(`/`).pop()??fu(e),path:fu(e),entry:e})).sort((e,t)=>e.path.localeCompare(t.path,void 0,{sensitivity:`base`}))}function gu(e){return e.type===`file`?[e.entry]:e.children.flatMap(gu)}var _u=`group-hover:[transform:translateX(var(--tail))]`;function vu({name:e,fullPath:t,status:n,depth:r,active:i,onOpen:a}){let o=Ul(n);return(0,Z.jsxs)(`button`,{type:`button`,title:t,onClick:()=>a(t),onDoubleClick:()=>a(t,{preview:!1}),className:V(`sidebar-row group flex items-center gap-2 py-1 pr-2 text-left transition-colors hover:bg-explorer-hover`,i&&`bg-explorer-selection`),style:{paddingLeft:8+r*12},children:[(0,Z.jsx)(`span`,{className:V(`w-3 shrink-0 text-center font-mono text-xs`,o.colourClass),children:o.letter}),(0,Z.jsx)(lu,{name:t.split(`/`).pop()??t,className:`size-4`}),(0,Z.jsx)(Vl,{text:e,className:`text-xs text-fg`,hoverClass:_u})]})}function yu({nodes:e,depth:t,activePath:n,onOpen:r}){let[i,a]=(0,X.useState)(new Set);return(0,Z.jsx)(Z.Fragment,{children:e.map(e=>{if(e.type===`file`)return(0,Z.jsx)(vu,{name:e.name,fullPath:e.path,status:e.entry.status,depth:t,active:n===e.path,onOpen:r},e.path);let o=i.has(e.path);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),className:`group flex w-full items-center gap-1 py-1 pr-3 text-left transition-colors hover:bg-elevated`,style:{paddingLeft:8+t*12},title:e.path,children:[o?(0,Z.jsx)(qn,{className:`size-3.5 shrink-0 text-fg-gold`}):(0,Z.jsx)(Ir,{className:`size-3.5 shrink-0 text-fg-gold`}),(0,Z.jsx)(Vl,{text:e.name,className:`text-xs text-fg-secondary`,hoverClass:_u})]}),!o&&(0,Z.jsx)(yu,{nodes:e.children,depth:t+1,activePath:n,onOpen:r})]},e.path)})})}function bu({session:e,root:t,activePath:n,onOpen:r}){let[i,a]=(0,X.useState)(!1),o=Qe(e,{against:`head`,root:t}),s=o.data?.entries??[],c=(e,n)=>{r(e,n),Cc({path:e,root:t})},l=(0,X.useMemo)(()=>i?null:mu(s),[i,s]),u=(0,X.useMemo)(()=>i?hu(s):null,[i,s]);return(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex h-7 shrink-0 items-center gap-2 px-3`,children:[(0,Z.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Uncommitted`}),s.length>0&&(0,Z.jsx)(`span`,{className:`truncate text-2xs text-fg-muted`,children:Gl(s)}),(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":!i,onClick:()=>a(e=>!e),className:`ml-auto rounded-sm p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[i?(0,Z.jsx)(Jr,{className:`size-3.5`}):(0,Z.jsx)(ui,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:i?`Show as tree`:`Show as flat list`})]})}),(0,Z.jsx)(G,{children:i?`Show as tree`:`Show as flat list`})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-1`,children:o.isPending?(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-fg-muted`,children:`Loading changes…`}):o.error?(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-fg-muted`,children:o.error instanceof Error?o.error.message:`Failed to load changes`}):s.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-1.5 text-xs text-fg-muted`,children:`No uncommitted changes.`}):i?u.map(e=>(0,Z.jsx)(vu,{name:e.path,fullPath:e.path,status:e.entry.status,depth:0,active:n===e.path,onOpen:c},e.path)):(0,Z.jsx)(yu,{nodes:l,depth:0,activePath:n,onOpen:c})})]})}var xu={untracked:{letter:`U`,colourClass:`text-success`},added:{letter:`A`,colourClass:`text-success`},modified:{letter:`M`,colourClass:`text-warning`},renamed:{letter:`R`,colourClass:`text-warning`},deleted:{letter:`D`,colourClass:`text-interrupted`},conflicted:{letter:`C`,colourClass:`text-interrupted`},ignored:{letter:``,colourClass:`text-fg-muted`}};function Su(e){return xu[e]}function Cu(e){let t=new Map;for(let n of e)t.set(n.path,n.status);return t}var wu={conflicted:0,modified:1,renamed:2,deleted:3,added:4,untracked:5,ignored:6};function Tu(e,t){let n=t===``?``:`${t}/`,r=null;for(let[t,i]of e)n!==``&&!t.startsWith(n)||i!==`ignored`&&(r===null||wu[i]<wu[r])&&(r=i);return r}function Eu(e){let t=new Set;for(let n of e)t.add(n.path),n.old_path!==null&&t.add(n.old_path);return[...t]}var Du=`group-hover:[transform:translateX(var(--tail))]`,Ou=`group-hover/repository:[transform:translateX(var(--tail))]`,ku=`group-hover:[transform:translateX(var(--tail))]`;function Au({label:e,onClick:t,disabled:n,className:r,children:i}){return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,"aria-label":e,disabled:n,onClick:e=>{e.stopPropagation(),t()},className:V(`shrink-0 rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-not-allowed disabled:opacity-40`,r),children:i})}),(0,Z.jsx)(G,{children:e})]})}function ju({title:e,entries:t,area:n,activePath:r,action:i,busy:a,flat:o,onAction:s,onRestore:c,onOpen:l}){let[u,d]=(0,X.useState)(!1),f=(0,X.useMemo)(()=>o?null:mu(t),[t,o]);if(t.length===0)return null;let p=i===`stage`;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`group flex h-7 items-center gap-1 px-3`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex min-w-0 flex-1 items-center gap-1 text-left text-2xs font-medium uppercase tracking-wide text-fg-gold transition-colors hover:text-fg`,children:[u?(0,Z.jsx)(qn,{className:`size-3`}):(0,Z.jsx)(Ir,{className:`size-3`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e}),(0,Z.jsx)(`span`,{className:`ml-1 text-fg-muted`,children:t.length})]}),(0,Z.jsx)(Au,{label:`${p?`Stage`:`Unstage`} all ${e.toLowerCase()}`,disabled:a,onClick:()=>s(Eu(t)),children:p?(0,Z.jsx)(fi,{className:`size-3.5`}):(0,Z.jsx)(ei,{className:`size-3.5`})})]}),!u&&(o?t.map(e=>(0,Z.jsx)(Mu,{entry:e,name:e.path,depth:0,area:n,active:r===e.path,action:i,busy:a,onAction:s,onRestore:c,onOpen:l},`${e.path}:${e.old_path??``}`)):(0,Z.jsx)(Nu,{nodes:f,depth:0,area:n,activePath:r,action:i,busy:a,onAction:s,onRestore:c,onOpen:l}))]})}function Mu({entry:e,name:t,depth:n,area:r,active:i,action:a,busy:o,onAction:s,onRestore:c,onOpen:l}){let u=Su(e.status),d=a===`stage`;return(0,Z.jsxs)(`div`,{className:V(`sidebar-row group flex items-center gap-1 pr-[calc(0.75rem-var(--ui-list-inset))] transition-colors hover:bg-explorer-hover`,i&&`bg-explorer-selection`),style:{paddingLeft:12+n*12},children:[(0,Z.jsxs)(`button`,{type:`button`,title:e.path,onClick:()=>l(e.path,{root:void 0,gitArea:r}),onDoubleClick:()=>l(e.path,{preview:!1,root:void 0,gitArea:r}),className:`flex min-w-0 flex-1 items-center gap-1.5 py-1 text-left`,children:[(0,Z.jsx)(`span`,{className:V(`w-3 shrink-0 text-center font-mono text-xs`,u.colourClass),children:u.letter}),(0,Z.jsx)(lu,{name:e.path.split(`/`).pop()??e.path,className:`size-4`}),(0,Z.jsx)(Vl,{text:t,className:`text-xs text-fg`,hoverClass:ku})]}),c&&(0,Z.jsx)(Au,{label:`Restore ${e.path}`,disabled:o,onClick:()=>c(e),children:(0,Z.jsx)(ai,{className:`size-3.5`})}),(0,Z.jsx)(Au,{label:`${d?`Stage`:`Unstage`} ${e.path}`,disabled:o,onClick:()=>s(Eu([e])),children:d?(0,Z.jsx)(fi,{className:`size-3.5`}):(0,Z.jsx)(ei,{className:`size-3.5`})})]})}function Nu({nodes:e,depth:t,area:n,activePath:r,action:i,busy:a,onAction:o,onRestore:s,onOpen:c}){let[l,u]=(0,X.useState)(new Set),d=i===`stage`;return(0,Z.jsx)(Z.Fragment,{children:e.map(e=>{if(e.type===`file`)return(0,Z.jsx)(Mu,{entry:e.entry,name:e.name,depth:t,area:n,active:r===e.path,action:i,busy:a,onAction:o,onRestore:s,onOpen:c},`${e.entry.path}:${e.entry.old_path??``}`);let f=l.has(e.path);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`sidebar-row group flex items-center gap-1 pr-[calc(0.75rem-var(--ui-list-inset))] transition-colors hover:bg-explorer-hover`,style:{paddingLeft:12+t*12},children:[(0,Z.jsxs)(`button`,{type:`button`,title:e.path,onClick:()=>u(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),className:`flex min-w-0 flex-1 items-center gap-1 py-1 text-left`,children:[f?(0,Z.jsx)(qn,{className:`size-3.5 shrink-0 text-fg-gold`}):(0,Z.jsx)(Ir,{className:`size-3.5 shrink-0 text-fg-gold`}),(0,Z.jsx)(Vl,{text:e.name,className:`text-xs text-fg-secondary`,hoverClass:ku})]}),(0,Z.jsx)(Au,{label:`${d?`Stage`:`Unstage`} ${e.path}`,disabled:a,onClick:()=>o(Eu(gu(e))),children:d?(0,Z.jsx)(fi,{className:`size-3.5`}):(0,Z.jsx)(ei,{className:`size-3.5`})})]}),!f&&(0,Z.jsx)(Nu,{nodes:e.children,depth:t+1,area:n,activePath:r,action:i,busy:a,onAction:o,onRestore:s,onOpen:c})]},e.path)})})}function Pu(e){return e.detached?`Detached at ${e.head?.slice(0,8)??`HEAD`}`:e.branch??`Unborn branch`}function Fu(e){return[Pu(e),e.upstream,e.ahead>0?`${e.ahead} ahead`:null,e.behind>0?`${e.behind} behind`:null].filter(e=>e!=null).join(` · `)}function Iu({session:e,targetRoot:t,repository:n,selected:r,restoreSupported:i=!1,activePath:a,onSelect:o,onOpen:s}){let[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(``),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),v=nt(e,t),y=[...n.conflicts,...n.staged,...n.unstaged],b=v.isPending,x=async(e,t)=>{try{await v.mutateAsync(e),U.success(t)}catch(e){U.error(e instanceof Error?e.message:`Git operation failed`)}},S=(e,t)=>{x({action:e,repository:n.root,paths:t},e===`stage`?`Staged`:`Unstaged`)},C=async()=>{let e=f.trim();if(!e||b)return;let t=!1;if(n.staged.length===0){if(n.conflicts.length>0){U.error(`Resolve and stage merge changes before committing`);return}if(n.unstaged.length===0){U.error(`There are no changes to commit`);return}if(t=window.confirm(`Nothing is staged. Stage every change and commit it?`),!t)return}try{await v.mutateAsync({action:`commit`,repository:n.root,message:e,stage_all:t}),p(``),U.success(`Committed`)}catch(e){U.error(e instanceof Error?e.message:`Commit failed`)}},w=e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),C())},T=(e,t)=>s(e,{...t,root:n.root});return(0,Z.jsxs)(`section`,{className:`mx-2 border-t border-border py-1 first:border-t-0`,"data-selected":r||void 0,onFocus:o,children:[(0,Z.jsxs)(`div`,{className:`flex h-8 items-center gap-1 pl-2 pr-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{o(),l(e=>!e)},className:`group/repository flex min-w-0 flex-1 items-center gap-1.5 text-left transition-colors hover:text-fg`,children:[c?(0,Z.jsx)(qn,{className:`size-3 shrink-0`}):(0,Z.jsx)(Ir,{className:`size-3 shrink-0`}),(0,Z.jsxs)(Vl,{text:`${n.name} ${n.relative_path}`,title:`${n.name} ${n.relative_path}`,className:`text-xs`,hoverClass:Ou,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:n.name}),` `,(0,Z.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:n.relative_path})]}),y.length>0&&(0,Z.jsx)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:y.length})]}),!c&&n.initialised&&y.length>0&&(0,Z.jsx)(Au,{label:u?`Show changes as tree`:`Show changes as flat list`,onClick:()=>d(e=>!e),children:u?(0,Z.jsx)(Jr,{className:`size-3.5`}):(0,Z.jsx)(ui,{className:`size-3.5`})})]}),!c&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`group flex min-h-7 items-center px-3 text-2xs text-fg-muted`,children:(0,Z.jsx)(Vl,{text:Fu(n),title:Fu(n),hoverClass:Du})}),n.initialised?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`px-3 pb-1.5 pt-1`,children:[(0,Z.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),onKeyDown:w,rows:2,placeholder:`Commit message`,"aria-label":`Commit message for ${n.name}`,className:`w-full resize-none rounded-sm bg-elevated px-2 py-1.5 text-xs text-fg outline-none placeholder:text-fg-muted focus:ring-1 focus:ring-focus`}),(0,Z.jsxs)(`div`,{className:`mt-1 flex items-center gap-0.5`,children:[n.has_remote&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Au,{label:`Fetch`,disabled:b,className:`flex size-7 shrink-0 items-center justify-center p-0`,onClick:()=>void x({action:`fetch`,repository:n.root},`Fetched`),children:(0,Z.jsx)(pt,{className:`size-3.5`})}),n.upstream&&(0,Z.jsx)(Au,{label:`Pull`,disabled:b,className:`flex size-7 shrink-0 items-center justify-center p-0`,onClick:()=>void x({action:`pull`,repository:n.root},`Pulled`),children:(0,Z.jsx)(Qr,{className:`size-3.5 rotate-180`})}),n.branch&&(0,Z.jsx)(Au,{label:n.upstream?`Push`:`Publish branch`,disabled:b,className:`flex size-7 shrink-0 items-center justify-center p-0`,onClick:()=>void x({action:`push`,repository:n.root,set_upstream:!n.upstream},n.upstream?`Pushed`:`Branch published`),children:n.upstream?(0,Z.jsx)(ri,{className:`size-3.5`}):(0,Z.jsx)(Qr,{className:`size-3.5`})})]}),(0,Z.jsx)(`button`,{type:`button`,disabled:b||f.trim().length===0,onClick:()=>void C(),className:`flex h-7 min-w-0 flex-1 items-center justify-center rounded-sm bg-action px-2 text-xs text-action-ink transition-colors hover:bg-action-hover disabled:cursor-not-allowed disabled:opacity-40`,children:`Commit`})]})]}),(0,Z.jsx)(ju,{title:`Merge Changes`,entries:n.conflicts,area:`unstaged`,activePath:a,action:`stage`,busy:b,flat:u,onAction:e=>S(`stage`,e),onOpen:T}),(0,Z.jsx)(ju,{title:`Staged Changes`,entries:n.staged,area:`staged`,activePath:a,action:`unstage`,busy:b,flat:u,onAction:e=>S(`unstage`,e),onOpen:T}),(0,Z.jsx)(ju,{title:`Changes`,onRestore:i?e=>{h(e),_(!0)}:void 0,entries:n.unstaged,area:`unstaged`,activePath:a,action:`stage`,busy:b,flat:u,onAction:e=>S(`stage`,e),onOpen:T}),y.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No changes.`})]}):(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Submodule not initialised.`})]}),(0,Z.jsx)(Ln,{open:g,onOpenChange:_,children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsxs)(In,{children:[m?.status===`untracked`?`Delete`:`Restore`,` “`,m?.path,`”?`]}),(0,Z.jsx)(Nn,{children:m?.status===`untracked`?`This file is not tracked by Git. Restoring it permanently deletes the file. There is no undo.`:`This discards the unstaged changes to this file. Any staged changes are kept. There is no undo.`})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:()=>_(!1),children:`Cancel`}),(0,Z.jsx)(q,{variant:`danger`,disabled:b,onClick:()=>{!m||b||!i||(x({action:`restore`,repository:n.root,path:m.path,delete_untracked:m.status===`untracked`},`Restored`),_(!1))},children:m?.status===`untracked`?`Delete file`:`Restore`})]})]})})]})}function Lu({header:e,session:t,root:n,activeDiffPath:r,onOpenDiff:i,onOpenCommitFile:a}){let{height:o,handle:s}=Il(`changes-uncommitted`,240,{sized:`above`,min:80}),l=Le(),u=l.data!==void 0&&h(l.data.protocol),d=ot(t,{root:n,enabled:u}),[f,p]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!u||!d.data)return;let e=d.data.repositories;(!f||!e.some(e=>e.root===f))&&p(e[0]?.root??null)},[u,d.data,f]);let m=u?f??n:n;return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col`,children:[(0,Z.jsxs)(`section`,{className:`workspace-surface island-outline flex shrink-0 flex-col bg-surface`,style:{height:o,maxHeight:`70%`},children:[e,u?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-1`,children:d.isPending?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Loading repositories…`}):d.error?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:d.error instanceof Error?d.error.message:`Failed to load repositories`}):d.data.repositories.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No Git repositories.`}):d.data.repositories.map(e=>(0,Z.jsx)(Iu,{restoreSupported:(!P()||!1)&&c(l.data?.protocol),session:t,targetRoot:n,repository:e,selected:f===e.root,activePath:r,onSelect:()=>p(e.root),onOpen:i},`${t}:${n??``}:${e.root}`))}):(0,Z.jsx)(bu,{session:t,root:n,activePath:r,onOpen:i})]}),(0,Z.jsx)(Ll,{handle:s,label:`Resize the uncommitted changes`}),(0,Z.jsxs)(`div`,{className:`workspace-surface island-outline flex min-h-0 flex-1 flex-col bg-surface`,children:[(0,Z.jsx)(`div`,{className:`flex h-7 shrink-0 items-center px-3`,children:(0,Z.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`History`})}),(0,Z.jsx)(iu,{session:t,root:m,onOpenCommitFile:(e,t,n)=>a(e,t,{...n,root:m})})]})]})}var Ru=`puddle.explorerClipboard.v1`;function zu(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.sid==`string`&&typeof t.directory==`string`&&(t.root===void 0||typeof t.root==`string`)&&(t.host===void 0||typeof t.host==`string`)}function Bu(e){if(e===null)return null;try{let t=JSON.parse(e);return typeof t.id!=`string`||t.mode!==`cut`&&t.mode!==`copy`||!Array.isArray(t.paths)||t.paths.length===0||!t.paths.every(e=>typeof e==`string`)||!zu(t.source)?null:t}catch{return null}}function Vu(){if(typeof localStorage>`u`)return null;try{return Bu(localStorage.getItem(Ru))}catch{return null}}var Hu=Vu(),Uu=new Set;function Wu(e,t){if(Hu=e,t&&typeof localStorage<`u`)try{e===null?localStorage.removeItem(Ru):localStorage.setItem(Ru,JSON.stringify(e))}catch{}for(let e of Uu)e()}typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===Ru&&Wu(Bu(e.newValue),!1)});function Gu(){return globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random()}`}function Ku(e){return e?`${e.username}\0${e.hostname}\0${e.home}`:void 0}function qu(e,t){return e.directory===t.directory}function Ju(e,t){return e.host===void 0||t.host===void 0||e.host===t.host}function Yu(e,t){return e.host!==void 0&&e.host===t.host}function Xu(e,t,n){e.length!==0&&Wu({id:Gu(),paths:e,mode:t,source:n},!0)}function Zu(e,t){Hu?.id!==e||Hu.mode!==`cut`||Wu(t.length===0?null:{...Hu,paths:t},!0)}function Qu(e){return Uu.add(e),()=>Uu.delete(e)}function $u(){return Hu}function ed(){return(0,X.useSyncExternalStore)(Qu,$u,()=>null)}var td={"image/avif":`avif`,"image/bmp":`bmp`,"image/gif":`gif`,"image/heic":`heic`,"image/heif":`heif`,"image/jpeg":`jpg`,"image/png":`png`,"image/svg+xml":`svg`,"image/tiff":`tiff`,"image/webp":`webp`};function nd(e,t){return{items:Array.from(e??[]).map(e=>({entry:e.webkitGetAsEntry?.()??null,file:e.kind===`file`?e.getAsFile():null,mime:e.type})),fallback:Array.from(t)}}function rd(e){return e.every(({entry:e,file:t})=>e===null&&t===null)}function id(e,t){let n=(e.type||t).toLowerCase().split(`;`,1)[0],r=td[n];if(r)return r;let i=e.name.match(/\.([a-z0-9]{1,10})$/i)?.[1];return i?i.toLowerCase():n.slice(6).replace(/^x-/,``).split(`+`,1)[0].replace(/[^a-z0-9-]/g,``)||`image`}function ad(e,t,n,r){let i=(e,t=2)=>String(e).padStart(t,`0`);return`Screenshot ${`${e.getFullYear()}-${i(e.getMonth()+1)}-${i(e.getDate())}`} at ${`${i(e.getHours())}.${i(e.getMinutes())}.${i(e.getSeconds())}.${i(e.getMilliseconds(),3)}`}${r===0?``:` (${r+1})`}.${id(t,n)}`}async function od(e){let t=e.createReader(),n=[];for(;;){let e=await new Promise((e,n)=>t.readEntries(e,n));if(e.length===0)return n;n.push(...e)}}function sd(e){return new Promise((t,n)=>e.file(t,n))}async function cd(e,t,n){if(e.isFile){let r=await sd(e);n.push(t?new File([r],`${t}/${e.name}`,{type:r.type,lastModified:r.lastModified}):r)}else if(e.isDirectory){let r=await od(e),i=t?`${t}/${e.name}`:e.name;for(let e of r)await cd(e,i,n)}}async function ld(e,t){let n=e.items;if(rd(n))return e.fallback;if(!t)return n.some(({entry:e})=>e?.isDirectory)&&U.error(`This daemon can't take folders — update it, or zip them first`),n.filter(({entry:e})=>e?.isDirectory!==!0).map(({file:e})=>e).filter(e=>e!==null);let r=[];for(let{entry:e,file:t}of n)e?.isDirectory?await cd(e,``,r):t&&r.push(t);return r}function ud(e,t,n){return ld(nd(e,t),n)}function dd(e,t){return t.length>0||Array.from(e??[]).some(e=>e.kind===`file`)}function fd(e,t,n,r=new Date){let i=nd(e,t),a=rd(i.items),o=new Map;for(let{file:e,mime:t}of i.items){let n=e?.type||t;e&&n.startsWith(`image/`)&&o.set(e,n)}if(a)for(let e of i.fallback)e.type.startsWith(`image/`)&&o.set(e,e.type);return ld(i,n).then(e=>{let t=0;return e.map(e=>{let n=o.get(e);if(!n)return e;let i=new File([e],ad(r,e,n,t),{type:e.type||n,lastModified:e.lastModified});return t+=1,i})})}var pd=(e,t)=>e instanceof Error?e.message:t;function md(e,t,n=t??``){let r=Ye(),i=(0,X.useCallback)(()=>{r.invalidateQueries({queryKey:[`wt-tree`,e]}),r.invalidateQueries({queryKey:[`wt-git-status`,e]})},[r,e]),a=(0,X.useCallback)(e=>{r.invalidateQueries({queryKey:[`wt-tree`,e.sid]}),r.invalidateQueries({queryKey:[`wt-git-status`,e.sid]})},[r]);return(0,X.useMemo)(()=>({async create(n,r,a){try{let o=await tt(e,Xs(n,r),a,t);return i(),o.path}catch(e){return U.error(pd(e,`Couldn't create ${r}`)),null}},async rename(n,r){let a=Xs(n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)):``,r);try{let r=await vt(e,n,a,t);return i(),r.path}catch(e){return U.error(pd(e,`Couldn't rename ${Ks(n)}`)),null}},async move(n,r){let a=await Promise.allSettled(n.map(n=>vt(e,n,Xs(r,Ks(n)),t)));i();let o=a.filter(e=>e.status===`rejected`);o.length>0&&U.error(n.length===1?pd(o[0].reason,`Couldn't move ${Ks(n[0])}`):`Couldn't move ${o.length} item${o.length>1?`s`:``}`)},async remove(n){let r=await Promise.allSettled(n.map(n=>et(e,n,t)));i();let a=r.filter(e=>e.status===`rejected`).length;a>0?U.error(`Couldn't delete ${a} item${a>1?`s`:``}`):U.success(n.length===1?`Deleted ${Ks(n[0])}`:`Deleted ${n.length} items`)},async paste(r,o){let s={sid:e,root:t,directory:n},c=qu(r.source,s),l=await Promise.allSettled(r.paths.map(n=>{let i=Xs(o,Ks(n));return c?(r.mode===`cut`?vt:ut)(e,n,i,t):_t(e,{operation:r.mode===`cut`?`move`:`copy`,source:{session_id:r.source.sid,root:r.source.root},from:n,to:i},t)}));i(),!c&&r.mode===`cut`&&a(r.source);let u=r.paths.filter((e,t)=>l[t]?.status===`rejected`);return u.length>0&&U.error(`Couldn't paste ${u.length} item${u.length>1?`s`:``}`),u}}),[e,t,n,i,a])}function hd(e,t,n){return n&&n.type!==`dir`||(e.includes(`/`)?e.slice(0,e.lastIndexOf(`/`)):``)===t?!1:t===``||!`${t}/`.startsWith(`${e}/`)}function gd({sid:e,root:t,rootPath:n,readOnly:r,onOpenFile:i,navigation:a}){let s=(0,X.useRef)(!1),c=(0,X.useRef)(!r);(0,X.useLayoutEffect)(()=>(s.current=!0,()=>{s.current=!1}),[]),(0,X.useLayoutEffect)(()=>{c.current=!r},[r]);let l=Ye(),u=md(e,t,n),{treeKey:d,expand:f,focusedPath:p,visibleRows:m}=a,h=(0,X.useCallback)((n,i)=>{i.length===0||r||!s.current||!c.current||st(e,n,i,t).then(()=>{l.invalidateQueries({queryKey:d(n)}),l.invalidateQueries({queryKey:[`wt-git-status`,e]}),U.success(i.length===1?`Uploaded ${i[0].name}`:`Uploaded ${i.length} files`)}).catch(e=>U.error(e instanceof Error?e.message:`Upload failed`))},[e,t,r,l,d]),g=Le().data?.protocol,_=ze(),v=(0,X.useMemo)(()=>({sid:e,root:t,directory:n,host:Ku(_.data)}),[e,t,n,_.data]),y=!g||g.major>9||g.major===9&&g.minor>=2,b=(0,X.useCallback)((e,t,n)=>{ud(t,n,y).then(t=>h(e,t)).catch(e=>U.error(e instanceof Error?e.message:`Couldn't read the dropped folder`))},[h,y]),x=ed(),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=()=>T(null);return window.addEventListener(`dragend`,e),()=>window.removeEventListener(`dragend`,e)},[]);let O=(0,X.useCallback)(e=>Xu($s(e),`cut`,v),[v]),k=(0,X.useCallback)(e=>Xu($s(e),`copy`,v),[v]),A=x!==null&&Ju(x.source,v),ee=x!==null&&qu(x.source,v),j=!r&&(A&&ee||x!==null&&Yu(x.source,v)&&o(g)),M=(0,X.useCallback)(e=>x?.mode===`cut`&&Ju(x.source,v)&&qu(x.source,v)&&x.paths.includes(e),[x,v]),N=(0,X.useCallback)(e=>{if(!x||r)return;let t=qu(x.source,v);if(!Ju(x.source,v)){U.error(`That filetree clipboard belongs to another daemon host.`);return}if(!t&&!Yu(x.source,v)){U.error(`Copy again after daemon host information finishes loading.`);return}if(!t&&!o(g)){U.error(`Cross-filetree paste requires a daemon with protocol 16.3.`);return}u.paste(x,e).then(e=>{x.mode===`cut`&&Zu(x.id,e)})},[x,u,g,r,v]),P=(0,X.useCallback)((e,t)=>{if(r||S)return!1;let n=p?m.find(e=>e.path===p):void 0,i=n?n.type===`dir`?n.path:n.parentDir:``;return dd(e,t)?(fd(e,t,y).then(e=>h(i,e)).catch(e=>U.error(e instanceof Error?e.message:`Couldn't read the pasted files`)),!0):j?(N(i),!0):!1},[r,S,p,m,y,h,j,N]),F=(0,X.useCallback)(e=>{r||C({mode:`rename`,path:e})},[r]),I=(0,X.useCallback)((e,t)=>{r||(e!==``&&f(e),C({mode:`create`,parentDir:e,kind:t}))},[f,r]),te=(0,X.useCallback)(()=>C(null),[]),ne=(0,X.useCallback)(t=>{let n=t.trim(),a=S;if(C(null),!(r||!a||n===``))if(a.mode===`rename`){if(n===Ks(a.path))return;u.rename(a.path,n)}else u.create(a.parentDir,n,a.kind).then(t=>{t&&a.kind===`file`&&s.current&&i?.(e,t)})},[S,u,i,e,r]),re=(0,X.useCallback)(e=>{if(r)return;let t=$s(e);t.length>0&&D(t)},[r]),ie=(0,X.useCallback)(()=>{let e=E;D(null),e&&!r&&u.remove(e)},[E,u,r]),ae=(0,X.useCallback)(()=>D(null),[]);return{clipboard:x,canPaste:j,isCut:M,cut:O,copy:k,paste:N,editing:S,beginRename:F,beginCreate:I,cancelEdit:te,commitEdit:ne,requestDelete:re,copyPathToClipboard:(0,X.useCallback)((e,t)=>{let r=e.map(e=>t?e:Xs(n,e)).join(`
16
+ `);navigator.clipboard.writeText(r);let i=t?`Relative path`:`Path`;U.success(e.length>1?`${e.length} ${i.toLowerCase()}s copied`:`${i} copied`)},[n]),download:(0,X.useCallback)(n=>{(async()=>{for(let r of $s(n))await lt(e,r,t)})().catch(e=>U.error(e instanceof Error?e.message:`Download failed`))},[e,t]),onUpload:h,onDropUpload:b,onClipboardPaste:P,dropTarget:w,setDropTarget:T,onInternalDrop:(0,X.useCallback)((e,t)=>{if(r)return;let n=$s(t).filter(t=>hd(t,e));n.length>0&&u.move(n,e)},[u,r]),pendingDelete:E,confirmDelete:ie,cancelDelete:ae}}function _d(e,t,n){return e!==null&&e.id===t&&n-e.at<1500}function vd({sid:e,root:t,rootPath:n,readOnly:r,onOpenFile:i,navigation:a,actions:o}){let{visibleRows:s,focusedPath:c,expanded:l,selection:u,toggle:d,expand:f,selectOnly:p,selectClick:m,focus:h,reveal:g,actionTargets:_}=a,{editing:v,beginRename:y,requestDelete:b,copy:x,cut:S,copyPathToClipboard:C}=o;(0,X.useEffect)(()=>wc(e=>{(e.directory===void 0?e.root!==t:e.directory!==n)||(Tc(),g(e),e.renameTarget&&y(e.path))}),[t,n,g,y]);let w=(0,X.useRef)(null),T=(0,X.useRef)(null),E=(0,X.useCallback)(()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]);(0,X.useEffect)(()=>(r&&E(),E),[r,E]);let D=(0,X.useCallback)((t,n)=>{if(E(),m(t.path,n))return;let a=Date.now(),o=T.current;if(T.current={id:t.path,at:a},t.type!==`dir`&&!r&&!v&&u.size===1&&u.has(t.path)&&_d(o,t.path,a)){w.current=window.setTimeout(()=>{w.current=null,y(t.path)},500);return}p(t.path),t.type===`dir`?d(t.path):i?.(e,t.path)},[m,p,y,d,i,e,u,v,r,E]),O=(0,X.useCallback)(t=>{E(),t.type!==`dir`&&i?.(e,t.path,{preview:!1})},[i,e,E]),k=(0,X.useRef)({buffer:``,at:0});return{onRowClick:D,onRowDoubleClick:O,handleKeyDown:(0,X.useCallback)(t=>{if(v)return;let n=s;if(n.length===0)return;let r=c?n.findIndex(e=>e.path===c):-1,a=r>=0?n[r]:void 0,o=t.metaKey||t.ctrlKey,u=r=>{E(),T.current=null;let a=n[Math.max(0,Math.min(r,n.length-1))];h(r,t.shiftKey),!t.shiftKey&&!o&&!t.altKey&&a?.type!==`dir`&&a&&i?.(e,a.path,{preview:!0})};switch(t.key){case`ArrowDown`:t.preventDefault(),u(r+1);return;case`ArrowUp`:t.preventDefault(),u(r<=0?0:r-1);return;case`ArrowRight`:t.preventDefault(),a?.type===`dir`&&!l.has(a.path)?f(a.path):a?.type===`dir`&&h(r+1,!1);return;case`ArrowLeft`:if(t.preventDefault(),a?.type===`dir`&&l.has(a.path))d(a.path);else if(a){let e=n.findIndex(e=>e.path===a.parentDir);e>=0&&h(e,!1)}return;case`Enter`:case` `:if(t.preventDefault(),!a)return;a.type===`dir`?d(a.path):i?.(e,a.path,{preview:t.key!==`Enter`});return;case`F2`:t.preventDefault(),a&&y(a.path);return;case`Delete`:t.preventDefault(),b(_());return;case`Backspace`:o&&(t.preventDefault(),b(_()));return}if(o&&(t.key===`c`||t.key===`C`)){t.preventDefault();let e=_();t.altKey?C(e,t.shiftKey):x(e);return}if(o&&(t.key===`x`||t.key===`X`)){t.preventDefault(),S(_());return}if(!o&&!t.altKey&&t.key.length===1&&/\S/.test(t.key)){let e=Date.now(),i=k.current;i.buffer=e-i.at>700?t.key:i.buffer+t.key,i.at=e;let a=i.buffer.toLowerCase(),o=r+1;for(let e=0;e<n.length;e++){let t=n[(o+e)%n.length];if(t.name.toLowerCase().startsWith(a)){h(n.findIndex(e=>e.path===t.path),!1);break}}}},[h,v,s,c,l,f,d,i,e,y,b,_,x,S,C,E])}}function yd(e,t){let n=Ye(),r=(0,X.useCallback)(n=>t===void 0?[`wt-tree`,e,n]:[`wt-tree`,e,n,t],[e,t]),[i,a]=(0,X.useState)(new Set),[o,s]=(0,X.useState)(new Set),[c,l]=(0,X.useState)(null),u=(0,X.useRef)(null),[d,f]=(0,X.useState)(0);(0,X.useEffect)(()=>n.getQueryCache().subscribe(n=>{if(n.type!==`added`&&n.type!==`removed`&&n.type!==`updated`)return;let r=n.query.queryKey;Array.isArray(r)&&r[0]===`wt-tree`&&r[1]===e&&r[3]===t&&f(e=>e+1)}),[n,e,t]);let p=(0,X.useMemo)(()=>rc(e=>n.getQueryData(r(e)),i),[n,r,i,d]),m=(0,X.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),h=(0,X.useCallback)(e=>{a(t=>t.has(e)?t:new Set(t).add(e))},[]),g=(0,X.useCallback)(()=>a(new Set),[]),_=(0,X.useCallback)(e=>{s(new Set([e])),l(e),u.current=e},[]),v=(0,X.useCallback)((e,t)=>(l(e),t.metaKey||t.ctrlKey?(s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),u.current=e,!0):t.shiftKey&&u.current?(s(new Set(ic(p,u.current,e))),!0):!1),[p]),y=(0,X.useCallback)((e,t)=>{let n=p[Math.max(0,Math.min(p.length-1,e))];n&&(l(n.path),t&&u.current?s(new Set(ic(p,u.current,n.path))):(s(new Set([n.path])),u.current=n.path))},[p]),[b,x]=(0,X.useState)(null),S=(0,X.useCallback)(e=>{for(let t of Js(e.path))h(t);e.expandTarget&&e.path!==``&&h(e.path),_(e.path),x(e.path)},[h,_]);return(0,X.useEffect)(()=>{if(b===null)return;let e=document.querySelector(`[data-explorer-root] [data-path="${CSS.escape(b)}"]`);if(e){e.scrollIntoView({block:`nearest`}),x(null);return}let t=window.setTimeout(()=>x(null),4e3);return()=>window.clearTimeout(t)},[b,p]),{treeKey:r,expanded:i,selection:o,focusedPath:c,visibleRows:p,toggle:m,expand:h,collapseAll:g,selectOnly:_,selectClick:v,focus:y,reveal:S,actionTargets:(0,X.useCallback)(()=>c&&o.has(c)?[...o]:c?[c]:[...o],[c,o])}}var bd=(0,X.createContext)(null),xd=(0,X.createContext)(null);function Sd(){let e=(0,X.useContext)(bd);if(!e)throw Error(`explorer components must render inside <ExplorerProvider>`);return e}function Cd(){return(0,X.useContext)(xd)}function wd(e){return(0,Z.jsx)(Td,{...e},JSON.stringify([e.session.id,e.root,e.root??e.session.worktree_path]))}function Td({session:e,root:t,readOnly:n=!1,onOpenFile:r,onOpenTerminal:i,compilableExtensions:a,onOpenCompilationSettings:o,activePath:s,children:c}){let l=e.id,u=Ye(),d=t??e.worktree_path,f=yd(l,t),p=gd({sid:l,root:t,rootPath:d,readOnly:n,onOpenFile:r,navigation:f}),m=vd({sid:l,root:t,rootPath:d,readOnly:n,onOpenFile:r,navigation:f,actions:p}),g=Le().data?.protocol,_=it(l,{root:t,enabled:t===void 0||g!==void 0&&h(g)}),v=(0,X.useMemo)(()=>Cu(_.data?.entries??[]),[_.data]),y=_.refetch,b=(0,X.useCallback)(()=>{u.invalidateQueries({queryKey:[`wt-tree`,l]}),y()},[u,l,y]),x={sid:l,projectId:e.project_id,rootPath:d,root:t,readOnly:n,onOpenFile:r,onOpenTerminal:i,activePath:s,compilableExtensions:a,onOpenCompilationSettings:o,statusMap:v,refresh:b,expanded:f.expanded,selection:f.selection,focusedPath:f.focusedPath,visibleRows:f.visibleRows,toggle:f.toggle,collapseAll:f.collapseAll,selectOnly:f.selectOnly,...p,...m},S=(0,X.useMemo)(()=>({refresh:b,collapseAll:f.collapseAll}),[b,f.collapseAll]);return(0,Z.jsx)(xd.Provider,{value:S,children:(0,Z.jsx)(bd.Provider,{value:x,children:c})})}function Ed(e,t){if(!t)return e;let n=t.endsWith(`/`)?t.slice(0,-1):t;return n===``||n===`/`?e:e===n?`~`:e.startsWith(`${n}/`)?`~${e.slice(n.length)}`:e}var Dd=`application/x-puddle-tab`;function Od(){return z()!==null&&_e()?.windows?.transfers?.beginTabDrag!==void 0}function kd(e,t={}){let n=z(),r=Hs(),i=n&&_e()?.windows?.transfers;if(!r||!n||!i?.beginTabDrag)return Ws(e);let a=t.projectId??(n.identity.kind===`host`?window.location.pathname.match(/^\/project\/([0-9a-f]{10})(?:\/|$)/)?.[1]:n.identity.projectId);if(!a)return Ws(e);let o=crypto.randomUUID();return i.beginTabDrag({token:o,profileId:r.profileId,projectId:a,ref:e,paneId:t.paneId}).catch(J),JSON.stringify({...r,token:o,ref:e,paneId:t.paneId})}function Ad(e){return jd(e)?.ref??null}function jd(e){try{if(e.length>128*1024)return null;let t=D.safeParse(JSON.parse(e));return t.success?Us(t.data)?{ref:t.data.ref,paneId:t.data.paneId}:null:{ref:C.parse(Gs(e))}}catch{return null}}function Md(e){return e.includes(Dd)}function Nd({path:e}){let t=P(),n=Ke({queryKey:[`frontend-file-manager`],queryFn:async()=>b.parse(await he(`GET`,`/frontend/file-manager`)),enabled:!t,staleTime:1/0,retry:!1});return t||!n.data?.name||!e?null:(0,Z.jsxs)(H,{onSelect:()=>{P()||he(`POST`,`/frontend/file-manager`,{path:e}).catch(e=>U.error(e instanceof Error?e.message:`Could not reveal this path.`))},children:[`Reveal in `,n.data.name]})}function Pd({children:e}){return(0,Z.jsx)(`span`,{className:`ml-auto pl-6 text-2xs text-fg-muted tabular-nums`,children:e})}function Fd({absolutePath:e,readOnly:t,canPaste:n,onCut:r,onCopy:i,onPaste:a,onCopyPath:o,onCopyRelativePath:s,onReveal:c,onOpenWindow:l,onCompilationSettings:u,onRename:d,onDelete:f,onDownload:p}){return(0,Z.jsxs)(Z.Fragment,{children:[l&&(0,Z.jsx)(H,{onSelect:l,children:`Open file in window`}),!t&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(H,{onSelect:r,children:[`Cut `,(0,Z.jsx)(Pd,{children:`⌘X`})]}),(0,Z.jsxs)(H,{onSelect:i,children:[`Copy `,(0,Z.jsx)(Pd,{children:`⌘C`})]}),(0,Z.jsxs)(H,{disabled:!n,onSelect:a,children:[`Paste `,(0,Z.jsx)(Pd,{children:`⌘V`})]}),(0,Z.jsx)(vn,{})]}),(0,Z.jsxs)(H,{onSelect:o,children:[`Copy Path `,(0,Z.jsx)(Pd,{children:`⌥⌘C`})]}),(0,Z.jsxs)(H,{onSelect:s,children:[`Copy Relative Path `,(0,Z.jsx)(Pd,{children:`⌥⇧⌘C`})]}),c&&(0,Z.jsx)(H,{onSelect:c,children:`Reveal in Filetree`}),(0,Z.jsx)(Nd,{path:e}),u&&(0,Z.jsx)(H,{onSelect:u,children:`Compilation Settings…`}),(0,Z.jsx)(vn,{}),!t&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(H,{onSelect:d,children:[`Rename… `,(0,Z.jsx)(Pd,{children:`F2`})]}),(0,Z.jsxs)(H,{onSelect:f,children:[`Delete `,(0,Z.jsx)(Pd,{children:`⌘⌫`})]}),(0,Z.jsx)(vn,{})]}),(0,Z.jsx)(H,{onSelect:p,children:`Download`})]})}var Id=16,Ld=`group-hover/treerow:[transform:translateX(var(--tail))]`;function Rd(e,t){let n=document.createElement(`div`);n.textContent=`${t} items`,n.className=`fixed -top-12 left-0 rounded-md bg-elevated px-2 py-1 text-xs text-fg`,document.body.appendChild(n),e.dataTransfer.setDragImage(n,12,12),requestAnimationFrame(()=>n.remove())}function zd({depth:e,initial:t,icon:n,onCommit:r,onCancel:i}){let a=(0,X.useRef)(null),o=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let e=a.current;if(!e)return;let n=()=>{e.focus();let n=t.lastIndexOf(`.`);e.setSelectionRange(0,n>0?n:t.length)};n();let r=requestAnimationFrame(()=>{document.activeElement!==e&&n()});return()=>cancelAnimationFrame(r)},[t]);let s=()=>{o.current||(o.current=!0,r(a.current?.value??``))};return(0,Z.jsxs)(`div`,{className:`flex h-[var(--ui-row-height)] items-center gap-[var(--ui-item-gap)] rounded-[var(--ui-radius)] pr-2`,style:{paddingLeft:e*Id+4},children:[(0,Z.jsx)(`span`,{className:`size-3.5 shrink-0`}),n,(0,Z.jsx)(`input`,{ref:a,defaultValue:t,spellCheck:!1,onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?s():e.key===`Escape`&&(o.current=!0,i())},onBlur:s,className:`min-w-0 flex-1 bg-surface text-sm text-fg outline-none`})]})}function Bd({path:e,entry:t,depth:n}){let r=Sd(),i=t.type===`dir`,a=Ba(i?null:{type:`editor`,tab:r.root===void 0?{session:r.sid,path:e}:{kind:`external`,session:r.sid,path:e,root:r.root}},{projectId:r.projectId}),o=i&&r.expanded.has(e),s=i&&r.dropTarget===e,c=!i&&e===r.activePath,l=r.selection.has(e),u=r.isCut(e),d={path:e,name:t.name,type:t.type,depth:n,parentDir:qs(e)},f=r.statusMap.get(e),p=i?Tu(r.statusMap,e):null,m=f?Su(f):p?Su(p):null,h=m?m.colourClass:`text-fg`,g=l&&r.selection.size>1?[...r.selection]:[e],_=i?e:qs(e),v=r.editing?.mode===`rename`&&r.editing.path===e,y=!i&&r.onOpenCompilationSettings!==void 0&&Oc(e,r.compilableExtensions)?{session:r.sid,path:e,...r.root===void 0?{}:{root:r.root}}:null;return v?(0,Z.jsx)(zd,{depth:n,initial:t.name,icon:i?(0,Z.jsx)(uu,{className:m?.colourClass}):(0,Z.jsx)(lu,{name:t.name}),onCommit:r.commitEdit,onCancel:r.cancelEdit}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_n,{children:[(0,Z.jsx)(bn,{asChild:!0,children:(0,Z.jsxs)(`div`,{role:`treeitem`,"data-path":e,"aria-expanded":i?o:void 0,"aria-selected":l,tabIndex:-1,draggable:!r.readOnly,onClick:e=>{e.currentTarget.closest(`[data-explorer-root]`)?.focus(),r.onRowClick(d,e)},onDoubleClick:()=>r.onRowDoubleClick(d),onContextMenu:()=>{l||r.selectOnly(e)},onDragStart:t=>{let n=$s(g);t.dataTransfer.setData(ec,tc(n)),n.length>1&&Rd(t,n.length),!i&&n.length===1&&t.dataTransfer.setData(Dd,kd({type:`editor`,tab:r.root===void 0?{kind:`file`,session:r.sid,path:e}:{kind:`external`,session:r.sid,path:e,root:r.root}})),t.dataTransfer.effectAllowed=`copyMove`},onDragOver:t=>{!i||r.readOnly||(t.preventDefault(),t.stopPropagation(),r.setDropTarget(e))},onDragLeave:e=>{i&&e.currentTarget===e.target&&r.setDropTarget(null)},onDrop:t=>{if(!i||r.readOnly)return;t.preventDefault(),t.stopPropagation(),r.setDropTarget(null);let n=nc(t.dataTransfer.getData(ec));n.length>0?r.onInternalDrop(e,n):r.onDropUpload(e,t.dataTransfer.items,t.dataTransfer.files)},style:{paddingLeft:n*Id+4},className:V(`group/treerow flex h-[var(--ui-row-height)] cursor-pointer items-center gap-[var(--ui-item-gap)] rounded-[var(--ui-radius)] pr-2 text-sm transition-colors`,l?`bg-explorer-selection`:`hover:bg-explorer-hover`,!l&&c&&`bg-explorer-hover`,s&&`bg-selection`,u&&`opacity-50`),children:[i?(0,Z.jsx)(qn,{className:V(`size-3.5 shrink-0 text-fg-muted transition-transform duration-150`,o&&`rotate-90`)}):(0,Z.jsx)(`span`,{className:`size-3.5 shrink-0`}),i?(0,Z.jsxs)(`span`,{className:`relative flex shrink-0`,children:[(0,Z.jsx)(uu,{open:o,dimmed:f===`ignored`,className:m?.colourClass}),t.symlink&&(0,Z.jsx)(Sa,{"aria-hidden":`true`,className:`absolute -bottom-0.5 -right-1 size-2.5 text-fg`})]}):t.symlink||t.type===`symlink`?(0,Z.jsx)(Sa,{"aria-hidden":`true`,className:`size-4.5 shrink-0 text-fg-muted`}):(0,Z.jsx)(lu,{name:t.name,dimmed:f===`ignored`}),(0,Z.jsx)(Vl,{text:t.name,className:h,hoverClass:Ld}),f&&m&&m.letter&&(0,Z.jsx)(`span`,{className:V(`shrink-0 font-mono text-2xs`,m.colourClass),children:m.letter})]})}),(0,Z.jsxs)(Dn,{onCloseAutoFocus:e=>{r.editing&&e.preventDefault()},children:[i&&!r.readOnly&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{onSelect:()=>r.beginCreate(e,`file`),children:`New File…`}),(0,Z.jsx)(H,{onSelect:()=>r.beginCreate(e,`dir`),children:`New Folder…`}),r.onOpenTerminal&&(0,Z.jsx)(H,{onSelect:()=>r.onOpenTerminal?.(e),children:`Open Terminal in Directory`}),(0,Z.jsx)(vn,{})]}),(0,Z.jsx)(Fd,{absolutePath:Zs(r.rootPath,e),readOnly:r.readOnly,canPaste:r.canPaste,onOpenWindow:a,onCut:()=>r.cut(g),onCopy:()=>r.copy(g),onPaste:()=>r.paste(_),onCopyPath:()=>r.copyPathToClipboard(g,!1),onCopyRelativePath:()=>r.copyPathToClipboard(g,!0),onCompilationSettings:y?()=>r.onOpenCompilationSettings?.(y):void 0,onRename:()=>r.beginRename(e),onDelete:()=>r.requestDelete(g),onDownload:()=>r.download(g)})]})]}),i&&o&&(0,Z.jsx)(Vd,{sid:r.sid,path:e,depth:n+1})]})}function Vd({sid:e,path:t,depth:n}){let r=Sd(),i=rt(e,t,r.root),a={paddingLeft:n*Id+4},o=r.editing,s=o?.mode===`create`&&o.parentDir===t?(0,Z.jsx)(Hd,{depth:n,kind:o.kind}):null;if(i.isLoading)return(0,Z.jsxs)(Z.Fragment,{children:[s,(0,Z.jsx)(`div`,{style:a,className:`py-0.5 text-xs text-fg-muted`,children:`Loading…`})]});if(i.isError)return(0,Z.jsx)(`div`,{style:a,className:`py-0.5 text-xs text-fg-muted`,children:i.error instanceof Error?i.error.message:`Couldn't load this folder.`});let c=i.data?.entries??[];return c.length===0&&!s?(0,Z.jsx)(`div`,{style:a,className:`py-0.5 text-xs text-fg-muted`,children:`Empty`}):(0,Z.jsxs)(Z.Fragment,{children:[s,c.map(e=>(0,Z.jsx)(Bd,{path:Xs(t,e.name),entry:e,depth:n},e.name))]})}function Hd({depth:e,kind:t}){let n=Sd(),[r,i]=(0,X.useState)(``);return(0,Z.jsx)(zd,{depth:e,initial:r,icon:t===`dir`?(0,Z.jsx)(uu,{}):(0,Z.jsx)(lu,{name:r||`file`}),onCommit:e=>{i(e),n.commitEdit(e)},onCancel:n.cancelEdit})}function Ud(){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Wd,{}),(0,Z.jsx)(Gd,{})]})}function Wd(){let e=Sd(),t=(0,X.useRef)(null);return(0,X.useEffect)(()=>{!e.focusedPath||!t.current||t.current.querySelector(`[data-path="${CSS.escape(e.focusedPath)}"]`)?.scrollIntoView({block:`nearest`})},[e.focusedPath]),(0,Z.jsxs)(_n,{children:[(0,Z.jsx)(bn,{asChild:!0,children:(0,Z.jsx)(`div`,{ref:t,"data-explorer-root":!0,role:`tree`,tabIndex:0,onKeyDown:e.handleKeyDown,onPaste:t=>{e.onClipboardPaste(t.clipboardData.items,t.clipboardData.files)&&t.preventDefault()},onDragOver:t=>{e.readOnly||(t.preventDefault(),e.setDropTarget(``))},onDragLeave:t=>{t.currentTarget===t.target&&e.setDropTarget(null)},onDrop:t=>{if(e.readOnly)return;t.preventDefault(),e.setDropTarget(null);let n=nc(t.dataTransfer.getData(ec));n.length>0?e.onInternalDrop(``,n):e.onDropUpload(``,t.dataTransfer.items,t.dataTransfer.files)},className:V(`h-full overflow-y-auto px-2 pb-19 pt-1 outline-none compact:pb-16.5`,e.dropTarget===``&&`bg-selection`),children:(0,Z.jsx)(Vd,{sid:e.sid,path:``,depth:0})})}),(0,Z.jsxs)(Dn,{onCloseAutoFocus:t=>{e.editing&&t.preventDefault()},children:[!e.readOnly&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(H,{onSelect:()=>e.beginCreate(``,`file`),children:`New File…`}),(0,Z.jsx)(H,{onSelect:()=>e.beginCreate(``,`dir`),children:`New Folder…`}),e.onOpenTerminal&&(0,Z.jsx)(H,{onSelect:()=>e.onOpenTerminal?.(``),children:`Open Terminal in Directory`}),(0,Z.jsx)(vn,{}),(0,Z.jsx)(H,{disabled:!e.canPaste,onSelect:()=>e.paste(``),children:`Paste`}),(0,Z.jsx)(vn,{})]}),(0,Z.jsx)(H,{onSelect:()=>e.copyPathToClipboard([``],!1),children:`Copy Path`}),(0,Z.jsx)(Nd,{path:e.rootPath}),(0,Z.jsxs)(H,{onSelect:()=>e.download([``]),children:[`Download `,Ks(e.rootPath)||`folder`]})]})]})}function Gd(){let e=Sd(),t=ze().data?.home,n=e.pendingDelete;return(0,Z.jsx)(Ln,{open:n!==null,onOpenChange:t=>!t&&e.cancelDelete(),children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsxs)(In,{children:[`Delete `,n&&n.length===1?`“${Ks(n[0])}”`:`${n?.length??0} items`,`?`]}),(0,Z.jsxs)(Nn,{children:[`This permanently removes `,n&&n.length>1?`them`:`it`,` from`,` `,(0,Z.jsx)(`span`,{className:`text-fg-secondary`,children:Ed(e.rootPath,t)}),`. There is no undo.`]})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:e.cancelDelete,children:`Cancel`}),(0,Z.jsx)(q,{variant:`danger`,onClick:e.confirmDelete,children:`Delete`})]})]})})}function Kd({session:e,root:t,readOnly:n,boundHeader:r,onNavigateUp:i,onReset:a,onOpenFile:o,activePath:s,compilableExtensions:c,onOpenCompilationSettings:l}){return(0,Z.jsxs)(wd,{session:e,root:t,readOnly:n,onOpenFile:(e,t,n)=>o(t,n),compilableExtensions:c,onOpenCompilationSettings:l,activePath:s,children:[r,(0,Z.jsx)(qd,{root:t,onNavigateUp:i,onReset:a}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(Ud,{})})]},t)}function qd({root:e,onNavigateUp:t,onReset:n}){return(0,Z.jsxs)(`div`,{className:`flex h-8 shrink-0 items-center px-2`,children:[(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:t,disabled:e===`/`,className:`flex min-w-0 flex-1 items-center gap-1.5 rounded-sm px-1 py-1 text-left text-fg-gold transition-colors hover:bg-elevated hover:text-fg disabled:pointer-events-none disabled:opacity-40`,children:[(0,Z.jsx)(Tn,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`..`})]})}),(0,Z.jsx)(G,{children:e===`/`?e:`Browse the parent directory`})]}),(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:n,className:`ml-1 shrink-0 rounded-sm p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Z.jsx)(ai,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Back to the worktree`})]})}),(0,Z.jsx)(G,{children:`Back to the worktree`})]})]})}var Jd=/[.*+?^${}()|[\]\\]/g;function Yd(e){if(e.query.length===0)return null;try{let t=e.regex?e.query:e.query.replace(Jd,`\\$&`);return e.wholeWord&&(t=`\\b(?:${t})\\b`),new RegExp(t,e.caseSensitive?`g`:`gi`)}catch{return null}}function Xd(e,t){if(!t)return[{text:e,hit:!1}];let n=[],r=0;t.lastIndex=0;let i;for(;(i=t.exec(e))!==null;){if(i[0].length===0){t.lastIndex++;continue}i.index>r&&n.push({text:e.slice(r,i.index),hit:!1}),n.push({text:i[0],hit:!0}),r=i.index+i[0].length}return r<e.length&&n.push({text:e.slice(r),hit:!1}),n.length>0?n:[{text:e,hit:!1}]}var Zd=240;function Qd(e){let t=e.replace(/^\s+/,``);return t.length>Zd?`${t.slice(0,Zd)}…`:t}var $d=250,ef=`group-hover:[transform:translateX(var(--tail))]`;function tf({active:e,label:t,onClick:n,children:r}){return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":e,onClick:n,className:V(`rounded-sm p-1 transition-colors`,e?`bg-elevated text-accent`:`text-fg-muted hover:bg-elevated hover:text-fg`),children:[r,(0,Z.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Z.jsx)(G,{children:t})]})}function nf({session:e,root:t,onOpen:n}){let[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=setTimeout(()=>o(r),$d);return()=>clearTimeout(e)},[r]);let p={query:a,regex:s,caseSensitive:l,wholeWord:d},m=ft(e,p,t),h=(0,X.useMemo)(()=>Yd(p),[a,s,l,d]),g=m.data,_=!!g&&(g.files.length>0||g.content.length>0),v=(e,r,i=!0)=>{n(e,r,i?void 0:{preview:!1}),Cc({path:e,root:t})};return(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1 px-2 py-1.5`,children:[(0,Z.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`Search files and contents`,spellCheck:!1,autoComplete:`off`,className:`rounded-md bg-elevated px-2 py-1 text-xs text-fg outline-none placeholder:text-fg-muted`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(tf,{active:l,label:`Match case`,onClick:()=>u(e=>!e),children:(0,Z.jsx)(Pr,{className:`size-3.5`})}),(0,Z.jsx)(tf,{active:d,label:`Match whole word`,onClick:()=>f(e=>!e),children:(0,Z.jsx)(Fr,{className:`size-3.5`})}),(0,Z.jsx)(tf,{active:s,label:`Use regular expression`,onClick:()=>c(e=>!e),children:(0,Z.jsx)(Nr,{className:`size-3.5`})})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-2`,children:a.length===0?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Search file names and contents.`}):m.isPending?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Searching…`}):m.error?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:m.error instanceof Error?m.error.message:`Search failed`}):_?(0,Z.jsxs)(Z.Fragment,{children:[g.files.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`div`,{className:`px-3 pb-0.5 pt-1.5 text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Files`}),g.files.map(e=>(0,Z.jsxs)(`button`,{type:`button`,title:e,onClick:()=>v(e),onDoubleClick:()=>v(e,void 0,!1),className:`sidebar-row group flex items-center gap-2 px-2 py-1 text-left transition-colors hover:bg-explorer-hover`,children:[(0,Z.jsx)(lu,{name:e.split(`/`).pop()??e,className:`size-4`}),(0,Z.jsx)(Vl,{text:e,className:`text-xs text-fg`,hoverClass:ef})]},e))]}),g.content.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`div`,{className:`px-3 pb-0.5 pt-2 text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Contents`}),g.content.map(e=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`button`,{type:`button`,title:e.path,onClick:()=>v(e.path),onDoubleClick:()=>v(e.path,void 0,!1),className:`sidebar-row group flex items-center gap-2 px-2 py-1 text-left transition-colors hover:bg-explorer-hover`,children:[(0,Z.jsx)(lu,{name:e.path.split(`/`).pop()??e.path,className:`size-4`}),(0,Z.jsx)(Vl,{text:e.path,className:`text-2xs text-fg-secondary`,hoverClass:ef})]}),e.matches.map((t,n)=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>v(e.path,t.line),onDoubleClick:()=>v(e.path,t.line,!1),className:`flex w-full items-baseline gap-2 py-0.5 pl-6 pr-3 text-left transition-colors hover:bg-elevated`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 font-mono text-2xs tabular-nums text-fg-muted`,children:t.line}),(0,Z.jsx)(`span`,{className:`truncate font-mono text-2xs text-fg-secondary`,children:Xd(Qd(t.text),h).map((e,t)=>e.hit?(0,Z.jsx)(`span`,{className:`text-accent`,children:e.text},t):(0,Z.jsx)(`span`,{children:e.text},t))})]},`${t.line}:${n}`))]},e.path))]}),g.truncated&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-2xs text-fg-muted`,children:`Showing the first results — refine the query for more.`})]}):(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No results.`})})]})}var rf=new Set([`starting`,`running`,`waiting_input`]),af=`group-hover:[transform:translateX(var(--tail))]`;function of(e){return e.split(`/`).filter(Boolean).pop()??e}function sf({children:e,className:t,title:n}){return(0,Z.jsx)(`span`,{title:n,className:V(`shrink-0 text-2xs`,t),children:e})}function cf({label:e,blockReason:t,onClick:n}){return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,disabled:t!==null,onClick:n,className:V(`-my-1 rounded-sm p-1 text-fg-gold transition-colors hover:text-danger`,t===null?`hidden group-hover:inline-flex pointer-coarse:inline-flex`:`hidden`),children:[(0,Z.jsx)(hi,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:e})]})}),(0,Z.jsx)(G,{children:t?`Can't ${e.toLowerCase()} — ${t}`:e})]})}function lf({repoId:e,projectId:t,sessions:n}){let r=Ce(e),i=Se(e,t),a=Ae(e,t),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),u=i.isPending||a.isPending,d=(0,X.useMemo)(()=>{let e=new Map;for(let t of n)rf.has(t.status)&&e.set(t.worktree_path,(e.get(t.worktree_path)??0)+1);return e},[n]),f=(0,X.useMemo)(()=>{let e=new Map;for(let t of r.data?.worktrees??[]){let n=t.branch??`(detached)`;(e.get(n)??e.set(n,[]).get(n)).push(t)}return[...e.entries()].sort(([,e],[,t])=>!e.some(e=>e.is_primary)-+!t.some(e=>e.is_primary)||(e[0]?.branch??``).localeCompare(t[0]?.branch??``))},[r.data]),p=(0,X.useMemo)(()=>[...r.data?.orphan_branches??[]].sort((e,t)=>e.name.localeCompare(t.name)),[r.data]);return r.isPending?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Loading worktrees…`}):r.error?(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:r.error instanceof Error?r.error.message:`Failed to load worktrees`}):(0,Z.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto pb-2`,children:[f.length===0&&p.length===0&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No worktrees.`}),f.map(([e,t])=>(0,Z.jsxs)(`div`,{children:[(0,Z.jsxs)(`div`,{className:`group flex items-center gap-1.5 px-3 pb-0.5 pt-2 text-2xs text-fg-muted`,children:[(0,Z.jsx)(Xr,{className:`size-3 shrink-0 text-fg-gold`}),(0,Z.jsx)(Vl,{text:e,hoverClass:af})]}),t.map(e=>{let t=d.get(e.path)??0,n=e.is_primary?`the repository clone`:e.dirty?`uncommitted changes`:t>0?`${t} running session${t>1?`s`:``}`:null;return(0,Z.jsxs)(`div`,{className:`sidebar-row group flex items-center gap-2 px-2 py-1 pl-4 transition-colors hover:bg-explorer-hover`,children:[(0,Z.jsx)(Vl,{text:of(e.path),title:e.path,className:`text-xs text-fg`,hoverClass:af}),e.is_primary&&(0,Z.jsx)(sf,{className:`text-fg-muted`,children:`clone`}),e.dirty&&(0,Z.jsx)(sf,{className:`text-warning`,title:`Modified — uncommitted changes`,children:`M`}),t>0&&(0,Z.jsx)(sf,{className:`text-running`,title:`${t} running session${t>1?`s`:``}`,children:t}),(0,Z.jsx)(cf,{label:`Prune`,blockReason:n,onClick:()=>{l(null),s({kind:`worktree`,path:e.path,branch:e.branch})}})]},e.path)})]},`wt:${e}`)),p.length>0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`px-3 pb-0.5 pt-3 text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Branches without a worktree`}),p.map(e=>(0,Z.jsxs)(`div`,{className:`sidebar-row group flex items-center gap-2 px-2 py-1 transition-colors hover:bg-explorer-hover`,children:[(0,Z.jsx)(Xr,{className:`size-3 shrink-0 text-fg-gold`}),(0,Z.jsx)(Vl,{text:e.name,className:`text-xs text-fg`,hoverClass:af}),e.local_only&&(0,Z.jsx)(sf,{className:`text-warning`,children:`local only`}),(0,Z.jsx)(cf,{label:`Delete branch`,blockReason:null,onClick:()=>{l(null),s({kind:`branch`,name:e.name,localOnly:e.local_only})}})]},`br:${e.name}`))]}),(0,Z.jsx)(Ln,{open:o!==null,onOpenChange:e=>{e||s(null)},children:(0,Z.jsxs)(Fn,{children:[o?.kind===`branch`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Delete branch`}),(0,Z.jsxs)(Nn,{children:[`Delete branch `,(0,Z.jsx)(`span`,{className:`text-fg`,children:o.name}),`? This removes the branch from the repository.`]})]}),o.localOnly&&(0,Z.jsxs)(`p`,{className:`text-xs text-warning`,children:[(0,Z.jsx)(`span`,{children:o.name}),` has commits on no remote — deleting it discards that work permanently.`]})]}):(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Prune worktree`}),(0,Z.jsxs)(Nn,{children:[`Remove `,(0,Z.jsx)(`span`,{className:`text-fg`,children:o?of(o.path):``}),`? The working directory is deleted; the branch`,` `,(0,Z.jsx)(`span`,{className:`text-fg`,children:o?.branch??``}),` is kept.`]})]}),c&&(0,Z.jsx)(`p`,{className:`text-xs text-danger`,children:c}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{type:`button`,variant:`ghost`,onClick:()=>s(null),children:`Cancel`}),(0,Z.jsx)(q,{type:`button`,variant:`danger`,disabled:u,onClick:()=>{if(!o)return;l(null);let e=e=>l(e.message),t=()=>s(null);o.kind===`worktree`?i.mutate(o.path,{onSuccess:t,onError:e}):a.mutate({name:o.name,confirm:!0},{onSuccess:t,onError:e})},children:o?.kind===`branch`?`Delete`:`Prune`})]})]})})]})}function uf({name:e,session:t}){let n=ji()??void 0,r=ue().projectBasedLayout,i=Ne(r?void 0:n),a=t?.kind===`agent`,o=Ge(a?n:void 0),s=i.data?.find(e=>e.id===t?.project_id)?.name,c=t?.account_id==null?void 0:o.data?.find(e=>e.id===t.account_id)?.label,l=[s,t?.branch].filter(Boolean).join(` · `);return(0,Z.jsxs)(`span`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{children:e}),l!==``&&(0,Z.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:l}),a&&(0,Z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-2xs text-fg-muted`,children:[(0,Z.jsx)(Ei,{type:t.agent_type??``,className:`size-3 shrink-0`}),(0,Z.jsx)(`span`,{children:t.agent_type}),c!==void 0&&(0,Z.jsxs)(`span`,{children:[` · `,c]})]}),t?.kind===`huddle`&&(0,Z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-2xs text-fg-muted`,children:[(0,Z.jsx)(Zr,{className:`size-3 shrink-0`}),(0,Z.jsx)(`span`,{children:`huddle`})]}),t?.kind===`terminal`&&(0,Z.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-2xs text-fg-muted`,children:[t.detected_agent_type?(0,Z.jsx)(Ei,{type:t.detected_agent_type,className:`size-3 shrink-0`}):(0,Z.jsx)(hn,{className:`size-3 shrink-0`}),(0,Z.jsx)(`span`,{children:t.detected_agent_type?`${t.detected_agent_type} · terminal`:`terminal`})]})]})}function df({text:e,path:t}){let n=(0,X.useRef)(null);return(0,X.useEffect)(()=>{n.current&&(n.current.scrollLeft=0)},[e,t]),(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(`div`,{ref:n,dir:`ltr`,className:`no-scrollbar min-w-0 flex-1 overflow-x-auto`,children:(0,Z.jsx)(`span`,{className:`inline-block whitespace-nowrap text-sm font-bold text-fg-secondary`,children:e})})}),(0,Z.jsx)(G,{side:`right`,align:`center`,sideOffset:4,children:t??e})]})}function ff({sessions:e,target:t,showFileActions:n=!1,location:r}){let{session:i,pinned:a,pin:o,unpin:s,isProjectDirectory:c}=t,l=_i(),u=e.filter(e=>e.status!==`archived`),d=r??t.root??i?.worktree_path??null;return(0,Z.jsxs)(`div`,{className:`group relative flex h-8 shrink-0 items-center px-2`,children:[(0,Z.jsx)(df,{text:d?d.split(/[\\/]/).filter(Boolean).at(-1)??d:`No worktree`,path:d}),(0,Z.jsxs)(`div`,{className:V(`absolute inset-y-0 right-1 flex items-center gap-1 bg-surface pl-2 opacity-0 transition-opacity`,`pointer-events-none focus-within:pointer-events-auto focus-within:opacity-100 group-hover:pointer-events-auto group-hover:opacity-100`,a&&`pointer-events-auto opacity-100`),children:[n&&i&&(0,Z.jsx)(mf,{}),(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":a,disabled:!i||c,title:c?`The project directory is the fallback binding — nothing to pin`:a?`Unpin — follow the active session`:`Pin the sidebar to this worktree`,onClick:()=>a?s():i&&o(i.id),className:V(`shrink-0 rounded-sm p-1 transition-colors disabled:pointer-events-none disabled:opacity-40`,a?`text-fg`:`text-fg-gold hover:bg-elevated hover:text-fg`),children:[(0,Z.jsx)(ka,{className:V(`size-3.5`,a&&`fill-current`)}),(0,Z.jsx)(`span`,{className:`sr-only`,children:a?`Unpin sidebar`:`Pin sidebar`})]}),(0,Z.jsxs)(ur,{children:[(0,Z.jsx)(mr,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,title:`Bind a different worktree`,className:`shrink-0 rounded-sm p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Z.jsx)(Ir,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Choose a worktree`})]})}),(0,Z.jsx)(Sr,{align:`end`,children:u.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-1.5 text-xs text-fg-muted`,children:`No sessions yet`}):u.map(e=>(0,Z.jsx)(Cr,{onSelect:()=>o(e.id),className:`min-w-64 items-start`,children:(0,Z.jsx)(uf,{name:l(e),session:e})},e.id))})]})]})]})}var pf=[{key:`refresh`,label:`Refresh`,icon:jr},{key:`collapse`,label:`Collapse Folders`,icon:ga}];function mf(){let e=Cd();if(!e)return null;let t=t=>{t===`refresh`?e.refresh():t===`collapse`&&e.collapseAll()};return(0,Z.jsx)(`div`,{className:`hidden shrink-0 items-center gap-0.5 group-hover:flex group-focus-within:flex`,children:pf.map(({key:e,label:n,icon:r})=>(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>t(e),className:`rounded-sm p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Z.jsx)(r,{className:`size-3.5`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:n})]})}),(0,Z.jsx)(G,{children:n})]},e))})}var hf=[{key:`files`,label:`Files`,icon:ui},{key:`search`,label:`Search`,icon:mi},{key:`changes`,label:`Changes`,icon:Xr},{key:`worktrees`,label:`Worktrees`,icon:ae}];function gf(e){return e===`diff`||e===`history`||e===`changes`?`changes`:e===`search`?`search`:e===`worktrees`?`worktrees`:`files`}function _f({mode:e,onExpand:t,onSelect:n}){return(0,Z.jsx)(`div`,{className:`workspace-surface relative flex w-9 shrink-0 self-start flex-col items-center gap-1`,children:(0,Z.jsxs)(Ri,{motionId:`workspace-navigators`,label:`Navigators`,variant:`island`,vertical:!0,children:[(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:t,"data-sidebar-motion":`navigator-toggle`,className:`flex items-center rounded-md p-1.5 text-fg transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Z.jsx)(Ea,{className:`size-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Show sidebar`})]})}),(0,Z.jsx)(G,{side:`right`,children:`Show sidebar`})]}),(0,Z.jsx)(`div`,{"aria-hidden":`true`,className:`mx-1 h-px self-stretch bg-border`}),hf.map(({key:t,label:r,icon:i})=>(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"data-tray-slot":!0,"aria-current":e===t?`page`:void 0,"data-sidebar-motion":`navigator-mode-${t}`,onClick:()=>n(t),className:V(`flex items-center rounded-md p-1.5 transition-colors`,e===t?`bg-elevated text-fg`:`text-fg-gold hover:bg-elevated hover:text-fg`),children:[(0,Z.jsx)(i,{className:`size-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:r})]})}),(0,Z.jsx)(G,{side:`right`,children:r})]},t))]})})}function vf({mode:e,onModeChange:t,onCollapse:n,projectId:r,repoId:i,sessions:a,target:o,browseRequest:s,onFiletreeRootChange:c,compilableExtensions:l,onOpenCompilationSettings:u,onOpenFile:d,onOpenExternalFile:f,onOpenTerminalIn:p,activeFilePath:m,activeExternalTab:h,activeDiffPath:g,onOpenDiff:_,onOpenCommitFile:v,onOpenSearchFile:y}){let{session:b}=o,x=o.root,[S,C]=(0,X.useState)(null),w=Le().data?.protocol,T=!w||w.major>10||w.major===10&&w.minor>=2,E=!w||w.major>12||w.major===12&&w.minor>=3,D=T&&S!==null&&S.forSession===b?.id?S.root:null,O=D??x,k=gc(o,D);(0,X.useEffect)(()=>(c?.(k),()=>c?.(null)),[k,c]);let A=e=>{b&&(o.pinned||o.pin(b.id),C({forSession:b.id,root:e}))};(0,X.useEffect)(()=>wc(e=>{let t=x??b?.worktree_path,n=e.directory===void 0?e.root===x:e.directory===t;S!==null&&n&&C(null)}),[S,b?.worktree_path,x]);let ee=(0,X.useRef)(0);(0,X.useEffect)(()=>{!s||!T||ee.current!==s.nonce&&(ee.current=s.nonce,o.pin(s.session),C({forSession:s.session,root:s.root}))},[s,T,o]);let j=_c(o,()=>C(null)),M=`${b?.worktree_path??``}:${O??``}`,N=(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1.5`,children:[(0,Z.jsx)(Ri,{motionId:`workspace-navigators`,label:`Navigators`,variant:`selection`,children:hf.map(({key:n,label:r,icon:i})=>(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"data-tray-slot":!0,"aria-current":e===n?`page`:void 0,"data-sidebar-motion":`navigator-mode-${n}`,onClick:()=>t(n),className:V(`flex items-center rounded-md p-1.5 transition-colors`,e===n?`bg-elevated text-fg`:`text-fg-gold hover:bg-elevated hover:text-fg`),children:[(0,Z.jsx)(i,{className:`size-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:r})]})}),(0,Z.jsx)(G,{side:`bottom`,children:r})]},n))}),(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:n,"data-sidebar-motion":`navigator-toggle`,className:`ml-auto flex items-center rounded-md p-1.5 text-fg transition-colors hover:bg-elevated hover:text-fg`,children:[(0,Z.jsx)(Ta,{className:`size-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Hide sidebar`})]})}),(0,Z.jsx)(G,{side:`bottom`,children:`Hide sidebar`})]})]});return e===`changes`&&b?(0,Z.jsx)(Lu,{header:(0,Z.jsxs)(Z.Fragment,{children:[N,(0,Z.jsx)(ff,{sessions:a,target:j,location:k})]}),session:b.id,root:O,activeDiffPath:g,onOpenDiff:_,onOpenCommitFile:v},M):(0,Z.jsxs)(`div`,{className:`workspace-surface island-outline flex h-full flex-col bg-surface`,children:[N,e!==`worktrees`&&e!==`files`&&(0,Z.jsx)(ff,{sessions:a,target:j,location:k}),e===`worktrees`&&(0,Z.jsx)(lf,{repoId:i,projectId:r,sessions:a}),e===`files`&&(b&&D!==null?(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsx)(Kd,{session:b,root:D,readOnly:!E,boundHeader:(0,Z.jsx)(ff,{sessions:a,target:j,showFileActions:!0,location:k}),onNavigateUp:()=>A(Ys(D)),onReset:j.unpin,onOpenFile:(e,t)=>f(b.id,e,D,t),activePath:h?.root===D?h.path:null,compilableExtensions:l,onOpenCompilationSettings:u})}):b?(0,Z.jsxs)(wd,{session:b,root:x,onOpenFile:x===void 0?d:(e,t,n)=>f(e,t,x,n),compilableExtensions:l,onOpenCompilationSettings:u,onOpenTerminal:x===void 0?e=>p(b.id,e):void 0,activePath:x===void 0?m:h?.root===x?h.path:null,children:[(0,Z.jsx)(ff,{sessions:a,target:j,showFileActions:!0,location:k}),T&&x===void 0&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(Ys(b.worktree_path)),title:`Browse the parent directory`,className:`flex shrink-0 items-center gap-1.5 px-3 py-1 text-left transition-colors hover:bg-elevated`,children:[(0,Z.jsx)(Tn,{className:`size-3 shrink-0 text-fg-gold`}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`..`})]}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,Z.jsx)(Ud,{})})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ff,{sessions:a,target:j,location:k}),(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No worktree to show.`})]})),e===`changes`&&(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No worktree to show.`}),e===`search`&&(b?(0,Z.jsx)(nf,{session:b.id,root:O,onOpen:(e,n,r)=>{y(e,n,r),n===void 0&&t(`files`)}},M):(0,Z.jsx)(`div`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`No worktree to search.`}))]})}function yf({projectId:e,repoId:t,open:n,kind:r=`agent`,seedAccountId:i,onOpenChange:a,onCreated:o,accountSetup:s}){let c=r===`terminal`,l=ji(),u=Ge(l??void 0),d=Me(l??void 0),f=Pe(),p=ze(),m=Xe(),[h,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(``),[x,S]=(0,X.useState)(!0),[C,w]=(0,X.useState)(!0),[T,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(!1),[ee,j]=(0,X.useState)(null),M=Ne(l??void 0),N=(0,X.useMemo)(()=>(M.data??[]).filter(e=>!e.archived),[M.data]),P=h||e,F=N.find(e=>e.id===P)?.repo_id??t,I=f.data?.find(e=>e.id===F),te=Ue(n?F:void 0),ne=Ce(n?F:void 0,0),re=u.data?.find(e=>String(e.id)===_),ie=d.data?.allowSkipPermissions===!0,ae=!c&&ie&&re?.skip_permissions_default===!0,oe=I?.default_base_branch===``&&!y.trim(),L=ne.data?.worktrees.find(e=>e.is_primary)?.branch,ce=I?.default_base_branch||L||(ne.data?`main`:``),le=y.trim()||ce;(0,X.useEffect)(()=>{n&&g(e)},[n,e]);let ue=(0,X.useMemo)(()=>(ne.data?.worktrees??[]).filter(e=>e.branch===le).map(e=>({path:e.path,is_primary:e.is_primary,label:e.is_primary?`${e.path.split(`/`).filter(Boolean).pop()??e.path} (clone)`:e.path.split(`/`).filter(Boolean).pop()??e.path})),[ne.data,le]),de=!x&&!C,fe=ue.find(e=>e.is_primary)?.path??ue[0]?.path??``,pe=D||fe,me=(0,X.useMemo)(()=>{let e=d.data?.default_account_id;return u.data?.find(e=>e.id===i)??u.data?.find(t=>typeof e==`number`&&t.id===e)??u.data?.[0]},[u.data,d.data,i]),R=_||(me?String(me.id):``),he=(0,X.useMemo)(()=>ti(u.data??[]),[u.data]);(0,X.useEffect)(()=>{n&&i!==void 0&&v(String(i))},[n,i]);let ge=(0,X.useRef)(d.data);ge.current=d.data,(0,X.useEffect)(()=>{if(n){let e=ua(c?`terminal`:`agent`,ge.current);b(e.baseBranch),S(e.separateBranch),w(e.separateWorktree),O(``)}},[n,c,P]);let _e=I?.default_base_branch;(0,X.useEffect)(()=>{!n||!_e||b(e=>e===``?_e:e)},[n,P,_e]);let ve=()=>{j(null),m.mutate({project_id:P,...c?{kind:`terminal`}:{account_id:Number(R)},...y.trim()?{base_branch:y.trim()}:{},separate_branch:x,...x&&T.trim()?{branch:T.trim()}:{},...x?{}:{separate_worktree:C},...de&&pe&&(!oe||D)?{join_worktree:pe}:{},...ae&&k?{skip_permissions:!0}:{}},{onSuccess:e=>{a(!1),E(``),A(!1),o(e)},onError:e=>j(e.message)})},z=c?`a shell`:`an agent`,ye=x?`on a new branch off ${le||`…`}, in its own directory`:de?`on ${le||`…`}, sharing an existing directory`:`on ${le||`…`}, in its own directory`;return(0,Z.jsx)(Ln,{open:n,onOpenChange:a,children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:c?`New terminal`:`New agent`}),(0,Z.jsxs)(Nn,{children:[c?`Opens`:`Spawns`,` `,z,` in`,` `,(0,Z.jsx)(bf,{projects:N,value:P,onChange:g}),` `,ye,`.`]})]}),(0,Z.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),(c||R)&&ve()},children:[!c&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(Xn,{children:`Account`}),u.data?.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:s??(0,Z.jsxs)(Z.Fragment,{children:[`No accounts yet —`,` `,(0,Z.jsx)(`button`,{type:`button`,className:`text-accent underline`,onClick:()=>Ai(`accounts`),children:`add one in settings`}),`.`]})}):(0,Z.jsxs)(Wn,{value:R,onValueChange:v,children:[(0,Z.jsx)(Vn,{children:(0,Z.jsx)(Bn,{placeholder:`pick an account`})}),(0,Z.jsx)(Hn,{children:he.map(e=>(0,Z.jsxs)(Un,{value:String(e.id),children:[(0,Z.jsxs)(`span`,{children:[e.agent_type,`/`,e.label]}),!e.logged_in&&(0,Z.jsx)(`span`,{className:`ml-2 text-2xs text-warning`,children:`not logged in`})]},e.id))})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1.5`,children:[(0,Z.jsx)(Xn,{htmlFor:`base-branch`,children:`Base branch`}),(0,Z.jsx)(se,{id:`base-branch`,placeholder:I?.default_base_branch||`current clone branch`,value:y,onValueChange:b,hints:(te.data?.branches??[]).filter(e=>e.name.toLowerCase().includes(y.trim().toLowerCase())).slice(0,20).map(e=>({value:e.name,badge:e.name===ce?`default`:e.is_session?`session: ${e.session_title??`untitled`}`:void 0})),hintsClassName:`w-max min-w-full max-w-[36rem]`}),oe&&(0,Z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[`Uses the clone’s current branch when created`,le?` (now ${le})`:``,`.`]})]}),x&&(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsx)(Xn,{htmlFor:`session-branch`,children:`New branch`}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`optional`})]}),(0,Z.jsx)(Gn,{id:`session-branch`,placeholder:`leave blank for auto`,value:T,onChange:e=>E(e.target.value)})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Mr,{id:`separate-branch`,checked:x,onCheckedChange:e=>{S(e),e&&w(!0)}}),(0,Z.jsx)(Xn,{htmlFor:`separate-branch`,children:`Use separate branch`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(Mr,{id:`separate-worktree`,checked:x?!0:C,disabled:x,onCheckedChange:w}),(0,Z.jsx)(Xn,{htmlFor:`separate-worktree`,className:V(x&&`text-fg-muted`),children:`Use separate directory`})]})]}),de&&(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(Xn,{htmlFor:`join-dir`,children:`Directory to join`}),ue.length===0?(0,Z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[`No existing directory on`,` `,(0,Z.jsx)(`span`,{className:`text-fg-secondary`,children:le||`…`}),` — a shared one will be created for later sessions to join.`]}):(0,Z.jsxs)(Wn,{value:pe,onValueChange:O,children:[(0,Z.jsx)(Vn,{id:`join-dir`,children:(0,Z.jsx)(Bn,{})}),(0,Z.jsx)(Hn,{children:ue.map(e=>(0,Z.jsx)(Un,{value:e.path,title:e.path,detail:(0,Z.jsx)(`span`,{className:`ml-auto min-w-0 truncate text-2xs text-fg-muted`,children:Ed(e.path,p.data?.home)}),children:e.label},e.path))})]})]}),!x&&!c&&(0,Z.jsxs)(`p`,{className:`text-xs text-warning`,children:[`The `,c?`shell`:`agent`,` commits straight to`,` `,(0,Z.jsx)(`span`,{children:le||`…`}),de?` and shares its working directory with concurrent sessions — they can trample each other’s edits.`:`.`]}),ae&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md bg-surface px-3 py-2`,children:[(0,Z.jsx)(Mr,{id:`skip-permissions`,checked:k,onCheckedChange:A}),(0,Z.jsx)(Xn,{htmlFor:`skip-permissions`,className:`text-warning`,children:`Skip permission prompts for this session`})]}),ee&&(0,Z.jsx)(`p`,{className:`text-xs text-danger`,children:ee}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{type:`button`,variant:`ghost`,onClick:()=>a(!1),children:`Cancel`}),(0,Z.jsx)(q,{type:`submit`,disabled:!c&&!R||m.isPending,children:c?`Open terminal`:`Start agent`})]})]})]})})}function bf({projects:e,value:t,onChange:n}){let r=e.find(e=>e.id===t)?.name??`this project`;return e.length<2?(0,Z.jsx)(`span`,{className:`text-fg-secondary`,children:r}):(0,Z.jsxs)(ur,{children:[(0,Z.jsx)(mr,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,title:`Choose the project`,className:`inline-flex items-center gap-0.5 text-fg-secondary transition-colors hover:text-fg`,children:[r,(0,Z.jsx)(Ir,{className:`size-3 shrink-0`})]})}),(0,Z.jsx)(Sr,{align:`start`,children:e.map(e=>(0,Z.jsx)(Cr,{onSelect:()=>n(e.id),className:V(`truncate`,e.id===t&&`text-fg`),children:e.name},e.id))})]})}var xf;function Sf(){let e=e=>{let t=e.target;xf=t instanceof Element?t.closest(`[draggable="true"]`)?.getBoundingClientRect():void 0},t=()=>{xf=void 0};return window.addEventListener(`dragstart`,e,!0),window.addEventListener(`dragend`,t),()=>{window.removeEventListener(`dragstart`,e,!0),window.removeEventListener(`dragend`,t),t()}}function Cf(e,t,n,r=xf){let i=new Set([...document.querySelectorAll(`[data-workspace-pane]`)].map(e=>e.dataset.workspacePane));xn(e,r,()=>{let e=[...document.querySelectorAll(`[data-pane-view]`)].filter(e=>e.dataset.paneView===B(t)&&!e.closest(`[data-motion-snapshot]`));return e.find(e=>!i.has(e.closest(`[data-workspace-pane]`)?.dataset.workspacePane))??e.find(e=>e.closest(`[data-workspace-pane]`)?.dataset.workspacePane===n)??null})}var wf=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function Tf(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function Ef(e){return`nodeType`in e}function Df(e){return e?Tf(e)?e:Ef(e)?e.ownerDocument?.defaultView??window:window:window}function Of(e){let{Document:t}=Df(e);return e instanceof t}function kf(e){return!Tf(e)&&e instanceof Df(e).HTMLElement}function Af(e){return e instanceof Df(e).SVGElement}function jf(e){return e?Tf(e)?e.document:Ef(e)?Of(e)?e:kf(e)||Af(e)?e.ownerDocument:document:document:document}var Mf=wf?X.useLayoutEffect:X.useEffect;function Nf(e){let t=(0,X.useRef)(e);return Mf(()=>{t.current=e}),(0,X.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function Pf(){let e=(0,X.useRef)(null);return[(0,X.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,X.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function Ff(e,t){t===void 0&&(t=[e]);let n=(0,X.useRef)(e);return Mf(()=>{n.current!==e&&(n.current=e)},t),n}function If(e,t){let n=(0,X.useRef)();return(0,X.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function Lf(e){let t=Nf(e),n=(0,X.useRef)(null);return[n,(0,X.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function Rf(e){let t=(0,X.useRef)();return(0,X.useEffect)(()=>{t.current=e},[e]),t.current}var zf={};function Bf(e,t){return(0,X.useMemo)(()=>{if(t)return t;let n=zf[e]==null?0:zf[e]+1;return zf[e]=n,e+`-`+n},[e,t])}function Vf(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var Hf=Vf(1),Uf=Vf(-1);function Wf(e){return`clientX`in e&&`clientY`in e}function Gf(e){if(!e)return!1;let{KeyboardEvent:t}=Df(e.target);return t&&e instanceof t}function Kf(e){if(!e)return!1;let{TouchEvent:t}=Df(e.target);return t&&e instanceof t}function qf(e){if(Kf(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Wf(e)?{x:e.clientX,y:e.clientY}:null}var Jf=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[Jf.Translate.toString(e),Jf.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),Yf=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function Xf(e){return e.matches(Yf)?e:e.querySelector(Yf)}var Zf={display:`none`};function Qf(e){let{id:t,value:n}=e;return X.createElement(`div`,{id:t,style:Zf},n)}function $f(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return X.createElement(`div`,{id:t,style:{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`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function ep(){let[e,t]=(0,X.useState)(``);return{announce:(0,X.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var tp=(0,X.createContext)(null);function np(e){let t=(0,X.useContext)(tp);(0,X.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of <DndContext>`);return t(e)},[e,t])}function rp(){let[e]=(0,X.useState)(()=>new Set),t=(0,X.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,X.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var ip={draggable:`
17
+ To pick up a draggable item, press the space bar.
18
+ While dragging, use the arrow keys to move the item.
19
+ Press space again to drop the item in its new position, or press escape to cancel.
20
+ `},ap={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function op(e){let{announcements:t=ap,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=ip}=e,{announce:a,announcement:o}=ep(),s=Bf(`DndLiveRegion`),[c,l]=(0,X.useState)(!1);if((0,X.useEffect)(()=>{l(!0)},[]),np((0,X.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=X.createElement(X.Fragment,null,X.createElement(Qf,{id:r,value:i.draggable}),X.createElement($f,{id:s,announcement:o}));return n?(0,Fa.createPortal)(u,n):u}var sp;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(sp||={});function cp(){}function lp(e,t){return(0,X.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function up(){var e=[...arguments];return(0,X.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var dp=Object.freeze({x:0,y:0});function fp(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function pp(e,t){let n=qf(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function mp(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function hp(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function gp(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function _p(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function vp(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r<i&&n<a){let n=t.width*t.height,r=e.width*e.height,i=o*s,a=i/(n+r-i);return Number(a.toFixed(4))}return 0}var yp=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=vp(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort(hp)};function bp(e,t){let{top:n,left:r,bottom:i,right:a}=t;return n<=e.y&&e.y<=i&&r<=e.x&&e.x<=a}var xp=e=>{let{droppableContainers:t,droppableRects:n,pointerCoordinates:r}=e;if(!r)return[];let i=[];for(let e of t){let{id:t}=e,a=n.get(t);if(a&&bp(r,a)){let n=gp(a).reduce((e,t)=>e+fp(r,t),0),o=Number((n/4).toFixed(4));i.push({id:t,data:{droppableContainer:e,value:o}})}}return i.sort(mp)};function Sp(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function Cp(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:dp}function wp(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var Tp=wp(1);function Ep(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function Dp(e,t,n){let r=Ep(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var Op={ignoreTransform:!1};function kp(e,t){t===void 0&&(t=Op);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=Df(e).getComputedStyle(e);t&&(n=Dp(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function Ap(e){return kp(e,{ignoreTransform:!0})}function jp(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function Mp(e,t){return t===void 0&&(t=Df(e).getComputedStyle(e)),t.position===`fixed`}function Np(e,t){t===void 0&&(t=Df(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`&&n.test(r)})}function Pp(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(Of(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!kf(i)||Af(i)||n.includes(i))return n;let a=Df(e).getComputedStyle(i);return i!==e&&Np(i,a)&&n.push(i),Mp(i,a)?n:r(i.parentNode)}return e?r(e):n}function Fp(e){let[t]=Pp(e,1);return t??null}function Ip(e){return!wf||!e?null:Tf(e)?e:Ef(e)?Of(e)||e===jf(e).scrollingElement?window:kf(e)?e:null:null}function Lp(e){return Tf(e)?e.scrollX:e.scrollLeft}function Rp(e){return Tf(e)?e.scrollY:e.scrollTop}function zp(e){return{x:Lp(e),y:Rp(e)}}var Bp;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(Bp||={});function Vp(e){return!wf||!e?!1:e===document.scrollingElement}function Hp(e){let t={x:0,y:0},n=Vp(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var Up={x:.2,y:.2};function Wp(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=Up);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=Hp(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=Bp.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=Bp.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=Bp.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=Bp.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function Gp(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function Kp(e){return e.reduce((e,t)=>Hf(e,zp(t)),dp)}function qp(e){return e.reduce((e,t)=>e+Lp(t),0)}function Jp(e){return e.reduce((e,t)=>e+Rp(t),0)}function Yp(e,t){if(t===void 0&&(t=kp),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);Fp(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var Xp=[[`x`,[`left`,`right`],qp],[`y`,[`top`,`bottom`],Jp]],Zp=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=Pp(t),r=Kp(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of Xp)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},Qp=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function $p(e){let{EventTarget:t}=Df(e);return e instanceof t?e:jf(e)}function em(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t&&r>t.y}var tm;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(tm||={});function nm(e){e.preventDefault()}function rm(e){e.stopPropagation()}var $;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})($||={});var im={start:[$.Space,$.Enter],cancel:[$.Esc],end:[$.Space,$.Enter,$.Tab]},am=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case $.Right:return{...n,x:n.x+25};case $.Left:return{...n,x:n.x-25};case $.Down:return{...n,y:n.y+25};case $.Up:return{...n,y:n.y-25}}},om=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new Qp(jf(t)),this.windowListeners=new Qp(Df(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(tm.Resize,this.handleCancel),this.windowListeners.add(tm.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(tm.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&Yp(n),t(dp)}handleKeyDown(e){if(Gf(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=im,coordinateGetter:a=am,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:dp;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=Uf(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=Hp(n),p=Gp(n),m={x:Math.min(i===$.Right?p.right-p.width/2:p.right,Math.max(i===$.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===$.Down?p.bottom-p.height/2:p.bottom,Math.max(i===$.Down?p.top:p.top+p.height/2,u.y))},h=i===$.Right&&!s||i===$.Left&&!c,g=i===$.Down&&!l||i===$.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===$.Right&&e<=d.x||i===$.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===$.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===$.Down&&e<=d.y||i===$.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===$.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,Hf(Uf(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};om.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=im,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function sm(e){return!!(e&&`distance`in e)}function cm(e){return!!(e&&`delay`in e)}var lm=class{constructor(e,t,n){n===void 0&&(n=$p(e.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=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=jf(i),this.documentListeners=new Qp(this.document),this.listeners=new Qp(n),this.windowListeners=new Qp(Df(i)),this.initialCoordinates=qf(r)??dp,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(tm.Resize,this.handleCancel),this.windowListeners.add(tm.DragStart,nm),this.windowListeners.add(tm.VisibilityChange,this.handleCancel),this.windowListeners.add(tm.ContextMenu,nm),this.documentListeners.add(tm.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(cm(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(sm(t)){this.handlePending(t);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(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(tm.Click,rm,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(tm.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=qf(e)??dp,s=Uf(n,o);if(!t&&a){if(sm(a)){if(a.tolerance!=null&&em(s,a.tolerance))return this.handleCancel();if(em(s,a.distance))return this.handleStart()}if(cm(a)&&em(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===$.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},um={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},dm=class extends lm{constructor(e){let{event:t}=e,n=jf(t.target);super(e,um,n)}};dm.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var fm={move:{name:`mousemove`},end:{name:`mouseup`}},pm;(function(e){e[e.RightClick=2]=`RightClick`})(pm||={});var mm=class extends lm{constructor(e){super(e,fm,jf(e.event.target))}};mm.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===pm.RightClick?!1:(r?.({event:n}),!0)}}];var hm={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},gm=class extends lm{constructor(e){super(e,hm)}static setup(){return window.addEventListener(hm.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(hm.move.name,e)};function e(){}}};gm.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var _m;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(_m||={});var vm;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(vm||={});function ym(e){let{acceleration:t,activator:n=_m.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=vm.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=xm({delta:d,disabled:!a}),[m,h]=Pf(),g=(0,X.useRef)({x:0,y:0}),_=(0,X.useRef)({x:0,y:0}),v=(0,X.useMemo)(()=>{switch(n){case _m.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case _m.DraggableRect:return i}},[n,i,c]),y=(0,X.useRef)(null),b=(0,X.useCallback)(()=>{let e=y.current;if(!e)return;let t=g.current.x*_.current.x,n=g.current.y*_.current.y;e.scrollBy(t,n)},[]),x=(0,X.useMemo)(()=>s===vm.TreeOrder?[...l].reverse():l,[s,l]);(0,X.useEffect)(()=>{if(!a||!l.length||!v){h();return}for(let e of x){if(r?.(e)===!1)continue;let n=l.indexOf(e),i=u[n];if(!i)continue;let{direction:a,speed:s}=Wp(e,i,v,t,f);for(let e of[`x`,`y`])p[e][a[e]]||(s[e]=0,a[e]=0);if(s.x>0||s.y>0){h(),y.current=e,m(b,o),g.current=s,_.current=a;return}}g.current={x:0,y:0},_.current={x:0,y:0},h()},[t,b,r,h,a,o,JSON.stringify(v),JSON.stringify(p),m,l,x,u,JSON.stringify(f)])}var bm={x:{[Bp.Backward]:!1,[Bp.Forward]:!1},y:{[Bp.Backward]:!1,[Bp.Forward]:!1}};function xm(e){let{delta:t,disabled:n}=e,r=Rf(t);return If(e=>{if(n||!r||!e)return bm;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[Bp.Backward]:e.x[Bp.Backward]||i.x===-1,[Bp.Forward]:e.x[Bp.Forward]||i.x===1},y:{[Bp.Backward]:e.y[Bp.Backward]||i.y===-1,[Bp.Forward]:e.y[Bp.Forward]||i.y===1}}},[n,t,r])}function Sm(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return If(e=>t==null?null:r??e??null,[r,t])}function Cm(e,t){return(0,X.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var wm;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(wm||={});var Tm;(function(e){e.Optimized=`optimized`})(Tm||={});var Em=new Map;function Dm(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,X.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,X.useRef)(e),d=g(),f=Ff(d),p=(0,X.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,X.useRef)(null),h=If(t=>{if(d&&!n)return Em;if(!t||t===Em||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new Zp(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,X.useEffect)(()=>{u.current=e},[e]),(0,X.useEffect)(()=>{d||p()},[n,d]),(0,X.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,X.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case wm.Always:return!1;case wm.BeforeDragging:return n;default:return!n}}}function Om(e,t){return If(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function km(e,t){return Om(e,t)}function Am(e){let{callback:t,disabled:n}=e,r=Nf(t),i=(0,X.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,X.useEffect)(()=>()=>i?.disconnect(),[i]),i}function jm(e){let{callback:t,disabled:n}=e,r=Nf(t),i=(0,X.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,X.useEffect)(()=>()=>i?.disconnect(),[i]),i}function Mm(e){return new Zp(kp(e),e)}function Nm(e,t,n){t===void 0&&(t=Mm);let[r,i]=(0,X.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=Am({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=jm({callback:a});return Mf(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function Pm(e){return Cp(e,Om(e))}var Fm=[];function Im(e){let t=(0,X.useRef)(e),n=If(n=>e?n&&n!==Fm&&e&&t.current&&e.parentNode===t.current.parentNode?n:Pp(e):Fm,[e]);return(0,X.useEffect)(()=>{t.current=e},[e]),n}function Lm(e){let[t,n]=(0,X.useState)(null),r=(0,X.useRef)(e),i=(0,X.useCallback)(e=>{let t=Ip(e.target);t&&n(e=>e?(e.set(t,zp(t)),new Map(e)):null)},[]);return(0,X.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=Ip(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,zp(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{Ip(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,X.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>Hf(e,t),dp):Kp(e):dp,[e,t])}function Rm(e,t){t===void 0&&(t=[]);let n=(0,X.useRef)(null);return(0,X.useEffect)(()=>{n.current=null},t),(0,X.useEffect)(()=>{let t=e!==dp;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?Uf(e,n.current):dp}function zm(e){(0,X.useEffect)(()=>{if(!wf)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function Bm(e,t){return(0,X.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function Vm(e){return(0,X.useMemo)(()=>e?jp(e):null,[e])}var Hm=[];function Um(e,t){t===void 0&&(t=kp);let[n]=e,r=Vm(n?Df(n):null),[i,a]=(0,X.useState)(Hm);function o(){a(()=>e.length?e.map(e=>Vp(e)?r:new Zp(t(e),e)):Hm)}let s=jm({callback:o});return Mf(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function Wm(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return kf(t)?t:e}function Gm(e){let{measure:t}=e,[n,r]=(0,X.useState)(null),i=jm({callback:(0,X.useCallback)(e=>{for(let{target:n}of e)if(kf(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=Lf((0,X.useCallback)(e=>{let n=Wm(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,X.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var Km=[{sensor:dm,options:{}},{sensor:om,options:{}}],qm={current:{}},Jm={draggable:{measure:Ap},droppable:{measure:Ap,strategy:wm.WhileDragging,frequency:Tm.Optimized},dragOverlay:{measure:kp}},Ym=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},Xm={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Ym,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:cp},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:Jm,measureDroppableContainers:cp,windowRect:null,measuringScheduled:!1},Zm={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:cp,draggableNodes:new Map,over:null,measureDroppableContainers:cp},Qm=(0,X.createContext)(Zm),$m=(0,X.createContext)(Xm);function eh(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Ym}}}function th(e,t){switch(t.type){case sp.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case sp.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case sp.DragEnd:case sp.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case sp.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new Ym(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case sp.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new Ym(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case sp.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new Ym(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function nh(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,X.useContext)(Qm),a=Rf(r),o=Rf(n?.id);return(0,X.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!Gf(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=Xf(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function rh(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function ih(e){return(0,X.useMemo)(()=>({draggable:{...Jm.draggable,...e?.draggable},droppable:{...Jm.droppable,...e?.droppable},dragOverlay:{...Jm.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function ah(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,X.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;Mf(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=Cp(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=Fp(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var oh=(0,X.createContext)({...dp,scaleX:1,scaleY:1}),sh;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(sh||={});var ch=(0,X.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=Km,collisionDetection:o=yp,measuring:s,modifiers:c,...l}=e,[u,d]=(0,X.useReducer)(th,void 0,eh),[f,p]=rp(),[m,h]=(0,X.useState)(sh.Uninitialized),g=m===sh.Initialized,{draggable:{active:_,nodes:v,translate:y},droppable:{containers:b}}=u,x=_==null?null:v.get(_),S=(0,X.useRef)({initial:null,translated:null}),C=(0,X.useMemo)(()=>_==null?null:{id:_,data:x?.data??qm,rect:S},[_,x]),w=(0,X.useRef)(null),[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(null),k=Ff(l,Object.values(l)),A=Bf(`DndDescribedBy`,t),ee=(0,X.useMemo)(()=>b.getEnabled(),[b]),j=ih(s),{droppableRects:M,measureDroppableContainers:N,measuringScheduled:P}=Dm(ee,{dragging:g,dependencies:[y.x,y.y],config:j.droppable}),F=Sm(v,_),I=(0,X.useMemo)(()=>D?qf(D):null,[D]),te=ke(),ne=km(F,j.draggable.measure);ah({activeNode:_==null?null:v.get(_),config:te.layoutShiftCompensation,initialRect:ne,measure:j.draggable.measure});let re=Nm(F,j.draggable.measure,ne),ie=Nm(F?F.parentElement:null),ae=(0,X.useRef)({activatorEvent:null,active:null,activeNode:F,collisionRect:null,collisions:null,droppableRects:M,draggableNodes:v,draggingNode:null,draggingNodeRect:null,droppableContainers:b,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),oe=b.getNodeFor(ae.current.over?.id),L=Gm({measure:j.dragOverlay.measure}),se=L.nodeRef.current??F,ce=g?L.rect??re:null,le=!!(L.nodeRef.current&&L.rect),ue=Pm(le?null:re),de=Vm(se?Df(se):null),fe=Im(g?oe??F:null),pe=Um(fe),me=rh(c,{transform:{x:y.x-ue.x,y:y.y-ue.y,scaleX:1,scaleY:1},activatorEvent:D,active:C,activeNodeRect:re,containerNodeRect:ie,draggingNodeRect:ce,over:ae.current.over,overlayNodeRect:L.rect,scrollableAncestors:fe,scrollableAncestorRects:pe,windowRect:de}),R=I?Hf(I,y):null,he=Lm(fe),ge=Rm(he),_e=Rm(he,[re]),ve=Hf(me,ge),z=ce?Tp(ce,me):null,ye=C&&z?o({active:C,collisionRect:z,droppableRects:M,droppableContainers:ee,pointerCoordinates:R}):null,be=_p(ye,`id`),[xe,Se]=(0,X.useState)(null),Ce=Sp(le?me:Hf(me,_e),xe?.rect??null,re),we=(0,X.useRef)(null),Te=(0,X.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(w.current==null)return;let i=v.get(w.current);if(!i)return;let a=e.nativeEvent,o=new n({active:w.current,activeNode:i,event:a,options:r,context:ae,onAbort(e){if(!v.get(e))return;let{onDragAbort:t}=k.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!v.get(e))return;let{onDragPending:i}=k.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=w.current;if(t==null)return;let n=v.get(t);if(!n)return;let{onDragStart:r}=k.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:S}};(0,Fa.unstable_batchedUpdates)(()=>{r?.(i),h(sh.Initializing),d({type:sp.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),E(we.current),O(a)})},onMove(e){d({type:sp.DragMove,coordinates:e})},onEnd:s(sp.DragEnd),onCancel:s(sp.DragCancel)});we.current=o;function s(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=ae.current,o=null;if(t&&i){let{cancelDrop:s}=k.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===sp.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=sp.DragCancel)}w.current=null,(0,Fa.unstable_batchedUpdates)(()=>{d({type:e}),h(sh.Uninitialized),Se(null),E(null),O(null),we.current=null;let t=e===sp.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=k.current[t];e?.(o),f({type:t,event:o})}})}}},[v]),Ee=Cm(a,(0,X.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=v.get(r);if(w.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},w.current=r,Te(n,t))},[v,Te]));zm(a),Mf(()=>{re&&m===sh.Initializing&&h(sh.Initialized)},[re,m]),(0,X.useEffect)(()=>{let{onDragMove:e}=k.current,{active:t,activatorEvent:n,collisions:r,over:i}=ae.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:ve.x,y:ve.y},over:i};(0,Fa.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[ve.x,ve.y]),(0,X.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=ae.current;if(!e||w.current==null||!t||!i)return;let{onDragOver:a}=k.current,o=r.get(be),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,Fa.unstable_batchedUpdates)(()=>{Se(s),a?.(c),f({type:`onDragOver`,event:c})})},[be]),Mf(()=>{ae.current={activatorEvent:D,active:C,activeNode:F,collisionRect:z,collisions:ye,droppableRects:M,draggableNodes:v,draggingNode:se,draggingNodeRect:ce,droppableContainers:b,over:xe,scrollableAncestors:fe,scrollAdjustedTranslate:ve},S.current={initial:ce,translated:z}},[C,F,ye,z,v,se,ce,M,b,xe,fe,ve]),ym({...te,delta:y,draggingRect:z,pointerCoordinates:R,scrollableAncestors:fe,scrollableAncestorRects:pe});let De=(0,X.useMemo)(()=>({active:C,activeNode:F,activeNodeRect:re,activatorEvent:D,collisions:ye,containerNodeRect:ie,dragOverlay:L,draggableNodes:v,droppableContainers:b,droppableRects:M,over:xe,measureDroppableContainers:N,scrollableAncestors:fe,scrollableAncestorRects:pe,measuringConfiguration:j,measuringScheduled:P,windowRect:de}),[C,F,re,D,ye,ie,L,v,b,M,xe,N,fe,pe,j,P,de]),Oe=(0,X.useMemo)(()=>({activatorEvent:D,activators:Ee,active:C,activeNodeRect:re,ariaDescribedById:{draggable:A},dispatch:d,draggableNodes:v,over:xe,measureDroppableContainers:N}),[D,Ee,C,re,d,A,v,xe,N]);return X.createElement(tp.Provider,{value:p},X.createElement(Qm.Provider,{value:Oe},X.createElement($m.Provider,{value:De},X.createElement(oh.Provider,{value:Ce},i)),X.createElement(nh,{disabled:n?.restoreFocus===!1})),X.createElement(op,{...n,hiddenTextDescribedById:A}));function ke(){let e=T?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),lh=(0,X.createContext)(null),uh=`button`,dh=`Draggable`;function fh(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=Bf(dh),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,X.useContext)(Qm),{role:p=uh,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,_=(0,X.useContext)(g?oh:lh),[v,y]=Lf(),[b,x]=Lf(),S=Bm(o,t),C=Ff(n);return Mf(()=>(d.set(t,{id:t,key:a,node:v,activatorNode:b,data:C}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,X.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===uh?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:S,node:v,over:f,setNodeRef:y,setActivatorNodeRef:x,transform:_}}function ph(){return(0,X.useContext)($m)}var mh=`Droppable`,hh={timeout:25};function gh(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=Bf(mh),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,X.useContext)(Qm),u=(0,X.useRef)({disabled:n}),d=(0,X.useRef)(!1),f=(0,X.useRef)(null),p=(0,X.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...hh,...i},_=Ff(h??r),v=jm({callback:(0,X.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(_.current)?_.current:[_.current]),p.current=null},g)},[g]),disabled:m||!o}),[y,b]=Lf((0,X.useCallback)((e,t)=>{v&&(t&&(v.unobserve(t),d.current=!1),e&&v.observe(e))},[v])),x=Ff(t);return(0,X.useEffect)(()=>{!v||!y.current||(v.disconnect(),d.current=!1,v.observe(y.current))},[y,v]),(0,X.useEffect)(()=>(s({type:sp.RegisterDroppable,element:{id:r,key:a,disabled:n,node:y,rect:f,data:x}}),()=>s({type:sp.UnregisterDroppable,key:a,id:r})),[r]),(0,X.useEffect)(()=>{n!==u.current.disabled&&(s({type:sp.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:y,over:c,setNodeRef:b}}function _h(e){let{animation:t,children:n}=e,[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),s=Rf(n);return!n&&!r&&s&&i(s),Mf(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),X.createElement(X.Fragment,null,n,r?(0,X.cloneElement)(r,{ref:o}):null)}var vh={x:0,y:0,scaleX:1,scaleY:1};function yh(e){let{children:t}=e;return X.createElement(Qm.Provider,{value:Zm},X.createElement(oh.Provider,{value:vh},t))}var bh={position:`fixed`,touchAction:`none`},xh=e=>Gf(e)?`transform 250ms ease`:void 0,Sh=(0,X.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=xh}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...bh,width:s.width,height:s.height,top:s.top,left:s.left,transform:Jf.Transform.toString(d),transformOrigin:i&&r?pp(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return X.createElement(n,{className:o,style:f,ref:t},a)}),Ch={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:Jf.Transform.toString(t)},{transform:Jf.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function wh(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return Nf((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=Wm(a);if(!c)return;let{transform:l}=Df(a).getComputedStyle(a),u=Ep(l);if(!u)return;let d=typeof t==`function`?t:Th(t);return Yp(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function Th(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...Ch,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var Eh=0;function Dh(e){return(0,X.useMemo)(()=>{if(e!=null)return Eh++,Eh},[e])}var Oh=X.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:_,measuringConfiguration:v,scrollableAncestors:y,scrollableAncestorRects:b,windowRect:x}=ph(),S=(0,X.useContext)(oh),C=Dh(d?.id),w=rh(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:_,overlayNodeRect:g.rect,scrollableAncestors:y,scrollableAncestorRects:b,transform:S,windowRect:x}),T=Om(f),E=wh({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:v}),D=T?g.setRef:void 0;return X.createElement(yh,null,X.createElement(_h,{animation:E},d&&C?X.createElement(Sh,{key:C,id:d.id,ref:D,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:T,style:{zIndex:l,...i},transform:w},n):null))});function kh(e,t,n=.25){if(e.width<=0||e.height<=0)return`center`;let r=Ah(t.x/e.width),i=Ah(t.y/e.height);if(r>n&&r<1-n&&i>n&&i<1-n)return`center`;let a=r,o=1-r,s=i,c=1-i,l=Math.min(a,o,s,c);return l===s?`top`:l===c?`bottom`:l===a?`left`:`right`}function Ah(e){return e<0?0:e>1?1:e}var jh=(0,X.createContext)(null);function Mh(){return(0,X.useContext)(jh)}var Nh=(0,X.createContext)(null),Ph=(0,X.createContext)(!1);function Fh(){return(0,X.useContext)(Ph)}function Ih(){return(0,X.useContext)(Nh)}var Lh=`leaf:`,Rh=`tabdrop:`,zh=`strip:`,Bh=`archive:`,Vh=e=>{let t=xp(e);if(e.active.data.current?.paneId&&t.length===0)return[];for(let e of[Rh,zh]){let n=t.filter(t=>String(t.id).startsWith(e));if(n.length>0)return n}return t.length>0?t:yp(e)};function Hh({onDrop:e,onDropPane:t,onArchive:n,renderOverlay:r,children:i}){let a=up(lp(dm,{activationConstraint:{distance:4}})),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),f=(0,X.useRef)(null);(0,X.useEffect)(Sf,[]);let p=()=>{s(null),l(null),d(null),f.current=null};return(0,Z.jsxs)(ch,{sensors:a,collisionDetection:Vh,onDragStart:e=>{l(e.active.data.current?.ref??null);let t=e.active.data.current?.paneId;d(t?{id:t,count:e.active.data.current?.tabCount}:null)},onDragMove:e=>{let t=e.over,n=Uh(e),r=t&&n?Gh(String(t.id),t.rect,t.data.current,n):null,i=e.active.data.current?.paneId;i&&r&&(r=r.leafId===i?null:{leafId:r.leafId,zone:r.zone}),!Wh(f.current,r)&&(f.current=r,s(r))},onDragEnd:r=>{let i=f.current,a=r.active.data.current?.ref,o=r.active.data.current?.fromLeafId,s=r.over===null?null:String(r.over.id);p();let c=r.active.data.current?.paneId;if(c){if(i&&s&&!s.startsWith(`archive:`)){let e=document.querySelector(`[data-workspace-pane="${CSS.escape(c)}"]`)?.getBoundingClientRect();xn(()=>t?.({fromLeafId:c,toLeafId:i.leafId,edge:i.zone}),e,()=>document.querySelector(`[data-workspace-pane="${CSS.escape(c)}"]`))}return}if(s!==null&&s.startsWith(`archive:`)){a&&a.type!==`editor`&&n?.(a.session);return}if(i&&a&&o){let t=r.active.rect.current.initial,n=t?new DOMRect(t.left,t.top,t.width,t.height):void 0;Cf(()=>e({ref:a,fromLeafId:o,toLeafId:i.leafId,edge:i.zone,index:i.index}),a,i.leafId,n)}},onDragCancel:p,children:[(0,Z.jsx)(jh.Provider,{value:o,children:(0,Z.jsx)(Ph.Provider,{value:c!==null||u!==null,children:(0,Z.jsx)(Nh.Provider,{value:c,children:i})})}),(0,Z.jsx)(Oh,{dropAnimation:null,children:u?(0,Z.jsxs)(`div`,{className:`rounded-md bg-elevated px-3 py-2 text-xs text-fg shadow-lg`,children:[`Move pane · `,u.count,` `,u.count===1?`tab`:`tabs`]}):c?r(c):null})]})}function Uh(e){let t=e.activatorEvent;return typeof t.clientX!=`number`||typeof t.clientY!=`number`?null:{x:t.clientX+e.delta.x,y:t.clientY+e.delta.y}}function Wh(e,t){return e===null||t===null?e===t:e.leafId===t.leafId&&e.zone===t.zone&&e.index===t.index}function Gh(e,t,n,r){if(e.startsWith(Rh)){let e=n;if(!e)return null;let i=r.x>t.left+t.width/2;return{leafId:e.leafId,zone:`center`,index:e.index+ +!!i}}if(e.startsWith(zh)){let e=n;return e?{leafId:e.leafId,zone:`center`,index:e.count}:null}if(e.startsWith(Lh)){let n=kh({width:t.width,height:t.height},{x:r.x-t.left,y:r.y-t.top});return{leafId:e.slice(5),zone:n}}return null}var Kh=`application/x-puddle-sessions`,qh=x(y().uuid()).min(1);function Jh(e,t,n,r,i){if(i.toggle){let e=new Set(t);return e.has(r)?e.delete(r):e.add(r),{selection:e,anchor:r}}if(i.shift&&n!==null){let t=e.indexOf(n),i=e.indexOf(r);if(t!==-1&&i!==-1){let r=Math.min(t,i),a=Math.max(t,i);return{selection:new Set(e.slice(r,a+1)),anchor:n}}}return{selection:new Set([r]),anchor:r}}function Yh(e,t){let n=new Set(t),r=new Set([...e].filter(e=>n.has(e)));return r.size===e.size&&[...r].every(t=>e.has(t))?e:r}function Xh(e,t,n){if(!t.has(n)||t.size<2)return[n];let r=e.filter(e=>t.has(e));return r.length>0?r:[n]}function Zh(e){return Ws(e)}function Qh(e){try{return[...new Set(qh.parse(Gs(e)))]}catch{return[]}}function $h(e){return e.includes(Kh)}function eg({children:e,className:t,...n}){let r=(0,X.useRef)(null),i=Ii(r,{selector:`[data-session-hover]`,direct:!1});return(0,Z.jsxs)(`div`,{...n,ref:r,className:V(`session-hover-list relative isolate`,t),children:[(0,Z.jsx)(`span`,{ref:i,"aria-hidden":!0,className:`tray-hover-surface session-hover-surface`}),e]})}function tg({collapsed:e,children:t}){return(0,Z.jsx)(`div`,{"data-session-accordion":!0,"data-collapsed":e,inert:e,"aria-hidden":e,className:V(`session-accordion grid min-h-0 transition-[grid-template-rows,opacity] duration-200 ease-out`,e?`grid-rows-[0fr] opacity-0`:`grid-rows-[1fr] opacity-100`),children:(0,Z.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:t})})}function ng({icon:e,label:t,onClick:n,active:r=!1,tooltipSide:i=`bottom`}){return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,onClick:n,"data-sidebar-motion":`sessions-control-${t===`Show sessions`||t===`Hide sessions`?`toggle`:t}`,"aria-pressed":r,className:V(`flex items-center rounded-md p-1.5 transition-colors`,r?`bg-elevated text-fg`:`text-fg hover:bg-elevated`),children:[(0,Z.jsx)(e,{className:`size-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,Z.jsx)(G,{side:i,children:t})]})}function rg(e,t){let n=document.createElement(`div`);n.textContent=`${t} sessions`,n.className=`fixed -top-12 left-0 rounded-md bg-elevated px-2 py-1 text-xs text-fg`,document.body.appendChild(n),e.dataTransfer.setDragImage(n,12,12),requestAnimationFrame(()=>n.remove())}function ig(e,t){let{isOver:n,setNodeRef:r}=gh({id:`${Bh}${e}`}),i=Ih(),[a,o]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{let e=()=>o(!1);return window.addEventListener(`dragend`,e),()=>window.removeEventListener(`dragend`,e)},[]),{setNodeRef:r,armed:a||n&&i!==null&&i.type!==`editor`,props:{onDragOver:e=>{!$h(e.dataTransfer.types)&&!Md(e.dataTransfer.types)||(e.preventDefault(),o(!0))},onDragLeave:()=>o(!1),onDrop:e=>{o(!1);let n=Qh(e.dataTransfer.getData(Kh));if(n.length>0){e.preventDefault(),t(n);return}let r=Ad(e.dataTransfer.getData(Dd));!r||r.type===`editor`||(e.preventDefault(),t([r.session]))}}}}var ag=`application/x-puddle-project`;function og({projectId:e,name:t,colour:n,actions:r,editLabel:i}){let[a,o]=(0,X.useState)(!1),s=ke(),c=Le().data?.protocol,l=g(c),u=t=>s.mutate({id:e,colour:t},{onSuccess:()=>o(!1),onError:J});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(Dn,{children:[(0,Z.jsx)(nr,{projectId:e}),(0,Z.jsxs)(H,{onSelect:()=>r.onNewSessionIn(e),children:[(0,Z.jsx)(Or,{}),`New agent`]}),(0,Z.jsxs)(H,{onSelect:()=>r.onNewTerminalIn(e),children:[(0,Z.jsx)(hn,{}),`New terminal`]}),r.onNewHuddleIn&&(0,Z.jsxs)(H,{onSelect:()=>r.onNewHuddleIn?.(e),children:[(0,Z.jsx)(Zr,{className:`size-4`}),`New huddle`]}),(0,Z.jsx)(vn,{}),(0,Z.jsxs)(H,{onSelect:i.onSelect,children:[(0,Z.jsx)(Jn,{}),i.label]}),l&&(0,Z.jsxs)(H,{onSelect:()=>o(!0),children:[(0,Z.jsx)(kr,{}),`Change project colour`]})]}),(0,Z.jsx)(Ln,{open:a,onOpenChange:o,children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Project colour`}),(0,Z.jsx)(Nn,{className:Yn(n),style:Zn(n),children:t})]}),(0,Z.jsx)(Qn,{value:n,label:`Project colour`,disabled:s.isPending,onChange:u,onCustomChange:p(c)?u:void 0})]})})]})}function sg({status:e,kind:t=`agent`,agentType:n,detectedAgentType:r,stale:i=!1,className:a,iconClassName:o=`size-3`,iconStrokeScale:s=1}){let c=t===`terminal`?r:n,l=`${t===`huddle`?`huddle`:t===`terminal`?c?`${c} in terminal`:`terminal`:c??`agent`} — status: ${e.replace(`_`,` `)}${i?` (no agent activity for over an hour — possibly stalled)`:``}`;return(0,Z.jsx)(`span`,{className:V(`status-glyph`,a),"data-status":e,"data-kind":t,"data-stale":i||void 0,role:`img`,title:i?`No agent activity for over an hour — possibly stalled`:void 0,"aria-label":l,children:t===`huddle`?(0,Z.jsx)(Zr,{className:o}):t===`terminal`&&!c?(0,Z.jsx)(hn,{className:o,strokeWidth:2*s}):(0,Z.jsx)(Ei,{type:c??``,className:o,strokeScale:s})})}var cg={no_live_runtime:`This session has no running persistent runtime.`,runtime_unavailable:`The runtime is unavailable. Reconnect before restarting it.`,runtime_changed:`The runtime moved to another session. Open its current session to inspect it.`,release_unavailable:`The installed runtime software is unavailable.`,conversation_unknown:`The exact native conversation is not available for resuming.`,resume_unsupported:`This agent cannot resume its native conversation.`,worktree_missing:`The session’s working directory is missing.`,state_not_saved:`Runtime state has not finished saving. Refresh before restarting.`};function lg({session:e,onClose:t}){let n=Ye(),r=[`session-runtime`,e.id],i=`/api/sessions/${e.id}/runtime`,a=Ke({queryKey:r,queryFn:async()=>re.parse(await he(`GET`,i)),retry:!1,staleTime:0,gcTime:0}),o=He({mutationKey:r,retry:!1,networkMode:`always`,mutationFn:async e=>A.parse(await he(`POST`,`${i}/restart`,{fingerprint:e})),onMutate:()=>n.cancelQueries({queryKey:r}),onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:r}),n.invalidateQueries({queryKey:[`sessions`]}),n.invalidateQueries({queryKey:[`project`,e.project_id]}),n.invalidateQueries({queryKey:[`frontend-host-updates`]})])}}),s=a.data,c=s?.restart.available?s.restart.fingerprint:null;return(0,Z.jsx)(Ln,{open:!0,onOpenChange:e=>{!e&&!o.isPending&&t()},children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(In,{children:[`Runtime · `,e.title||e.agent_title||e.id.slice(0,8)]}),(0,Z.jsx)(Nn,{children:`Inspect this session’s running software. Updating the installed default leaves existing runtimes running.`}),s&&(0,Z.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,Z.jsxs)(`p`,{children:[`Running build: `,s.runtime?.version??`None`,s.runtime&&!s.runtime.connected&&` · disconnected`]}),(0,Z.jsxs)(`p`,{children:[`Installed default: `,s.installed?.version??`Unavailable`]}),s.runtime?.lifetime===`host_session`&&(0,Z.jsx)(`p`,{className:`text-xs text-warning`,children:`Host-session lifetime: this host may stop the runtime when its login or SSH session ends. Daemon updates are blocked while it is running.`}),s.runtime&&s.runtime.lifetime!==`service`&&s.runtime.lifetime!==`host_session`&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Runtime lifetime could not be verified.`}),s.runtime?.terminals&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`text-fg-secondary`,children:`Affected terminals`}),(0,Z.jsx)(`ul`,{className:`mt-1 space-y-1 text-xs text-fg-muted`,children:s.runtime.terminals.map(({term:t})=>(0,Z.jsx)(`li`,{children:t===`agent`?e.kind===`agent`?`Main agent (${e.agent_type})`:`Main terminal`:`Shell ${t.replace(`shell-`,``)}`},t))})]}),!s.restart.available&&(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:cg[s.restart.reason]}),c&&(0,Z.jsxs)(`p`,{className:`text-xs text-warning`,children:[`Restart stops this runtime and all listed terminals. Shell jobs and in-memory process state are lost; extra shell tabs are closed.`,` `,e.kind===`agent`?`The agent resumes its exact native conversation.`:`A fresh shell opens in the saved directory.`,` `,`Commands and interrupted programmes are not replayed.`]})]}),a.isPending&&(0,Z.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:`Inspecting runtime…`}),a.isError&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-warning`,children:`Runtime inspection is unavailable. Refresh before another action.`}),o.isError&&(0,Z.jsxs)(`p`,{role:`alert`,className:`text-sm text-warning`,children:[o.error.message,` Inspect the current runtime before another action; the restart was not repeated.`]}),o.isSuccess&&(0,Z.jsx)(`p`,{role:`status`,className:`text-sm text-fg-secondary`,children:`The replacement was observed. Its current state is shown above.`}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,disabled:o.isPending,onClick:t,children:`Close`}),(0,Z.jsx)(q,{variant:`ghost`,disabled:a.isFetching||o.isPending,onClick:()=>void a.refetch({cancelRefetch:!1}),children:`Refresh`}),c&&(0,Z.jsx)(q,{variant:`danger`,disabled:a.isFetching||a.isError||o.isPending,onClick:()=>{n.isMutating({mutationKey:r})||o.mutate(c)},children:o.isPending?`Restarting…`:`Restart on ${s?.installed?.version}`})]})]})})}function ug(e){let t=e.status===`starting`||e.status===`running`||e.status===`waiting_input`,n=e.status===`archived`,r=e.worktree_missing?`Worktree directory is gone — resume unavailable`:e.conversation_missing?`Native conversation is missing — resume unavailable`:void 0;return{live:t,archived:n,resumable:e.kind!==`huddle`&&(e.status===`exited`||e.status===`interrupted`)&&!r,resumeUnavailable:r}}var dg={Item:Cr,Separator:fr,Sub:yr,SubTrigger:pr,SubContent:Tr},fg={Item:H,Separator:vn,Sub:wn,SubTrigger:yn,SubContent:jn};function pg(e,t,n){let r=Fe(`resume`),i=Fe(`kill`),a=Je(),o=qe(),c=we(),l=Ee(),u=De(),d=Re(),f=Xe(),p=dn(),m=ji(),h=Ba(T(e),{projectId:e.project_id,paneId:n}),g=Ge(m??void 0),_=Me(m??void 0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(e.title??``),[w,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(null),[k,A]=(0,X.useState)(!1),ee=Le().data?.protocol,j=e.kind!==`huddle`&&!P()&&s(ee),M=(g.data??[]).filter(t=>t.agent_type===e.agent_type),N=e.kind===`agent`&&!e.worktree_missing&&e.status!==`archived`&&M.some(t=>t.id!==e.account_id),F=(g.data??[]).filter(t=>t.agent_type!==e.agent_type&&t.logged_in),I=_.data?.default_account_id,te=typeof I==`number`?I:null,ne=(g.data??[]).filter(e=>e.logged_in),re=te===null?ne:[...ne.filter(e=>e.id===te),...ne.filter(e=>e.id!==te)];return{menu:{session:e,...h&&e.status!==`archived`?{openWindow:h}:{},...j?{inspectRuntime:()=>A(!0)}:{},...ug(e),canMigrate:N,sameAgent:M,handoffTargets:e.kind===`agent`&&!e.worktree_missing&&e.status!==`archived`?F:[],setHandoffTo:O,resume:()=>r.mutate(e.id,{onError:e=>{let t=zi(e);t?p(`/project/${t.projectId}/session/${t.sessionId}`):J(e)}}),kill:()=>i.mutate(e.id,{onError:e=>J(e)}),openClearEnv:()=>y(`clear-env`),openTerminal:()=>f.mutate({project_id:e.project_id,kind:`terminal`,separate_branch:!1,separate_worktree:!1,join_worktree:e.worktree_path},{onSuccess:e=>void p(`/project/${e.project_id}/session/${e.id}`),onError:e=>J(e)}),spawnAccounts:re,defaultAccountId:te,spawnAgent:t=>f.mutate({project_id:e.project_id,account_id:t,separate_branch:!1,separate_worktree:!1,join_worktree:e.worktree_path},{onSuccess:e=>void p(`/project/${e.project_id}/session/${e.id}`),onError:e=>J(e)}),openRename:()=>{C(e.title??``),x(!0)},archive:()=>a.mutate(e.id,{onSuccess:()=>t?.(e.id),onError:e=>J(e)}),unarchive:()=>o.mutate(e.id,{onError:e=>J(e)}),setMigrateTo:E},dialogs:(0,Z.jsxs)(Z.Fragment,{children:[k&&(0,Z.jsx)(lg,{session:e,onClose:()=>A(!1)}),(0,Z.jsx)(Ln,{open:v===`clear-env`,onOpenChange:e=>{e||y(null)},children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Clear captured environment?`}),(0,Z.jsx)(Nn,{children:`Variables exported in this session’s terminals will no longer be injected into new shells or agent restarts.`})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:()=>y(null),children:`Cancel`}),(0,Z.jsx)(q,{variant:`danger`,disabled:d.isPending,onClick:()=>d.mutate(e.id,{onSuccess:e=>{y(null),U.success(e.cleared===0?`Nothing was captured`:`Cleared ${e.cleared} captured var${e.cleared===1?``:`s`}`)},onError:e=>{y(null),J(e)}}),children:`Clear captured env`})]})]})}),(0,Z.jsx)(Ln,{open:b,onOpenChange:x,children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsx)(In,{children:`Rename session`}),(0,Z.jsx)(Nn,{children:`Leave it empty to use the agent’s own session name.`})]}),(0,Z.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:t=>{t.preventDefault(),c.mutate({sessionId:e.id,title:S.trim()},{onSuccess:()=>x(!1),onError:e=>J(e)})},children:[(0,Z.jsx)(Gn,{value:S,onChange:e=>C(e.target.value),placeholder:e.agent_title??e.osc_title??e.id.slice(0,8),autoFocus:!0}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{type:`button`,variant:`ghost`,onClick:()=>x(!1),children:`Cancel`}),(0,Z.jsx)(q,{type:`submit`,disabled:c.isPending,children:`Rename`})]})]})]})}),(0,Z.jsx)(Ln,{open:w!==null,onOpenChange:e=>!e&&E(null),children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsxs)(In,{children:[`Move this session to `,w?.label,`?`]}),(0,Z.jsx)(Nn,{children:`The conversation continues under that account’s credentials. If the session is running it is stopped first, then resumed on the new account.`})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:()=>E(null),children:`Cancel`}),(0,Z.jsx)(q,{disabled:l.isPending,onClick:()=>{w&&l.mutate({sessionId:e.id,accountId:w.id},{onSuccess:()=>{E(null),U.success(`Moved to ${w.label}`)},onError:e=>{E(null),J(e)}})},children:`Move session`})]})]})}),(0,Z.jsx)(Ln,{open:D!==null,onOpenChange:e=>!e&&O(null),children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsxs)(In,{children:[`Hand off to `,D?.agent_type,`?`]}),(0,Z.jsxs)(Nn,{children:[`A new session starts in this worktree and branch on`,` `,(0,Z.jsx)(`span`,{className:`text-fg`,children:D?.label}),`, opening with a summary of the conversation so far plus the branch’s commits and status. The conversation itself is summarised, not moved — the new agent will not have the old one’s reasoning. This session is left as it is.`]})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:()=>O(null),children:`Cancel`}),(0,Z.jsx)(q,{disabled:u.isPending,onClick:()=>{D&&u.mutate({sessionId:e.id,accountId:D.id},{onSuccess:e=>{O(null),U.success(`Handed off to ${D.agent_type}`),p(`/session/${e.id}`)},onError:e=>{O(null),J(e)}})},children:`Hand off`})]})]})})]})}}function mg({kit:e,menu:t}){let{Item:n,Separator:r,Sub:i,SubTrigger:a,SubContent:o}=e,{session:s}=t;return(0,Z.jsxs)(Z.Fragment,{children:[t.openWindow&&(0,Z.jsxs)(n,{onSelect:t.openWindow,children:[(0,Z.jsx)(er,{}),` Open session in window`]}),(0,Z.jsxs)(n,{onSelect:t.openRename,children:[(0,Z.jsx)(Jn,{}),` Rename`]}),t.resumable&&(0,Z.jsxs)(n,{onSelect:t.resume,children:[(0,Z.jsx)(at,{}),` Resume`]}),t.live&&(0,Z.jsxs)(n,{onSelect:t.kill,children:[(0,Z.jsx)(xt,{}),` Kill`]}),t.archived?(0,Z.jsxs)(n,{onSelect:t.unarchive,children:[(0,Z.jsx)(tr,{}),` Unarchive`]}):(0,Z.jsxs)(n,{onSelect:t.archive,children:[(0,Z.jsx)(rr,{}),` Archive`]}),(t.inspectRuntime||!t.archived)&&(0,Z.jsx)(r,{}),t.inspectRuntime&&(0,Z.jsxs)(n,{onSelect:t.inspectRuntime,children:[(0,Z.jsx)(di,{}),` Runtime`]}),!t.archived&&s.kind!==`huddle`&&(0,Z.jsxs)(n,{onSelect:t.openClearEnv,children:[(0,Z.jsx)(_a,{}),` Clear captured env`]}),(t.canMigrate||t.handoffTargets.length>0||!s.worktree_missing)&&(0,Z.jsx)(r,{}),t.canMigrate&&(0,Z.jsxs)(i,{children:[(0,Z.jsxs)(a,{children:[(0,Z.jsx)(Ma,{}),` Move to account…`]}),(0,Z.jsx)(o,{children:t.sameAgent.map(e=>{let r=e.id===s.account_id;return(0,Z.jsxs)(n,{disabled:r,onSelect:()=>t.setMigrateTo(e),children:[e.label,r&&(0,Z.jsx)(`span`,{className:`ml-auto text-fg-muted`,children:`current`})]},e.id)})})]}),t.handoffTargets.length>0&&(0,Z.jsxs)(i,{children:[(0,Z.jsxs)(a,{children:[(0,Z.jsx)(ma,{}),` Hand off to agent…`]}),(0,Z.jsx)(o,{children:t.handoffTargets.map(e=>(0,Z.jsxs)(n,{onSelect:()=>t.setHandoffTo(e),children:[(0,Z.jsx)(Ei,{type:e.agent_type,className:`size-4`}),e.agent_type,(0,Z.jsx)(`span`,{className:`ml-auto text-fg-muted`,children:e.label})]},e.id))})]}),!s.worktree_missing&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(n,{onSelect:t.openTerminal,children:[(0,Z.jsx)(hn,{}),` Open terminal in worktree`]}),t.spawnAccounts.length>0&&(0,Z.jsxs)(i,{children:[(0,Z.jsxs)(a,{children:[(0,Z.jsx)(Or,{}),` Spawn agent in worktree`]}),(0,Z.jsx)(o,{children:t.spawnAccounts.map(e=>(0,Z.jsxs)(n,{onSelect:()=>t.spawnAgent(e.id),children:[(0,Z.jsx)(Ei,{type:e.agent_type,className:`size-4 shrink-0`}),e.agent_type,`/`,e.label,e.id===t.defaultAccountId&&(0,Z.jsx)(`span`,{className:`ml-auto pl-3 text-fg-muted`,children:`default`})]},e.id))})]}),(0,Z.jsxs)(n,{onSelect:()=>{window.location.href=pe(`vscode`,s.worktree_path,me())},children:[(0,Z.jsx)(va,{}),` Open in VS Code`]}),(0,Z.jsxs)(n,{onSelect:()=>{window.location.href=pe(`cursor`,s.worktree_path,me())},children:[(0,Z.jsx)(va,{}),` Open in Cursor`]})]})]})}function hg({batch:e}){return(0,Z.jsxs)(H,{onSelect:()=>e.archiveAll(e.sessionIds),children:[(0,Z.jsx)(rr,{}),` Archive all`,(0,Z.jsx)(`span`,{className:`ml-auto pl-3 tabular-nums text-fg-muted`,children:e.sessionIds.length})]})}function gg({menu:e}){return(0,Z.jsxs)(ur,{children:[(0,Z.jsx)(mr,{asChild:!0,children:(0,Z.jsxs)(q,{variant:`ghost`,size:`icon`,className:`island-outline size-7 rounded-full bg-elevated shadow-sm hover:bg-surface`,onClick:e=>e.preventDefault(),children:[(0,Z.jsx)(vr,{}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Session actions`})]})}),(0,Z.jsx)(Sr,{align:`end`,children:(0,Z.jsx)(mg,{kit:dg,menu:e})})]})}function _g({session:e,paneId:t,onArchived:n,batch:r,children:i}){let{menu:a,dialogs:o}=pg(e,n,t);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_n,{children:[(0,Z.jsx)(bn,{asChild:!0,children:typeof i==`function`?i(a):i}),(0,Z.jsx)(Dn,{children:r?(0,Z.jsx)(hg,{batch:r}):(0,Z.jsx)(mg,{kit:fg,menu:a})})]}),o]})}function vg({menu:e,batch:t}){return(0,Z.jsx)(Dn,{children:t?(0,Z.jsx)(hg,{batch:t}):(0,Z.jsx)(mg,{kit:fg,menu:e})})}var yg=`group-hover:[transform:translateX(var(--tail))]`;function bg({session:e,activeSessionId:t,accountLabel:n,onPromote:r,onArchived:i,selectedIds:a,selection:o,ellipsis:s,lastActive:c=!1}){let l=_i(),u=o?.ids.has(e.id)??!1,d=o&&u&&a&&a.length>1?{sessionIds:a,archiveAll:o.onArchive}:void 0,f=e.kind===`agent`?e.agent_type??`agent`:e.kind,p=c?e.last_activity_at===null?``:` · ${sr(e.last_activity_at)}`:e.account_id!==null&&n.has(e.account_id)?` · ${n.get(e.account_id)}`:``;return(0,Z.jsx)(_g,{session:e,onArchived:i,batch:d,children:n=>(0,Z.jsxs)(pn,{draggable:!1,onClick:t=>{if(!o)return;let n=t.shiftKey||t.metaKey||t.ctrlKey;o.onSelect(e.id,{shift:t.shiftKey,toggle:t.metaKey||t.ctrlKey}),n&&t.preventDefault()},onDoubleClick:r&&(()=>r(e.id)),onContextMenu:()=>{o&&!u&&o.onSelectOnly(e.id)},to:`/project/${e.project_id}/session/${e.id}`,"data-sidebar-motion":`sessions-item-${e.id}`,"data-session-hover":!0,"data-session-active":e.id===t||void 0,"aria-selected":o?u:void 0,className:V(`session-hover-row sidebar-row group relative flex items-center gap-[var(--ui-item-gap)] px-2 py-2 transition-colors compact:py-1.5`,(u||e.id===t)&&`bg-explorer-selection`),children:[(0,Z.jsx)(sg,{status:e.status,kind:e.kind,agentType:e.agent_type,detectedAgentType:e.detected_agent_type,stale:e.stale_running}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(Vl,{text:l(e),className:`font-sans text-xs text-fg`,hoverClass:yg}),(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-2xs text-fg-muted`,children:[(0,Z.jsx)(Xr,{className:`size-3 shrink-0 text-fg-gold`}),(0,Z.jsx)(Vl,{text:e.branch,hoverClass:yg})]}),(0,Z.jsx)(`span`,{className:`flex items-center gap-1 text-2xs text-fg-muted`,children:(0,Z.jsx)(Vl,{text:`${f}${p}`,hoverClass:yg})})]}),e.skip_permissions&&(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(Aa,{className:`size-3.5 shrink-0 text-warning`})}),(0,Z.jsx)(G,{children:`Running with permission prompts skipped`})]}),e.worktree_missing&&(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(ba,{className:`size-3.5 shrink-0 text-interrupted`})}),(0,Z.jsx)(G,{children:`Worktree directory is gone — archive only`})]}),e.conversation_missing&&(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(wa,{className:`size-3.5 shrink-0 text-interrupted`})}),(0,Z.jsx)(G,{children:`Native conversation is missing — resume unavailable`})]}),e.native_sync===`fallback`&&e.status!==`archived`&&(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(xi,{className:`size-3.5 shrink-0 text-fg-muted`})}),(0,Z.jsx)(G,{children:`In-agent conversation switches are not synchronised`})]}),s&&(0,Z.jsx)(`span`,{className:`absolute right-2 top-1/2 z-10 -translate-y-1/2 opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto focus-within:opacity-100 focus-within:pointer-events-auto has-[[data-state=open]]:opacity-100 has-[[data-state=open]]:pointer-events-auto pointer-coarse:opacity-100 pointer-coarse:pointer-events-auto`,children:(0,Z.jsx)(gg,{menu:n})})]})})}function xg({header:e,query:t,showArchived:n,onShowArchivedChange:r,groups:i,accounts:a,activeSessionId:o,onReorder:s,onPromote:c,archived:l,onArchived:u,onArchiveDrop:d,selection:f,projectActions:p}){let[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),b=ig(`list`,d),x=Ih(),S=m!==null||x!==null&&x.type!==`editor`,C=ke(),w=Pi(`palette.toggle`),E=new Map(a.map(e=>[e.id,e.label])),D=_i(),O=t.toLocaleLowerCase().trim().split(/\s+/).filter(Boolean),k=(e,t=!1)=>O.length===0?e:e.map(e=>({...e,sessions:e.sessions.filter(n=>{let r=[e.name,D(n),n.branch,n.kind===`agent`?n.agent_type??`agent`:n.kind,t?n.last_activity_at===null?``:sr(n.last_activity_at):n.account_id===null?``:E.get(n.account_id)].join(` `).toLocaleLowerCase();return O.every(e=>r.includes(e))})})).filter(e=>e.sessions.length>0),A=k(i),ee=i.reduce((e,t)=>e+(t.collapsed?0:t.sessions.length),0),j=(0,X.useMemo)(()=>A.flatMap(e=>(e.collapsed?[]:e.sessions).map(e=>e.id)),[A]),M=j.filter(e=>f.ids.has(e)),{height:N,handle:P}=Il(`sessions-archived`,200,{sized:`below`,min:96}),F=k((0,X.useMemo)(()=>{let e=new Set,t=i.map(t=>{let n=l.filter(e=>e.project_id===t.projectId);for(let t of n)e.add(t.id);return{...t,sessions:n}}),n=l.filter(t=>!e.has(t.id));return[...t.filter(e=>e.sessions.length>0),...n.length>0?[{projectId:``,name:``,abbrev:``,colour:null,repoId:-1,sessions:n}]:[]]},[i,l]),!0),I=O.length>0&&A.length===0&&(!n||F.length===0),te=(e,t)=>{let n=En(i,e,t);n&&s(n)},ne=(e,t)=>{y(null);let n=t.trim();!n||n===e.name||C.mutate({id:e.projectId,name:n},{onError:e=>J(e)})};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`workspace-surface island-outline grid min-h-0 flex-1 grid-cols-1 grid-rows-[minmax(0,1fr)] bg-surface`,children:[e,(0,Z.jsxs)(eg,{className:`no-scrollbar col-start-1 row-start-1 min-h-0 overflow-y-auto overscroll-contain pb-1.5 pt-[calc(var(--ui-control-height)+1.5rem)]`,children:[O.length===0&&ee===0&&l.length===0&&(0,Z.jsxs)(`p`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[`No sessions yet — press `,w,` to start one.`]}),I&&(0,Z.jsx)(`p`,{role:`status`,className:`px-3 py-3 text-xs text-fg-muted`,children:`No matching sessions.`}),A.map(e=>(0,Z.jsxs)(`div`,{"data-session-project":e.projectId,className:`mx-2 border-t border-border py-1 first:border-t-0`,onDragOver:t=>{g&&(t.preventDefault(),g!==e.projectId&&p.onMoveProject(g,e.projectId))},children:[v===e.projectId?(0,Z.jsx)(gi,{initial:e.name,maxLength:100,className:`block w-full px-3 pb-1 pt-2 text-2xs font-medium tracking-wide text-fg`,onCommit:t=>ne(e,t),onCancel:()=>y(null)}):(0,Z.jsxs)(_n,{children:[(0,Z.jsx)(bn,{asChild:!0,children:(0,Z.jsx)(pn,{to:`/project/${e.projectId}`,"data-sidebar-motion":`sessions-project-${e.projectId}`,style:Zn(e.colour),...On(),draggable:!0,title:Si(e.projectId)?`Drag project back to its host window`:void 0,onDragStart:t=>{Ti(t.dataTransfer,e.projectId)||(t.dataTransfer.setData(ag,e.projectId),_(e.projectId))},onDragEnd:()=>_(null),className:V(`block truncate px-3 pb-1 pt-2 text-2xs font-medium uppercase tracking-wide transition-colors compact:pb-0.5 compact:pt-1.5`,Si(e.projectId)&&`cursor-grab active:cursor-grabbing`,e.colour?V(Yn(e.colour),`hover:opacity-75`):`text-fg-gold hover:text-fg`,g===e.projectId&&`opacity-50`),children:e.name})}),(0,Z.jsx)(og,{projectId:e.projectId,name:e.name,colour:e.colour,actions:p,editLabel:{label:`Change project name`,onSelect:()=>y(e.projectId)}})]}),(0,Z.jsx)(tg,{collapsed:!!e.collapsed||g!==null,children:(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5 overflow-hidden compact:gap-0`,children:e.sessions.map(e=>(0,Z.jsx)(`li`,{draggable:!0,onDragStart:t=>{let n=Xh(j,f.ids,e.id);t.dataTransfer.setData(Dd,kd(T(e),{projectId:e.project_id})),t.dataTransfer.setData(Kh,Zh(n)),t.dataTransfer.effectAllowed=`copyMove`,n.length>1&&rg(t,n.length),f.ids.has(e.id)||f.onSelectOnly(e.id),h({sourceId:e.id,sessionIds:n})},onDragEnd:()=>h(null),onDragOver:t=>{t.preventDefault(),m?.sessionIds.length===1&&m.sourceId!==e.id&&te(m.sourceId,e.id)},className:V(`transition-opacity`,m?.sessionIds.includes(e.id)&&`opacity-50`),children:(0,Z.jsx)(bg,{session:e,activeSessionId:o,accountLabel:E,onPromote:c,onArchived:u,selectedIds:M,selection:f,ellipsis:!0})},e.id))})})]},e.projectId))]})]}),(l.length>0||S||n)&&(0,Z.jsxs)(Z.Fragment,{children:[!n&&(0,Z.jsx)(`div`,{className:`h-[var(--ui-surface-gap)] shrink-0`}),n&&(0,Z.jsx)(Ll,{handle:P,label:`Resize the archived sessions`}),(0,Z.jsxs)(`div`,{"data-session-archive-island":!0,className:V(`workspace-surface island-outline flex shrink-0 flex-col bg-surface transition-[height] duration-200 ease-out`,P.dragging&&`transition-none`),style:{height:n?N:`calc(var(--text-2xs--line-height) + 0.75rem)`,maxHeight:`70%`},children:[(0,Z.jsxs)(`button`,{"data-sidebar-motion":`sessions-archive`,ref:b.setNodeRef,type:`button`,onClick:()=>r(!n),"aria-expanded":n,...b.props,className:V(`flex w-full shrink-0 items-center gap-1.5 px-3 py-1.5 text-2xs uppercase tracking-wide text-fg-gold transition-colors hover:text-fg`,b.armed&&`bg-selection text-fg`),children:[(0,Z.jsx)(qn,{className:V(`size-3 transition-transform`,n&&`rotate-90`)}),(0,Z.jsx)(rr,{className:`size-3`}),(0,Z.jsx)(`span`,{children:`Archived`}),(0,Z.jsx)(`span`,{className:`ml-auto tabular-nums`,children:l.length})]}),(0,Z.jsx)(Sn,{motionKey:String(n),className:`min-h-0 flex-1 overflow-hidden`,children:n&&(0,Z.jsxs)(eg,{className:`no-scrollbar h-full min-h-0 overflow-y-auto overscroll-contain pb-1.5`,children:[l.length===0&&(0,Z.jsx)(`p`,{className:`px-3 py-3 text-xs text-fg-muted`,children:`No archived sessions.`}),F.map(e=>(0,Z.jsxs)(`div`,{"data-session-project":e.projectId,className:`mx-2 border-t border-border py-1 first:border-t-0`,children:[e.name!==``&&(0,Z.jsx)(`div`,{style:Zn(e.colour),className:V(`truncate px-3 pb-0.5 pt-1.5 text-2xs font-medium uppercase tracking-wide`,e.colour?V(Yn(e.colour),`opacity-70`):`text-fg-muted`),children:e.name}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-0.5 compact:gap-0`,children:e.sessions.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(bg,{session:e,activeSessionId:o,accountLabel:E,onArchived:u,ellipsis:!0,lastActive:!0})},e.id))})]},e.projectId))]})})]})]})]})}function Sg({searching:e,setSearching:t,showArchived:n,onShowArchivedChange:r,groups:i,accounts:a,activeSessionId:o,onReorder:s,onPromote:c,archived:l,onNewSession:u,onNewHuddle:d,onNewTerminal:f,onCollapse:p,onArchived:m,onArchiveDrop:h,selection:g,projectActions:_}){let[v,y]=(0,X.useState)(``),b=(0,X.useRef)(null),x=(0,X.useRef)(null);(0,X.useEffect)(()=>{e&&x.current?.focus()},[e]);let S=()=>{t(!1),y(``),requestAnimationFrame(()=>{b.current?.querySelector(`[aria-label="New sessions"] > button:last-child`)?.focus()})};return(0,Z.jsx)(`div`,{className:`flex h-full min-h-0 flex-col`,children:(0,Z.jsx)(xg,{header:(0,Z.jsxs)(`div`,{ref:b,className:`session-sidebar-controls pointer-events-none z-10 col-start-1 row-start-1 self-start`,"data-searching":e,children:[!e&&(0,Z.jsx)(`div`,{className:`pointer-events-auto flex items-center`,children:(0,Z.jsx)(ng,{icon:Da,label:`Hide sessions`,onClick:p})}),(0,Z.jsx)(Ri,{label:e?`Search sessions`:`New sessions`,variant:`selection`,className:`session-sidebar-search-tray pointer-events-auto`,children:e?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(mi,{className:`ml-1 size-4 shrink-0 text-fg-muted`}),(0,Z.jsx)(`input`,{ref:x,type:`search`,"aria-label":`Search displayed sessions`,placeholder:`Search sessions…`,value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),S())},className:`h-[var(--ui-control-height)] min-w-0 flex-1 bg-transparent text-xs text-fg outline-none`}),(0,Z.jsx)(ng,{icon:Rn,label:`Close session search`,onClick:S})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ng,{icon:Or,label:`New agent`,onClick:u}),(0,Z.jsx)(ng,{icon:hn,label:`New terminal`,onClick:f}),d&&(0,Z.jsx)(ng,{icon:Zr,label:`New huddle`,onClick:d}),(0,Z.jsx)(ng,{icon:mi,label:`Search sessions`,onClick:()=>t(!0)})]})})]}),query:v,showArchived:n,onShowArchivedChange:r,groups:i,accounts:a,activeSessionId:o,onReorder:s,onPromote:c,archived:l,onArchived:m,onArchiveDrop:h,selection:g,projectActions:_})})}function Cg(e){let t=(0,X.useRef)(null);return(0,X.useLayoutEffect)(()=>{let e=t.current,n=[...e.querySelectorAll(`[data-project-abbreviation-measure]`)],r=()=>{let t=1;for(let e of n){let n=parseFloat(getComputedStyle(e.parentElement).width),r=parseFloat(getComputedStyle(e).width);n>0&&r>0&&(t=Math.min(t,n/r))}e.style.setProperty(`--project-abbreviation-size`,`${t}em`)};r();let i=new ResizeObserver(r);for(let e of n)i.observe(e.parentElement),i.observe(e);return()=>i.disconnect()},[e]),t}function wg({text:e}){return(0,Z.jsxs)(`span`,{className:`relative block whitespace-nowrap`,children:[(0,Z.jsx)(`span`,{"data-project-abbreviation-measure":!0,"aria-hidden":`true`,className:`pointer-events-none invisible absolute left-0 top-0 w-max`,children:e}),(0,Z.jsx)(`span`,{className:`inline-block`,"data-project-abbreviation":!0,style:{fontSize:`var(--project-abbreviation-size, 1em)`},children:e})]})}function Tg({onArchiveDrop:e,onShowArchived:t}){let n=ig(`rail`,e);return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(`button`,{"data-sidebar-motion":`sessions-archive`,ref:n.setNodeRef,type:`button`,onClick:t,...n.props,className:V(`island-outline mt-auto flex min-h-9 w-full shrink-0 items-center justify-center rounded-[var(--ui-surface-radius)] bg-tray p-1.5 text-fg-muted transition-colors hover:bg-elevated hover:text-fg compact:p-1`,n.armed&&`bg-selection text-fg`),children:[(0,Z.jsx)(rr,{className:`size-4`}),(0,Z.jsx)(`span`,{className:`sr-only`,children:`Archived sessions`})]})}),(0,Z.jsx)(G,{side:`left`,children:`Show archived sessions, or drop selected sessions here to archive them`})]})}function Eg({session:e,accountLabel:t}){return(0,Z.jsxs)(`span`,{className:`flex flex-col`,children:[(0,Z.jsx)(`span`,{children:_i()(e)}),(0,Z.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e.branch}),(0,Z.jsx)(`span`,{className:`mt-0.5 flex items-center gap-1 text-2xs text-fg-muted`,children:e.kind===`huddle`?(0,Z.jsx)(`span`,{children:`huddle`}):e.kind===`terminal`?(0,Z.jsxs)(Z.Fragment,{children:[e.detected_agent_type?(0,Z.jsx)(Ei,{type:e.detected_agent_type,className:`size-3 shrink-0`}):(0,Z.jsx)(hn,{className:`size-3 shrink-0`}),(0,Z.jsx)(`span`,{children:e.detected_agent_type?`${e.detected_agent_type} · terminal`:`terminal`})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ei,{type:e.agent_type??``,className:`size-3 shrink-0`}),(0,Z.jsx)(`span`,{children:e.agent_type}),t&&(0,Z.jsxs)(`span`,{children:[` · `,t]})]})})]})}function Dg({session:e,accountLabel:t,activeSessionId:n,onPromote:r,onArchived:i,selectedIds:a,selection:o}){let{menu:s,dialogs:c}=pg(e,i),l=_i(),u=o.ids.has(e.id),d=u&&a.length>1?{sessionIds:a,archiveAll:o.onArchive}:void 0;return(0,Z.jsxs)(_n,{children:[(0,Z.jsxs)(K,{children:[(0,Z.jsx)(bn,{asChild:!0,children:(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsxs)(pn,{draggable:!1,"aria-current":e.id===n?`true`:void 0,onClick:t=>{let n=t.shiftKey||t.metaKey||t.ctrlKey;o.onSelect(e.id,{shift:t.shiftKey,toggle:t.metaKey||t.ctrlKey}),n&&t.preventDefault()},onDoubleClick:()=>r(e.id),onContextMenu:()=>{u||o.onSelectOnly(e.id)},to:`/project/${e.project_id}/session/${e.id}`,"data-sidebar-motion":`sessions-item-${e.id}`,"data-session-hover":!0,"data-session-active":e.id===n||void 0,"aria-selected":u,className:V(`session-hover-row relative flex items-center rounded-[var(--ui-radius)] p-1 transition-colors`,(u||e.id===n)&&`bg-explorer-selection`),children:[(0,Z.jsx)(sg,{status:e.status,kind:e.kind,agentType:e.agent_type,detectedAgentType:e.detected_agent_type,stale:e.stale_running,className:`size-5 shrink-0 compact:size-4`,iconClassName:`size-full`,iconStrokeScale:.75}),(0,Z.jsx)(`span`,{className:`sr-only`,children:l(e)})]})})}),(0,Z.jsx)(G,{side:`left`,children:(0,Z.jsx)(Eg,{session:e,accountLabel:t})})]}),(0,Z.jsx)(vg,{menu:s,batch:d}),c]})}function Og({groups:e,accounts:t,activeSessionId:n,onReorder:r,onPromote:i,onExpand:a,onShowArchived:o,onSearch:s,onNewTerminal:c,onNewSession:l,onNewHuddle:u,onArchived:d,onArchiveDrop:f,selection:p,projectActions:m}){let[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(null),x=Cg(JSON.stringify([e.map(({projectId:e,abbrev:t})=>[e,t]),y])),S=ke(),C=new Map(t.map(e=>[e.id,e.label])),w=(0,X.useMemo)(()=>e.flatMap(e=>(e.collapsed?[]:e.sessions).map(e=>e.id)),[e]),E=w.filter(e=>p.ids.has(e)),D=(t,n)=>{let i=En(e,t,n);i&&r(i)},O=(e,t)=>{b(null);let n=L(t);!n||n===e.abbrev||S.mutate({id:e.projectId,abbrev:n},{onError:e=>J(e)})};return(0,Z.jsxs)(`div`,{ref:x,className:`flex h-full min-h-0 w-9 shrink-0 flex-col items-center gap-[var(--ui-surface-gap)] overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`relative flex w-full shrink-0 flex-col items-center gap-1 compact:gap-0.5`,children:(0,Z.jsxs)(Ri,{label:`New sessions`,variant:`island`,vertical:!0,children:[(0,Z.jsx)(ng,{icon:Oa,label:`Show sessions`,onClick:a,tooltipSide:`left`}),(0,Z.jsx)(`div`,{"aria-hidden":`true`,className:`mx-1 h-px self-stretch bg-border`}),(0,Z.jsx)(ng,{icon:Or,label:`New agent`,onClick:l,tooltipSide:`left`}),(0,Z.jsx)(ng,{icon:hn,label:`New terminal`,onClick:c,tooltipSide:`left`}),u&&(0,Z.jsx)(ng,{icon:Zr,label:`New huddle`,onClick:u,tooltipSide:`left`}),(0,Z.jsx)(ng,{icon:mi,label:`Search sessions`,onClick:s,tooltipSide:`left`})]})}),(0,Z.jsx)(eg,{className:`collapsed-session-list workspace-surface island-outline no-scrollbar flex min-h-0 w-full shrink flex-col items-center overflow-y-auto overscroll-contain bg-tray`,children:e.map(e=>(0,Z.jsxs)(`div`,{"data-session-project":e.projectId,className:`collapsed-session-project relative flex w-full shrink-0 flex-col items-center gap-1 py-1.5 compact:py-2`,onDragOver:t=>{_&&(t.preventDefault(),_!==e.projectId&&m.onMoveProject(_,e.projectId))},children:[y===e.projectId?(0,Z.jsx)(gi,{initial:e.abbrev,maxLength:5,className:`w-full px-1 text-center text-2xs uppercase text-fg`,onCommit:t=>O(e,t),onCancel:()=>b(null)}):(0,Z.jsxs)(_n,{children:[(0,Z.jsxs)(K,{children:[(0,Z.jsx)(bn,{asChild:!0,children:(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(pn,{to:`/project/${e.projectId}`,"data-sidebar-motion":`sessions-project-${e.projectId}`,style:Zn(e.colour),...On(),draggable:!0,onDragStart:t=>{Ti(t.dataTransfer,e.projectId)||(t.dataTransfer.setData(ag,e.projectId),v(e.projectId))},onDragEnd:()=>v(null),className:V(`w-full px-1 text-center text-2xs uppercase transition-colors`,Si(e.projectId)&&`cursor-grab active:cursor-grabbing`,e.colour?V(Yn(e.colour),`hover:opacity-75`):`text-fg-muted hover:text-fg`,_===e.projectId&&`opacity-50`),children:(0,Z.jsx)(wg,{text:e.abbrev})})})}),(0,Z.jsxs)(G,{side:`left`,children:[e.name,Si(e.projectId)?` · Drag back to host`:``]})]}),(0,Z.jsx)(og,{projectId:e.projectId,name:e.name,colour:e.colour,actions:m,editLabel:{label:`Change project abbreviation`,onSelect:()=>b(e.projectId)}})]}),e.sessions.length>0&&(0,Z.jsx)(tg,{collapsed:!!e.collapsed||_!==null,children:(0,Z.jsx)(`div`,{className:`flex flex-col items-center gap-1 overflow-hidden compact:gap-0.5`,children:e.sessions.map(e=>(0,Z.jsx)(`div`,{draggable:!0,onDragStart:t=>{let n=Xh(w,p.ids,e.id);t.dataTransfer.setData(`application/x-puddle-tab`,kd(T(e),{projectId:e.project_id})),t.dataTransfer.setData(`application/x-puddle-sessions`,Zh(n)),t.dataTransfer.effectAllowed=`copyMove`,n.length>1&&rg(t,n.length),p.ids.has(e.id)||p.onSelectOnly(e.id),g({sourceId:e.id,sessionIds:n})},onDragEnd:()=>g(null),onDragOver:t=>{t.preventDefault(),h?.sessionIds.length===1&&h.sourceId!==e.id&&D(h.sourceId,e.id)},className:V(`transition-opacity`,h?.sessionIds.includes(e.id)&&`opacity-50`),children:(0,Z.jsx)(Dg,{session:e,accountLabel:e.account_id===null?void 0:C.get(e.account_id),activeSessionId:n,onPromote:i,onArchived:d,selectedIds:E,selection:p})},e.id))})})]},e.projectId))}),(0,Z.jsx)(Tg,{onArchiveDrop:f,onShowArchived:o})]})}function kg(e,t){let n=(0,X.useMemo)(()=>e.flatMap(e=>(e.collapsed?[]:e.sessions).map(e=>e.id)),[e]),[r,i]=(0,X.useState)(()=>new Set),a=(0,X.useRef)(null);(0,X.useEffect)(()=>{i(e=>Yh(e,n)),a.current!==null&&!n.includes(a.current)&&(a.current=null)},[n]);let o=(0,X.useCallback)((e,t)=>{i(r=>{let i=Jh(n,r,a.current,e,t);return a.current=i.anchor,i.selection})},[n]),s=(0,X.useCallback)(e=>{a.current=e,i(new Set([e]))},[]),c=Je(),l=(0,X.useCallback)(async e=>{let n=[...new Set(e)],r=await Promise.allSettled(n.map(e=>c.mutateAsync(e))),o=n.filter((e,t)=>r[t]?.status===`fulfilled`);for(let e of o)t(e);o.length>0&&(i(e=>{let t=new Set(e);for(let e of o)t.delete(e);return t}),a.current!==null&&o.includes(a.current)&&(a.current=null));let s=r.filter(e=>e.status===`rejected`),l=s[0];s.length===1&&l?J(l.reason):s.length>1&&U.error(`Couldn’t archive ${s.length} of ${n.length} sessions`)},[c,t]);return{ids:r,onSelect:o,onSelectOnly:s,onArchive:e=>void l(e)}}var Ag=null,jg=null;async function Mg(){let[e,t]=await Promise.all([R(()=>import(`./PaneEditorBody-gYNeVTlY.js`),__vite__mapDeps([60,1,5,12,13,14,61,16,15,17,18,19,20,7,6,62,63,64,2,3,21,22,23,27,30,25,26,28,29,31,33,34,65,66,56,57,67,68,40,41,42,43,44,45,4,8,9,46,47,48,49,50,51,10,0,69,53,70,71,72,73,58,74,75,76,77,78,79])),R(()=>import(`./ModelRefcount-CWfA9XXu.js`),__vite__mapDeps([80,1,5,0,2,3,4,6,7,8,9,10]))]);Ag=e.PaneEditorBody,jg=t.ModelRefcount}var Ng=(0,X.lazy)(()=>R(()=>import(`./PaneEditorBody-gYNeVTlY.js`).then(e=>({default:e.PaneEditorBody})),__vite__mapDeps([60,1,5,12,13,14,61,16,15,17,18,19,20,7,6,62,63,64,2,3,21,22,23,27,30,25,26,28,29,31,33,34,65,66,56,57,67,68,40,41,42,43,44,45,4,8,9,46,47,48,49,50,51,10,0,69,53,70,71,72,73,58,74,75,76,77,78,79])));function Pg(e){return Ag?(0,Z.jsx)(Ag,{...e}):(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-xs text-fg-muted`,children:`Loading editor…`}),children:(0,Z.jsx)(Ng,{...e})})}var Fg=(0,X.lazy)(()=>R(()=>import(`./ModelRefcount-CWfA9XXu.js`).then(e=>({default:e.ModelRefcount})),__vite__mapDeps([80,1,5,0,2,3,4,6,7,8,9,10])));function Ig({buffers:e}){return jg?(0,Z.jsx)(jg,{buffers:e}):(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(Fg,{buffers:e})})}var Lg=(0,X.lazy)(()=>R(()=>import(`./EditorTabClose-fs9t84tp.js`).then(e=>({default:e.EditorDirtyDot})),__vite__mapDeps([81,1,5,12,20,14,7,26,25,27,23,28,33,43,45,49,50,51,0,2,3,4,6,8,9,10,82])));function Rg(e){return(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(Lg,{...e})})}var zg=(0,X.lazy)(()=>R(()=>import(`./EditorTabClose-fs9t84tp.js`).then(e=>({default:e.EditorTabClose})),__vite__mapDeps([81,1,5,12,20,14,7,26,25,27,23,28,33,43,45,49,50,51,0,2,3,4,6,8,9,10,82])));function Bg(e){return(0,Z.jsx)(X.Suspense,{fallback:(0,Z.jsx)(`button`,{disabled:!0,className:`hidden size-4 items-center justify-center rounded-sm text-fg-muted transition-colors hover:text-fg group-hover:flex pointer-coarse:flex`,"aria-label":e.recovered?`Discard recovered text for ${e.label}`:`Close ${e.label}`,children:`×`}),children:(0,Z.jsx)(zg,{...e})})}var Vg=(0,X.lazy)(()=>R(()=>import(`./FileEditorSettingsMenu-DUpeKKAz.js`).then(e=>({default:e.FileEditorSettingsMenu})),__vite__mapDeps([83,1,5,12,19,30,25,26,27,23,28,29,31,55,72,73,58,4,6,7,2,3,8,9,46,14,43,20])));function Hg(e){return(0,Z.jsx)(X.Suspense,{fallback:null,children:(0,Z.jsx)(Vg,{...e})})}var Ug=`application/x-puddle-pane-window`;function Wg(){return z()?.identity.kind===`pane`&&_e()?.windows?.transfers?.beginPaneDrag!==void 0}function Gg(e,t){let n=z(),r=_e()?.windows?.transfers;if(n?.identity.kind!==`pane`||!r?.beginPaneDrag)throw Error(`Pane dragging is unavailable`);let i=crypto.randomUUID();e.setData(Ug,JSON.stringify({token:i,sourceId:n.identity.id,hostId:n.hostId,profileId:n.identity.profileId})),e.effectAllowed=`move`,r.beginPaneDrag({token:i,profileId:n.identity.profileId,projectId:n.identity.projectId,paneId:t}).catch(J)}async function Kg(e,t,n,r){if(e.length>4096)throw Error(`Pane drag is too large`);let i=te.parse(JSON.parse(e)),a=z(),o=_e()?.windows?.transfers;if(!a||!o?.dropPane)throw Error(`Pane docking is unavailable`);if(a.hostId!==i.hostId)throw Error(`Cannot transfer between hosts`);if(Mi()!==i.profileId)throw Error(`Cannot transfer between profiles`);await o.dropPane({token:i.token,sourceId:i.sourceId,profileId:i.profileId,projectId:t,placement:{paneId:n,edge:r===`center`?`right`:r}})}function qg(e,t,n){if(e.length>128*1024)return!1;let r;try{r=D.safeParse(JSON.parse(e))}catch{return!1}let i=z();if(!r.success||!i||r.data.sourceId===i.identity.id)return!1;let a=r.data;return(async()=>{let e=_e()?.windows?.transfers;if(!e?.dropTab)throw Error(`Tab window transfers are unavailable`);if(i.hostId!==a.hostId)throw Error(`Cannot transfer between hosts`);if(Mi()!==a.profileId)throw Error(`Cannot transfer between profiles`);await e.dropTab({token:a.token,sourceId:a.sourceId,profileId:a.profileId,projectId:t,placement:n})})().catch(J),!0}var Jg=[`running`,`waiting_input`];function Yg({sessionId:e,status:t}){let n=Jg.includes(t),{data:r}=Oe(e,n),i=r?.vars??[];if(!n||i.length===0)return null;let a=async(e,t)=>{try{await navigator.clipboard.writeText(t),U.success(`${e} value copied`)}catch{U.error(`Couldn't copy ${e} value`)}};return(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 px-3 font-mono text-xs`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-fg-muted`,children:`env`}),(0,Z.jsx)(`div`,{className:`no-scrollbar min-w-0 flex-1 overflow-x-auto`,children:(0,Z.jsx)(`div`,{className:`flex w-max items-center gap-1 whitespace-nowrap`,children:i.map(e=>{let t=e.value;return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:t===void 0?(0,Z.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-fg-secondary`,children:e.name}):(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Copy ${e.name} environment variable value`,onClick:()=>void a(e.name,t),className:`cursor-pointer rounded px-1.5 py-0.5 text-fg-secondary transition-colors hover:bg-elevated hover:text-fg`,children:e.name})}),(0,Z.jsxs)(G,{children:[e.bytes,` B ·`,` `,t===void 0?`value unavailable from this daemon`:`click to copy value`]})]},e.name)})})})]})}function Xg(e,t,n){return`ssh -L ${e}:127.0.0.1:${e} ${t}@${n}`}var Zg=[`running`,`waiting_input`];function Qg({sessionId:e,status:t}){let n=Zg.includes(t),{data:r}=xe(e,n),i=r?.ports??[];return!n||i.length===0?null:(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 px-3 text-xs`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-fg-muted`,children:`ports`}),(0,Z.jsx)(`div`,{className:`no-scrollbar min-w-0 flex-1 overflow-x-auto`,children:(0,Z.jsx)(`div`,{className:`flex w-max items-center gap-1 whitespace-nowrap`,children:i.map(t=>(0,Z.jsx)($g,{sessionId:e,port:t},t.port))})})]})}function $g({sessionId:e,port:t}){let n=ze().data;return(0,Z.jsxs)(ur,{children:[(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(mr,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded px-1.5 py-0.5 tabular-nums text-fg-secondary outline-none transition-colors hover:bg-elevated hover:text-fg focus-visible:bg-elevated focus-visible:text-fg`,children:t.port})})}),(0,Z.jsxs)(G,{children:[t.command,` · pid `,t.pid]})]}),(0,Z.jsxs)(Sr,{align:`start`,children:[We()===null?(0,Z.jsx)(Cr,{asChild:!0,children:(0,Z.jsx)(`a`,{href:`http://localhost:${t.port}`,target:`_blank`,rel:`noopener noreferrer`,children:`Open localhost`})}):(0,Z.jsx)(Cr,{onSelect:()=>{be(`/forward/${e}/${t.port}`).catch(J)},children:`Open via proxy`}),(0,Z.jsx)(Cr,{onSelect:()=>{n&&navigator.clipboard.writeText(Xg(t.port,n.username,n.hostname)).then(()=>U.success(`Copied`))},children:`Copy ssh -L`})]})]})}function e_({session:e}){let t=Fe(`resume`),n=dn(),{resumable:r}=ug(e);return r?(0,Z.jsx)(`div`,{className:`pointer-events-none absolute bottom-2 right-3 z-10`,children:(0,Z.jsxs)(q,{size:`sm`,className:`pointer-events-auto`,disabled:t.isPending,onClick:()=>t.mutate(e.id,{onError:e=>{let t=zi(e);t?n(`/project/${t.projectId}/session/${t.sessionId}`):J(e)}}),children:[(0,Z.jsx)(at,{}),`Resume`]})}):null}var t_=[];function n_(e){let t=e?Ui(e):null;return(0,X.useSyncExternalStore)((0,X.useCallback)(e=>t?.subscribe(e)??(()=>{}),[t]),()=>t?.retainedBuffers()??t_)}function r_({huddleId:e,...t}){let n=n_(ji()),r=e?ee(e):n.filter(e=>E({type:`huddle`,session:t.session},e)).map(e=>e.path),i=r[0];return i?(0,Z.jsx)(Bg,{...t,path:i,relatedPaths:r.slice(1),kind:`file`}):(0,Z.jsx)(i_,{...t})}function i_({closeKey:e,label:t,onClose:n}){let r=async e=>!e?.aborted&&await n(e)!==!1;return $i(e,r),(0,Z.jsx)(`button`,{type:`button`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),r()},className:`inline-flex rounded-sm p-0.5 text-fg-muted transition-colors hover:text-fg`,"aria-label":`Close ${t}`,children:(0,Z.jsx)(Rn,{className:`size-3`})})}function a_(e,t,n){if(e.kind===`untitled`||t===void 0)return e.path;let r=Zs(t,e.path);return n?Qs(n,r)??r:r}function o_({tab:e,paneId:t,projectId:n,directory:r,onReveal:i,onCompilationSettings:a,onRename:s,editing:c,children:l}){let u=ze(),d=Ba({type:`editor`,tab:e},{paneId:t,projectId:n}),f=Le().data?.protocol,p=ed(),h=md(e.session,e.root,r),g=(0,X.useMemo)(()=>({sid:e.session,root:e.root,directory:r,host:Ku(u.data)}),[e.session,e.root,r,u.data]),_=e.root!==void 0&&!m(f),v=p!==null&&Ju(p.source,g),y=p!==null&&qu(p.source,g),b=!_&&(v&&y||p!==null&&Yu(p.source,g)&&o(f)),[x,S]=(0,X.useState)(!1),C=Zs(r,e.path),w=()=>{!p||!b||h.paste(p,qs(e.path)).then(e=>{p.mode===`cut`&&Zu(p.id,e)})},T=t=>{navigator.clipboard.writeText(t?e.path:C),U.success(t?`Relative path copied`:`Path copied`)};return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(_n,{children:[(0,Z.jsx)(bn,{asChild:!0,children:l}),(0,Z.jsx)(Dn,{onCloseAutoFocus:e=>{c&&e.preventDefault()},children:(0,Z.jsx)(Fd,{absolutePath:C,readOnly:_,canPaste:b,onCut:()=>Xu([e.path],`cut`,g),onCopy:()=>Xu([e.path],`copy`,g),onPaste:w,onCopyPath:()=>T(!1),onCopyRelativePath:()=>T(!0),onReveal:i,onOpenWindow:d,onCompilationSettings:a,onRename:s,onDelete:()=>S(!0),onDownload:()=>{lt(e.session,e.path,e.root).catch(e=>U.error(e instanceof Error?e.message:`Download failed`))}})})]}),(0,Z.jsx)(Ln,{open:x,onOpenChange:S,children:(0,Z.jsxs)(Fn,{children:[(0,Z.jsxs)(Pn,{children:[(0,Z.jsxs)(In,{children:[`Delete “`,Ks(e.path),`”?`]}),(0,Z.jsxs)(Nn,{children:[`This permanently removes it from `,r,`. There is no undo.`]})]}),(0,Z.jsxs)(Mn,{children:[(0,Z.jsx)(q,{variant:`ghost`,onClick:()=>S(!1),children:`Cancel`}),(0,Z.jsx)(q,{variant:`danger`,onClick:()=>{S(!1),h.remove([e.path])},children:`Delete`})]})]})})]})}var s_=`inline-flex rounded-sm p-0.5 text-fg-muted transition-colors hover:text-fg disabled:cursor-not-allowed disabled:opacity-50`;function c_({session:e,onArchived:t}){let{live:n,archived:r,resumable:i,resumeUnavailable:a}=ug(e),o=Fe(n?`kill`:`resume`),s=Je(),c=dn(),l=o.isPending||s.isPending;return r?null:(0,Z.jsxs)(Z.Fragment,{children:[(e.kind!==`huddle`||n)&&(0,Z.jsx)(`button`,{type:`button`,disabled:l||!n&&!i,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onClick:async t=>{t.stopPropagation();try{await o.mutateAsync(e.id)}catch(e){let t=!n&&zi(e);t?c(`/project/${t.projectId}/session/${t.sessionId}`):J(e)}},className:s_,"aria-label":n?`Stop session`:`Resume session`,title:n?`Stop session`:a??`Resume session`,children:n?(0,Z.jsx)(xt,{className:`size-3`}):(0,Z.jsx)(at,{className:`size-3`})}),!n&&(0,Z.jsx)(`button`,{type:`button`,disabled:l,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onClick:async n=>{n.stopPropagation();try{await s.mutateAsync(e.id),t(e.id)}catch(e){J(e)}},className:s_,"aria-label":`Archive session`,title:`Archive session`,children:(0,Z.jsx)(rr,{className:`size-3`})})]})}function l_({paneId:e,children:t}){let n=dn(),{id:r}=fn(),i=ji(),[a,o]=(0,X.useState)([]),s=_e()?.windows?.transfers,c=z()?.identity.kind===`pane`;return!s||c&&!s.dockTargets||!r||!i?t:(0,Z.jsxs)(_n,{onOpenChange:e=>{e&&c&&s.dockTargets(i).then(o,J)},children:[(0,Z.jsx)(bn,{asChild:!0,children:t}),(0,Z.jsx)(Dn,{children:c?a.length?a.map(t=>(0,Z.jsxs)(H,{onSelect:()=>{Ha(i,r,e,t.identity.id).catch(J)},children:[(0,Z.jsx)(er,{}),` Return pane to `,t.label]},t.identity.id)):(0,Z.jsx)(H,{disabled:!0,children:`Open a host or project window to return this pane`}):(0,Z.jsxs)(H,{onSelect:()=>{Va(i,r,e).then(()=>n(`/project/${r}`,{replace:!0}),J)},children:[(0,Z.jsx)(er,{}),` Open pane in window`]})})]})}function u_({tab:e,paneId:t,children:n}){let r=Ba(e,{paneId:t});return r?(0,Z.jsxs)(_n,{children:[(0,Z.jsx)(bn,{asChild:!0,children:n}),(0,Z.jsx)(Dn,{children:(0,Z.jsx)(H,{onSelect:r,children:`Open file in window`})})]}):n}var d_=`group relative flex min-w-[calc(var(--spacing)*28.8)] max-w-52 cursor-pointer select-none items-center gap-1.5 rounded-[var(--ui-radius)] px-2.5 text-xs transition-colors`,f_=`group-hover:[transform:translateX(var(--tail))]`;function p_({leaf:e,filetreeRoot:t,sessions:n,onActivate:r,onClose:i,onPromote:a,onDropTab:o,onArchived:s,onSetView:c,compilableExtensions:l,compilationProviders:u,compilationRunningKeys:d,onRunCompilation:f,onSetCompilationMode:p,onOpenCompilationSettings:m,onNewFile:h,onRevealFile:g,onRenameFile:_}){let{id:v}=fn(),y=e.tabs.length===1,b=Wg(),x=(0,X.useRef)(!1),[S,C]=(0,X.useState)(null),w=(0,X.useRef)(void 0);(0,X.useEffect)(()=>()=>clearTimeout(w.current),[]);let T=new Map(n.map(e=>[e.id,e])),E=new Map(n.map(e=>[e.id,e.branch])),D=new Map(n.map(e=>[e.id,e.worktree_path])),O=e.tabs.flatMap(e=>e.type===`editor`?[e.tab]:[]),k=Mh(),A=fh({id:`pane:${e.id}`,data:{paneId:e.id,tabCount:e.tabs.length}}),ee=S??(k?.leafId===e.id&&k.index!==void 0?k.index:null),j=(t,n)=>{let r=t instanceof Element?t.closest(`[data-pane-tab]`):null,i=r?e.tabs.findIndex(e=>B(e)===r.dataset.paneTab):-1;if(i<0||!r)return e.tabs.length;let a=r.getBoundingClientRect();return i+ +(n>=a.x+a.width/2)},{setNodeRef:M}=gh({id:`strip:${e.id}`,data:{leafId:e.id,count:e.tabs.length}}),N=e=>{let t=Yi(e.path,e.session,O,E,e.root,D);return Y(e)===`diff`?`${t} (diff)`:Y(e)===`commit`?`${t} @${(e.sha??``).slice(0,7)}`:t},P=(0,Z.jsxs)(`div`,{ref:e=>{M(e),A.setNodeRef(e)},"data-pane-drag-handle":e.id,onDragOver:e=>{Md(e.dataTransfer.types)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`move`,C(j(e.target,e.clientX)),clearTimeout(w.current),w.current=setTimeout(()=>C(null),750))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||C(null)},onDrop:t=>{if(!Md(t.dataTransfer.types))return;t.preventDefault(),t.stopPropagation(),C(null),clearTimeout(w.current);let n=t.dataTransfer.getData(Dd),r=j(t.target,t.clientX);if(v&&qg(n,v,{paneId:e.id,edge:`center`,index:r}))return;let i=jd(n);i&&o(i.ref,{fromLeafId:i.paneId,index:r})},draggable:b||void 0,onPointerDownCapture:e=>{x.current=e.target===e.currentTarget||y&&e.target instanceof Element&&!!e.target.closest(`[data-pane-tab]`)&&!e.target.closest(`button, input, [role="menuitem"]`)},onDragStart:t=>{if(!b||!x.current){t.preventDefault();return}Gg(t.dataTransfer,e.id)},onPointerDown:e=>{!b&&e.target===e.currentTarget&&A.listeners?.onPointerDown?.(e)},"data-pane-single-edge":y||void 0,className:y?`pane-single-tab-edge cursor-grab`:`flex h-[var(--ui-tab-strip-height)] shrink-0 cursor-grab items-stretch gap-1 overflow-x-auto bg-[var(--bg-pane)] p-1 active:cursor-grabbing`,onDoubleClick:e=>{e.target===e.currentTarget&&h()},children:[e.tabs.map((n,o)=>{let h=T.get(n.type===`editor`?n.tab.session:n.session);return(0,Z.jsxs)(X.Fragment,{children:[ee===o&&(0,Z.jsx)(m_,{}),(0,Z.jsx)(x_,{tab:n,single:y,nativePaneDrag:b&&y,filetreeRoot:t,leafId:e.id,index:o,active:B(n)===e.activeKey,preview:B(n)===e.previewKey,session:n.type===`editor`?void 0:h,fileSession:n.type===`editor`&&n.tab.root===void 0?h:void 0,fileDirectory:n.type===`editor`&&(Y(n.tab)===`file`||Y(n.tab)===`external`)?n.tab.root??h?.worktree_path:void 0,label:n.type===`editor`?N(n.tab):``,onActivate:()=>r(n),onClose:e=>i(n,e),onPromote:()=>a(n),onArchived:s,onSetView:e=>c(n,e),compilable:Oc(n.type===`editor`?n.tab.path:``,l),provider:n.type===`editor`?u.find(e=>e.extensions.includes(Dc(n.tab.path)??``)):void 0,compilationRunning:n.type===`editor`&&d.has(kc(n.tab.session,n.tab.path,n.tab.root)),onRunCompilation:()=>{n.type===`editor`&&(r(n),requestAnimationFrame(()=>f(n.tab)))},onSetCompilationMode:e=>{n.type===`editor`&&(r(n),requestAnimationFrame(()=>p(n.tab,e)))},onOpenCompilationSettings:n.type===`editor`&&m?()=>m({session:n.tab.session,path:n.tab.path,...n.tab.root===void 0?{}:{root:n.tab.root}}):void 0,onRevealFile:()=>n.type===`editor`&&g(n.tab),onRenameFile:e=>n.type===`editor`?_(n.tab,e):Promise.resolve(!1)})]},B(n)===e.previewKey?`preview-slot`:B(n))}),ee===e.tabs.length&&(0,Z.jsx)(m_,{})]});return(0,Z.jsx)(l_,{paneId:e.id,children:P})}function m_(){return(0,Z.jsx)(`div`,{className:`w-0.5 shrink-0 self-stretch rounded-full bg-accent`})}function h_({children:e}){let t=(0,X.useRef)(null);return(0,Z.jsxs)(`span`,{ref:t,className:`pane-tab-controls sliding-hover-tray island-outline pointer-events-none absolute right-1 top-1/2 z-10 flex -translate-y-1/2 items-center gap-1 rounded-full bg-elevated px-1 py-1 shadow-sm opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-visible:pointer-events-auto group-has-[:focus-visible]:pointer-events-auto group-focus-visible:opacity-100 group-has-[:focus-visible]:opacity-100 has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:opacity-100 pointer-coarse:pointer-events-auto pointer-coarse:opacity-100 [&_button]:size-5 [&_button]:items-center [&_button]:justify-center [&_button]:rounded-full`,children:[(0,Z.jsx)(`span`,{ref:Li(t),"aria-hidden":!0,className:`tray-hover-surface`}),e]})}var g_={source:`preview`,preview:`linked`,linked:`locked`,locked:`source`},__={source:qr,preview:Br,linked:li,locked:$r},v_={source:`Source — switch to preview`,preview:`Preview — switch to linked preview`,linked:`Linked preview — switch to locked preview`,locked:`Locked preview — switch to source`};function y_({view:e,notebook:t=!1,onSetView:n}){let r=__[e],i=t?e===`source`?`Show notebook`:`Show JSON source`:v_[e];return(0,Z.jsxs)(K,{children:[(0,Z.jsx)(W,{asChild:!0,children:(0,Z.jsx)(`button`,{onClick:r=>{r.stopPropagation(),n(t?e===`source`?`preview`:`source`:g_[e])},className:`inline-flex rounded-sm p-0.5 text-fg-muted transition-colors hover:text-fg`,"aria-label":i,children:(0,Z.jsx)(r,{className:`size-3`})})}),(0,Z.jsx)(G,{side:`bottom`,collisionPadding:8,children:i})]})}function b_({mode:e,running:t,onRun:n,onSetMode:r,provider:i}){let a=e===`eager`,o=Pi(`editor.compile`);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,disabled:t,onClick:e=>{e.stopPropagation(),n()},className:V(`inline-flex rounded-sm p-0.5 transition-colors hover:text-fg disabled:cursor-wait`,a?`text-fg-muted`:`text-accent`),"aria-label":i?.terminal?`Run in terminal`:i?.action===`run`?`Run file`:`Compile on demand`,title:`${i?.terminal?`Run in terminal`:i?.action===`run`?`Run file`:`Compile on demand`} (${o})`,children:t&&!a?(0,Z.jsx)(Ca,{className:`size-3 animate-spin`}):(0,Z.jsx)(at,{className:`size-3`})}),i?.eager&&(0,Z.jsx)(`button`,{type:`button`,disabled:t,onClick:e=>{e.stopPropagation(),r(a?`on_demand`:`eager`)},className:V(`inline-flex rounded-sm p-0.5 transition-colors hover:text-fg disabled:cursor-wait`,a?`text-accent`:`text-fg-muted`),"aria-label":a?`Disable eager compilation`:`Enable eager compilation`,title:a?`Eager compilation — switch to on demand`:`Compile eagerly on disk changes`,children:t&&a?(0,Z.jsx)(Ca,{className:`size-3 animate-spin`}):(0,Z.jsx)(Ar,{className:`size-3`})})]})}function x_({tab:e,single:t,nativePaneDrag:n,filetreeRoot:r,leafId:i,index:a,active:o,preview:s,session:c,fileSession:l,fileDirectory:u,label:d,onActivate:f,onClose:p,onPromote:m,onArchived:h,onSetView:g,compilable:_,provider:v,compilationRunning:y,onRunCompilation:b,onSetCompilationMode:x,onOpenCompilationSettings:S,onRevealFile:C,onRenameFile:w}){let[T,E]=(0,X.useState)(!1),[D,k]=(0,X.useState)(!1),A=!n&&Od(),j=(0,X.useRef)(!1),{id:M}=fn(),N=_i(),P=B(e),{attributes:F,listeners:I,setNodeRef:te,isDragging:ne}=fh({id:`drag:${i}:${P}`,data:{ref:e,fromLeafId:i}}),{setNodeRef:re}=gh({id:`tabdrop:${i}:${P}`,data:{leafId:i,index:a}}),ie=e=>{te(e),re(e)},ae=V(t?`pane-single-tab group relative flex h-2 w-full cursor-grab items-center text-xs`:d_,!t&&(o?`bg-ground text-fg`:`text-fg-secondary hover:bg-elevated`),s&&`italic`,ne&&`opacity-40`),oe=(0,Z.jsx)(`div`,{ref:ie,...T?{}:F,...T||n||A?{}:I,onKeyDown:T?void 0:e=>I?.onKeyDown?.(e),draggable:A&&!T||void 0,onPointerDownCapture:e=>{j.current=e.target instanceof Element&&!e.target.closest(`button, input, [contenteditable], [role="menuitem"]`)},onDragStart:t=>{if(A){if(t.stopPropagation(),!j.current){t.preventDefault();return}t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(Dd,kd(e,{paneId:i,projectId:c?.project_id??l?.project_id??M}))}},onClick:f,onDoubleClick:m,className:V(ae,T&&`pane-tab-renaming cursor-text select-text`),"data-pane-tab":P,"aria-label":t?e.type===`editor`?a_(e.tab,u,r):c?N(c):e.session:void 0,children:e.type===`editor`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(lu,{name:Y(e.tab)===`untitled`?d:e.tab.path.split(`/`).pop()??e.tab.path,className:`size-4`}),T?(0,Z.jsx)(S_,{initial:e.tab.path.split(`/`).pop()??e.tab.path,onCommit:w,onCancel:()=>E(!1),onCommitted:()=>E(!1)}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Vl,{text:d,hoverClass:f_,containerClassName:`flex-[0_1_auto]`,className:(Y(e.tab)===`file`||Y(e.tab)===`external`)&&(Vi(e.tab.path)!==null||_)?`-mr-20 pr-20`:`-mr-11 pr-11`}),(0,Z.jsx)(Rg,{session:e.tab.session,path:e.tab.path,kind:Y(e.tab),root:e.tab.root}),(0,Z.jsxs)(h_,{children:[(Y(e.tab)===`file`||Y(e.tab)===`external`)&&Vi(e.tab.path)!==null&&(0,Z.jsx)(y_,{notebook:Vi(e.tab.path)===`notebook`,view:e.tab.view??`source`,onSetView:g}),(Y(e.tab)===`file`||Y(e.tab)===`external`)&&_&&!e.tab.generated_by&&(0,Z.jsx)(b_,{provider:v,mode:e.tab.compile_mode??`on_demand`,running:y,onRun:b,onSetMode:x}),!gr(e.tab.path)&&(0,Z.jsx)(Hg,{tab:e.tab,onOpenChange:k}),(0,Z.jsx)(Bg,{closeKey:Zi(i,P),session:e.tab.session,path:e.tab.path,kind:Y(e.tab),root:e.tab.root,label:d,onClose:p})]})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[c&&(0,Z.jsx)(sg,{status:c.status,kind:c.kind,agentType:c.agent_type,detectedAgentType:c.detected_agent_type,stale:c.stale_running}),(0,Z.jsx)(`span`,{className:`truncate`,children:c?N(c):e.session.slice(0,8)}),e.type===`huddle`&&c?.huddle_id&&(0,Z.jsx)(Rg,{session:c.id,path:O(c.huddle_id),relatedPaths:ee(c.huddle_id).slice(1),kind:`file`}),(0,Z.jsxs)(h_,{children:[c&&(0,Z.jsx)(c_,{session:c,onArchived:h}),e.type===`huddle`?(0,Z.jsx)(r_,{closeKey:Zi(i,P),session:e.session,huddleId:c?.huddle_id??void 0,label:c?N(c):`Huddle ${e.session.slice(0,8)}`,onClose:p}):(0,Z.jsx)(`button`,{type:`button`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},className:`inline-flex rounded-sm p-0.5 text-fg-muted transition-colors hover:text-fg`,"aria-label":`Close tab`,children:(0,Z.jsx)(Rn,{className:`size-3`})})]})]})}),L=(0,Z.jsx)(G,{side:`bottom`,portalled:!t,className:V(`max-w-[calc(100vw-2rem)] break-all`,t&&`pointer-events-none z-0`),children:(0,Z.jsx)(uf,{name:e.type===`editor`?t?a_(e.tab,u,r):d:c?N(c):e.session,session:e.type===`editor`?l:c})});return e.type!==`editor`&&c?(0,Z.jsxs)(K,{children:[(0,Z.jsx)(_g,{session:c,paneId:i,onArchived:()=>h(e.session),children:(0,Z.jsx)(W,{asChild:!0,children:oe})}),L]}):e.type===`editor`&&u!==void 0&&(Y(e.tab)===`file`||Y(e.tab)===`external`)?(0,Z.jsxs)(K,{open:T||D?!1:void 0,children:[(0,Z.jsx)(o_,{tab:e.tab,paneId:i,projectId:l?.project_id,directory:u,onReveal:C,onCompilationSettings:_?S:void 0,onRename:()=>E(!0),editing:T,children:(0,Z.jsx)(W,{asChild:!0,children:oe})}),L]}):(0,Z.jsxs)(K,{open:!D&&void 0,children:[(0,Z.jsx)(u_,{tab:e,paneId:i,children:(0,Z.jsx)(W,{asChild:!0,children:oe})}),L]})}function S_({initial:e,onCommit:t,onCommitted:n,onCancel:r}){let i=(0,X.useRef)(null),a=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let t=i.current;if(!t)return;let n=()=>{t.focus();let n=e.lastIndexOf(`.`);t.setSelectionRange(0,n>0?n:e.length)};n();let r=requestAnimationFrame(()=>{document.activeElement!==t&&n()});return()=>cancelAnimationFrame(r)},[e]);let o=()=>{a.current||(a.current=!0,t(i.current?.value??``).then(e=>{if(e){n();return}a.current=!1,requestAnimationFrame(()=>i.current?.focus())}))};return(0,Z.jsx)(`input`,{ref:i,defaultValue:e,spellCheck:!1,"aria-label":`Rename ${e}`,onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?o():e.key===`Escape`&&(a.current=!0,r())},onBlur:o,className:`min-w-0 flex-1 bg-transparent text-xs text-fg outline-none`,style:{width:`${Math.max(8,Math.min(e.length,24))}ch`}})}function C_(e,t,n){return{focus:e===`press`,driveScroll:t&&n!==`linked`}}function w_({session:e}){let t=n_(ji()).filter(t=>E({type:`huddle`,session:e},t));return(0,Z.jsxs)(`div`,{className:`h-full overflow-auto p-4`,role:`region`,"aria-label":`Unavailable huddle`,children:[(0,Z.jsx)(`p`,{className:`mb-3 text-sm text-fg-muted`,children:`Huddle unavailable — this tab is retained for reconnection.`}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-4`,children:t.map(e=>(0,Z.jsx)(wr,{draft:e},Hi(e)))})]})}var T_=e=>`${B(e)}:${e.type===`editor`?e.tab.view??`source`:`source`}`;function E_({leaf:e,filetreeRoot:t,sessions:n,reveal:r,onActivateTab:i,onCloseTab:a,onPromoteTab:o,onArchived:s,onFocusLeaf:c,onScrollDrive:l,onDropTab:u,onSetTabView:d,compilableExtensions:f,compilationProviders:p,compilationRunningKeys:m,onRunCompilation:h,onSetCompilationMode:g,onOpenCompilationSettings:_,onRevealPreviewSource:v,onRevealCompiledSource:y,onNewUntitled:b,onRevealFile:x,onRenameFile:S,focused:C,scrollDriver:w,scrollChannel:T}){let{id:E}=fn(),D=e.tabs.find(t=>B(t)===e.activeKey)??null,O=D?.type===`terminal`?B(D):null,k=D?.type===`terminal`?n.find(e=>e.id===D.session)??null:null,A=Bc(O),{setNodeRef:ee}=gh({id:`leaf:${e.id}`}),j=Mh(),M=Fh(),N=Pi(`palette.toggle`),P=D?.type===`editor`?D.tab:null,F=P?.view??`source`,I=P!==null&&(Y(P)===`file`||Y(P)===`external`)&&Vi(P.path)!==null,te=w&&I&&F!==`linked`,ne=!te&&(F===`locked`||I&&F===`source`),re=t=>{let n=C_(t,I,F);n.focus&&c(e.id),n.driveScroll&&l(e.id)},ie=(0,X.useRef)(null),ae=(0,X.useRef)(()=>void 0);ae.current=()=>{D&&i(e.id,D)},(0,X.useEffect)(()=>{let e=ie.current;if(!e)return;let t=()=>ae.current();return e.addEventListener(`mousedown`,t,!0),()=>e.removeEventListener(`mousedown`,t,!0)},[]);let[oe,L]=(0,X.useState)(null),se=(0,X.useRef)(u);return se.current=u,(0,X.useEffect)(()=>{let t=ie.current;if(!t)return;let n,r=()=>{clearTimeout(n),L(null)},i=e=>e.dataTransfer!==null&&(Md(e.dataTransfer.types)||e.dataTransfer.types.includes(`application/x-puddle-pane-window`)),a=e=>{let n=t.getBoundingClientRect();return kh({width:n.width,height:n.height},{x:e.clientX-n.left,y:e.clientY-n.top})},o=e=>{i(e)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),L(a(e)),clearTimeout(n),n=setTimeout(r,750))},s=e=>{t.contains(e.relatedTarget)||r()},c=t=>{if(!i(t))return;if(t.preventDefault(),t.stopPropagation(),r(),t.dataTransfer?.types.includes(`application/x-puddle-pane-window`)){E&&Kg(t.dataTransfer.getData(Ug),E,e.id,a(t)).catch(J);return}let n=t.dataTransfer?.getData(`application/x-puddle-tab`)??``;if(E&&qg(n,E,{paneId:e.id,edge:a(t)}))return;let o=jd(n);if(o){let{ref:n}=o,r=a(t);Cf(()=>se.current(e.id,n,r,{fromLeafId:o.paneId}),n,e.id)}};return t.addEventListener(`dragenter`,o,!0),t.addEventListener(`dragover`,o,!0),t.addEventListener(`dragleave`,s,!0),t.addEventListener(`drop`,c,!0),window.addEventListener(`dragend`,r),()=>{t.removeEventListener(`dragenter`,o,!0),t.removeEventListener(`dragover`,o,!0),t.removeEventListener(`dragleave`,s,!0),t.removeEventListener(`drop`,c,!0),window.removeEventListener(`dragend`,r),clearTimeout(n)}},[e.id,E]),(0,Z.jsxs)(`div`,{className:`workspace-pane workspace-surface island-outline relative isolate flex h-full min-w-0 flex-col bg-[var(--bg-pane)]`,"data-workspace-pane":e.id,"data-single-tab":e.tabs.length===1||void 0,onMouseDownCapture:()=>re(`press`),onWheelCapture:()=>re(`scroll`),children:[e.tabs.length>0&&(0,Z.jsx)(p_,{leaf:e,filetreeRoot:t,sessions:n,onActivate:t=>i(e.id,t),onClose:(t,n)=>a(e.id,t,n),onPromote:o,onDropTab:(t,n)=>u(e.id,t,`center`,n),onArchived:s,onSetView:(t,n)=>d(e.id,t,n),compilableExtensions:f,compilationProviders:p,compilationRunningKeys:m,onRunCompilation:t=>h(e.id,t),onSetCompilationMode:g,onOpenCompilationSettings:_,onNewFile:()=>b(e),onRevealFile:x,onRenameFile:S}),(0,Z.jsx)(`div`,{ref:e=>{ie.current=e,ee(e)},"data-editor-surface":D?.type===`editor`||void 0,"data-pane-drop-target":e.id,"data-pane-view":D?B(D):void 0,className:V(`relative isolate min-h-0 flex-1`,e.tabs.length===1&&`mt-1`,D&&`mx-1 mb-1 overflow-hidden rounded-[var(--ui-radius)] bg-ground`),children:(0,Z.jsxs)(Sn,{className:`absolute inset-0`,motionKey:`${e.activeKey??``}:${F}`,presentKeys:e.tabs.map(T_),preview:!!e.previewKey&&e.previewKey===e.activeKey,children:[D?.type===`editor`&&(0,Z.jsx)(`div`,{className:`absolute inset-1 overflow-hidden rounded-[var(--ui-radius)]`,children:(0,Z.jsx)(Wi.Provider,{value:JSON.stringify([T,e.id,B(D)]),children:(0,Z.jsx)(Pg,{tab:D.tab,onRunCompilation:f.has(Dc(D.tab.path)??``)?t=>h(e.id,D.tab,t):void 0,compilationRunning:m.has(kc(D.tab.session,D.tab.path,D.tab.root)),reveal:r,focused:C,scrollDriver:te,scrollReceiver:ne,scrollChannel:T,onRevealSource:P?.view===`linked`||P?.view===`locked`?t=>v(e.id,P,t):void 0,onRevealCompiledSource:t=>y(e.id,t)})})}),(0,Z.jsx)(`div`,{ref:A,className:V(`absolute inset-0 py-1 pl-4 pr-2`,!O&&`hidden`)}),D?.type===`huddle`&&(()=>{let t=n.find(e=>e.id===D.session);return t?(0,Z.jsx)(Wi.Provider,{value:JSON.stringify([T,e.id,B(D)]),children:(0,Z.jsx)(Lc,{session:t,focused:C},t.id)}):(0,Z.jsx)(w_,{session:D.session})})(),O&&!k&&(0,Z.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-sm text-fg-muted`,children:`Session unavailable — this tab is retained for reconnection.`}),M&&(0,Z.jsx)(`div`,{className:`absolute inset-0 z-10 cursor-grabbing`,"aria-hidden":`true`}),j?.leafId===e.id&&j.index===void 0&&(0,Z.jsx)(O_,{zone:j.zone}),oe!==null&&(0,Z.jsx)(O_,{zone:oe}),k&&(0,Z.jsx)(e_,{session:k}),!D&&(0,Z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-6 text-center`,children:[(0,Z.jsx)(Zr,{className:`size-24 text-fg-muted/40`}),(0,Z.jsx)(`button`,{type:`button`,onClick:vi,className:`rounded-md bg-elevated px-3 py-1.5 font-mono text-xs text-fg-muted transition-colors hover:bg-border hover:text-fg-secondary`,children:N})]})]})}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 pb-1 empty:hidden`,children:[k&&(0,Z.jsx)(Yg,{sessionId:k.id,status:k.status}),k&&(0,Z.jsx)(Qg,{sessionId:k.id,status:k.status})]})]})}var D_={center:`inset-0`,left:`inset-y-0 left-0 w-1/2`,right:`inset-y-0 right-0 w-1/2`,top:`inset-x-0 top-0 h-1/2`,bottom:`inset-x-0 bottom-0 h-1/2`};function O_({zone:e}){return(0,Z.jsx)(`div`,{className:V(`pointer-events-none absolute z-20 bg-accent/20`,D_[e])})}function k_({tree:e,...t}){let n=(0,X.useMemo)(()=>{let n=new Set,r=[];for(let i of Rt(e)){if(i.type===`huddle`){let e=t.sessions.find(e=>e.id===i.session);e?.huddle_id&&r.push(...ee(e.huddle_id).map(e=>({session:i.session,path:e})));continue}if(i.type!==`editor`||![`file`,`diff`,`external`].includes(Y(i.tab)))continue;let e=`${i.tab.session}\0${i.tab.path}\0${i.tab.root??``}`;n.has(e)||(n.add(e),r.push({session:i.tab.session,path:i.tab.path,root:i.tab.root}))}return r},[e,t.sessions]);return(0,Z.jsxs)(Z.Fragment,{children:[n.length>0&&(0,Z.jsx)(Ig,{buffers:n}),(0,Z.jsx)(A_,{node:e,...t})]})}function A_({node:e,...t}){if(e.kind===`leaf`)return(0,Z.jsx)(E_,{leaf:e,filetreeRoot:t.filetreeRoot,sessions:t.sessions,reveal:t.reveal,onActivateTab:t.onActivateTab,onCloseTab:t.onCloseTab,onPromoteTab:t.onPromoteTab,onArchived:t.onArchived,onFocusLeaf:t.onFocusLeaf,onScrollDrive:t.onScrollDrive,onDropTab:t.onDropTab,onSetTabView:t.onSetTabView,compilableExtensions:t.compilableExtensions,compilationProviders:t.compilationProviders,compilationRunningKeys:t.compilationRunningKeys,onRunCompilation:t.onRunCompilation,onSetCompilationMode:t.onSetCompilationMode,onOpenCompilationSettings:t.onOpenCompilationSettings,onRevealPreviewSource:t.onRevealPreviewSource,onRevealCompiledSource:t.onRevealCompiledSource,onNewUntitled:t.onNewUntitled,onRevealFile:t.onRevealFile,onRenameFile:t.onRenameFile,focused:e.id===t.focusedLeafId,scrollDriver:e.id===t.scrollDriverLeafId,scrollChannel:t.scrollChannel});let n=e.direction===`row`?`horizontal`:`vertical`;return(0,Z.jsx)(Ns,{orientation:n,className:`size-full`,defaultLayout:Object.fromEntries(e.children.map((t,n)=>[t.id,e.sizes[n]??100/e.children.length])),onLayoutChanged:n=>t.onResize(e.id,e.children.map(e=>n[e.id]??0)),children:e.children.map((e,r)=>(0,Z.jsxs)(X.Fragment,{children:[r>0&&(0,Z.jsx)(Vs,{className:n===`horizontal`?`workspace-divider-vertical`:`workspace-divider-horizontal`}),(0,Z.jsx)(Is,{id:e.id,minSize:64,children:(0,Z.jsx)(A_,{node:e,...t})})]},e.id))},e.id)}function j_(e,t,n){if(n.ref.type!==`huddle`||!n.fromLeafId||e===t)return;let r=B(n.ref);if(!Lt(e,n.fromLeafId)?.tabs.some(e=>B(e)===r))return;let i=e=>Lt(t,e)?.tabs.some(e=>B(e)===r),a=new Set(Ht(e).map(e=>e.id)),o=n.edge===`center`&&i(n.toLeafId)?n.toLeafId:Ht(t).find(e=>!a.has(e.id)&&i(e.id))?.id;if(!(!o||o===n.fromLeafId)&&!Lt(e,o)?.tabs.some(e=>B(e)===r))return o}function M_(e,t,n,r){if(e.startsWith(t))try{let i=JSON.parse(e.slice(t.length));return!Array.isArray(i)||i.length!==3||i[0]!==n||i[1]!==`huddle`?void 0:t+JSON.stringify([r,...i.slice(1)])}catch{return}}function N_(e,t,n,r){let i=j_(e,t,n);if(!i)return;let a=`${Mi()??``}:${r}`,o=B(n.ref),s=JSON.stringify([a,n.fromLeafId,o]),c=JSON.stringify([a,i,o]),l=M(``);si.copyKeys(e=>M_(e,l,s,c))}function P_(e,t){return e.session===t.session&&e.path===t.path&&(e.root??``)===(t.root??``)&&Y(e)===Y(t)}function F_(e,t=`profile`){let n=e.snapshot,r=(0,X.useRef)(null),i=(0,X.useRef)(null),a=(0,X.useRef)(t),o=(0,X.useRef)(!1);a.current!==t&&(a.current=t,r.current=null,i.current=null,o.current=!1),!n.layout_tree&&!r.current&&(r.current=Ot(n));let s=n.layout_tree??r.current??It([]),c=(0,X.useMemo)(()=>$t(s),[s]),l=(0,X.useCallback)(t=>e.update({layout_tree:t}),[e]),u=(0,X.useRef)(l);u.current=l,(0,X.useEffect)(()=>{o.current||e.loaded&&!n.layout_tree&&r.current&&(o.current=!0,Rt(r.current).length>0&&u.current(r.current))},[e.loaded,n.layout_tree]),(0,X.useEffect)(()=>{e.loaded&&c!==s&&n.layout_tree&&u.current(c)},[e.loaded,c,s,n.layout_tree]);let[d,f]=(0,X.useState)(null),p=(d?Lt(c,d):null)??Ht(c)[0]??It([]),m=p.tabs.find(e=>B(e)===p.activeKey)??null,h=m?.type===`editor`?m.tab:null,g=(e,t)=>{let n=Nt(t);n&&(i.current={leafId:e,target:n})};return(0,X.useMemo)(()=>({tree:c,focusedLeaf:p,activeEditorTab:h,focusLeaf:e=>f(e),activate:(e,t)=>{f(e),g(e,t);let n=B(t),r=Lt(c,e)?.activeKey===n,i=jt(r?c:Bt(c,e,n),t);r&&i===c||l(i)},close:(e,t)=>{let n=zt(c,e,B(t)),r=Lt(n,e),i=r?.tabs.find(e=>B(e)===r.activeKey);i&&g(e,i),l(i?jt(n,i):n)},openEditor:(e,t)=>{let n=p.id;f(n);let r={type:`editor`,tab:e};g(n,r);let i=t?.preview?Et(c,n,r):cn(c,n,r);l(jt(i,r))},openEditorInLeaf:(e,t,n)=>{let r={type:`editor`,tab:t},i=B(r),a=n?.activate??!0,o=n?.dedupeAcrossTree?At(c,i):null;if(o){let e=Kt(c,o.id,r);return a&&(f(o.id),e=Bt(e,o.id,i)),o.previewKey===i&&(e=Wt(e,i)),e!==c&&l(e),o.id}let s=Lt(c,e)?.id??p.id;return a?(f(s),g(s,r),l(jt(cn(c,s,r),r))):l(Dt(c,s,r)),s},setCompileMode:(e,t)=>{let n=Ft(c,e,t);n!==c&&l(n)},ensureSession:(e,t)=>{let n=t?.keepSession?Wt(c,`term:${t.keepSession}`):c,r=T(e),i=B(r),a=At(n,i);if(a){f(a.id);let e=a.activeKey!==i,r=!t?.preview&&a.previewKey===i;if(e||r||n!==c){let t=n;e&&(t=Bt(t,a.id,i)),r&&(t=Wt(t,i)),l(t)}}else{let e=p.id;f(e),l(t?.preview?Et(n,e,r):cn(n,e,r))}},promote:e=>l(Wt(c,B(e))),setView:(e,t,n)=>{g(e,t);let r=an(c,e,B(t),n),i=Lt(r,e),a=i?.tabs.find(e=>B(e)===i.activeKey);l(a?jt(r,a):r)},revealSource:(e,t)=>{let n=i.current,r=n&&P_(n.target,t)?n:null,a=r&&Pt(c,t,r.leafId)?r.leafId:void 0,o=Pt(c,t,a);if(o){f(o.leafId);let e=an(c,o.leafId,B(o.ref),`source`);return e=Bt(e,o.leafId,B(o.ref)),i.current={leafId:o.leafId,target:t},e!==c&&l(e),o.leafId}let s=(r?Lt(c,r.leafId):null)?.id??Lt(c,e)?.id??p.id,u={type:`editor`,tab:{session:t.session,path:t.path,...t.kind===void 0?{}:{kind:t.kind},...t.root===void 0?{}:{root:t.root},view:`source`}};return f(s),i.current={leafId:s,target:t},l(cn(c,s,u)),s},renameFile:(e,t)=>{let n=Ut(c,e,t);n!==c&&l(n)},removeSession:(t,n)=>{let r=e.current().layout_tree??c;if(n){for(let e of Ht(r))if(e.tabs.some(e=>e.type===`huddle`&&e.session===t))for(let t of Array.isArray(n)?n:[n])r=Dt(r,e.id,{type:`editor`,tab:t})}l(Mt(r,e=>e.type===`editor`||e.session!==t))},pruneSessions:e=>l(Mt(c,kt(e))),resize:(e,t)=>l(Gt(c,e,t)),drop:e=>{f(e.toLeafId),g(e.toLeafId,e.ref);let n=jt(Qt(c,e),e.ref);N_(c,n,e,t),l(n)},dropPane:e=>{let t=Tt(c,e);t!==c&&(f(e.fromLeafId),l(t))}}),[c,p,h,l,t])}function I_(e,{projectId:t,projectMode:n,sessions:r,projects:i,orderedProjects:a}){let o=n&&e.snapshot.layout_mode===`project`,s=Jt(e,t,o),c=(0,X.useRef)(e);c.current=e;let l=(0,X.useRef)(r);l.current=r;let u=(0,X.useRef)(a);u.current=a;let d=(0,X.useRef)(i);d.current=i,(0,X.useEffect)(()=>{let e=c.current;if(!e.loaded)return;let a=e.current(),o=a.layout_mode??`profile`;if(n&&o!==`project`){if(!r||!i)return;let n=new Map(r.map(e=>[e.id,e.project_id])),o=ln(a,i.map(e=>e.id),n,t);e.update({...o,project_layouts:sn(o.project_layouts??{},a.project_layouts)})}else!n&&o===`project`&&e.update(Vt(a,[t,...u.current.map(e=>e.id)]))},[n,e.loaded,r,i,t]);let f=o?`project:${t}`:`profile`,p=F_(s,f),[m,h]=(0,X.useState)(null),g=(0,X.useCallback)(e=>h({scopeKey:f,leafId:e}),[f]),_=(m?.scopeKey===f?Lt(p.tree,m.leafId):null)?.id??p.focusedLeaf.id;(0,X.useEffect)(()=>{g(p.focusedLeaf.id)},[g,p.focusedLeaf.id,p.focusedLeaf.activeKey]);let v=(0,X.useCallback)(e=>{p.focusLeaf(e),g(e)},[p,g]),y=e.snapshot.project_layouts,b=(0,X.useMemo)(()=>o?un(y,t):[],[o,y,t]),x=(0,X.useRef)(p);x.current=p;let S=(0,X.useRef)(s);S.current=s;let[C,w]=(0,X.useState)(!1);(0,X.useEffect)(()=>{if(!s.loaded)return;let e=!0,t=Rt(x.current.tree),n=()=>{e&&w(!0)};return Promise.all([t.some(e=>e.type===`terminal`)?oe():void 0,t.some(e=>e.type===`editor`)?Mg():void 0]).then(n,n),()=>{e=!1}},[s.loaded,f]);let T=(0,X.useRef)(!1);(0,X.useEffect)(()=>{if(T.current||!s.loaded||!r||z())return;T.current=!0;let e=new Set(r.filter(e=>e.status!==`archived`).map(e=>e.id));x.current.pruneSessions(e);let t=c.current,n=t.current().project_layouts;if(Object.keys(n).length>0){let r=kt(e);t.update({project_layouts:Object.fromEntries(Object.entries(n).map(([t,n])=>[t,{...n,layout_tree:n.layout_tree?Mt(n.layout_tree,r):null,active_session:n.active_session!==null&&e.has(n.active_session)?n.active_session:null}]))})}let i=S.current.snapshot.session_order,a=i.filter(t=>e.has(t));a.length!==i.length&&S.current.update({session_order:a})},[s.loaded,r]);let E=(0,X.useCallback)(e=>{let n=c.current,r=l.current,i=d.current;if(!n.loaded||!r||!i)return!1;let{patch:a,projectBased:o}=qt(n.current(),e,{alive:new Set(r.filter(e=>e.status!==`archived`).map(e=>e.id)),sessionProject:new Map(r.map(e=>[e.id,e.project_id])),projectIds:i.map(e=>e.id),currentProject:t});return n.update(a),fe().projectBasedLayout!==o&&de({projectBasedLayout:o}),!0},[t]),D=o?`project`:`profile`,O=s.snapshot.layout_tree,k=s.snapshot.layout_ref,A=e.snapshot.project_layouts;return(0,X.useEffect)(()=>{e.loaded&&wi({scope:D,projectId:t,layoutRef:k,signature:bi(O),slices:Object.fromEntries(Object.entries(A).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:bi(t.layout_tree)}])),capture:()=>{let e=S.current.current();return{layout_tree:e.layout_tree,active_session:e.active_session}},apply:E,adopt:e=>{if(Mi()!==e.profile_id)return;let t=c.current;if(e.scope===`profile`)t.update({layout_ref:e.id});else if(e.project_id){let n=t.current().project_layouts,r=n[e.project_id];r&&t.update({project_layouts:{...n,[e.project_id]:{...r,layout_ref:e.id}}})}}})},[e.loaded,D,t,O,k,A,E]),(0,X.useEffect)(()=>()=>wi(null),[]),{uiState:s,projectScoped:o,scopeKey:f,layout:p,parkedSessions:b,chunksReady:C,focusLeaf:v,claimScrollDriver:g,scrollDriverLeafId:_}}function L_(e,t,n){return t?t.type===`editor`?t.tab.path.split(`/`).at(-1)||t.tab.path:n??t.session.slice(0,8):e}function R_({draft:e}){return(0,Z.jsx)(wr,{draft:e,actions:(0,Z.jsx)(Bg,{session:e.session,path:e.path,root:e.root,kind:`file`,label:e.path,recovered:!0,closeKey:pc(e),onClose:()=>{}})})}function z_({paneId:e,tab:t,drafts:n,onClose:r}){let i=n.filter(e=>E(t,e)),a=i[0];if(!a)return null;let o=`Huddle ${t.session.slice(0,8)}`;return(0,Z.jsxs)(`section`,{className:`flex flex-col gap-3`,"aria-label":o,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Z.jsx)(`span`,{children:o}),(0,Z.jsx)(Bg,{session:t.session,path:a.path,relatedPaths:i.slice(1).map(e=>e.path),kind:`file`,label:o,closeKey:Zi(e,B(t)),onClose:r})]}),i.map(e=>(0,Z.jsx)(wr,{draft:e},Hi(e)))]})}function B_({profileId:e,snapshot:t,retry:n,onClose:r}){let i=n_(e),a={snapshot:t,buffers:[...i],views:{}},{targets:o}=N(a),s=F(a);return(0,Z.jsxs)(`div`,{className:`h-full overflow-auto p-4`,role:`region`,"aria-label":`Unavailable project`,children:[(0,Z.jsx)(`h1`,{className:`text-sm`,children:`Project unavailable`}),(0,Z.jsx)(`p`,{className:`my-2 text-sm text-fg-muted`,children:`This window’s saved tabs and drafts are retained. Retry when the project is available.`}),(0,Z.jsx)(q,{variant:`ghost`,onClick:n,children:`Retry project`}),(0,Z.jsxs)(`div`,{className:`mt-4 flex flex-col gap-4`,children:[o.map(({paneId:e,ref:t})=>{if(t.type===`huddle`)return(0,Z.jsx)(z_,{paneId:e,tab:t,drafts:i,onClose:n=>r(e,t,n)},Zi(e,B(t)));if(t.type!==`editor`)return null;let n=i.find(e=>Hi(e)===Hi(t.tab)),a=(0,Z.jsx)(Bg,{session:t.tab.session,path:t.tab.path,root:t.tab.root,kind:Y(t.tab),label:t.tab.path,closeKey:Zi(e,B(t)),onClose:n=>r(e,t,n)});return n?(0,Z.jsx)(wr,{draft:n,actions:a},Zi(e,B(t))):(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[t.tab.path,a]},Zi(e,B(t)))}),s.map(e=>(0,Z.jsx)(R_,{draft:e},Hi(e)))]})]})}function V_({profileId:e,...t}){return!e||!z()?t.children:(0,Z.jsx)(H_,{profileId:e,...t})}function H_({profileId:e,snapshot:t,children:n}){let r=F({snapshot:t,buffers:[...n_(e)],views:{}});return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[r.length>0&&(0,Z.jsxs)(`details`,{open:!0,className:`max-h-[45%] shrink-0 overflow-auto p-3`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:`Recovered drafts`}),(0,Z.jsx)(`p`,{className:`my-2 text-sm text-fg-muted`,children:`These retained copies no longer have tabs. Copy, download or discard them here.`}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-4`,children:r.map(e=>(0,Z.jsx)(R_,{draft:e},Hi(e)))})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1`,children:n})]})}function U_(){return(0,Z.jsx)(Fi,{children:(0,Z.jsx)(wt,{children:(0,Z.jsx)(Qi,{children:(0,Z.jsx)(W_,{})})})})}function W_(){let e=ta(),t=z()?.identity,n=ji(),r=t?.kind===`pane`,i=t!==void 0&&t.kind!==`host`,a=fn(),o=dn(),s=Xe(),c=a.id??``,u=/^[0-9a-f]{10}$/.test(c),f=a.sid??null,p=je(u?c:void 0),m=p.data?.project.id===c?p.data:void 0,h=Ge(p.data?.project.profile_id).data??[],g=_i(),_=Le().data?.protocol,v=yi(),y=Be(),b=(0,X.useMemo)(()=>m?.sessions??y.data?.filter(e=>e.project_id===c)??[],[m,y.data,c]),x=y.data??b,S=ue(),C=!i&&(nn(S.projectBasedLayout)??S.projectBasedLayout),w=S.showAllProjectSessions,T=m?.project.profile_id??(t&&t.kind!==`host`?t.profileId:t?n??void 0:p.data?.project.profile_id),E=Ne(T);hc(T??null);let D=Me(T),O=Te(T??``),k=m?.project??E.data?.find(e=>e.id===c),A=(0,X.useMemo)(()=>kn((E.data??(k?[k]:[])).filter(e=>!e.archived),D.data?.projectOrder??[]),[E.data,k,D.data]),{uiState:j,projectScoped:M,scopeKey:N,layout:P,parkedSessions:F,chunksReady:I,focusLeaf:te,claimScrollDriver:ne,scrollDriverLeafId:re}=I_(v,{projectId:c,projectMode:C,sessions:y.data,projects:E.data,orderedProjects:A});Wa(T,I&&j.loaded),ir(T,I&&j.loaded&&(!!k||!!t&&!!p.error));let ie=(0,X.useMemo)(()=>{let e=e=>e.status!==`archived`,t=y.data??b;return A.map(n=>({projectId:n.id,name:n.name,abbrev:ce(n),colour:n.colour,repoId:n.repo_id,collapsed:!w&&n.id!==c,sessions:kn(t.filter(t=>t.project_id===n.id&&e(t)),j.snapshot.session_order)}))},[w,b,c,j.snapshot.session_order,A,y.data]),ae=(0,X.useCallback)((e,t)=>{let n=A.map(e=>e.id),r=Cn(n,e,t);r.some((e,t)=>e!==n[t])&&O.mutate({projectOrder:r})},[A,O]),oe=(0,X.useMemo)(()=>{let e=e=>Date.parse(e.last_activity_at??e.created_at)||0,t=t=>t.sort((t,n)=>e(n)-e(t)),n=e=>e.status===`archived`;if(M||!w)return t(b.filter(n));let r=y.data??b;return A.flatMap(e=>t(r.filter(t=>t.project_id===e.id&&n(t))))},[w,M,b,y.data,A]),L=Fc({layout:P,scopeKey:N,projectId:c,profileId:T,sessions:x,protocol:_}),se=(0,X.useRef)(j);se.current=j;let le=(0,X.useCallback)(e=>se.current.update({session_order:An(e,se.current.snapshot.session_order)}),[]),de=jl(Ml),fe=!r&&de,pe=(0,X.useRef)(fe);pe.current=fe;let[me,R]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(!1),[_e,ve]=(0,X.useState)(!1),[ye,be]=(0,X.useState)(`agent`),[xe,Se]=(0,X.useState)(void 0),[Ce,we]=(0,X.useState)(null),Ee=(0,X.useCallback)((e=`agent`,t)=>{Se(void 0),we(t??null),be(e),ve(!0)},[]),De=(0,X.useCallback)((e,t)=>{let n=A.find(e=>e.id===t);Ee(e,n?{projectId:n.id,repoId:n.repo_id}:void 0)},[A,Ee]),{setHandler:Oe}=Oi(),ke=ci(),[Ae,Fe]=(0,X.useState)(null);(0,X.useEffect)(()=>{!u||!l(_)||Ie(c).catch(()=>void 0)},[_,c,u]);let{openFile:Re,openEditorTab:ze,reveal:Ve,revealPreviewSource:He,revealCompiledSource:Ue,renameFileTab:We}=oc({layout:P,baseUiState:v,claimScrollDriver:ne,onOpen:()=>{pe.current&&R(!1)}}),Ke=(0,X.useCallback)((e,t,n)=>Re(e,t,void 0,{preview:n?.preview??!0}),[Re]),qe=(0,X.useCallback)((e,t)=>{let n=b.find(t=>t.id===e);n&&s.mutate({project_id:n.project_id,kind:`terminal`,separate_branch:!1,separate_worktree:!1,join_worktree:n.worktree_path,cwd:t},{onSuccess:e=>void o(`/project/${e.project_id}/session/${e.id}`),onError:e=>J(e)})},[b,s,o]),Je=(0,X.useCallback)(e=>P.promote(e),[P]),Ye=(0,X.useCallback)((e,t,n,r)=>ze({kind:`external`,session:e,path:t,root:n},void 0,{preview:r?.preview??!0}),[ze]);(0,X.useEffect)(()=>(Oe(e=>{Se(e?.accountId),be(e?.kind??`agent`),ve(!0)}),()=>Oe(null)),[Oe]);let Ze=P.focusedLeaf.tabs.find(e=>B(e)===P.focusedLeaf.activeKey)??null,Qe=Ze&&Ze.type!==`editor`?x.find(e=>e.id===Ze.session):void 0;ki(`workspace`,L_(k?.name??(p.error?`Unavailable project`:`Project`),r?Ze:null,Qe?g(Qe):void 0));let $e=Ze===null?null:Ze.type===`editor`?Ze.tab.session:Ze.session,et=$e===`00000000-0000-0000-0000-000000000000`?null:$e,tt=Pe().data?.find(e=>e.id===k?.repo_id),nt=(0,X.useMemo)(()=>d(_)&&tt&&k?{path:tt.path,projectId:k.id,name:k.name,defaultBranch:tt.default_base_branch}:null,[_,tt,k]),rt=yc(x,et??f,j,nt),it=rt.session,at=rt.root,ot=fc({baseUiState:v,scopeKey:N,projectId:c,targetSession:it,targetRoot:at,openEditorTab:ze}),{closeTab:st,onActivateTab:ct,onCloseTab:lt,onDropTab:ut,reopenClosedTab:dt,phoneSelection:ft,phoneVisited:pt,selectPhoneSession:mt}=Al({layout:P,uiState:j,scopeKey:N,projectScoped:M,sessions:b,allSessions:y.data,projectReady:!!m,isNarrow:fe,onNavigate:()=>ge(!1),claimScrollDriver:ne,requestDiscard:ot.requestDiscard}),ht=kg(ie,st),{browseRequest:gt,filetreeRoot:_t,rememberFiletreeRoot:vt,revealFileTab:yt,openFromTerminal:bt}=Ec({uiState:j,sidebarTarget:rt,tabSessions:x,openFile:Re,scopeKey:`${T}:${c}:${N}`,isNarrow:fe,showNavigator:()=>R(!0)}),xt=gf(j.snapshot.sidebar_mode),St=j.snapshot.sidebar_collapsed,Ct=j.snapshot.sessions_collapsed,[wt,Tt]=(0,X.useState)(!1),[Et,Dt]=(0,X.useState)(!1),Ot=(0,X.useCallback)(e=>{let t=P.focusedLeaf,n=t.tabs.find(e=>B(e)===t.activeKey)??null;if(!n||n.type!==`terminal`){U.error(`Focus a terminal or agent to insert`);return}Bi.write(n.session,`agent`,`\x1b[200~${e}\x1b[201~`)},[P]);(0,X.useEffect)(()=>(Ci(Ot),()=>Ci(null)),[Ot]);let kt=(0,X.useRef)({}),At=e=>{let t=P.focusedLeaf;if(t.tabs.length<2)return;let n=t.tabs.findIndex(e=>B(e)===t.activeKey),r=n===-1?e===1?0:t.tabs.length-1:n+e,i=t.tabs[(r+t.tabs.length)%t.tabs.length];i&&ct(t.id,i)},jt=e=>{fe?(j.update({sidebar_mode:e}),Ra(()=>R(!0))):j.update({sidebar_mode:e,sidebar_collapsed:!1})};kt.current={"tab.close":()=>{let t=P.focusedLeaf,n=t.tabs.find(e=>B(e)===t.activeKey);n?.type===`editor`||n?.type===`huddle`?e(Zi(t.id,B(n))):n&&lt(t.id,n)},"tab.reopen":dt,"tab.newUntitled":()=>void ot.create(),"tab.next":()=>At(1),"tab.prev":()=>At(-1),"editor.save":()=>{let e=Ze?.type===`huddle`?x.find(e=>e.id===Ze.session):void 0;if(e?.huddle_id)for(let t of ee(e.huddle_id))sc({session:e.id,path:t});else sc(P.activeEditorTab)},"editor.compile":()=>{let e=P.activeEditorTab;e&&!e.generated_by&&(e.kind===void 0||e.kind===`file`||e.kind===`external`)&&L.run(P.focusedLeaf.id,e)},"sidebar.left":()=>Ra(fe?()=>R(e=>!e):()=>j.update({sidebar_collapsed:!j.snapshot.sidebar_collapsed})),"sidebar.right":()=>Ra(fe?()=>ge(e=>!e):()=>j.update({sessions_collapsed:!j.snapshot.sessions_collapsed})),"nav.files":()=>jt(`files`),"nav.search":()=>jt(`search`),"nav.changes":()=>jt(`changes`),"nav.worktrees":()=>jt(`worktrees`),"session.newAgent":()=>Ee(`agent`),"session.newTerminal":()=>Ee(`terminal`)},(0,X.useEffect)(()=>{let e=Object.keys(kt.current).map(e=>Ni(e,()=>kt.current[e]?.()));return()=>e.forEach(e=>e())},[]);let Mt=P.activeEditorTab,Nt=Mt?.kind===`diff`&&it&&Mt.session===it.id?Mt.path:null,Pt=Mt&&(Mt.kind??`file`)===`file`&&it&&Mt.session===it.id?Mt.path:null,Ft=Mt?.kind===`external`&&Mt.root!==void 0?{path:Mt.path,root:Mt.root}:null,It=e=>({preview:e?.preview??!0}),Lt=(e,t)=>{if(it){let n=t?.root??at,r=n===void 0?{}:{root:n};ze({kind:`diff`,session:it.id,path:e,...r,...t?.gitArea===void 0?{}:{git_area:t.gitArea}},void 0,It(t))}},Rt=(e,t,n)=>{if(it){let r=n?.root??at,i=r===void 0?{}:{root:r};ze({kind:`commit`,session:it.id,path:e,sha:t,...i},void 0,It(n))}},zt=(e,t,n)=>{if(!it)return;let r=t===void 0?void 0:{line:t,column:1};if(at!==void 0){ze({kind:`external`,session:it.id,path:e,root:at},r,It(n));return}Re(it.id,e,r,It(n))},Bt=(0,X.useCallback)(e=>j.update({layout:{...j.snapshot.layout,...e}}),[j]),Vt=Nl(j.snapshot.layout,[...St?[]:[`nav`],`main`,...Ct?[]:[`sessions`]]);if(!u)return null;if(t&&!k&&p.error&&j.loaded&&T)return(0,Z.jsxs)(na,{state:v,children:[(0,Z.jsx)(B_,{profileId:T,snapshot:v.snapshot,retry:()=>void p.refetch(),onClose:(e,t,n)=>t.type===`editor`&&t.tab.kind===`untitled`?ot.requestDiscard(e,t,n):mc(v,e,t)}),ot.dialogs]});if(!j.loaded||!k||!I)return(0,Z.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-fg-muted`,children:`…`});let Ut=e=>(0,Z.jsx)(vf,{mode:xt,onModeChange:e=>j.update({sidebar_mode:e}),onCollapse:e,projectId:c,repoId:k.repo_id,sessions:b,target:rt,browseRequest:gt,onFiletreeRootChange:vt,compilableExtensions:L.extensions,onOpenCompilationSettings:L.openSettings,onOpenFile:Ke,onOpenExternalFile:Ye,onOpenTerminalIn:qe,activeFilePath:Pt,activeExternalTab:Ft,activeDiffPath:Nt,onOpenDiff:Lt,onOpenCommitFile:Rt,onOpenSearchFile:zt}),Wt=e=>{let t=E.data?.find(t=>t.id===e);t&&ke&&Fe({project:e,repo:t.repo_id})},Gt={onNewHuddleIn:ke?Wt:void 0,onNewSessionIn:e=>De(`agent`,e),onNewTerminalIn:e=>De(`terminal`,e),onMoveProject:ae},Kt=e=>(0,Z.jsx)(Sg,{searching:wt,setSearching:Tt,showArchived:Et,onShowArchivedChange:Dt,groups:ie,accounts:h,activeSessionId:f,onReorder:le,onPromote:e=>{let t=x.find(t=>t.id===e);t&&P.ensureSession(t)},archived:oe,onNewSession:()=>Ee(`agent`),onNewHuddle:ke?()=>Wt(c):void 0,onNewTerminal:()=>Ee(`terminal`),onCollapse:e,onArchived:st,onArchiveDrop:ht.onArchive,selection:ht,projectActions:Gt}),qt=b.find(e=>e.id===ft)?.id??b.find(e=>e.id===f)?.id??null,Jt=fe?(0,Z.jsx)(Cl,{sessions:b,selected:qt,select:mt}):(0,Z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[L.watchers,(0,Z.jsx)(Sn,{className:`min-h-0 flex-1`,motionKey:JSON.stringify([N,j.snapshot.layout_ref,Ht(P.tree).map(e=>e.id)]),children:(0,Z.jsx)(k_,{tree:P.tree,filetreeRoot:_t??at??it?.worktree_path??null,sessions:x,reveal:Ve,onActivateTab:ct,onCloseTab:lt,onPromoteTab:Je,onArchived:st,onFocusLeaf:te,onScrollDrive:ne,onResize:P.resize,onDropTab:ut,onSetTabView:P.setView,compilableExtensions:L.extensions,compilationProviders:L.providers,compilationRunningKeys:L.runningKeys,onRunCompilation:(e,t,n)=>void L.run(e,t,n),onSetCompilationMode:L.setMode,onOpenCompilationSettings:L.openSettings,onRevealPreviewSource:He,onRevealCompiledSource:Ue,onNewUntitled:()=>void ot.create(),onRevealFile:yt,onRenameFile:We,focusedLeafId:P.focusedLeaf.id,scrollDriverLeafId:re,scrollChannel:`${T??``}:${N}`})})]}),Yt=(0,Z.jsx)(zc,{tree:P.tree,parked:[...F,...pt,...qt?[qt]:[]].filter(e=>x.some(t=>t.id===e&&t.kind!==`huddle`)),onOpenFile:bt,children:(0,Z.jsx)(Hh,{onDrop:P.drop,onDropPane:P.dropPane,onArchive:e=>ht.onArchive([e]),renderOverlay:e=>{let t=e.type===`editor`?void 0:x.find(t=>t.id===e.session);return(0,Z.jsx)(`div`,{className:`rounded-md bg-elevated px-2.5 py-1 text-xs text-fg shadow-lg`,children:e.type===`editor`?e.tab.path.split(`/`).pop()??e.tab.path:t?g(t):e.session.slice(0,8)})},children:(0,Z.jsxs)(`div`,{className:`relative flex h-full min-h-0 gap-[var(--ui-surface-gap)] overflow-hidden p-[var(--ui-surface-gap)]`,children:[r?(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:Jt}):fe?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(_f,{mode:xt,onExpand:()=>Ra(()=>R(!0)),onSelect:e=>{j.update({sidebar_mode:e}),Ra(()=>R(!0))}}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`,children:Jt}),(0,Z.jsx)(Og,{groups:ie,accounts:h,activeSessionId:f,onReorder:le,onPromote:e=>{let t=x.find(t=>t.id===e);t&&P.ensureSession(t)},onExpand:()=>Ra(()=>ge(!0)),onShowArchived:()=>Ra(()=>{Dt(!0),ge(!0)}),onSearch:()=>{Tt(!0),Ra(()=>ge(!0))},onNewTerminal:()=>Ee(`terminal`),onNewSession:()=>Ee(`agent`),onNewHuddle:ke?()=>Wt(c):void 0,onArchived:st,onArchiveDrop:ht.onArchive,selection:ht,projectActions:Gt}),me&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close the navigator`,className:`absolute inset-0 z-30 bg-ground/60`,onClick:()=>Ra(()=>R(!1))}),(0,Z.jsx)(`div`,{style:{viewTransitionName:`workspace-navigator`},className:`absolute inset-y-1.5 left-11 z-40 w-[min(20rem,calc(100%-4.5rem))] shadow-xl`,children:Ut(()=>Ra(()=>R(!1)))})]}),he&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close the session list`,className:`absolute inset-0 z-30 bg-ground/60`,onClick:()=>Ra(()=>ge(!1))}),(0,Z.jsx)(`div`,{style:{viewTransitionName:`workspace-sessions`},className:`absolute inset-y-1.5 right-11 z-40 w-[min(20rem,calc(100%-4.5rem))] shadow-xl`,children:Kt(()=>Ra(()=>ge(!1)))})]})]}):(0,Z.jsxs)(Z.Fragment,{children:[St&&(0,Z.jsx)(`div`,{className:`flex h-full shrink-0`,style:{viewTransitionName:`workspace-navigator`},children:(0,Z.jsx)(_f,{mode:xt,onExpand:()=>Ra(()=>j.update({sidebar_collapsed:!1})),onSelect:e=>Ra(()=>j.update({sidebar_collapsed:!1,sidebar_mode:e}))})}),(0,Z.jsxs)(Ns,{orientation:`horizontal`,className:`h-full min-w-0 flex-1`,defaultLayout:Vt,onLayoutChanged:Bt,children:[!St&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Is,{id:`nav`,defaultSize:280,minSize:200,maxSize:560,style:{viewTransitionName:`workspace-navigator`},children:Ut(()=>Ra(()=>j.update({sidebar_collapsed:!0})))}),(0,Z.jsx)(Vs,{className:`workspace-divider-vertical`})]}),(0,Z.jsx)(Is,{id:`main`,children:(0,Z.jsx)(`div`,{"data-sidebar-main":!0,className:`h-full w-full`,children:Jt})}),!Ct&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Vs,{className:`workspace-divider-vertical`}),(0,Z.jsx)(Is,{id:`sessions`,defaultSize:260,minSize:180,maxSize:480,style:{viewTransitionName:`workspace-sessions`},children:Kt(()=>Ra(()=>j.update({sessions_collapsed:!0})))})]})]}),Ct&&(0,Z.jsx)(`div`,{className:`flex h-full shrink-0`,style:{viewTransitionName:`workspace-sessions`},children:(0,Z.jsx)(Og,{groups:ie,accounts:h,activeSessionId:f,onReorder:le,onPromote:e=>{let t=x.find(t=>t.id===e);t&&P.ensureSession(t)},onExpand:()=>Ra(()=>j.update({sessions_collapsed:!1})),onShowArchived:()=>Ra(()=>{Dt(!0),j.update({sessions_collapsed:!1})}),onSearch:()=>{Tt(!0),Ra(()=>j.update({sessions_collapsed:!1}))},onNewTerminal:()=>Ee(`terminal`),onNewSession:()=>Ee(`agent`),onNewHuddle:ke?()=>Wt(c):void 0,onArchived:st,onArchiveDrop:ht.onArchive,selection:ht,projectActions:Gt})})]}),Ae&&T&&(0,Z.jsx)(Pa,{profile:T,project:Ae.project,repo:Ae.repo,onClose:()=>Fe(null),onOpened:e=>{o(`/project/${e.project_id}/session/${e.id}`)}}),(0,Z.jsx)(yf,{projectId:Ce?.projectId??c,repoId:Ce?.repoId??k.repo_id,open:_e,kind:ye,seedAccountId:xe,onOpenChange:ve,onCreated:e=>void o(`/project/${e.project_id}/session/${e.id}`)}),ot.dialogs,L.settingsDialog]})})});return(0,Z.jsx)(na,{state:v,children:(0,Z.jsx)(V_,{profileId:T,snapshot:v.snapshot,children:Yt})})}export{U_ as Workspace};