@surething/cockpit 1.0.229 → 1.0.231

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 (192) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +3 -3
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/prerender-manifest.json +3 -3
  5. package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
  6. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  7. package/.next-prod/server/app/_global-error.html +1 -1
  8. package/.next-prod/server/app/_global-error.rsc +1 -1
  9. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
  13. package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
  14. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  15. package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
  16. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  17. package/.next-prod/server/app/_not-found.html +2 -2
  18. package/.next-prod/server/app/_not-found.rsc +3 -3
  19. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +3 -3
  20. package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
  21. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +3 -3
  22. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  23. package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  24. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  25. package/.next-prod/server/app/api/agent/test/route.js.nft.json +1 -1
  26. package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
  27. package/.next-prod/server/app/api/chat/codex/route.js +1 -1
  28. package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
  29. package/.next-prod/server/app/api/chat/deepseek/route.js +1 -1
  30. package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
  31. package/.next-prod/server/app/api/chat/kimi/route.js +1 -1
  32. package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
  33. package/.next-prod/server/app/api/chat/ollama/route.js +1 -1
  34. package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
  35. package/.next-prod/server/app/api/chat/pty-input/route.js.nft.json +1 -1
  36. package/.next-prod/server/app/api/chat/route.js +1 -1
  37. package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
  38. package/.next-prod/server/app/api/chat/stop/route.js.nft.json +1 -1
  39. package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
  40. package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
  41. package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
  42. package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
  43. package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
  44. package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
  45. package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
  46. package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
  47. package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
  48. package/.next-prod/server/app/api/dev/spans/route.js.nft.json +1 -1
  49. package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
  50. package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
  51. package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
  52. package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
  53. package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
  54. package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
  55. package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
  56. package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
  57. package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
  58. package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
  59. package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
  60. package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
  61. package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
  62. package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
  63. package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
  64. package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
  65. package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
  66. package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
  67. package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
  68. package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
  69. package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
  70. package/.next-prod/server/app/api/git/current-branch/route.js.nft.json +1 -1
  71. package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
  72. package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
  73. package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
  74. package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
  75. package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
  76. package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
  77. package/.next-prod/server/app/api/global-state/route.js +3 -1
  78. package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
  79. package/.next-prod/server/app/api/health/route.js.nft.json +1 -1
  80. package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
  81. package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
  82. package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
  83. package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
  84. package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
  85. package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
  86. package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
  87. package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
  88. package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
  89. package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
  90. package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
  91. package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
  92. package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
  93. package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
  94. package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
  95. package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
  96. package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
  97. package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
  98. package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
  99. package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
  100. package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
  101. package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
  102. package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
  103. package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
  104. package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
  105. package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
  106. package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
  107. package/.next-prod/server/app/api/projectGraph/affected/route.js.nft.json +1 -1
  108. package/.next-prod/server/app/api/projectGraph/callees/route.js.nft.json +1 -1
  109. package/.next-prod/server/app/api/projectGraph/callers/route.js.nft.json +1 -1
  110. package/.next-prod/server/app/api/projectGraph/coedit/route.js.nft.json +1 -1
  111. package/.next-prod/server/app/api/projectGraph/context/route.js.nft.json +1 -1
  112. package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
  113. package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
  114. package/.next-prod/server/app/api/projectGraph/impact/route.js.nft.json +1 -1
  115. package/.next-prod/server/app/api/projectGraph/related/route.js.nft.json +1 -1
  116. package/.next-prod/server/app/api/projectGraph/risk/route.js.nft.json +1 -1
  117. package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
  118. package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
  119. package/.next-prod/server/app/api/push/public-key/route.js.nft.json +1 -1
  120. package/.next-prod/server/app/api/push/subscribe/route.js.nft.json +1 -1
  121. package/.next-prod/server/app/api/push/unsubscribe/route.js.nft.json +1 -1
  122. package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
  123. package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
  124. package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
  125. package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
  126. package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
  127. package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
  128. package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
  129. package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
  130. package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
  131. package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
  132. package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
  133. package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
  134. package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
  135. package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
  136. package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
  137. package/.next-prod/server/app/api/scheduled-tasks/route.js +1 -1
  138. package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
  139. package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
  140. package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
  141. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
  142. package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
  143. package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
  144. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
  145. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
  146. package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
  147. package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
  148. package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
  149. package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
  150. package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
  151. package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
  152. package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
  153. package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
  154. package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
  155. package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
  156. package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
  157. package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
  158. package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
  159. package/.next-prod/server/app/m/page.js.nft.json +1 -1
  160. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  161. package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
  162. package/.next-prod/server/app/page.js.nft.json +1 -1
  163. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  164. package/.next-prod/server/app/project/page.js.nft.json +1 -1
  165. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  166. package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
  167. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  168. package/.next-prod/server/app-paths-manifest.json +3 -3
  169. package/.next-prod/server/chunks/3633.js +1 -1
  170. package/.next-prod/server/chunks/9658.js +3 -3
  171. package/.next-prod/server/chunks/9830.js +1 -0
  172. package/.next-prod/server/middleware-build-manifest.js +1 -1
  173. package/.next-prod/server/pages/404.html +2 -2
  174. package/.next-prod/server/pages/500.html +1 -1
  175. package/.next-prod/server/server-reference-manifest.json +1 -1
  176. package/.next-prod/static/chunks/217-a25b84ad39cf73ed.js +5 -0
  177. package/.next-prod/static/chunks/2576-439565bf051dc1ba.js +25 -0
  178. package/.next-prod/static/css/ee516fc73c03aa88.css +1 -0
  179. package/.next-prod/trace +13 -13
  180. package/.next-prod/trace-build +1 -1
  181. package/bin/cock.mjs +10 -0
  182. package/dist/auth.mjs +92 -0
  183. package/dist/{chunk-XW5CKMXI.mjs → chunk-VHFWPI2X.mjs} +64 -3
  184. package/dist/scheduledTasks.mjs +1 -1
  185. package/dist/wsServer.mjs +1 -1
  186. package/package.json +1 -1
  187. package/server.mjs +48 -0
  188. package/.next-prod/static/chunks/217-d644348194c14361.js +0 -5
  189. package/.next-prod/static/chunks/2576-49c4aeffa6a6b95e.js +0 -25
  190. package/.next-prod/static/css/1d4a0de85e617fe5.css +0 -1
  191. /package/.next-prod/static/{fLCxsDN9EciQYDYw-OdS3 → eirTPmw6oXFp3wKgUVcXn}/_buildManifest.js +0 -0
  192. /package/.next-prod/static/{fLCxsDN9EciQYDYw-OdS3 → eirTPmw6oXFp3wKgUVcXn}/_ssgManifest.js +0 -0
@@ -0,0 +1,25 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2576],{1700:(e,t,r)=>{r.d(t,{TabManager:()=>nF});var n=r(95155),s=r(12115),o=r(79114),a=r(95045),l=r(75346),i=r(86957),c=r(83448);function d({isOpen:e,onClose:t,cwd:r,onSelectSession:u}){let{t:x}=(0,o.Bd)(),[m,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(""),w=(0,s.useRef)(null),k=(0,s.useCallback)(async()=>{if(!r)return;p(!0),b(null);let e=r.replace(/\//g,"-"),t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?h(t.value):b("Failed to load sessions"),p(!1)},[r]);(0,s.useEffect)(()=>{e&&(k(),setTimeout(()=>{w.current?.focus()},100))},[e,k]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let y=m.filter(e=>{if(!v)return!0;let t=v.toLowerCase();return void 0!==e.searchText?e.searchText.includes(t):e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:x("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:r,children:r})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:w,type:"text",placeholder:x("sessions.searchSessions"),value:v,onChange:e=>j(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[f&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:x("sessions.loadingSessions")})]})}),g&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:g})}),!f&&!g&&0===y.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:x(v?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!f&&!g&&y.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:y.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(u?(u(n,e.title),t()):(0,a.F)(l.n.OpenProject,{cwd:r,sessionId:n}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:e.title,children:e.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path))})]})]})]}):null}var u=r(47650),x=r(64428),m=r(60938),h=r(53213),f=r(67362),p=r(70188);let g={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},b={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function v({name:e,className:t="",size:r=16}){let s,o=b[s=e.toLowerCase()]?b[s]:g[e.split(".").pop()?.toLowerCase()||""]||g.default,a=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===a||"tsx"===a&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===a||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===a||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===a||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function j({status:e}){let{label:t,className:r}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,n.jsx)("span",{className:`text-xs font-bold ${r}`,children:t})}let w=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let x=o===t.path,m=a.has(t.path),h=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):l(t)},[t,l,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick:h,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:m?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),m&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${x?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:h,onContextMenu:f,children:[(0,n.jsx)(v,{name:t.name,size:16,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:`text-sm flex-1 truncate ${x?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(j,{status:t.status}),d&&void 0!==t.additions&&void 0!==t.deletions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,n.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),u&&u(t)]})});function k({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,cwd:l,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:x}=(0,o.Bd)(),m=d??x("gitFileTree.noFiles"),{contextMenu:h,showContextMenu:f,hideContextMenu:g}=(0,p.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:m}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(w,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,onContextMenu:f,showChanges:i,renderActions:c},e.path)),h&&(0,n.jsx)(p.ft,{x:h.x,y:h.y,path:h.path,cwd:l,isDirectory:h.isDirectory,onClose:g})]})}function y(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,a=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===s);l||(l={name:s,path:a,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(l)),o||(n=l.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function N(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function C(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var S=r(47215),L=r(56045);function M({isOpen:e,onClose:t,commit:r,cwd:a,embedded:l=!1,initialFilePath:c,onContentSearch:d}){let{t:u}=(0,o.Bd)(),[x,m]=(0,s.useState)([]),[p,g]=(0,s.useState)([]),[b,v]=(0,s.useState)(new Set),[j,w]=(0,s.useState)(null),[C,E]=(0,s.useState)(null),[P,$]=(0,s.useState)(!1),[T,R]=(0,s.useState)(!1),[B,F]=(0,s.useState)(null),I=(0,s.useRef)(null),D=(0,L.o)(I);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&B){e.preventDefault(),D.open();return}if("Escape"===e.key){if(D.isVisible)return void D.close();if(B)return void F(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,B,D]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{m([]),g([]),w(null),E(null),$(!0)}),i.t4.runPromiseExit((0,h.Zi)(a,r.hash)).then(e=>{if("Success"===e._tag){let t=e.value.files??[];m(t);let n=y(t);if(g(n),v(new Set(N(n))),c&&t.length>0){let e=t.find(e=>e.path===c);e&&setTimeout(()=>{w(e),i.t4.runPromiseExit((0,h.Zi)(a,r.hash,e.path)).then(e=>{"Success"===e._tag?E(e.value):console.error(e.cause)})},0)}}else console.error(e.cause);$(!1)}))},[e,r,a,c]);let A=(0,s.useCallback)(e=>{r&&(w(e),R(!0),i.t4.runPromiseExit((0,h.Zi)(a,r.hash,e.path)).then(e=>{"Success"===e._tag?E(e.value):console.error(e.cause),R(!1)}))},[a,r]),W=(0,s.useCallback)(e=>{v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),z=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,a,l;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${a}:${l}`:`${e.getFullYear()}-${s}-${o} ${a}:${l}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let _=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border bg-secondary flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-slate-9",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.date")}),(0,n.jsx)("span",{children:z}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-slate-9",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.files")}),(0,n.jsx)("span",{children:u("commitDetail.nChanges",{count:x.length})})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:P?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:u("commitDetail.loadingFiles")}):(0,n.jsx)(k,{files:p,selectedPath:j?.path||null,expandedPaths:b,onSelect:e=>e.file&&A(e.file),onToggle:W,cwd:a,showChanges:!0,emptyMessage:u("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:T?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.loadingDiff")}):C?(0,n.jsx)(f.xZ,{oldContent:C.oldContent,newContent:C.newContent,filePath:C.filePath,isNew:C.isNew,isDeleted:C.isDeleted,cwd:a,enableComments:!0,onPreview:!C.isDeleted&&C.filePath.endsWith(".json")?()=>F({content:C.newContent,filePath:C.filePath}):void 0,previewLabel:u("common.readable"),onContentSearch:d}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.selectFileToView")})})]})]}),H=B&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>F(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:B.filePath}),(0,n.jsx)("button",{onClick:()=>F(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(L._,{search:D}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:I,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,S.xb)(B.content)})})]})});return l?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:u("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),_,H]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:u("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),_,H]})})}var E=r(34075),P=r(64702);let $={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},"?":{text:"text-slate-9",bg:"bg-slate-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},T=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:a,onToggle:l,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:x,hasChangedChildren:m}=e,h=x?$[x]:null,f=(0,s.useCallback)(()=>{d.isDirectory?l(d.path):a(d.path)},[d.isDirectory,d.path,a,l]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=x?h.text:m?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!d.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-accent ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[d.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(v,{name:d.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":d.isSymlink&&d.symlinkTarget?`${d.path} → ${d.symlinkTarget}`:d.path,children:d.name}),d.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),x&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${h.text} ${h.bg} flex-shrink-0`,children:x}),d.isDirectory&&m&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function R({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:a=null,loadingDirs:l,onSelect:i,onToggle:c,cwd:d,shouldScrollToSelected:u=!1,onScrolledToSelected:x,className:m,renderActions:h,onCreateFile:f,onDelete:g,onRefresh:b,onCopyFile:v,onPaste:j}){let w=(0,s.useRef)(null),{contextMenu:k,showContextMenu:y,hideContextMenu:N}=(0,p.Ee)(),C=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let a=[];for(let l of t){if(null!==n&&!n.has(l.path))continue;let t=s?.get(l.path),i=l.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(l.path,s):void 0;a.push({node:l,level:o,gitStatus:t,hasChangedChildren:i}),l.isDirectory&&l.children&&r.has(l.path)&&a.push(...e(l.children,r,n,s,o+1))}return a})(e,r,o,a),[e,r,o,a]),S=(0,P.Te)({count:C.length,getScrollElement:()=>w.current,estimateSize:()=>26,overscan:10}),L=(0,s.useRef)(x);return(L.current=x,(0,s.useEffect)(()=>{if(u&&t&&C.length>0){let e=C.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{S.scrollToIndex(e,{align:"center"}),L.current?.()},150);return()=>clearTimeout(t)}}},[u,t,C,S]),0===C.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:w,className:m||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${S.getTotalSize()}px`,width:"100%",position:"relative"},children:S.getVirtualItems().map(e=>{let s=C[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(T,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:l?.has(s.node.path),onSelect:i,onToggle:c,onContextMenu:y,renderActions:h})},s.node.path)})}),k&&(0,n.jsx)(p.ft,{x:k.x,y:k.y,path:k.path,cwd:d,isDirectory:k.isDirectory,onClose:N,onCreateFile:f,onDelete:g,onRefresh:b,onCopyFile:v,onPaste:j})]})}var B=r(38408),F=r(82292),I=r(5135),D=r(38175),A=r(79968);function W({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),a=o>=0?e.slice(0,o+1):"",l=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],a="",l=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==l&&a&&(o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-${s}`):(0,n.jsx)("span",{children:a},`${t}-${s}`)),a=""),l=c,a+=e[s]}return a&&o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-end`):(0,n.jsx)("span",{children:a},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[a&&i(a,0,"text-muted-foreground"),i(l,a.length,"text-foreground")]})}function z({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(""),[u,m]=(0,s.useState)(0),h=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),g=(0,s.useMemo)(()=>{if(!c.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...p.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of p){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,a=0,l=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),l===i-1&&(a+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(a+=10),i>e.lastIndexOf("/")&&(a+=3),e[i]===t[o]&&(a+=1),l=i,o++);return o<n.length?null:(a-=.1*e.length,{path:e,score:a,matchedIndices:s})}(t,c.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[c,p,r]),b=(0,s.useCallback)(e=>{d(e),m(0)},[]);(0,s.useEffect)(()=>{h.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[u];e?.scrollIntoView({block:"nearest"})}},[u]);let j=(0,s.useCallback)(e=>{a(e),l()},[a,l]),w=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),m(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),m(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[u]&&j(g[u].path);break;case"Escape":e.preventDefault(),l()}},[g,u,j,l]);return(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:l,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:h,value:c,onChange:e=>b(e.target.value),onKeyDown:w,placeholder:i("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:f,className:"flex-1 overflow-y-auto py-1",children:0===g.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:i("quickFileOpen.noMatch")}):g.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===u?"bg-brand/15 text-foreground":"hover:bg-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>j(e.path),children:[(0,n.jsx)(v,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(W,{path:e.path,matchedIndices:e.matchedIndices}),!c.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:i("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",i("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",i("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",i("quickFileOpen.closeHint")]})]})]})})})}var _=r(2111),H=r(41474),O=r(61878),q=r(33210),V=r(48368),K=r(91958),U=r(45916),J=r(31794),Q=r(69048),Z=r(97567),Y=r(68806),G=r(52475);function X({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(V.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(U.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(J.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(Q.A,{className:s});case"class":return(0,n.jsx)(Z.A,{className:s});case"interface":return(0,n.jsx)(Y.A,{className:s});default:return(0,n.jsx)(G.A,{className:s})}}var ee=r(49433),et=r(82680);let er=new Map,en=new Map;async function es(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){er.clear(),en.clear();return}let t=`${e}::`;for(let e of er.keys())e.startsWith(t)&&er.delete(e);for(let e of en.keys())e.startsWith(t)&&en.delete(e)}(e);else{let e=er.get(n);if(e)return e;let t=en.get(n);if(t)return t}let s=ee.tryPromise({try:async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let a=await o.json();return er.set(n,a),a},catch:e=>new et.uV({message:"fetchFileFunctions failed",cause:e})}),o=i.t4.runPromiseExit(s).then(e=>{if("Success"===e._tag)return e.value;let t="Fail"===e.cause._tag?e.cause.error:null,r=t?.cause;if(r instanceof Error)throw r;throw Error(t?.message??"fetchFileFunctions failed")}).finally(()=>en.delete(n));return en.set(n,o),o}function eo(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let a=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),es(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?a(e,t,!1):n({state:"idle"})},[e,t,a]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&a(e,t,!0)},[e,t,a])}}var ea=r(48347),el=r(1058),ei=r(90717),ec=r(3238),ed=r(17196),eu=r(50538),ex=r(94287);function em({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eu.A,{className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})]}),e.length>0&&(0,n.jsx)(ex.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(q.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)(ex.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:bg-secondary/60 transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(X,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eh(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let ef=new Set(["function","class","method"]);function ep(e){return ef.has(e.kind)}function eg({functions:e,currentQname:t,onSelect:r,notIndexed:a,onRebuild:l}){let{t:i}=(0,o.Bd)(),c=(0,s.useMemo)(()=>e.filter(ep),[e]);return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-r border-border flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:0===c.length?i("blockViewer.toc.title"):`${i("blockViewer.toc.title")} \xb7 ${c.length}`}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===c.length?a?(0,n.jsxs)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/80 leading-relaxed flex flex-col gap-2",children:[(0,n.jsx)("span",{className:"italic",children:i("blockViewer.toc.notIndexed")}),l&&(0,n.jsx)("button",{type:"button",onClick:l,className:"self-start px-2 py-1 rounded border border-border bg-secondary/60 hover:bg-secondary text-[10px] text-foreground transition-colors",children:i("blockViewer.refresh")})]}):(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:i("blockViewer.toc.empty")}):c.map(e=>{let s=t===e.qualifiedName;return(0,n.jsx)(ex.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>r(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-center gap-1.5 min-w-0 ${s?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(X,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs font-mono truncate ${s?"font-semibold text-brand":""}`,children:e.name})]})},e.qualifiedName)})})]})}var eb=r(27570),ev=r(96035);function ej({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:a}){let l=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=l.get(n.endLine);e?e.push(n):l.set(n.endLine,[n])}return 0===l.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(l.entries()).map(([e,r])=>{let l=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsx)(ex.m,{content:1===r.length?i.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>a(i,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-sm transition-colors",style:{top:`${l+s/2-8}px`},children:[(0,n.jsx)(ev.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function ew(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function ek({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let a,l=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),c=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let d=(e,t)=>{let r=ew(i,e),n=ew(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:l,onClick:e=>{let t=l.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,a=c.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(a)return void o(a.qname,s);if(c.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=ew(i,s);if(null!==t){let r=null,n=1/0;for(let e of c){let s=ew(i,e.start),o=ew(i,e.end);if(null===s||null===o)continue;let a=t<s?s-t:t>o?t-o:0;a<n&&(r=e,n=a)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let d=i.blocks.find(e=>e.qname===n.qname);d&&o(d.qname,d.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[c.map(e=>{let t=d(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((a=d(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${a.top}%`,height:`${Math.max(1.2,a.heightPct)}%`}}):null)]})}var ey=r(89109),eN=r(7320),eC=r(37614);function eS(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eL({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:a,onCommentClick:l,addedLines:i}){let{resolvedTheme:c}=(0,ec.D)(),d=(0,s.useMemo)(()=>(0,ed.sQ)(e.filePath),[e.filePath]),[u,x]=(0,s.useState)(null),[m,h]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void x(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,ed.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,ed.b8)(t)}</span></div>`}).join("");r||(x(s),h(null))}catch(e){r||h(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==m)&&o(e.qualifiedName)},[u,m,e.qualifiedName,o]),(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-secondary/40 text-xs",children:[(0,n.jsx)(X,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eE}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),m&&(0,n.jsx)("span",{className:"text-red-11",children:m}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),a&&a.length>0&&l&&(0,n.jsx)(ej,{comments:a,startLine:e.startLine,endLine:e.endLine,lineHeight:eE,bodyTopOffset:eP+e$,onCommentClick:l})]})}function eM({side:e,pin:t,accent:r,onClick:s}){let o,a,l,i,c,d,u,x=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="ext",l="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="method",l="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="method (unresolved)",u=x>0?`at line${x>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",a="self",l="text-muted-foreground/70",i=t.external.name,c=null,d="same-file",u=x>0?`at line${x>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",a=e,l="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=eS(t.external.filePath),d="in"===e?"caller":"callee",u=t.external.filePath);let m=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${m} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${l} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:a}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),x>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",x,"\xd7"]})]})]})}let eE=18,eP=29,e$=8;function eT(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eR(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function eB(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function eF({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:a,onHighlighted:l,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let x=function(e,t){if(0===e.length)return[];let r=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eP+e$+(o-t.startLine)*eE,s);n[e]=r,s=r+22}return n}(o,e);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:"w-44 flex-shrink-0 flex flex-col gap-1 pt-1",children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(eM,{side:"in",pin:t,accent:eR(t,d),onClick:()=>a(t,e)},eT("in",t)))}),(0,n.jsx)(eL,{symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 flex-shrink-0 relative",children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${x[r]}px`},children:(0,n.jsx)(eM,{side:"out",pin:t,accent:eR(t,d),onClick:()=>a(t,e)})},eT("out",t)))})]})}function eI({cwd:e,onSelect:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,c]=(0,s.useState)(""),[d,u]=(0,s.useState)({files:[],symbols:[]}),[x,m]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),g=(0,s.useMemo)(()=>[...d.files,...d.symbols],[d]);(0,s.useEffect)(()=>{let t=l.trim();if(!t)return void u({files:[],symbols:[]});p(!0);let r=setTimeout(async()=>{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await i.t4.runPromiseExit((0,h.MB)(r));"Success"===n._tag&&(u(n.value),m(0)),p(!1)},120);return()=>clearTimeout(r)},[l,e]);let b=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==g.length){if("ArrowDown"===e.key)e.preventDefault(),m(e=>Math.min(e+1,g.length-1));else if("ArrowUp"===e.key)e.preventDefault(),m(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=g[x];r&&t(r)}}},[g,x,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-2xl overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(O.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:l,onChange:e=>c(e.target.value),onKeyDown:b,placeholder:a("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),f&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(q.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===g.length&&l&&!f&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("blockViewer.search.noResults","No matches")}),(0,n.jsx)(eD,{label:a("blockViewer.search.files","Files"),hits:d.files,startIdx:0,activeIdx:x,onSelect:t,setActive:m}),(0,n.jsx)(eD,{label:a("blockViewer.search.symbols","Symbols"),hits:d.symbols,startIdx:d.files.length,activeIdx:x,onSelect:t,setActive:m})]})]})})}function eD({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:a}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let l=r+t,i=l===s;return(0,n.jsxs)("button",{onMouseEnter:()=>a(l),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.target.kind?(0,n.jsx)(V.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(X,{kind:e.target.symbolKind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function eA({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:a,enableComments:l=!1,onContentSearch:c,onFocalChange:d,qnameFilter:u,qnameFilterFile:x,accentQnames:h,accentFile:f,addedLines:p,addedLinesFile:g,headerExtraLeft:b,headerExtraRight:v}){let{t:j}=(0,o.Bd)(),[w,k]=(0,s.useState)(null),y=w??t??null;(0,s.useEffect)(()=>{k(null)},[t]),(0,s.useEffect)(()=>{d?.(y)},[y,d]);let{state:N,refresh:C}=eo(e,y),[S,L]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!y)return void L(null);let t=!1;return L(null),(async()=>{let r=new URLSearchParams({cwd:e,path:y}),n=await i.t4.runPromiseExit((0,m.eA)(r));t||("Success"===n._tag?L({content:n.value.content,mtimeMs:n.value.mtimeMs}):console.error("[BlockViewer] failed to load file source for",y,n.cause))})(),()=>{t=!0}},[e,y]);let M=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!S||"ready"!==N.state)return;let e=N.data.mtimeMs;!e||S.mtimeMs<=e||M.current!==S.mtimeMs&&(M.current=S.mtimeMs,C())},[S,N,C]);let[E,P]=(0,s.useState)([]),[$,T]=(0,s.useState)(!1),[R,B]=(0,s.useState)(null),F=(0,s.useRef)(0),I=(0,s.useRef)(0),[D,A]=(0,s.useState)(()=>new Set),W="ready"===N.state?N.data.filePath:null;(0,s.useEffect)(()=>{A(new Set)},[W]);let z=(0,s.useCallback)(e=>{A(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),T(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let _=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;F.current+=1,B({filePath:e,qname:"__imports__",nonce:F.current});return}let r=eB(t),n=eB(e.external);P(e=>eh(eh(e,r),n)),k(n.filePath),F.current+=1,B({filePath:n.filePath,qname:n.qname,nonce:F.current})},[]),H=(0,s.useCallback)(e=>{k(e.filePath),F.current+=1,B({filePath:e.filePath,qname:e.qname,nonce:F.current})},[]),O=(0,s.useCallback)(e=>{T(!1),k(e.target.filePath),"symbol"===e.target.kind&&(F.current+=1,B({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.line,nonce:F.current}))},[]),q=(0,s.useCallback)((e,t)=>{y&&(F.current+=1,B({filePath:y,qname:e,line:t,nonce:F.current}))},[y]),[V,K]=(0,s.useState)(null),[U,J]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!V)return;let e=null,t=()=>{e=null;let t=V.getBoundingClientRect();if(t.height<=0)return;let r=V.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let a=Number(r),l=Number(o);if(!Number.isFinite(a)||!Number.isFinite(l))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=l-a+1,x=Math.floor(c/i.height*u),m=Math.ceil(d/i.height*u)-1,h=a+Math.max(0,x),f=a+Math.min(u-1,Math.max(0,m));h<n&&(n=h),f>s&&(s=f)}),n===1/0||s===-1/0?J(null):J(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),V.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(V);let s=new MutationObserver(r);return s.observe(V,{childList:!0,subtree:!0}),()=>{V.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[V]);let Q=(0,s.useMemo)(()=>{if("ready"!==N.state||!U)return null;let e=N.data.functions;if(0===e.length)return null;let t=(U.start+U.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=U.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[N,U]),Z=l&&!!e&&!!y,Y=(0,ea.r)(),{comments:G,addComment:X,updateComment:ee,deleteComment:et,refresh:er}=(0,el._)({cwd:e,filePath:y??""}),[en,es]=(0,s.useState)(null),{toolbarRef:ec,bumpRef:ed,clearToolbar:eu}=(0,eb.L)({enabled:Z,container:en,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,r=t?.closest("[data-line]");if(!r||!en||!en.contains(r))return null;let n=r.getAttribute("data-line");if(!n)return null;let s=parseInt(n,10);return Number.isFinite(s)?{start:s,end:s}:null},buildLineSnapshot:({start:e,end:t})=>{let r=S?.content;return r?r.split("\n").slice(e-1,t).join("\n"):""}}),[ex,ef]=(0,s.useState)(null),[ep,ev]=(0,s.useState)(null),[ej,ew]=(0,s.useState)(null),eL=(0,s.useCallback)(()=>{let e=ec.current;e&&(ef({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eu())},[eu,ec]),eM=(0,s.useCallback)(()=>{let e=ec.current;e&&(ev({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eu())},[eu,ec]),eE=(0,s.useCallback)(()=>{let e=ec.current;if(!e||!c)return;let t=e.selectedText.trim();eu(),t&&c(t)},[c,eu,ec]),eP=(0,s.useCallback)(async e=>{ex&&(await X(ex.range.start,ex.range.end,e,ex.selectedText),ef(null))},[ex,X]),e$=(0,s.useCallback)(async t=>{if(ep&&Y&&e&&y)try{let r=(await (0,ei.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:y,startLine:ep.range.start,endLine:ep.range.end,codeContent:ep.lineSnapshot});let n=(0,ei.Gw)(r,t);Y.sendMessage(n),await (0,ei.RP)(e),er(),ev(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[ep,Y,e,y,er]),eT=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ew({comment:e,x:t.clientX,y:t.clientY}),eu(),ef(null),ev(null)},[eu]);if((0,s.useEffect)(()=>{let e;if(!R||I.current>=R.nonce||"ready"!==N.state||!S||N.data.filePath!==R.filePath)return;if(x&&x===N.data.filePath&&u){let t=0;for(let e of N.data.functions)u.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,N.data.functions.length);if(D.size<e)return;I.current=R.nonce;let t=null,r=requestAnimationFrame(()=>{let e=R.qname.indexOf(">"),r=e>=0?R.qname.slice(0,e):R.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof R.line){let e=n.querySelector(`[data-line="${R.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[R,N,S,D,u,x]),!y)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(ez,{focalFile:null,fileCount:null,onSwitchToCode:a,onSearch:()=>T(!0),onRefresh:C,refreshDisabled:!0,extraLeft:b,extraRight:v}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:j("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:j("blockViewer.empty.hint","or press ⌘K to search.")})]}),$&&(0,n.jsx)(eI,{cwd:e,onSelect:O,onClose:()=>T(!1)})]});if("idle"===N.state||"loading"===N.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(ez,{focalFile:y,fileCount:null,onSwitchToCode:a,onSearch:()=>T(!0),onRefresh:C,refreshDisabled:!0,extraLeft:b,extraRight:v}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:j("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===N.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(ez,{focalFile:y,fileCount:null,onSwitchToCode:a,onSearch:()=>T(!0),onRefresh:C,extraLeft:b,extraRight:v}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:j("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),$&&(0,n.jsx)(eI,{cwd:e,onSelect:O,onClose:()=>T(!1)})]});if("error"===N.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(ez,{focalFile:y,fileCount:null,onSwitchToCode:a,onSearch:()=>T(!0),onRefresh:C,extraLeft:b,extraRight:v}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:N.message}),(0,n.jsx)("button",{onClick:C,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:j("blockViewer.retry","Retry")})]})]});let eR=N.data,eD=eR.functions;if(0===eD.length&&S){let e=Math.max(1,S.content.split("\n").length);eD=[{filePath:eR.filePath,qualifiedName:"__file__",name:eS(eR.filePath),kind:"unknown",startLine:1,endLine:e}]}let e_=x&&x===eR.filePath,eH=f&&f===eR.filePath,eO=g&&g===eR.filePath;e_&&u&&(eD=eD.filter(e=>u.has(e.qualifiedName)));let eq=eH?h:void 0,eV=eO?p:void 0,eK=eW(eR.upstreamCalls),eU=eW(eR.downstreamCalls),eJ=new Map(eD.map(e=>[e.qualifiedName,e])),eQ=new Map,eZ=new Map;for(let e of eR.intraCalls){let t=eJ.get(e.to),r=eJ.get(e.from);if(t){let r=eQ.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eQ.set(e.from,[n])}if(r){let t=eZ.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):eZ.set(e.to,[n])}}let eY=new Map;for(let e of eR.externalCalls??[]){let t=eY.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eY.set(e.focalQname,[r])}let eG=new Map;for(let e of eR.methodCalls??[]){let t=eG.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):eG.set(e.focalQname,[r])}let eX=r.has(eR.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(ez,{focalFile:y,fileCount:eR.fileCount,functionCount:eR.functions.length,upstreamCount:eR.upstreamCalls.length,downstreamCount:eR.downstreamCalls.length,onSwitchToCode:a,onSearch:()=>T(!0),onRefresh:C,extraLeft:b,extraRight:v}),(0,n.jsxs)("div",{ref:es,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)(eg,{functions:eD,currentQname:Q,onSelect:q,notIndexed:eR.notIndexed,onRebuild:C}),(0,n.jsx)("div",{ref:K,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eD.map(e=>{let t,r,s,o,a,l;return(0,n.jsx)(eF,{symbol:e,fileSource:S?.content??null,hasChange:eX,upstream:(t=eK.get(e.qualifiedName),r=eZ.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eU.get(e.qualifiedName),o=eQ.get(e.qualifiedName),a=eG.get(e.qualifiedName),l=eY.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...a??[],...l??[]]),onPinClick:_,onHighlighted:z,comments:Z?G:void 0,onCommentClick:Z?eT:void 0,accentQnames:eq,addedLines:eV},e.qualifiedName)})})}),Z&&en&&(0,n.jsx)(ey.f,{floatingToolbarRef:ec,bumpRef:ed,container:en,onAddComment:eL,onSendToAI:eM,onSearch:c?eE:void 0,isChatLoading:Y?.isLoading}),Z&&ex&&(0,n.jsx)(eN.t,{x:ex.x,y:ex.y,range:ex.range,lineSnapshot:ex.lineSnapshot,container:en,onSubmit:eP,onClose:()=>ef(null)}),Z&&ep&&y&&(0,n.jsx)(eN.G,{x:ep.x,y:ep.y,range:ep.range,filePath:y,lineSnapshot:ep.lineSnapshot,container:en,onSubmit:e$,onClose:()=>ev(null),isChatLoading:Y?.isLoading}),Z&&ej&&(0,n.jsx)(eC.t,{x:ej.x,y:ej.y,comment:ej.comment,container:en,onClose:()=>ew(null),onUpdateComment:ee,onDeleteComment:et}),eV&&eV.size>0&&eD.length>0&&(0,n.jsx)(ek,{addedLines:eV,blockRanges:eD.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:U,onJumpToLine:q}),(0,n.jsx)(em,{entries:E,onSelect:H,onClear:()=>P([])}),$&&(0,n.jsx)(eI,{cwd:e,onSelect:O,onClose:()=>T(!1)})]})]})}function eW(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function ez({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:a,onSwitchToCode:l,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:x}){let{t:m}=(0,o.Bd)(),h={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:a??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof a&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",a," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(h)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[x&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:x(h)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":m("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(O.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":m("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(K.A,{className:"w-3 h-3"})}),l&&(0,n.jsx)("button",{onClick:l,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}var e_=r(22576);function eH(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function eO(e){return e.replace(/\s+/g," ").trim()}function eq(e,t){return e?`${e}>${t}`:t}function eV(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function eK(e,t,r,n,s=[],o){return{qualifiedName:eq(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:eH(eO(e.text)),children:s,params:o}}function eU(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}function eJ(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";default:return null}}var eQ=r(14066);let eZ="/tree-sitter",eY=null,eG=new Map;async function eX(e){let t,r=await (!(t=eG.get(e))&&(t=(async()=>(await (!eY&&(eY=eQ.iX.init({locateFile:e=>`${eZ}/${e}`})),eY),eQ.TM.load(`${eZ}/tree-sitter-${e}.wasm`)))(),eG.set(e,t)),t),n=new eQ.iX;return n.setLanguage(r),n}function e0(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function e1(e){return!e0(e)&&"__file__"!==e.qualifiedName}async function e2(e,t){if(!e)return[];let r=eJ(t);if(!r)return null;let n=(await eX(r)).parse(e);if(!n)return null;try{return function(e){let t=[],r=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:eH(eO(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[eK(t,eV(t),"function",r,[],eU(t))];case"class_declaration":case"abstract_class_declaration":{let e=eV(t),n=eq(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(eK(s,eV(s),"method",t,[],eU(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(eK(s,eV(s),"method",t,[],eU(e)))}}}return r}(t.childForFieldName("body"),n);return[eK(t,e,"class",r,s)]}case"interface_declaration":return[eK(t,eV(t),"interface",r)];case"type_alias_declaration":return[eK(t,eV(t),"type",r)];case"enum_declaration":return[eK(t,eV(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),a=s.childForFieldName("value");if(!o)continue;let l=o.text,i=a&&("arrow_function"===a.type||"function_expression"===a.type),c=i&&a?eU(a):void 0;if(r.push(eK(e,l,i?"function":"const",t,[],c)),a&&"object"===a.type&&!i){let e=t?`${t}>${l}`:l;for(let t=0;t<a.namedChildCount;t++){let n=a.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(eK(n,t.text,"method",e,[],eU(s)))}else if("method_definition"===n.type){let t=eV(n);t&&r.push(eK(n,t,"method",e,[],eU(n)))}}}}}return r}(t,r);case"class_definition":{let e=eV(t),n=eq(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(eK(o,eV(o),"method",r,[],eU(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...eK(t,eV(t),"method",r,[],eU(t)),startLine:o.startPosition.row+1,contentHash:eH(eO(o.text))});else if(t?.type==="class_definition"){let s=eV(t),a=eq(r,s),l=e(t.childForFieldName("body"),a);n.push({...eK(t,s,"class",r,l),startLine:o.startPosition.row+1,contentHash:eH(eO(o.text))})}}else if("class_definition"===o.type){let t=eV(o),s=eq(r,t),a=e(o.childForFieldName("body"),s);n.push(eK(o,t,"class",r,a))}}}return n}(t.childForFieldName("body"),n);return[eK(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:eH(eO(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:eq(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:eH(eO(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,a=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&a.push(t)}}if(0===a.length||!o)return[];let l=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=l?`${l} ${o}`:o;return a.map((e,r)=>eK(e,a.length>1?`${i} #${r+1}`:i,"function",t,[],eU(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],a=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:eH(eO(s)),children:[]})},l=-1;for(let e=1;e<=n;e++)s[e]?l>=0&&(a(l,e-1),l=-1):l<0&&(l=e);return l>=0&&a(l,n),o}(e,t)),t}(n.rootNode)}finally{n.delete()}}async function e5(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of(0,e_.X)(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!eJ(r))return{addedLines:o};let[a,l]=await Promise.all([e2(n?"":e,r),e2(s?"":t,r)]),i=l??[],c=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}((a??[]).filter(e1),i.filter(e1)),d=new Set;for(let e of c)"deleted"!==e.changeKind&&d.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(e0(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))d.add(e);return{changedQnames:d,addedLines:o}}function e4({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:a=!1,isDeleted:l=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:x,headerExtraRight:m}){let[h,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await e3(h,t,r,o,a,l,i,c,e);if(n||!s)return;let d=await e5(s.oldContent,s.newContent,h,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[h,t,r,o,a,l,i,c,e]),(0,n.jsx)(eA,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:h,accentQnames:p?.changedQnames,accentFile:h,addedLines:p?.addedLines,addedLinesFile:h,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:x,headerExtraRight:m})}async function e3(e,t,r,n,s,o,a,l,c){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!a.has(e))return null;let d=l?.get(e);if(!d)return null;let u=new URLSearchParams({cwd:c,file:e,type:d}),x=await i.t4.runPromiseExit((0,h.oh)(u));if("Success"!==x._tag)return null;let m=x.value;return{oldContent:m.oldContent,newContent:m.newContent,isNew:m.isNew??!1,isDeleted:m.isDeleted??!1}}var e6=r(50860);function e8({cwd:e,selected:t,diff:r,showMarkdownPreview:a,setShowMarkdownPreview:l,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:x,setJsonPreview:m,jsonPreviewSearch:h,jsonPreviewPreRef:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)("file"),[j,w]=(0,s.useState)("compact"),k=t.file.path,y=(0,F.u)(k),{state:N}=eo(e,k),C=(0,s.useMemo)(()=>{if("ready"===N.state)return N.data.functions.filter(ep).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[N]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[y||"map"!==b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:k}),(0,n.jsx)(ex.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${k}`),(0,E.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(ex.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(k)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?g("fileBrowser.staged"):g("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!y&&"file"===b&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["compact","full"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},className:`px-2 py-0.5 text-xs transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("compact"===e?"diffViewer.compact":"diffViewer.full")},e))}),!y&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-xs transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:y?(0,n.jsx)(e6.I,{cwd:e,path:k,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:k}):(0,n.jsx)(f.xZ,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===j,symbols:C,onPreview:!r.isDeleted&&(0,S.e$)(k)?()=>l(!0):!r.isDeleted&&k.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:k.endsWith(".json")?g("common.readable"):g("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(e4,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ex.m,{content:g("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,E.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(ex.m,{content:g("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?g("fileBrowser.staged"):g("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})}),a&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>l(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(I.M,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>l(!1)})})}),x&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>m(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:x.filePath}),(0,n.jsx)("button",{onClick:()=>m(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(L._,{search:h}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:p,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,S.xb)(x.content)})})]})})]})}function e9({branches:e,selectedBranch:t,onSelect:r,isLoading:a,pinnedBranches:l=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,x]=(0,s.useState)(""),m=(0,s.useRef)(null),h=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{m.current&&!m.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&h.current&&h.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=l.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],w=e=>{r(e),d(!1),x("")};return(0,n.jsxs)("div",{className:"relative",ref:m,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:a,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${c?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:h,type:"text",value:u,onChange:e=>x(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground placeholder-slate-9"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}var e7=r(69809);function te(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}let tt=(e,t)=>ee.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:t=>new et.uV({message:`${e} failed`,cause:t})});function tr(e){return e.replace(/^\([^)]+\)\s*/,"")}let tn=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:a,container:l,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},x){let{t:m}=(0,o.Bd)(),h=(0,s.useRef)(null);(0,s.useImperativeHandle)(x,()=>h.current,[]);let f=l.getBoundingClientRect(),p=r-f.left,g=a-f.top,b=(0,s.useMemo)(()=>tr(e),[e]),v=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,a=0,l=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=l.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},a++));let l=t[0];/^["']/.test(l)?s.push((0,n.jsx)("span",{className:"text-green-400",children:l},a++)):/^\d+$/.test(l)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:l},a++)):r.test(l)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:l},a++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:l},a++)),o=t.index+l.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},a++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!h.current)return;let e=h.current,t=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=a-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,a,l]),(0,n.jsxs)("div",{ref:h,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-xl px-3 py-2 pointer-events-none",style:{left:p,top:g},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:v}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(d||u)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:c,children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-[11px] text-brand hover:underline cursor-pointer",children:m("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=tr(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:m("hoverTooltip.search")})]})]})]})});function ts({references:e,loading:t,onSelect:r,onClose:a}){let{t:l}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,ed.kS)();if(t!==a.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let a=(0,ed.sQ)(r.file);if("text"!==a)try{let e=n.codeToTokens(r.lineText,{lang:a,theme:s}),l=(0,ed.b8)(e.tokens[0]||[]);l&&o.set(t,l)}catch{}}t===a.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[l("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(q.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.notFound")}):c.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function to({results:e,loading:t,totalMatches:r,onSelect:a,onClose:l,scope:i,onScopeChange:c,selectedPath:d}){let{t:u}=(0,o.Bd)(),x=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,ed.kS)(),o=new Map;for(let t of e){let e=(0,ed.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let a=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),l=(0,ed.b8)(t.tokens[0]||[]);l&&o.set(a,l)}catch{}}}t===a.current&&r(o)})()},[e,n]),t}(e),m="selected"===i?e.filter(e=>e.path===d):e,h=m.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground truncate",children:[u("searchResults.title")," ",!t&&u("searchResults.nMatches",{count:"selected"===i?h:r})]}),(0,n.jsxs)("div",{className:"flex items-center rounded border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("selected"),className:`px-2 py-0.5 ${"selected"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-accent"}`,children:u("searchResults.scopeSelected")}),(0,n.jsx)("button",{onClick:()=>c("all"),className:`px-2 py-0.5 border-l border-border ${"all"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-accent"}`,children:u("searchResults.scopeAll")})]})]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground flex-shrink-0",children:(0,n.jsx)(q.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.searching")}):0===m.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.noResults")}):m.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=x.get(s);return(0,n.jsxs)("button",{onClick:()=>a(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}var ta=r(63728);function tl({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:l,searchQueryTrigger:c}){var d;let g,b,v,j,w,P,{t:$}=(0,o.Bd)(),{activeView:T,onViewChange:W}=(0,ta.R8)(),[O,q]=(0,s.useState)(r),[V,K]=(0,s.useState)("code"),U=(0,s.useRef)(null),J=(0,s.useRef)(!1),[Q,Z]=(0,s.useState)(null),[Y,G]=(0,s.useState)(null),[X,er]=(0,s.useState)(!1),en=(0,s.useRef)(1),es=(0,s.useRef)(null),[eo,ea]=(0,s.useState)(null),el=(0,s.useRef)(null),[ei,ec]=(0,s.useState)({isDirty:!1,isSaving:!1}),[ed,eu]=(0,s.useState)(!1),[ex,em]=(0,s.useState)(!1),[eh,ef]=(0,s.useState)(null),ep=(0,s.useRef)(null),eg=(0,L.o)(ep),eb=(0,s.useRef)(null),ev=(0,L.o)(eb),ej=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);let o=await i.t4.runPromiseExit(tt("/api/lsp/definition",{cwd:e,filePath:t,line:n,column:s}));return(r(!1),"Success"===o._tag)?o.value.definitions??[]:(console.error("[useLSP] definition error:",o.cause),[])},[e]),loading:t}}(t),ew=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),a=(0,s.useRef)(0),l=(0,s.useRef)(!1),c=(0,s.useRef)(null),d=(0,s.useRef)({x:0,y:0}),u=(0,s.useCallback)(e=>{c.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{d.current.x=e.clientX,d.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let x=(0,s.useRef)(!1),m=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=c.current;e&&x.current&&(e.style.pointerEvents="none"),x.current=!1,m.current&&(c.current?.removeEventListener("mouseleave",m.current),m.current=null)},[]),f=(0,s.useCallback)(()=>{let e=c.current;if(!e||x.current)return;x.current=!0,l.current=!0,e.style.pointerEvents="auto";let t=()=>{l.current=!1,h(),a.current++,r(null)};m.current=t,e.addEventListener("mouseleave",t)},[h]),p=(0,s.useCallback)((t,s,l,c)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let d=++a.current;n.current=setTimeout(async()=>{let n=await i.t4.runPromiseExit(tt("/api/lsp/hover",{cwd:e,filePath:t,line:s,column:l}));if(d!==a.current||"Success"!==n._tag)return;let o=n.value.hover;o&&o.displayString&&r({...o,x:c.x,y:c.y,filePath:t,line:s,column:l})},300)},[e]),g=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),a.current++,o.current=setTimeout(function(){if(l.current)return;let e=c.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=d.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void f()}r(null)},150)},[f]),b=(0,s.useCallback)(()=>{l.current=!0,o.current&&clearTimeout(o.current)},[]),v=(0,s.useCallback)(()=>{l.current=!1,a.current++,r(null)},[]),j=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),l.current=!1,h(),a.current++,r(null)},[h]);return(0,s.useEffect)(()=>{t||h()},[t,h]),{hoverInfo:t,onTokenMouseEnter:p,onTokenMouseLeave:g,onCardMouseEnter:b,onCardMouseLeave:v,clearHover:j,setTooltipEl:u}}(t),ek=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1);return{references:t,loading:n,visible:a,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),l(!0);let a=await i.t4.runPromiseExit(tt("/api/lsp/references",{cwd:e,filePath:t,line:n,column:s}));"Success"===a._tag?r(a.value.references??[]):(console.error("[useLSP] references error:",a.cause),r([])),o(!1)},[e]),closeReferences:(0,s.useCallback)(()=>{l(!1),r([])},[])}}(t),ey=(g=(0,s.useRef)([]),b=(0,s.useRef)([]),v=(0,s.useCallback)(e=>{g.current.push(e),g.current.length>50&&(g.current=g.current.slice(-50)),b.current=[]},[]),j=(0,s.useCallback)(e=>{if(0===g.current.length)return null;let t=g.current.pop();return b.current.push(e),b.current.length>50&&(b.current=b.current.slice(-50)),t},[]),w=(0,s.useCallback)(e=>{if(0===b.current.length)return null;let t=b.current.pop();return g.current.push(e),g.current.length>50&&(g.current=g.current.slice(-50)),t},[]),{push:v,goBack:j,goForward:w,canGoBack:(0,s.useCallback)(()=>g.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>b.current.length>0,[])}),eN=(0,H.F)(),eC=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(new Set),[c,d]=(0,s.useState)([]),[u,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,L]=(0,s.useState)(!1),[M,E]=(0,s.useState)(!1),[P,$]=(0,s.useState)(null),T=(0,s.useRef)(null),[R,B]=(0,s.useState)(!1),[I,D]=(0,s.useState)(null),[A,W]=(0,s.useState)("center"),[z,_]=(0,s.useState)(null),[H,O]=(0,s.useState)(null),[q,V]=(0,s.useState)(!1),[K,U]=(0,s.useState)([]),[J,Q]=(0,s.useState)(!1),[Z,Y]=(0,s.useState)(null),[G,X]=(0,s.useState)(null),[et,er]=(0,s.useState)(!0),[en,es]=(0,s.useState)(!1),eo=(0,s.useMemo)(()=>c.map(e=>e.path).filter(Boolean),[c]),ea=(0,s.useMemo)(()=>(0,F.v3)(eo),[eo]),el=(0,s.useMemo)(()=>new Set((0,F.tW)(ea)),[ea]),ei=(0,s.useMemo)(()=>j?n?(0,F.KH)(n,j,k):(0,F.q3)(t,j,k):null,[t,n,j,k]);(0,s.useEffect)(()=>{if(!ei||0===ei.size)return void v(null);let e=new Set;if(n){let t=new Set(n);for(let r of ei)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&ei.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}v(e)},[ei,t,n]);let ec=b??p,ed=(0,s.useRef)(null),eu=(0,s.useCallback)(t=>{ed.current&&clearTimeout(ed.current),ed.current=setTimeout(()=>{i.t4.runFork((0,m.Ft)(e,Array.from(t)).pipe(ee.tapError(e=>ee.sync(()=>console.error("Error saving expanded paths:",e))),ee.orElse(()=>ee.void)))},500)},[e]),ex=(0,s.useCallback)(async()=>{L(!0),$(null),await i.t4.runPromise((0,m.mP)(e).pipe(ee.match({onSuccess:e=>{e.error?$(e.error):(r(e.files??[]),e.expandedPaths&&Array.isArray(e.expandedPaths)&&g(new Set(e.expandedPaths)))},onFailure:e=>{console.error("Error loading files:",e),$("Failed to load files")}}))),L(!1)},[e]),em=(0,s.useCallback)(()=>{i.t4.runPromise((0,m.DZ)(e).pipe(ee.match({onSuccess:e=>{e.paths&&o(e.paths)},onFailure:e=>{console.error("Error loading file index:",e)}})))},[e]),eh=(0,s.useCallback)(async t=>{l(e=>new Set([...e,t])),await i.t4.runPromise((0,m.gZ)(e,t).pipe(ee.match({onSuccess:e=>{e.children&&r(r=>{if(!t){let t=new Map(r.map(e=>[e.path,e]));return e.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let n=structuredClone(r),s=(0,F.MB)(n,t);return s&&(s.children=e.children),n})},onFailure:e=>{console.error("Error loading directory:",e)}}))),l(e=>{let r=new Set(e);return r.delete(t),r})},[e]),ef=(0,s.useRef)(a);ef.current=a,(0,s.useEffect)(()=>{for(let e of b??p){let r=(0,F.MB)(t,e);r&&r.isDirectory&&!r.children&&!ef.current.has(e)&&eh(e)}},[t,p,b,eh]);let ep=(0,s.useCallback)(async()=>{await i.t4.runPromise((0,m.r9)(e).pipe(ee.match({onSuccess:e=>d(e.files??[]),onFailure:e=>console.error("Error loading recent files:",e)})))},[e]),eg=(0,s.useCallback)(async t=>{d(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)}),await i.t4.runPromise((0,m.YW)(e,t).pipe(ee.tapError(e=>ee.sync(()=>console.error("Error adding to recent files:",e))),ee.orElse(()=>ee.void)))},[e]),eb=(0,s.useCallback)((t,r,n,s)=>{d(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),i.t4.runFork((0,m.YW)(e,t,{scrollLine:r,cursorLine:n,cursorCol:s}).pipe(ee.orElse(()=>ee.void)))},[e]),ev=(0,s.useCallback)(e=>c.find(t=>t.path===e),[c]),ej=(0,s.useCallback)(async t=>{let r=t||u;r&&(Q(!0),Y(null),await i.t4.runPromise((0,m.eE)(e,r).pipe(ee.match({onSuccess:e=>{e.error?Y(e.error):U(e.blame??[])},onFailure:e=>{console.error("Error loading blame:",e),Y("Failed to load blame info")}}))),Q(!1))},[e,u]),ew=(0,s.useCallback)(async t=>{E(!0),f(null),V(!1),U([]),Y(null),X(null);let r=ee.gen(function*(){let r=yield*(0,m.r6)(e,t);if(!r.ok)return{type:"error",message:r.data?.error||"Failed to stat file"};let n=r.data??{};if(!n.exists)return{type:"error",message:"File not found"};if("dir"===n.kind)return{type:"error",message:"Path is a directory"};switch(n.category){case"image":return{type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"binary":return{type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};case"too-large":return{type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs};default:{let r=yield*(0,m.K9)(e,t);if(409===r.status)return{type:"binary",message:r.data?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};if(!r.ok)return{type:"error",message:r.data?.error||"Failed to load file"};let s=r.data??{};return{type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}}}}});await i.t4.runPromise(r.pipe(ee.match({onSuccess:e=>f(e),onFailure:e=>{console.error("Error loading file content:",e),f({type:"error",message:"Failed to load file"})}}))),eg(t),ej(t),E(!1)},[e,eg,ej]),ek=(0,s.useCallback)(()=>{q?V(!1):(V(!0),0===K.length&&ej())},[q,K.length,ej]),ey=(0,s.useCallback)((e,t)=>{if(!e)return;if(x(e),D(t??null),null==t){let t=c.find(t=>t.path===e);t?.scrollLine?(D(t.scrollLine),W("start"),_(t.cursorLine??null),O(t.cursorCol??null)):(W("center"),_(null),O(null))}else W("center"),_(null),O(null);ew(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));g(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&eu(r),n?r:t})}},[ew,eu,c]),eN=(0,s.useCallback)(e=>{if(b)v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!p.has(e);if(g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),eu(r),r}),r){let r=(0,F.MB)(t,e);r&&r.isDirectory&&!r.children&&eh(e)}}},[b,eu,p,t,eh]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:a,expandedPaths:p,setExpandedPaths:g,searchTreeExpandedPaths:b,setSearchTreeExpandedPaths:v,effectiveExpandedPaths:ec,searchQuery:j,setSearchQuery:w,searchExactMatch:k,setSearchDirExact:y,matchedPaths:ei,creatingItem:N,setCreatingItem:C,isLoadingFiles:S,fileError:P,searchInputRef:T,shouldScrollToSelected:R,setShouldScrollToSelected:B,targetLineNumber:I,setTargetLineNumber:D,targetScrollAlign:A,setTargetScrollAlign:W,initialCursorLine:z,initialCursorCol:H,setInitialCursorLine:_,setInitialCursorCol:O,selectedPath:u,setSelectedPath:x,fileContent:h,setFileContent:f,isLoadingContent:M,recentFiles:c,recentFilePaths:eo,setRecentFiles:d,recentFilesTree:ea,recentTreeDirPaths:el,showBlame:q,setShowBlame:V,blameLines:K,isLoadingBlame:J,blameError:Z,blameSelectedCommit:G,setBlameSelectedCommit:X,previewMarkdown:et,setPreviewMarkdown:er,showEditor:en,setShowEditor:es,saveExpandedPaths:eu,loadFiles:ex,loadFileIndex:em,loadDirectory:eh,loadRecentFiles:ep,addToRecentFiles:eg,updateRecentFilePosition:eb,getRecentFilePosition:ev,loadFileContent:ew,loadBlame:ej,handleToggleBlame:ek,handleSelectFile:ey,handleToggle:eN}}({cwd:t});d=eC.selectedPath,P=(0,s.useRef)(null),(0,s.useEffect)(()=>{d&&d!==P.current&&te(d)&&(P.current=d,i.t4.runFork(tt("/api/lsp/warmup",{cwd:t,filePath:d}).pipe(ee.asVoid).pipe(ee.orElse(()=>ee.void))))},[t,d]);let eS=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[l,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[x,m]=(0,s.useState)(new Set),[h,f]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[p,g]=(0,s.useState)(null),b=(0,s.useRef)(null),v=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){a([]),g(null);return}if(n.length<2)return void u(e7.A.t("fileBrowser.searchMinChars"));c(!0),u(null);let s=new URLSearchParams({cwd:e,q:r,caseSensitive:String(h.caseSensitive),wholeWord:String(h.wholeWord),regex:String(h.regex),fileType:h.fileType}),o=ee.tryPromise({try:async()=>{let e=await fetch(`/api/files/search?${s}`),t=await e.json();if(t.error)throw Error(t.error);return t},catch:e=>new et.uV({message:"content search failed",cause:e})});await i.t4.runPromise(o.pipe(ee.match({onSuccess:e=>{a(e.results),g({totalFiles:e.totalFiles,totalMatches:e.totalMatches,truncated:e.truncated}),m(new Set(e.results.map(e=>e.path))),e.results.length>0&&t?.()},onFailure:e=>{u(e.cause instanceof Error?e.cause.message:"Search failed"),a([])}}))),c(!1)},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:l,searchError:d,searchExpandedPaths:x,searchOptions:h,setSearchOptions:f,searchStats:p,contentSearchInputRef:b,performContentSearch:v,handleSearchToggle:(0,s.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>eu(!0)}),eL=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(!1),[l,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(null),[x,m]=(0,s.useState)(null),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(new Set),[w,k]=(0,s.useState)([]),[C,S]=(0,s.useState)([]),L=(0,s.useMemo)(()=>{let e=new Set(N(w));for(let t of g)e.delete(t);return e},[w,g]),M=(0,s.useMemo)(()=>{let e=new Set(N(C));for(let t of v)e.delete(t);return e},[C,v]),[P,$]=(0,s.useState)(!1),[T,R]=(0,s.useState)(0),B=(0,s.useCallback)(async()=>{a(!0),c(null),await i.t4.runPromise((0,h.lv)(e).pipe(ee.match({onSuccess:e=>{n(e);let t=y(e.staged),r=y(e.unstaged);k(t),S(r)},onFailure:e=>{c(e.cause instanceof Error?e.cause.message:"Unknown error")}}))),a(!1)},[e]),F=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,s.useCallback)(e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),D=(0,s.useCallback)((e,r)=>{u({file:e,type:r}),t(e.path)},[t]),A=(0,s.useCallback)(async(e,t,r,n)=>{let s=await i.t4.runPromiseExit(e);"Success"===s._tag?(await B(),(0,E.oR)(t,"success")):(console.error(r,s.cause),(0,E.oR)(n,"error"))},[B]),W=(0,s.useCallback)(t=>A((0,h.Iz)(e,[t]),e7.A.t("toast.staged"),"Error staging file:",e7.A.t("toast.stageFailed")),[e,A]),z=(0,s.useCallback)(t=>A((0,h.X0)(e,[t]),e7.A.t("toast.unstaged"),"Error unstaging file:",e7.A.t("toast.unstageFailed")),[e,A]),_=(0,s.useCallback)(async t=>{0!==t.length&&await A((0,h.Iz)(e,t),e7.A.t("toast.stagedNFiles",{count:t.length}),"Error staging files:",e7.A.t("toast.stageFailed"))},[e,A]),H=(0,s.useCallback)(async t=>{0!==t.length&&await A((0,h.X0)(e,t),e7.A.t("toast.unstagedNFiles",{count:t.length}),"Error unstaging files:",e7.A.t("toast.unstageFailed"))},[e,A]),O=(0,s.useCallback)(async t=>{if(0===t.length)return;let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path),s=ee.gen(function*(){r.length>0&&(yield*(0,h.Ub)(e,r,!0)),n.length>0&&(yield*(0,h.Ub)(e,n,!1))});await A(s,e7.A.t("toast.discardedNFiles",{count:t.length}),"Error discarding files:",e7.A.t("toast.discardFailed"))},[e,A]),q=(0,s.useCallback)(async()=>{r?.unstaged.length&&await A((0,h.Iz)(e,r.unstaged.map(e=>e.path)),e7.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"Error staging all files:",e7.A.t("toast.stageFailed"))},[e,r,A]),V=(0,s.useCallback)(async()=>{r?.staged.length&&await A((0,h.X0)(e,r.staged.map(e=>e.path)),e7.A.t("toast.unstagedNFiles",{count:r.staged.length}),"Error unstaging all files:",e7.A.t("toast.unstageFailed"))},[e,r,A]),K=(0,s.useCallback)(async t=>{let r="untracked"===t.status;await A((0,h.Ub)(e,[t.path],r),r?e7.A.t("toast.deletedFile"):e7.A.t("toast.discardedChanges"),"Error discarding file:",e7.A.t("toast.discardFailed"))},[e,A]),U=(0,s.useCallback)(async()=>{if(!r?.unstaged.length||!await (0,E.lJ)(e7.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))return;let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path),s=r.unstaged.length,o=ee.gen(function*(){n.length>0&&(yield*(0,h.Ub)(e,n,!1)),t.length>0&&(yield*(0,h.Ub)(e,t,!0))});await A(o,e7.A.t("toast.discardedNFiles",{count:s}),"Error discarding all:",e7.A.t("toast.discardFailed"))},[e,r,A]);return(0,s.useEffect)(()=>{d?(p(!0),i.t4.runPromiseExit((0,h.w2)(e,d.file.path,d.type)).then(e=>{"Success"===e._tag?m(e.value):console.error("Error fetching diff:",e.cause),p(!1)})):m(null)},[d,e,T]),{status:r,setStatus:n,statusLoading:o,statusError:l,statusSelectedFile:d,statusDiff:x,statusDiffLoading:f,stagedExpandedPaths:L,unstagedExpandedPaths:M,stagedTree:w,setStagedTree:k,unstagedTree:C,setUnstagedTree:S,showStatusDiffPreview:P,setShowStatusDiffPreview:$,fetchStatus:B,handleStagedToggle:F,handleUnstagedToggle:I,handleStatusFileSelect:D,handleStage:W,handleUnstage:z,handleStageFiles:_,handleUnstageFiles:H,handleDiscardFiles:O,handleStageAll:q,handleUnstageAll:V,handleDiscardFile:K,handleDiscardAll:U,refreshDiff:(0,s.useCallback)(()=>R(e=>e+1),[])}}({cwd:t,addToRecentFiles:eC.addToRecentFiles}),eM=(0,s.useMemo)(()=>{let e=new Set;if(eL.status){for(let t of eL.status.staged)e.add(t.path);for(let t of eL.status.unstaged)e.add(t.path)}return e},[eL.status]),eE=(0,s.useMemo)(()=>{let e=new Map;if(eL.status){for(let t of eL.status.staged)e.set(t.path,"staged");for(let t of eL.status.unstaged)e.set(t.path,"unstaged")}return e},[eL.status]),eP=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(""),[l,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[x,m]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!1),[E,P]=(0,s.useState)(!1),[$,T]=(0,s.useState)(!0),[R,B]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[A,W]=(0,s.useState)(null),z=(0,s.useRef)(null),[_,H]=(0,s.useState)(null),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)(""),[U,J]=(0,s.useState)(""),[Q,Z]=(0,s.useState)([]),[Y,G]=(0,s.useState)([]),[X,et]=(0,s.useState)(new Set),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(null),[ea,el]=(0,s.useState)(!1),[ei,ec]=(0,s.useState)(!1),ed=(0,s.useCallback)(()=>{S(!0),W(null),i.t4.runPromise((0,h.r4)(e).pipe(ee.match({onSuccess:e=>{e.local&&e.current?(n(e),a(e.current),e.upstream&&K(e.upstream)):(W(e7.A.t("git.cannotGetBranches")),n(null))},onFailure:e=>{console.error(e),"NotFoundError"===e._tag?W(e7.A.t("git.notGitRepo")):W(e7.A.t("git.getBranchesFailed")),n(null)}}))).finally(()=>S(!1))},[e]),eu=(0,s.useCallback)(t=>{M(!0),u(null),m([]),p([]),j(null),k(null),T(!0),i.t4.runPromise((0,h.Bj)(e,t,F.B_).pipe(ee.match({onSuccess:e=>{let t=e.commits||[];c(t),T(t.length>=F.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>M(!1))},[e]),ex=(0,s.useCallback)(()=>{if(E||!$||!o)return;P(!0);let t=l.length;i.t4.runPromise((0,h.Bj)(e,o,F.B_,t).pipe(ee.match({onSuccess:e=>{let t=e.commits||[];t.length>0&&c(e=>[...e,...t]),T(t.length>=F.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>P(!1))},[e,o,l.length,E,$]),em=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ex()},[ex]),eh=(0,s.useCallback)(t=>{u(t),j(null),k(null),B(!0),i.t4.runPromise((0,h.Zi)(e,t.hash).pipe(ee.match({onSuccess:e=>{let t=e.files||[];m(t);let r=y(t);p(r),b(new Set(N(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>B(!1))},[e]),ef=(0,s.useCallback)(r=>{d&&(j(r),t(r.path),D(!0),i.t4.runPromise((0,h.Zi)(e,d.hash,r.path).pipe(ee.match({onSuccess:e=>k(e),onFailure:e=>{console.error(e)}}))).finally(()=>D(!1)))},[e,d,t]),ep=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eg=(0,s.useCallback)(t=>{el(!0),en(null),eo(null),i.t4.runPromise((0,h.yy)(e,t).pipe(ee.match({onSuccess:e=>{let t=e.files||[];Z(t);let r=y(t);G(r),et(new Set(N(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>el(!1))},[e]),eb=(0,s.useCallback)(r=>{en(r),t(r.path),ec(!0),i.t4.runPromise((0,h.yy)(e,U,r.path).pipe(ee.match({onSuccess:e=>eo(e),onFailure:e=>{console.error(e)}}))).finally(()=>ec(!1))},[e,U,t]),ev=(0,s.useCallback)(e=>{et(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ej=(0,s.useCallback)(e=>{if(q(e),e){let e="origin/main";J(e),eg(e)}else Z([]),G([]),en(null),eo(null),J("")},[V,eg]);return{branches:r,selectedBranch:o,setSelectedBranch:a,commits:l,setCommits:c,selectedCommit:d,setSelectedCommit:u,historyFiles:x,historyFileTree:f,historyExpandedPaths:g,historySelectedFile:v,historyFileDiff:w,isLoadingBranches:C,isLoadingCommits:L,isLoadingMore:E,hasMoreCommits:$,setHasMoreCommits:T,isLoadingHistoryFiles:R,isLoadingHistoryDiff:I,historyError:A,commitListRef:z,tooltipPos:_,loadBranches:ed,loadCommits:eu,loadMoreCommits:ex,handleCommitListScroll:em,handleSelectCommit:eh,handleSelectHistoryFile:ef,handleHistoryToggle:ep,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{H({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{H(null)},[]),compareMode:O,toggleCompareMode:ej,compareBaseBranch:U,setCompareBaseBranch:J,upstreamBranch:V,compareFiles:Q,compareFileTree:Y,compareExpandedPaths:X,compareSelectedFile:er,compareFileDiff:es,isLoadingCompareFiles:ea,isLoadingCompareDiff:ei,handleSelectCompareFile:eb,handleCompareToggle:ev,loadCompareFiles:eg}}({cwd:t,addToRecentFiles:eC.addToRecentFiles}),e$=(0,s.useRef)(!1),eT=(0,s.useCallback)(e=>{eC.setFileContent(t=>t?.type==="text"?{...t,content:e}:t),eC.showEditor||(e$.current=!0,eC.setShowEditor(!0))},[eC]);(0,s.useEffect)(()=>{eC.showEditor&&e$.current&&(el.current?.markDirty(),e$.current=!1)},[eC.showEditor]);let eR=(0,s.useCallback)(e=>{eC.setShowEditor(!0)},[eC]),eB=(0,s.useCallback)(async()=>{if(!eC.fileContent||"text"!==eC.fileContent.type||!eC.fileContent.content)return;let e=await i.t4.runPromiseExit((0,m.OJ)({cwd:t,path:eC.selectedPath,content:eC.fileContent.content}));try{if("Failure"===e._tag||!e.value.ok)throw Error("Failed to save file");let t=e.value.data?.mtime;t&&eC.setFileContent(e=>e?.type==="text"?{...e,mtime:t}:e),(0,E.oR)($("toast.savedSuccess"),"success")}catch{(0,E.oR)($("toast.saveFailed"),"error")}},[t,eC]),eF=(0,s.useCallback)(()=>{if(!eC.selectedPath)return;let e=en.current,t=es.current;e>0&&eC.updateRecentFilePosition(eC.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[eC]),eI=(0,s.useCallback)(async(e,t)=>{let r=e!==eC.selectedPath;if(r&&eC.showEditor){if(ei.isDirty&&(!await (0,E.lJ)($("fileBrowser.saveBeforeSwitch"),{confirmText:$("fileBrowser.saveAndSwitch"),cancelText:$("common.cancel")})||(await el.current?.save(),el.current?.isDirty)))return;eC.setShowEditor(!1)}r&&eF(),eC.handleSelectFile(e,t)},[eC,eF,ei.isDirty,$]),eD=(0,s.useMemo)(()=>{let e=eS.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,F.v3)(r),s=new Set((0,F.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[eS.contentSearchResults]),[eW,ez]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{ez(eD.expandDirs)},[eD.expandDirs]);let e_=(0,s.useCallback)(e=>{ez(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eH=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eD.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eD.matchMap]),eO=ed&&eS.contentSearchResults.length>0,[eq,eV]=(0,s.useState)("selected");(0,s.useEffect)(()=>{eV("selected")},[eS.contentSearchResults]);let eK=!!eC.selectedPath&&null!==te(eC.selectedPath),eU=(0,s.useCallback)(async(e,r)=>{if(!eC.selectedPath||!eK)return;let n=await ej.goToDefinition(eC.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",a=s.file.startsWith(o)?s.file.slice(o.length):s.file;ey.push({filePath:eC.selectedPath,lineNumber:en.current}),a===eC.selectedPath?eC.setTargetLineNumber(s.line):eI(a,s.line)},[eC,t,eK,ej,ey]),eJ=(0,s.useCallback)((e,t,r)=>{eC.selectedPath&&eK&&ew.onTokenMouseEnter(eC.selectedPath,e,t,r)},[eC.selectedPath,eK,ew]),eQ=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;eC.selectedPath&&ey.push({filePath:eC.selectedPath,lineNumber:en.current}),n===eC.selectedPath?eC.setTargetLineNumber(e.line):eI(n,e.line)},[eC,t,ey]),eZ=(0,s.useMemo)(()=>{if(!eL.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":return"A";case"deleted":return"D";case"renamed":return"R";case"untracked":return"?"}};for(let r of eL.status.staged)e.set(r.path,t(r.status));for(let r of eL.status.unstaged)e.set(r.path,t(r.status));return e},[eL.status]);(0,s.useEffect)(()=>{Z(U.current)},[]),(0,s.useEffect)(()=>{q(r)},[r,a]),(0,s.useEffect)(()=>{l&&(q("search"),eS.setContentSearchQuery(l),eS.performContentSearch(l))},[c]);let eY=(0,s.useCallback)(e=>{q(e),eC.setBlameSelectedCommit(null),"history"===e&&eP.selectedBranch&&eP.loadCommits(eP.selectedBranch)},[eC,eP.selectedBranch,eP.loadCommits]),eG=(0,s.useCallback)(()=>{if(!eC.selectedPath)return;let e={filePath:eC.selectedPath,lineNumber:en.current},t=ey.goBack(e);t&&(t.filePath===eC.selectedPath?eC.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[eC,ey]),eX=(0,s.useCallback)(()=>{if(!eC.selectedPath)return;let e={filePath:eC.selectedPath,lineNumber:en.current},t=ey.goForward(e);t&&(t.filePath===eC.selectedPath?eC.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[eC,ey]),e0=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;"Success"===(await i.t4.runPromiseExit((0,m.__)({cwd:t,paths:[e],op:"copy"})))._tag?(0,E.oR)($("toast.copiedName",{name:r}),"success"):(0,E.oR)($("toast.copyFailed"),"error")},[t,$]),e1=(0,s.useCallback)(async e=>{let r=await i.t4.runPromiseExit((0,m.dt)());if("Success"!==r._tag||!r.value.path)return void(0,E.oR)($("toast.noFileToPaste"),"info");let n=r.value.path,s=await i.t4.runPromiseExit((0,m.Nn)({cwd:t,targetDir:e,sourceAbsPath:n}));if("Success"===s._tag)(0,E.oR)($("toast.pastedFile",{name:s.value.newName}),"success"),eC.loadDirectory(e),eC.loadFileIndex();else{let e="Fail"===s.cause._tag?s.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:$("toast.pasteFailed");(0,E.oR)(r,"error")}},[t,eC,$]),e2=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===T;if(t.ctrlKey&&!t.metaKey&&"Minus"===t.code){if(t.preventDefault(),!r)return;t.shiftKey?eX():eG();return}if((t.metaKey||t.ctrlKey)&&"p"===t.key&&!t.shiftKey&&!t.altKey){t.preventDefault(),r?er(e=>!e):(W("explorer"),er(!0));return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===O||"recent"===O)&&eC.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),e0(eC.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===O||"recent"===O)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),e1((0,F.S7)(eC.selectedPath,eC.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eh){t.preventDefault(),ev.open();return}if(ex&&eC.selectedPath?.endsWith(".json")){t.preventDefault(),eg.open();return}}if(r&&"Escape"===t.key){if(X)return void er(!1);if(ev.isVisible)return void ev.close();if(eg.isVisible)return void eg.close();if(eh)return void ef(null);let t=Date.now();if(t-e2.current<3e3)return;e2.current=t,ek.visible?ek.closeReferences():ed?eu(!1):eC.blameSelectedCommit?eC.setBlameSelectedCommit(null):eC.showBlame?eC.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,eC.showBlame,eC.blameSelectedCommit,eC,X,ek.visible,ek.closeReferences,ed,eG,eX,ex,eg,eh,ev,O,e0,e1,T,W]),(0,s.useEffect)(()=>{eC.loadFiles(),eC.loadFileIndex(),eC.loadRecentFiles(),eL.fetchStatus(),eP.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{eL.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[eL.fetchStatus]);let e5=(0,s.useRef)(eN);(0,s.useEffect)(()=>{eN&&!e5.current&&(eC.loadFiles(),eC.loadFileIndex(),eC.loadRecentFiles(),eL.fetchStatus(),eP.loadBranches()),e5.current=eN},[eN]),(0,s.useEffect)(()=>{eP.selectedBranch&&eP.loadCommits(eP.selectedBranch)},[eP.selectedBranch,eP.loadCommits]);let e4=(0,s.useRef)(O);(0,s.useEffect)(()=>{let e=e4.current;if(e4.current=O,("tree"===O||"recent"===O)&&eC.recentFiles.length>0){let t=eC.recentFiles[0].path;eC.selectedPath&&("status"!==e&&"history"!==e||eC.selectedPath===t)||(eC.setShouldScrollToSelected(!0),eI(t))}},[O,eC.recentFiles,eC.selectedPath,eI,eC]);let e3=(0,s.useRef)(eP.selectedBranch);e3.current=eP.selectedBranch;let tr=(0,s.useRef)(eC.selectedPath);tr.current=eC.selectedPath;let ti=(0,s.useRef)(eC.fileContent?.type);ti.current=eC.fileContent?.type;let tc=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!r)return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(i.t4.runPromise((0,m.mP)(t)).then(e=>{e.error||eC.setFiles(t=>(0,F.HR)(e.files??[],t))}).catch(()=>{})),o.push(i.t4.runPromise((0,m.DZ)(t)).then(e=>{e.paths&&eC.setFileIndex(e.paths)}).catch(()=>{})),o.push(i.t4.runPromise((0,m.r9)(t)).then(e=>{eC.setRecentFiles(e.files??[])}).catch(()=>{}))),n||s){o.push(i.t4.runPromise((0,h.lv)(t)).then(e=>{eL.setStatus(e);let t=y(e.staged),r=y(e.unstaged);eL.setStagedTree(t),eL.setUnstagedTree(r)}).catch(()=>{})),eL.refreshDiff(),n&&eP.loadBranches();let e=e3.current;e&&o.push(i.t4.runPromise((0,h.Bj)(t,e,F.B_)).then(e=>{let t=e.commits??[];eP.setCommits(t),eP.setHasMoreCommits(t.length>=F.B_)}).catch(()=>{}))}let a=tr.current,l=ti.current;a&&"text"===l&&o.push(i.t4.runPromise((0,m.K9)(t,a)).then(e=>{let t=e.ok?e.data:null;t&&"string"==typeof t.content&&eC.setFileContent({type:"text",content:t.content,size:t.size,mtime:t.mtimeMs,...t.isSymlink?{isSymlink:!0,symlinkTarget:t.symlinkTarget}:{}})}).catch(()=>{})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,_.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:tc,enabled:eN});let td=(0,s.useCallback)(e=>{eI(e),eC.setShouldScrollToSelected(!0),q("tree")},[eC,eI]),[tu,tx]=(0,s.useState)(null),tm=(0,s.useCallback)((e,t)=>{eC.setPreviewMarkdown(!0),td(e),tx(t),t&&setTimeout(()=>tx(null),400)},[eC,td]);return(0,n.jsxs)(p.SU,{container:Q,children:[(0,n.jsxs)("div",{ref:U,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"w-80 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>eY("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===O?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:$("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eY("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===O?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:$("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eY("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===O?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:$("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eY("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===O?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:$("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eY("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===O?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:$("fileBrowser.historyTab")})]}),"tree"===O&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:eC.searchInputRef,type:"text",value:eC.searchQuery,onChange:e=>eC.setSearchQuery(e.target.value),placeholder:$("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),eC.searchQuery&&(0,n.jsx)("button",{onClick:()=>eC.setSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:$("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>eC.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${eC.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:eC.searchExactMatch?$("fileBrowser.exactMatchOn"):$("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>eC.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:$("fileBrowser.refreshTree"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>eC.searchTreeExpandedPaths?eC.setSearchTreeExpandedPaths(new Set):eC.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:$("fileBrowser.collapseAll"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})]})]}),"search"===O&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:eS.contentSearchInputRef,type:"text",value:eS.contentSearchQuery,onChange:e=>eS.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eS.performContentSearch(eS.contentSearchQuery)},placeholder:$("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),eS.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>eS.setContentSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:$("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>eS.performContentSearch(eS.contentSearchQuery),disabled:eS.isSearching||!eS.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:eS.isSearching?"...":$("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eS.searchOptions.caseSensitive,onChange:e=>eS.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:$("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eS.searchOptions.wholeWord,onChange:e=>eS.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:$("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eS.searchOptions.regex,onChange:e=>eS.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:$("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:eS.searchOptions.fileType,onChange:e=>eS.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:$("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===O&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eP.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"truncate",children:eP.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eP.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:$("fileBrowser.compareModeOff"),children:$("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(e9,{branches:eP.branches,selectedBranch:eP.compareBaseBranch,onSelect:e=>{eP.setCompareBaseBranch(e),eP.loadCompareFiles(e)},isLoading:eP.isLoadingBranches,pinnedBranches:["origin/main",...eP.upstreamBranch&&"origin/main"!==eP.upstreamBranch?[eP.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(e9,{branches:eP.branches,selectedBranch:eP.selectedBranch,onSelect:e=>{eP.setSelectedBranch(e)},isLoading:eP.isLoadingBranches,pinnedBranches:["origin/main",...eP.upstreamBranch&&"origin/main"!==eP.upstreamBranch?[eP.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eP.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-accent border border-border",title:$("fileBrowser.compareModeOn"),children:$("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===O?"":"hidden"}`,children:[eC.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border bg-secondary flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:eC.creatingItem.parentPath?$("fileBrowser.createFileIn",{path:eC.creatingItem.parentPath}):$("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:$("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{J.current=!0},onCompositionEnd:()=>{J.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(J.current)return;let r=e.target.value.trim();if(!r)return;let n=eC.creatingItem.parentPath,s=n?`${n}/${r}`:r,o=await i.t4.runPromiseExit((0,m.OJ)({cwd:t,path:s,content:""}));if("Success"===o._tag&&o.value.ok)(0,E.oR)($("toast.createdFile",{name:r}),"success"),eC.setCreatingItem(null),eC.loadDirectory(n),eC.loadFileIndex(),n&&eC.setExpandedPaths(e=>new Set([...e,n])),eI(s);else if("Success"===o._tag){let e=o.value.data?.error;(0,E.oR)(e||$("toast.createFailed"),"error")}else(0,E.oR)($("toast.createFailed"),"error")}else"Escape"===e.key&&eC.setCreatingItem(null)},onBlur:()=>eC.setCreatingItem(null)})]}),eC.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:$("common.loading")}):eC.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eC.fileError}):(0,n.jsx)(R,{files:eC.files,selectedPath:eC.selectedPath,expandedPaths:eC.effectiveExpandedPaths,matchedPaths:eC.matchedPaths,gitStatusMap:eZ,loadingDirs:eC.loadingDirs,onSelect:e=>{eC.setShouldScrollToSelected(!1),eI(e)},onToggle:eC.handleToggle,cwd:t,shouldScrollToSelected:eC.shouldScrollToSelected,onScrolledToSelected:()=>eC.setShouldScrollToSelected(!1),onCreateFile:e=>eC.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>G({path:e,isDirectory:t,name:r}),onRefresh:()=>eC.loadFiles(),onCopyFile:e0,onPaste:e1})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===O?"":"hidden"}`,children:eS.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):eS.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eS.searchError}):0===eS.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:eS.contentSearchQuery?$("fileBrowser.noContentSearchResults"):$("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[eS.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-secondary border-b border-border flex-shrink-0",children:[$("fileBrowser.nFilesNMatches",{files:eS.searchStats.totalFiles,matches:eS.searchStats.totalMatches}),eS.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",$("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(R,{files:eD.files,selectedPath:eC.selectedPath,expandedPaths:eW,onSelect:e=>{let t=eD.matchMap.get(e);eI(e,t?.matches[0]?.lineNumber),ed||eu(!0)},onToggle:e_,cwd:t,renderActions:eH,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===O?"":"hidden"}`,children:0===eC.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:$("fileBrowser.noRecentFiles")}):(0,n.jsx)(R,{files:eC.recentFilesTree,selectedPath:eC.selectedPath,expandedPaths:eC.recentTreeDirPaths,onSelect:eI,onToggle:F.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===O?"":"hidden"}`,children:eL.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):eL.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:eL.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:$("fileBrowser.stagingArea",{count:eL.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>eL.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:$("fileBrowser.refreshChanges"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),(eL.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:eL.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:$("fileBrowser.unstageAll")})]}),(0,n.jsx)(k,{files:eL.stagedTree,selectedPath:eL.statusSelectedFile?.type==="staged"?eL.statusSelectedFile.file.path:null,expandedPaths:eL.stagedExpandedPaths,onSelect:e=>e.file&&eL.handleStatusFileSelect(e.file,"staged"),onToggle:eL.handleStagedToggle,cwd:t,emptyMessage:$("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=C(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eL.handleUnstageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:$("fileBrowser.unstageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),eL.handleUnstage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:$("fileBrowser.unstageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:$("fileBrowser.workspace",{count:eL.status?.unstaged.length||0})}),(eL.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:eL.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:$("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:eL.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:$("fileBrowser.stageAll")})]})]}),(0,n.jsx)(k,{files:eL.unstagedTree,selectedPath:eL.statusSelectedFile?.type==="unstaged"?eL.statusSelectedFile.file.path:null,expandedPaths:eL.unstagedExpandedPaths,onSelect:e=>e.file&&eL.handleStatusFileSelect(e.file,"unstaged"),onToggle:eL.handleUnstagedToggle,cwd:t,emptyMessage:$("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=C(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eL.handleDiscardFiles(r)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:$("fileBrowser.discardNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eL.handleStageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:$("fileBrowser.stageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})}return e.file?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),eL.handleDiscardFile(e.file)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:$("fileBrowser.discardChanges"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),eL.handleStage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:$("fileBrowser.stageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===O?"":"hidden"}`,children:eP.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-muted-foreground",children:eP.historyError})]})}):eP.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eP.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:$("fileBrowser.loadingDiff")}):0===eP.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:$("fileBrowser.noDiffFiles")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:$("fileBrowser.nFilesChanged",{count:eP.compareFiles.length,branch:eP.compareBaseBranch})})}),(0,n.jsx)(k,{files:eP.compareFileTree,expandedPaths:eP.compareExpandedPaths,onToggle:eP.handleCompareToggle,selectedPath:eP.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eP.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eP.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eP.handleCommitListScroll,children:eP.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:$("fileBrowser.loadingCommits")}):0===eP.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:$("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eP.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eP.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eP.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,F.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),eP.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!eP.hasMoreCommits&&eP.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:$("fileBrowser.allLoaded",{count:eP.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===O||"search"===O||"recent"===O)&&(eC.blameSelectedCommit?(0,n.jsx)(M,{isOpen:!0,onClose:()=>eC.setBlameSelectedCommit(null),commit:eC.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:eC.selectedPath||void 0,onContentSearch:e=>{q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)}}):"map"===V?(0,n.jsx)(eA,{cwd:t,highlightedFilePath:eC.selectedPath,changedFiles:eM,onSwitchToCode:()=>K("code"),enableComments:!0,onContentSearch:e=>{q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,E.oR)($("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:$("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),td(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:$("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]})}):eC.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:eC.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${eC.selectedPath}`),(0,E.oR)($("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:$("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),td(eC.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:$("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:eC.showEditor?(0,n.jsxs)(n.Fragment,{children:[ei.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:$("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>el.current?.save(),disabled:!ei.isDirty||ei.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ei.isDirty&&!ei.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:ei.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):$("common.save")}),(0,n.jsx)("button",{onClick:()=>el.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:$("fileBrowser.closeEdit"),children:$("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[eC.fileContent?.type==="text"&&(0,S.e$)(eC.selectedPath)&&(0,n.jsx)(A.ShareReviewToggle,{content:eC.fileContent.content||"",sourceFile:eC.selectedPath&&t&&eC.selectedPath.startsWith(t)?eC.selectedPath.slice(t.endsWith("/")?t.length:t.length+1):eC.selectedPath||""}),eC.selectedPath?.endsWith(".json")&&eC.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>em(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ex?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:$("fileBrowser.toggleJsonReadable"),children:$("common.readable")}),eC.fileContent?.type==="text"&&((0,S.e$)(eC.selectedPath)||(0,S.aR)(eC.selectedPath))&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)("button",{onClick:()=>eC.setPreviewMarkdown(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eC.previewMarkdown?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:eC.previewMarkdown?$("fileBrowser.exitPreview"):$("common.preview"),children:eC.previewMarkdown?$("fileBrowser.exitPreview"):$("common.preview")})}),eC.fileContent?.type==="text"&&!(eC.previewMarkdown&&((0,S.e$)(eC.selectedPath)||(0,S.aR)(eC.selectedPath)))&&(0,n.jsx)("button",{onClick:eC.handleToggleBlame,disabled:eC.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eC.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:$("fileBrowser.viewBlame"),children:eC.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),eC.fileContent?.type==="text"&&!(eC.previewMarkdown&&((0,S.e$)(eC.selectedPath)||(0,S.aR)(eC.selectedPath)))&&(0,n.jsx)("button",{onClick:()=>eC.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:$("fileBrowser.editFile"),children:$("common.edit")}),eC.fileContent?.type==="text"&&eC.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(eC.fileContent.content),(0,E.oR)($("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:$("fileBrowser.copyFileContent"),children:$("common.copy")}),eC.fileContent?.type==="text"&&!(0,S.e$)(eC.selectedPath)&&!(0,S.aR)(eC.selectedPath)&&(0,n.jsx)("button",{onClick:()=>K("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:$("blockViewer.viewerToggle.toBlock"),children:$("common.codeMap")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:eC.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):eC.fileContent?"text"===eC.fileContent.type&&"string"==typeof eC.fileContent.content?eC.showBlame&&eC.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:eC.blameError}),(0,n.jsx)("button",{onClick:()=>eC.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:$("fileBrowser.backToPreview")})]})}):eC.showBlame&&0===eC.blameLines.length&&eC.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ex&&eC.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(L._,{search:eg}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:ep,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,S.xb)(eC.fileContent.content)})})]}):eC.previewMarkdown&&(0,S.e$)(eC.selectedPath)&&!eC.showBlame?(0,n.jsx)("div",{className:"h-full flex flex-col",children:(0,n.jsx)(I.M,{content:eC.fileContent.content,filePath:eC.selectedPath,cwd:t,embedded:!0,onLocalMdLink:tm,scrollToAnchor:tu})}):eC.previewMarkdown&&(0,S.aR)(eC.selectedPath)&&!eC.showBlame?(0,n.jsx)(D.E,{content:eC.fileContent.content,filePath:eC.selectedPath}):(0,n.jsx)(B.Cv,{ref:el,content:eC.fileContent.content,filePath:eC.selectedPath,cwd:t,enableComments:!0,scrollToLine:eo??eC.targetLineNumber,scrollToLineAlign:null!=eo?"start":eC.targetScrollAlign,onScrollToLineComplete:()=>{ea(null),eC.setTargetLineNumber(null)},highlightKeyword:"search"===O?eS.contentSearchQuery:null,visibleLineRef:en,viStateRef:es,initialCursorLine:eC.initialCursorLine,initialCursorCol:eC.initialCursorCol,onInitialCursorSet:()=>{eC.setInitialCursorLine(null),eC.setInitialCursorCol(null)},onCmdClick:eK?eU:void 0,onTokenHover:eK?eJ:void 0,onTokenHoverLeave:eK?ew.onTokenMouseLeave:void 0,onTokenHoverCancel:eK?ew.clearHover:void 0,blameLines:eC.showBlame&&eC.blameLines.length>0?eC.blameLines:void 0,inlineBlameLines:eC.blameLines.length>0?eC.blameLines:void 0,onSelectCommit:eC.setBlameSelectedCommit,editable:eC.showEditor,initialMtime:eC.fileContent.mtime,onEditorClose:e=>{eC.setShowEditor(!1),ea(e)},onSaved:()=>{let e=en.current??1;eC.loadFileContent(eC.selectedPath),eC.setShowEditor(!1),ea(e)},onEditorStateChange:ec,viMode:!0,onContentMutate:eT,onEnterInsertMode:eR,onViSave:eB,onContentSearch:e=>{q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)}}):"image"===eC.fileContent.type&&eC.selectedPath?(0,n.jsx)(e6.I,{cwd:t,path:eC.selectedPath,refreshKey:eC.fileContent.mtime,alt:eC.selectedPath}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:eC.fileContent.message||$("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:$("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("p",{children:$("fileBrowser.selectFileToPreview")})]})})),"status"===O&&(eL.statusSelectedFile&&eL.statusDiff?(0,n.jsx)(e8,{cwd:t,selected:eL.statusSelectedFile,diff:eL.statusDiff,showMarkdownPreview:eL.showStatusDiffPreview,setShowMarkdownPreview:eL.setShowStatusDiffPreview,changedFiles:eM,fileGitStatusMap:eE,onContentSearch:e=>{q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)},locateInTree:td,jsonPreview:eh,setJsonPreview:ef,jsonPreviewSearch:ev,jsonPreviewPreRef:eb}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:$("fileBrowser.selectFileToViewDiff")})})),"history"===O&&!eP.historyError&&(eP.compareMode?eP.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:$("fileBrowser.loadingDiffContent")}):eP.compareFileDiff?(0,n.jsx)(f.xZ,{oldContent:eP.compareFileDiff.oldContent,newContent:eP.compareFileDiff.newContent,filePath:eP.compareFileDiff.filePath,isNew:eP.compareFileDiff.isNew,isDeleted:eP.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eP.compareFileDiff.isDeleted&&eP.compareFileDiff.filePath.endsWith(".json")?()=>ef({content:eP.compareFileDiff.newContent,filePath:eP.compareFileDiff.filePath}):void 0,previewLabel:$("common.readable"),onContentSearch:e=>{q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eP.compareFiles.length>0?$("fileBrowser.selectFileToViewDiff"):$("fileBrowser.clickCompareToLoad")})}):eP.selectedCommit?(0,n.jsx)(M,{isOpen:!0,onClose:()=>eP.setSelectedCommit(null),commit:eP.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:$("fileBrowser.selectCommitToView")})}))]})]}),X&&(0,n.jsx)(z,{files:eC.files,fileIndex:eC.fileIndex,recentFiles:eC.recentFilePaths,onSelectFile:e=>{eI(e),eC.setShouldScrollToSelected(!0),q("tree")},onClose:()=>er(!1)}),(eO||ek.visible)&&(0,n.jsxs)("div",{className:`flex ${ek.visible&&eO?"":"flex-col"}`,children:[eO&&(0,n.jsx)("div",{className:ek.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(to,{results:eS.contentSearchResults,loading:eS.isSearching,totalMatches:eS.searchStats?.totalMatches??0,onSelect:(e,t)=>{eC.selectedPath&&ey.push({filePath:eC.selectedPath,lineNumber:en.current}),eI(e,t)},onClose:()=>eu(!1),scope:eq,onScopeChange:eV,selectedPath:eC.selectedPath})}),ek.visible&&(0,n.jsx)("div",{className:eO?"flex-1 min-w-0":"",children:(0,n.jsx)(ts,{references:ek.references,loading:ek.loading,onSelect:eQ,onClose:ek.closeReferences})})]})]}),Y&&(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>G(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:$("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:$("fileBrowser.confirmDeleteMessage",{name:Y.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>G(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:$("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=Y;G(null);let n=await i.t4.runPromiseExit((0,m.VK)({cwd:t,path:e}));if("Success"===n._tag){(0,E.oR)($("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";eC.loadDirectory(t),eC.loadFileIndex(),eC.selectedPath===e&&eI("")}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:$("toast.deleteFailed");(0,E.oR)(r,"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:$("common.delete")})]})]})})}),ew.hoverInfo&&Q&&(0,u.createPortal)((0,n.jsx)(tn,{ref:ew.setTooltipEl,displayString:ew.hoverInfo.displayString,documentation:ew.hoverInfo.documentation,x:ew.hoverInfo.x,y:ew.hoverInfo.y,container:Q,onMouseEnter:ew.onCardMouseEnter,onMouseLeave:ew.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ew.hoverInfo;ew.clearHover(),ek.findReferences(e,t,r)},onSearch:e=>{ew.clearHover(),q("search"),eS.setContentSearchQuery(e),eS.performContentSearch(e)}}),Q)]})}function ti({isOpen:e,onClose:t,cwd:r}){let c,{t:d}=(0,o.Bd)(),[u,x]=(0,s.useState)([]),[m,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(""),[M,P]=(0,s.useState)(!1),[$,T]=(0,s.useState)([]),[R,B]=(0,s.useState)(""),[I,D]=(0,s.useState)(!1),A=(0,s.useCallback)((e,t)=>e?._tag==="Fail"&&e.error?.cause instanceof Error?e.error.cause.message:d(t),[d]),W=(0,s.useCallback)(async()=>{v(!0);let e=await i.t4.runPromiseExit((0,h.FK)(r));if("Success"===e._tag){let t=e.value;x(t.worktrees),f(t.nextPath),g(t.nextRandomWord),t.gitUserName&&L(t.gitUserName)}else console.error("Failed to load worktrees:",e.cause),(0,E.oR)(d("toast.worktreeLoadFailed"),"error");v(!1)},[r,d]),z=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(W(),y(null))},[e,W]);let _=async()=>{if(!m)return;let e="origin/main",t=await i.t4.runPromiseExit((0,h.r4)(r));"Success"===t._tag&&(e=z(t.value));let n=p||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),s=S?`${S}/${n}`:n;w(!0);let o=await i.t4.runPromiseExit((0,h.CM)({action:"add",cwd:r,path:m,newBranch:s,baseBranch:e}));"Success"===o._tag?((0,E.oR)(d("toast.worktreeCreateSuccess",{name:s}),"success"),W()):(console.error("Failed to create worktree:",o.cause),(0,E.oR)(A(o.cause,"toast.worktreeCreateFailed"),"error")),w(!1)},H=async()=>{D(!0),B(""),P(!0);let e=await i.t4.runPromiseExit((0,h.r4)(r));if("Success"===e._tag){let t=e.value,r=t.local??[],n=t.remote??[],s=new Set(u.map(e=>e.branch).filter(Boolean));T([...r.filter(e=>!s.has(e)),...n.filter(e=>!s.has(e)&&!r.includes(e.replace(/^origin\//,"")))])}else(0,E.oR)(d("toast.loadBranchFailed"),"error");D(!1)},O=async e=>{if(!m)return;P(!1),w(!0);let t=await i.t4.runPromiseExit((0,h.CM)({action:"add",cwd:r,path:m,branch:e}));"Success"===t._tag?((0,E.oR)(d("toast.worktreeCreateSuccess",{name:e}),"success"),W()):(console.error("Failed to create worktree:",t.cause),(0,E.oR)(A(t.cause,"toast.worktreeCreateFailed"),"error")),w(!1)},q=async()=>{if(!k)return;C(!0);let e=await i.t4.runPromiseExit((0,h.CM)({action:"remove",cwd:r,path:k.path}));"Success"===e._tag?((0,E.oR)(d("toast.worktreeDeleted"),"success"),y(null),W()):(console.error("Failed to delete worktree:",e.cause),(0,E.oR)(A(e.cause,"toast.worktreeDeleteFailed"),"error")),C(!1)},V=async e=>{let t=e.isLocked?"unlock":"lock",n=await i.t4.runPromiseExit((0,h.CM)({action:t,cwd:r,path:e.path}));"Success"===n._tag?((0,E.oR)(e.isLocked?d("toast.worktreeUnlocked"):d("toast.worktreeLocked"),"success"),W()):(console.error("Failed to toggle lock:",n.cause),(0,E.oR)(A(n.cause,"toast.operationFailed"),"error"))};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:d("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:b?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:u.map(e=>{let s,o=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${o?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&((0,a.F)(l.n.OpenProject,{cwd:e.path}),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${o?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:d("git.worktree.locked"),children:"\uD83D\uDD12"}),o&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",d("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),V(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?d("git.worktree.unlock"):d("git.worktree.lock"),children:e.isLocked?(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:d("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(0,n.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 pl-4",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.path}),null!=e.createdAt&&(s=(0,F.fw)(e.createdAt/1e3),(0,n.jsx)("span",{className:`text-xs flex-shrink-0 ${"just now"===s?"text-brand":"text-muted-foreground/70"}`,title:new Date(e.createdAt).toLocaleString(),children:s}))]}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),M&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:R,onChange:e=>B(e.target.value),placeholder:d("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none placeholder:text-muted-foreground",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>P(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:d("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:I?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:d("common.loading")}):0===(c=$.filter(e=>e.toLowerCase().includes(R.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:d("git.worktree.noBranches")}):c.map(e=>(0,n.jsx)("button",{onClick:()=>O(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:d("git.worktree.count",{count:u.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:H,disabled:!m||j,className:`px-3 py-1.5 text-sm rounded transition-colors ${m&&!j?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:d("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:_,disabled:!m||j,className:`px-3 py-1.5 text-sm rounded transition-colors ${m&&!j?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:j?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):d("git.worktree.addWorktree")})]})]}),k&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>y(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:d("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:d("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:d("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:k.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:d("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:k.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>y(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:d("common.cancel")}),(0,n.jsx)("button",{onClick:q,disabled:N,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:N?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):d("common.delete")})]})]})})]})}):null}var tc=r(67635),td=r(73300),tu=r(20986),tx=r(9921),tm=r(66088),th=r(42790);function tf(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}function tp({open:e,anchorRef:t,initialValue:r,onCancel:a,onSave:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(r),[x,m]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(e){d(r),m(!1);let e=requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()});return()=>cancelAnimationFrame(e)}f(null)},[e,r]);let b=(0,s.useCallback)(()=>{let e=t.current;if(!e)return;let r=e.getBoundingClientRect(),n=g.current?.offsetHeight??0,s=r.bottom+4;if(n&&s+n>window.innerHeight-8){let e=r.top-4-n;e>=8&&(s=e)}let o=r.left;f({top:s,left:o=Math.max(o=Math.min(o,window.innerWidth-260-8),8)})},[t]);if((0,s.useLayoutEffect)(()=>{if(e)return b(),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),()=>{window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}},[e,b]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&(e.preventDefault(),a())},n=e=>{let r=e.target;g.current?.contains(r)||t.current?.contains(r)||a()};return window.addEventListener("keydown",r),document.addEventListener("mousedown",n,!0),()=>{window.removeEventListener("keydown",r),document.removeEventListener("mousedown",n,!0)}},[e,a,t]),!e||"u"<typeof document)return null;let v=async()=>{if(!x){m(!0);try{await l(c.trim())}finally{m(!1)}}};return(0,u.createPortal)((0,n.jsxs)("div",{ref:g,style:{top:h?.top??0,left:h?.left??0,width:260,visibility:h?"visible":"hidden"},className:"fixed z-[100] rounded-lg border border-border bg-card p-3 shadow-xl",children:[(0,n.jsx)("div",{className:"mb-2 text-sm font-medium text-foreground",children:i("shortIdBadge.dialogTitle")}),(0,n.jsx)("input",{ref:p,type:"text",value:c,onChange:e=>d(e.target.value.slice(0,64)),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||229===e.keyCode||(e.preventDefault(),v())},placeholder:i("shortIdBadge.dialogPlaceholder"),maxLength:64,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-sm font-mono outline-none focus:border-brand"}),(0,n.jsxs)("div",{className:"mt-3 flex justify-end gap-2 text-sm",children:[(0,n.jsx)("button",{onClick:a,className:"rounded px-3 py-1 text-muted-foreground hover:bg-accent",disabled:x,children:i("common.cancel")}),(0,n.jsx)("button",{onClick:()=>void v(),className:"rounded bg-brand px-3 py-1 text-white hover:opacity-90 disabled:opacity-50",disabled:x,children:x?"…":i("common.save")})]})]}),document.body)}let tg=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:a,fullId:l,projectCwd:i,tabId:c}){let{t:d}=(0,o.Bd)(),[u,x]=(0,s.useState)(!1),[m,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),g=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!l||!i||!c)return;let e=!1,t=new URLSearchParams({cwd:i,tabId:c});return fetch(`/api/terminal/bubble-order?${t.toString()}`).then(e=>e.ok?e.json():null).then(t=>{if(e)return;let r=(t?.data?.titles??{})[l];"string"==typeof r&&h(r)}).catch(()=>{}),()=>{e=!0}},[l,i,c]),(0,_.h)({url:"/ws/global-state",enabled:!!l&&!!i&&!!c,onMessage:e=>{"console-delta"!==e.type||"rename"!==e.op||e.cwd!==i||e.tabId!==c||e.titles&&l&&Object.prototype.hasOwnProperty.call(e.titles,l)&&h(e.titles[l]??"")}});let b=(0,s.useCallback)(async n=>{if(n.stopPropagation(),u)await a(),x(!1),(0,E.oR)(d("toast.disconnected",{id:e}));else{await r(),x(!0);let n=`${"3456"===window.location.port?"cockpit-dev":"cockpit"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,E.oR)(d("toast.copiedCommand",{command:n}))}},[u,e,t,r,a,d]),v=!!(l&&i&&c),j=(0,s.useCallback)(e=>{e.stopPropagation(),v&&p(!0)},[v]),w=(0,s.useCallback)(async e=>{if(l&&i&&c)try{await fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:i,tabId:c,titles:{[l]:e}})}),h(e),p(!1)}catch{p(!1)}},[l,i,c]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:b,onDoubleClick:e=>e.stopPropagation(),className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:u?d("shortIdBadge.clickToDisconnect"):d("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${u?"bg-green-500":"bg-muted-foreground/40"}`}),e]}),v&&(m?(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground",title:d("shortIdBadge.titleSet",{title:m})||m,children:[(0,n.jsx)("span",{className:"px-1 py-0.5 rounded bg-muted/40 max-w-[120px] truncate",children:m}),(0,n.jsx)("button",{ref:g,onClick:j,className:"opacity-50 hover:opacity-100 transition-opacity","aria-label":d("shortIdBadge.editTitle"),title:d("shortIdBadge.editTitle"),children:"✎"})]}):(0,n.jsxs)("button",{ref:g,onClick:j,className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground/50 hover:text-muted-foreground italic transition-colors",title:d("shortIdBadge.setTitle"),children:["(",d("shortIdBadge.setTitlePlaceholder"),") ✎"]})),(0,n.jsx)(tp,{open:f,anchorRef:g,initialValue:m,onCancel:()=>p(!1),onSave:w})]})});var tb=r(12786);let tv=e=>ee.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new et.uV({message:`fetch ${e} failed`,cause:t})}),tj=(e,t)=>ee.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:r=>new et.uV({message:`${t.method} ${e} failed`,cause:r})}),tw=(e,t)=>tj(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),tk=(e,t)=>ee.gen(function*(){let r=new URLSearchParams({cwd:e});return t&&r.set("tabId",t),(yield*tv(`/api/terminal/env?${r}`)).env||{}}),ty=()=>tv("/api/terminal/aliases").pipe(ee.map(e=>e.aliases||{})),tN=(e,t,r,n)=>tw("/api/terminal/bubble-order",{cwd:e,tabId:t,order:r,sourceId:n}),tC=(e,t,r,n)=>tw("/api/terminal/history",{cwd:e,tabId:t,entry:r,sourceId:n}),tS=(e,t,r,n)=>tj(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&commandId=${encodeURIComponent(r)}${n?`&sourceId=${encodeURIComponent(n)}`:""}`,{method:"DELETE"}),tL=e=>tv(`/api/services/config?cwd=${encodeURIComponent(e)}`),tM=(0,s.lazy)(()=>r.e(1959).then(r.bind(r,71959)).then(e=>({default:e.XtermRenderer}))),tE={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tP=/\x1b\[[0-9;]*m/g;function t$({output:e,query:t,mode:r,currentIdx:o,matchListRef:a}){let l=(0,s.useRef)(null);l.current||(l.current=new th.v,l.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return a.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(tP,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=l.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],x=0,m=s.toLowerCase(),h=0;for(;h<m.length;){let e=m.indexOf(c,h);if(-1===e)break;e>x&&u.push((0,n.jsx)("span",{children:s.slice(x,e)},`t${x}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{a.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),h=x=e+c.length}return x<s.length&&u.push((0,n.jsx)("span",{children:s.slice(x)},`t${x}`)),(0,n.jsx)("div",{children:u},t)})})}let tT=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:a,output:l,exitCode:c,isRunning:d,selected:u,onSelect:x,onInterrupt:m,onStdin:h,onDelete:f,onRerun:p,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,subscribePtyRefresh:w,onPtyResize:k,onToggleMaximize:y,maximized:N,expandedHeight:C,bubbleContentHeight:S,onTitleMouseDown:L}){let{t:M}=(0,o.Bd)(),P=(0,s.useRef)(null),$=(0,s.useRef)(null),T=(0,s.useRef)(!0),R=(0,s.useRef)(null),B=(0,s.useRef)(null),F=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(g),I=e&&t?tf(t+e):void 0,[D,A]=(0,s.useState)(!1),[W,z]=(0,s.useState)(""),_=(0,s.useRef)(null),H=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>_.current?v(e,_.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>_.current?j(e,_.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]),(0,s.useEffect)(()=>{if(!w||!e)return;let t=()=>_.current?w(e,_.current.refresh):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[w,e]);let[V,K]=(0,s.useState)(!1),[U,J]=(0,s.useState)(""),[Q,Z]=(0,s.useState)("search"),[Y,G]=(0,s.useState)(0),X=(0,s.useRef)([]),et=(0,s.useRef)(null),er=(0,s.useRef)(0);(0,s.useEffect)(()=>{et.current||(et.current=new th.v,et.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=$.current;if(e&&et.current){if(l.length<er.current&&(et.current=new th.v,et.current.use_classes=!0,er.current=0,e.innerHTML=""),l.length>er.current){let t=l.slice(er.current),r=et.current.ansi_to_html(t);er.current=l.length,e.insertAdjacentHTML("beforeend",r)}if(P.current){let e=P.current.scrollHeight>P.current.clientHeight;A(e),e&&(P.current.scrollTop=P.current.scrollHeight)}}},[l]),(0,s.useEffect)(()=>(d&&T.current&&P.current&&(null!==R.current&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight),R.current=null})),()=>{null!==R.current&&cancelAnimationFrame(R.current)}),[l,d]),(0,s.useEffect)(()=>{if(!N)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),y?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[N,y]);let en=l?l.split("\n").length:0,es=(0,s.useCallback)(()=>{K(!0),requestAnimationFrame(()=>H.current?.focus())},[]),eo=(0,s.useCallback)(()=>{K(!1),J(""),G(0),_.current?.clearSearch()},[]),ea=(0,s.useCallback)(e=>{e.trim()&&(b?_.current?.findNext(e):G(e=>{let t=e+1,r=X.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(X.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),el=(0,s.useCallback)(e=>{e.trim()&&(b?_.current?.findPrevious(e):G(e=>{let t=e-1;if(t>=0)return X.current[t]?.scrollIntoView({block:"nearest"}),t;let r=X.current.length-1;return r>=0&&X.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!u)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),es();return}if("Escape"===e.key&&V){e.preventDefault(),e.stopPropagation(),eo();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[u,V,es,eo]);let ei=N&&C?C-41:S??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${N?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${N?"":u?"border-brand":"border-brand/30"}`,onClick:x,children:[N?(0,n.jsxs)("div",{onDoubleClick:()=>y?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:a}),d&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),M("console.runningText")]}),d&&m&&(0,n.jsx)("button",{onClick:m,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-md active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>y?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:M("console.restoreTooltip",{modKey:(0,tb.Mu)()}),children:(0,n.jsx)(q.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>L?.(),onDoubleClick:e=>{e.stopPropagation(),y?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${u?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),I&&e&&t&&(0,n.jsx)(tg,{shortId:I,type:"terminal",onRegister:()=>{i.t4.runFork(tw("/api/terminal/register",{tabId:t,commandId:e,command:a,projectCwd:r}).pipe(ee.orElse(()=>ee.void)))},onUnregister:()=>{i.t4.runFork(tw("/api/terminal/unregister",{commandId:e}).pipe(ee.orElse(()=>ee.void)))},fullId:e,projectCwd:r,tabId:t}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:a}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),(0,E.oR)(M("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:M("console.copyCommand"),children:(0,n.jsx)(tc.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),D&&!d&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:M("console.totalLines",{count:en})}),l&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=l.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,E.oR)(M("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:M("console.copyOutput"),children:(0,n.jsx)(td.A,{className:"w-3.5 h-3.5"})}),p&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),p()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:M("console.rerun"),children:(0,n.jsx)(tu.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:M("console.deleteRecord"),children:(0,n.jsx)(q.A,{className:"w-3.5 h-3.5"})})]}),V&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(O.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:H,value:U,onChange:e=>{let t=e.target.value;J(t),G(0),b&&(t.trim()?_.current?.findNext(t):_.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?el(U):ea(U))},placeholder:M("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}),!b&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>Z("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===Q?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:M("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>Z("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===Q?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:M("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>el(U),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:M("console.prevShiftEnter"),children:(0,n.jsx)(tx.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>ea(U),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:M("console.nextEnter"),children:(0,n.jsx)(tm.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:eo,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(q.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsxs)("div",{className:"relative group",style:{height:ei,overflow:"hidden"},children:[(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:ei},children:M("console.loadingTerminal")}),children:(0,n.jsx)(tM,{ref:_,output:l,isRunning:d,onInput:h,onResize:k,maximized:N,height:ei,directWrite:!!v})}),!d&&p&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",onClick:e=>{e.stopPropagation(),p()},title:M("console.rerun"),children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-black/60 text-white text-xs",children:[(0,n.jsx)(tu.A,{className:"w-3.5 h-3.5"}),M("console.rerun")]})})]}):(0,n.jsx)("div",{ref:P,className:"overflow-auto px-4 py-2",style:{height:ei},onScroll:()=>{if(P.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=P.current;T.current=t-e-r<50}},children:V&&U.trim()?(0,n.jsx)(t$,{output:l,query:U,mode:Q,currentIdx:Y,matchListRef:X}):(0,n.jsx)("pre",{ref:$,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),d&&!N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),b?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:M("console.clickToInput")}):h?(0,n.jsx)("input",{ref:B,value:W,onChange:e=>z(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tE[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(W+"\n"),z("")),"Tab"===e.key&&(e.preventDefault(),h(" "))},placeholder:M("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:M("console.runningText")}),m&&(0,n.jsx)("button",{onClick:m,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),F&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:F})]}),!d&&void 0!==c&&!N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===c?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:M("console.exitCode",{code:c})}),(0,n.jsx)("span",{className:"flex-1"}),F&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:F})]})]})})});var tR=r(68459),tB=r(51914);function tF({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[c,d]=(0,s.useState)({}),[u,x]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(async()=>{p(!0);let r=await i.t4.runPromiseExit(tk(e,t));"Success"===r._tag?d(r.value):console.error("Failed to load env:",r.cause),p(!1)},[e,t]);(0,s.useEffect)(()=>{g()},[g]);let b=()=>{u.trim()&&(d(e=>({...e,[u.trim()]:m})),x(""),h(""))},v=async()=>{let n=await i.t4.runPromiseExit(tw("/api/terminal/env",{cwd:e,tabId:t,env:c}));"Success"===n._tag?(a(c),r()):console.error("Failed to save env:",n.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold",children:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(q.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:f?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(c).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"flex-1 px-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void d(t=>({...t,[e]:r}))},placeholder:l("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{d(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors",children:(0,n.jsx)(tR.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("input",{type:"text",value:u,onChange:e=>x(e.target.value),placeholder:l("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),b())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),placeholder:l("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),b())}}),(0,n.jsx)("button",{onClick:b,disabled:!u.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tB.A,{className:"w-4 h-4"})})]}),0===Object.keys(c).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:l("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var tI=r(10762);function tD({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[c,d]=(0,s.useState)(""),[u,x]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0),f=(0,s.useCallback)(async()=>{h(!0);let e=await i.t4.runPromiseExit(ty());"Success"===e._tag?l(e.value):console.error("Failed to load aliases:",e.cause),h(!1)},[]);(0,s.useEffect)(()=>{f()},[f]);let p=()=>{c.trim()&&u.trim()&&(l(e=>({...e,[c.trim()]:u.trim()})),d(""),x(""))},g=async()=>{let r=await i.t4.runPromiseExit(tw("/api/terminal/aliases",{aliases:a}));"Success"===r._tag?(t(a),e()):console.error("Failed to save aliases:",r.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[(0,n.jsx)(tI.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(q.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(a).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void l(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{l(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(tR.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:r("aliasManager.aliasPlaceholder"),className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),p())}})]}),(0,n.jsx)("input",{type:"text",value:u,onChange:e=>x(e.target.value),placeholder:r("aliasManager.commandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),p())}})]}),(0,n.jsx)("button",{onClick:p,disabled:!c.trim()||!u.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(tB.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(a).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:g,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:r("common.save")})]})]})})}var tA=r(53961),tW=r(15813),tz=r(37595),t_=r(49698),tH=r(20232);let tO=new Map;function tq(e){tO.set(e.type,e)}function tV(e){return tO.get(e)}function tK(e){for(let t of tO.values())if(t.match(e))return t;return null}let tU=(e,t)=>ee.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new et.uV({message:`POST ${e} failed`,cause:t})}),tJ=(e,t)=>i.t4.runPromise(tU(`/api/${e}/disconnect`,{id:t}).pipe(ee.orElse(()=>ee.void))),tQ=e=>i.t4.runPromise(tU("/api/browser/unregister",{id:e}).pipe(ee.orElse(()=>ee.void))),tZ=e=>i.t4.runPromise(e.pipe(ee.catchAll(e=>ee.sync(()=>{if(e.cause instanceof Error)throw e.cause;throw Error(e.message)})))),tY=(e,t)=>{if(e&&"object"==typeof e&&"error"in e){let t=e.error;if("string"==typeof t&&t.length>0)return t;if(t&&"object"==typeof t){let e=t.message;if("string"==typeof e&&e.length>0)return e;let r=t._tag;if("string"==typeof r&&r.length>0)return r}}return`HTTP ${t}`},tG=(e,t)=>tZ(ee.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(tY(n,r.status));return n},catch:t=>new et.uV({message:`POST ${e} failed`,cause:t})})),tX=(e,t)=>tZ(ee.tryPromise({try:async()=>{let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(tY(s,n.status));return s},catch:t=>new et.uV({message:`GET ${e} failed`,cause:t})})),t0=(e,t)=>tZ(ee.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return r.blob()},catch:t=>new et.uV({message:`POST blob ${e} failed`,cause:t})}));var t1=r(53853);function t2(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function t5(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function t4(e){let t=(0,t1.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function t3(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function t6({url:e,id:t,selected:r,maximized:i,expandedHeight:c,bubbleContentHeight:d,onSelect:u,onClose:x,onToggleMaximize:m,onNewTab:h,timestamp:f,onTitleMouseDown:p,initialSleeping:g,onSleep:b,onWake:v,projectCwd:j,tabId:w}){let{t:k}=(0,o.Bd)(),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(null),[L,M]=(0,s.useState)(e),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)(g??!1),B=(0,s.useRef)(null),F=(0,s.useRef)(null),I=(0,s.useRef)(null);(0,s.useEffect)(()=>{M(e)},[e]);let D=(0,s.useRef)(!0),A=(0,s.useCallback)(()=>{T||(R(!0),$(null),b?.(t))},[T,t,b]),W=(0,s.useCallback)(()=>{B.current&&(clearTimeout(B.current),B.current=null)},[]),{shortId:z,connected:_,connect:H,disconnect:O}=function(e,t,r,n,o){let i=(0,s.useMemo)(()=>tf(e),[e]),[c,d]=(0,s.useState)(!1),u=(0,s.useRef)(null),x=(0,s.useRef)([]),m=(0,s.useRef)(null),h=(0,s.useRef)(!1),f=(0,s.useRef)(r);(0,s.useEffect)(()=>{f.current=r});let p=(0,s.useRef)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=u.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),(0,a.F)(l.n.ScreenshotPrepare,{cwd:n}),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n}},"*")},150)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),(0,a.F)(l.n.ScreenshotDone,{});return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let g=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=u.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!c)return;let r=!1;return h.current=!0,!function s(){if(r||!h.current)return;let a="https:"===window.location.protocol?"wss:":"ws:",l=new URLSearchParams({fullId:e});n&&l.set("projectCwd",n),o&&l.set("tabId",o);let i=new WebSocket(`${a}//${window.location.host}/ws/browser?${l.toString()}`);u.current=i,i.onopen=()=>{for(let e of p.current)e();if(p.current=[],x.current.length>0){for(let e of x.current)g(e);x.current=[]}},i.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&f.current?g(e):x.current.push(e)}},i.onclose=()=>{u.current=null,!r&&h.current&&(m.current=setTimeout(s,3e3))},i.onerror=()=>i.close()}(),()=>{r=!0,h.current=!1,m.current&&clearTimeout(m.current),u.current&&(u.current.close(),u.current=null),p.current=[]}},[c,e,t,g,n,o]),(0,s.useEffect)(()=>{if(r&&x.current.length>0){for(let e of x.current)g(e);x.current=[]}},[r,g]);let b=(0,s.useCallback)(()=>c&&u.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{p.current.push(e),c||d(!0)}),[c]);return{shortId:i,connected:c,connect:b,disconnect:(0,s.useCallback)(()=>{d(!1)},[])}}(t,I,!!P&&!T&&!y,j,w),q=(0,s.useRef)(_);q.current=_,(0,s.useEffect)(()=>{let e=F.current;if(!e||T)return;let t=new IntersectionObserver(([e])=>{D.current=e.isIntersecting,e.isIntersecting||q.current?W():(B.current&&clearTimeout(B.current),B.current=setTimeout(A,3e5))});return t.observe(e),()=>t.disconnect()},[T,A,W]),(0,s.useEffect)(()=>{T?O():_?W():D.current||(B.current&&clearTimeout(B.current),B.current=setTimeout(A,3e5))},[_,T,O,W,A]),(0,s.useEffect)(()=>{g&&$(null)},[]);let V=(0,s.useCallback)(()=>{R(!1),v?.(t);let r=t2(e);t3(e)?$(r):t4(e).then(()=>$(r))},[e,t,v]);(0,s.useEffect)(()=>{if(!e||T){e||$(null);return}let t=t2(e);if(t3(e))return void $(t);let r=!1;return t4(e).then(()=>{r||$(t)}),()=>{r=!0}},[e,T]);let K=(0,s.useCallback)(()=>N(!1),[]);(0,s.useEffect)(()=>{let e=F.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,a=()=>{o&&t&&(t.scrollTop=s)},l=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",a)},i=()=>{o=!1,t.removeEventListener("scroll",a),t.style.overflow=n};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",a),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=F.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?h?.(t5(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&M(t5(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,h]);let U=(0,s.useCallback)(()=>{N(!1),S(k("browser.pageLoadFailed"))},[]),J=(0,s.useCallback)(()=>{if(T)return void V();let e=F.current?.querySelector("iframe");if(e&&P){N(!0),S(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[T,V,P]);(0,s.useEffect)(()=>{e&&!T&&(N(!0),S(null))},[e,T]);let Q=(0,s.useCallback)(()=>{L&&window.open(L,"_blank")},[L]);(0,s.useEffect)(()=>{if(!r&&!i)return;let e=e=>{"Escape"===e.key&&i&&(e.stopPropagation(),m()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),m())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[i,r,m]);let Z=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(L),Y=i&&c?c-41:d??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
2
+ relative transition-colors cursor-pointer
3
+ ${i?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
4
+ ${i?"":r?"border-brand":"border-brand/30"}`,onClick:i?void 0:u,children:[i?(0,n.jsxs)("div",{onDoubleClick:m,className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),z&&(0,n.jsx)(tg,{shortId:z,type:"browser",onRegister:()=>H(),onUnregister:async()=>{O(),await tQ(z)},fullId:t,projectCwd:j,tabId:w}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:L||k("browser.blankPage")}),L&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(L),(0,E.oR)(k("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),y&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:J,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:Q,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:m,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.exitMaximize",{modKey:(0,tb.Mu)()}),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>p?.(),onDoubleClick:e=>{e.stopPropagation(),m()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing
5
+ ${r?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3 inline-block",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),z&&(0,n.jsx)(tg,{shortId:z,type:"browser",onRegister:()=>H(),onUnregister:async()=>{O(),await tQ(z)},fullId:t,projectCwd:j,tabId:w}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:L||k("browser.blankPage")}),L&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(L),(0,E.oR)(k("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),y&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Q()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),J()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:k("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:F,className:"w-full",style:{height:Y},children:T?(0,n.jsxs)("div",{className:"relative overflow-hidden cursor-pointer group h-full",onClick:e=>{e.stopPropagation(),J()},children:[(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-muted/30",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground/60",children:Z})]}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-black/60 text-white text-xs",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),k("browser.clickToWake")]})})]}):e?C?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground p-6 h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-3 text-red-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-xs",children:C}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),J()},className:"mt-2 px-3 py-1 text-xs bg-secondary text-foreground rounded hover:bg-accent transition-colors",children:k("common.retry")})]}):(0,n.jsxs)("div",{className:"relative overflow-hidden h-full",style:{contain:"strict"},children:[y&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-white/80 dark:bg-slate-900/80 z-10",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),P?(0,n.jsx)("iframe",{ref:I,src:P,className:"border-0",allow:"clipboard-write; clipboard-read",style:i?{width:"100%",height:"100%"}:{position:"absolute",top:0,left:0,width:"200%",height:"200%",transform:"scale(0.5)",transformOrigin:"top left"},onLoad:K,onError:U,title:`Browser: ${Z}`,"data-browser-id":t}):(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-slate-300 dark:text-slate-700",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs",children:k("browser.blankPage")})]})}),!i&&e&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${T?"bg-yellow-500":y?"bg-brand animate-pulse":C?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:"truncate",children:T?k("browser.sleeping"):y?k("browser.loadingPage"):C?k("browser.loadFailed"):Z}),(0,n.jsx)("span",{className:"flex-1"}),f&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(f)})]})]})})}tq({type:"browser",idPrefix:"browser",match(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")},parse:e=>({url:e.trim()}),fromHistory:e=>({url:e.url}),toHistory:e=>({url:e.url}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d,extra:u}){return(0,n.jsx)(t6,{id:e.id,url:e.url,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d,onNewTab:u?.addBrowserItem,initialSleeping:u?.initialSleeping,onSleep:u?.onSleep,onWake:u?.onWake,projectCwd:u?.projectCwd,tabId:u?.tabId})}});let t8=[{value:"=",label:"="},{value:"!=",label:"≠"},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:"≥"},{value:"<=",label:"≤"},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function t9(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function t7(e){return`"${e.replace(/"/g,'""')}"`}function re(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rt({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),c=(0,s.useRef)(!1),d=(0,x.F2)(),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{c.current||r(!1)},80)},[]),m=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),c.current=!1,i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=d?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.width??window.innerWidth,c=n?.height??window.innerHeight,u=t.left-s,x=t.top-o,m=t.bottom-o,h=Math.min(600,i-u-8),f=x-8,p=c-m-8,g=f>p&&f>80;a({x:h<200?Math.max(8,i-600-8):u,y:g?x-4:m+4,maxW:h<200?Math.min(600,i-16):h,maxH:Math.max(60,g?f-4:p-4),above:g}),r(!0)},350)},[d]),h=(0,s.useCallback)(()=>{u()},[u]),f=(0,s.useCallback)(()=>{c.current=!0,i.current&&clearTimeout(i.current)},[]),p=(0,s.useCallback)(()=>{c.current=!1,u()},[u]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:m,onMouseLeave:h,children:[e,t&&(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}function rr({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:x,timestamp:m,onTitleMouseDown:h}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,E.dj)(),[g,b]=(0,s.useState)("connecting"),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)("public"),[C,S]=(0,s.useState)([]),[L,M]=(0,s.useState)(null),[P,$]=(0,s.useState)("table"),[T,R]=(0,s.useState)("data"),[B,F]=(0,s.useState)([]),[I,D]=(0,s.useState)([]),[A,W]=(0,s.useState)([]),[z,_]=(0,s.useState)([]),[H,O]=(0,s.useState)(null),[q,V]=(0,s.useState)(0),[K,U]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(0),[Z,Y]=(0,s.useState)(new Set),[G,X]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)({}),[ei,ec]=(0,s.useState)({}),[ed,eu]=(0,s.useState)(null),[ex,em]=(0,s.useState)(""),[eh,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ew=(0,s.useCallback)(async()=>{b("connecting"),j("");try{let r=await tG("/api/db/connect",{id:e,connectionString:t});k(r.schemas||[]),r.schemas?.length>0&&!r.schemas.includes("public")&&N(r.schemas[0]),b("connected")}catch(e){j(e instanceof Error?e.message:String(e)),b("error")}},[e,t]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async()=>{if("connected"===g)try{let r=await tX("/api/db/schemas",{id:e,connectionString:t,schema:y});S(r.tables||[])}catch{}},[e,t,y,g]);(0,s.useEffect)(()=>{ek()},[ek]);let ey=(0,s.useCallback)(async(r,n,s,o)=>{U(!0);let a=s??ei,l=void 0!==o?o:ed;try{let s=`${t7(y)}.${t7(r)}`,{where:o,params:i}=function(e){let t=[],r=[],n=1;for(let[s,o]of Object.entries(e)){if(!o.enabled)continue;let e=t7(s);if("IS NULL"===o.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===o.op)t.push(`${e} IS NOT NULL`);else if("IN"===o.op){let s=o.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===s.length)continue;let a=s.map(e=>(r.push(e),`$${n++}`));t.push(`${e}::text IN (${a.join(", ")})`)}else"LIKE"===o.op||o.op,t.push(`${e}::text ${o.op} $${n++}`),r.push(o.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(a),c=l?` ORDER BY ${t7(l.column)} ${l.dir}`:"",d=`SELECT * FROM ${s}${o}${c} LIMIT 50 OFFSET ${50*n}`,u=await tG("/api/db/query",{id:e,connectionString:t,sql:d,params:i});O(u);let x=`SELECT count(*)::int AS cnt FROM ${s}${o}`,m=await tG("/api/db/query",{id:e,connectionString:t,sql:x,params:i});Q(m.rows?.[0]?.cnt??0)}catch{}U(!1)},[e,t,y,ei,ed]),eN=(0,s.useCallback)(async r=>{M(r),V(0),et(null),eo(!1),Y(new Set),X(!1),ec({}),eu(null);try{let n=await tX("/api/db/columns",{id:e,connectionString:t,schema:y,table:r});F(n.columns||[]),D(n.primaryKeys||[]),W(n.foreignKeys||[]),_(n.indexes||[])}catch{}ey(r,0,{},null)},[e,t,y,ey]),eC=(0,s.useCallback)(async()=>{if(ex.trim()){ev(!0),eg(""),ef(null);try{let r=await tG("/api/db/query",{id:e,connectionString:t,sql:ex});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,ex]),eS=(0,s.useCallback)(async()=>{if(null===ee||!H||!L)return;let r=H.rows[ee],n=[],s=[],o=1;for(let e of B)void 0!==er[e.name]&&er[e.name]!==re(r[e.name]??"")&&(n.push(`${t7(e.name)} = $${o}`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]),o++);if(0===n.length)return void et(null);let a=I.length>0?I:B.map(e=>e.name),l=[];for(let e of a)null===r[e]||void 0===r[e]?l.push(`${t7(e)} IS NULL`):(l.push(`${t7(e)} = $${o}`),s.push(r[e]),o++);let i=`UPDATE ${t7(y)}.${t7(L)} SET ${n.join(", ")} WHERE ${l.join(" AND ")}`;try{await tG("/api/db/query",{id:e,connectionString:t,sql:i,params:s}),et(null),ey(L,q,ei,ed)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,H,L,B,I,er,e,t,y,ey,q,ei,ed]),eL=(0,s.useCallback)(async()=>{if(!L)return;let r=[],n=[],s=[],o=1;for(let e of B)void 0!==ea[e.name]&&""!==ea[e.name]&&(r.push(t7(e.name)),n.push(ea[e.name]),s.push(`$${o}`),o++);if(0===r.length)return;let a=`INSERT INTO ${t7(y)}.${t7(L)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await tG("/api/db/query",{id:e,connectionString:t,sql:a,params:n}),eo(!1),el({}),ey(L,q,ei,ed)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[L,B,ea,e,t,y,ey,q,ei,ed]),eM=(0,s.useCallback)(async()=>{if(0===Z.size||!H||!L)return;let r=I.length>0?I:B.map(e=>e.name),n=0;for(let s of Array.from(Z).sort((e,t)=>t-e)){let o=H.rows[s];if(!o)continue;let a=[],l=[],i=1;for(let e of r)null===o[e]||void 0===o[e]?a.push(`${t7(e)} IS NULL`):(a.push(`${t7(e)} = $${i}`),l.push(o[e]),i++);let c=`DELETE FROM ${t7(y)}.${t7(L)} WHERE ctid = (SELECT ctid FROM ${t7(y)}.${t7(L)} WHERE ${a.join(" AND ")} LIMIT 1)`;try{await tG("/api/db/query",{id:e,connectionString:t,sql:c,params:l})}catch{n++}}Y(new Set),X(!1),ey(L,q,ei,ed),n>0&&alert(f("database.deleteRowsFailed",{count:n}))},[Z,H,L,I,B,e,t,y,ey,q,ei,ed]),eE=(0,s.useCallback)(async r=>{if(!L)return;if(Z.size>0&&H){let e,t=H.fields.map(e=>e.name),n=Array.from(Z).sort((e,t)=>e-t).map(e=>H.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${t7(y)}.${t7(L)}`;try{let s=await t0("/api/db/export",{id:e,connectionString:t,sql:n,format:r}),o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=`${L}.${r}`,a.click(),URL.revokeObjectURL(o)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[L,e,t,y,Z,H]),eP=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),e$=Math.max(1,Math.ceil(J/50)),eT=(0,s.useCallback)(e=>{L&&(V(e),ey(L,e,ei,ed))},[L,ey,ei,ed]),eR=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ec(r),V(0),Y(new Set),L&&ey(L,0,r,ed)},[ei,ed,L,ey]),eB=(0,s.useCallback)(()=>{ec({}),V(0),Y(new Set),L&&ey(L,0,{},ed)},[ed,L,ey]),eF=(0,s.useCallback)(e=>{eu(e),V(0),Y(new Set),L&&ey(L,0,ei,e)},[ei,L,ey]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
6
+ relative transition-colors cursor-pointer
7
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
8
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:x,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC18"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===g&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===g&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("database.connectionFailed")}),"connected"===g&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:f("database.connected")}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:t9(m)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?f("browser.exitMaximize",{modKey:(0,tb.Mu)()}):f("browser.maximize",{modKey:(0,tb.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===g&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("database.connecting")]}),"error"===g&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:v}),(0,n.jsx)("button",{onClick:ew,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:y,onChange:e=>{N(e.target.value),M(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:y}),(0,n.jsx)("button",{onClick:ek,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:f("database.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>$(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${P===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("database.filterTable"),view:f("database.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.filter(e=>"table"===P?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${L===e.name?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rt,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===C.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("database.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:`px-3 py-1.5 text-xs transition-colors ${T===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("database.tabStructure"),data:f("database.tabData"),sql:"SQL"}[e]},e)),L&&"data"===T&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("database.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eB,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("database.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),Z.size>0&&!G&&(0,n.jsx)("button",{onClick:()=>X(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("database.deleteNRows",{count:Z.size})}),G&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("database.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eM,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>X(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Z.size>0?f("database.copyCsvSelected"):f("database.copyCsvAll"),children:Z.size>0?f("database.copyCSV"):f("database.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Z.size>0?f("database.copyJsonSelected"):f("database.copyJsonAll"),children:Z.size>0?f("database.copyJSON"):f("database.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:L||"sql"===T?"structure"===T?(0,n.jsx)(rn,{columns:B,primaryKeys:I,foreignKeys:A,indexes:z}):"data"===T?(0,n.jsx)(ro,{result:H,loading:K,columns:B,page:q,totalPages:e$,totalRows:J,onPageChange:eT,filters:ei,sort:ed,onFilterChange:eR,onSortChange:eF,selectedRows:Z,onSelectedRowsChange:e=>{Y(e),X(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!H)return;let t=H.rows[e],r={};for(let e of B)r[e.name]=null==t[e.name]?"":re(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eL,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(ra,{sqlInput:ex,onSqlChange:em,onExecute:eC,onKeyDown:eP,result:eh,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("database.selectTable")})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===g?"bg-green-500":"error"===g?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[g]}),"connected"===g&&L&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:L}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:t9(m)})]})]})})}function rn({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("database.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-accent/50",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-500 mr-1",title:a("database.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate",title:e.definition,children:e.name},e.name))})]})]})}function rs({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:i,anchorRect:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(e?.op||"="),[h,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,x.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let b="IS NULL"!==u&&"IS NOT NULL"!==u,v=()=>{(!b||h.trim())&&t({op:u,value:h.trim(),enabled:!0})},j=g?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=c.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=c.bottom+2-k;return(0,n.jsx)(x.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lg p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),d("database.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:i})]}),(0,n.jsx)("select",{value:u,onChange:e=>m(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:t8.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:d("IN"===u?"database.commaValues":"LIKE"===u?"database.likePattern":"database.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!h.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:d("database.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:d("database.clearFilter")})]})]})})}function ro({result:e,loading:t,columns:r,page:a,totalPages:l,totalRows:i,onPageChange:c,filters:d,sort:u,onFilterChange:x,onSortChange:m,selectedRows:h,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:w,isAddingRow:k,newRowValues:y,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:L,onCellCopy:M}){let{t:E}=(0,o.Bd)(),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),$(null)):null!==p?(e.stopPropagation(),w()):k&&(e.stopPropagation(),L()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[P,p,k,w,L]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("database.selectTableForData")});let B=e?.fields||[],F=e?.rows||[],I={};for(let e of r)I[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=F.length>0&&h.size===F.length,A=h.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=A)},onChange:()=>{D?f(new Set):f(new Set(F.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),B.map(e=>{let t=u?.column===e.name?u.dir:null,r=d[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?m({column:t,dir:"DESC"}):m(null):m({column:t,dir:"ASC"}))},children:[e.name,I[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:I[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),P===e.name)return void $(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),$(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),P===e.name&&(0,n.jsx)(rs,{filter:r||null,onApply:t=>{x(e.name,t),$(null)},onClear:()=>{x(e.name,null),$(null)},onToggle:t=>{r&&x(e.name,{...r,enabled:t})},onClose:()=>$(null),colName:e.name,anchorRect:T})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[k&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:L,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),B.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:y[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),F.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-accent/50 ${h.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:w,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:h.has(t),onChange:()=>{let e;(e=new Set(h)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),B.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),M(re(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rt,{text:re(e[r.name])})},r.name))]},t))]})]}),0===F.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:k,className:"px-1.5 py-0.5 text-[10px] text-emerald-500 hover:text-emerald-400 disabled:opacity-30",children:E("database.addRow")}),(0,n.jsx)("span",{children:E("database.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>c(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>c(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function ra({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,loading:i,sqlRef:c,onCellCopy:d}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:c,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("database.sqlPlaceholder",{modKey:(0,tb.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"database.executing":"database.execute")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("database.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("database.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("database.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:a.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:a.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),d(re(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rt,{text:re(e[t.name])})},t.name))},t))})]})})]})}tq({type:"database",idPrefix:"db",match(e){let t=e.trim().toLowerCase();return t.startsWith("postgresql://")||t.startsWith("postgres://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"postgres";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rr,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){await tJ("db",e.id)}});var rl=r(91334),ri=r(38194),rc=r(88522),rd=r(13219);let ru=new th.v;function rx(e){return e?Array.isArray(e)?e.join(""):e:""}function rm(e,t){return e&&e[t]?rx(e[t]):""}ru.use_classes=!0;let rh=(0,s.memo)(function({output:e}){if("stream"===e.output_type){let t=rx(e.text);if(!t)return null;let r=ru.ansi_to_html(t);return(0,n.jsx)("pre",{className:`text-xs leading-relaxed whitespace-pre-wrap break-all px-3 py-1 ${"stderr"===e.name?"text-amber-500":"text-foreground"}`,dangerouslySetInnerHTML:{__html:r}})}if("error"===e.output_type){let t=(e.traceback||[]).join("\n"),r=ru.ansi_to_html(t);return(0,n.jsx)("pre",{className:"text-xs leading-relaxed whitespace-pre-wrap break-all px-3 py-1 text-red-400 bg-red-500/5 rounded",dangerouslySetInnerHTML:{__html:r}})}if("execute_result"===e.output_type||"display_data"===e.output_type||"update_display_data"===e.output_type){let t=e.data;if(!t)return null;let r=rm(t,"image/png"),s=rm(t,"image/jpeg"),o=rm(t,"image/svg+xml"),a=rm(t,"text/html"),l=rm(t,"text/markdown"),i=rm(t,"text/latex"),c=rm(t,"text/plain");if(r)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)("img",{src:`data:image/png;base64,${r}`,alt:"output",className:"max-w-full"})});if(s)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)("img",{src:`data:image/jpeg;base64,${s}`,alt:"output",className:"max-w-full"})});if(o)return(0,n.jsx)("div",{className:"px-3 py-1",dangerouslySetInnerHTML:{__html:o}});if(a)return(0,n.jsx)("div",{className:"px-3 py-1 overflow-x-auto notebook-html-output",dangerouslySetInnerHTML:{__html:a}});if(l)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)(rd.T,{content:l})});if(i)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)(rd.T,{content:`$$${i}$$`})});if(c)return(0,n.jsx)("pre",{className:"text-xs leading-relaxed whitespace-pre-wrap break-all px-3 py-1 text-foreground",children:c})}return null}),rf=(0,s.memo)(function({cell:e,isActive:t,isEditing:r,onSelect:o,onEdit:a,onStopEdit:l,onSourceChange:i,onRun:c,onDelete:d,onMoveUp:u,onMoveDown:x,onToggleType:m,isFirst:h,isLast:f}){let{resolvedTheme:p}=(0,ec.D)(),g=(0,s.useRef)(null),[b,v]=(0,s.useState)(e.source),j=(0,s.useCallback)(()=>{v(e.source),a()},[e.source,a]);(0,s.useEffect)(()=>{if(r&&g.current){g.current.focus();let e=g.current.value.length;g.current.setSelectionRange(e,e)}},[r]);let w=(0,s.useCallback)(()=>{let e=g.current;e&&(e.style.height="auto",e.style.height=e.scrollHeight+"px")},[]);(0,s.useEffect)(()=>{r&&w()},[r,b,w]);let k=(0,s.useCallback)(e=>{v(e.target.value),w()},[w]),y=(0,s.useCallback)(()=>{b!==e.source&&i(b),l()},[b,e.source,i,l]),N=(0,s.useCallback)(t=>{if("Enter"===t.key&&t.shiftKey)t.preventDefault(),b!==e.source&&i(b),c();else if("Enter"===t.key&&(t.metaKey||t.ctrlKey))t.preventDefault(),b!==e.source&&i(b),c();else if("Escape"===t.key)t.preventDefault(),y();else if("Tab"===t.key){t.preventDefault();let e=g.current;if(e){let t=e.selectionStart,r=e.selectionEnd;v(b.substring(0,t)+" "+b.substring(r)),requestAnimationFrame(()=>{e.selectionStart=e.selectionEnd=t+4})}}},[b,e.source,i,c,y]),C=e.isExecuting?"*":e.execution_count??" ",S="code"===e.cell_type?"Code":"markdown"===e.cell_type?"Md":"Raw";return(0,n.jsxs)("div",{className:`group relative border rounded-lg transition-colors ${t?"border-brand/50 bg-brand/5":"border-border/50 hover:border-border"}`,onClick:o,children:[(0,n.jsxs)("div",{className:`absolute -top-3 left-2 flex items-center gap-0.5 text-[10px] z-10 bg-surface-secondary rounded px-1 py-0.5 border border-border/50 transition-opacity ${t?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:[(0,n.jsx)("button",{onClick:c,className:"px-1 hover:text-brand",title:"Run (Shift+Enter)",children:e.isExecuting?"⬛":"▶"}),(0,n.jsx)("button",{onClick:m,className:"px-1 hover:text-brand",title:"Toggle type",children:S}),!h&&(0,n.jsx)("button",{onClick:u,className:"px-1 hover:text-brand",title:"Move up",children:"↑"}),!f&&(0,n.jsx)("button",{onClick:x,className:"px-1 hover:text-brand",title:"Move down",children:"↓"}),(0,n.jsx)("button",{onClick:d,className:"px-1 hover:text-red-400",title:"Delete",children:"\xd7"})]}),(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-10 text-center py-2 text-[10px] text-muted-foreground select-none cursor-pointer border-r border-border/30",onClick:e=>{e.stopPropagation(),c()},title:"code"===e.cell_type?"Click to run":void 0,children:"code"===e.cell_type?(0,n.jsxs)("span",{className:e.isExecuting?"text-brand animate-pulse":"",children:["[",C,"]"]}):(0,n.jsx)("span",{className:"text-muted-foreground/50",children:S})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"cursor-text",onDoubleClick:e=>{e.stopPropagation(),j()},children:r?(0,n.jsx)("textarea",{ref:g,value:b,onChange:k,onBlur:y,onKeyDown:N,className:"w-full bg-transparent text-xs font-mono leading-relaxed px-3 py-2 resize-none outline-none text-foreground",spellCheck:!1,style:{minHeight:"1.5rem"}}):"code"===e.cell_type?(0,n.jsx)("div",{className:"text-xs [&_pre]:!m-0 [&_pre]:!p-2 [&_pre]:!bg-transparent [&_code]:!bg-transparent",children:(0,n.jsx)(rl.A,{language:"python",style:"dark"===p?ri.A:rc.A,customStyle:{margin:0,padding:"8px 12px",background:"transparent",fontSize:"12px"},wrapLongLines:!0,children:e.source||" "})}):"markdown"===e.cell_type?e.source.trim()?(0,n.jsx)("div",{className:"px-3 py-2 text-sm prose prose-sm dark:prose-invert max-w-none",children:(0,n.jsx)(rd.T,{content:e.source})}):(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground italic",children:"Empty markdown cell"}):(0,n.jsx)("pre",{className:"text-xs font-mono px-3 py-2 text-muted-foreground whitespace-pre-wrap",children:e.source||" "})}),e.outputs.length>0&&(0,n.jsx)("div",{className:"border-t border-border/30",children:e.outputs.map((e,t)=>(0,n.jsx)(rh,{output:e},t))})]})]})]})});function rp({id:e,filePath:t,displayName:r,cwd:o,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,timestamp:d,onSelect:u,onClose:x,onToggleMaximize:m,onTitleMouseDown:h}){let{showToast:f}=(0,E.dj)(),[p,g]=(0,s.useState)([]),[b,v]=(0,s.useState)(!0),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),[M,P]=(0,s.useState)(null),[$,T]=(0,s.useState)("disconnected"),[R,B]=(0,s.useState)(null),F=(0,s.useRef)(null),I=(0,s.useRef)(new Map),D=(0,s.useRef)(null),A=(0,s.useRef)(p);A.current=p;let W=(0,s.useCallback)(async()=>{v(!0),w(null);try{let e=await tG("/api/jupyter/load",{filePath:t,cwd:o});g(e.cells.map((e,t)=>({...e,index:t,isExecuting:!1}))),y(!1)}catch(e){w(e.message)}finally{v(!1)}},[t,o]);(0,s.useEffect)(()=>{W()},[W]);let z=(0,s.useCallback)(async()=>{if(!N){C(!0);try{await tG("/api/jupyter/save",{filePath:t,cwd:o,cells:p.map(e=>({cell_type:e.cell_type,source:e.source,outputs:e.outputs,execution_count:e.execution_count,metadata:e.metadata}))}),y(!1),f("Saved","success")}catch(e){f(e.message,"error")}finally{C(!1)}}},[t,o,p,N,f]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),z())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[z]);let _=(0,s.useCallback)(()=>{if(F.current&&F.current.readyState<=1)return;T("starting"),B(null);let t="https:"===window.location.protocol?"wss:":"ws:",r=new WebSocket(`${t}//${window.location.host}/ws/jupyter?bubbleId=${encodeURIComponent(e)}&cwd=${encodeURIComponent(o)}`);F.current=r,r.onopen=()=>{},r.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ready"===r)T("idle"),B(null);else if("status"===r){let e=t.execution_state;"idle"===e?T("idle"):"busy"===e&&T("busy")}else if("output"===r){let e=t.msg_id,r=t.msg_type,n=t.content,s=I.current.get(e);if(void 0===s)return;g(e=>e.map((e,t)=>{if(t!==s)return e;let o={output_type:"execute_result"===r?"execute_result":"display_data"===r?"display_data":"update_display_data"===r?"update_display_data":"stream"===r?"stream":"error"===r?"error":"display_data"};return"stream"===r?(o.name=n.name,o.text=n.text):"error"===r?(o.ename=n.ename,o.evalue=n.evalue,o.traceback=n.traceback):(o.data=n.data,o.metadata=n.metadata,"execute_result"===r&&(o.execution_count=n.execution_count)),{...e,outputs:[...e.outputs,o]}}))}else if("kernel_error"===r)T("error"),B(t.message);else if("kernel_died"===r){for(let[,e]of(T("dead"),B("Kernel died"),I.current))g(t=>t.map((t,r)=>r===e?{...t,isExecuting:!1}:t));I.current.clear()}},r.onclose=()=>{"error"!==$&&"dead"!==$&&T("disconnected")},r.onerror=()=>{T("error")}},[e,o,$]);(0,s.useEffect)(()=>()=>{F.current?.close()},[]);let H=(0,s.useRef)(null),O=(0,s.useCallback)(e=>{let t=A.current[e];if(!t||"code"!==t.cell_type)return;if(!F.current||F.current.readyState!==WebSocket.OPEN){_();let t=setInterval(()=>{F.current?.readyState===WebSocket.OPEN&&(clearInterval(t),H.current?.(e))},200);setTimeout(()=>clearInterval(t),15e3);return}let r=`cell-${e}-${Date.now()}`;I.current.set(r,e),g(t=>t.map((t,r)=>r===e?{...t,outputs:[],isExecuting:!0,execution_count:null}:t)),F.current.send(JSON.stringify({type:"execute",msg_id:r,code:t.source})),setTimeout(()=>{I.current.has(r)&&(I.current.delete(r),g(t=>t.map((t,r)=>r===e?{...t,isExecuting:!1}:t)))},3e5)},[_]);H.current=O,(0,s.useEffect)(()=>{let e=F.current;if(!e)return;let t=e=>{let t=I.current.get(e);void 0!==t&&(I.current.delete(e),g(e=>e.map((e,r)=>{if(r!==t)return e;let n=e.outputs.find(e=>"execute_result"===e.output_type);return{...e,isExecuting:!1,execution_count:n?.execution_count??e.execution_count}})))},r=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("status"===r.type&&"idle"===r.execution_state)for(let[e]of I.current)t(e)};return e.addEventListener("message",r),()=>{e.removeEventListener("message",r)}},[$]);let q=(0,s.useCallback)(()=>{let e=[...p.map((e,t)=>({cell:e,index:t})).filter(e=>"code"===e.cell.cell_type)],t=()=>{if(0===e.length)return;let{index:r}=e.shift();O(r);let n=setInterval(()=>{let e=A.current[r];e&&!e.isExecuting&&(clearInterval(n),t())},200)};t()},[p,O]),V=(0,s.useCallback)(()=>{F.current?.send(JSON.stringify({type:"interrupt"}))},[]),K=(0,s.useCallback)((e,t)=>{g(r=>r.map((r,n)=>n===e?{...r,source:t}:r)),y(!0)},[]),U=(0,s.useCallback)(e=>{g(t=>t.filter((t,r)=>r!==e)),y(!0),S===e&&L(null)},[S]),J=(0,s.useCallback)((e,t)=>{g(r=>{let n=[...r],s="up"===t?e-1:e+1;return s<0||s>=n.length?r:([n[e],n[s]]=[n[s],n[e]],n)}),y(!0),L("up"===t?e-1:e+1)},[]),Q=(0,s.useCallback)(e=>{g(t=>t.map((t,r)=>{if(r!==e)return t;let n="code"===t.cell_type?"markdown":"markdown"===t.cell_type?"raw":"code";return{...t,cell_type:n,outputs:"code"===n?t.outputs:[]}})),y(!0)},[]),Z=(0,s.useCallback)((e,t)=>{let r={index:0,cell_type:e,source:"",outputs:[],execution_count:null,metadata:{},isExecuting:!1};g(e=>{let n=[...e],s=void 0!==t?t+1:n.length;return n.splice(s,0,r),n}),y(!0);let n=void 0!==t?t+1:p.length;L(n),P(n)},[p.length]),Y=(0,s.useMemo)(()=>{switch($){case"idle":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 inline-block",title:"Kernel idle"});case"busy":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-amber-500 animate-pulse inline-block",title:"Kernel busy"});case"starting":return(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin inline-block",title:"Starting kernel"});case"error":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500 inline-block",title:R||"Kernel error"});case"dead":return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500 inline-block",title:"Kernel died"});default:return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-gray-500 inline-block",title:"Disconnected"})}},[$,R]);return(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
9
+ relative transition-colors cursor-pointer
10
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
11
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:u,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDCD3"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),Y,k&&(0,n.jsx)("span",{className:"text-[10px] text-amber-500 flex-shrink-0",children:"unsaved"}),(0,n.jsx)("span",{className:"flex-1"}),d&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(d)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?`Exit maximize (${(0,tb.Mu)()}+M)`:`Maximize (${(0,tb.Mu)()}+M)`,children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-3 py-1 border-b border-border/50 bg-surface-secondary/50 text-[11px]",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),q()},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Run All",children:"▶ All"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),V()},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Interrupt",disabled:"busy"!==$,children:"⬛ Stop"}),(0,n.jsx)("div",{className:"w-px h-3 bg-border/50 mx-1"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Z("code",S??p.length-1)},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Add code cell",children:"+ Code"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Z("markdown",S??p.length-1)},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Add markdown cell",children:"+ Md"}),(0,n.jsx)("div",{className:"w-px h-3 bg-border/50 mx-1"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),z()},className:`px-1.5 py-0.5 rounded hover:bg-accent transition-colors ${k?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:`Save (${(0,tb.Mu)()}+S)`,disabled:N,children:N?"Saving...":"Save"}),(0,n.jsx)("span",{className:"flex-1"}),R&&(0,n.jsx)("span",{className:"text-[10px] text-red-400 truncate max-w-[50%]",title:R,children:R}),"dead"===$&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),_()},className:"px-1.5 py-0.5 rounded text-brand hover:bg-accent transition-colors",children:"Restart"})]}),(0,n.jsx)("div",{ref:D,className:"overflow-y-auto",style:{height:(l&&i?i-41:c??360)-30},children:b?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground text-sm",children:"Loading notebook..."}):j?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-32 gap-2",children:[(0,n.jsx)("span",{className:"text-red-400 text-sm",children:j}),(0,n.jsx)("button",{onClick:W,className:"text-xs text-brand hover:underline",children:"Retry"})]}):0===p.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-32 gap-2 text-muted-foreground text-sm",children:[(0,n.jsx)("span",{children:"Empty notebook"}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>Z("code"),className:"text-xs text-brand hover:underline",children:"+ Code cell"}),(0,n.jsx)("button",{onClick:()=>Z("markdown"),className:"text-xs text-brand hover:underline",children:"+ Markdown cell"})]})]}):(0,n.jsxs)("div",{className:"flex flex-col gap-1 p-2",children:[p.map((e,t)=>(0,n.jsx)(rf,{cell:e,isActive:S===t,isEditing:M===t,onSelect:()=>L(t),onEdit:()=>{L(t),P(t)},onStopEdit:()=>P(null),onSourceChange:e=>K(t,e),onRun:()=>{"code"===e.cell_type&&O(t),t<p.length-1&&L(t+1)},onDelete:()=>U(t),onMoveUp:()=>J(t,"up"),onMoveDown:()=>J(t,"down"),onToggleType:()=>Q(t),isFirst:0===t,isLast:t===p.length-1},`${t}-${e.cell_type}`)),(0,n.jsxs)("div",{className:"flex justify-center gap-2 py-2 opacity-0 hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:()=>Z("code",p.length-1),className:"text-[10px] text-muted-foreground hover:text-foreground px-2 py-0.5 rounded border border-border/50 hover:border-border transition-colors",children:"+ Code"}),(0,n.jsx)("button",{onClick:()=>Z("markdown",p.length-1),className:"text-[10px] text-muted-foreground hover:text-foreground px-2 py-0.5 rounded border border-border/50 hover:border-border transition-colors",children:"+ Markdown"})]})]})})]})}tq({type:"jupyter",idPrefix:"nb",match:e=>e.trim().endsWith(".ipynb"),parse(e){let t=e.trim(),r=t.split("/"),n=r[r.length-1]||t;return{filePath:t,displayName:n,cwd:""}},fromHistory:e=>({filePath:e.filePath,displayName:e.displayName||"",cwd:e.cwd||""}),toHistory:e=>({filePath:e.filePath,displayName:e.displayName,cwd:e.cwd}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rp,{id:e.id,filePath:e.filePath,displayName:e.displayName,cwd:e.cwd,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){let t;await (t=e.id,i.t4.runPromise(tU("/api/jupyter/shutdown",{bubbleId:t}).pipe(ee.orElse(()=>ee.void))))}});let rg=[{value:"=",label:"="},{value:"!=",label:"!="},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:">="},{value:"<=",label:"<="},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rb(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function rv(e){return`\`${e.replace(/`/g,"``")}\``}function rj(e){try{let t=e.match(/\/\/[^/]+\/([^?]+)/);if(t)return t[1]}catch{}return""}function rw(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rk({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),c=(0,s.useRef)(!1),d=(0,x.F2)(),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{c.current||r(!1)},80)},[]),m=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),c.current=!1,i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=d?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.width??window.innerWidth,c=n?.height??window.innerHeight,u=t.left-s,x=t.top-o,m=t.bottom-o,h=Math.min(600,i-u-8),f=x-8,p=c-m-8,g=f>p&&f>80;a({x:h<200?Math.max(8,i-600-8):u,y:g?x-4:m+4,maxW:h<200?Math.min(600,i-16):h,maxH:Math.max(60,g?f-4:p-4),above:g}),r(!0)},350)},[d]),h=(0,s.useCallback)(()=>{u()},[u]),f=(0,s.useCallback)(()=>{c.current=!0,i.current&&clearTimeout(i.current)},[]),p=(0,s.useCallback)(()=>{c.current=!1,u()},[u]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:m,onMouseLeave:h,children:[e,t&&(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}function ry({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:x,timestamp:m,onTitleMouseDown:h}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,E.dj)(),[g,b]=(0,s.useState)("connecting"),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(()=>rj(t)),[C,S]=(0,s.useState)([]),[L,M]=(0,s.useState)(null),[P,$]=(0,s.useState)("table"),[T,R]=(0,s.useState)("data"),[B,F]=(0,s.useState)([]),[I,D]=(0,s.useState)([]),[A,W]=(0,s.useState)([]),[z,_]=(0,s.useState)([]),[H,O]=(0,s.useState)(null),[q,V]=(0,s.useState)(0),[K,U]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(0),[Z,Y]=(0,s.useState)(new Set),[G,X]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)({}),[ei,ec]=(0,s.useState)({}),[ed,eu]=(0,s.useState)(null),[ex,em]=(0,s.useState)(""),[eh,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ew=(0,s.useCallback)(async()=>{b("connecting"),j("");try{let r=await tG("/api/mysql/connect",{id:e,connectionString:t});k(r.schemas||[]);let n=rj(t);r.schemas?.length>0&&n&&r.schemas.includes(n)?N(n):r.schemas?.length>0&&N(r.schemas[0]),b("connected")}catch(e){j(e instanceof Error?e.message:String(e)),b("error")}},[e,t]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async()=>{if("connected"===g)try{let r=await tX("/api/mysql/schemas",{id:e,connectionString:t,schema:y});S(r.tables||[])}catch{}},[e,t,y,g]);(0,s.useEffect)(()=>{ek()},[ek]);let ey=(0,s.useCallback)(async(r,n,s,o)=>{U(!0);let a=s??ei,l=void 0!==o?o:ed;try{let s=`${rv(y)}.${rv(r)}`,{where:o,params:i}=function(e){let t=[],r=[];for(let[n,s]of Object.entries(e)){if(!s.enabled)continue;let e=rv(n);if("IS NULL"===s.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===s.op)t.push(`${e} IS NOT NULL`);else if("IN"===s.op){let n=s.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===n.length)continue;let o=n.map(e=>(r.push(e),"?"));t.push(`${e} IN (${o.join(", ")})`)}else"LIKE"===s.op||s.op,t.push(`${e} ${s.op} ?`),r.push(s.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(a),c=l?` ORDER BY ${rv(l.column)} ${l.dir}`:"",d=`SELECT * FROM ${s}${o}${c} LIMIT 50 OFFSET ${50*n}`,u=await tG("/api/mysql/query",{id:e,connectionString:t,sql:d,params:i});O(u);let x=`SELECT count(*) AS cnt FROM ${s}${o}`,m=await tG("/api/mysql/query",{id:e,connectionString:t,sql:x,params:i});Q(m.rows?.[0]?.cnt??0)}catch{}U(!1)},[e,t,y,ei,ed]),eN=(0,s.useCallback)(async r=>{M(r),V(0),et(null),eo(!1),Y(new Set),X(!1),ec({}),eu(null);try{let n=await tX("/api/mysql/columns",{id:e,connectionString:t,schema:y,table:r});F(n.columns||[]),D(n.primaryKeys||[]),W(n.foreignKeys||[]),_(n.indexes||[])}catch{}ey(r,0,{},null)},[e,t,y,ey]),eC=(0,s.useCallback)(async()=>{if(ex.trim()){ev(!0),eg(""),ef(null);try{let r=await tG("/api/mysql/query",{id:e,connectionString:t,sql:ex});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,ex]),eS=(0,s.useCallback)(async()=>{if(null===ee||!H||!L)return;let r=H.rows[ee],n=[],s=[];for(let e of B)void 0!==er[e.name]&&er[e.name]!==rw(r[e.name]??"")&&(n.push(`${rv(e.name)} = ?`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]));if(0===n.length)return void et(null);let o=I.length>0?I:B.map(e=>e.name),a=[];for(let e of o)null===r[e]||void 0===r[e]?a.push(`${rv(e)} IS NULL`):(a.push(`${rv(e)} = ?`),s.push(r[e]));let l=`UPDATE ${rv(y)}.${rv(L)} SET ${n.join(", ")} WHERE ${a.join(" AND ")}`;try{await tG("/api/mysql/query",{id:e,connectionString:t,sql:l,params:s}),et(null),ey(L,q,ei,ed)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,H,L,B,I,er,e,t,y,ey,q,ei,ed]),eL=(0,s.useCallback)(async()=>{if(!L)return;let r=[],n=[],s=[];for(let e of B)void 0!==ea[e.name]&&""!==ea[e.name]&&(r.push(rv(e.name)),n.push(ea[e.name]),s.push("?"));if(0===r.length)return;let o=`INSERT INTO ${rv(y)}.${rv(L)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await tG("/api/mysql/query",{id:e,connectionString:t,sql:o,params:n}),eo(!1),el({}),ey(L,q,ei,ed)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[L,B,ea,e,t,y,ey,q,ei,ed]),eM=(0,s.useCallback)(async()=>{if(0===Z.size||!H||!L)return;let r=I.length>0?I:B.map(e=>e.name),n=0;for(let s of Array.from(Z).sort((e,t)=>t-e)){let o=H.rows[s];if(!o)continue;let a=[],l=[];for(let e of r)null===o[e]||void 0===o[e]?a.push(`${rv(e)} IS NULL`):(a.push(`${rv(e)} = ?`),l.push(o[e]));let i=`DELETE FROM ${rv(y)}.${rv(L)} WHERE ${a.join(" AND ")} LIMIT 1`;try{await tG("/api/mysql/query",{id:e,connectionString:t,sql:i,params:l})}catch{n++}}Y(new Set),X(!1),ey(L,q,ei,ed),n>0&&alert(f("mysql.deleteRowsFailed",{count:n}))},[Z,H,L,I,B,e,t,y,ey,q,ei,ed]),eE=(0,s.useCallback)(async r=>{if(!L)return;if(Z.size>0&&H){let e,t=H.fields.map(e=>e.name),n=Array.from(Z).sort((e,t)=>e-t).map(e=>H.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${rv(y)}.${rv(L)}`;try{let s=await t0("/api/mysql/export",{id:e,connectionString:t,sql:n,format:r}),o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=`${L}.${r}`,a.click(),URL.revokeObjectURL(o)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[L,e,t,y,Z,H]),eP=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),e$=Math.max(1,Math.ceil(J/50)),eT=(0,s.useCallback)(e=>{L&&(V(e),ey(L,e,ei,ed))},[L,ey,ei,ed]),eR=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ec(r),V(0),Y(new Set),L&&ey(L,0,r,ed)},[ei,ed,L,ey]),eB=(0,s.useCallback)(()=>{ec({}),V(0),Y(new Set),L&&ey(L,0,{},ed)},[ed,L,ey]),eF=(0,s.useCallback)(e=>{eu(e),V(0),Y(new Set),L&&ey(L,0,ei,e)},[ei,L,ey]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
12
+ relative transition-colors cursor-pointer
13
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
14
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:x,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC2C"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===g&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===g&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("mysql.connectionFailed")}),"connected"===g&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:f("mysql.connected")}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rb(m)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?f("browser.exitMaximize",{modKey:(0,tb.Mu)()}):f("browser.maximize",{modKey:(0,tb.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===g&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("mysql.connecting")]}),"error"===g&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:v}),(0,n.jsx)("button",{onClick:ew,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:y,onChange:e=>{N(e.target.value),M(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:y}),(0,n.jsx)("button",{onClick:ek,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:f("mysql.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>$(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${P===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("mysql.filterTable"),view:f("mysql.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.filter(e=>"table"===P?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${L===e.name?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rk,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===C.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("mysql.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:`px-3 py-1.5 text-xs transition-colors ${T===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("mysql.tabStructure"),data:f("mysql.tabData"),sql:"SQL"}[e]},e)),L&&"data"===T&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("mysql.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eB,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("mysql.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),Z.size>0&&!G&&(0,n.jsx)("button",{onClick:()=>X(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("mysql.deleteNRows",{count:Z.size})}),G&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("mysql.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eM,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>X(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Z.size>0?f("mysql.copyCsvSelected"):f("mysql.copyCsvAll"),children:Z.size>0?f("mysql.copyCSV"):f("mysql.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Z.size>0?f("mysql.copyJsonSelected"):f("mysql.copyJsonAll"),children:Z.size>0?f("mysql.copyJSON"):f("mysql.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:L||"sql"===T?"structure"===T?(0,n.jsx)(rN,{columns:B,primaryKeys:I,foreignKeys:A,indexes:z}):"data"===T?(0,n.jsx)(rS,{result:H,loading:K,columns:B,page:q,totalPages:e$,totalRows:J,onPageChange:eT,filters:ei,sort:ed,onFilterChange:eR,onSortChange:eF,selectedRows:Z,onSelectedRowsChange:e=>{Y(e),X(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!H)return;let t=H.rows[e],r={};for(let e of B)r[e.name]=null==t[e.name]?"":rw(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eL,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(rL,{sqlInput:ex,onSqlChange:em,onExecute:eC,onKeyDown:eP,result:eh,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("mysql.selectTable")})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===g?"bg-green-500":"error"===g?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[g]}),"connected"===g&&L&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:L}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rb(m)})]})]})})}function rN({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("mysql.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-accent/50",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-500 mr-1",title:a("mysql.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate",title:e.definition,children:e.name},e.name))})]})]})}function rC({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:i,anchorRect:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(e?.op||"="),[h,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,x.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let b="IS NULL"!==u&&"IS NOT NULL"!==u,v=()=>{(!b||h.trim())&&t({op:u,value:h.trim(),enabled:!0})},j=g?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=c.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=c.bottom+2-k;return(0,n.jsx)(x.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lg p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),d("mysql.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:i})]}),(0,n.jsx)("select",{value:u,onChange:e=>m(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:rg.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:d("IN"===u?"mysql.commaValues":"LIKE"===u?"mysql.likePattern":"mysql.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!h.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:d("mysql.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:d("mysql.clearFilter")})]})]})})}function rS({result:e,loading:t,columns:r,page:a,totalPages:l,totalRows:i,onPageChange:c,filters:d,sort:u,onFilterChange:x,onSortChange:m,selectedRows:h,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:w,isAddingRow:k,newRowValues:y,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:L,onCellCopy:M}){let{t:E}=(0,o.Bd)(),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),$(null)):null!==p?(e.stopPropagation(),w()):k&&(e.stopPropagation(),L()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[P,p,k,w,L]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("mysql.selectTableForData")});let B=e?.fields||[],F=e?.rows||[],I={};for(let e of r)I[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=F.length>0&&h.size===F.length,A=h.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=A)},onChange:()=>{D?f(new Set):f(new Set(F.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),B.map(e=>{let t=u?.column===e.name?u.dir:null,r=d[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?m({column:t,dir:"DESC"}):m(null):m({column:t,dir:"ASC"}))},children:[e.name,I[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:I[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),P===e.name)return void $(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),$(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),P===e.name&&(0,n.jsx)(rC,{filter:r||null,onApply:t=>{x(e.name,t),$(null)},onClear:()=>{x(e.name,null),$(null)},onToggle:t=>{r&&x(e.name,{...r,enabled:t})},onClose:()=>$(null),colName:e.name,anchorRect:T})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[k&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:L,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),B.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:y[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),F.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-accent/50 ${h.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-emerald-500 hover:text-emerald-400",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:w,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:h.has(t),onChange:()=>{let e;(e=new Set(h)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),B.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),M(rw(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rk,{text:rw(e[r.name])})},r.name))]},t))]})]}),0===F.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:k,className:"px-1.5 py-0.5 text-[10px] text-emerald-500 hover:text-emerald-400 disabled:opacity-30",children:E("mysql.addRow")}),(0,n.jsx)("span",{children:E("mysql.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>c(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>c(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rL({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,loading:i,sqlRef:c,onCellCopy:d}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:c,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("mysql.sqlPlaceholder",{modKey:(0,tb.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"mysql.executing":"mysql.execute")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("mysql.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("mysql.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("mysql.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:a.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:a.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),d(rw(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rk,{text:rw(e[t.name])})},t.name))},t))})]})})]})}tq({type:"mysql",idPrefix:"mysql",match:e=>e.trim().toLowerCase().startsWith("mysql://"),parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"mysql";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(ry,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){await tJ("mysql",e.id)}});let rM={string:{label:"S",color:"text-emerald-500 bg-emerald-500/10"},hash:{label:"H",color:"text-blue-500 bg-blue-500/10"},list:{label:"L",color:"text-orange-500 bg-orange-500/10"},set:{label:"SET",color:"text-teal-500 bg-teal-500/10"},zset:{label:"Z",color:"text-purple-500 bg-purple-500/10"},stream:{label:"STR",color:"text-pink-500 bg-pink-500/10"}};function rE({type:e}){let t=rM[e]||{label:"?",color:"text-muted-foreground bg-muted"};return(0,n.jsx)("span",{className:`inline-block text-[9px] font-mono font-bold leading-none px-1 py-0.5 rounded flex-shrink-0 ${t.color}`,children:t.label})}function rP({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),c=(0,x.F2)(),d=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=c?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.height??window.innerHeight,d=t.top-o,u=t.bottom-o,x=d>i/2;a({x:t.left-s,y:x?d-4:u+4,above:x}),r(!0)},350)},[c]),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),r(!1)},[]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:d,onMouseLeave:u,children:[e,t&&(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] max-w-[500px] max-h-[200px] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lg whitespace-pre-wrap break-all select-text",style:{left:o.x,top:o.y,transform:o.above?"translateY(-100%)":void 0},children:e})})]})}function r$({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:x,timestamp:m,onTitleMouseDown:h}){var f;let{t:p}=(0,o.Bd)(),{showToast:g}=(0,E.dj)(),[b,v]=(0,s.useState)("connecting"),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)([]),[S,L]=(0,s.useState)("0"),[M,P]=(0,s.useState)(!1),[$,T]=(0,s.useState)("*"),[R,B]=(0,s.useState)(!1),[F,I]=(0,s.useState)(null),[D,A]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[_,H]=(0,s.useState)(null),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)("data"),[U,J]=(0,s.useState)(""),[Q,Z]=(0,s.useState)(""),[Y,G]=(0,s.useState)([]),[X,ee]=(0,s.useState)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useCallback)(async()=>{v("connecting"),w("");try{let r=await tG("/api/redis/connect",{id:e,connectionString:t});y(r),v("connected")}catch(e){w(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{en()},[en]);let es=(0,s.useCallback)(async(r,n,s)=>{B(!0);try{let o=await tG("/api/redis/keys",{id:e,connectionString:t,pattern:r,cursor:n,count:200});C(e=>s?[...e,...o.keys]:o.keys),L(o.cursor),P(o.hasMore)}catch{}B(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&es($,"0",!1)},[b]);let eo=(0,s.useCallback)(()=>{I(null),A(null),es($,"0",!1)},[$,es]),ea=(0,s.useCallback)(async r=>{I(r),z(!0),H(null),q(!1);try{let n=await tG("/api/redis/get",{id:e,connectionString:t,key:r});A(n)}catch(e){A(null),g(e instanceof Error?e.message:p("redis.loadFailed"))}z(!1)},[e,t,g]),el=(0,s.useCallback)(async()=>{if(F)try{await tG("/api/redis/delete",{id:e,connectionString:t,keys:[F]}),I(null),A(null),q(!1),es($,"0",!1)}catch(e){g(e instanceof Error?e.message:p("redis.deleteFailed"))}},[F,e,t,$,es,g]),ei=(0,s.useCallback)(async()=>{if(F&&null!==_)try{await tG("/api/redis/set",{id:e,connectionString:t,key:F,value:_,type:"string"}),H(null),ea(F),g(p("common.saved"))}catch(e){g(e instanceof Error?e.message:p("redis.saveFailed"))}},[F,_,e,t,ea,g]),ec=(0,s.useCallback)(async()=>{try{let r=await tG("/api/redis/command",{id:e,connectionString:t,command:"INFO"});J("string"==typeof r.result?r.result:String(r.result))}catch{}},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&"info"===V&&ec()},[b,V,ec]);let ed=(0,s.useCallback)(async()=>{let r,n=Q.trim();if(!n)return;ee(!0),Z("");let s=[],o=/(?:"([^"]*)")|(?:'([^']*)')|(\S+)/g;for(;null!==(r=o.exec(n));)s.push(r[1]??r[2]??r[3]);let a=s[0]||"",l=s.slice(1);try{let r=await tG("/api/redis/command",{id:e,connectionString:t,command:a,args:l});G(e=>[...e,{command:n,result:r.result,duration:r.duration,isError:!1}])}catch(e){G(t=>[...t,{command:n,result:e instanceof Error?e.message:String(e),duration:0,isError:!0}])}ee(!1)},[Q,e,t]);return(0,s.useEffect)(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[Y]),(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
15
+ relative transition-colors cursor-pointer
16
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
17
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:x,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"♦"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===b&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===b&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:p("common.connectionFailed")}),"connected"===b&&k&&(0,n.jsxs)("span",{className:"text-[10px] text-red-500 flex-shrink-0",children:["v",k.version," \xb7 ",k.dbSize," keys \xb7 ",k.memory]}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(m)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?p("browser.exitMaximize",{modKey:(0,tb.Mu)()}):p("browser.maximize",{modKey:(0,tb.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:p("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===b&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),p("common.connecting"),"..."]}),"error"===b&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:j}),(0,n.jsx)("button",{onClick:en,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:p("common.retry")})]}),"connected"===b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:$,onChange:e=>T(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eo()},placeholder:p("redis.scanPlaceholder"),className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("button",{onClick:eo,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:p("redis.scanSearch"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"6.5",cy:"6.5",r:"4.5"}),(0,n.jsx)("path",{d:"M10 10l4 4"})]})}),(0,n.jsx)("button",{onClick:()=>es($,"0",!1),className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-accent active:bg-accent/50 transition-colors",title:p("common.refresh"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[N.map(e=>(0,n.jsxs)("div",{onClick:()=>ea(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${F===e.key?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)(rE,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rP,{text:e.key})})]},e.key)),0===N.length&&!R&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:p("redis.noKeys")}),R&&(0,n.jsx)("div",{className:"p-2 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})}),M&&!R&&(0,n.jsx)("button",{onClick:()=>es($,S,!0),className:"w-full py-1.5 text-[10px] text-brand hover:text-brand/80 transition-colors",children:p("redis.loadMore")})]}),(0,n.jsxs)("div",{className:"px-2 py-1 border-t border-border text-[10px] text-muted-foreground",children:[N.length," keys",M?"+":"",k?` / ${k.dbSize} total`:""]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["data","info","cli"].map(e=>(0,n.jsx)("button",{onClick:()=>K(e),className:`px-3 py-1.5 text-xs transition-colors ${V===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{data:p("redis.tabData"),info:p("redis.tabInfo"),cli:"CLI"}[e]},e)),F&&"data"===V&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[D&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["TTL: ",function(e,t){if(-1===e)return t("redis.neverExpires");if(-2===e)return t("redis.expired");if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m${e%60>0?` ${e%60}s`:""}`;let r=Math.floor(e/3600),n=Math.floor(e%3600/60);return`${r}h${n>0?` ${n}m`:""}`}(D.ttl,p),null!==D.size?` \xb7 ${null==(f=D.size)?"":f<1024?`${f} B`:f<1048576?`${(f/1024).toFixed(1)} KB`:`${(f/1048576).toFixed(1)} MB`}`:""]}),O?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-[10px] text-destructive",children:[p("common.confirm"),"?"]}),(0,n.jsx)("button",{onClick:el,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:p("common.confirm")}),(0,n.jsx)("button",{onClick:()=>q(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:p("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>q(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:p("common.delete")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:"data"===V?(0,n.jsx)(rT,{selectedKey:F,keyValue:D,keyLoading:W,editingValue:_,onStartEdit:e=>H(e),onEditChange:H,onSaveEdit:ei,onCancelEdit:()=>H(null),onCellCopy:e=>{navigator.clipboard.writeText(e),g(p("common.copied"))}}):"info"===V?(0,n.jsx)(rR,{infoText:U,onRefresh:ec}):(0,n.jsx)(rB,{cliInput:Q,onInputChange:Z,onExecute:ed,history:Y,loading:X,endRef:et,inputRef:er})})]})]})]})]})})}function rT({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:a,onEditChange:l,onSaveEdit:i,onCancelEdit:c,onCellCopy:d}){let{t:u}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.selectKey")});if(r)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if(!t)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.keyNotExist")});let{type:x,value:m}=t;if("string"===x){let t=String(m??""),r=null!==s;return(0,n.jsxs)("div",{className:"p-3 h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)(rE,{type:"string"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsx)("span",{className:"flex-1"}),r?(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:i,className:"px-2 py-0.5 text-[10px] text-white bg-brand rounded hover:bg-brand/90",children:u("common.save")}),(0,n.jsx)("button",{onClick:c,className:"px-2 py-0.5 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground",children:u("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>a(t),className:"px-2 py-0.5 text-[10px] text-brand hover:text-brand/80 bg-brand/10 rounded transition-colors",children:u("common.edit")})]}),r?(0,n.jsx)("textarea",{value:s,onChange:e=>l(e.target.value),className:"flex-1 w-full px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-none focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}):(0,n.jsx)("pre",{className:"flex-1 overflow-auto text-xs font-mono bg-muted/30 rounded p-2 whitespace-pre-wrap break-all select-text cursor-text",onContextMenu:e=>{e.preventDefault(),d(t)},children:t})]})}if("hash"===x){let t=Object.entries(m||{});return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rE,{type:"hash"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[t.length," fields"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-1/3",children:"Field"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[150px]",onContextMenu:t=>{t.preventDefault(),d(e)},children:(0,n.jsx)(rP,{text:e})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:e=>{e.preventDefault(),d(t)},children:(0,n.jsx)(rP,{text:t})})]},e))})]})})]})}if("list"===x){let t=m?.items||[],r=m?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rE,{type:"list"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nItems",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-16",children:"#"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 text-muted-foreground",children:t}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),d(e)},children:(0,n.jsx)(rP,{text:e})})]},t))})]})})]})}if("set"===x){let t=m?.items||[],r=m?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rE,{type:"set"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"})})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[400px]",onContextMenu:t=>{t.preventDefault(),d(e)},children:(0,n.jsx)(rP,{text:e})})},t))})]})})]})}if("zset"===x){let t=m?.items||[],r=m?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rE,{type:"zset"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"}),(0,n.jsx)("th",{className:"px-2 py-1 text-right text-muted-foreground font-medium border-b border-border w-28",children:"Score"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),d(e.member)},children:(0,n.jsx)(rP,{text:e.member})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-right text-muted-foreground",children:e.score})]},t))})]})})]})}if("stream"===x){let t=m?.entries||[],r=m?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rE,{type:"stream"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nEntries",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-40",children:"ID"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Fields"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>{let r=[];for(let e=0;e<t.length;e+=2)r.push(`${t[e]}: ${t[e+1]}`);return(0,n.jsxs)("tr",{className:"hover:bg-accent/50",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-muted-foreground",children:e}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",children:(0,n.jsx)(rP,{text:r.join(", ")})})]},e)})})]})})]})}return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.unsupportedType",{type:x})})}function rR({infoText:e,onRefresh:t}){let{t:r}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});let s=[],a=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))a={title:e.replace(/^#\s*/,""),items:[]},s.push(a);else if(a&&e.includes(":")){let t=e.indexOf(":");a.items.push({key:e.slice(0,t),value:e.slice(t+1)})}}}return(0,n.jsxs)("div",{className:"p-2 space-y-3 overflow-auto h-full",children:[(0,n.jsx)("div",{className:"flex justify-end",children:(0,n.jsx)("button",{onClick:t,className:"px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:r("common.refresh")})}),s.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1 font-medium",children:e.title}),(0,n.jsx)("div",{className:"space-y-0",children:e.items.map(({key:e,value:t})=>(0,n.jsxs)("div",{className:"flex items-start gap-2 px-1.5 py-0.5 text-xs hover:bg-accent/50 rounded",children:[(0,n.jsx)("span",{className:"text-muted-foreground font-mono flex-shrink-0 w-48 truncate",children:e}),(0,n.jsx)("span",{className:"font-mono text-foreground break-all",children:t})]},e))})]},e.title))]})}function rB({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:a,endRef:l,inputRef:i}){let{t:c}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto p-2 font-mono text-xs space-y-2",onClick:()=>i.current?.focus(),children:[0===s.length&&(0,n.jsx)("div",{className:"text-muted-foreground text-center py-4",children:c("redis.cliHint")}),s.map((e,t)=>(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"text-brand",children:[(0,n.jsx)("span",{className:"text-muted-foreground mr-1",children:">"}),e.command,e.duration>0&&(0,n.jsxs)("span",{className:"text-muted-foreground/50 ml-2",children:["(",e.duration,"ms)"]})]}),(0,n.jsx)("pre",{className:`whitespace-pre-wrap break-all mt-0.5 ${e.isError?"text-destructive":"text-foreground"}`,children:e.isError?`(error) ${e.result}`:function e(t,r=0){let n=" ".repeat(r);return null===t?`${n}(nil)`:"number"==typeof t?`${n}(integer) ${t}`:"string"==typeof t?`${n}"${t}"`:Array.isArray(t)?0===t.length?`${n}(empty array)`:t.map((t,r)=>`${n}${r+1}) ${e(t,0)}`).join("\n"):`${n}${String(t)}`}(e.result)})]},t)),(0,n.jsx)("div",{ref:l})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1.5 border-t border-border bg-card/30 flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-xs text-brand font-mono flex-shrink-0",children:">"}),(0,n.jsx)("input",{ref:i,type:"text",value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{"Enter"!==e.key||a||r()},placeholder:c("redis.cliPlaceholder"),className:"flex-1 min-w-0 text-xs font-mono bg-transparent border-0 focus:outline-none",autoComplete:"off",spellCheck:!1,disabled:a}),a&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}tq({type:"redis",idPrefix:"redis",match(e){let t=e.trim().toLowerCase();return t.startsWith("redis://")||t.startsWith("rediss://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"0";r=`db${n}@${e.hostname}${e.port?":"+e.port:":6379"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(r$,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){await tJ("redis",e.id)}});let rF=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function rI(e,t){return rF[t.indexOf(e)%rF.length]}function rD(e){if(!e)return"";let t=new Date(e);return isNaN(t.getTime())?"":`${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function rA({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),l=(0,s.useRef)([]),i=(0,s.useRef)(0),c=(0,s.useRef)(null),d=(0,s.useRef)({w:0,h:0}),u=(0,s.useRef)(new Map),[x,m]=(0,s.useState)(null),h=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=o.current;if(!e)return;let t=new ResizeObserver(e=>{let{width:t,height:r}=e[0].contentRect,n=d.current;if(t===n.w&&r===n.h)return;if(n.w>0&&n.h>0&&l.current.length>0){let e=t/n.w,s=r/n.h;l.current.forEach(t=>{t.x=(t.x||0)*e,t.y=(t.y||0)*s})}d.current={w:t,h:r};let s=a.current;s&&(s.width=t,s.height=r)});return t.observe(e),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{let{w:t,h:r}=d.current,n=t||o.current?.clientWidth||600,s=r||o.current?.clientHeight||400;0===t&&(d.current={w:n,h:s}),l.current=e.map((t,r)=>({...t,x:t.x??n/2+Math.cos(2*r*Math.PI/e.length)*Math.min(n,s)*.3,y:t.y??s/2+Math.sin(2*r*Math.PI/e.length)*Math.min(n,s)*.3,vx:0,vy:0})),u.current=new Map(l.current.map(e=>[e.id,e]))},[e]),(0,s.useEffect)(()=>{let e=u.current;return i.current=requestAnimationFrame(function n(){let{w:s,h:o}=d.current;if(0===s||0===o){i.current=requestAnimationFrame(n);return}let u=l.current;u.forEach(e=>{e.vx=(e.vx||0)+(s/2-(e.x||0))*.001,e.vy=(e.vy||0)+(o/2-(e.y||0))*.001});for(let e=0;e<u.length;e++)for(let t=e+1;t<u.length;t++){let r=(u[e].x||0)-(u[t].x||0),n=(u[e].y||0)-(u[t].y||0),s=Math.sqrt(r*r+n*n)||1,o=2e3/(s*s),a=r/s*o,l=n/s*o;u[e].vx+=a,u[t].vx-=a,u[e].vy+=l,u[t].vy-=l}t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;let s=(n.x||0)-(r.x||0),o=(n.y||0)-(r.y||0),a=Math.sqrt(s*s+o*o)||1,l=(a-100)*.01,i=s/a*l,c=o/a*l;r.vx+=i,n.vx-=i,r.vy+=c,n.vy-=c}),u.forEach(e=>{c.current?.nodeId!==e.id&&(e.vx=.6*(e.vx||0),e.vy=.6*(e.vy||0),e.x=Math.max(20,Math.min(s-20,(e.x||0)+.1*(e.vx||0))),e.y=Math.max(20,Math.min(o-20,(e.y||0)+.1*(e.vy||0))))});let x=a.current?.getContext("2d");x&&(x.clearRect(0,0,s,o),x.lineWidth=1.5,t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;x.strokeStyle="#666",x.beginPath(),x.moveTo(r.x,r.y),x.lineTo(n.x,n.y),x.stroke();let s=Math.atan2(n.y-r.y,n.x-r.x),o=n.x-24*Math.cos(s),a=n.y-24*Math.sin(s);x.fillStyle="#666",x.beginPath(),x.moveTo(o,a),x.lineTo(o-8*Math.cos(s-.3),a-8*Math.sin(s-.3)),x.lineTo(o-8*Math.cos(s+.3),a-8*Math.sin(s+.3)),x.closePath(),x.fill(),x.font="9px system-ui",x.fillStyle="#999",x.textAlign="center",x.fillText(t.type,(r.x+n.x)/2,(r.y+n.y)/2-4)}),u.forEach(e=>{let t=e.labels[0]||"",n=t?rI(t,r):"#888";x.beginPath(),x.arc(e.x,e.y,20,0,2*Math.PI),x.fillStyle=n,x.fill();let s=h.current?.id===e.id;x.strokeStyle=s?"#fff":"rgba(255,255,255,0.3)",x.lineWidth=s?2.5:1,x.stroke(),x.font="10px system-ui",x.fillStyle="#fff",x.textAlign="center",x.textBaseline="middle";let o=String(e.properties.name||e.properties.title||e.properties.id||t||e.id);x.fillText(o.length>8?o.slice(0,7)+"…":o,e.x,e.y)}),i.current=requestAnimationFrame(n))}),()=>cancelAnimationFrame(i.current)},[e,t,r]);let f=(0,s.useCallback)(e=>{let t=a.current?.getBoundingClientRect();if(!t)return null;let r=e.clientX-t.left,n=e.clientY-t.top;return l.current.find(e=>{let t=(e.x||0)-r,s=(e.y||0)-n;return t*t+s*s<400})||null},[]);return(0,n.jsxs)("div",{ref:o,className:"relative w-full h-full",children:[(0,n.jsx)("canvas",{ref:a,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=f(e);if(t){let r=a.current.getBoundingClientRect();c.current={nodeId:t.id,offsetX:e.clientX-r.left-(t.x||0),offsetY:e.clientY-r.top-(t.y||0)}}},onMouseMove:e=>{if(c.current){let t=a.current.getBoundingClientRect(),r=l.current.find(e=>e.id===c.current.nodeId);r&&(r.x=e.clientX-t.left-c.current.offsetX,r.y=e.clientY-t.top-c.current.offsetY,r.vx=0,r.vy=0)}else{let t=f(e);h.current=t,m(t)}},onMouseUp:()=>{c.current=null},onMouseLeave:()=>{c.current=null,h.current=null,m(null)}}),x&&!c.current&&(0,n.jsxs)("div",{className:"absolute top-2 left-2 bg-popover text-popover-foreground border border-border rounded px-2 py-1 text-xs max-w-[300px] pointer-events-none",children:[(0,n.jsxs)("div",{className:"font-medium",children:[x.labels.join(", ")," #",String(x.id)]}),Object.entries(x.properties).slice(0,8).map(([e,t])=>(0,n.jsxs)("div",{className:"truncate",children:[(0,n.jsxs)("span",{className:"text-muted-foreground",children:[e,":"]})," ",String(t)]},e))]})]})}function rW({id:e,connectionString:t,displayName:r,selected:o,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,timestamp:x,onTitleMouseDown:m}){let[h,f]=(0,s.useState)("connecting"),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)("labels"),[S,L]=(0,s.useState)(""),[M,E]=(0,s.useState)(null),[P,$]=(0,s.useState)(!1),[T,R]=(0,s.useState)(""),B=(0,s.useRef)(null),[F,I]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[W,z]=(0,s.useState)("schema"),_=(0,s.useCallback)(async()=>{f("connecting");try{let r=await tG("/api/neo4j/connect",{id:e,connectionString:t});v(r),f("connected")}catch(e){g(e instanceof Error?e.message:String(e)),f("error")}},[e,t]);(0,s.useEffect)(()=>{_()},[_]);let H=(0,s.useCallback)(async()=>{y(!0);try{let r=await tG("/api/neo4j/schema",{id:e,connectionString:t});w(r)}catch{}y(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===h&&H()},[h,H]);let O=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){$(!0),R("");try{var s;let r,o,a=await tG("/api/neo4j/query",{id:e,connectionString:t,cypher:n});E(a);let{nodes:l,rels:i}=(s=a.records,r=new Map,o=[],s.forEach(e=>Object.values(e).forEach(function e(t){if(t&&"object"==typeof t)if("node"===t._type){let e=t._id;r.has(e)||r.set(e,{id:e,labels:t._labels||[],properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))})}else if("relationship"===t._type)o.push({id:t._id,type:t._relType,startId:t._start,endId:t._end,properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))});else if("path"===t._type){let r=t.segments;r?.forEach(t=>{e(t.start),e(t.relationship),e(t.end)})}else Array.isArray(t)&&t.forEach(e)})),{nodes:Array.from(r.values()),rels:o});l.length>0&&(I(l),A(i))}catch(e){R(e instanceof Error?e.message:String(e))}$(!1)}},[e,t,S]),q=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;L(t),z("cypher"),O(t)},[O]),V=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;L(t),z("graph"),O(t)},[O]);return(0,n.jsx)("div",{className:"flex flex-col items-start",onClick:c,children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground relative transition-colors ${o?"ring-1 ring-ring":""} rounded-lg overflow-hidden`,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:u,onMouseDown:m,className:"flex items-center gap-2 px-4 py-1.5 border-b border-border cursor-grab active:cursor-grabbing select-none",children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"⬡"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===h&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"connected"===h&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:"Connected"}),"error"===h&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:"Error"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rD(x)}),"connected"===h&&b&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:["v",b.version," \xb7 ",b.nodeCount.toLocaleString(),"n \xb7 ",b.relationshipCount.toLocaleString(),"r"]}),(0,n.jsx)("span",{className:"flex-1"}),"connected"===h&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),H(),_()},disabled:k,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0 disabled:opacity-40",title:"Refresh",children:(0,n.jsx)("svg",{className:`w-3.5 h-3.5 ${k?"animate-spin":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a?(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25"}):(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:a&&l?l-41:i??360},className:"flex flex-col overflow-hidden",children:["connecting"===h&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Connecting..."]}),"error"===h&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-xs p-4 gap-2",children:[(0,n.jsx)("p",{className:"text-destructive",children:p}),(0,n.jsx)("button",{onClick:_,className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Retry"})]}),"connected"===h&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:["schema","cypher","graph"].map(e=>(0,n.jsx)("button",{onClick:()=>z(e),className:`px-3 py-1.5 text-xs transition-colors ${W===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{schema:"Schema",cypher:"Cypher",graph:"Graph"}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex",children:["schema"===W&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-40 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:(0,n.jsx)("div",{className:"flex-1 overflow-y-auto text-xs",children:[{key:"labels",label:"Labels",count:j?.labels.length},{key:"relationships",label:"Relationships",count:j?.relationshipTypes.length},{key:"properties",label:"Properties",count:j?.propertyKeys.length},{key:"indexes",label:"Indexes",count:j?.indexes.length},{key:"constraints",label:"Constraints",count:j?.constraints.length}].map(e=>(0,n.jsxs)("div",{onClick:()=>C(e.key),className:`flex items-center gap-1.5 px-2 py-1.5 cursor-pointer truncate transition-colors ${N===e.key?"bg-brand/10 text-brand":"hover:bg-white/10 text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:e.label}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count??0})]},e.key))})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[k&&(0,n.jsxs)("div",{className:"flex items-center justify-center p-4 gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})," Loading..."]}),!k&&"labels"===N&&j?.labels.map(e=>(0,n.jsxs)("div",{onClick:()=>q(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:rI(e.name,j.labels.map(e=>e.name))}}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!k&&"relationships"===N&&j?.relationshipTypes.map(e=>(0,n.jsxs)("div",{onClick:()=>V(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:"→"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!k&&"properties"===N&&j?.propertyKeys.map(e=>(0,n.jsx)("div",{className:"px-2 py-1 font-mono text-muted-foreground hover:bg-brand/10 transition-colors",children:e},e)),!k&&"indexes"===N&&j?.indexes.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),") \xb7 ",e.state]})]},e.name)),!k&&"constraints"===N&&j?.constraints.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),")"]})]},e.name))]})]}),"cypher"===W&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("textarea",{ref:B,value:S,onChange:e=>L(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),O())},placeholder:`Enter Cypher query (${(0,tb.Mu)()}+Enter to run)`,className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center justify-between mt-1",children:[(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[(0,tb.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>O(),disabled:P||!S.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:P?"Running...":"Execute"})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[T&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:T}),M&&!T&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-2 py-1 text-[10px] text-muted-foreground border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("span",{children:[M.records.length," rows"]}),(0,n.jsxs)("span",{children:[M.duration,"ms"]}),Object.entries(M.counters).filter(([,e])=>e>0).map(([e,t])=>(0,n.jsxs)("span",{children:[e,": ",t]},e))]}),M.records.length>0&&(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:M.keys.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e},e))})}),(0,n.jsx)("tbody",{children:M.records.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:M.keys.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",children:null===e[t]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):function(e){if(null==e)return"null";if("object"==typeof e){if("node"===e._type){let t=e._labels?.[0]||"",r=e.name||e.title||e.id||"";return`(${t}${r?": "+r:""})`}return"relationship"===e._type?`[${e._relType}]`:JSON.stringify(e)}return String(e)}(e[t])},t))},t))})]})]})]})]}),"graph"===W&&(0,n.jsx)("div",{className:"flex-1 relative",children:0===F.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-xs text-muted-foreground gap-2",children:[(0,n.jsx)("p",{children:"Run a Cypher query that returns nodes to visualize"}),(0,n.jsx)("button",{onClick:()=>{let e="MATCH (a)-[r]->(b) RETURN a, r, b LIMIT 50";L(e),O(e)},className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Load sample graph"})]}):(0,n.jsx)(rA,{nodes:F,rels:D,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!a&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===h?"bg-green-500":"error"===h?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:"Connecting",connected:"Connected",error:"Error"}[h]}),"connected"===h&&b&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:b.edition}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rD(x)})]})]})})}function rz({onAdd:e,onCancel:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(""),[i,c]=(0,s.useState)("");return(0,n.jsxs)("div",{className:"flex gap-1 mb-1",children:[(0,n.jsx)("input",{type:"text",value:a,onChange:e=>l(e.target.value),placeholder:r("console.namePlaceholder"),className:"w-24 flex-shrink-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0,onKeyDown:e=>{"Escape"===e.key&&t()}}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:r("console.commandPlaceholder"),className:"flex-1 min-w-0 px-2 py-1 text-xs font-mono rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring",onKeyDown:r=>{"Enter"!==r.key||r.nativeEvent.isComposing?"Escape"===r.key&&t():(r.preventDefault(),r.stopPropagation(),a.trim()&&i.trim()&&e(a.trim(),i.trim()))}})]})}function r_({label:e,commands:t,isAdding:r,onStartAdd:s,onAdd:a,onCancelAdd:l,onDelete:i,onExecute:c}){let{t:d}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),(0,n.jsx)("button",{type:"button",onClick:s,className:"p-0.5 text-muted-foreground hover:text-foreground rounded",children:(0,n.jsx)(tB.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(rz,{onAdd:(e,t)=>a(e,t),onCancel:l}),0===t.length&&!r&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:d("console.noCustomCommands")}),t.map((e,t)=>(0,n.jsx)(ex.m,{content:e.command,children:(0,n.jsxs)("div",{className:"flex items-center group min-w-0",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>c(e.command),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-accent transition-colors",children:[(0,n.jsx)(tH.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),(0,n.jsx)("button",{type:"button",onClick:()=>i(t),className:"p-1 text-muted-foreground hover:text-destructive rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",children:(0,n.jsx)(q.A,{className:"w-3 h-3"})})]})},t))]})}function rH({cwd:e,show:t,onClose:r,onExecute:a,onAddPluginItem:l}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)([]),[x,m]=(0,s.useState)([]),[h,f]=(0,s.useState)(null),p=(0,s.useRef)(null),g=(0,s.useCallback)(async()=>{let[t,r]=await Promise.all([i.t4.runPromiseExit(tv("/api/services/config?scope=global")),i.t4.runPromiseExit(tL(e))]);"Success"===t._tag&&u(t.value.customCommands||[]),"Success"===r._tag&&m(r.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{t&&queueMicrotask(()=>g())},[t,g]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{p.current&&!p.current.contains(e.target)&&(r(),f(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let b=(0,s.useCallback)(async e=>{u(e);let t=await i.t4.runPromiseExit(tw("/api/services/config",{scope:"global",customCommands:e}));"Failure"===t._tag&&console.error("Failed to save global commands:",t.cause)},[]),v=(0,s.useCallback)(async t=>{m(t);let r=await i.t4.runPromiseExit(tw("/api/services/config",{cwd:e,customCommands:t}));"Failure"===r._tag&&console.error("Failed to save project commands:",r.cause)},[e]),j=(0,s.useCallback)(e=>{r();let t=tK(e);t?l?.(t.type,e.trim()):a(e)},[r,a,l]);return t?(0,n.jsxs)("div",{ref:p,className:"absolute bottom-full left-0 mb-2 w-72 bg-popover border border-border rounded-lg shadow-lg z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(r_,{label:c("console.globalCommands"),commands:d,isAdding:"global"===h,onStartAdd:()=>f("global"),onAdd:(e,t)=>{b([...d,{name:e,command:t}]),f(null)},onCancelAdd:()=>f(null),onDelete:e=>b(d.filter((t,r)=>r!==e)),onExecute:j}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(r_,{label:c("console.projectCommands"),commands:x,isAdding:"project"===h,onStartAdd:()=>f("project"),onAdd:(e,t)=>{v([...x,{name:e,command:t}]),f(null)},onCancelAdd:()=>f(null),onDelete:e=>v(x.filter((t,r)=>r!==e)),onExecute:j})]}):null}function rO({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:a,onGridLayoutChange:l,onExecute:c,onAddPluginItem:d,onShowEnvManager:u,onOpenZsh:x,onOpenNote:m}){let{t:h}=(0,o.Bd)(),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(-1),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(0),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!1),[E,P]=(0,s.useState)([]),[$,T]=(0,s.useState)(!1),[R,B]=(0,s.useState)(0),F=(0,s.useRef)(null),I=(0,s.useRef)(null),D=(0,s.useRef)(!1),{projectCommands:A,globalCommands:W,expandCustomCommand:z,loadQuickCommands:_}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),a=(0,s.useCallback)(async()=>{let[t,n]=await Promise.all([i.t4.runPromiseExit(tL(e)),i.t4.runPromiseExit(tv("/api/services/config?scope=global"))]);"Success"===t._tag&&r(t.value.customCommands||[]),"Success"===n._tag&&o(n.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>a())},[a]);let l=[...t,...n],c=(0,s.useCallback)(e=>{let r=e.trim().split(/\s+/),s=r[0];if(!s.startsWith("/")||s.length<=1)return null;let o=s.slice(1),a=t.find(e=>e.name===o)??n.find(e=>e.name===o);return a?a.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:l,projectCommands:t,globalCommands:n,expandCustomCommand:c,loadQuickCommands:a}}(e);(0,s.useEffect)(()=>{F.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.startsWith("/")){let e=f.slice(1).toLowerCase(),t=[...A.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({...e,scope:"project"})),...W.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({...e,scope:"global"}))];queueMicrotask(()=>{P(t),T(t.length>0),B(0)})}else queueMicrotask(()=>T(!1))},[f,A,W]),(0,s.useEffect)(()=>{if($&&I.current){let e=I.current.children[R];e?.scrollIntoView({block:"nearest"})}},[R,$]);let H=(0,s.useCallback)(e=>{T(!1);let t=e.command,r=tK(t);r?d?.(r.type,t.trim()):c(t),p("")},[c,d]),O=(0,s.useCallback)(e=>{if(e.preventDefault(),D.current||!f.trim())return;let t=z(f)??f,r=tK(t);r?d?.(r.type,t.trim()):c(t),p(""),b(-1),j("")},[f,c,d,z]),q=(0,s.useCallback)(async()=>{let e;if(!F.current)return;let r=F.current.selectionStart||0,n=await i.t4.runPromiseExit((e={cwd:t,input:f,cursorPosition:r},ee.tryPromise({try:async()=>{let t=await fetch("/api/terminal/autocomplete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new et.uV({message:"POST /api/terminal/autocomplete failed",cause:e})})));if("Success"===n._tag){let e=n.value,t=e.suggestions;if(t&&t.length>0&&(k(t),N(0),S(!0),1===t.length)){let n=f.substring(0,e.replaceStart??0),s=f.substring(e.replaceEnd??r);p(n+t[0]+s),S(!1),setTimeout(()=>{if(F.current){let r=(e.replaceStart??0)+t[0].length;F.current.setSelectionRange(r,r)}},0)}}else console.error("Autocomplete error:",n.cause)},[t,f]),V=(0,s.useCallback)(e=>{if(!F.current)return;let t=F.current.selectionStart||0,r=f.substring(0,t),n=f.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;p(f.substring(0,o)+e+n),S(!1),setTimeout(()=>{if(F.current){let t=o+e.length;F.current.setSelectionRange(t,t)}},0)},[f]),K=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if($&&E.length>0){if("ArrowUp"===e.key){e.preventDefault(),B(e=>(e-1+E.length)%E.length);return}if("ArrowDown"===e.key){e.preventDefault(),B(e=>(e+1)%E.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),H(E[R]);return}if("Escape"===e.key){e.preventDefault(),T(!1);return}}if("Tab"===e.key){if(e.preventDefault(),C&&w.length>0){let e=(y+1)%w.length;N(e),V(w[e])}else q();return}if("Escape"===e.key&&C){e.preventDefault(),S(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===g&&j(f);let r=-1===g?t.length-1:Math.max(0,g-1);b(r),p(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===g)return;let r=g+1;r>=t.length?(b(-1),p(v)):(b(r),p(t[r]))}}},[g,f,v,C,w,y,q,V,$,E,R,H,r]);return(0,n.jsx)("div",{className:"border-t border-border p-4",children:(0,n.jsxs)("form",{onSubmit:O,className:"relative flex gap-2 items-center",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{L||_(),M(!L)},className:`p-2 rounded-lg transition-all ${L?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:h("console.quickCommands"),children:(0,n.jsx)(tA.A,{className:"w-4 h-4"})}),(0,n.jsx)(rH,{cwd:e,show:L,onClose:()=>M(!1),onExecute:c,onAddPluginItem:d})]}),m&&(0,n.jsx)("button",{type:"button",onClick:m,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:h("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>l(!a),className:`p-2 rounded-lg transition-all ${a?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:a?h("console.singleColumn"):h("console.dualColumn"),children:a?(0,n.jsx)(tW.A,{className:"w-4 h-4"}):(0,n.jsx)(tz.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:h("console.envVars"),children:(0,n.jsx)(t_.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:x,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:h("console.launchZsh"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}),(0,n.jsx)("input",{ref:F,type:"text",value:f,onChange:e=>{p(e.target.value),-1!==g&&(b(-1),j("")),S(!1)},onKeyDown:K,onCompositionStart:()=>{D.current=!0},onCompositionEnd:()=>{D.current=!1},placeholder:h("console.inputPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring font-mono"}),$&&E.length>0&&(0,n.jsx)("div",{ref:I,className:"absolute bottom-full left-0 right-0 mb-1 max-h-64 overflow-y-auto bg-popover border border-border rounded-lg shadow-lg z-50",children:E.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>H(e),className:`flex items-center gap-3 px-3 py-1.5 cursor-pointer text-sm ${t===R?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsxs)("span",{className:"font-mono font-medium text-foreground",children:["/",e.name]}),(0,n.jsx)("span",{className:"flex-1 text-muted-foreground truncate",children:e.command}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/60 flex-shrink-0",children:"project"===e.scope?h("console.scopeProject"):h("console.scopeGlobal")})]},`${e.scope}-${e.name}`))}),C&&w.length>1&&(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-1 bg-popover border border-border rounded-lg shadow-lg max-h-48 overflow-y-auto z-50",children:[(0,n.jsx)("div",{className:"py-1",children:w.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>V(e),className:`w-full px-3 py-1.5 text-left text-sm font-mono hover:bg-accent transition-colors ${t===y?"bg-accent":""}`,children:e},t))}),(0,n.jsx)("div",{className:"border-t border-border px-3 py-1 text-xs text-muted-foreground",children:h("console.tabSwitchEscClose")})]})]})})}function rq({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:a}=(0,o.Bd)();return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)("button",{onClick:r,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95 z-10",title:a("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),t&&(0,n.jsx)("button",{onClick:s,className:"absolute bottom-20 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-md rounded-full transition-all hover:shadow-lg active:scale-95 z-10",title:a("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})}tq({type:"neo4j",idPrefix:"neo4j",match(e){let t=e.trim().toLowerCase();return t.startsWith("neo4j://")||t.startsWith("neo4j+s://")||t.startsWith("bolt://")||t.startsWith("bolt+s://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t);r=`${e.hostname}${e.port?":"+e.port:":7687"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rW,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){await tJ("neo4j",e.id)}});let rV=null,rK="",rU=0,rJ=null,rQ=!1,rZ=new Map,rY=null,rG=null;function rX(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){rY&&(rY(t.commands),rY=null);return}let n=t.commandId;if(!n)return;let s=rZ.get(n);if(s){if("error"===r)s.onError(t.error);else{let{commandId:e,type:n,...o}=t;s.onData(r,o)}("exit"===r||"error"===r)&&rZ.delete(n)}}function r0(e){rV?.readyState===WebSocket.OPEN&&rV.send(JSON.stringify(e))}function r1(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);rK===r&&rV||(r7(),rQ=!1,rK=r,function e(){if(rQ||!rK)return;let t=new WebSocket(rK);rV=t,t.onopen=()=>{for(let e of(rU=0,rZ.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=rX,t.onclose=()=>{if(rV!==t||(rV=null,rQ))return;rJ&&clearTimeout(rJ);let r=Math.min(1e3*Math.pow(1.5,rU),1e4);rU++,rJ=setTimeout(e,r)},t.onerror=()=>{}}())}function r2(){return new Promise((e,t)=>{if(rV?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{rV?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function r5(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:i,rows:c,sourceId:d,onData:u,onError:x}=e;r1(o);try{await r2()}catch{x("WebSocket connection failed");return}rZ.delete(n),rZ.set(n,{onData:u,onError:x}),r0({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...i?{cols:i,rows:c}:{},...d?{sourceId:d}:{}})}async function r4(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;r1(r);try{await r2()}catch{s("WebSocket connection failed");return}rZ.set(t,{onData:n,onError:s}),r0({type:"attach",commandId:t})}function r3(e,t){r0({type:"stdin",commandId:e,data:t})}function r6(e,t,r){r0({type:"resize",commandId:e,cols:t,rows:r})}function r8(e){r0({type:"interrupt",pid:e})}async function r9(e){try{r1(e);try{await r2()}catch{return[]}return await new Promise(e=>{rY=t=>{e(t)},r0({type:"running"}),setTimeout(()=>{rY&&(rY=null,e([]))},3e3)})}finally{rG=null}}function r7(){if(rQ=!0,rJ&&(clearTimeout(rJ),rJ=null),rV){let e=rV;rV=null,e.close()}rZ.clear(),rY&&(rY([]),rY=null),rG=null,rK="",rU=0}function ne(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}let nt=new Set(["zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]),nr=[{key:"command",label:"console.bubbleCommand",triggers:["ls","git status","npm run dev"]},{key:"pty",label:"console.bubbleInteractive",triggers:["zsh","vim","python","top"]},{key:"browser",label:"console.bubbleBrowser",triggers:["https://…"]},{key:"database",label:"console.bubbleDatabase",triggers:["postgresql://","mysql://","redis://","neo4j://"]},{key:"notebook",label:"console.bubbleNotebook",triggers:["*.ipynb"]}];function nn({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a,onOpenNote:l}){let{t:c}=(0,o.Bd)(),{consoleItems:d,scrollRef:u,selectedCommandId:x,setSelectedCommandId:m,interruptCommand:h,sendStdin:f,deleteCommand:p,rerunCommand:g,ptySizeRef:b,resizePty:v,executeCommand:j,addPluginItem:w,closePluginItem:k,sleepingBubbles:y,handleBubbleSleep:N,handleBubbleWake:C,scrollToBottom:S,currentCwd:L,commandHistoryRef:M,setCustomEnv:E,setAliases:P,saveBubbleOrder:$,hasMoreHistory:T,loadHistory:R,currentPage:B,isLoadingHistory:F,subscribePtyOutput:I,subscribePtyReset:D,subscribePtyRefresh:A}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,a]=(0,s.useState)([]),[l,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(new Set),[x,m]=(0,s.useState)(t||e),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)({}),[N,C]=(0,s.useState)({}),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),E=(0,s.useRef)(new Map),P=(0,s.useRef)(new Map),$=(0,s.useRef)(new Set),T=(0,s.useRef)([]),R=(0,s.useRef)(new Map),B=(0,s.useRef)(new Map),F=(0,s.useRef)(new Map),I=(0,s.useRef)(null),D=(0,s.useRef)(null),A=(0,s.useRef)([]),W=(0,s.useRef)("");W.current||(W.current="u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():`s_${Date.now()}_${Math.random().toString(36).slice(2)}`);let z=(0,s.useRef)(null);(0,s.useEffect)(()=>{n?.(e)},[]);let H=(0,s.useCallback)(()=>{if(E.current.size>0){let e=new Map(E.current);E.current.clear(),a(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}M.current=null},[]),O=(0,s.useCallback)((e,t)=>{if($.current.has(e)){let r=B.current.get(e);if(r&&r.size>0)for(let e of r)e(t);else F.current.has(e)||F.current.set(e,[]),F.current.get(e).push(t);return}let r=(P.current.get(e)||"")+t;if(r.length>2097152){let t=function(e){let t=e.slice(-2097152),r=0;if(t.length>0){let e=t.charCodeAt(0);e>=56320&&e<=57343&&(r=1)}let n=Math.min(t.length,64);for(let e=r;e<n;e++){let n=t.charCodeAt(e);if(27===n){r=e;break}if((!(n>=48)||!(n<=63))&&59!==n&&63!==n&&32!==n){n>=64&&n<=126&&(r=e+1);break}}return r>0?t.slice(r):t}(r);P.current.set(e,t),E.current.set(e,t)}else P.current.set(e,r),E.current.set(e,r);null===M.current&&(M.current=requestAnimationFrame(H))},[H]),q=(0,s.useCallback)((e,t=!1)=>{P.current.delete(e),$.current.delete(e),E.current.delete(e),F.current.delete(e),t||(B.current.delete(e),K.current.delete(e))},[]),V=(0,s.useCallback)((e,t)=>{B.current.has(e)||B.current.set(e,new Set),B.current.get(e).add(t);let r=F.current.get(e);if(r&&r.length>0){for(let e of r)t(e);F.current.delete(e)}return()=>{B.current.get(e)?.delete(t)}},[]),K=(0,s.useRef)(new Map),U=(0,s.useCallback)((e,t)=>(K.current.has(e)||K.current.set(e,new Set),K.current.get(e).add(t),()=>{K.current.get(e)?.delete(t)}),[]),J=(0,s.useRef)(new Map),Q=(0,s.useCallback)((e,t)=>(J.current.has(e)||J.current.set(e,new Set),J.current.get(e).add(t),()=>{J.current.get(e)?.delete(t)}),[]);(0,s.useEffect)(()=>{if(!S)return;let e=requestAnimationFrame(()=>{for(let e of J.current.values())for(let t of e)t()});return()=>cancelAnimationFrame(e)},[S]);let Z=(0,s.useCallback)(e=>(null!==M.current&&(cancelAnimationFrame(M.current),M.current=null),H(),P.current.get(e)||""),[H]),Y=(0,s.useCallback)(()=>{z.current&&(z.current.scrollTop=z.current.scrollHeight)},[]),G=(0,s.useCallback)(async(t=0)=>{if(r){f(!0);try{let n=await i.t4.runPromise(((e,t,r,n=100)=>tv(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&page=${r}&pageSize=${n}`))(e,r,t,100)).catch(e=>(console.error("Failed to load history:",e),null));if(n){let e=[],r=[],s=new Set;for(let t of n.entries){let n=tV(t.type);if(n){let e=n.fromHistory(t);r.push({id:t.id,_type:t.type,timestamp:t.timestamp,...e}),t.sleeping&&s.add(t.id)}else{if(t.running)continue;let r=t.id.includes("-")&&3===t.id.split("-").length?t.id:ne();e.push({id:r,command:t.command,output:t.output,exitCode:t.exitCode,isRunning:!1,timestamp:t.timestamp,cwd:t.cwd,usePty:t.usePty})}}0===t?(a(e),c(r),s.size>0&&u(s)):(a(t=>{let r=new Set(t.map(e=>e.id)),n=e.filter(e=>!r.has(e.id));return[...t,...n]}),c(e=>{let t=new Set(e.map(e=>e.id)),n=r.filter(e=>!t.has(e.id));return[...e,...n]})),g(n.hasMore),v(t)}}catch(e){console.error("Failed to load history:",e)}finally{f(!1)}}},[e,r]),X=(0,s.useCallback)(async t=>{r&&await i.t4.runPromise(tC(e,r,{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:x},W.current).pipe(ee.tapError(e=>ee.sync(()=>console.error("Failed to save cd history:",e))),ee.orElse(()=>ee.void)))},[e,r,x]),et=(0,s.useCallback)(async t=>{try{let n=await (rG||(rG=r9(e)));if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;a(e=>e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,isRunning:!0,exitCode:void 0,pid:s.pid,...s.usePty?{usePty:!0}:{}}:e):[...e,{id:n,command:s.command,output:"",isRunning:!0,pid:s.pid,timestamp:s.timestamp,cwd:s.cwd,...s.usePty?{usePty:!0}:{}}]),P.current.set(n,""),s.usePty&&$.current.add(n),await r4({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e);else if("stdout"===e||"stderr"===e)O(n,t.data);else if("exit"===e){let e=Z(n);q(n),a(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{a(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,O,Z,q]),er=(0,s.useCallback)((t,r)=>{P.current.set(t,""),r&&$.current.add(t),r4({commandId:t,projectCwd:e,onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid}:e));else if("stdout"===e||"stderr"===e)O(t,r.data);else if("exit"===e){let e=Z(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:()=>{a(e=>e.map(e=>e.id===t&&e.isRunning?{...e,isRunning:!1}:e))}}).catch(()=>{})},[e,O,Z,q]),en=(0,s.useCallback)(e=>{let t=e?.id;if(!e||!t||A.current.some(e=>e.data.id===t))return;let r=e.type,n=r?tV(r):void 0;if(n)c(s=>s.some(e=>e.id===t)?s:[...s,{id:t,_type:r,timestamp:e.timestamp??new Date().toISOString(),...n.fromHistory(e)}]),e.sleeping&&u(e=>new Set(e).add(t));else{let r=!!e.running;a(n=>n.some(e=>e.id===t)?n:[...n,{id:t,command:e.command??"",output:e.output??"",exitCode:e.exitCode,isRunning:r,timestamp:e.timestamp??new Date().toISOString(),cwd:e.cwd,usePty:e.usePty}]),r&&er(t,!!e.usePty)}L(e=>e&&!e.includes(t)?[...e,t]:e)},[er]),es=(0,s.useCallback)(e=>{if("add"===e.op)e.entry&&en(e.entry);else if("rerun"===e.op){let t=e.entry,r=t?.id;if(!t||!r)return;if(!A.current.some(e=>e.data.id===r))return void en(t);let n=!!t.usePty;if(n){let e=K.current.get(r);if(e)for(let t of e)t()}q(r,n),a(e=>e.map(e=>e.id===r?{...e,output:"",exitCode:void 0,isRunning:!0,pid:void 0}:e)),er(r,n)}else if("update"===e.op){let t=e.id,r=e.fields;if(!t||!r)return;void 0!==r.sleeping&&u(e=>{let n=new Set(e);return r.sleeping?n.add(t):n.delete(t),n}),(void 0!==r.exitCode||void 0!==r.running)&&a(e=>e.map(e=>e.id===t?{...e,...void 0!==r.exitCode?{exitCode:r.exitCode}:{},...void 0!==r.running?{isRunning:r.running}:{}}:e))}else if("delete"===e.op){let t=e.id;if(!t)return;a(e=>e.filter(e=>e.id!==t)),c(e=>e.filter(e=>e.id!==t)),L(e=>e?e.filter(e=>e!==t):e),u(e=>{if(!e.has(t))return e;let r=new Set(e);return r.delete(t),r}),q(t)}else"clear"===e.op?(a([]),c([]),L([]),u(new Set)):"reorder"===e.op&&Array.isArray(e.order)&&L(e.order)},[en,er,q]);(0,_.h)({url:"/ws/global-state",enabled:!!e&&!!r,onMessage:t=>{"console-delta"!==t.type||t.cwd!==e||t.tabId!==r||t.sourceId&&t.sourceId===W.current||es(t)}});let eo=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),l=o[0],i=t;N[l]&&(i=N[l]+(o.length>1?" "+o.slice(1).join(" "):""));let c=tK(i);if(c)return void D.current?.(c.type,i.trim());let d=ne(),u=new Date().toISOString(),h=(s=i.trim().split(/\s+/)[0],nt.has(s)),f={id:d,command:t,output:i!==t?`→ ${i}
18
+ `:"",isRunning:!0,timestamp:u,cwd:x,...h?{usePty:!0}:{}};if(a(e=>e.some(e=>e.id===d)?e:[...e,f]),w(d),P.current.set(d,f.output),h&&$.current.add(d),setTimeout(Y,100),i.trim().startsWith("cd ")){let e=i.trim().substring(3).trim(),t=x;e.startsWith("/")?t=e:".."===e?t=x.split("/").slice(0,-1).join("/")||"/":"."!==e&&(t=`${x}/${e}`.replace(/\/+/g,"/")),m(t),n?.(t),a(e=>e.map(e=>{if(e.id===d){let r={...e,output:`Changed directory to: ${t}`,exitCode:0,isRunning:!1};return X(r),r}return e}));return}try{await r5({cwd:x,command:i,commandId:d,tabId:r||"",projectCwd:e,env:k,usePty:h,sourceId:W.current,onData:(e,t)=>{if("pid"===e)a(e=>e.map(e=>e.id===d?{...e,pid:t.pid}:e));else if("stdout"===e||"stderr"===e)O(d,t.data);else if("exit"===e){let e=Z(d);q(d),a(r=>r.map(r=>r.id===d?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:e=>{let t=Z(d);q(d),a(r=>r.map(r=>r.id===d?{...r,output:t+`
19
+ Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=Z(d);q(d),a(r=>r.map(r=>r.id===d?{...r,output:e+`
20
+ Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[N,x,k,r,e,O,Z,q,Y,n,X]),ea=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&r8(t.pid)},[o]),el=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&(r8(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),l=s[0],i=n.command;N[l]&&(i=N[l]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=K.current.get(t);if(e)for(let t of e)t()}q(t,c);let d=i!==n.command?`→ ${i}
21
+ `:"";c||P.current.set(t,d),c&&$.current.add(t),a(e=>e.map(e=>e.id===t?{...e,output:c?"":d,exitCode:void 0,isRunning:!0,pid:void 0}:e));let u=R.current.get(t);try{await r5({cwd:n.cwd||x,command:i,commandId:t,tabId:r||"",projectCwd:e,env:k,usePty:c,sourceId:W.current,...c&&u?{cols:u.cols,rows:u.rows}:{},onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid}:e));else if("stdout"===e||"stderr"===e)O(t,r.data);else if("exit"===e){let e=Z(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=Z(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
22
+ Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=Z(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
23
+ Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,N,x,k,r,e,O,Z,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await i.t4.runPromise(tS(e,r,t,W.current).pipe(ee.tapError(e=>ee.sync(()=>console.error("Failed to delete command:",e))),ee.orElse(()=>ee.void)))},[e,r,q]),ec=(0,s.useCallback)((t,n,s)=>{var o;let a=tV(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=x);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(c(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=S&&S.length>0?[...S]:A.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&i.t4.runFork(tN(e,r,t,W.current).pipe(ee.orElse(()=>ee.void)))}if(r){let n=a.toHistory(d);i.t4.runFork(tC(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},W.current).pipe(ee.tapError(e=>ee.sync(()=>console.error(`Failed to save ${t} item:`,e))),ee.orElse(()=>ee.void)))}},[Y,e,r,S]),ed=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(c(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),u(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=tV(n._type);e?.onClose?.(n)}r&&i.t4.runFork(tS(e,r,t,W.current).pipe(ee.tapError(e=>ee.sync(()=>console.error("Failed to delete plugin item:",e))),ee.orElse(()=>ee.void)))},[l,e,r]);D.current=ec,I.current=eo;let eu=(0,s.useCallback)((t,n)=>{let s,o,a,l;r&&i.t4.runFork((s=e,o=r,a=t,l={sleeping:n},tj("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:s,tabId:o,id:a,fields:l,sourceId:W.current})})).pipe(ee.orElse(()=>ee.void)))},[e,r]),ex=(0,s.useCallback)(e=>{u(t=>new Set(t).add(e)),eu(e,!0)},[eu]),em=(0,s.useCallback)(e=>{u(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),eh=(0,s.useCallback)(async t=>{L(t),r&&await i.t4.runPromise(tN(e,r,t,W.current).pipe(ee.orElse(()=>ee.void)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!S||0===S.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(S.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,S]);A.current=ef,(0,s.useEffect)(()=>{T.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{y(await i.t4.runPromise(tk(e,r).pipe(ee.tapError(e=>ee.sync(()=>console.error("Failed to load env:",e))),ee.orElseSucceed(()=>({})))))},eg=async()=>{C(await i.t4.runPromise(ty().pipe(ee.tapError(e=>ee.sync(()=>console.error("Failed to load aliases:",e))),ee.orElseSucceed(()=>({})))))},eb=async()=>{if(!r)return;let t=await i.t4.runPromise(tv(`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}`).pipe(ee.map(e=>e.order||[])).pipe(ee.orElseSucceed(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await G(0),e.current||await et(e)})(),ep(),eg(),eb(),()=>{e.current=!0}},[G,et]),(0,s.useEffect)(()=>()=>{null!==M.current&&cancelAnimationFrame(M.current)},[]),(0,s.useEffect)(()=>()=>{r7()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:x,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:N,setAliases:C,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:z,commandHistoryRef:T,ptySizeRef:R,executeCommandRef:I,executeCommand:eo,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ec,closePluginItem:ed,handleBubbleSleep:ex,handleBubbleWake:em,loadHistory:G,scrollToBottom:Y,saveBubbleOrder:eh,sendStdin:r3,resizePty:r6,subscribePtyOutput:V,subscribePtyReset:U,subscribePtyRefresh:Q}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[W,z]=(0,s.useState)(null),[H,O]=(0,s.useState)(0),[q,V]=(0,s.useState)(0),[K,U]=(0,s.useState)(!0),[J,Q]=(0,s.useState)(!1),[Z,Y]=(0,s.useState)(!1),[G,X]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),eo=(0,s.useRef)(null),ea=(0,s.useRef)(!1),el=(0,s.useRef)(null),ei=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=d},[d]);let ed=(0,s.useCallback)(()=>{let e=u.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[u]),eu=(0,s.useCallback)(()=>{let e=u.current;return!e||e.scrollTop<50},[u]),ex=(0,s.useCallback)(()=>{X(!eu()),er(!ed())},[ed,eu]),em=(0,s.useCallback)(()=>{es.current?.scrollIntoView({behavior:"smooth"})},[]),eh=async()=>{let t=await i.t4.runPromiseExit(tv(`/api/project-settings?cwd=${encodeURIComponent(e)}`));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&U(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>eh())},[]);let ef=(0,s.useCallback)(()=>{ea.current=!0},[]),ep=(0,s.useCallback)((e,t)=>{if(!ea.current)return void e.preventDefault();ea.current=!1,el.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:var(--card);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),eg=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ei.current=t},[]),eb=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ev=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=el.current,r=ei.current;if(el.current=null,ei.current=null,!t||!r||t===r)return;let n=ec.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,$(a)},[$]),ek=(0,s.useCallback)(e=>{z(t=>t===e?null:e)},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),x&&ek(x))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[x,ek]),(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=new ResizeObserver(([e])=>{V(e.contentRect.height)});return t.observe(e),V(e.clientHeight),()=>t.disconnect()},[u]),(0,s.useEffect)(()=>{let e=u.current;if(e)return W?O(e.clientHeight):(e.style.overflow="",O(0)),()=>{e&&(e.style.overflow="")}},[W,u]),(0,s.useEffect)(()=>{let e=u.current;if(!e||!W||!H)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${W}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[W,H,u]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&j(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[j]);let ey=q>0?Math.floor((q-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:en,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:u,onScroll:ex,className:`console-scroll-root flex-1 overflow-y-auto ${W?"":"py-4 px-4"}`,children:0===d.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:c("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:nr.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:c(e.label)}),(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>j("zsh"),title:c("console.launchZsh"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:es}),T&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>R(B+1),disabled:F,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-50",children:F?c("console.loadingMore"):c("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:W?"flex flex-col gap-3":K?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:d.map(t=>{let s={draggable:!0,onDragStart:e=>ep(e,t.data.id),onDragOver:e=>eg(e,t.data.id),onDragEnter:eb,onDragLeave:ev,onDrop:ej,onDragEnd:ew};if("command"===t.type){let o=t.data;return(0,n.jsx)("div",{"data-bubble-id":o.id,className:"group/cmd rounded-lg transition-shadow",...s,children:(0,n.jsx)(tT,{commandId:o.id,tabId:r,projectCwd:e,command:o.command,output:o.output,exitCode:o.exitCode,isRunning:o.isRunning,selected:x===o.id,onSelect:()=>{m(o.id)},onInterrupt:o.isRunning?()=>h(o.id):void 0,onStdin:o.isRunning?e=>f(o.id,e):void 0,onDelete:()=>{o.isRunning&&o.pid&&r8(o.pid),p(o.id)},onRerun:()=>g(o.id),timestamp:o.timestamp,usePty:o.usePty,subscribePtyOutput:o.usePty?I:void 0,subscribePtyReset:o.usePty?D:void 0,subscribePtyRefresh:o.usePty?A:void 0,onPtyResize:(e,t)=>{b.current.set(o.id,{cols:e,rows:t}),v(o.id,e,t)},onToggleMaximize:()=>ek(o.id),maximized:W===o.id,expandedHeight:H,bubbleContentHeight:ey,onTitleMouseDown:ef})},o.id)}let o=tV(t.type);if(!o)return null;let a=o.Component,l=t.data;return(0,n.jsx)("div",{"data-bubble-id":l.id,className:"rounded-lg transition-shadow",...s,children:(0,n.jsx)(a,{item:l,selected:x===l.id,maximized:W===l.id,expandedHeight:H,bubbleContentHeight:ey,timestamp:l.timestamp,onSelect:()=>{m(l.id)},onClose:()=>k(l.id),onToggleMaximize:()=>ek(l.id),onTitleMouseDown:ef,extra:{addBrowserItem:(e,t)=>w("browser",e,t),initialSleeping:y.has(l.id),onSleep:N,onWake:C,projectCwd:e,tabId:r}})},l.id)})}),(0,n.jsx)("div",{ref:eo})]})}),!W&&d.length>0&&(0,n.jsx)(rq,{showTop:G,showBottom:et,onScrollTop:em,onScrollBottom:S}),(0,n.jsx)(rO,{cwd:e,currentCwd:L,commandHistoryRef:M,gridLayout:K,onGridLayoutChange:t=>{U(t);i.t4.runFork(tw("/api/project-settings",{cwd:e,settings:{gridLayout:t}}).pipe(ee.tapError(e=>ee.sync(()=>console.error("Failed to save project settings:",e))),ee.orElse(()=>ee.void)))},onExecute:j,onAddPluginItem:w,onShowEnvManager:()=>Q(!0),onOpenZsh:()=>j("zsh"),onOpenNote:l}),J&&(0,n.jsx)(tF,{cwd:e,tabId:r,onClose:()=>Q(!1),onSave:e=>E(e)}),Z&&(0,n.jsx)(tD,{onClose:()=>Y(!1),onSave:e=>P(e)})]})}var ns=r(83897),no=r(89039),na=r(76412),nl=r(24058),ni=r(98307),nc=r(65153);function nd({cwd:e,sessionId:t,onOpenProjectSessions:r,onOpenSessionBrowser:a,onOpenSettings:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),t&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t}`;navigator.clipboard.writeText(e).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-500 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:c?i("chat.copiedCommandTooltip"):i("chat.copyCommandTooltip",{sessionId:t}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nu({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-500":t?.status==="allowed_warning"?"text-yellow-500":"text-muted-foreground",c=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,d=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border bg-secondary",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&c&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,title:[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${d(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:c}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${d(t.resetsAt)}`]})]}),t&&!c&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${d(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:d(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function nx({isOpen:e,onClose:t,messages:r,onSelectMessage:a}){let{t:l}=(0,o.Bd)();if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t]),!e)return null;let i=r.filter(e=>"user"===e.role),c=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("userMessages.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===i.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:i.map((e,r)=>{let s,o,l,i=(s=e.id.match(/^user-(\d+)/))?parseInt(s[1],10):null,c=i?(o=new Date(i),l=new Date,o.toDateString()===l.toDateString()?o.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):o.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})):"";return(0,n.jsx)("button",{onClick:()=>{a(e.id),t()},className:"w-full px-4 py-3 text-left hover:bg-accent transition-colors",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[r+1,"."]}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-sm text-foreground break-words",children:function(e,t=50){let r=e.replace(/\s+/g," ").trim();return r.length<=t?r:r.slice(0,t)+"..."}(e.content)})}),c&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:c})]})},e.id)})})})]})});return(0,n.jsx)(x.ZL,{children:c})}var nm=r(85839),nh=r(20917),nf=r(8988);function np({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{onClick:t,className:"absolute -top-3 -right-3 w-8 h-8 bg-card text-foreground hover:text-foreground rounded-full shadow-lg flex items-center justify-center transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})});return(0,n.jsx)(x.ZL,{children:s})}function ng({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 bg-secondary border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(np,{image:l,onClose:()=>i(null)})]})}var nb=r(93777),nv=r(88371);let nj=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:a,onShowGitStatus:l,onShowComments:d,onShowUserMessages:u,onOpenNote:x,onCreateScheduledTask:m}){let{t:f}=(0,o.Bd)(),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)([]),[k,y]=(0,s.useState)([]),[N,C]=(0,s.useState)([]),[S,L]=(0,s.useState)(!1),[M,P]=(0,s.useState)(0),[$,T]=(0,s.useState)(!1),R=(0,s.useRef)(null),B=(0,s.useRef)(null),F=(0,s.useCallback)(()=>{let e=R.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{F()},[p,F]),(0,s.useEffect)(()=>{i.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?y(e.value):console.error("Failed to load commands:",e.cause)})},[]);let I=(0,s.useCallback)(async()=>{let e=await i.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;C((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(I(),(0,nv.U)(I)),[I]);let D=(0,s.useMemo)(()=>{let e=0===b?0:p.lastIndexOf("\n",b-1)+1,t=p.indexOf("\n",b),r=-1===t?p.length:t;return{text:p.slice(e,r),start:e,end:r}},[p,b]),A=(0,s.useMemo)(()=>{let e=D.text.match(/^\s*([/@])([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[D.text]),W=(0,s.useMemo)(()=>a&&"claude"!==a&&"claude2"!==a?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[a]),z=(0,s.useMemo)(()=>{if(!A)return[];let{verb:e}=A,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return[...W.filter(t),...k.filter(t),...N.filter(t)]},[A,W,k,N]),_=!$&&!!A&&z.length>0,H=(0,s.useRef)(p);(0,s.useLayoutEffect)(()=>{H.current!==p&&(queueMicrotask(()=>P(0)),$&&queueMicrotask(()=>T(!1)),H.current=p)},[p,$]),(0,s.useLayoutEffect)(()=>{if(_&&B.current){let e=B.current.children[M];e&&e.scrollIntoView({block:"nearest"})}},[M,_]);let O=(0,s.useCallback)(()=>{let r=p.trim();(r||j.length>0)&&!t&&(e(r,j.length>0?j:void 0),g(""),w([]),R.current&&(R.current.style.height="auto"))},[p,j,t,e]),q=(0,s.useCallback)(e=>{let t=A?.marker??"/",r=`${t}${e.name.slice(1)} `,n=p.slice(0,D.start),s=n+r+p.slice(D.end),o=n.length+r.length;g(s),v(o),requestAnimationFrame(()=>{let e=R.current;e&&(e.focus(),e.setSelectionRange(o,o))})},[p,D,A]),V=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(_&&z.length>0){if("ArrowDown"===e.key){e.preventDefault(),P(e=>(e+1)%z.length);return}if("ArrowUp"===e.key){e.preventDefault(),P(e=>(e-1+z.length)%z.length);return}if("Enter"===e.key){e.preventDefault(),q(z[M]);return}if("Escape"===e.key){e.preventDefault(),T(!0);return}if("Tab"===e.key){e.preventDefault(),q(z[M]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),O())}},[_,z,M,q,O]),K=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(f("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};w(e=>[...e,s])},s.readAsDataURL(r)}}},[f]),U=(0,s.useCallback)(e=>{w(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(ng,{images:j,onRemove:U,disabled:t}),_&&z.length>0&&(0,n.jsx)("div",{ref:B,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lg",children:z.map((e,t)=>{let r=t>0?z[t-1]:null,s="skill"===e.source&&(!r||"skill"!==r.source),o="skill"!==e.source&&0===t;return(0,n.jsxs)("div",{children:[o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),s&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),(0,n.jsxs)("div",{onClick:()=>q(e),className:`px-4 py-2 cursor-pointer ${t===M?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:(A?.marker??"/")+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?f(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return f("common.builtin");case"skill":return"Skill"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{if(!r)return;let e=await i.t4.runPromiseExit((0,h.Iz)(r,["."]));"Success"===e._tag?((0,E.oR)(f("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(console.error("Error staging files:",e.cause),(0,E.oR)(f("toast.stageFailed"),"error"))},className:"p-2 text-green-11 hover:text-green-10 hover:bg-green-9/10 active:bg-green-9/20 active:scale-95 rounded-lg transition-all",title:f("chat.stageAll"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),l&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:f("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),d&&(0,n.jsx)("button",{onClick:d,className:"p-2 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:f("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),u&&(0,n.jsx)("button",{onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:f("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),x&&(0,n.jsx)("button",{onClick:x,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:f("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),m&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>L(!S),className:`p-2 rounded-lg transition-all ${S?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:f("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),S&&(0,n.jsx)(nb.E,{onClose:()=>L(!1),onCreate:m})]}),(0,n.jsx)("textarea",{ref:R,value:p,onChange:e=>{g(e.target.value),v(e.target.selectionStart??e.target.value.length)},onSelect:e=>v(e.currentTarget.selectionStart??0),onKeyDown:V,onPaste:K,placeholder:t?f("chat.placeholderDisabled"):f("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground placeholder-slate-9"})]})]})});var nw=r(95942);function nk({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1),[m,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(!1),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)({top:0,left:0}),w=(0,x.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{b.current&&!b.current.contains(e.target)&&g.current&&!g.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let k=(0,s.useCallback)(async()=>{u(!0),h(null);let e=await i.t4.runPromiseExit((0,c.qD)(()=>p(!0)));if(p(!1),"Failure"===e._tag)h("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":h(t.message);break;case"not-running":h("Ollama is not running")}}u(!1)},[]),y=e?e.replace(/:latest$/,""):"Select model",N=r?(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{ref:b,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[200px] max-h-[300px] overflow-y-auto",style:{top:v.top,left:v.left},children:d||f?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),f?"Starting Ollama...":"Loading models..."]}):m?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-400",children:m}):0===a.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):a.map(r=>{var s;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center justify-between gap-2 px-3 py-1.5 text-xs hover:bg-brand/10 transition-colors ${r.name===e?"text-brand":"text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:g,onClick:()=>{if(!r){if(g.current){let e=g.current.getBoundingClientRect(),t=w?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;j({top:e.bottom+4-n,left:e.left-r})}k()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-violet-500/15 text-violet-400 hover:bg-violet-500/25 transition-colors",title:"Switch Ollama model",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-violet-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate max-w-[120px]",children:y}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),N]})}let ny=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function nN({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null),y=(0,s.useRef)(null),[N,C]=(0,s.useState)({top:0,left:0}),S=(0,x.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{k.current&&!k.current.contains(e.target)&&w.current&&!w.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let L=(0,s.useCallback)(async()=>{p(!0),j(null);let r=await i.t4.runPromiseExit((0,c.td)());if("Failure"===r._tag){j("Failed to load settings"),p(!1);return}let n=r.value;l(n?.engines?.deepseek?.apiKey||""),u(""),h(!1);let s=n?.engines?.deepseek?.model;!e&&s&&ny.some(e=>e.value===s)&&t(s),p(!1)},[e,t]),M=(0,s.useCallback)(async e=>{let t=await i.t4.runPromiseExit((0,c.td)()),r=("Success"===t._tag?t.value:{}).engines||{},n={...r,deepseek:{...r.deepseek||{},...e}};if("Failure"===(await i.t4.runPromiseExit((0,c.em)({engines:n})))._tag)throw Error("Failed to save settings")},[]),E=async()=>{let e=d.trim();if(e){b(!0),j(null);try{await M({apiKey:e}),l(e),u(""),h(!1)}catch(e){j(e instanceof Error?e.message:"Save failed")}finally{b(!1)}}},P=async()=>{b(!0),j(null);try{await M({apiKey:""}),l(""),u(""),h(!1)}catch(e){j(e instanceof Error?e.message:"Clear failed")}finally{b(!1)}},$=async e=>{t(e);try{await M({model:e})}catch{}},T=!!a,R=T?e||"deepseek-v4-flash":"Set API key",B=T?"text-sky-400":"text-amber-400",F=r?(0,n.jsx)(x.ZL,{children:(0,n.jsx)("div",{ref:k,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-2 min-w-[280px]",style:{top:N.top,left:N.left},children:f?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"API Key"}),T&&!m?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:a?a.length<=8?a.replace(/./g,"•"):`${a.slice(0,3)}${"•".repeat(Math.max(4,a.length-7))}${a.slice(-4)}`:""}),(0,n.jsx)("button",{onClick:()=>{h(!0),u(""),setTimeout(()=>y.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-accent text-foreground transition-colors",disabled:g,children:"Edit"}),(0,n.jsx)("button",{onClick:P,className:"text-[11px] px-2 py-1 rounded text-red-400 hover:bg-red-500/10 transition-colors",disabled:g,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:y,type:"password",value:d,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E()},placeholder:"sk-...",className:"flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:border-sky-500 focus:outline-none font-mono",autoFocus:!0}),(0,n.jsx)("button",{onClick:E,disabled:g||!d.trim(),className:"text-[11px] px-2 py-1 rounded bg-sky-500/20 hover:bg-sky-500/30 text-sky-300 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:g?"Saving...":"Save"}),T&&(0,n.jsx)("button",{onClick:()=>{h(!1),u("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),v&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-400",children:v})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:ny.map(t=>{let r=(e||"deepseek-v4-flash")===t.value;return(0,n.jsxs)("button",{onClick:()=>$(t.value),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?"bg-sky-500/15 text-sky-300":"text-foreground hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${r?"border-sky-400":"border-muted-foreground"}`,children:r&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-400"})}),(0,n.jsx)("span",{children:t.label})]},t.value)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:w,onClick:()=>{if(!r){if(w.current){let e=w.current.getBoundingClientRect(),t=S?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;C({top:e.bottom+4-n,left:e.left-r})}L()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-sky-500/15 hover:bg-sky-500/25 transition-colors",title:"Configure DeepSeek",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-500 flex-shrink-0"}),(0,n.jsx)("span",{className:`truncate max-w-[160px] ${B}`,children:R}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-sky-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),F]})}var nC=r(46456);function nS(e){if(0===e.length)return"";let t=[e7.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===ei.Un),n=e.filter(e=>e.filePath!==ei.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{t.push(`[${r+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(e7.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function nL({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(!1),v=(0,s.useCallback)(async()=>{if(!r)return;h(!0);let e=await i.t4.runPromiseExit((0,nC.$)(r));"Success"===e._tag?d(e.value.comments??[]):console.error("Failed to load comments:",e.cause),h(!1)},[r]);(0,s.useEffect)(()=>{e&&v()},[e,v]);let j=async e=>{let t=await i.t4.runPromiseExit((0,nC.Tu)(r,e));"Success"===t._tag?(d(t=>t.filter(t=>t.id!==e)),(0,ei.Cm)()):console.error("Failed to delete comment:",t.cause)},w=async e=>{p(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await i.t4.runPromiseExit((0,m.K9)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=nS([n]);await navigator.clipboard.writeText(s),(0,E.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{p(null)}},k=async()=>{if(0!==c.length){b(!0);try{let e=await (0,ei.$3)(r),t=nS(e);await navigator.clipboard.writeText(t),(0,E.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{b(!1)}}},y=c.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let N=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),c.length>0&&(0,n.jsx)("button",{onClick:k,disabled:g,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:u?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===c.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(y).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===ei.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-accent/50 cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},disabled:f===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:f===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border bg-secondary flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:c.length})}),(0,n.jsx)("button",{onClick:async()=>{0===c.length||await (0,ei.RP)(r)&&d([])},disabled:0===c.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})});return(0,n.jsx)(x.ZL,{children:N})}function nM({tabId:e,initialCwd:t,initialSessionId:r,engine:u,ollamaModel:x,onOllamaModelChange:m,deepseekModel:h,onDeepseekModelChange:f,chatMode:p,onChatModeChange:g,planMode:b,onPlanModeChange:v,hideHeader:j,hideSidebar:w,isActive:k=!0,onLoadingChange:y,onSessionIdChange:N,onTitleChange:C,onShowGitStatus:S,onOpenNote:L,onCreateScheduledTask:M,onOpenSession:P,onContentSearch:$,onOpenSessionBrowser:T,onOpenSettings:R}){let{t:B}=(0,o.Bd)(),F=(0,ns.nH)(),[I,D]=(0,s.useState)([]),[A,W]=(0,s.useState)(null),[z,_]=(0,s.useState)(!1),[H,O]=(0,s.useState)(!1),[q,V]=(0,s.useState)(!1),[K,U]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(null),[Z,Y]=(0,s.useState)("sdk"),G=p??Z,X=(0,s.useCallback)(e=>{Y(e),g?.(e)},[g]),[ee,et]=(0,s.useState)(!1),er=b??ee,en=(0,s.useCallback)(e=>{et(e),v?.(e)},[v]),es=!u||"claude"===u||"claude2"===u,eo=(0,s.useRef)(null),ea=(0,s.useCallback)(e=>{eo.current?.write(e)},[]),el=(0,s.useCallback)(e=>{A&&fetch("/api/chat/pty-input",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:A,data:e})}).catch(()=>{})},[A]),ei=(0,s.useRef)(!1),ec=(0,s.useRef)(null),ed=(0,s.useRef)(null),eu=(0,s.useCallback)(async e=>{if(!t)return;let r=await i.t4.runPromiseExit((0,c.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?C?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,C]),{isLoading:ex,tokenUsage:em,rateLimitInfo:eh,apiRetryInfo:ef,ptyNotice:ep,handleSend:eg,handleStop:eb}=(0,nh.e)(I,D,{sessionId:A,cwd:t,engine:u,chatMode:G,planMode:er,ollamaModel:x,deepseekModel:h,onSessionId:W,onFetchTitle:eu,onPtyOutput:ea}),ev=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(es&&"sdk"===G){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(en(!1),(0,E.oR)(B("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(en(!0),(0,E.oR)(B("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(en(!0),eg(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void eg(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await i.t4.runPromiseExit((0,c.JC)({command:s,cwd:t}));if("Success"===a._tag){let e=a.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=B("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
24
+
25
+ ${o}`),eg(n,r)}else eg(B("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}eg(e,r)},[eg,t,B,es,G,en]),ej=(0,s.useCallback)(()=>{en(!1),eg(B("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[eg,en,B]),[ew,ek]=(0,s.useState)(!1),ey=(0,s.useRef)(!1);(0,s.useEffect)(()=>{ey.current=ew},[ew]);let{isLoadingHistory:eN,isLoadingMore:eC,hasMoreHistory:eS,loadMoreHistory:eL,loadHistoryByCwdAndSessionId:eM,loadedSessionId:eE}=(0,nm.m)(I,D,A,{cwd:t,initialSessionId:r,onSessionId:W,onTitleChange:C,onTokenUsage:Q,liveRunningRef:ey}),eP=eE||A,e$=k&&!ex&&!!eP;(0,nc.u)(eP,D,e$,u,{onRunningChange:e=>{ey.current=e,ek(e)},onComplete:()=>{t&&eP&&eM(t,eP,!0)}}),(0,s.useEffect)(()=>{e$||ek(!1)},[e$]);let eT=(0,s.useRef)(k);(0,s.useEffect)(()=>{k&&!eT.current&&A&&t&&!ex&&!ew&&eM(t,A,!0,10),eT.current=k},[k,A,t,ex,ew,eM]),(0,s.useEffect)(()=>{"pty"===G&&ex&&!ei.current&&eo.current?.clear(),ei.current=ex},[ex,G]);let eR=em||J;(0,s.useEffect)(()=>{A&&N?.(A)},[A,N]);let eB=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(y?.(ex),eB.current&&!ex&&t&&A){let e;for(let t=I.length-1;t>=0;t--)if("user"===I[t].role&&I[t].content){e=I[t].content.slice(0,100);break}(0,a.F)(l.n.SessionComplete,{cwd:t,sessionId:A,lastUserMessage:e})}eB.current=ex},[ex,y,t]),(0,s.useEffect)(()=>{k&&F?.setIsLoading(ex)},[ex,k,F]),(0,s.useEffect)(()=>{if(e&&F)return F.registerChat(e=>{ed.current?.(e)},e),()=>{F.unregisterChat(e)}},[e,F]),(0,s.useEffect)(()=>{e&&k&&F&&F.setActiveTab(e)},[e,k,F]),(0,s.useEffect)(()=>{ed.current=ev},[ev]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&z&&(ex||ew)&&eb()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[z,ex,ew,eb]);let eF=(0,s.useCallback)(async e=>{let r=eE??A;if(!t||!r)return;let n=await i.t4.runPromiseExit((0,c.Zr)(r,{cwd:t,fromMessageUuid:e}));if("Success"===n._tag&&n.value.newSessionId){let e=n.value.newSessionId;P?P(e,"Fork"):(0,a.F)(l.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===n._tag&&console.error("Fork failed:",n.cause)},[t,eE,A,P]),eI=(0,s.useCallback)(()=>{V(!0)},[]),eD=(0,s.useCallback)(()=>{U(!0)},[]),eA=(0,s.useMemo)(()=>{if(M&&t&&e&&A)return r=>{M({...r,cwd:t,tabId:e,sessionId:A,engine:u,..."ollama"===u&&x&&{model:x},..."deepseek"===u&&h&&{model:h}})}},[M,t,e,A,u,x,h]);return(0,n.jsxs)("div",{className:`flex ${j&&w?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>_(!0),onMouseLeave:()=>_(!1),children:[!j&&(0,n.jsx)(nd,{cwd:t,sessionId:A,onOpenProjectSessions:()=>O(!0),onOpenSessionBrowser:T,onOpenSettings:R}),es&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:B("chat.executionMode",{defaultValue:"Execution mode"})}),(0,n.jsxs)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":"chatmode-toggle",children:[(0,n.jsx)("button",{type:"button","data-testid":"chatmode-sdk",onClick:()=>X("sdk"),className:`px-2 py-0.5 ${"sdk"===G?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-accent"}`,children:"Claude Agent SDK"}),(0,n.jsx)("button",{type:"button","data-testid":"chatmode-pty",onClick:()=>X("pty"),className:`px-2 py-0.5 ${"pty"===G?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-accent"}`,title:B("chat.ptyModeHint",{defaultValue:"Subscription-billing mode: driven by the interactive claude CLI"}),children:"Claude Code CLI"})]}),"sdk"===G&&(0,n.jsxs)("label",{className:"flex items-center gap-1.5 ml-2 pl-3 border-l border-border text-xs cursor-pointer select-none",title:B("chat.planModeHint",{defaultValue:"Plan mode: read-only exploration that produces a plan without editing. Uncheck and resend to implement."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:er,onChange:e=>en(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(ni.A,{className:"w-3.5 h-3.5"}),B("chat.planMode",{defaultValue:"Plan mode"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:B("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"})})]})]}),"ollama"===u&&m&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(nk,{currentModel:x,onModelChange:m})}),"deepseek"===u&&f&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(nN,{currentModel:h,onModelChange:f})}),eN?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:B("sessions.loadingHistory")})}):(0,n.jsx)(nf.M,{ref:ec,messages:I,isLoading:ex||ew,cwd:t,sessionId:A,engine:u,apiRetryInfo:ef,ptyNotice:ep,hasMoreHistory:eS,isLoadingMore:eC,onLoadMore:eL,onFork:eF,isActive:k,onContentSearch:$,onApprovePlan:ej}),eR&&(0,n.jsx)(nu,{tokenUsage:eR,rateLimitInfo:eh}),(0,n.jsx)(nj,{onSend:ev,disabled:ex||ew,cwd:t,engine:u,onShowGitStatus:S,onShowComments:t?eI:void 0,onShowUserMessages:eD,onOpenNote:L,onCreateScheduledTask:eA}),(0,n.jsx)(nw.ri,{ref:eo,visible:es&&"pty"===G,running:ex,onInput:el})]}),!j&&t&&(0,n.jsx)(d,{isOpen:H,onClose:()=>O(!1),cwd:t}),t&&(0,n.jsx)(nL,{isOpen:q,onClose:()=>V(!1),cwd:t}),(0,n.jsx)(nx,{isOpen:K,onClose:()=>U(!1),messages:I,onSelectMessage:e=>{ec.current?.scrollToMessage(e)}})]})}function nE({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:l,deepseekModel:i,onDeepseekModelChange:c,chatMode:d,onChatModeChange:u,planMode:x,onPlanModeChange:m,isActive:h,onStateChange:f,onShowGitStatus:p,onOpenNote:g,onCreateScheduledTask:b,onOpenSession:v,onContentSearch:j}){let w=(0,s.useCallback)(t=>{f(e,{isLoading:t})},[e,f]),k=(0,s.useCallback)(t=>{f(e,{sessionId:t})},[e,f]),y=(0,s.useCallback)(t=>{f(e,{title:t})},[e,f]),N=(0,s.useCallback)(t=>{l?.(e,t)},[e,l]),C=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),S=(0,s.useCallback)(t=>{u?.(e,t)},[e,u]),L=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]);return(0,n.jsx)(nM,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:N,deepseekModel:i,onDeepseekModelChange:C,chatMode:d,onChatModeChange:S,planMode:x,onPlanModeChange:L,hideHeader:!0,hideSidebar:!0,isActive:h,onLoadingChange:w,onSessionIdChange:k,onTitleChange:y,onShowGitStatus:p,onOpenNote:g,onCreateScheduledTask:b,onOpenSession:v,onContentSearch:j})}var nP=r(3292),n$=r(23121),nT=r(88292),nR=r(76900),nB=r(96472);function nF({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[a,c]=(0,s.useState)("agent"),{tabs:u,activeTabId:m,activeTab:h,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,closeTab:b,switchTab:v,handleSelectSession:j,handleNewTab:w,handleNewClaude2Tab:k,handleNewCodexTab:y,handleNewKimiTab:N,handleNewOllamaTab:C,handleNewDeepseekTab:S,handleOpenSession:L,updateTabState:M,updateTabOllamaModel:E,updateTabDeepseekModel:P,updateTabChatMode:$,updateTabPlanMode:T,handleTabDragStart:R,handleTabDragOver:B,handleTabDrop:F,handleTabDragEnd:I}=(0,no.useTabState)({initialCwd:e,initialSessionId:t,activeView:a}),{isPinned:D,pinSession:A,unpinSession:W}=(0,nP.P)(),{createTask:z}=(0,n$.n)(),H=(0,s.useCallback)(e=>{let t=u.find(t=>t.id===e);return!!t?.sessionId&&D(t.sessionId)},[u,D]),O=(0,s.useCallback)(t=>{let r=u.find(e=>e.id===t);r?.sessionId&&(D(r.sessionId)?W(r.sessionId):A(r.sessionId,r.cwd||e||"",r.title))},[u,D,A,W,e]),[q,V]=(0,s.useState)(!1),[K,U]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(!1),[Z,Y]=(0,s.useState)(null),[G,X]=(0,s.useState)(!1),[et,er]=(0,s.useState)("tree"),[en,es]=(0,s.useState)(0),[eo,ea]=(0,s.useState)(null),[el,ei]=(0,s.useState)(0);(0,s.useEffect)(()=>{e&&i.t4.runPromiseExit((0,nR.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&c(t.activeView)}})},[e]);let[ec,ed]=(0,s.useState)(!1),eu=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eu.current=a,c("console"),ed(!0)):(ed(!1),eu.current&&"console"!==eu.current&&c(eu.current),eu.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[a]);let ex=(0,s.useCallback)(t=>{c(t),e&&(i.t4.runFork((0,nR.Yn)({cwd:e,settings:{activeView:t}}).pipe(ee.orElse(()=>ee.void))),i.t4.runFork(ee.flatMap(nT.d,r=>r.publish(l.n.ViewChange,{cwd:e,view:t}))))},[e]),em=(0,s.useCallback)(async()=>{if(!e)return;let t=await i.t4.runPromiseExit((0,nR.b2)(e));if("Success"===t._tag){let r=t.value;if(X(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&Y(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>em())},[em]);let eh=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&em()},[em]);(0,_.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eh,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),ex("agent")):"2"===e.key?(e.preventDefault(),ex("explorer")):"3"===e.key?(e.preventDefault(),ex("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){j(r),n&&ex("agent");let t=u.find(e=>e.sessionId===r);e&&!t?.isLoading&&(i.t4.runFork((0,nB.KJ)(e,r,"normal").pipe(ee.orElse(()=>ee.void))),i.t4.runFork((0,nB.M2)(r).pipe(ee.orElse(()=>ee.void))))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[j,ex,e,u]);let ef=(0,s.useCallback)(()=>{er("status"),es(e=>e+1),ex("explorer")},[ex]),ep=(0,s.useCallback)(e=>{ea(e),ei(e=>e+1),ex("explorer")},[ex]),eg=(0,s.useCallback)(()=>{e&&i.t4.runFork(ee.flatMap(nT.d,t=>t.publish(l.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ns.k_,{children:(0,n.jsx)(ta.fY,{activeView:a,onViewChange:ex,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(na.TabManagerTopBar,{initialCwd:e,activeTab:h,isGitRepo:G,currentBranch:Z,onOpenWorktree:()=>U(!0),onOpenAliasManager:()=>Q(!0),onBranchSwitched:em}),ec&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),r("console.screenshotting")]}),e?(0,n.jsxs)(ta.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(x.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nl.TabBar,{tabs:u,activeTabId:m,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:H,onTogglePin:O,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:k,onNewCodexTab:y,onNewKimiTab:N,onNewOllamaTab:C,onNewDeepseekTab:S,onOpenProjectSessions:()=>V(!0),onDragStart:R,onDragOver:B,onDrop:F,onDragEnd:I}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===m?"block":"hidden"}`,children:(0,n.jsx)(nE,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:E,deepseekModel:e.deepseekModel,onDeepseekModelChange:P,chatMode:e.chatMode,onChatModeChange:$,planMode:e.planMode,onPlanModeChange:T,isActive:e.id===m&&"agent"===a,onStateChange:M,onShowGitStatus:ef,onContentSearch:ep,onOpenNote:eg,onCreateScheduledTask:z,onOpenSession:L})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(x.a9,{children:(0,n.jsx)(tl,{onClose:()=>ex("agent"),cwd:e,initialTab:et,tabSwitchTrigger:en,initialSearchQuery:eo,searchQueryTrigger:el})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(x.a9,{children:(0,n.jsx)(nn,{cwd:e,tabId:"default",onOpenNote:eg})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nl.TabBar,{tabs:u,activeTabId:m,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:H,onTogglePin:O,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:k,onNewCodexTab:y,onNewKimiTab:N,onNewDeepseekTab:S,onDragStart:R,onDragOver:B,onDrop:F,onDragEnd:I}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===m?"block":"hidden"}`,children:(0,n.jsx)(nE,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:E,deepseekModel:e.deepseekModel,onDeepseekModelChange:P,chatMode:e.chatMode,onChatModeChange:$,planMode:e.planMode,onPlanModeChange:T,isActive:e.id===m,onStateChange:M,onCreateScheduledTask:z,onOpenSession:L})},e.id))})]})]}),e&&(0,n.jsx)(d,{isOpen:q,onClose:()=>V(!1),cwd:e,onSelectSession:j}),e&&G&&(0,n.jsx)(ti,{isOpen:K,onClose:()=>U(!1),cwd:e}),J&&(0,n.jsx)(tD,{onClose:()=>Q(!1),onSave:()=>Q(!1)})]})})})}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(86957),l=r(2111),i=r(53213);function c({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-6 h-6 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function d({index:e,name:t,cwd:r,isActive:u,collapsed:x,hasUnread:m,isLoading:h,onClick:f,onRemove:p,onOpenNote:g}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),y=(0,s.useCallback)(()=>{a.t4.runPromiseExit((0,i.ue)(r)).then(e=>{"Success"===e._tag&&k(e.value.branch)})},[r]);(0,s.useEffect)(()=>{y()},[y]);let N=(0,s.useCallback)(e=>{e?.type==="watch"&&Array.isArray(e.data)&&e.data.some(e=>"git"===e.type)&&y()},[y]);(0,l.h)({url:`/ws/watch?cwd=${encodeURIComponent(r)}`,onMessage:N});let C=w?x?`${t} \xb7 ${w}`:w:r;return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${x?"justify-center":""} ${u?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:f,onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),"data-tooltip":C,children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(c,{number:e+1,isActive:u}),m&&!u&&!h&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),h&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"})]}),!x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:`flex-1 truncate text-sm ${u?"text-brand":""}`,children:t}),!h&&u?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}):null]}),v&&!x&&(0,n.jsxs)("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-0.5",children:[g&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),g()},title:b("workspace.projectNotes"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{className:"p-1 rounded hover:bg-red-500/20 text-muted-foreground hover:text-red-500 transition-colors",onClick:e=>{e.stopPropagation(),p()},title:b("workspace.closeProject"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})}},8648:(e,t,r)=>{r.d(t,{NoteModal:()=>C});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(13439),i=r(37795),c=r(43561),d=r(5989),u=r(76065),x=r(43203),m=r(6268),h=r(48434),f=r(44695),p=r(59265),g=r(26932);function b(e){return e.storage.markdown.getMarkdown()}function v(){return[{label:a.A.t("slashCommands.heading1"),icon:"H1",description:a.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:a.A.t("slashCommands.heading2"),icon:"H2",description:a.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:a.A.t("slashCommands.heading3"),icon:"H3",description:a.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:a.A.t("slashCommands.bulletList"),icon:"•",description:a.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:a.A.t("slashCommands.orderedList"),icon:"1.",description:a.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:a.A.t("slashCommands.taskList"),icon:"☑",description:a.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:a.A.t("slashCommands.blockquote"),icon:"❝",description:a.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:a.A.t("slashCommands.codeBlock"),icon:"<>",description:a.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:a.A.t("slashCommands.table"),icon:"▦",description:a.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:a.A.t("slashCommands.horizontalRule"),icon:"──",description:a.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:a.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:a.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function j({editor:e,query:t,position:r,onClose:o}){let[a,l]=(0,s.useState)(0),i=(0,s.useRef)(null),c=v().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>l(0))},[t]);let d=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),l(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[a]&&d(c[a])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,a,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===a?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>l(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}v();var w=r(76043),k=r(86957),y=r(49433),N=r(76900);function C({isOpen:e,onClose:t,projectCwd:r,projectName:v}){let{t:S}=(0,o.Bd)(),[L,M]=(0,s.useState)(!0),[E,P]=(0,s.useState)(!1),$=(0,s.useRef)(null),T=(0,s.useRef)(!1),[R,B]=(0,s.useState)(null),F=(0,s.useRef)(null),I=(0,s.useCallback)(async e=>{P(!0),"Success"===(await k.t4.runPromiseExit((0,N.Cq)(r,e).pipe(y.tapError(e=>y.sync(()=>console.error("Failed to save note:",e))))))._tag&&(T.current=!1),P(!1)},[r]),D=(0,s.useCallback)(e=>{T.current=!0,$.current&&clearTimeout($.current),$.current=setTimeout(()=>{I(e)},5e3)},[I]),A=(0,l.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:{levels:[1,2,3]}}),c.A.configure({placeholder:()=>a.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,x.n,m.A,h._,p.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),f.L.configure({nested:!0}),g.o.configure({html:!0,transformCopiedText:!0,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&W.current){let e=W.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||R||setTimeout(()=>{if(!W.current)return;let{from:e}=W.current.state.selection;if("/"===W.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){F.current=e;let t=W.current.view.coordsAtPos(e);B({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(D(b(e)),null!==F.current){let{from:t}=e.state.selection;if(t<F.current)B(null),F.current=null;else{let r=e.state.doc.textBetween(F.current,t,"\n");r.includes(" ")||r.includes("\n")?(B(null),F.current=null):B(e=>e?{...e,query:r}:null)}}}}),W=(0,s.useRef)(A);(0,s.useEffect)(()=>{W.current=A},[A]),(0,s.useEffect)(()=>{e&&A&&(M(!0),B(null),F.current=null,k.t4.runPromiseExit((0,N.zF)(r)).then(e=>{"Success"===e._tag?(A.commands.setContent(e.value.content||""),T.current=!1):console.error("Failed to load note:",e.cause),M(!1)}))},[e,A,r]);let z=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),T.current&&A&&I(b(A)),B(null),F.current=null,t()},[A,I,t]);return((0,s.useEffect)(()=>()=>{$.current&&clearTimeout($.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(R?(B(null),F.current=null):z())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,z,R]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:z}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v?S("editor.noteTitle",{name:v}):S("editor.noteUntitled")}),E&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:S("editor.saving")})]}),(0,n.jsx)("button",{onClick:z,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(w.NoteToolbar,{editor:A}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:L?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:S("common.loading")})}):(0,n.jsx)(l.$Z,{editor:A})})]}),R&&A&&(0,n.jsx)(j,{editor:A,query:R.query,position:R.position,onClose:()=>{B(null),F.current=null}})]}):null}},12786:(e,t,r)=>{r.d(t,{L:()=>s,Mu:()=>o});var n=r(41463);function s(){return!("u"<typeof navigator)&&(/Mac|iPhone|iPad/.test(navigator.platform||"")||navigator.userAgentData?.platform==="macOS")}function o(){return s()?"⌘":"Ctrl+"}n.platform,n.platform,n.platform},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>m});var n=r(95155),s=r(12115),o=r(79114),a=r(3238),l=r(34075),i=r(12786),c=r(53853),d=r(86957),u=r(49433),x=r(76900);function m({isOpen:e,onClose:t}){let{t:r,i18n:h}=(0,o.Bd)(),{theme:f,setTheme:p}=(0,a.D)(),g=(0,c.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&y(e.value.language)})},[e]);let N=(0,s.useCallback)(e=>{y(e),d.t4.runFork((0,x.DZ)({language:e}).pipe(u.orElse(()=>u.void)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),C=g?"installed":"not-installed",S=g?.version??null;if((0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.Wr)()).then(e=>{"Success"===e._tag&&e.value.version&&w(e.value.version)})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let L=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:L.map(e=>(0,n.jsxs)("button",{onClick:()=>p(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${f===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>N(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${k===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===C?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===C&&`${r("settings.extensionInstalled")}${S?` (v${S})`:""}`,"not-installed"===C&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==C&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=b||"chrome-extension";navigator.clipboard.writeText(e),(0,l.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===C&&(0,n.jsx)("button",{onClick:()=>{g?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(g.id,{type:"reload"}),(0,l.oR)(r("toast.pluginReloading")))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),b&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:b})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",j?` v${j}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{n:()=>x});var n=r(12115),s=r(95045),o=r(75346),a=r(49433),l=r(86957),i=r(82680);let c=(e,t,r)=>a.tryPromise({try:async()=>{let n=await fetch(e,{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:r=>new i.uV({message:`${t} ${e} failed`,cause:r})}),d="SCHEDULED_TASKS_CHANGED";function u(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:d},"*")}catch{}})}function x(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;l.t4.runPromise((e="/api/scheduled-tasks",a.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new i.uV({message:`fetch ${e} failed`,cause:t})})).pipe(a.match({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===d&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let x=(0,n.useCallback)(async e=>{let t=await l.t4.runPromiseExit(c("/api/scheduled-tasks","POST",e));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),u(),r.task):null},[o]),m=(0,n.useCallback)(async(e,t,r)=>{await l.t4.runPromise(c("/api/scheduled-tasks","PATCH",{id:e,action:t,fields:r}).pipe(a.asVoid).pipe(a.orElse(()=>a.void))),o(),u()},[o]),h=(0,n.useCallback)(e=>m(e,"pause"),[m]),f=(0,n.useCallback)(e=>m(e,"resume"),[m]),p=(0,n.useCallback)(async e=>{await l.t4.runPromise(c("/api/scheduled-tasks","DELETE",{id:e}).pipe(a.asVoid).pipe(a.orElse(()=>a.void))),o(),u()},[o]),g=(0,n.useCallback)((e,t)=>m(e,"update",t),[m]),b=(0,n.useCallback)(e=>m(e,"trigger"),[m]),v=(0,n.useCallback)(e=>m(e,"markRead"),[m]);return{tasks:e,unreadCount:r,reload:o,createTask:x,pauseTask:h,resumeTask:f,triggerTask:b,deleteTask:p,updateTask:g,markRead:v,markAllRead:(0,n.useCallback)(()=>m("_","markAllRead"),[m]),reorderTasks:(0,n.useCallback)(e=>m("_","reorder",{orderedIds:e}),[m])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),a=r(64428),l=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:l,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),x=(0,s.useRef)(null),m=(0,s.useRef)(null),[h,f]=(0,s.useState)({top:0,right:0}),p=(0,a.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{m.current&&!m.current.contains(e.target)&&x.current&&!x.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?l?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:x,onClick:()=>{if(!d&&x.current){let e=x.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),d&&(0,n.jsx)(a.ZL,{children:(0,n.jsxs)("div",{ref:m,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:h.top,right:h.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"DeepSeek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:a,isPinned:u,onTogglePin:x,onSwitchTab:m,onCloseTab:h,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onOpenProjectSessions:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C}){let{t:S}=(0,l.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((l,c)=>(0,n.jsx)(o.m,{content:l.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>k(c),onDragOver:e=>y(e,c),onDrop:()=>N(c),onDragEnd:C,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg border-t-[1.5px] transition-colors ${l.id===t?"border-brand bg-slate-4 text-foreground font-medium":"border-transparent text-muted-foreground hover:bg-secondary/50"} ${s===c?"opacity-50":""} ${a===c?"border-l-2 border-brand":""}`,onClick:()=>m(l.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:l.id===t}),l.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!l.isLoading&&r.has(l.id)&&l.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),x&&u?.(l.id)&&!l.isLoading&&!(r.has(l.id)&&l.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x(l.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:S("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),x&&!u?.(l.id)&&!l.isLoading&&!(r.has(l.id)&&l.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),x(l.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:S("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:l.title}),"claude2"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(l.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:S("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},l.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j}),w&&(0,n.jsx)("button",{onClick:w,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:S("sessions.projectSessions"),"aria-label":S("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})})]})})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},42701:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>k});var n=r(95155),s=r(12115),o=r(79114),a=r(2228),l=r(86957),i=r(53213),c=r(83448);function d({isOpen:e,onClose:t,onSwitchProject:r}){let{t:a}=(0,o.Bd)(),[i,u]=(0,s.useState)([]),[x,m]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{m(!0),f(null);let e=await l.t4.runPromiseExit((0,c.z2)());"Success"===e._tag?u([...e.value]):f(a("sessions.loadSessionsFailed")),m(!1)},[a]);(0,s.useEffect)(()=>{e&&(v(),setTimeout(()=>b.current?.focus(),100))},[e,v]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let j=i.filter(e=>{if(!p)return!0;let t=p.toLowerCase();return void 0!==e.searchText?e.searchText.includes(t):e.cwd.toLowerCase().includes(t)||(e.title?.toLowerCase().includes(t)??!1)||(e.lastUserMessage?.toLowerCase().includes(t)??!1)||(e.firstMessages?.some(e=>e.toLowerCase().includes(t))??!1)||(e.lastMessages?.some(e=>e.toLowerCase().includes(t))??!1)});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:a("sessions.recentSessions")})}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:b,type:"text",placeholder:a("sessions.searchSessions"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[x&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:a("sessions.loadingSessions")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:h})}),!x&&!h&&0===j.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:p?a("sessions.noMatchingSessions"):a("sessions.noSessions")})}),!x&&!h&&j.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:j.map(e=>{let s;return(0,n.jsxs)("div",{onClick:()=>{r(e.cwd,e.sessionId),t()},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"loading"===e.status?"bg-orange-9 animate-pulse":"unread"===e.status?"bg-red-500":"bg-muted-foreground/30"}`}),e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate flex-1",title:e.cwd,children:(s=e.cwd).split("/").pop()||s}),"loading"===e.status&&(0,n.jsx)("span",{className:"text-[10px] text-orange-11 flex-shrink-0",children:a("sessions.running")}),"unread"===e.status&&(0,n.jsx)("span",{className:"text-[10px] text-red-500 flex-shrink-0",children:a("sessions.done")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.lastActive).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(e.firstMessages?.length??0)>0||(e.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),(e.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]}):e.lastUserMessage||e.title?(0,n.jsxs)("div",{className:"text-xs text-foreground truncate",title:e.lastUserMessage||e.title,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e.lastUserMessage||e.title]}):null]},`${e.cwd}-${e.sessionId}`)})})]})]})]}):null}function u({currentCwd:e,onSwitchProject:t,collapsed:r,sessions:a}){let{t:c}=(0,o.Bd)(),[x,m]=(0,s.useState)(!1),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(0),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)({}),y=(0,s.useCallback)((e,t)=>{let r=t.currentTarget.getBoundingClientRect(),n=r.top;n+260>window.innerHeight&&(n=Math.max(8,window.innerHeight-260-8)),j({session:e,top:n,left:r.right+8}),k(t=>e.cwd in t?t:(l.t4.runPromiseExit((0,i.ue)(e.cwd)).then(t=>{"Success"===t._tag&&k(r=>({...r,[e.cwd]:t.value.branch}))}),{...t,[e.cwd]:null}))},[]),N=(0,s.useCallback)(()=>j(null),[]);(0,s.useEffect)(()=>{x||j(null)},[x]),(0,s.useEffect)(()=>{if(!x)return;let e=e=>{b.current&&!b.current.contains(e.target)&&m(!1)},t=()=>{m(!1)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[x]);let C=(0,s.useCallback)(e=>{t(e.cwd,e.sessionId),m(!1),j(null)},[t]),S=a.filter(e=>"loading"===e.status).length,L=a.filter(e=>"unread"===e.status).length,M=(0,s.useCallback)(e=>{let t=Math.floor((p-e)/6e4);if(t<1)return c("common.justNow");if(t<60)return c("common.minutesAgo",{count:t});let r=Math.floor(t/60);return r<24?c("common.hoursAgo",{count:r}):c("common.daysAgo",{count:Math.floor(r/24)})},[c,p]),E=e=>e.split("/").pop()||e;return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsxs)("button",{onClick:()=>{g(Date.now()),m(!x)},className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"w-full justify-center":"w-full"}`,title:c("sessions.recentSessions"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),!r&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:c("sessions.recentSessions")}),S>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-orange-9 animate-pulse ${r?"absolute -top-1 -right-1":""}`,children:S}),L>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${r&&!S?"absolute -top-1 -right-1":""}`,children:L})]}),x&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:c("sessions.recentSessions")}),S>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",c("sessions.runningCount",{count:S}),")"]}),L>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-red-500",children:["(",c("sessions.unreadCount",{count:L}),")"]}),(0,n.jsx)("button",{onClick:()=>{g(Date.now()),m(!1),j(null),f(!0)},className:"ml-auto p-1 -mr-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:c("sessions.searchRecentSessions"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:c("sessions.noSessions")}):a.map((t,r)=>(0,n.jsxs)("button",{onClick:()=>C(t),onMouseEnter:e=>y(t,e),onMouseLeave:N,className:`w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 ${r!==a.length-1?"border-b border-border/50":""} ${e===t.cwd?"bg-accent/50":""}`,children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${"loading"===t.status?"bg-orange-9 animate-pulse":"unread"===t.status?"bg-red-500":"bg-muted-foreground/30"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:E(t.cwd)}),"loading"===t.status&&(0,n.jsx)("span",{className:"text-xs text-orange-11 flex-shrink-0",children:c("sessions.running")}),"unread"===t.status&&(0,n.jsx)("span",{className:"text-xs text-red-500 flex-shrink-0",children:c("sessions.done")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:M(t.lastActive)})]}),(t.lastUserMessage||t.title)&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:t.lastUserMessage||t.title})]})]},`${t.cwd}-${t.sessionId}`))})]}),v&&(0,n.jsxs)("div",{className:"fixed z-[60] w-72 max-h-[260px] overflow-y-auto bg-popover border border-border rounded-lg shadow-lg p-3 pointer-events-none",style:{top:v.top,left:v.left},children:[(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:E(v.session.cwd)}),w[v.session.cwd]&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-normal min-w-0",children:[(0,n.jsxs)("svg",{className:"w-3 h-3 flex-shrink-0 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2.5"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2.5"}),(0,n.jsx)("circle",{cx:"18",cy:"7",r:"2.5"}),(0,n.jsx)("path",{strokeLinecap:"round",d:"M6 8.5v7M8.5 6.5h4.5a3 3 0 013 3v0"})]}),(0,n.jsx)("span",{className:"truncate",children:w[v.session.cwd]})]}),(v.session.firstMessages?.length??0)>0||(v.session.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs border-t border-border/50 mt-2 pt-2",children:[v.session.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`f-${t}`)),(v.session.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),v.session.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`l-${t}`))]}):v.session.lastUserMessage||v.session.title?(0,n.jsx)("div",{className:"text-xs text-foreground/90 border-t border-border/50 mt-2 pt-2 line-clamp-3 break-words",children:v.session.lastUserMessage||v.session.title}):null]}),(0,n.jsx)(d,{isOpen:h,onClose:()=>f(!1),onSwitchProject:t})]})}function x({collapsed:e,pinnedSessions:t,onSwitchProject:r,onUnpin:a,onUpdateTitle:l,onReorder:i}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{m.current&&!m.current.contains(e.target)&&(u(!1),f(null))},t=()=>{u(!1),f(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[d]),(0,s.useEffect)(()=>{h&&(b.current?.focus(),b.current?.select())},[h]);let y=(0,s.useCallback)(e=>{h||(r(e.cwd,e.sessionId),u(!1))},[r,h]),N=(0,s.useCallback)((e,t)=>{t.stopPropagation(),f(e.sessionId),g(e.customTitle||"")},[]),C=(0,s.useCallback)(()=>{h&&p.trim()&&l(h,p.trim()),f(null)},[h,p,l]),S=(0,s.useCallback)(e=>{j(e)},[]),L=(0,s.useCallback)((e,t)=>{e.preventDefault(),k(t)},[]),M=(0,s.useCallback)(e=>{if(null===v||v===e){j(null),k(null);return}let r=[...t],[n]=r.splice(v,1);r.splice(e,0,n),i(r),j(null),k(null)},[v,t,i]),E=(0,s.useCallback)(()=>{j(null),k(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:m,children:[(0,n.jsxs)("button",{onClick:()=>u(!d),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:c("sessions.pinnedSessions"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:c("sessions.pinnedSessions")}),e&&t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-accent",children:t.length})]}),d&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:c("sessions.pinnedSessions")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:c("sessions.noPinnedSessions")}):t.map((e,r)=>{let s;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>S(r),onDragOver:e=>L(e,r),onDrop:()=>M(r),onDragEnd:E,onClick:()=>y(e),className:`group w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 cursor-pointer ${r!==t.length-1?"border-b border-border/50":""} ${v===r?"opacity-50":""} ${w===r?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 cursor-grab",children:(0,n.jsxs)("svg",{className:"w-3 h-3",viewBox:"0 0 10 16",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"3",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"14",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"14",r:"1.5"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",title:e.cwd,children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=e.cwd).split("/").pop()||s})}),h===e.sessionId?(0,n.jsx)("input",{ref:b,type:"text",value:p,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&C(),"Escape"===e.key&&f(null))},onBlur:C,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:e.customTitle||e.sessionId.slice(0,8)})]}),h!==e.sessionId&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>N(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:c("sessions.editTitle"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),a(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:c("sessions.remove"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},e.sessionId)})})]})]})}var m=r(93777);function h(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{minutes:e.delayMinutes});if("interval"===e.type){let r=t("scheduledTasks.everyNMinutes",{minutes:e.intervalMinutes});return e.activeFrom&&e.activeTo?`${r} (${e.activeFrom}-${e.activeTo})`:r}return"cron"===e.type?e.cron||"cron":e.type}function f(e){return e.unread?"bg-red-500":e.completed?"bg-muted-foreground":e.paused?"bg-yellow-500":"error"===e.lastResult?"bg-red-500":"bg-green-500"}function p({collapsed:e,tasks:t,unreadCount:r,onSwitchProject:a,onPause:l,onResume:i,onTrigger:c,onDelete:d,onMarkRead:u,onUpdateTask:x,onReorder:g}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),y=(0,s.useRef)(null),N=t.filter(e=>!e.completed),C=N.filter(e=>!e.paused).length,S=t.filter(e=>e.completed),[L,M]=(0,s.useState)(null),[E,P]=(0,s.useState)(null),$=(0,s.useCallback)(e=>{M(e)},[]),T=(0,s.useCallback)((e,t)=>{e.preventDefault(),P(t)},[]),R=(0,s.useCallback)(e=>{if(null===L||L===e){M(null),P(null);return}let t=[...N],[r]=t.splice(L,1);t.splice(e,0,r),g([...t,...S].map(e=>e.id)),M(null),P(null)},[L,N,S,g]),B=(0,s.useCallback)(()=>{M(null),P(null)},[]),[,F]=(0,s.useState)(0);return(0,s.useEffect)(()=>{if(!v)return;let e=setInterval(()=>F(e=>e+1),1e4);return()=>clearInterval(e)},[v]),(0,s.useEffect)(()=>{if(!v)return;let e=e=>{y.current&&!y.current.contains(e.target)&&j(!1)},t=()=>j(!1);return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[v]),(0,n.jsxs)("div",{className:"relative",ref:y,children:[(0,n.jsxs)("button",{onClick:()=>j(!v),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:b("scheduledTasks.title"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:b("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${e?"absolute -top-1 -right-1":""}`,children:r}):e&&t.length>0?(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-accent",children:t.length}):null]}),v&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-96 max-h-[500px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:b("scheduledTasks.title")}),N.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[b("scheduledTasks.activeCount",{running:C}),N.length-C>0?` \xb7 ${b("scheduledTasks.pausedCount",{paused:N.length-C})}`:""]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:b("scheduledTasks.noScheduledTasks")}):(0,n.jsxs)(n.Fragment,{children:[N.map((e,t)=>{var r;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>$(t),onDragOver:e=>T(e,t),onDrop:()=>R(t),onDragEnd:B,className:`group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 cursor-pointer ${e.unread?"bg-brand/5":""} ${L===t?"opacity-50":""} ${E===t?"border-t-2 border-brand":""}`,onClick:()=>{a(e.cwd,e.sessionId),e.unread&&u(e.id),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${f(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground font-mono",children:(r=e.cwd).split("/").pop()||r}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"\xb7"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:e.completed?b("scheduledTasks.completed"):e.paused?b("scheduledTasks.paused"):b("common.running")})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5",title:e.message,children:e.message}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:h(e,b)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{children:e.paused?b("scheduledTasks.paused"):function(e,t){if(!e)return"-";let r=e-Date.now();if(r<=0)return t("scheduledTasks.aboutToTrigger");if(r<6e4)return t("scheduledTasks.secondsLater",{count:Math.ceil(r/1e3)});if(r<36e5)return t("scheduledTasks.minutesLater",{count:Math.ceil(r/6e4)});if(r<864e5){let e=Math.floor(r/36e5),n=Math.ceil(r%36e5/6e4);return n>0?t("scheduledTasks.hoursMinutesLater",{h:e,m:n}):t("scheduledTasks.hoursLater",{h:e})}return new Date(e).toLocaleDateString("zh-CN",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.nextFireTime,b)}),e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{children:[b("scheduledTasks.lastResult"),": ","success"===e.lastResult?"✓":"✗"]})]})]})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:b("scheduledTasks.runNow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{d:"M8 5v14l11-7z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:b("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-500",title:b("scheduledTasks.resume"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"})})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-yellow-500",title:b("scheduledTasks.pause"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 9v6m4-6v6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})},e.id)}),S.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-muted/30 border-b border-border/50",children:b("scheduledTasks.completedCount",{count:S.length})}),S.map(e=>(0,n.jsx)("div",{className:"group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 opacity-60 cursor-pointer",onClick:()=>{a(e.cwd,e.sessionId),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${f(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:e.message}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground mt-0.5",children:[h(e,b)," \xb7 ","success"===e.lastResult?b("scheduledTasks.success"):b("scheduledTasks.failure")]})]}),(0,n.jsx)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]})},e.id))]})]})})]}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30",onClick:()=>k(null)}),(0,n.jsx)("div",{className:"relative",children:(0,n.jsx)(m.E,{onClose:()=>k(null),onCreate:()=>{},editTask:{id:w.id,message:w.message,type:w.type,delayMinutes:w.delayMinutes,intervalMinutes:w.intervalMinutes,activeFrom:w.activeFrom,activeTo:w.activeTo,cron:w.cron},onUpdate:(e,t)=>{x(e,t),k(null)}})})]})]})}var g=r(3292),b=r(23121),v=r(34075),j=r(2111),w=r(76900);function k({projects:e,activeIndex:t,collapsed:r,currentCwd:i,onSelectProject:c,onRemoveProject:d,onReorderProjects:m,onToggleCollapse:h,onOpenSessionBrowser:f,onOpenSettings:y,onOpenNote:N,onOpenSkills:C,onSwitchProject:S,onAddProject:L}){let{t:M,i18n:E}=(0,o.Bd)(),{latest:P,hasUpdate:$}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;l.t4.runPromiseExit((0,w.Wr)()).then(r=>{!e&&"Success"===r._tag&&r.value.version&&t(r.value.version)});let r=new AbortController,s=setTimeout(()=>r.abort(),3e3);return fetch("https://registry.npmjs.org/@surething/cockpit/latest",{signal:r.signal}).then(e=>e.ok?e.json():null).then(t=>{if(e)return;let r=t?.version;"string"==typeof r&&n(r)}).catch(()=>{}).finally(()=>clearTimeout(s)),()=>{e=!0,r.abort(),clearTimeout(s)}},[]);let o=!!e&&!!r&&function(e,t){let r=e=>e.replace(/^v/,"").split("-")[0].split(".").map(e=>parseInt(e,10)||0),n=r(e),s=r(t),o=Math.max(n.length,s.length);for(let e=0;e<o;e++){let t=n[e]??0,r=s[e]??0;if(t!==r)return t-r}return 0}(r,e)>0;return{current:e,latest:r,hasUpdate:o}}(),[T,R]=(0,s.useState)(!1),B=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!T)return;let e=e=>{B.current?.contains(e.target)||R(!1)},t=()=>R(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[T]);let F=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,v.oR)(M("workspace.upgradeCommandCopied")),R(!1)},[M]),{pinnedSessions:I,unpinSession:D,updateTitle:A,reorder:W}=(0,g.P)(),{tasks:z,unreadCount:_,reload:H,pauseTask:O,resumeTask:q,triggerTask:V,deleteTask:K,updateTask:U,markRead:J,reorderTasks:Q}=(0,b.n)(),[Z,Y]=(0,s.useState)(null),[G,X]=(0,s.useState)(null),[ee,et]=(0,s.useState)([]),er=(0,s.useRef)(ee);(0,s.useEffect)(()=>{er.current=ee});let en=(0,s.useRef)(H);(0,s.useEffect)(()=>{en.current=H});let es=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void en.current();let{data:t}=e;if(!t)return;et(t.sessions||[])}catch{}},[]);(0,j.h)({url:"/ws/global-state",onMessage:es});let eo=new Set(ee.filter(e=>"loading"===e.status).map(e=>e.cwd)),ea=new Set(ee.filter(e=>"unread"===e.status).map(e=>e.cwd)),el=(0,s.useCallback)(e=>{Y(e)},[]),ei=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==Z&&Z!==t&&X(t)},[Z]),ec=(0,s.useCallback)(t=>{if(null!==Z&&Z!==t){let r=[...e],[n]=r.splice(Z,1);r.splice(t,0,n),m(r)}Y(null),X(null)},[Z,e,m]),ed=(0,s.useCallback)(()=>{Y(null),X(null)},[]);return(0,n.jsxs)("div",{className:`h-full bg-card border-r border-border flex flex-col transition-all duration-200 ${r?"w-12":"w-56"}`,children:[(0,n.jsxs)("div",{className:"group p-2 border-b border-border relative",children:[(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:f,title:M("workspace.openProject"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.openProject")})]}),r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-accent text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:M("workspace.expandSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0 rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}):(0,n.jsx)("button",{className:"absolute top-1/2 -translate-y-1/2 right-2 p-2 rounded-lg bg-accent text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:M("workspace.collapseSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:e.map((e,s)=>{var o;let l;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>el(s),onDragOver:e=>ei(e,s),onDrop:()=>ec(s),onDragEnd:ed,className:`${G===s?"border-t-2 border-brand":""} ${Z===s?"opacity-50":""}`,children:(0,n.jsx)(a.ProjectItem,{index:s,name:(l=(o=e.cwd).split("/").filter(Boolean))[l.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:ea.has(e.cwd),isLoading:eo.has(e.cwd),onClick:()=>c(s),onRemove:()=>d(s),onOpenNote:()=>N(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(u,{currentCwd:i,onSwitchProject:S,collapsed:r,sessions:ee}),(0,n.jsx)(x,{collapsed:r,pinnedSessions:I,onSwitchProject:S,onUnpin:D,onUpdateTitle:A,onReorder:W}),(0,n.jsx)(p,{collapsed:r,tasks:z,unreadCount:_,onSwitchProject:S,onPause:O,onResume:q,onTrigger:V,onDelete:K,onMarkRead:J,onUpdateTask:U,onReorder:Q}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:()=>N(),title:M("workspace.notes"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.notes")})]}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:C,title:M("workspace.skills"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.skills")})]}),(0,n.jsxs)("div",{className:`relative flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:y,title:M("workspace.settings"),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),r&&$&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:P?M("workspace.updateAvailable",{version:P}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:M("workspace.settings")}),!r&&$&&P&&(0,n.jsxs)("div",{ref:B,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),R(e=>!e)},className:"px-1.5 py-0.5 rounded text-xs font-mono font-medium text-brand hover:bg-brand/10 transition-colors",title:M("workspace.updateAvailable",{version:P}),"aria-label":M("workspace.updateAvailable",{version:P}),children:["v",P]}),T&&(0,n.jsxs)("div",{className:"absolute left-full bottom-full ml-2 mb-1 w-56 rounded-lg border border-border bg-popover shadow-lg p-2 z-50",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2 px-1",children:M("workspace.updateAvailable",{version:P})}),(0,n.jsxs)("button",{type:"button",onClick:F,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left hover:bg-accent transition-colors",children:[(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]}),(0,n.jsx)("span",{className:"flex-1",children:M("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${E.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>R(!1),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent transition-colors",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"flex-1",children:M("workspace.viewChangelog")}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]}),!r&&(0,n.jsx)("a",{href:`https://opencockpit.dev/${E.language?.startsWith("zh")?"zh":"en"}/docs/get-started/quickstart/`,target:"_blank",rel:"noopener",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",onClick:e=>e.stopPropagation(),title:M("workspace.help"),"aria-label":M("workspace.help"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]})})]})]})]})}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(86957),i=r(76900);function c({children:e}){return(0,s.useEffect)(()=>{l.t4.runPromiseExit((0,i.M5)()).then(e=>{var t;let r="auto"!==(t=("Success"===e._tag?e.value.language:"auto")||"auto")&&t?t:navigator.language.startsWith("zh")?"zh":"en";a.A.language!==r&&a.A.changeLanguage(r)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return a.A.on("languageChanged",e),()=>{a.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&a.A.language!==e.data.lang&&a.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:a.A,children:e})}},53213:(e,t,r)=>{r.d(t,{Bj:()=>c,CM:()=>v,FK:()=>b,Iz:()=>m,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>d,lv:()=>x,oh:()=>g,r4:()=>l,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok){let e;try{e=(await t.json()).error}catch{}throw Error(e||`HTTP ${t.status}`)}return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),a=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),l=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.flatMap(t=>"Failed to get branches"===t.error?n.fail(new s.m_({resource:"git-repo",id:e})):n.succeed(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),c=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),d=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r)=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),x=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),m=(e,t)=>a("/api/git/stage",{cwd:e,files:t}),h=(e,t)=>a("/api/git/unstage",{cwd:e,files:t}),f=(e,t,r)=>a("/api/git/discard",{cwd:e,files:t,isUntracked:r}),p=(e,t,r)=>{let n=new URLSearchParams({cwd:e,file:t,type:r});return o(`/api/git/diff?${n}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json().catch(()=>null);if(!t.ok)throw Error(r?.error||`HTTP ${t.status}`);return r},catch:e=>new s.uV({message:"POST /api/git/worktree failed",cause:e})}),j=e=>o(`/api/projectGraph/search?${e.toString()}`)},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>x});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,a=new Set;function l(){a.forEach(e=>e())}function i(e){a.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(l)),()=>{a.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,l())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function x(){return o??s()}},63048:(e,t,r)=>{r.d(t,{Workspace:()=>K});var n=r(95155),s=r(12115),o=r(79114),a=r(42701),l=r(76288),i=r(83678),c=r(21484),d=r(86957),u=r(83448);let x={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},m={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function h(e){if(x[e])return x[e];let t=e.toLowerCase();return t.includes("opus")?{...m,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...m,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:m}function f(e){let t=x[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function p(e){return(x[e]??h(e)).color}function g(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function b(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function v({data:e,height:t=200,formatValue:r=g}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),[l,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=a.current;if(!n||!s)return;let l=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*l,n.height=t*l,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(l,l),d.clearRect(0,0,i,t);let{labels:u,datasets:x}=e;if(0===u.length)return;let m=i-50-12,h=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>x.reduce((e,r)=>e+r.data[t],0))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+m,s),d.stroke()}let g=m/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;x.forEach(n=>{var o,a,l,i,c,u;let x=n.data[t];if(x<=0)return;let m=x/f*h,p=8+h-s-m;d.fillStyle=n.color,o=d,a=r,l=p,i=b,u=2,(c=m)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(a+u,l),o.lineTo(a+i-u,l),o.quadraticCurveTo(a+i,l,a+i,l+u),o.lineTo(a+i,l+c-u),o.quadraticCurveTo(a+i,l+c,a+i-u,l+c),o.lineTo(a+u,l+c),o.quadraticCurveTo(a,l+c,a,l+c-u),o.lineTo(a,l+u),o.quadraticCurveTo(a,l,a+u,l),o.fill()),v.push({x:r,y:p,w:b,h:m,label:e,value:x,dataset:n.label,color:n.color}),s+=m}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+h+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return a.current&&e.observe(a.current),()=>e.disconnect()},[d]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,a=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);a?i({x:e.clientX-t.left,y:a.y-4,content:`${a.dataset}: ${r(a.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:a,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),l&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:l.x,top:l.y,transform:"translate(-50%, -100%)"},children:l.content})]})}function j({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:s.map(s=>{let o=e[String(s)]||0,a=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*a)}px`,backgroundColor:a>0?`rgba(59, 130, 246, ${.2+.8*a})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function w({isOpen:e,onClose:t}){var r;let a,l,{t:i}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[m,y]=(0,s.useState)(!0),[N,C]=(0,s.useState)("day"),[S,L]=(0,s.useState)("tokens"),[M,E]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>y(!0)),d.t4.runPromiseExit((0,u.Cr)(M)).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>x(t))}queueMicrotask(()=>y(!1))}))},[e,M]);let P=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:f(e),color:p(e),usage:t,cost:(r=h(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[c]),$=(0,s.useMemo)(()=>P.reduce((e,t)=>e+t.cost,0),[P]),T=(0,s.useMemo)(()=>P.map(e=>e.id),[P]),R=(0,s.useMemo)(()=>{let e={};for(let t of P)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[P]),{activityChart:B,tokenChart:F,costChart:I}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===N){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:T.map(e=>({label:f(e),data:n.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:o,datasets:T.map(e=>({label:f(e),data:n.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}}if("week"===N){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let a=r.get(s);a.messages+=t.messageCount,a.sessions+=t.sessionCount,a.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:T.map(e=>({label:f(e),data:r.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:n,datasets:T.map(e=>({label:f(e),data:r.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:T.map(e=>({label:f(e),data:r.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:n,datasets:T.map(e=>({label:f(e),data:r.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}},[c,N,T,R,i]);if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),!e)return null;let D=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${M===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{x(null),E(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:D.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${N===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:m?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(k,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(k,{label:i("tokenStats.totalMessages"),value:g(c.totalMessages??0)}),(0,n.jsx)(k,{label:i("tokenStats.equivalentApiCost"),value:b($),highlight:!0}),(0,n.jsx)(k,{label:i("tokenStats.longestSession"),value:c.longestSession?(a=Math.floor((r=c.longestSession.duration)/36e5),l=Math.floor(r%36e5/6e4),a>0?`${a}h ${l}m`:`${l}m`):"-"}),(0,n.jsx)(k,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#3b82f6"}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(v,{data:B,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===S?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>L("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===S?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>L("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:P.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(v,{data:"tokens"===S?F:I,height:180,formatValue:"tokens"===S?g:b})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[P.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:$>0?`${(e.cost/$*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:b(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(P.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(P.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(P.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(P.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:b($)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function k({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var y=r(8648),N=r(34075),C=r(5135),S=r(38408),L=r(49433),M=r(82680);let E=(e,t)=>L.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:r=>new M.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})});function P({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return l(!0),d.t4.runPromiseExit(E(`/api/skills/content?id=${encodeURIComponent(e)}`)).then(e=>{t||("Success"===e._tag?o(e.value):console.error("Failed to load skill content",e.cause),l(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let u=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,N.oR)("Path copied","success")}catch{(0,N.oR)("Failed to copy","error")}},[r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-[70%] h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:u,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)(C.M,{content:r.content,filePath:r.path,cwd:r.path.slice(0,Math.max(0,r.path.lastIndexOf("/"))),embedded:!0,onClose:t}):(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(S.XO,{content:r.content,filePath:r.path,className:"min-h-full"})}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"File cannot be read."})]})]})}var $=r(88371);function T({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[a,l]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[u,x]=(0,s.useState)(!1),[m,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),v=(0,s.useCallback)(async()=>{l(!0);let e=await d.t4.runPromiseExit(E("/api/skills"));"Success"===e._tag?o(e.value):console.error("Failed to load skills",e.cause),l(!1)},[]);(0,s.useEffect)(()=>{e&&v()},[e,v]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!g){if(u){x(!1),h("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,u,g]);let j=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),w=(0,s.useCallback)(async()=>{let e=m.trim();if(!e)return;p(!0);let t=await d.t4.runPromiseExit(E("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}));if("Success"===t._tag)(0,N.oR)("Skill added","success"),h(""),x(!1),await v(),(0,$.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:"Failed to add skill";(0,N.oR)(n,"error")}p(!1)},[m,v]),k=(0,s.useCallback)(async e=>{"Success"===(await d.t4.runPromiseExit(E(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})))._tag?(o(t=>t.filter(t=>t.id!==e)),(0,$.k)()):(0,N.oR)("Failed to delete","error")},[]),y=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,N.oR)("Path copied","success")}catch{(0,N.oR)("Failed to copy","error")}},[]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-7xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:"Skills"}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsxs)("button",{onClick:()=>x(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:"Add Skill",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Add Skill"]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:a?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===j.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:j.map(e=>(0,n.jsx)(R,{skill:e,onPreview:()=>b(e.id),onDelete:()=>k(e.id),onCopyPath:()=>y(e.path)},e.id))})})]})]}),u&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>{f||(x(!1),h(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||w()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{x(!1),h("")},disabled:f,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:w,disabled:f||!m.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:f?"Adding...":"Add"})]})]})]}),g&&(0,n.jsx)(P,{skillId:g,onClose:()=>b(null)})]}):null}function R({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[a,l]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`group flex flex-col h-full border border-border rounded-lg p-3 bg-secondary hover:border-brand hover:shadow-md transition-all ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground truncate flex-1 min-w-0",title:`/${e.name}`,children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{l(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>l(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>l(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"Delete",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 break-all",children:[e.path,(0,n.jsx)("button",{onClick:o,className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mt-2 pt-2 border-t border-border/60 break-words whitespace-pre-wrap",children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:"No description"})}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-1 truncate",title:e.argumentHint,children:e.argumentHint})]})}var B=r(47650);let F=[],I=[];function D(){I.forEach(e=>e())}function A(e){F=F.filter(t=>t.id!==e),D()}function W({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return I.push(t),()=>{I=I.filter(e=>e!==t)}},[]),F}();return 0===t.length?null:(0,B.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(z,{item:t,onNavigate:e,onRemove:A},t.id))}),document.body)}function z({item:e,onNavigate:t,onRemove:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),x=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),m=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${l?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:l?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:x,onMouseLeave:m,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:a("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}var _=r(10592),H=r(86359),O=r(80905),q=r(80286);let V=L.tryPromise({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new M.uV({message:"fetch /api/projects failed",cause:e})});function K({initialCwd:e,initialSessionId:t}){let{t:u}=(0,o.Bd)(),[x,m]=(0,s.useState)([]),[h,f]=(0,s.useState)(0),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,E]=(0,s.useState)(!1),[P,$]=(0,s.useState)(null),[R,B]=(0,s.useState)(!1),[I,A]=(0,s.useState)(!1),[z,U]=(0,s.useState)(new Set),J=(0,s.useRef)(new Map),Q=(0,s.useRef)(new Map),Z=(0,s.useRef)(new Map),Y=(0,s.useRef)(null),G=function(e,t){let[r,n]=(0,s.useState)({status:"loading"});return(0,s.useEffect)(()=>{n({status:"loading"});let t=d.t4.runFork(e);return t.addObserver(e=>{_.YW(e,{onSuccess:e=>n({status:"success",data:e}),onFailure:e=>{let t=H.od(e);n({status:"error",error:O.Ru(t)?t.value:e})}})}),()=>{L.runFork(q.G(t))}},t),r}(V,[]);(0,s.useEffect)(()=>{if("success"===G.status){let e=G.data;m([...e.projects||[]]),f(e.activeIndex||0),g(e.collapsed||!1),A(!0)}else"error"===G.status&&(console.error("Failed to load projects:",G.error),A(!0))},[G]);let X=(0,s.useCallback)(async(e,t,n)=>{let s,{Effect:o}=await r.e(9012).then(r.bind(r,49012)),{BrowserRuntime:a}=await r.e(7562).then(r.bind(r,47562)),l=await a.runPromise((s={projects:e,activeIndex:t,collapsed:n},L.tryPromise({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new M.uV({message:"save /api/projects failed",cause:e})})).pipe(o.either));"Left"===l._tag&&console.error("Failed to save projects:",l.left)},[]);(0,s.useEffect)(()=>{let e=x[h]?.cwd;e&&U(t=>t.has(e)?t:new Set(t).add(e))},[h,x]),(0,s.useEffect)(()=>{for(let[e,t]of J.current.entries()){let r=x[h]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[h,x]);let ee=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),et=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!I||et.current||!e)return;et.current=!0,t&&(Q.current.set(e,{sessionId:t}),Z.current.set(e,t));let r=x.findIndex(t=>t.cwd===e);if(r>=0)r!==h&&(f(r),X(x,r,p));else{let t=[...x,{cwd:e}],r=t.length-1;m(t),f(r),X(t,r,p)}ee(e,t)},[I,e,t,x,h,p,X,ee]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;Z.current.set(t,r);let n=x[h];n?.cwd===t&&ee(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=x[h];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,F=[...F,{...t,id:e}],D()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&C(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&($(e.data.cwd),E(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){Y.current=h;let t=e.data.cwd,r=x.findIndex(e=>e.cwd===t);r>=0&&r!==h&&f(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==Y.current&&Y.current!==h&&f(Y.current),Y.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";Z.current.set(t,n);let s=x.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=J.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==h&&(f(s),X(x,s,p))}else{let e=[...x,{cwd:t}],r=e.length-1;m(e),f(r),X(e,r,p),n&&Q.current.set(t,{sessionId:n})}ee(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[x,h,p,ee,X]),(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey){if(!e.shiftKey&&("p"===e.key||"f"===e.key||"s"===e.key))return void e.preventDefault();e.ctrlKey&&!e.metaKey&&"Minus"===e.code&&e.preventDefault()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let er=(0,s.useCallback)(e=>{f(e),X(x,e,p);let t=x[e];if(t?.cwd){let e=Z.current.get(t.cwd);ee(t.cwd,e)}},[x,p,X,ee]),en=(0,s.useCallback)(e=>{let t=x.filter((t,r)=>r!==e),r=h;e<h?r=h-1:e===h&&r>=t.length&&(r=Math.max(0,t.length-1)),m(t),f(r),X(t,r,p)},[x,h,p,X]),es=(0,s.useCallback)(e=>{let t=x[h],r=e.findIndex(e=>e.cwd===t?.cwd);m(e),f(r>=0?r:0),X(e,r>=0?r:0,p)},[x,h,p,X]),eo=(0,s.useCallback)(()=>{let e=!p;g(e),X(x,h,e)},[x,h,p,X]),ea=(0,s.useCallback)((e,t)=>{Z.current.set(e,t);let r=x.findIndex(t=>t.cwd===e);if(r>=0){let n=J.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),f(r),X(x,r,p)}else{let r=[...x,{cwd:e}],n=r.length-1;m(r),f(n),X(r,n,p),Q.current.set(e,{sessionId:t,switchToAgent:!0})}ee(e,t),v(!1)},[x,p,X,ee]),el=(0,s.useCallback)((e,t)=>{Z.current.set(e,t);let r=x.findIndex(t=>t.cwd===e);if(r>=0){let n=J.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==h&&(f(r),X(x,r,p))}else{let r=[...x,{cwd:e}],n=r.length-1;m(r),f(n),X(r,n,p),Q.current.set(e,{sessionId:t,switchToAgent:!0})}ee(e,t)},[x,h,p,X,ee]),ei=(0,s.useCallback)(e=>{let t=Q.current.get(e);if(t){let r=J.current.get(e);r?.contentWindow&&r.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t.sessionId,switchToAgent:t.switchToAgent},"*"),Q.current.delete(e)}},[]);return I?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(a.ProjectSidebar,{projects:x,activeIndex:h,collapsed:p,currentCwd:x[h]?.cwd,onSelectProject:er,onRemoveProject:en,onReorderProjects:es,onToggleCollapse:eo,onOpenSessionBrowser:()=>v(!0),onOpenSettings:()=>k(!0),onOpenNote:e=>{$(e??null),E(!0)},onOpenSkills:()=>B(!0),onSwitchProject:el,onAddProject:e=>{let t=x.findIndex(t=>t.cwd===e);if(t>=0)f(t),X(x,t,p);else{let t=[...x,{cwd:e}],r=t.length-1;m(t),f(r),X(t,r,p)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===x.length?(0,n.jsx)(l.EmptyState,{onSelectSession:ea}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:x.map((e,t)=>z.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?J.current.set(e.cwd,t):J.current.delete(e.cwd)},src:`/project?cwd=${encodeURIComponent(e.cwd)}`,onLoad:()=>ei(e.cwd),className:`absolute inset-0 w-full h-full border-0 ${t===h?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd))})}),(0,n.jsx)(i.SessionBrowser,{isOpen:b,onClose:()=>v(!1),onSelectSession:ea,onAddProject:e=>{let t=x.findIndex(t=>t.cwd===e);if(t>=0)f(t),X(x,t,p);else{let t=[...x,{cwd:e}],r=t.length-1;m(t),f(r),X(t,r,p)}v(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:j,onClose:()=>k(!1)}),(0,n.jsx)(w,{isOpen:N,onClose:()=>C(!1)}),(0,n.jsx)(y.NoteModal,{isOpen:S,onClose:()=>{E(!1),$(null)},projectCwd:P,projectName:P?P.split("/").pop():null}),(0,n.jsx)(T,{isOpen:R,onClose:()=>B(!1)}),(0,n.jsx)(W,{onNavigate:el})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:u("workspace.loadingText")})]})})}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>d,fY:()=>c,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],a={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},l=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(l);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function c({activeView:e,onViewChange:t,children:r}){let a=(0,s.useRef)(null),i=(0,s.useRef)(!1),d=(0,s.useRef)(0),[u,x]=(0,s.useState)(0),[m,h]=(0,s.useState)(!1),f=o.indexOf(e),p=o.length-1;(0,s.useEffect)(()=>{d.current=0,queueMicrotask(()=>x(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){let r=e.target;if("IFRAME"===r.tagName||function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth>e.clientWidth)return!0;e=e.parentElement}return!1}(r))return;e.preventDefault(),e.stopPropagation(),i.current&&(i.current=!1);let n=window.innerWidth,s=d.current-6*e.deltaX;!(f>0)&&s>0&&(s=0),!(f<p)&&s<0&&(s=0),d.current=s=Math.max(-n,Math.min(n,s)),x(s),h(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{let e=d.current,r=.12*n;h(!1),i.current=!0;let s=f;e<-r&&f<p?s=f+1:e>r&&f>0&&(s=f-1),d.current=0,x(0),s!==f&&t(o[s]),setTimeout(()=>{i.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[f,p,t]);let[g,b]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>b(!0))},[]);let v={activeView:e,onViewChange:t,dragOffset:(()=>{if(!g)return 0;let e=window.innerWidth;return e?u/e:0})(),isDragging:g&&m};return(0,n.jsx)(l.Provider,{value:v,children:r})}function d({children:e}){let t,r,{activeView:a,dragOffset:l,isDragging:c}=i(),u=(0,s.useRef)(null),x=(0,s.useRef)(null),m=o.indexOf(a),h=o.length;return(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{0!==e.scrollLeft&&(e.scrollLeft=0)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.jsx)("div",{ref:u,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:x,className:c?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=l/h*100,r=-(100/h*m)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function u(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:l}=i(),c=(0,s.useRef)(null),d=(0,s.useRef)([]),[u,x]=(0,s.useState)({left:0,width:0}),m=o.indexOf(e),h=()=>{if(!c.current||0===d.current.length)return{left:0,width:0};let e=c.current.getBoundingClientRect(),t=d.current.filter(Boolean);if(t.length!==o.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(o.length-1,m-n)),a=Math.floor(s),l=Math.ceil(s),i=s-a,u=t[a],x=t[l];if(!u||!x)return{left:0,width:0};let h=u.getBoundingClientRect(),f=x.getBoundingClientRect();return{left:h.left+(f.left-h.left)*i-e.left,width:h.width+(f.width-h.width)*i}};(0,s.useEffect)(()=>{queueMicrotask(()=>x(h()))},[m,r]),(0,s.useEffect)(()=>{let e=()=>{x(h())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[m,r]);let f=Number.isFinite(r)?r:0,p=Math.round(Math.max(0,Math.min(o.length-1,m-f)));return(0,n.jsxs)("div",{ref:c,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{d.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${p===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:a[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${l?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>l});var n=r(95155),s=r(12115),o=r(79114);function a({editor:e,onClose:t,position:r}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)(()=>e.getAttributes("link").href||""),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.current?.focus()},[]);let u=()=>{let r=i.trim();if(r){let t=r.match(/^https?:\/\//)?r:`https://${r}`;e.chain().focus().extendMarkRange("link").setLink({href:t}).run()}else e.chain().focus().extendMarkRange("link").unsetLink().run();t()},x=r?{top:r.top,left:r.left}:{};return(0,n.jsxs)("div",{className:`${r?"fixed":"absolute top-full left-0 mt-1"} z-[60] bg-popover border border-border rounded-lg shadow-lg p-2 flex items-center gap-2`,style:x,children:[(0,n.jsx)("input",{ref:d,type:"text",value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:l("editor.linkPlaceholder"),className:"bg-background border border-border rounded px-2 py-1 text-sm w-64 outline-none focus:border-brand"}),(0,n.jsx)("button",{onClick:u,className:"p-1 rounded text-sm font-medium text-brand hover:bg-brand/10 transition-colors",title:l("editor.confirmLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})}),e.isActive("link")&&(0,n.jsx)("button",{onClick:()=>{e.chain().focus().extendMarkRange("link").unsetLink().run(),t()},className:"p-1 rounded text-sm font-medium text-red-500 hover:bg-red-500/10 transition-colors",title:l("editor.removeLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})}function l({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),[,d]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>d(e=>e+1);return e.on("selectionUpdate",t),e.on("transaction",t),()=>{e.off("selectionUpdate",t),e.off("transaction",t)}},[e]),(0,s.useEffect)(()=>{let e=()=>i(!0);return window.addEventListener("tiptap-insert-link",e),()=>window.removeEventListener("tiptap-insert-link",e)},[]),!e)return null;let u=e=>`p-1.5 rounded text-xs font-medium transition-colors ${e?"bg-brand/15 text-brand":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,x="w-px h-5 bg-border mx-0.5",m=e.isActive("table");return(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-4 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsx)("button",{className:u(e.isActive("heading",{level:1})),onClick:()=>e.chain().focus().toggleHeading({level:1}).run(),title:t("editor.heading1"),children:"H1"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:2})),onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),title:t("editor.heading2"),children:"H2"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:3})),onClick:()=>e.chain().focus().toggleHeading({level:3}).run(),title:t("editor.heading3"),children:"H3"}),(0,n.jsx)("div",{className:x}),(0,n.jsx)("button",{className:u(e.isActive("bold")),onClick:()=>e.chain().focus().toggleBold().run(),title:t("editor.bold"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"})})}),(0,n.jsx)("button",{className:u(e.isActive("italic")),onClick:()=>e.chain().focus().toggleItalic().run(),title:t("editor.italic"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"})})}),(0,n.jsx)("button",{className:u(e.isActive("strike")),onClick:()=>e.chain().focus().toggleStrike().run(),title:t("editor.strikethrough"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("code")),onClick:()=>e.chain().focus().toggleCode().run(),title:t("editor.inlineCode"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})})}),(0,n.jsx)("div",{className:x}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{ref:c,className:u(e.isActive("link")),onClick:()=>i(!r),title:t("editor.link"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})}),r&&(0,n.jsx)(a,{editor:e,onClose:()=>i(!1),position:null})]}),(0,n.jsx)("div",{className:x}),(0,n.jsx)("button",{className:u(e.isActive("bulletList")),onClick:()=>e.chain().focus().toggleBulletList().run(),title:t("editor.bulletList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"})})}),(0,n.jsx)("button",{className:u(e.isActive("orderedList")),onClick:()=>e.chain().focus().toggleOrderedList().run(),title:t("editor.orderedList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("taskList")),onClick:()=>e.chain().focus().toggleTaskList().run(),title:t("editor.taskList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM17.99 9l-1.41-1.42-6.59 6.59-2.58-2.57-1.42 1.41 4 3.99z"})})}),(0,n.jsx)("div",{className:x}),(0,n.jsx)("button",{className:u(e.isActive("blockquote")),onClick:()=>e.chain().focus().toggleBlockquote().run(),title:t("editor.blockquote"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"})})}),(0,n.jsx)("button",{className:u(e.isActive("codeBlock")),onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.codeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H4V5h16v14zm-7.5-4.5L15 12l-2.5-2.5L11 11l1.5 1.5L11 14l1.5 1.5zM9.5 14.5L7 12l2.5-2.5L11 11 9.5 12.5 11 14l-1.5.5z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:t("editor.table"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-9 15H4v-4h7v4zm0-6H4V7h7v4zm9 6h-7v-4h7v4zm0-6h-7V7h7v4z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().setHorizontalRule().run(),title:t("editor.horizontalRule"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 11h16v2H4z"})})}),m&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:x}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowBefore().run(),title:t("editor.insertRowAbove"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zM11 17H4v-2h7v2zm0-4H4v-2h7v2zm9 4h-7v-2h7v2zm0-4h-7v-2h7v2z"}),(0,n.jsx)("path",{d:"M14 1h-4v2H8v2h2v2h4V5h2V3h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowAfter().run(),title:t("editor.insertRowBelow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v10h20V6c0-1.1-.9-2-2-2zM11 12H4v-2h7v2zm0-4H4V6h7v2zm9 4h-7v-2h7v2zm0-4h-7V6h7v2z"}),(0,n.jsx)("path",{d:"M14 19h-4v2H8v2h2v-2h4v2h2v-2h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnBefore().run(),title:t("editor.insertColumnLeft"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 11H10v-2h7v2zm0-4H10V9h7v2z"}),(0,n.jsx)("path",{d:"M1 14v-4h2V8h2v2h-2v4h2v2H3v-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnAfter().run(),title:t("editor.insertColumnRight"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M4 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h10V4H4zm7 11H4v-2h7v2zm0-4H4V9h7v2z"}),(0,n.jsx)("path",{d:"M18 4v20h2c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-2z"}),(0,n.jsx)("path",{d:"M21 14v-4h2V8h2v2h-2v4h2v2h-2v-2z",opacity:".6"})]})}),(0,n.jsx)("div",{className:x}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-500 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteRow().run(),title:t("editor.deleteRow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zm-8 8H4v-2h8v2z"}),(0,n.jsx)("path",{d:"M15 13l-1.41 1.41L15.17 16l-1.58 1.59L15 19l1.59-1.59L18.17 19l1.42-1.41L18 16l1.59-1.59L18.17 13 16.59 14.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-500 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteColumn().run(),title:t("editor.deleteColumn"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 7H10V9h7v2z"}),(0,n.jsx)("path",{d:"M13 16l-1.41 1.41L13.17 19l-1.58 1.59L13 22l1.59-1.59L16.17 22l1.42-1.41L16 19l1.59-1.59L16.17 16l-1.58 1.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-500 hover:bg-red-500/10",onClick:()=>e.chain().focus().deleteTable().run(),title:t("editor.deleteTable"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]}),e.isActive("codeBlock")&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:x}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-500 hover:bg-red-500/10",onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.deleteCodeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})]})}},76288:(e,t,r)=>{r.d(t,{EmptyState:()=>i});var n=r(95155),s=r(12115),o=r(79114),a=r(86957),l=r(76900);function i({onSelectSession:e}){let{t}=(0,o.Bd)(),[r,c]=(0,s.useState)([]),[d,u]=(0,s.useState)({}),[x,m]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{m(!0),f(null),u({});let e=await a.t4.runPromiseExit((0,l.H7)());"Success"===e._tag?c(e.value):f("Failed to load projects"),m(!1)},[]),j=(0,s.useCallback)(async e=>{u(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await a.t4.runPromiseExit((0,l.QW)(e));"Success"===t._tag?u(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):u(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),w=(0,s.useCallback)(e=>{let t=d[e];t?.isExpanded?u(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?u(t=>({...t,[e]:{...t[e],isExpanded:!0}})):j(e)},[d,j]);return(0,s.useEffect)(()=>{v(),setTimeout(()=>{b.current?.focus()},100)},[v]),(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-card",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-lg font-medium text-foreground",children:t("workspace.selectProject")}),(0,n.jsx)("input",{ref:b,type:"text",placeholder:t("workspace.searchProjectPath"),value:p,onChange:e=>g(e.target.value),className:"px-3 py-1.5 text-sm border border-border rounded-lg bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[x&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:t("workspace.loadingProjects")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-red-500",children:h})}),!x&&!h&&0===r.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:t("workspace.projectNotFound")})}),!x&&!h&&(0,n.jsx)("div",{className:"space-y-2",children:r.filter(e=>e.fullPath.toLowerCase().includes(p.toLowerCase())).map(r=>{let s=d[r.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>w(r.encodedPath),className:"w-full flex items-center gap-3 p-3 hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-4 h-4 text-muted-foreground transition-transform ${s.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-5 h-5 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate",children:r.name}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:r.fullPath})]}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground bg-secondary px-2 py-0.5 rounded",children:t("workspace.sessions",{count:r.sessionCount})})]}),s.isExpanded&&(0,n.jsxs)("div",{className:"border-t border-border bg-secondary/30",children:[s.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:t("workspace.loadingSessions")})]}),s.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-500",children:s.error}),!s.isLoading&&!s.error&&0===s.sessions.length&&(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:t("workspace.noSessions")}),!s.isLoading&&!s.error&&s.sessions.map(t=>(0,n.jsxs)("button",{onClick:()=>{e(r.fullPath,(t.path.split("/").pop()||"").replace(".jsonl",""))},className:"w-full flex items-start gap-3 p-3 hover:bg-accent transition-colors text-left border-t border-border first:border-t-0",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:t.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),t.firstMessages.length>0&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:t.firstMessages[0]})]})]},t.path))]})]},r.encodedPath)})})]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>p});var n=r(95155),s=r(12115),o=r(63728),a=r(82032),l=r(34075),i=r(79114),c=r(95045),d=r(75346),u=r(49433),x=r(86957),m=r(53213),h=r(76900);function f({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[a,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)([]),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),k=(0,s.useRef)(null),y=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{g(!0);let t=await x.t4.runPromiseExit((0,m.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];u([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,l.oR)(o("toast.loadBranchFailed"),"error");g(!1)},[e,o]),C=(0,s.useCallback)(()=>{c(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{c(!1)},[]);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{k.current&&!k.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a,S]),(0,s.useEffect)(()=>{a&&setTimeout(()=>y.current?.focus(),50)},[a]);let L=async t=>{v(!0);let n=await x.t4.runPromiseExit((0,h.Kl)({action:"checkout",cwd:e,path:e,branch:t}));if("Success"===n._tag){let e=t.replace(/^origin\//,"");(0,l.oR)(o("toast.switchedToBranch",{branch:e}),"success"),S(),r()}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:o("toast.switchBranchFailed");(0,l.oR)(r,"error")}v(!1)},M=d.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:a?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:o("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),a&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:y,type:"text",value:j,onChange:e=>w(e.target.value),placeholder:o("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:p?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===M.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):M.map(e=>(0,n.jsx)("button",{onClick:()=>L(e),disabled:b,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function p({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:m,onOpenAliasManager:g,onBranchSwitched:b}){let{t:v}=(0,i.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:v("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,l.oR)(v("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,l.oR)(v("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:m,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(f,{cwd:e,currentBranch:s,onSwitched:()=>b?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(o.gT,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(a.ReviewDropdown,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&x.t4.runFork((0,h.em)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&x.t4.runFork((0,h.Q1)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,l.oR)(v("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("chat.copyCommandTooltip",{sessionId:t.sessionId}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:g,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>(0,c.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},76900:(e,t,r)=>{r.d(t,{Cq:()=>m,D0:()=>p,DZ:()=>i,H7:()=>h,It:()=>b,Kl:()=>k,M5:()=>l,Or:()=>d,Q1:()=>j,QW:()=>f,Wr:()=>c,Yn:()=>g,b2:()=>w,em:()=>v,zF:()=>x});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:r=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})}),a=(e,t)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),l=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/version"),d=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",x=e=>o(u(e)),m=(e,t)=>a(u(e),{content:t}),h=()=>o("/api/sessions/projects"),f=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),p=e=>o(`/api/project-settings?cwd=${encodeURIComponent(e)}`),g=e=>a("/api/project-settings",e),b=()=>o("/api/pick-folder"),v=e=>a("/api/open-vscode",{cwd:e}),j=e=>a("/api/open-cursor",{cwd:e}),w=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),k=e=>a("/api/git/worktree",e)},83678:(e,t,r)=>{r.d(t,{SessionBrowser:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(95045),l=r(75346),i=r(86957),c=r(76900);function d({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u}){let{t:x}=(0,o.Bd)(),[m,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)({}),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),C=(0,s.useRef)(null),S=(0,s.useCallback)(async()=>{j(!0),k(null),b({});let e=await i.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?p(e.value):k("Failed to load projects"),j(!1)},[]),L=(0,s.useCallback)(async e=>{b(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?b(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):b(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),M=(0,s.useCallback)(e=>{let t=g[e];t?.isExpanded?b(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?b(t=>({...t,[e]:{...t[e],isExpanded:!0}})):L(e)},[g,L]);(0,s.useEffect)(()=>{e&&(S(),setTimeout(()=>{C.current?.focus()},100))},[e,S]);let E=(0,s.useCallback)(async()=>{if(m)return;h(!0);let e=await i.t4.runPromiseExit((0,c.It)());"Success"===e._tag&&e.value.folder&&u&&(u(e.value.folder),t()),h(!1)},[m,u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:x("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("input",{ref:C,type:"text",placeholder:x("workspace.searchProjectPath"),value:y,onChange:e=>N(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),u&&(0,n.jsxs)("button",{onClick:E,disabled:m,className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",title:x("sessions.openFolder"),children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),m?x("sessions.selectingFolder"):x("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[v&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:x("workspace.loadingProjects")})]})}),w&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:w})}),!v&&!w&&0===f.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:x("workspace.projectNotFound")})}),!v&&!w&&f.filter(e=>e.fullPath.toLowerCase().includes(y.toLowerCase())).map(e=>{let t=g[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>M(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform ${t.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate",title:e.fullPath,children:e.fullPath}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.sessionCount,")"]})]}),t.isExpanded&&(0,n.jsxs)("div",{className:"ml-6 mt-2",children:[t.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-3 w-3",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:x("sessions.loadingSessions")})]}),t.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:t.error}),!t.isLoading&&!t.error&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:t.sessions.map(t=>(0,n.jsxs)("div",{onClick:()=>{var n;let s;return n=e.fullPath,s=(t.path.split("/").pop()||"").replace(".jsonl",""),void(r?r(n,s):(0,a.F)(l.n.OpenProject,{cwd:n,sessionId:s}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[t.engine&&"claude"!==t.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===t.engine?"bg-orange-500/15 text-orange-11":"ollama"===t.engine?"bg-blue-500/15 text-blue-11":"codex"===t.engine?"bg-green-500/15 text-green-11":"kimi"===t.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:t.title,children:t.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[t.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path))})]})]},e.encodedPath)})]})]})]}):null}},84310:(e,t,r)=>{r.d(t,{Providers:()=>u});var n=r(95155),s=r(47617),o=r(3238),a=r(34075),l=r(12115),i=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function d(){let[e,t]=(0,l.useState)(null),r=(0,l.useRef)(null);r.current=e;let s=(0,l.useRef)(null),o=(0,l.useRef)(null),[a,d]=(0,l.useState)({left:0,top:0}),[u,x]=(0,l.useState)(!1);return((0,l.useEffect)(()=>x(!0),[]),(0,l.useEffect)(()=>{let e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},n=n=>{let o=c(n.target);if(!o){e(),r.current&&t(null);return}if(r.current&&r.current.text===o)return void t({text:o,x:n.clientX,y:n.clientY});e();let a=n.clientX,l=n.clientY;s.current=setTimeout(()=>{t({text:o,x:a,y:l}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},a=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("mousedown",a),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",a),document.removeEventListener("mousedown",a),e()}},[]),(0,l.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,a=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),a+t.height>n-8&&(a=e.y-t.height-8),d({left:s,top:a})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none max-w-[80vw] overflow-hidden text-ellipsis",style:{left:a.left,top:a.top},children:e.text}),document.body):null}function u({children:e}){return(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.N,{children:(0,n.jsxs)(a.tE,{children:[e,(0,n.jsx)(d,{})]})})})}},88371:(e,t,r)=>{r.d(t,{U:()=>o,k:()=>s});let n="cockpit-skills";function s(){let e="u"<typeof BroadcastChannel?null:new BroadcastChannel(n);if(e)try{e.postMessage({type:"changed"})}finally{e.close()}}function o(e){if("u"<typeof BroadcastChannel)return()=>{};let t=new BroadcastChannel(n),r=t=>{t.data?.type==="changed"&&e()};return t.addEventListener("message",r),()=>{t.removeEventListener("message",r),t.close()}}},89039:(e,t,r)=>{r.d(t,{useTabState:()=>u});var n=r(12115),s=r(41474),o=r(2111),a=r(95045),l=r(75346),i=r(49433),c=r(86957),d=r(96472);function u({initialCwd:e,initialSessionId:t,activeView:r}){let x=(0,n.useRef)(!1),m=(0,n.useRef)(!0),h=(0,n.useRef)(r);(0,n.useEffect)(()=>{h.current=r},[r]);let f=(0,s.F)(),p=(0,n.useRef)(f);(0,n.useEffect)(()=>{p.current=f},[f]);let[g,b]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[v,j]=(0,n.useState)(g[0]?.id??""),[w,k]=(0,n.useState)(new Set),y=(0,n.useRef)(g);(0,n.useEffect)(()=>{y.current=g},[g]);let N=(0,n.useRef)(v);(0,n.useEffect)(()=>{N.current=v},[v]);let C=(0,n.useRef)(new Set),S=(0,n.useCallback)((t,r)=>{e&&t&&c.t4.runFork((0,d.KJ)(e,t,r).pipe(i.catchAll(()=>i.void)))},[e]),[L,M]=(0,n.useState)(null),[E,P]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||x.current||(x.current=!0,(async()=>{let r=await c.t4.runPromise((0,d.n8)(e).pipe(i.catchAll(()=>i.succeed(null))));if(r){let n=r.sessions||[],s=r.activeSessionId,o=r.engines||{},a=r.ollamaModels||{},l=r.deepseekModels||{},i=r.chatModes||{},c=r.planModes||{},d=[...n];if(t&&!d.includes(t)&&(d=[t,...d]),d.length>0){let r=d.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:o[t]||void 0,ollamaModel:a[t]||void 0,deepseekModel:l[t]||void 0,chatMode:i[t]||void 0,planMode:c[t]||void 0})),n=t||s,u=n?d.indexOf(n):-1;u<0&&(u=0);let x=r[u].id;b(r),j(x),setTimeout(()=>{m.current=!1},0)}else m.current=!1}else m.current=!1})())},[e,t]),(0,n.useEffect)(()=>{if(m.current||!e)return;let t=g.map(e=>e.sessionId).filter(e=>!!e),r=g.find(e=>e.id===v),n=r?.sessionId,s={},o={},a={},l={},u={};for(let e of g)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(a[e.sessionId]=e.deepseekModel),e.sessionId&&(l[e.sessionId]="pty"===e.chatMode?"pty":"sdk",u[e.sessionId]=!!e.planMode);let x=[...C.current];c.t4.runFork((0,d.ej)({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:o,deepseekModels:a,chatModes:l,planModes:u,...x.length?{closedSessionIds:x}:{}}).pipe(i.tap(()=>i.sync(()=>{for(let e of x)C.current.delete(e)})),i.tapError(e=>i.sync(()=>console.error("Failed to save sessions:",e))),i.catchAll(()=>i.void)))},[g,v,e]),(0,n.useEffect)(()=>{if(m.current||!e)return;let t=g.find(e=>e.id===v);t?.sessionId&&(0,a.F)(l.n.SessionChange,{cwd:e,sessionId:t.sessionId})},[v,g,e]);let $=(0,n.useCallback)(t=>{e&&c.t4.runPromise((0,d.n8)(e).pipe(i.catchAll(()=>i.succeed(null)))).then(r=>{if(!r)return;let n=r.sessions||[],s=r.engines||{},o=r.ollamaModels||{},a=r.deepseekModels||{},l=r.chatModes||{},i=r.planModes||{},c=y.current,d=new Set(t),u=c.filter(e=>!e.sessionId||!d.has(e.sessionId)),x=new Set(u.map(e=>e.sessionId).filter(Boolean)),m=n.filter(e=>!x.has(e));if(u.length===c.length&&0===m.length)return;let h=[...u,...m.map((t,r)=>({id:`tab-${Date.now()}-sync-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:s[t]||void 0,ollamaModel:o[t]||void 0,deepseekModel:a[t]||void 0,chatMode:l[t]||void 0,planMode:i[t]||void 0}))];0===h.length&&(h=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),b(h),h.some(e=>e.id===N.current)||j(h[h.length-1].id)})},[e]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:t=>{m.current||!e||"project-state-changed"===t.type&&t.cwd===e&&$(t.closedSessionIds??[])}});let T=(0,n.useCallback)((e,t,r,n,s,o,a=!1)=>{let l={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s,deepseekModel:o};b(e=>{if(a)return[...e,l];let t=e.findIndex(e=>e.id===v);if(-1===t)return[...e,l];let r=[...e];return r.splice(t+1,0,l),r}),j(l.id)},[v]),R=(0,n.useCallback)(t=>{let r=y.current.find(e=>e.id===t);r?.sessionId&&C.current.add(r.sessionId),b(r=>{let n=r.filter(e=>e.id!==t);if(t===v&&n.length>0&&j(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return j(t.id),[t]}return n})},[v,e]),B=(0,n.useCallback)((t,r)=>{let n=g.find(e=>e.sessionId===t);n?j(n.id):T(e,t,r,void 0,void 0,void 0,!0)},[g,e,T]),F=(0,n.useCallback)(()=>{T(e,void 0,void 0,void 0,void 0,void 0,!0)},[e,T]),I=(0,n.useCallback)(()=>{T(e,void 0,"New Claude 2 Chat","claude2",void 0,void 0,!0)},[e,T]),D=(0,n.useCallback)(()=>{T(e,void 0,"New Codex Chat","codex",void 0,void 0,!0)},[e,T]),A=(0,n.useCallback)(()=>{T(e,void 0,"New Kimi Chat","kimi",void 0,void 0,!0)},[e,T]),W=(0,n.useCallback)(t=>{T(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t,void 0,!0)},[e,T]),z=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),_=(0,n.useCallback)(()=>{T(e,void 0,"New DeepSeek Chat","deepseek",void 0,"deepseek-v4-flash",!0)},[e,T]),H=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),O=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,chatMode:t}:r))},[]),q=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),V=(0,n.useCallback)((t,r)=>{T(e,t,r)},[e,T]),K=(0,n.useCallback)((e,t)=>{b(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!h.current||"agent"===h.current;if(e===v&&r&&p.current){let e=n.sessionId||t.sessionId;e&&S(e,"normal")}else k(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[v,S]);(0,n.useEffect)(()=>{(!r||"agent"===r)&&f&&k(e=>{if(!e.has(v))return e;let t=new Set(e);t.delete(v);let r=y.current.find(e=>e.id===v);return r?.sessionId&&(S(r.sessionId,"normal"),c.t4.runFork((0,d.M2)(r.sessionId).pipe(i.catchAll(()=>i.void)))),t})},[r,v,f,S]);let U=(0,n.useCallback)(e=>{j(e),k(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=y.current.find(t=>t.id===e);return n?.sessionId&&(S(n.sessionId,"normal"),c.t4.runFork((0,d.M2)(n.sessionId).pipe(i.catchAll(()=>i.void)))),r})},[S]),J=(0,n.useCallback)(e=>{M(e)},[]),Q=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==L&&L!==t&&P(t)},[L]),Z=(0,n.useCallback)(e=>{null!==L&&L!==e&&b(t=>{let r=[...t],[n]=r.splice(L,1);return r.splice(e,0,n),r}),M(null),P(null)},[L]),Y=(0,n.useCallback)(()=>{M(null),P(null)},[]),G=g.find(e=>e.id===v);return{tabs:g,activeTabId:v,activeTab:G,unreadTabs:w,dragTabIndex:L,dragOverTabIndex:E,addTab:T,closeTab:R,switchTab:U,handleSelectSession:B,handleNewTab:F,handleNewClaude2Tab:I,handleNewCodexTab:D,handleNewKimiTab:A,handleNewOllamaTab:W,handleNewDeepseekTab:_,handleOpenSession:V,updateTabState:K,updateTabOllamaModel:z,updateTabDeepseekModel:H,updateTabChatMode:O,updateTabPlanMode:q,handleTabDragStart:J,handleTabDragOver:Q,handleTabDrop:Z,handleTabDragEnd:Y}}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(12786);let i={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:d}){let{t:u}=(0,o.Bd)(),x=!!r,[m,h]=(0,s.useState)(r?.type||"once"),[f,p]=(0,s.useState)(r?.message||""),[g,b]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[v,j]=(0,s.useState)(r?.cron||""),[w,k]=(0,s.useState)(r?.activeFrom||"09:00"),[y,N]=(0,s.useState)(r?.activeTo||"18:00"),[C,S]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[L,M]=(0,s.useState)(null),E=(0,s.useRef)(null),P=(0,s.useRef)(null);(0,s.useEffect)(()=>{P.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{E.current&&!E.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let $=(0,s.useCallback)(()=>{if(!f.trim())return;let n=null;if("once"===m){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"once",delayMinutes:e}}else if("interval"===m){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"interval",intervalMinutes:e,...C?{activeFrom:w,activeTo:y}:{}}}else if("cron"===m){let e=L||v.trim();if(!e)return;n={message:f.trim(),type:"cron",cron:e}}n&&(x&&r&&d?d(r.id,n):t(n),e())},[f,m,L,g,v,C,w,y,t,e,x,r,d]);return(0,n.jsxs)("div",{ref:E,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lg z-50 ${x?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&$()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:x?u("scheduledTasks.editTask"):u("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.sendMessage")}),(0,n.jsx)("textarea",{ref:P,value:f,onChange:e=>p(e.target.value),placeholder:u("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{h(e),M(null),b(""),j("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${m===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?u("scheduledTasks.once"):"interval"===e?u("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:i[m].map(e=>(0,n.jsx)("button",{onClick:()=>{M(e.value),"cron"===m?j(String(e.value)):b(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${L===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:u(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===m?u("scheduledTasks.customCron"):u("scheduledTasks.customMinutes")}),"cron"===m?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:v,onChange:e=>{j(e.target.value),M(null)},placeholder:u("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),v.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=a.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,l,i]=r,c={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},d={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),a=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(a)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:a}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`;let u=[];if("*"!==l){let e=l.split(",").map(e=>d[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:c[r]||r,b:c[n]||n})}return`${t("cron.weekdayPrefix")}${c[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===l&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(v.trim())||(0,n.jsx)("span",{className:"text-destructive",children:u("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:g,onChange:e=>{b(e.target.value),M(null)},placeholder:u("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===m&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:C,onChange:e=>S(e.target.checked),className:"rounded border-border"}),u("scheduledTasks.limitTimeRange")]}),C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:w,onChange:e=>k(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:y,onChange:e=>N(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:$,disabled:!(f.trim()&&("once"===m||"interval"===m?!!(L||g&&parseInt(g,10)>0):"cron"===m&&!!(L||v.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:x?u("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):u("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.tryPromise({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})}}]);