@surething/cockpit 1.0.186 → 1.0.187

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 (180) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +23 -23
  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_client-reference-manifest.js +1 -1
  6. package/.next-prod/server/app/_global-error.html +2 -2
  7. package/.next-prod/server/app/_global-error.rsc +1 -1
  8. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
  13. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  15. package/.next-prod/server/app/_not-found.html +2 -2
  16. package/.next-prod/server/app/_not-found.rsc +2 -2
  17. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
  18. package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
  19. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
  20. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  21. package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  22. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  23. package/.next-prod/server/app/api/bash/route_client-reference-manifest.js +1 -1
  24. package/.next-prod/server/app/api/chat/codex/route_client-reference-manifest.js +1 -1
  25. package/.next-prod/server/app/api/chat/kimi/route_client-reference-manifest.js +1 -1
  26. package/.next-prod/server/app/api/chat/ollama/route_client-reference-manifest.js +1 -1
  27. package/.next-prod/server/app/api/chat/route.js +3 -3
  28. package/.next-prod/server/app/api/chat/route_client-reference-manifest.js +1 -1
  29. package/.next-prod/server/app/api/claude-stats/route.js +1 -1
  30. package/.next-prod/server/app/api/claude-stats/route_client-reference-manifest.js +1 -1
  31. package/.next-prod/server/app/api/commands/route.js +1 -1
  32. package/.next-prod/server/app/api/commands/route_client-reference-manifest.js +1 -1
  33. package/.next-prod/server/app/api/comments/route.js +1 -1
  34. package/.next-prod/server/app/api/comments/route_client-reference-manifest.js +1 -1
  35. package/.next-prod/server/app/api/db/columns/route_client-reference-manifest.js +1 -1
  36. package/.next-prod/server/app/api/db/connect/route_client-reference-manifest.js +1 -1
  37. package/.next-prod/server/app/api/db/disconnect/route_client-reference-manifest.js +1 -1
  38. package/.next-prod/server/app/api/db/export/route_client-reference-manifest.js +1 -1
  39. package/.next-prod/server/app/api/db/query/route_client-reference-manifest.js +1 -1
  40. package/.next-prod/server/app/api/db/schemas/route_client-reference-manifest.js +1 -1
  41. package/.next-prod/server/app/api/extension/version/route_client-reference-manifest.js +1 -1
  42. package/.next-prod/server/app/api/file/route_client-reference-manifest.js +1 -1
  43. package/.next-prod/server/app/api/files/blame/route_client-reference-manifest.js +1 -1
  44. package/.next-prod/server/app/api/files/clipboard/route_client-reference-manifest.js +1 -1
  45. package/.next-prod/server/app/api/files/copy/route_client-reference-manifest.js +1 -1
  46. package/.next-prod/server/app/api/files/delete/route_client-reference-manifest.js +1 -1
  47. package/.next-prod/server/app/api/files/expanded/route.js +1 -1
  48. package/.next-prod/server/app/api/files/expanded/route_client-reference-manifest.js +1 -1
  49. package/.next-prod/server/app/api/files/index/route_client-reference-manifest.js +1 -1
  50. package/.next-prod/server/app/api/files/init/route.js +1 -1
  51. package/.next-prod/server/app/api/files/init/route_client-reference-manifest.js +1 -1
  52. package/.next-prod/server/app/api/files/paste/route_client-reference-manifest.js +1 -1
  53. package/.next-prod/server/app/api/files/read/route_client-reference-manifest.js +1 -1
  54. package/.next-prod/server/app/api/files/readdir/route_client-reference-manifest.js +1 -1
  55. package/.next-prod/server/app/api/files/recent/route.js +1 -1
  56. package/.next-prod/server/app/api/files/recent/route_client-reference-manifest.js +1 -1
  57. package/.next-prod/server/app/api/files/save/route_client-reference-manifest.js +1 -1
  58. package/.next-prod/server/app/api/files/search/route_client-reference-manifest.js +1 -1
  59. package/.next-prod/server/app/api/git/branch-diff/route_client-reference-manifest.js +1 -1
  60. package/.next-prod/server/app/api/git/branches/route_client-reference-manifest.js +1 -1
  61. package/.next-prod/server/app/api/git/commit-diff/route_client-reference-manifest.js +1 -1
  62. package/.next-prod/server/app/api/git/commits/route_client-reference-manifest.js +1 -1
  63. package/.next-prod/server/app/api/git/diff/route_client-reference-manifest.js +1 -1
  64. package/.next-prod/server/app/api/git/discard/route_client-reference-manifest.js +1 -1
  65. package/.next-prod/server/app/api/git/stage/route_client-reference-manifest.js +1 -1
  66. package/.next-prod/server/app/api/git/status/route_client-reference-manifest.js +1 -1
  67. package/.next-prod/server/app/api/git/unstage/route_client-reference-manifest.js +1 -1
  68. package/.next-prod/server/app/api/git/worktree/route_client-reference-manifest.js +1 -1
  69. package/.next-prod/server/app/api/global-state/route_client-reference-manifest.js +1 -1
  70. package/.next-prod/server/app/api/jupyter/load/route_client-reference-manifest.js +1 -1
  71. package/.next-prod/server/app/api/jupyter/save/route_client-reference-manifest.js +1 -1
  72. package/.next-prod/server/app/api/jupyter/shutdown/route_client-reference-manifest.js +1 -1
  73. package/.next-prod/server/app/api/lsp/definition/route_client-reference-manifest.js +1 -1
  74. package/.next-prod/server/app/api/lsp/hover/route_client-reference-manifest.js +1 -1
  75. package/.next-prod/server/app/api/lsp/references/route_client-reference-manifest.js +1 -1
  76. package/.next-prod/server/app/api/lsp/status/route_client-reference-manifest.js +1 -1
  77. package/.next-prod/server/app/api/lsp/warmup/route_client-reference-manifest.js +1 -1
  78. package/.next-prod/server/app/api/mysql/columns/route_client-reference-manifest.js +1 -1
  79. package/.next-prod/server/app/api/mysql/connect/route_client-reference-manifest.js +1 -1
  80. package/.next-prod/server/app/api/mysql/disconnect/route_client-reference-manifest.js +1 -1
  81. package/.next-prod/server/app/api/mysql/export/route_client-reference-manifest.js +1 -1
  82. package/.next-prod/server/app/api/mysql/query/route_client-reference-manifest.js +1 -1
  83. package/.next-prod/server/app/api/mysql/schemas/route_client-reference-manifest.js +1 -1
  84. package/.next-prod/server/app/api/neo4j/connect/route_client-reference-manifest.js +1 -1
  85. package/.next-prod/server/app/api/neo4j/disconnect/route_client-reference-manifest.js +1 -1
  86. package/.next-prod/server/app/api/neo4j/query/route_client-reference-manifest.js +1 -1
  87. package/.next-prod/server/app/api/neo4j/schema/route_client-reference-manifest.js +1 -1
  88. package/.next-prod/server/app/api/note/route.js +1 -1
  89. package/.next-prod/server/app/api/note/route_client-reference-manifest.js +1 -1
  90. package/.next-prod/server/app/api/ollama/models/route_client-reference-manifest.js +1 -1
  91. package/.next-prod/server/app/api/ollama/start/route_client-reference-manifest.js +1 -1
  92. package/.next-prod/server/app/api/open-cursor/route_client-reference-manifest.js +1 -1
  93. package/.next-prod/server/app/api/open-vscode/route_client-reference-manifest.js +1 -1
  94. package/.next-prod/server/app/api/pick-folder/route_client-reference-manifest.js +1 -1
  95. package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
  96. package/.next-prod/server/app/api/pinned-sessions/route_client-reference-manifest.js +1 -1
  97. package/.next-prod/server/app/api/project-settings/route.js +1 -1
  98. package/.next-prod/server/app/api/project-settings/route_client-reference-manifest.js +1 -1
  99. package/.next-prod/server/app/api/project-state/route.js +1 -1
  100. package/.next-prod/server/app/api/project-state/route_client-reference-manifest.js +1 -1
  101. package/.next-prod/server/app/api/projects/route.js +1 -1
  102. package/.next-prod/server/app/api/projects/route_client-reference-manifest.js +1 -1
  103. package/.next-prod/server/app/api/redis/command/route_client-reference-manifest.js +1 -1
  104. package/.next-prod/server/app/api/redis/connect/route_client-reference-manifest.js +1 -1
  105. package/.next-prod/server/app/api/redis/delete/route_client-reference-manifest.js +1 -1
  106. package/.next-prod/server/app/api/redis/disconnect/route_client-reference-manifest.js +1 -1
  107. package/.next-prod/server/app/api/redis/get/route_client-reference-manifest.js +1 -1
  108. package/.next-prod/server/app/api/redis/keys/route_client-reference-manifest.js +1 -1
  109. package/.next-prod/server/app/api/redis/set/route_client-reference-manifest.js +1 -1
  110. package/.next-prod/server/app/api/review/[id]/comments/route_client-reference-manifest.js +1 -1
  111. package/.next-prod/server/app/api/review/[id]/replies/route_client-reference-manifest.js +1 -1
  112. package/.next-prod/server/app/api/review/[id]/route.js +1 -1
  113. package/.next-prod/server/app/api/review/[id]/route_client-reference-manifest.js +1 -1
  114. package/.next-prod/server/app/api/review/identify/route.js +1 -1
  115. package/.next-prod/server/app/api/review/identify/route_client-reference-manifest.js +1 -1
  116. package/.next-prod/server/app/api/review/order/route.js +1 -1
  117. package/.next-prod/server/app/api/review/order/route_client-reference-manifest.js +1 -1
  118. package/.next-prod/server/app/api/review/route_client-reference-manifest.js +1 -1
  119. package/.next-prod/server/app/api/review/share-info/route_client-reference-manifest.js +1 -1
  120. package/.next-prod/server/app/api/review/users/route.js +1 -1
  121. package/.next-prod/server/app/api/review/users/route_client-reference-manifest.js +1 -1
  122. package/.next-prod/server/app/api/scheduled-tasks/route.js +1 -1
  123. package/.next-prod/server/app/api/scheduled-tasks/route_client-reference-manifest.js +1 -1
  124. package/.next-prod/server/app/api/services/config/route.js +1 -1
  125. package/.next-prod/server/app/api/services/config/route_client-reference-manifest.js +1 -1
  126. package/.next-prod/server/app/api/services/scripts/route_client-reference-manifest.js +1 -1
  127. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
  128. package/.next-prod/server/app/api/session/[sessionId]/fork/route_client-reference-manifest.js +1 -1
  129. package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
  130. package/.next-prod/server/app/api/session/[sessionId]/history/route_client-reference-manifest.js +1 -1
  131. package/.next-prod/server/app/api/session-by-path/route.js +1 -1
  132. package/.next-prod/server/app/api/session-by-path/route_client-reference-manifest.js +1 -1
  133. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
  134. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route_client-reference-manifest.js +1 -1
  135. package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
  136. package/.next-prod/server/app/api/sessions/projects/route_client-reference-manifest.js +1 -1
  137. package/.next-prod/server/app/api/sessions/route.js +1 -1
  138. package/.next-prod/server/app/api/sessions/route_client-reference-manifest.js +1 -1
  139. package/.next-prod/server/app/api/settings/route.js +1 -1
  140. package/.next-prod/server/app/api/settings/route_client-reference-manifest.js +1 -1
  141. package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
  142. package/.next-prod/server/app/api/terminal/aliases/route_client-reference-manifest.js +1 -1
  143. package/.next-prod/server/app/api/terminal/autocomplete/route_client-reference-manifest.js +1 -1
  144. package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
  145. package/.next-prod/server/app/api/terminal/bubble-order/route_client-reference-manifest.js +1 -1
  146. package/.next-prod/server/app/api/terminal/env/route.js +1 -1
  147. package/.next-prod/server/app/api/terminal/env/route_client-reference-manifest.js +1 -1
  148. package/.next-prod/server/app/api/terminal/history/route.js +1 -1
  149. package/.next-prod/server/app/api/terminal/history/route_client-reference-manifest.js +1 -1
  150. package/.next-prod/server/app/api/version/route_client-reference-manifest.js +1 -1
  151. package/.next-prod/server/app/manifest.webmanifest/route_client-reference-manifest.js +1 -1
  152. package/.next-prod/server/app/page.js +1 -1
  153. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  154. package/.next-prod/server/app/project/page.js +4 -4
  155. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  156. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  157. package/.next-prod/server/app-paths-manifest.json +23 -23
  158. package/.next-prod/server/chunks/4098.js +1 -1
  159. package/.next-prod/server/chunks/5394.js +1 -1
  160. package/.next-prod/server/chunks/6062.js +1 -1
  161. package/.next-prod/server/chunks/7284.js +1 -1
  162. package/.next-prod/server/pages/404.html +2 -2
  163. package/.next-prod/server/pages/500.html +2 -2
  164. package/.next-prod/server/server-reference-manifest.json +1 -1
  165. package/.next-prod/static/chunks/{1593-7902218f5b10761f.js → 1593-d845ec6e5c8de67e.js} +1 -1
  166. package/.next-prod/static/chunks/{5493-482fc2bbb049e7a4.js → 5493-83d6a5ec42d6cbb3.js} +1 -1
  167. package/.next-prod/static/chunks/app/page-cc2b332242bc2c93.js +1 -0
  168. package/.next-prod/static/chunks/app/project/page-95039285184e0c74.js +25 -0
  169. package/.next-prod/static/css/bbd65867698c479b.css +3 -0
  170. package/.next-prod/trace +12 -12
  171. package/.next-prod/trace-build +1 -1
  172. package/dist/{chunk-VV5VMA4B.mjs → chunk-KLV3PBIZ.mjs} +17 -0
  173. package/dist/scheduledTasks.mjs +7 -2
  174. package/dist/wsServer.mjs +1 -1
  175. package/package.json +2 -2
  176. package/.next-prod/static/chunks/app/page-cc2bf3ca4c337090.js +0 -1
  177. package/.next-prod/static/chunks/app/project/page-62d5a8ed458279b8.js +0 -25
  178. package/.next-prod/static/css/1573b510894a4234.css +0 -3
  179. /package/.next-prod/static/{0mBqfZkcLM2Y1ikI9uxKG → Avd2f2SegjGOElSYvrTlK}/_buildManifest.js +0 -0
  180. /package/.next-prod/static/{0mBqfZkcLM2Y1ikI9uxKG → Avd2f2SegjGOElSYvrTlK}/_ssgManifest.js +0 -0
@@ -0,0 +1,25 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6500],{60499:(e,t,r)=>{Promise.resolve().then(r.bind(r,97484))},97484:(e,t,r)=>{"use strict";r.d(t,{TabManager:()=>nI});var n=r(95155),s=r(12115),o=r(79114);function l({isOpen:e,onClose:t,cwd:r,onSelectSession:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useCallback)(async()=>{if(r){u(!0),h(null);try{let e=r.replace(/\//g,"-"),t=await fetch(`/api/sessions/projects/${encodeURIComponent(e)}`);if(!t.ok)throw Error("Failed to load sessions");let n=await t.json();c(n)}catch(e){h(e instanceof Error?e.message:"Unknown error")}finally{u(!1)}}},[r]);(0,s.useEffect)(()=>{e&&(g(),setTimeout(()=>{p.current?.focus()},100))},[e,g]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let b=i.filter(e=>{if(!x)return!0;let t=x.toLowerCase();return 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-6xl 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:a("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:p,type:"text",placeholder:a("sessions.searchSessions"),value:x,onChange:e=>f(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:[d&&(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")})]})}),m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:m})}),!d&&!m&&0===b.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:a(x?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!d&&!m&&b.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:b.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(l?(l(n,e.title),t()):window.parent.postMessage({type:"OPEN_PROJECT",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 a=r(47650),i=r(64702),c=r(87918);let d=new Set;function u(){d.forEach(e=>e())}async function m(e){let t=await fetch(`/api/comments?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error("Failed to fetch comments");let r=(await t.json()).comments||[];if(0===r.length)return[];let n=new Map;for(let e of r)e.selectedText||(n.has(e.filePath)||n.set(e.filePath,[]),n.get(e.filePath).push(e));let s=new Map;await Promise.all(Array.from(n.keys()).map(async t=>{try{let r=await fetch(`/api/files/read?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);if(r.ok){let e=await r.json();"text"===e.type&&e.content&&s.set(t,e.content.split("\n"))}}catch(e){console.error(`Failed to read file ${t}:`,e)}}));let o=[];for(let e of r){if(e.selectedText){o.push({...e,codeContent:e.selectedText});continue}let t=s.get(e.filePath),r="";if(t){let n=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);r=t.slice(n,s).join("\n")}o.push({...e,codeContent:r})}return o}async function h(e){try{if((await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`,{method:"DELETE"})).ok)return u(),!0;return!1}catch(e){return console.error("Failed to clear comments:",e),!1}}let x="__chat__";function f(e,t){let r=e.filter(e=>e.filePath===x),n=e.filter(e=>e.filePath!==x),s=[];for(let e of(n.length>0&&(s.push(`${c.A.t("comments.codeRef")}`,""),n.forEach((e,t)=>{s.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),s.push("```"),s.push(e.codeContent),s.push("```"),e.note&&s.push(c.A.t("comments.note",{content:e.note})),s.push("")})),r)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");s.push(t),e.note&&s.push(e.note),s.push("")}return s.push(c.A.t("comments.question",{question:t})),s.join("\n")}function p({cwd:e,filePath:t}){let[r,n]=(0,s.useState)([]),[o,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)(null),c=(0,s.useCallback)(async()=>{if(e&&t){l(!0),i(null);try{let r=await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&filePath=${encodeURIComponent(t)}`);if(r.ok){let e=await r.json();n(e.comments||[])}else i("Failed to load comments")}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1)}}},[e,t]);(0,s.useEffect)(()=>{c()},[c]),(0,s.useEffect)(()=>{var e;return e=()=>{c()},d.add(e),()=>d.delete(e)},[c]);let u=(0,s.useCallback)(async(r,s,o,l)=>{try{let a=await fetch("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,startLine:r,endLine:s,content:o,...l?{selectedText:l}:{}})});if(a.ok){let e=await a.json();return n(t=>[...t,e.comment]),e.comment}}catch(e){console.error("Failed to add comment:",e)}return null},[e,t]),m=(0,s.useCallback)(async(t,r)=>{try{let s=await fetch("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:r})});if(s.ok){let e=await s.json();return n(r=>r.map(r=>r.id===t?e.comment:r)),!0}}catch(e){console.error("Failed to update comment:",e)}return!1},[e]),h=(0,s.useCallback)(async t=>{try{if((await fetch(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"})).ok)return n(e=>e.filter(e=>e.id!==t)),!0}catch(e){console.error("Failed to delete comment:",e)}return!1},[e]),x=(0,s.useCallback)(e=>r.filter(t=>e>=t.startLine&&e<=t.endLine),[r]);return{comments:r,isLoading:o,error:a,addComment:u,updateComment:m,deleteComment:h,refresh:c,getCommentsForLine:x}}var g=r(38093);let b=(0,s.createContext)(null);function v({container:e,children:t}){return(0,n.jsx)(b.Provider,{value:e,children:t})}function j(){return(0,s.useContext)(b)}function y({x:e,y:t,path:r,cwd:l,isDirectory:i,onClose:c,onCreateFile:d,onDelete:u,onRefresh:m,onCopyFile:h,onPaste:x}){let{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null),v=(0,s.useContext)(b),j=r.split("/").pop()||r,y=`${l}/${r}`,w=r.includes("/")?r.substring(0,r.lastIndexOf("/")):"",k=w?`${l}/${w}`:l,N=i?r:w,C=i?y:k;(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&c()},t=e=>{"Escape"===e.key&&c()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[c]);let[S,L]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&v){let r=v.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s=Math.min(s,r.width-n.width-8),o=Math.min(o,r.height-n.height-8),L({x:s=Math.max(8,s),y:o=Math.max(8,o)})}else if(p.current){let r=p.current.getBoundingClientRect();L({x:Math.max(8,Math.min(e,window.innerWidth-r.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-r.height-8))})}},[e,t,v]);let E=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,g.oR)(f("toast.copiedName",{name:t}),"success")}catch{(0,g.oR)(f("toast.copyFailed"),"error")}c()},[c,f]),M=i?r:w,T=[{label:f("fileContextMenu.copyRelativePath"),value:r},{label:f("fileContextMenu.copyAbsolutePath"),value:y},{label:f("fileContextMenu.copyRelativeDirPath"),value:N||"."},{label:f("fileContextMenu.copyAbsoluteDirPath"),value:C},{label:i?f("fileContextMenu.copyFolderName"):f("fileContextMenu.copyFileName"),value:j}],R=(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:S.x,top:S.y},children:[d&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{c(),d(M)},children:f("fileContextMenu.createFile")}),h&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{c(),h(r)},children:i?f("fileContextMenu.copyFolder"):f("fileContextMenu.copyFile")}),x&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{c(),x(M)},children:f("fileContextMenu.pasteHere")}),u&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{c(),u(r,i,j)},children:i?f("fileContextMenu.deleteFolder"):f("fileContextMenu.deleteFile")}),(d||u||h||x)&&(0,n.jsx)("div",{className:"my-1 border-t border-border"}),T.map((e,t)=>(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>E(e.value,e.label),children:e.label},t))]});return v?(0,a.createPortal)(R,v):R}function w(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,r,n)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:r,isDirectory:n})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}let k=(0,s.createContext)(null);function N({children:e}){let t=(0,s.useRef)(new Map),r=(0,s.useRef)(null),[o,l]=(0,s.useState)(!1),a=(0,s.useCallback)((e,r)=>{t.current.set(r,e)},[]),i=(0,s.useCallback)(e=>{t.current.delete(e)},[]),c=(0,s.useCallback)(e=>{r.current=e},[]),d=(0,s.useCallback)(e=>{let n=r.current;if(!n)return void console.warn("No active tab to send message");let s=t.current.get(n);s?s(e):console.warn(`No chat sender registered for tab ${n}`)},[]),u=(0,s.useMemo)(()=>({sendMessage:d,isLoading:o,registerChat:a,unregisterChat:i,setActiveTab:c,setIsLoading:l}),[d,o,a,i,c]);return(0,n.jsx)(k.Provider,{value:u,children:e})}function C(){return(0,s.useContext)(k)}function S({x:e,y:t,range:r,codeContent:l,container:a,onSubmit:i,onClose:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(""),[h,x]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0}),v=l?.split("\n").slice(0,5).join("\n"),j=!!l&&l.split("\n").length>5;return(0,s.useEffect)(()=>{if(f.current&&a){let r=a.getBoundingClientRect(),n=f.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>b({x:s,y:o}))}},[e,t,a]),(0,s.useEffect)(()=>{p.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{h||!f.current||f.current.contains(e.target)||c()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c,h]),(0,n.jsxs)("div",{ref:f,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:[(0,n.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-amber-11",children:d("comments.addComment")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:d("comments.lineRange",{start:r.start,end:r.end})})]})}),l&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[v,j&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:p,value:u,onChange:e=>m(e.target.value),placeholder:d("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:h,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!h&&u.trim()&&(x(!0),i(u.trim()))),"Escape"!==e.key||h||c()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:d(h?"comments.submitting":"comments.enterSubmit")})]})]})}function L({x:e,y:t,range:r,filePath:l,codeContent:a,container:i,onSubmit:c,onClose:d,isChatLoading:u}){let{t:m}=(0,o.Bd)(),[h,x]=(0,s.useState)(""),f=(0,s.useRef)(null),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(f.current&&i){let r=i.getBoundingClientRect(),n=f.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>b({x:s,y:o}))}},[e,t,i]),(0,s.useEffect)(()=>{p.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let v=a?.split("\n").slice(0,5).join("\n"),j=!!a&&a.split("\n").length>5;return(0,n.jsxs)("div",{ref:f,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-brand",children:m("comments.askAI")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:m("comments.lineRange",{start:r.start,end:r.end})})]}),l&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:l})]}),a&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[v,j&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:p,value:h,onChange:e=>x(e.target.value),placeholder:m("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:u,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!u&&h.trim()&&(c(h.trim()),d())),"Escape"===e.key&&d()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:m(u?"comments.aiGenerating":"comments.enterSend")})]})]})}function E(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,l=n.length,a=Array(o+1).fill(null).map(()=>Array(l+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=l;t++)r[e-1]===n[t-1]?a[e][t]=a[e-1][t-1]+1:a[e][t]=Math.max(a[e-1][t],a[e][t-1]);let i=o,c=l,d=[];for(;i>0||c>0;)i>0&&c>0&&r[i-1]===n[c-1]?(d.push({type:"unchanged",content:r[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||a[i][c-1]>=a[i-1][c])?(d.push({type:"added",content:n[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:r[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}var M=r(67014);let T=null,R=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function $(){return T||(T=(0,M.O_)({themes:["github-dark","github-light"],langs:[...R]})),T}function P(e){let t=e.split("/").pop()?.toLowerCase()||"",r=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[r||""]||"text";return R.includes(n)?n:"text"}function I(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function B(e){return e.map(e=>e.color?`<span style="color:${e.color}">${I(e.content)}</span>`:I(e.content)).join("")}function D(e,t){let[r,n]=(0,s.useState)([]),[o,l]=(0,s.useState)(!1),a=(0,s.useRef)("");(0,s.useEffect)(()=>{let e=()=>{l(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let i=e.join("\n");return(0,s.useEffect)(()=>{if(0===e.length)return;let r=`${i}:${t}:${o}`;if(r===a.current)return;a.current=r,n(e.map(e=>I(e||" ")));let s=!1;return(async()=>{try{let r=await $();if(s)return;let l=P(t),a=e.join("\n"),i=r.codeToTokens(a,{lang:l,theme:o?"github-dark":"github-light"}),c=[];for(let e=0;e<i.tokens.length;e++)if(c[e]=B(i.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),s))return;n(c)}catch(e){console.error("Line highlight error:",e)}})(),()=>{s=!0}},[i,t,o]),r}function F({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,l]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:s}=e,o=r.current?.clientHeight||0;if(n<=s)l({top:0,height:o});else{let e=o/n;l({top:t*e,height:s*e})}};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}},[t]),0===e.length)return null;let a=100/e.length;return(0,n.jsxs)("div",{ref:r,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let n=t.current,s=r.current;if(!n||!s)return;let o=s.getBoundingClientRect(),l=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,l),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,n.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*a}%`,height:`${Math.max(a,.5)}%`,minHeight:"2px"}},t)),(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${o.top}px`,height:`${Math.max(o.height,10)}px`}})]})}function O({x:e,y:t,visible:r,container:s,onAddComment:l,onSendToAI:a,onSearch:i,isChatLoading:c}){let{t:d}=(0,o.Bd)(),u=s.getBoundingClientRect(),m=e-u.left,h=Math.max(0,t-u.top-40);return(0,n.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:m+8,top:h,visibility:r?"visible":"hidden",pointerEvents:r?"auto":"none"},children:[(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:l,children:d("floatingToolbar.addComment")}),(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:a,disabled:c,title:d(c?"comments.aiResponding":"floatingToolbar.sendToAI"),children:d("floatingToolbar.sendToAI")}),i&&(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:i,children:d("floatingToolbar.search")})]})}let A=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i}){let[c,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let u=(0,s.useMemo)(()=>e.current,[c]);return(0,n.jsx)(O,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i})});function W({x:e,y:t,comment:r,container:l,onClose:a,onUpdateComment:i,onDeleteComment:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(r.content),f=(0,s.useRef)(null),[p,g]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(f.current&&l){let r=l.getBoundingClientRect(),n=f.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>g({x:s,y:o}))}},[e,t,l]),(0,s.useEffect)(()=>{let e=e=>{f.current&&!f.current.contains(e.target)&&a()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]);let b=async()=>{h.trim()&&(await i(r.id,h.trim()),m(!1))},v=async()=>{await c(r.id),a()};return(0,n.jsx)("div",{ref:f,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:p.x,top:p.y},children:(0,n.jsx)("div",{className:"p-3",children:u?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("textarea",{value:h,onChange:e=>x(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),b()),"Escape"===e.key&&(m(!1),x(r.content))}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>{m(!1),x(r.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:d("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:d("common.save")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.content}),(0,n.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:d("comments.lineRange",{start:r.startLine,end:r.endLine})}),(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:()=>m(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:d("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"})})}),(0,n.jsx)("button",{onClick:v,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:d("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:"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"})})})]})]})]})})})}let z=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i}){let[c,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let u=(0,s.useMemo)(()=>e.current,[c]);return(0,n.jsx)(O,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:l,onSearch:a,isChatLoading:i})});function H({oldContent:e,newContent:t,filePath:r,isNew:l=!1,isDeleted:c=!1,cwd:d,enableComments:u=!1,onPreview:x,previewLabel:b,onContentSearch:v}){let{t:y}=(0,o.Bd)(),w=b??y("common.preview"),k=(0,s.useMemo)(()=>E(e,t),[e,t]),N=(0,s.useRef)(null),M=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useRef)(!1),[$,P]=(0,s.useState)(!1),B=j(),O=C(),A=u&&!!d,{comments:H,addComment:_,updateComment:U,deleteComment:q,refresh:V}=p({cwd:d||"",filePath:r}),[K,J]=(0,s.useState)(null),X=(0,s.useRef)(null),Y=(0,s.useRef)(()=>{}),[Q,G]=(0,s.useState)(null),[Z,ee]=(0,s.useState)(null);(0,s.useEffect)(()=>{P(!0)},[]);let et=(0,s.useMemo)(()=>{let e=new Set;for(let t of H)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[H]),er=(0,s.useMemo)(()=>{let e=new Map;for(let t of H){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[H]);(0,s.useEffect)(()=>{if(!A)return;let e=T.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,X.current&&(X.current=null,Y.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed||!l.toString().trim()||!o){X.current&&(X.current=null,Y.current());return}let a=l.getRangeAt(0),i=T.current;if(!i||!i.contains(a.commonAncestorContainer))return;let c=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;for(;t&&t!==i;){let e=t.closest("[data-new-line]");if(e)return parseInt(e.getAttribute("data-new-line")||"0",10);t=t.parentElement}return null},d=c(a.startContainer),u=c(a.endContainer);if(d&&u){let t=Math.min(d,u),r=Math.max(d,u),n=[],s=0;for(let e of k)("unchanged"===e.type||"added"===e.type)&&++s>=t&&s<=r&&n.push(e.content);let o=n.join("\n");X.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},codeContent:o},Y.current()}},l=()=>{if(t||!X.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(X.current=null,Y.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[A,k]);let en=(0,s.useCallback)((e,t)=>{t.stopPropagation(),J({comment:e,x:t.clientX,y:t.clientY}),X.current=null,Y.current(),G(null),ee(null)},[]),es=(0,s.useCallback)(()=>{let e=X.current;e&&(G({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),X.current=null,Y.current())},[]),eo=(0,s.useCallback)(()=>{let e=X.current;e&&(ee({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),X.current=null,Y.current())},[]),el=(0,s.useCallback)(()=>{let e=X.current;if(!e||!v)return;let t=e.codeContent.trim();X.current=null,Y.current(),t&&v(t)},[v]),ea=(0,s.useCallback)(async e=>{if(Z&&O&&d)try{let t=await m(d),n=[];for(let e of t)n.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});n.push({filePath:r,startLine:Z.range.start,endLine:Z.range.end,codeContent:Z.codeContent});let s=f(n,e);O.sendMessage(s),await h(d),V(),ee(null)}catch(e){console.error("Failed to send to AI:",e)}},[Z,O,r,d,V]),ei=(0,s.useCallback)(async e=>{Q&&(await _(Q.range.start,Q.range.end,e),G(null))},[Q,_]);(0,s.useEffect)(()=>{let e=M.current,t=T.current;if(!e||!t)return;let r=(e,t)=>{R.current||(R.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{R.current=!1}))},n=()=>r(e,t),s=()=>r(t,e);return e.addEventListener("scroll",n),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",n),t.removeEventListener("scroll",s)}},[]);let{leftLines:ec,rightLines:ed}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<k.length;s++){let o=k[s];if("unchanged"===o.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});r++,n++,e.push({lineNum:r,content:o.content,type:"unchanged",originalIdx:s}),t.push({lineNum:n,content:o.content,type:"unchanged",originalIdx:s})}else"removed"===o.type?(r++,e.push({lineNum:r,content:o.content,type:"removed",originalIdx:s})):"added"===o.type&&(n++,t.push({lineNum:n,content:o.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[k]),eu=D((0,s.useMemo)(()=>k.map(e=>e.content),[k]),r),em=(0,i.Te)({count:ec.length,getScrollElement:()=>N.current,estimateSize:()=>20,overscan:20}),eh=l?"w-1/4":c?"w-3/4":"w-1/2",ex=l?"w-3/4":c?"w-1/4":"w-1/2",ef=(0,s.useMemo)(()=>ec.map((e,t)=>{let r=ed[t];return"removed"===e.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ec,ed]),ep=em.getTotalSize(),eg=em.getVirtualItems();return(0,n.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,n.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,n.jsx)("div",{className:`${eh} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:l?"(New File)":c?"Deleted":"Old"}),(0,n.jsxs)("div",{className:`${ex} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,n.jsx)("span",{className:"block text-center",children:c?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[x&&(0,n.jsx)("button",{onClick:x,className:"text-muted-foreground hover:text-foreground transition-colors",children:w}),!c&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,g.oR)(y("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:y("common.copy")})]})]}),(0,n.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:N,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,n.jsxs)("div",{className:"flex",style:{height:`${ep}px`},children:[(0,n.jsx)("div",{ref:M,className:`${eh} overflow-x-auto border-r border-border`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eg.map(e=>{let t=ec[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:t.lineNum||""}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:t.originalIdx>=0&&eu[t.originalIdx]||I(t.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:T,className:`${ex} overflow-x-auto`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eg.map(e=>{let t=ed[e.index],r=t?.lineNum||0,s=r>0&&et.has(r),o=er.get(r),l=o?.[0],a=Q&&r>=Q.range.start&&r<=Q.range.end,i=Z&&r>=Z.range.start&&r<=Z.range.end,c=a||i;return(0,n.jsxs)("div",{"data-new-line":r||void 0,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${c?"bg-blue-9/20":s?"bg-amber-9/10":t?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${c?"bg-blue-9/30":""}`,style:{width:A?"52px":"40px"},children:[A&&r>0&&s&&l&&(0,n.jsx)("button",{onClick:e=>en(l,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:y("codeViewer.nComments",{count:o?.length}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),A&&r>0&&!s&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"flex-1 text-right pr-1",children:r||""})]}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:t?.originalIdx>=0&&eu[t.originalIdx]||I(t?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(F,{lines:ef,containerRef:N})]}),$&&B&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(z,{floatingToolbarRef:X,bumpRef:Y,container:B,onAddComment:es,onSendToAI:eo,onSearch:v?el:void 0,isChatLoading:O?.isLoading??!1}),Q&&(0,n.jsx)(S,{x:Q.x,y:Q.y,range:Q.range,codeContent:Q.codeContent,container:B,onSubmit:ei,onClose:()=>G(null)}),Z&&(0,n.jsx)(L,{x:Z.x,y:Z.y,range:Z.range,container:B,onSubmit:ea,onClose:()=>ee(null)}),K&&(0,n.jsx)(W,{x:K.x,y:K.y,comment:K.comment,container:B,onClose:()=>J(null),onUpdateComment:U,onDeleteComment:q})]}),B)]})}function _({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>E(e,t),[e,t]),l=(0,s.useRef)(null),a=D((0,s.useMemo)(()=>o.map(e=>e.content),[o]),r),c=(0,i.Te)({count:o.length,getScrollElement:()=>l.current,estimateSize:()=>20,overscan:20});return(0,n.jsx)("div",{ref:l,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${c.getTotalSize()}px`,position:"relative"},children:c.getVirtualItems().map(e=>{let t=o[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,n.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,n.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:a[e.index]||I(t.content||" ")}})]},e.key)})})})}let U={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"},q={"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=q[s=e.toLowerCase()]?q[s]:U[e.split(".").pop()?.toLowerCase()||""]||U.default,l=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(l)?(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(l)?(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"===l||"tsx"===l&&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"===l?(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(l)?(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(l)?(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"===l?(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"===l?(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(l)?(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"===l?(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"===l?(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(l)?(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(l)?(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(l)?(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"===l||".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"===l||"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"===l||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"===l?(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"===l?(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 K({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 J=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let m=o===t.path,h=l.has(t.path),x=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):a(t)},[t,a,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:x,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:h?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),h&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:l,onSelect:a,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 ${m?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:x,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 ${m?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(K,{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 X({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,cwd:a,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:m}=(0,o.Bd)(),h=d??m("gitFileTree.noFiles"),{contextMenu:x,showContextMenu:f,hideContextMenu:p}=w();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:h}):(0,n.jsxs)("div",{className:u||"py-1 overflow-y-auto h-full min-w-max",children:[e.map(e=>(0,n.jsx)(J,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,onContextMenu:f,showChanges:i,renderActions:c},e.path)),x&&(0,n.jsx)(y,{x:x.x,y:x.y,path:x.path,cwd:a,isDirectory:x.isDirectory,onClose:p})]})}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,l=e.slice(0,t+1).join("/"),a=n.find(e=>e.name===s);a||(a={name:s,path:l,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(a)),o||(n=a.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 Q(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function G(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}function Z(e){try{let t=JSON.parse(e);return el(t,0)}catch{return e}}let ee="#79c0ff",et="#a5d6ff",er="#ff7b72",en="#8b949e",es=(e,t)=>s.createElement("span",{style:{color:e}},t);function eo({label:e,labelColor:t,value:r,indent:n}){let[o,l]=s.useState(!1),[a,i]=s.useState({x:0,y:0}),d="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,u={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-a.x,r=e.clientY-a.y;t*t+r*r>25||(e.stopPropagation(),l(e=>!e))},style:{cursor:"pointer"}};if(d&&o&&"string"==typeof r){let n=r.replace(/\\n/g,"\n").split("\n")[0],o=r.replace(/\\n/g,"\n").split("\n").length;return s.createElement("span",u,es(t,e),es(en,": "),es(et,n),es("#6e7681",` ${c.A.t("toolCall.foldedLines",{count:o})}`))}let m=s.createElement(s.Fragment,null,es(t,e),es(en,": "),el(r,n));return d?s.createElement("span",u,m):m}function el(e,t){let r=" ".repeat(t);if(null===e)return es(er,"null");if(void 0===e)return es(er,"undefined");if("string"==typeof e)return es(et,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return es("#79c0ff",String(e));if("boolean"==typeof e)return es(er,String(e));if(Array.isArray(e))return 0===e.length?es(en,"[]"):s.createElement(s.Fragment,null,es(en,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(eo,{label:`[${o}]`,labelColor:ee,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,es(en,","),"\n"):"\n")),r,es(en,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?es(en,"{}"):s.createElement(s.Fragment,null,es(en,"{"),"\n",...n.map(([e,o],l)=>s.createElement("span",{key:e},r+" ",s.createElement(eo,{label:e,labelColor:ee,value:o,indent:t+1}),l<n.length-1?s.createElement(s.Fragment,null,es(en,","),"\n"):"\n")),r,es(en,"}"))}return String(e)}let ea=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function ei(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return ea.has(t)}function ec(e){return e.toLowerCase().endsWith(".md")}let ed="json-search-highlight-style";function eu(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(0),m=(0,s.useRef)(null),h=(0,s.useRef)([]),x=(0,s.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),h.current=[];let r=e.current;if(!r||!n){c(0),u(0);return}!function(){if(document.getElementById(ed))return;let e=document.createElement("style");e.id=ed,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let s=r.textContent||"",o=l?n:n.toLowerCase(),a=l?s:s.toLowerCase(),i=[],d=0;for(;d<a.length;){let e=a.indexOf(o,d);if(-1===e)break;i.push([e,e+o.length]),d=e+1}if(0===i.length){c(0),u(0);return}let m=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),x=0,f=0,p=[],g=null,b=0;for(;(t=m.nextNode())&&f<i.length;){let e=t.textContent?.length||0,r=x,n=x+e;for(;f<i.length;){let[e,s]=i[f];if(e>=n)break;if(!g)if(e>=r)(g=document.createRange()).setStart(t,e-r),b=s;else break;if(b<=n)g.setEnd(t,b-r),p.push(g),g=null,f++;else break}x=n}h.current=p,c(p.length),u(e=>p.length>0?Math.min(e,p.length-1):0),CSS.highlights&&p.length>0&&CSS.highlights.set("json-search",new Highlight(...p))},[e,n,l]),f=(0,s.useCallback)((e,t)=>{let r=e.getBoundingClientRect();(t.top<r.top||t.bottom>r.bottom)&&(e.scrollTop+=t.top-r.top-r.height/2+t.height/2)},[]),p=(0,s.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let r=h.current[t];if(!r||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(r));let n=r.getBoundingClientRect(),s=e.current?.parentElement;s&&f(s,n)},[e,f]);(0,s.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,s.useEffect)(()=>{p(d)},[d,i,p]),(0,s.useEffect)(()=>{let t=e.current;if(!t||!n)return;let r=new MutationObserver(()=>x());return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>r.disconnect()},[e,n,x]),(0,s.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),h.current=[])},[t]),(0,s.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let g=(0,s.useCallback)(()=>{0!==i&&u(e=>(e+1)%i)},[i]),b=(0,s.useCallback)(()=>{0!==i&&u(e=>(e-1+i)%i)},[i]),v=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>m.current?.focus(),0)},[]),j=(0,s.useCallback)(()=>{r(!1),o(""),u(0)},[]),y=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?b():g()),"Escape"===e.key&&(e.preventDefault(),j())},[g,b,j]);return{isVisible:t,query:n,setQuery:o,caseSensitive:l,setCaseSensitive:a,matchCount:i,currentIndex:d,searchInputRef:m,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:y}}function em({search:e}){return e.isVisible?s.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},s.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:c.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),s.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:c.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:c.A.t("common.noMatch")),s.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:c.A.t("common.previous")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),s.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:c.A.t("common.next")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),s.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:c.A.t("common.close")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}function eh({isOpen:e,onClose:t,commit:r,cwd:l,embedded:a=!1,initialFilePath:i,onContentSearch:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[h,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(null),L=(0,s.useRef)(null),E=eu(L);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&C){e.preventDefault(),E.open();return}if("Escape"===e.key){if(E.isVisible)return void E.close();if(C)return void S(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,C,E]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{m([]),x([]),b(null),j(null),w(!0)}),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let n=Y(t);if(x(n),p(new Set(Q(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{b(e),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error)},0)}}).catch(console.error).finally(()=>w(!1)))},[e,r,l,i]);let M=(0,s.useCallback)(e=>{r&&(b(e),N(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(l)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>N(!1)))},[l,r]),T=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),R=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,l,a;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"),l=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${l}:${a}`:`${e.getFullYear()}-${s}-${o} ${l}:${a}`}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:d("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:d("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:d("commitDetail.date")}),(0,n.jsx)("span",{children:R}),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:d("commitDetail.files")}),(0,n.jsx)("span",{children:d("commitDetail.nChanges",{count:u.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:y?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:d("commitDetail.loadingFiles")}):(0,n.jsx)(X,{files:h,selectedPath:g?.path||null,expandedPaths:f,onSelect:e=>e.file&&M(e.file),onToggle:T,cwd:l,showChanges:!0,emptyMessage:d("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:k?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.loadingDiff")}):v?(0,n.jsx)(H,{oldContent:v.oldContent,newContent:v.newContent,filePath:v.filePath,isNew:v.isNew,isDeleted:v.isDeleted,cwd:l,enableComments:!0,onPreview:!v.isDeleted&&v.filePath.endsWith(".json")?()=>S({content:v.newContent,filePath:v.filePath}):void 0,previewLabel:d("common.readable"),onContentSearch:c}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:d("commitDetail.selectFileToView")})})]})]}),P=C&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>S(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:C.filePath}),(0,n.jsx)("button",{onClick:()=>S(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)(em,{search:E}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:L,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:Z(C.content)})})]})});return a?(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: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"})})}),$,P]}):(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:d("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"})})})]}),$,P]})})}let ex={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"}},ef=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:l,onToggle:a,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:m,hasChangedChildren:h}=e,x=m?ex[m]:null,f=(0,s.useCallback)(()=>{d.isDirectory?a(d.path):l(d.path)},[d.isDirectory,d.path,l,a]),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=m?x.text:h?"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:"→"}),m&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${x.text} ${x.bg} flex-shrink-0`,children:m}),d.isDirectory&&h&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function ep({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:l=null,loadingDirs:a,onSelect:c,onToggle:d,cwd:u,shouldScrollToSelected:m=!1,onScrolledToSelected:h,className:x,renderActions:f,onCreateFile:p,onDelete:g,onRefresh:b,onCopyFile:v,onPaste:j}){let k=(0,s.useRef)(null),{contextMenu:N,showContextMenu:C,hideContextMenu:S}=w(),L=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let l=[];for(let a of t){if(null!==n&&!n.has(a.path))continue;let t=s?.get(a.path),i=a.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}(a.path,s):void 0;l.push({node:a,level:o,gitStatus:t,hasChangedChildren:i}),a.isDirectory&&a.children&&r.has(a.path)&&l.push(...e(a.children,r,n,s,o+1))}return l})(e,r,o,l),[e,r,o,l]),E=(0,i.Te)({count:L.length,getScrollElement:()=>k.current,estimateSize:()=>26,overscan:10}),M=(0,s.useRef)(h);return(M.current=h,(0,s.useEffect)(()=>{if(m&&t&&L.length>0){let e=L.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{E.scrollToIndex(e,{align:"center"}),M.current?.()},150);return()=>clearTimeout(t)}}},[m,t,L,E]),0===L.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:k,className:x||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${E.getTotalSize()}px`,width:"100%",position:"relative"},children:E.getVirtualItems().map(e=>{let s=L[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)(ef,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:a?.has(s.node.path),onSelect:c,onToggle:d,onContextMenu:C,renderActions:f})},s.node.path)})}),N&&(0,n.jsx)(y,{x:N.x,y:N.y,path:N.path,cwd:u,isDirectory:N.isDirectory,onClose:S,onCreateFile:p,onDelete:g,onRefresh:b,onCopyFile:v,onPaste:j})]})}function eg({blame:e,onClick:t}){let{t:r}=(0,o.Bd)(),l=(0,s.useRef)(null),i=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useRef)(!1),m=(0,s.useRef)(null),h=(0,s.useRef)(null),x=(0,s.useRef)(null),f=(0,s.useRef)(e);(0,s.useEffect)(()=>{f.current=e},[e]);let p=(0,s.useRef)(t);(0,s.useEffect)(()=>{p.current=t},[t]);let g=(0,s.useCallback)(()=>{let e,t=i.current,r=l.current;if(!t||!r)return;let n=r.getBoundingClientRect(),s=t.getBoundingClientRect(),o=window.innerWidth,a=window.innerHeight,c=n.left;c+s.width>o-8&&(c=o-s.width-8),c<8&&(c=8),(e=n.top-s.height-4<0?n.bottom+4:n.top-s.height-4)+s.height>a-8&&(e=a-s.height-8),t.style.left=`${c}px`,t.style.top=`${e}px`},[]),b=(0,s.useCallback)(()=>{m.current&&(clearTimeout(m.current),m.current=null),h.current&&(clearTimeout(h.current),h.current=null),d.current=!1,u.current=!1,i.current&&(i.current.style.display="none"),x.current&&(document.removeEventListener("mousedown",x.current.down),document.removeEventListener("mouseup",x.current.up),x.current=null)},[]),v=(0,s.useCallback)(()=>{let e=i.current;if(!e||d.current)return;d.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(g));let t=0,r=0,n=e=>{t=e.clientX,r=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-r)>5)){let t;t=e.target,i.current?.contains(t)||l.current?.contains(t)||b()}};document.addEventListener("mousedown",n),document.addEventListener("mouseup",s),x.current={down:n,up:s}},[g,b]),j=(0,s.useCallback)(()=>{if(m.current&&clearTimeout(m.current),h.current&&(clearTimeout(h.current),h.current=null),d.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(m.current=setTimeout(v,500))},[v]),y=(0,s.useCallback)(()=>{m.current&&(clearTimeout(m.current),m.current=null),d.current&&(h.current=setTimeout(()=>{u.current||b()},200))},[b]),w=(0,s.useCallback)(()=>{u.current=!0,h.current&&(clearTimeout(h.current),h.current=null)},[]),k=(0,s.useCallback)(()=>{u.current=!1,b()},[b]),N=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&i.current?.contains(t.anchorNode)||(p.current?.(f.current),b())},[b]);(0,s.useEffect)(()=>()=>b(),[b]);let C=e.message.split("\n")[0]||"",S=e.message.split("\n").slice(1).join("\n").trim();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{ref:l,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:j,onMouseLeave:y,children:[e.author.split(" ")[0],", ",function(e){let t=c.A.t,r=Math.floor((Date.now()-1e3*e)/1e3);if(r<60)return t("common.justNow");let n=Math.floor(r/60);if(n<60)return t("common.minutesAgo",{count:n});let s=Math.floor(n/60);if(s<24)return t("common.hoursAgo",{count:s});let o=Math.floor(s/24);if(o<30)return t("common.daysAgo",{count:o});let l=Math.floor(o/30);return l<12?t("common.monthsAgo",{count:l}):t("common.yearsAgo",{count:Math.floor(l/12)})}(e.time)," \xb7 ",C]}),(0,a.createPortal)((0,n.jsxs)("div",{ref:i,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:w,onMouseLeave:k,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,n.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,n.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,n.jsx)("div",{className:"font-medium",children:C}),S&&(0,n.jsx)("div",{className:"mt-1 text-muted-foreground",children:S}),(0,n.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:N,children:r("codeViewer.clickToViewDetails")})]}),document.body)]})}let eb=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function ev(e,t){let r,n=document.caretRangeFromPoint(e.clientX,e.clientY);if(!n||!t.contains(n.startContainer))return 1;let s=n.startContainer,o=n.startOffset,l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;r=l.nextNode();){if(r===s){a+=o;break}a+=r.textContent?.length||0}return a}let ej=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:r,hasComments:l,firstComment:a,lineCommentsCount:i,isInRange:c,showLineNumbers:d,lineNumChars:u,commentsEnabled:m,virtualItemSize:h,virtualItemStart:x,onCommentBubbleClick:f,onCmdClick:p,onTokenHover:g,onTokenHoverLeave:b,flashLine:v,blameLine:j,showBlameInfo:y,blameAuthorColor:w,isBlameHovered:k,onBlameClick:N,onBlameMouseEnter:C,onBlameMouseLeave:S,inlineBlameData:L,onInlineBlameClick:E,isCursorLine:M,cursorCol:T}){let{t:R}=(0,o.Bd)(),$=(0,s.useMemo)(()=>M&&null!=T?function(e,t){let r=0,n=0;for(;n<e.length;){if("<"===e[n]){let t=e.indexOf(">",n);if(-1!==t){n=t+1;continue}}if(r===t){let t;if("&"===e[n]){let r=e.indexOf(";",n);t=-1!==r&&r-n<10?r+1:n+1}else t=n+1;let r=e.substring(n,t);return e.substring(0,n)+'<span class="vi-char-cursor">'+r+"</span>"+e.substring(t)}if("&"===e[n]){let t=e.indexOf(";",n);n=-1!==t&&t-n<10?t+1:n+1}else n++;r++}return e+'<span class="vi-char-cursor"> </span>'}(r,T):r,[r,M,T]),P=(0,s.useCallback)(e=>{if(!e.metaKey||!p)return;e.preventDefault(),e.stopPropagation();let r=e.currentTarget,n=ev(e,r);window.getSelection()?.removeAllRanges(),p(t,n)},[t,p]),I=(0,s.useCallback)(e=>{if(!g||0!==e.buttons)return;let r=window.getSelection();if(r&&!r.isCollapsed)return;let n=e.target;if("SPAN"!==n.tagName||!n.style.color)return;let s=e.currentTarget,o=ev(e,s),l=n.getBoundingClientRect();g(t,o,{x:l.left,y:l.bottom+4})},[t,g]),B=(0,s.useCallback)(()=>{j&&N&&N(j)},[j,N]),D=(0,s.useCallback)(e=>{j&&C&&C(j,e)},[j,C]);return(0,n.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${h}px`,transform:`translateY(${x}px)`,backgroundColor:k&&w?w.bg:void 0},className:`flex ${v===t?"flash-line":""} ${M?"vi-cursor-line":""} ${c?"bg-blue-9/20":l?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,n.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:k&&w?w.bg:void 0},children:[j&&w&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:w.border}}),(0,n.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:D,onMouseLeave:S,onClick:B,title:R("codeViewer.clickToViewCommit"),children:y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"font-medium",style:{color:w.border},children:j.hash}),(0,n.jsx)("span",{className:"truncate flex-1",children:j.author.split(" ")[0]})]}):null})]}),d&&(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[m&&l&&a&&(0,n.jsx)("button",{onClick:e=>f(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:i}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),m&&!l&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"text-right",style:{minWidth:`${u}ch`},children:t})]})]}),(0,n.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:P,onMouseOver:I,onMouseLeave:b,"data-code-content":!0,children:[(0,n.jsx)("span",{dangerouslySetInnerHTML:{__html:$}}),L&&(0,n.jsx)(eg,{blame:L,onClick:E})]})]},e)});function ey(e,t,r){let n,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=0;for(;(n=s.nextNode())&&n!==t;)o+=n.textContent.length;return o+r}function ew(e,t){let r,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,o=null;for(;r=n.nextNode();){o=r;let e=r.textContent.length;if(s<=e)return{node:r,offset:s};s-=e}return o?{node:o,offset:o.textContent.length}:null}function ek(e,t){for(let r of e){if(r.path===t)return r;if(r.children){let e=ek(r.children,t);if(e)return e}}return null}function eN(e){let t=[];for(let r of e){let e=r.split("/"),n=t;for(let t=0;t<e.length;t++){let r=e[t],s=t===e.length-1,o=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===r);l||(l={name:r,path:o,isDirectory:!s,children:s?void 0:[]},n.push(l)),!s&&l.children&&(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=>{e.children&&r(e.children)})};return r(t),t}function eC(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),n.children&&r(n.children))};return r(e),t}let eS=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]),eL=()=>{},eE="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function eM(e){let t=window.getSelection();if(!t?.rangeCount)return null;let r=t.getRangeAt(0),n=r.startContainer;for(;n&&n.parentElement!==e;)n=n.parentElement;if(!n)return null;let s=Array.from(e.children).indexOf(n);if(s<0)return null;let o=document.createRange();return o.selectNodeContents(n),o.setEnd(r.startContainer,r.startOffset),{line:s,offset:o.toString().length}}function eT(e,t){let r,n=e.children[t.line];if(!n)return;let s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=t.offset;for(;r=s.nextNode();){let e=r.textContent?.length||0;if(o<=e){let e=window.getSelection(),t=document.createRange();t.setStart(r,o),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}o-=e}let l=window.getSelection(),a=document.createRange();a.selectNodeContents(n),a.collapse(!1),l?.removeAllRanges(),l?.addRange(a)}function eR(e){return e.map(e=>`<div style="${eE}">${e}</div>`).join("")}let e$=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:r=!0,showSearch:l=!0,className:c="",cwd:d,enableComments:u=!1,scrollToLine:x=null,scrollToLineAlign:b="center",onScrollToLineComplete:v,highlightKeyword:y=null,visibleLineRef:w,onCmdClick:k,onTokenHover:N,onTokenHoverLeave:E,onTokenHoverCancel:M,blameLines:T,inlineBlameLines:R,onSelectCommit:F,editable:O=!1,initialMtime:z,onEditorClose:H,onSaved:_,onEditorStateChange:U,viMode:q=!1,onContentMutate:V,onEnterInsertMode:K,onViSave:J,viStateRef:X,initialCursorLine:Y,initialCursorCol:Q,onInitialCursorSet:G,onContentSearch:Z},ee){var et;let er,en,es,eo,el,{t:ea}=(0,o.Bd)(),ei=(0,s.useRef)(e),ec=(0,s.useRef)(!1),[ed,eu]=(0,s.useState)(!1),[em,eh]=(0,s.useState)(!1),[ex,ef]=(0,s.useState)(()=>e.split("\n").length),ep=(0,s.useRef)(e.split("\n").length),[eg,ev]=(0,s.useState)({show:!1}),ek=(0,s.useRef)(null),eN=(0,s.useRef)(null),eC=(0,s.useRef)(z),eS=(0,s.useRef)(null),eL=(0,s.useRef)(!1),e$=(0,s.useRef)(!1),{parentRef:eP,containerRef:eI,searchInputRef:eB,floatingToolbarRef:eD,suppressHoverRef:eF,bumpToolbarRef:eO,savedSelectionRef:eA,highlightedLines:eW,isMounted:ez,cmdHeld:eH,flashLine:e_,isSearchVisible:eU,searchQuery:eq,caseSensitive:eV,wholeWord:eK,currentMatchIndex:eJ,viewingComment:eX,addCommentInput:eY,sendToAIInput:eQ,chatContext:eG,commentsEnabled:eZ,updateComment:e0,deleteComment:e1,lines:e2,matches:e5,rowData:e4,virtualizer:e3,commentsByEndLine:e6,linesWithComments:e8,setIsSearchVisible:e9,setSearchQuery:e7,setCaseSensitive:te,setWholeWord:tt,setViewingComment:tr,setAddCommentInput:tn,setSendToAIInput:ts,goToNextMatch:to,goToPrevMatch:tl,handleSearchKeyDown:ta,handleCommentBubbleClick:ti,handleToolbarAddComment:tc,handleToolbarSendToAI:td,handleToolbarSearch:tu,handleCommentSubmit:tm,handleSendToAISubmit:th,getHighlightedLineHtml:tx,suppressMatchScrollRef:tf,inlineBlameLineRef:tp,inlineBlameVersion:tg}=function({content:e,filePath:t,showSearch:r=!0,cwd:n,enableComments:o=!1,scrollToLine:l=null,scrollToLineAlign:a="center",onScrollToLineComplete:c,visibleLineRef:d,onContentSearch:u}){let[x,g]=(0,s.useState)(!1),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),y=C();(0,s.useEffect)(()=>{g(!0)},[]);let[w,k]=(0,s.useState)(!1),[N,S]=(0,s.useState)(null),L=(0,s.useRef)(null),[E,M]=(0,s.useState)(!1),[T,R]=(0,s.useState)(""),[$,P]=(0,s.useState)(!1),[B,F]=(0,s.useState)(!1),[O,A]=(0,s.useState)(0),[W,z]=(0,s.useState)(0),H=(0,s.useRef)(!1),[_,U]=(0,s.useState)(null),q=(0,s.useRef)(null),V=(0,s.useRef)(()=>{}),K=(0,s.useRef)(!1),J=(0,s.useRef)(null),[X,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null),Z=(0,s.useRef)(null),[ee,et]=(0,s.useState)(0),er=o&&!!n,{comments:en,addComment:es,updateComment:eo,deleteComment:el,refresh:ea}=p({cwd:n||"",filePath:t}),ei=(0,s.useMemo)(()=>e.split("\n"),[e]),ec=D(ei,t),ed=(0,s.useMemo)(()=>{let e=new Map;for(let t of en){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[en]),eu=(0,s.useMemo)(()=>{let e=new Set;for(let t of en)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[en]),em=(0,s.useMemo)(()=>(function(e,t,r,n){if(!t)return[];let s=[],o=r?t:t.toLowerCase();for(let t=0;t<e.length;t++){let l=r?e[t]:e[t].toLowerCase(),a=0;for(;;){let e=l.indexOf(o,a);if(-1===e)break;let r=e+o.length;if(n){let n=e>0?l[e-1]:" ",o=r<l.length?l[r]:" ",a=!/\w/.test(n),i=!/\w/.test(o);a&&i&&s.push({lineIndex:t,startCol:e,endCol:r})}else s.push({lineIndex:t,startCol:e,endCol:r});a=e+1}}return s})(ei,T,$,B),[ei,T,$,B]);(0,s.useEffect)(()=>{em.length>0&&A(0)},[em.length,T,$,B]);let eh=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<ei.length;t++)e.push({type:"code",lineIndex:t});return e},[ei.length]),ex=(0,i.Te)({count:eh.length,getScrollElement:()=>b.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!d)return;let e=b.current;if(!e)return;let t=()=>{if(!ex.range)return;let t=e.scrollTop;for(let e of ex.getVirtualItems())if(e.start>=t){let t=eh[e.index];t?.type==="code"&&(d.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[d,eh]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&k(!0)},t=e=>{"Meta"===e.key&&k(!1)},r=()=>k(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",r),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",r)}},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),M(!0),setTimeout(()=>j.current?.focus(),0)),"Escape"===e.key&&(E?(M(!1),R("")):Q?G(null):X?Y(null):q.current?(q.current=null,V.current()):_&&U(null))},t=v.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[r,E,Q,X,_]),(0,s.useEffect)(()=>{if(H.current){H.current=!1;return}if(em.length>0&&O>=0&&O<em.length){let e=em[O],t=eh.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&ex.scrollToIndex(t,{align:"center"})}},[O,em,ex,eh,W]);let ef=(0,s.useCallback)(()=>{0!==em.length&&(A(e=>(e+1)%em.length),z(e=>e+1))},[em.length]),ep=(0,s.useCallback)(()=>{0!==em.length&&(A(e=>(e-1+em.length)%em.length),z(e=>e+1))},[em.length]),eg=(0,s.useRef)(l);eg.current=l,(0,s.useEffect)(()=>{if(null!==eg.current&&eg.current>0&&eh.length>0){let e=eg.current,t=e-1,r=eh.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(r>=0){let t=()=>{ex.scrollToIndex(r,{align:a}),"center"===a&&(L.current&&clearTimeout(L.current),S(e),L.current=setTimeout(()=>S(null),500)),c?.()};"start"===a?requestAnimationFrame(t):setTimeout(t,150)}}},[l,a,eh.length,ex,c]);let eb=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ep():ef()),"Escape"===e.key&&(M(!1),R(""))},[ef,ep]),ev=(0,s.useCallback)((e,t)=>{er&&(t.stopPropagation(),U({comment:e,x:t.clientX,y:t.clientY}),q.current=null,V.current(),Y(null),G(null))},[er]);(0,s.useEffect)(()=>{if(!er)return;let e=b.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,J.current=null,K.current=!0,q.current&&(q.current=null,V.current())},o=e=>{t=!1;let s=e.target;if(s.closest?.(".floating-toolbar"))return;let o=Math.abs(e.clientX-r)>5||Math.abs(e.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed){K.current=!1,q.current&&(q.current=null,V.current());return}let a=l.toString();if(!a.trim()||!o){K.current=!1,q.current&&(q.current=null,V.current());return}let i=l.getRangeAt(0),c=b.current;if(!c||!c.contains(i.commonAncestorContainer))return;let d=i.startContainer,u=i.endContainer,m=e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t)return null;let r=t.closest("[data-line]");return r?parseInt(r.getAttribute("data-line")||"0",10):null},h=m(d),x=m(u);if(h&&x){let t=Math.min(h,x),r=Math.max(h,x);q.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},selectedText:a},K.current=!0,V.current();let n=d.nodeType===Node.TEXT_NODE?d.parentElement?.closest("[data-line]"):d.closest("[data-line]"),s=u.nodeType===Node.TEXT_NODE?u.parentElement?.closest("[data-line]"):u.closest("[data-line]");n&&s&&(J.current={startLine:h,startOffset:ey(n,i.startContainer,i.startOffset),endLine:x,endOffset:ey(s,i.endContainer,i.endOffset)})}},l=()=>{if(t||!q.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(q.current=null,J.current=null,K.current=!1,V.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[er]),(0,s.useEffect)(()=>{let e=b.current;if(!e)return;let t=t=>{let r,n;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==Z.current&&(Z.current=null,et(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let o=(r=t.target,(n=r.closest?.("[data-line]"))?parseInt(n.getAttribute("data-line")||"0",10):null);o!==Z.current&&(Z.current=o,requestAnimationFrame(()=>et(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ej=(0,s.useCallback)(()=>{let e=q.current;e&&(Y({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),q.current=null,V.current())},[]),ew=(0,s.useCallback)(()=>{let e=q.current;if(!e)return;let t=e.selectedText;G({x:e.x,y:e.y,range:e.range,codeContent:t}),q.current=null,V.current()},[]),ek=(0,s.useCallback)(()=>{let e=q.current;if(!e||!u)return;let t=e.selectedText.trim();q.current=null,V.current(),t&&u(t)},[u]),eN=(0,s.useCallback)(async e=>{X&&(await es(X.range.start,X.range.end,e),Y(null))},[X,es]),eC=(0,s.useCallback)(async e=>{if(Q&&y&&n)try{let r=await m(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:Q.range.start,endLine:Q.range.end,codeContent:Q.codeContent});let o=f(s,e);y.sendMessage(o),await h(n),ea(),G(null)}catch(e){console.error("Failed to send to AI:",e)}},[Q,y,t,n,ea]),eS=(0,s.useCallback)((e,t,r)=>{let n=ei[e];if(!n)return t;let s=[];if(T&&em.length>0)for(let t of em.filter(t=>t.lineIndex===e)){let r=em[O]?.lineIndex===e&&em[O]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:r?"hl-cur":"hl-m"})}if(r&&!T&&r.length>=1){let e=r.toLowerCase(),t=n.toLowerCase(),o=0;for(;-1!==(o=t.indexOf(e,o));)s.push({start:o,end:o+r.length,cls:"hl-kw"}),o+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let o=[],l=0;for(let e of s){if(e.start<l)continue;e.start>l&&o.push(I(n.substring(l,e.start)));let t=I(n.substring(e.start,e.end));o.push(`<span class="${e.cls}">${t}</span>`),l=e.end}if(l<n.length&&o.push(I(n.substring(l))),t!==I(n)){let e=t;for(let t of s){let r=I(n.substring(t.start,t.end)),s=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=RegExp(`(?<=>)([^<]*?)(${s})`,""),l=`$1<span class="${t.cls}">${r}</span>`,a=e.replace(o,l);a.length>e.length+200||(e=a)}return e}return o.join("")},[T,em,O,ei]);return{parentRef:b,containerRef:v,searchInputRef:j,floatingToolbarRef:q,suppressHoverRef:K,savedSelectionRef:J,highlightedLines:ec,isMounted:x,cmdHeld:w,flashLine:N,isSearchVisible:E,searchQuery:T,caseSensitive:$,wholeWord:B,currentMatchIndex:O,viewingComment:_,bumpToolbarRef:V,addCommentInput:X,sendToAIInput:Q,chatContext:y,commentsEnabled:er,comments:en,updateComment:eo,deleteComment:el,lines:ei,matches:em,rowData:eh,virtualizer:ex,commentsByEndLine:ed,linesWithComments:eu,setIsSearchVisible:M,setSearchQuery:R,suppressMatchScrollRef:H,setCaseSensitive:P,setWholeWord:F,setViewingComment:U,setAddCommentInput:Y,setSendToAIInput:G,goToNextMatch:ef,goToPrevMatch:ep,handleSearchKeyDown:eb,handleCommentBubbleClick:ev,handleToolbarAddComment:ej,handleToolbarSendToAI:ew,handleToolbarSearch:ek,handleCommentSubmit:eN,handleSendToAISubmit:eC,getHighlightedLineHtml:eS,inlineBlameLineRef:Z,inlineBlameVersion:ee}}({content:e,filePath:t,showSearch:l,cwd:d,enableComments:!O&&u,scrollToLine:O?null:x,scrollToLineAlign:O?"center":b,onScrollToLineComplete:O?void 0:v,visibleLineRef:O?void 0:w,onContentSearch:Z}),tb=j(),tv=(0,s.useRef)(null),tj=(0,s.useRef)(null),ty=(0,s.useRef)({line:0,col:0}),tw=function({lines:e,enabled:t,onContentChange:r,onEnterInsert:n,onSave:o,getVisibleLineCount:l,scrollToLine:a,onSearchExecute:i,onSearchNext:c,onSearchPrev:d,onSearchClear:u}){let[m,h]=(0,s.useState)("normal"),[x,f]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)(""),[N,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(""),E=(0,s.useRef)([]),M=(0,s.useRef)([]),T=(0,s.useRef)([]),R=(0,s.useRef)(null),$=(0,s.useRef)(e);(0,s.useEffect)(()=>{$.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>f(t=>Math.min(t,e.length-1)))},[e.length]);let P=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,($.current[e]??"").length-1))),[]),I=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-I.current);I.current=e.length,t>10&&(queueMicrotask(()=>{f(-1),g(0),v(!1)}),E.current=[],M.current=[],T.current=[])},[e]);let B=(0,s.useCallback)(()=>{R.current&&(clearTimeout(R.current),R.current=null),y("")},[]),D=(0,s.useCallback)(()=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{y(""),R.current=null},500)},[]),F=(0,s.useCallback)((e,t)=>{E.current.push(t),M.current=[],v(!0),r(e.join("\n"))},[r]),O=(0,s.useCallback)((e,t)=>{let r=Math.max(0,Math.min(e,$.current.length-1));f(r),g(P(r,t??0)),a(r,"auto")},[a,P]),A=(0,s.useCallback)(e=>{f(t=>{let r=Math.max(0,Math.min(t+e,$.current.length-1));return a(r,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,($.current[r]??"").length-1)))),r})},[a]),W=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(x,e.length-1);if(0===e.length)return;let r=e[t];T.current=[r];let n=[...e];n.splice(t,1),0===n.length&&n.push("");let s=Math.min(t,n.length-1);F(n,{lineIndex:t,oldLines:[r],newLines:[],cursorLine:t}),f(s),g(0)},[x,F]),z=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(x,e.length-1);e.length>0&&(T.current=[e[t]])},[x]),H=(0,s.useCallback)(()=>{let e=T.current;if(0===e.length)return;let t=$.current,r=Math.min(x,t.length-1)+1,n=[...t];n.splice(r,0,...e),F(n,{lineIndex:r,oldLines:[],newLines:[...e],cursorLine:x}),f(r),g(0),a(r,"auto")},[x,F,a]),_=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(x,e.length-1),r=e[t];if(!r||0===r.length)return;let n=r.substring(1),s=[...e];s[t]=n,F(s,{lineIndex:t,oldLines:[r],newLines:[n],cursorLine:x})},[x,F]),U=(0,s.useCallback)(()=>{let e=E.current;if(0===e.length)return;let t=e.pop(),n=[...$.current];0===t.newLines.length&&t.oldLines.length>0?n.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(n.splice(t.lineIndex,t.newLines.length),0===n.length&&n.push("")):n.splice(t.lineIndex,t.newLines.length,...t.oldLines),M.current.push(t),r(n.join("\n")),f(Math.min(t.cursorLine,n.length-1)),a(Math.min(t.cursorLine,n.length-1),"auto"),0===e.length&&v(!1)},[r,a]),q=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),n=[...$.current];0===t.newLines.length&&t.oldLines.length>0?(n.splice(t.lineIndex,t.oldLines.length),0===n.length&&n.push("")):0===t.oldLines.length&&t.newLines.length>0?n.splice(t.lineIndex,0,...t.newLines):n.splice(t.lineIndex,t.oldLines.length,...t.newLines),E.current.push(t),v(!0),r(n.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);f(Math.min(s,n.length-1)),a(Math.min(s,n.length-1),"auto")},[r,a]),V=(0,s.useCallback)(e=>{let t=$.current,r=Math.min(x,t.length-1);if("o"===e||"O"===e){let n="o"===e?r+1:r,s=[...t];s.splice(n,0,""),F(s,{lineIndex:n,oldLines:[],newLines:[""],cursorLine:x}),r=n,f(n)}h("insert"),n(r,p,e)},[x,p,F,n]),K=(0,s.useCallback)(()=>{h("normal"),B()},[B]),J=(0,s.useCallback)(()=>{h("command"),k("")},[]),X=(0,s.useCallback)(()=>{h("normal"),k("")},[]),Y=(0,s.useCallback)(()=>{h("search"),C("")},[]),Q=(0,s.useCallback)(()=>{h("normal"),C("")},[]),G=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){o?.(),h("normal"),k("");return}if("q"===t){h("normal"),k("");return}if("wq"===t){o?.(),h("normal"),k("");return}if("noh"===t||"nohlsearch"===t){u?.(),h("normal"),k("");return}let r=parseInt(t,10);if(!isNaN(r)&&r>0){let e=Math.min(r-1,$.current.length-1);f(e),a(e,"center"),h("normal"),k("");return}h("normal"),k("")},[o,u,a]),Z=(0,s.useCallback)(e=>{if(!e){h("normal"),C("");return}L(e),i?.(e),h("normal"),C("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===m)return("Escape"===e.key||!!r)&&(K(),!0);if("command"===m)return!e.isComposing&&("Escape"===e.key||r?X():"Enter"===e.key?G(w):"Backspace"===e.key?0===w.length?X():k(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||k(t=>t+e.key),!0);if("search"===m)return!e.isComposing&&("Escape"===e.key||r?Q():"Enter"===e.key?Z(N):"Backspace"===e.key?0===N.length?Q():C(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||C(t=>t+e.key),!0);if(x<0&&(f(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(A(Math.max(1,Math.floor(l()/2))),B(),!0):"u"===e.key?(A(-Math.max(1,Math.floor(l()/2))),B(),!0):"r"===e.key&&(q(),B(),!0);let n=e.key,s=j+n;if("g"===s)return y("g"),D(),!0;if("gg"===s)return O(0),B(),!0;if("d"===s)return y("d"),D(),!0;if("dd"===s)return W(),B(),!0;if("y"===s)return y("y"),D(),!0;if("yy"===s)return z(),B(),!0;if(j&&s!==n&&B(),"j"===n||"ArrowDown"===n)return A(1),!0;if("k"===n||"ArrowUp"===n)return A(-1),!0;if("h"===n||"ArrowLeft"===n)return g(e=>Math.max(0,e-1)),!0;if("l"===n||"ArrowRight"===n){let e=Math.max(0,($.current[x]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===n)return g(0),!0;if("$"===n)return g(Math.max(0,($.current[x]??"").length-1)),!0;if("^"===n){let e=($.current[x]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===n?(O($.current.length-1),!0):"x"===n?(_(),!0):"p"===n?(H(),!0):"u"===n?(U(),!0):"i"===n||"a"===n||"I"===n||"A"===n||"o"===n||"O"===n?(V(n),!0):"/"===n?(Y(),!0):"n"===n?(c?.(),!0):"N"===n?(d?.(),!0):":"===n?(J(),!0):"Escape"!==n&&1===n.length},[t,m,j,w,N,x,K,V,J,X,Y,Q,G,Z,A,O,l,W,z,H,_,U,q,B,D,c,d]);return{state:{mode:m,cursorLine:x,cursorCol:p,isDirty:b,keyBuffer:j,commandInput:w,searchInput:N,lastSearch:S},handleKeyDown:ee,enterNormal:K,enterInsert:V,setCursorLine:f,setCursorCol:g,setCommandInput:k,setSearchInput:C,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{E.current=[],M.current=[]},[])}}({lines:e2,enabled:q&&!O,onContentChange:e=>{V?.(e)},onEnterInsert:(e,t,r)=>{let n=t;if("a"===r)n=t+1;else if("A"===r)n=(e2[e]??"").length;else if("I"===r){let t=(e2[e]??"").search(/\S/);n=t>=0?t:0}else("o"===r||"O"===r)&&(n=0);ty.current={line:e,col:n},K?.(e)},onSave:J,getVisibleLineCount:()=>{let e=eP.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let r=e4.findIndex(t=>"code"===t.type&&t.lineIndex===e);r>=0&&e3.scrollToIndex(r,{align:t||"auto"})},onSearchExecute:e=>{e7(e),e9(!1)},onSearchNext:to,onSearchPrev:tl,onSearchClear:()=>{e7("")}});(0,s.useEffect)(()=>{X&&(X.current={cursorLine:tw.state.cursorLine,cursorCol:tw.state.cursorCol})},[X,tw.state.cursorLine,tw.state.cursorCol]);let tk=(0,s.useRef)(null);(0,s.useEffect)(()=>{q&&!O&&null!=Y&&t&&tk.current!==t&&(tk.current=t,tw.setCursorLine(Y-1),null!=Q&&tw.setCursorCol(Q-1),G?.())},[q,O,Y,Q,t]),(0,s.useEffect)(()=>{if(!q||O)return;let e=eI.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tw.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[q,O,tw.handleKeyDown]),(0,s.useEffect)(()=>{if(!q||O)return;let e=eI.current;e&&"normal"===tw.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[q,O,tw.state.mode,e]);let tN=(0,s.useCallback)(e=>{if(!q||O)return;let t=e.target.closest("[data-line]");if(t){let r=parseInt(t.getAttribute("data-line"),10);if(!isNaN(r)){tw.setCursorLine(r-1);let n=t.querySelector("[data-code-content]");if(n){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&n.contains(t.startContainer)){let e,s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=0;for(;e=s.nextNode();){if(e===t.startContainer){o+=t.startOffset;break}o+=e.textContent?.length||0}let l=e2[r-1]??"";tw.setCursorCol(Math.max(0,Math.min(o,Math.max(0,l.length-1))))}}}}let r=e.target;if("TEXTAREA"===r.tagName||"INPUT"===r.tagName||r.isContentEditable)return;let n=eI.current;n&&n.focus()},[q,O,tw.setCursorLine,tw.setCursorCol,e2]),tC=(0,s.useCallback)(e=>{q&&!O&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(tf.current=!0,e7(t))})},[q,O,e7,tf]);(0,s.useEffect)(()=>{"command"===tw.state.mode?setTimeout(()=>tv.current?.focus(),0):"search"===tw.state.mode&&setTimeout(()=>tj.current?.focus(),0)},[tw.state.mode]),(0,s.useEffect)(()=>{let e=eP.current;if(!e)return;let t=()=>{(M??E)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[M,E]),(0,s.useEffect)(()=>{eY||eQ?(eF.current=!0,E?.()):eD.current||(eF.current=!1)},[eY,eQ,E]),(0,s.useLayoutEffect)(()=>{let e=eA.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let r=eP.current;if(!r)return;let n=r.querySelector(`[data-line="${e.startLine}"]`),s=r.querySelector(`[data-line="${e.endLine}"]`);if(!n||!s)return;let o=ew(n,e.startOffset),l=ew(s,e.endOffset);if(o&&l)try{let e=document.createRange();e.setStart(o.node,o.offset),e.setEnd(l.node,l.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tS=(0,s.useCallback)((e,t,r)=>{eF.current||N?.(e,t,r)},[N]),tL=(0,s.useCallback)((e,t)=>{eF.current||k?.(e,t)},[k]),tE=Math.max(4,String(O?ex:e2.length).length),tM=(0,s.useMemo)(()=>{let e=0;for(let t of e2){let r=0;for(let e=0;e<t.length;e++)" "===t[e]?r+=2-r%2:r+=1;r>e&&(e=r)}return e},[e2]);(0,s.useEffect)(()=>{if(O){ei.current=e;let t=e.split("\n").length;ep.current=t,ef(t),ec.current=!1,eu(!1),ev({show:!1}),eC.current=z}},[O,e,z]),(0,s.useEffect)(()=>{if(!O)return;let t=ek.current;if(!t)return;let r=e.split("\n");t.innerHTML=eR(r.map((e,t)=>eW[t]||I(e||" "))),requestAnimationFrame(()=>{let e,n;q?(e=Math.max(0,Math.min(ty.current.line,r.length-1)),n=ty.current.col):(e=Math.max(0,Math.min((w?.current??1)-1,r.length-1)),n=0),t.focus(),eT(t,{line:e,offset:n});let s=w?.current??1;eN.current&&(eN.current.scrollTop=(s-1)*20)})},[O]),(0,s.useEffect)(()=>{O&&U?.({isDirty:ed,isSaving:em})},[O,ed,em,U]);let tT=(0,s.useCallback)(()=>{let e=ek.current;if(!e)return ei.current;let t=[];for(let r of e.childNodes){let e=r.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tR=(0,s.useCallback)(()=>{eS.current&&clearTimeout(eS.current),eS.current=setTimeout(async()=>{let e=ek.current;if(e&&!e$.current){ei.current=tT();try{let r=await $(),n=P(t),s=document.documentElement.classList.contains("dark"),o=ei.current.split("\n"),l=r.codeToTokens(o.join("\n"),{lang:n,theme:s?"github-dark":"github-light"}).tokens.map(e=>B(e)),a=eM(e);eL.current=!0,e.innerHTML=eR(l),eL.current=!1,a&&eT(e,a)}catch{}}},300)},[t,tT]);(0,s.useEffect)(()=>{if(O)return()=>{eS.current&&clearTimeout(eS.current)}},[O]);let t$=(0,s.useCallback)(()=>{let e=ek.current;if(!e)return;ec.current||(ec.current=!0,eu(!0));let t=e.children.length;t!==ep.current&&(ep.current=t,ef(t))},[]),tP=(0,s.useCallback)(()=>{eL.current||e$.current||(t$(),tR())},[t$,tR]),tI=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ek.current;if(!t)return;let r=window.getSelection();if(!r?.rangeCount)return;let n=r.getRangeAt(0);n.deleteContents();let s=n.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let o=eM(t),l=Array.from(t.children).indexOf(s),a=s.textContent||"",i=o?.offset??a.length,c=a.substring(0,i),d=a.substring(i);s.innerHTML=I(c||" ");let u=document.createElement("div");u.setAttribute("style",eE),u.innerHTML=I(d||" "),s.after(u),eT(t,{line:l+1,offset:0}),t$(),tR()}},[t$,tR]),tB=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tD=(0,s.useCallback)(async(e=!1)=>{if(d){ei.current=tT(),eh(!0);try{let r=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:d,path:t,content:ei.current,expectedMtime:e?void 0:eC.current})}),n=await r.json();if(409===r.status&&n.conflict){try{let e=await fetch(`/api/files/read?cwd=${encodeURIComponent(d)}&path=${encodeURIComponent(t)}`),r=await e.json();ev({show:!0,diskContent:"text"===r.type?r.content:void 0})}catch{ev({show:!0})}return}if(!r.ok)throw Error("Failed to save file");n.mtime&&(eC.current=n.mtime),ec.current=!1,eu(!1),ev({show:!1}),(0,g.oR)(ea("toast.savedSuccess"),"success"),_?.()}catch(e){console.error("Error saving file:",e),(0,g.oR)(ea("toast.saveFailed"),"error")}finally{eh(!1)}}},[d,t,tT,_]),tF=(0,s.useCallback)(async()=>{ed&&!em&&await tD(!1)},[ed,em,tD]),tO=(0,s.useCallback)(async()=>{ev({show:!1}),await tD(!0)},[tD]),tA=(0,s.useCallback)(()=>{if(void 0!==eg.diskContent){ei.current=eg.diskContent;let t=eg.diskContent.split("\n").length;ep.current=t,ef(t);let r=eg.diskContent!==e;ec.current=r,eu(r);let n=ek.current;n&&(n.innerHTML=eR(eg.diskContent.split("\n").map(e=>I(e||" "))),tR())}ev({show:!1}),_?.()},[eg.diskContent,e,_,tR]),tW=(0,s.useCallback)(()=>{let e=eN.current;return e?Math.floor(e.scrollTop/20)+1:w?.current??1},[w]),tz=(0,s.useCallback)(async()=>{(!ed||await (0,g.lJ)(ea("codeViewer.unsavedConfirm"),{danger:!0,confirmText:ea("codeViewer.discardChanges"),cancelText:ea("codeViewer.continueEditing")}))&&H?.(tW())},[ed,H,tW]);(0,s.useEffect)(()=>{if(!O)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tF())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[O,tF]);let tH=(0,s.useCallback)(()=>{let e=tT();V?.(e);let t=ek.current,r=t?eM(t):null,n=tW();if(tw.enterNormal(),r){tw.setCursorLine(r.line);let t=e.split("\n")[r.line]??"";tw.setCursorCol(Math.max(0,Math.min(r.offset,Math.max(0,t.length-1))))}else tw.setCursorLine(Math.max(0,n-1));H?.(n)},[tT,V,tW,H,tw]);(0,s.useEffect)(()=>{if(!O)return;let e=e=>{let t="Escape"===e.key,r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||q&&r)&&(e.preventDefault(),e.stopPropagation(),q?ec.current?(0,g.lJ)(ea("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:ea("codeViewer.discardChanges"),cancelText:ea("codeViewer.continueEditing")}).then(e=>{e&&tH()}):tH():tz())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[O,q,tz,tH]),(0,s.useImperativeHandle)(ee,()=>({save:tF,close:tz,get isDirty(){return ed},get isSaving(){return em}}),[tF,tz,ed,em]);let t_=!!(T&&T.length>0),tU=(0,s.useMemo)(()=>{if(!T)return new Map;let e=[...new Set(T.map(e=>e.author))],t=new Map;return e.forEach((e,r)=>{t.set(e,eb[r%eb.length])}),t},[T]),[tq,tV]=(0,s.useState)(null),[tK,tJ]=(0,s.useState)(null);(0,s.useEffect)(()=>{tV(null),tJ(null)},[T]);let tX=(0,s.useCallback)((e,t)=>{tV(e.author);let r=t.currentTarget.getBoundingClientRect();tJ({line:e,x:r.right+8,y:r.top})},[]),tY=(0,s.useCallback)(()=>{tV(null),tJ(null)},[]),tQ=(0,s.useCallback)(e=>{F&&(F({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tJ(null))},[F]),tG=`${tE+2}ch`;return(0,n.jsxs)("div",{ref:eI,className:`h-full flex flex-col outline-none ${c}`,tabIndex:0,onClick:tN,onDoubleClick:tC,children:[O&&eg.show&&(0,n.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("svg",{className:"w-5 h-5 text-amber-500 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 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1",children:ea("codeViewer.fileModifiedExternally")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:tA,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:ea("codeViewer.useDiskVersion")}),(0,n.jsx)("button",{onClick:tO,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:ea("codeViewer.forceOverwrite")})]})]}),!O&&l&&eU&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:eB,type:"text",value:eq,onChange:e=>e7(e.target.value),onKeyDown:ta,placeholder:ea("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("button",{onClick:()=>te(!eV),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eV?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:ea("codeViewer.caseSensitive"),children:"Aa"}),(0,n.jsx)("button",{onClick:()=>tt(!eK),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eK?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:ea("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:e5.length>0?`${eJ+1}/${e5.length}`:ea("common.noMatch")}),(0,n.jsx)("button",{onClick:tl,disabled:0===e5.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:ea("common.previous"),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"})})}),(0,n.jsx)("button",{onClick:to,disabled:0===e5.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:ea("common.next"),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"})})}),(0,n.jsx)("button",{onClick:()=>{e9(!1),e7("")},className:"p-1 rounded hover:bg-accent",title:ea("common.close"),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"})})})]}),O?(0,n.jsx)("div",{ref:eN,className:"flex-1 overflow-auto bg-secondary",children:(0,n.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,n.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tG},children:Array.from({length:ex},(e,t)=>(0,n.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,n.jsx)("div",{ref:ek,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tP,onKeyDown:tI,onPaste:tB,onCompositionStart:()=>{e$.current=!0},onCompositionEnd:()=>{e$.current=!1,tP()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,n.jsx)("div",{ref:eP,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${eH?" cmd-held-container":""}`,children:(0,n.jsx)("div",{style:{height:`${e3.getTotalSize()}px`,minWidth:"100%",width:t_?`calc(${tE+tM+10}ch + 13rem)`:`${tE+tM+10}ch`,position:"relative"},children:e3.getVirtualItems().map(e=>{let t=e4[e.index];if("code"!==t.type)return null;let s=t.lineIndex,o=s+1,l=eW[s]||I(e2[s]||""),a=tx(s,l,y),i=e8.has(o),c=e6.get(o),d=c?.[0],u=!!(eY&&o>=eY.range.start&&o<=eY.range.end),m=tg>=0?tp.current:null,h=!O&&R&&m===o?R[s]??null:null,x=t_?T[s]:void 0,f=t_&&s>0?T[s-1]:void 0,p=!!x&&(!f||f.hash!==x.hash),g=x?tU.get(x.author):void 0;return(0,n.jsx)(ej,{virtualKey:e.key,lineNum:o,highlightedHtml:a,hasComments:i,firstComment:d,lineCommentsCount:c?.length,isInRange:u,showLineNumbers:r,lineNumChars:tE,commentsEnabled:eZ,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:ti,onCmdClick:tL,onTokenHover:tS,onTokenHoverLeave:E,flashLine:e_,blameLine:x,showBlameInfo:p,blameAuthorColor:g,isBlameHovered:!!(x&&tq===x.author),onBlameClick:tQ,onBlameMouseEnter:tX,onBlameMouseLeave:tY,inlineBlameData:h,onInlineBlameClick:tQ,isCursorLine:q&&!O&&tw.state.cursorLine===s,cursorCol:q&&!O&&tw.state.cursorLine===s?tw.state.cursorCol:void 0},e.key)})})}),q&&(0,n.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tw.state.mode&&(0,n.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tw.state.mode&&(0,n.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tw.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:":"}),(0,n.jsx)("input",{ref:tv,value:tw.state.commandInput,onChange:e=>tw.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tw.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tw.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:"/"}),(0,n.jsx)("input",{ref:tj,value:tw.state.searchInput,onChange:e=>tw.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tw.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tw.state.keyBuffer&&"normal"===tw.state.mode&&(0,n.jsx)("span",{className:"ml-2 text-muted-foreground",children:tw.state.keyBuffer}),tw.state.isDirty&&("normal"===tw.state.mode||"command"===tw.state.mode)&&(0,n.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,n.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tw.state.cursorLine+1,":",tw.state.cursorCol+1]})]}),ez&&tb&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[!O&&(0,n.jsx)(A,{floatingToolbarRef:eD,bumpRef:eO,container:tb,onAddComment:tc,onSendToAI:td,onSearch:Z?tu:void 0,isChatLoading:eG?.isLoading}),!O&&eY&&(0,n.jsx)(S,{x:eY.x,y:eY.y,range:eY.range,codeContent:eY.codeContent,container:tb,onSubmit:tm,onClose:()=>tn(null)}),!O&&eQ&&(0,n.jsx)(L,{x:eQ.x,y:eQ.y,range:eQ.range,filePath:t,codeContent:eQ.codeContent,container:tb,onSubmit:th,onClose:()=>ts(null),isChatLoading:eG?.isLoading}),!O&&eX&&(0,n.jsx)(W,{x:eX.x,y:eX.y,comment:eX.comment,container:tb,onClose:()=>tr(null),onUpdateComment:e0,onDeleteComment:e1}),tK&&(0,n.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tK.x,window.innerWidth-450),top:Math.max(8,Math.min(tK.y,window.innerHeight-200))},children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tU.get(tK.line.author)?.border||"#666"},children:tK.line.hash}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground",children:tK.line.author}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:tK.line.authorEmail})]})]}),(0,n.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tK.line.message}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(et=tK.line.time,eo=Math.floor((es=Math.floor((en=Math.floor((er=Math.floor(Math.floor((Date.now()-1e3*et)/1e3)/60))/60))/24))/30),(el=Math.floor(es/365))>0?`${el}y ago`:eo>0?`${eo}mo ago`:es>0?`${es}d ago`:en>0?`${en}h ago`:er>0?`${er}m ago`:"just now")," \xb7 ",new Date(1e3*tK.line.time).toLocaleString(),(0,n.jsx)("span",{className:"ml-2 text-brand",children:ea("codeViewer.clickToViewDetails")})]})]})]}),tb)]})});var eP=r(26108),eI=r(95766),eB=r(94002);function eD({content:e,sourceFile:t}){let r,l,a,i,c,{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!0),[f,p]=(0,s.useState)(!1);(0,s.useEffect)(()=>{if(!t)return void x(!1);let e=!1;return fetch("/api/review").then(e=>e.ok?e.json():Promise.reject()).then(r=>{if(e)return;let n=r.reviews.find(e=>e.sourceFile===t);m(n?{id:n.id,active:n.active,updatedAt:n.updatedAt}:null)}).catch(()=>{}).finally(()=>{e||x(!1)}),()=>{e=!0}},[t]);let b=u?.active===!0,v=(0,s.useCallback)(async()=>{p(!0);try{let r=t.split("/").pop()||t,n=await fetch("/api/review",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:r,content:e,sourceFile:t})});if(!n.ok)throw Error("Failed");let s=(await n.json()).review;m({id:s.id,active:!0,updatedAt:s.updatedAt||s.createdAt});try{let e=await fetch("/api/review/share-info"),t=await e.json(),r=t.shareBase?`${t.shareBase}/review/${s.id}`:`${window.location.origin}/review/${s.id}`;await navigator.clipboard.writeText(r)}catch{}(0,g.oR)(s.existing?d("toast.reviewUpdated"):d("toast.reviewCreated"),"success")}catch{(0,g.oR)(d("toast.reviewCreateFailed"),"error")}finally{p(!1)}},[e,t]),j=(0,s.useCallback)(async()=>{if(u){p(!0);try{if(!(await fetch(`/api/review/${u.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({active:!1})})).ok)throw Error("Failed");m(e=>e?{...e,active:!1}:null),(0,g.oR)(d("toast.sharingClosed"),"success")}catch{(0,g.oR)(d("toast.sharingCloseFailed"),"error")}finally{p(!1)}}},[u]),y=(0,s.useCallback)(()=>{f||(b?j():v())},[f,b,v,j]),w=(0,s.useCallback)(()=>{u&&window.open(`${window.location.origin}/review/${u.id}`,"_blank")},[u]);return h?null:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:y,disabled:f,className:`relative inline-flex h-4 w-7 items-center rounded-full transition-colors ${f?"opacity-50 cursor-wait":"cursor-pointer"} ${b?"bg-green-500":"bg-muted-foreground/30"}`,title:b?d("review.closeSharing"):d("review.enableSharing"),children:(0,n.jsx)("span",{className:`inline-block h-3 w-3 rounded-full bg-white transition-transform ${b?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsx)("span",{className:`text-[11px] ${b?"text-green-600 dark:text-green-400":"text-muted-foreground"}`,children:b?d("review.sharing"):d("review.notShared")}),u&&u.updatedAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground",children:(l=String((r=new Date(u.updatedAt)).getMonth()+1).padStart(2,"0"),a=String(r.getDate()).padStart(2,"0"),i=String(r.getHours()).padStart(2,"0"),c=String(r.getMinutes()).padStart(2,"0"),`${l}-${a} ${i}:${c}`)}),(0,n.jsx)("button",{onClick:w,className:"text-[11px] text-brand hover:underline",children:d("review.view")})]})]})}function eF(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let r=t.closest("[data-source-start]");if(!r)return null;let n=r.getAttribute("data-source-start"),s=r.getAttribute("data-source-end");return n&&s?{start:parseInt(n,10),end:parseInt(s,10)}:null}let eO=[eI.W];function eA({content:e,filePath:t,cwd:r,onClose:l,sourceFile:i}){let c=i||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:d}=(0,o.Bd)(),u=(0,s.useRef)(null),x=(0,s.useRef)(null),g=(0,s.useRef)(()=>{}),b=j(),v=C(),{comments:y,addComment:w,updateComment:k,deleteComment:N,refresh:E}=p({cwd:r,filePath:t}),[M,T]=(0,s.useState)(!1),[R,$]=(0,s.useState)(null),[P,I]=(0,s.useState)(null),[B,D]=(0,s.useState)(null),F=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>T(!0))},[]),(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,x.current&&(x.current=null,g.current())},o=s=>{t=!1;let o=s.target;if(o.closest?.(".floating-toolbar")||o.closest?.("[data-comment-card]"))return;let l=Math.abs(s.clientX-r)>5||Math.abs(s.clientY-n)>5,a=window.getSelection();if(!a||a.isCollapsed){x.current=null,g.current();return}let i=a.toString();if(!i.trim()||!l){x.current=null,g.current();return}let c=a.getRangeAt(0);if(!e.contains(c.commonAncestorContainer))return;let d=eF(c.startContainer),u=eF(c.endContainer);if(d&&u){let e=Math.min(d.start,u.start),t=Math.max(d.end,u.end);x.current={x:s.clientX,y:s.clientY,range:{start:e,end:t},selectedText:i},g.current()}},l=()=>{if(t||!x.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(x.current=null,g.current())};return e.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",l),()=>{e.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",l)}},[]);let O=(0,s.useCallback)(()=>{let e=x.current;e&&($({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),x.current=null,g.current())},[]),z=(0,s.useCallback)(()=>{let e=x.current;e&&(I({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),x.current=null,g.current())},[]),H=(0,s.useCallback)(async e=>{R&&(await w(R.range.start,R.range.end,e),$(null))},[R,w]),_=(0,s.useCallback)(async e=>{if(P&&v)try{let n=await m(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});let o=Math.max(0,P.range.start-1),l=Math.min(F.length,P.range.end),a=F.slice(o,l).join("\n");s.push({filePath:t,startLine:P.range.start,endLine:P.range.end,codeContent:a});let i=f(s,e);v.sendMessage(i),await h(r),E(),I(null)}catch(e){console.error("Failed to send to AI:",e)}},[P,v,t,r,F,E]),U=(0,s.useMemo)(()=>{if(0===y.length)return[];let e=new Map;for(let t of y){let r=`${t.startLine}-${t.endLine}`;e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[y]),[q,V]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===U.length||!u.current)return void queueMicrotask(()=>V([]));let e=setTimeout(()=>{let e=u.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of U){let s=null,o=1/0;for(let e of r){let t=parseInt(e.getAttribute("data-source-start"),10),r=parseInt(e.getAttribute("data-source-end"),10);if(t<=n.startLine&&r>=n.endLine){let n=r-t;n<o&&(o=n,s=e)}}if(s){let r=e.getBoundingClientRect(),o=s.getBoundingClientRect();t.push({key:n.key,top:o.top-r.top+e.scrollTop,comments:n.comments})}}V(t)},100);return()=>clearTimeout(e)},[U,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(P){I(null),e.stopPropagation();return}if(R){$(null),e.stopPropagation();return}if(x.current){x.current=null,g.current(),e.stopPropagation();return}if(B){D(null),e.stopPropagation();return}l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[P,R,B,l]),(0,n.jsxs)(n.Fragment,{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 truncate",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(eD,{content:e,sourceFile:c}),(0,n.jsx)("button",{onClick:l,className:"p-1 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.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(eB.l,{content:e,containerRef:u}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:u,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(eP.T,{content:e,rehypePlugins:eO})}),q.map(({key:e,top:t,comments:r})=>(0,n.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),D({comment:r[0],x:e.clientX,y:e.clientY})},children:(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:r.length})},e))]})]}),M&&b&&(0,a.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(A,{floatingToolbarRef:x,bumpRef:g,container:b,onAddComment:O,onSendToAI:z,isChatLoading:v?.isLoading}),R&&(0,n.jsx)(S,{x:R.x,y:R.y,range:R.range,codeContent:R.codeContent,container:b,onSubmit:H,onClose:()=>$(null)}),P&&(0,n.jsx)(L,{x:P.x,y:P.y,range:P.range,filePath:t,codeContent:P.codeContent,container:b,onSubmit:_,onClose:()=>I(null),isChatLoading:v?.isLoading}),B&&(0,n.jsx)(W,{x:B.x,y:B.y,comment:B.comment,container:b,onClose:()=>D(null),onUpdateComment:k,onDeleteComment:N})]}),b)]})}function eW({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),l=o>=0?e.slice(0,o+1):"",a=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],l="",a=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==a&&l&&(o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-${s}`):(0,n.jsx)("span",{children:l},`${t}-${s}`)),l=""),a=c,l+=e[s]}return l&&o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-end`):(0,n.jsx)("span",{children:l},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[l&&i(l,0,"text-muted-foreground"),i(a,l.length,"text-foreground")]})}function ez({files:e,fileIndex:t,recentFiles:r,onSelectFile:l,onClose:i}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(0),x=(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(!d.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,l=0,a=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),a===i-1&&(l+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(l+=10),i>e.lastIndexOf("/")&&(l+=3),e[i]===t[o]&&(l+=1),a=i,o++);return o<n.length?null:(l-=.1*e.length,{path:e,score:l,matchedIndices:s})}(t,d.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[d,p,r]),b=(0,s.useCallback)(e=>{u(e),h(0)},[]);(0,s.useEffect)(()=>{x.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[m];e?.scrollIntoView({block:"nearest"})}},[m]);let v=(0,s.useCallback)(e=>{l(e),i()},[l,i]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),h(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),h(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[m]&&v(g[m].path);break;case"Escape":e.preventDefault(),i()}},[g,m,v,i]);return(0,a.createPortal)((0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:i,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:x,value:d,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:c("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:c("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===m?"bg-brand/15 text-foreground":"hover:bg-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(V,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(eW,{path:e.path,matchedIndices:e.matchedIndices}),!d.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:c("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:"↑↓"})," ",c("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"})," ",c("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"})," ",c("quickFileOpen.closeHint")]})]})]})}),document.body)}var eH=r(22552);function e_(){let[e,t]=(0,s.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,s.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}function eU({branches:e,selectedBranch:t,onSelect:r,isLoading:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),[d,u]=(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)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{i&&h.current&&h.current.focus()},[i]);let x=e?.local.filter(e=>e.toLowerCase().includes(d.toLowerCase()))||[],f=e?.remote.filter(e=>e.toLowerCase().includes(d.toLowerCase()))||[],p=e=>{r(e),c(!1),u("")};return(0,n.jsxs)("div",{className:"relative",ref:m,children:[(0,n.jsxs)("button",{onClick:()=>c(!i),disabled:l,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||a("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",a("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${i?"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"})})]}),i&&(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:d,onChange:e=>u(e.target.value),placeholder:a("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:[x.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:a("git.localBranches")}),x.map(r=>(0,n.jsxs)("div",{onClick:()=>p(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:a("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))]}),f.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:a("git.remoteBranches")}),f.map(e=>(0,n.jsxs)("div",{onClick:()=>p(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===x.length&&0===f.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:a("git.noMatchingBranches")})]})]})]})}function eq(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}function eV(e){return e.replace(/^\([^)]+\)\s*/,"")}let eK=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:l,container:a,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},m){let{t:h}=(0,o.Bd)(),x=(0,s.useRef)(null);(0,s.useImperativeHandle)(m,()=>x.current,[]);let f=a.getBoundingClientRect(),p=r-f.left,g=l-f.top,b=(0,s.useMemo)(()=>eV(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,l=0,a=/\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=a.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},l++));let a=t[0];/^["']/.test(a)?s.push((0,n.jsx)("span",{className:"text-green-400",children:a},l++)):/^\d+$/.test(a)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:a},l++)):r.test(a)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:a},l++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:a},l++)),o=t.index+a.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},l++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!x.current)return;let e=x.current,t=a.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=l-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,l,a]),(0,n.jsxs)("div",{ref:x,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:h("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=eV(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:h("hoverTooltip.search")})]})]})]})});var eJ=r(33210);function eX({references:e,loading:t,onSelect:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(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=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await $();if(t!==l.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let l=P(r.file);if("text"!==l)try{let e=n.codeToTokens(r.lineText,{lang:l,theme:s}),a=B(e.tokens[0]||[]);a&&o.set(t,a)}catch{}}t===l.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:[a("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(eJ.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:a("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("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 eY({results:e,loading:t,totalMatches:r,onSelect:l,onClose:a}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(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=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await $(),o=new Map;for(let t of e){let e=P(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let l=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),a=B(t.tokens[0]||[]);a&&o.set(l,a)}catch{}}}t===l.current&&r(o)})()},[e,n]),t}(e);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:[i("searchResults.title")," ",!t&&i("searchResults.nMatches",{count:r})]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(eJ.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:i("searchResults.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.noResults")}):e.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=c.get(s);return(0,n.jsxs)("button",{onClick:()=>l(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))})]})}let eQ=["agent","explorer","console"],eG={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},eZ=(0,s.createContext)(null);function e0(){let e=(0,s.useContext)(eZ);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function e1({activeView:e,onViewChange:t,children:r}){let o=(0,s.useRef)(null),l=(0,s.useRef)(!1),a=(0,s.useRef)(0),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(!1),m=eQ.indexOf(e),h=eQ.length-1;(0,s.useEffect)(()=>{a.current=0,queueMicrotask(()=>c(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(),l.current&&(l.current=!1);let n=window.innerWidth,s=a.current-6*e.deltaX;!(m>0)&&s>0&&(s=0),!(m<h)&&s<0&&(s=0),a.current=s=Math.max(-n,Math.min(n,s)),c(s),u(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{let e=a.current,r=.12*n;u(!1),l.current=!0;let s=m;e<-r&&m<h?s=m+1:e>r&&m>0&&(s=m-1),a.current=0,c(0),s!==m&&t(eQ[s]),setTimeout(()=>{l.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[m,h,t]);let[x,f]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>f(!0))},[]);let p={activeView:e,onViewChange:t,dragOffset:(()=>{if(!x)return 0;let e=window.innerWidth;return e?i/e:0})(),isDragging:x&&d};return(0,n.jsx)(eZ.Provider,{value:p,children:r})}function e2({children:e}){let t,r,{activeView:o,dragOffset:l,isDragging:a}=e0(),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=eQ.indexOf(o),u=eQ.length;return(0,s.useEffect)(()=>{let e=i.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:i,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:c,className:a?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*eQ.length}%`,transform:(t=l/u*100,r=-(100/u*d)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function e5(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:o}=e0(),l=(0,s.useRef)(null),a=(0,s.useRef)([]),[i,c]=(0,s.useState)({left:0,width:0}),d=eQ.indexOf(e),u=()=>{if(!l.current||0===a.current.length)return{left:0,width:0};let e=l.current.getBoundingClientRect(),t=a.current.filter(Boolean);if(t.length!==eQ.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(eQ.length-1,d-n)),o=Math.floor(s),i=Math.ceil(s),c=s-o,u=t[o],m=t[i];if(!u||!m)return{left:0,width:0};let h=u.getBoundingClientRect(),x=m.getBoundingClientRect();return{left:h.left+(x.left-h.left)*c-e.left,width:h.width+(x.width-h.width)*c}};(0,s.useEffect)(()=>{queueMicrotask(()=>c(u()))},[d,r]),(0,s.useEffect)(()=>{let e=()=>{c(u())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[d,r]);let m=Number.isFinite(r)?r:0,h=Math.round(Math.max(0,Math.min(eQ.length-1,d-m)));return(0,n.jsxs)("div",{ref:l,className:"relative flex gap-4",children:[eQ.map((e,r)=>(0,n.jsx)("button",{ref:e=>{a.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${h===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:eG[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${o?"":"transition-all duration-100 ease-out"}`,style:{left:i.left,width:i.width}})]})}function e4({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:l,initialSearchQuery:i,searchQueryTrigger:d}){var u,m;let h,x,f,p,b,j,y,{t:w}=(0,o.Bd)(),{activeView:k}=e0(),[N,C]=(0,s.useState)(r),S=(0,s.useRef)(null),L=(0,s.useRef)(!1),[E,M]=(0,s.useState)(null),[T,R]=(0,s.useState)(null),[$,P]=(0,s.useState)(!1),[I,B]=(0,s.useState)(null),D=(0,s.useRef)(1),F=(0,s.useRef)(null),[O,A]=(0,s.useState)(null),W=(0,s.useRef)(null),[z,_]=(0,s.useState)({isDirty:!1,isSaving:!1}),[U,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)(!1),[J,ee]=(0,s.useState)(null),et=(0,s.useRef)(null),er=eu(et),en=(0,s.useRef)(null),es=eu(en),eo=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);try{let r=await fetch("/api/lsp/definition",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})});return(await r.json()).definitions||[]}catch(e){return console.error("[useLSP] definition error:",e),[]}finally{r(!1)}},[e]),loading:t}}(t),el=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),l=(0,s.useRef)(0),a=(0,s.useRef)(!1),i=(0,s.useRef)(null),c=(0,s.useRef)({x:0,y:0});(0,s.useEffect)(()=>{let e=e=>{c.current.x=e.clientX,c.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let d=(0,s.useRef)(!1),u=(0,s.useRef)(null),m=(0,s.useCallback)(()=>{let e=i.current;e&&d.current&&(e.style.pointerEvents="none"),d.current=!1,u.current&&(i.current?.removeEventListener("mouseleave",u.current),u.current=null)},[]),h=(0,s.useCallback)(()=>{let e=i.current;if(!e||d.current)return;d.current=!0,a.current=!0,e.style.pointerEvents="auto";let t=()=>{a.current=!1,m(),l.current++,r(null)};u.current=t,e.addEventListener("mouseleave",t)},[m]),x=(0,s.useCallback)((t,s,a,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let c=++l.current;n.current=setTimeout(async()=>{try{let n=await fetch("/api/lsp/hover",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:s,column:a})}),o=await n.json();if(c!==l.current)return;o.hover&&o.hover.displayString&&r({...o.hover,x:i.x,y:i.y,filePath:t,line:s,column:a})}catch{}},300)},[e]),f=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),l.current++,o.current=setTimeout(function(){if(a.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=c.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void h()}r(null)},150)},[h]),p=(0,s.useCallback)(()=>{a.current=!0,o.current&&clearTimeout(o.current)},[]),g=(0,s.useCallback)(()=>{a.current=!1,l.current++,r(null)},[]),b=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),a.current=!1,m(),l.current++,r(null)},[m]);return(0,s.useEffect)(()=>{t||m()},[t,m]),{hoverInfo:t,onTokenMouseEnter:x,onTokenMouseLeave:f,onCardMouseEnter:p,onCardMouseLeave:g,clearHover:b,tooltipElRef:i}}(t),ea=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(!1);return{references:t,loading:n,visible:l,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),a(!0);try{let o=await fetch("/api/lsp/references",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,filePath:t,line:n,column:s})}),l=await o.json();r(l.references||[])}catch(e){console.error("[useLSP] references error:",e),r([])}finally{o(!1)}},[e]),closeReferences:(0,s.useCallback)(()=>{a(!1),r([])},[])}}(t),ei=(h=(0,s.useRef)([]),x=(0,s.useRef)([]),f=(0,s.useCallback)(e=>{h.current.push(e),h.current.length>50&&(h.current=h.current.slice(-50)),x.current=[]},[]),p=(0,s.useCallback)(e=>{if(0===h.current.length)return null;let t=h.current.pop();return x.current.push(e),x.current.length>50&&(x.current=x.current.slice(-50)),t},[]),b=(0,s.useCallback)(e=>{if(0===x.current.length)return null;let t=x.current.pop();return h.current.push(e),h.current.length>50&&(h.current=h.current.slice(-50)),t},[]),{push:f,goBack:p,goForward:b,canGoBack:(0,s.useCallback)(()=>h.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),ed=e_(),ex=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(new Set),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(new Set),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(null),T=(0,s.useRef)(null),[R,$]=(0,s.useState)(!1),[P,I]=(0,s.useState)(null),[B,D]=(0,s.useState)("center"),[F,O]=(0,s.useState)(null),[A,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[_,U]=(0,s.useState)([]),[q,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(null),[X,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(!1),[Z,ee]=(0,s.useState)(!1),et=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),er=(0,s.useMemo)(()=>eN(et),[et]),en=(0,s.useMemo)(()=>new Set(eC(er)),[er]),es=(0,s.useMemo)(()=>b?n?function(e,t,r=!1){let n=new Set;if(!t)return n;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let o=e[t].toLowerCase();if(r?o===s:o.includes(s)){for(let t=0;t<=e.length-1;t++)n.add(e.slice(0,t+1).join("/"));break}}}return n}(n,b,j):function(e,t,r=!1){let n=new Set;if(!t)return n;let s=t.toLowerCase(),o=e=>{if(n.add(e.path),e.children)for(let t of e.children)o(t)},l=(e,t)=>{let a=e.name.toLowerCase(),i=r?a===s:a.includes(s);if(i&&e.children)return o(e),t.forEach(e=>n.add(e)),!0;let c=!1;if(e.children)for(let r of e.children)l(r,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(n.add(e.path),t.forEach(e=>n.add(e)),!0)};for(let t of e)l(t,[]);return n}(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!es||0===es.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of es)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&es.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[es,t,n]);let eo=p??x,el=(0,s.useRef)(null),ea=(0,s.useCallback)(t=>{el.current&&clearTimeout(el.current),el.current=setTimeout(async()=>{try{await fetch("/api/files/expanded",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,paths:Array.from(t)})})}catch(e){console.error("Error saving expanded paths:",e)}},500)},[e]),ei=(0,s.useCallback)(async()=>{C(!0),M(null);try{let t=await fetch(`/api/files/init?cwd=${encodeURIComponent(e)}`),n=await t.json();n.error?M(n.error):(r(n.files||[]),n.expandedPaths&&Array.isArray(n.expandedPaths)&&f(new Set(n.expandedPaths)))}catch(e){console.error("Error loading files:",e),M("Failed to load files")}finally{C(!1)}},[e]),ec=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/index?cwd=${encodeURIComponent(e)}`),r=await t.json();r.paths&&o(r.paths)}catch(e){console.error("Error loading file index:",e)}},[e]),ed=(0,s.useCallback)(async t=>{a(e=>new Set([...e,t]));try{let n=await fetch(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),s=await n.json();s.children&&r(e=>{if(!t){let t=new Map(e.map(e=>[e.path,e]));return s.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let r=structuredClone(e),n=ek(r,t);return n&&(n.children=s.children),r})}catch(e){console.error("Error loading directory:",e)}finally{a(e=>{let r=new Set(e);return r.delete(t),r})}},[e]),eu=(0,s.useRef)(l);eu.current=l,(0,s.useEffect)(()=>{for(let e of p??x){let r=ek(t,e);r&&r.isDirectory&&!r.children&&!eu.current.has(e)&&ed(e)}},[t,x,p,ed]);let em=(0,s.useCallback)(async()=>{try{let t=await fetch(`/api/files/recent?cwd=${encodeURIComponent(e)}`),r=await t.json();c(r.files||[])}catch(e){console.error("Error loading recent files:",e)}},[e]),eh=(0,s.useCallback)(async t=>{c(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)});try{await fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t})})}catch(e){console.error("Error adding to recent files:",e)}},[e]),ex=(0,s.useCallback)((t,r,n,s)=>{c(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),fetch("/api/files/recent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,file:t,scrollLine:r,cursorLine:n,cursorCol:s})}).catch(()=>{})},[e]),ef=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),ep=(0,s.useCallback)(async t=>{let r=t||d;if(r){V(!0),J(null);try{let t=await fetch(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(r)}`),n=await t.json();n.error?J(n.error):U(n.blame||[])}catch(e){console.error("Error loading blame:",e),J("Failed to load blame info")}finally{V(!1)}}},[e,d]),eg=(0,s.useCallback)(async t=>{L(!0),h(null),H(!1),U([]),J(null),Y(null);try{let r=await fetch(`/api/files/read?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),n=await r.json();h(n),eh(t),ep(t)}catch(e){console.error("Error loading file content:",e),h({type:"error",message:"Failed to load file"})}finally{L(!1)}},[e,eh,ep]),eb=(0,s.useCallback)(()=>{z?H(!1):(H(!0),0===_.length&&ep())},[z,_.length,ep]),ev=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),I(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(I(t.scrollLine),D("start"),O(t.cursorLine??null),W(t.cursorCol??null)):(D("center"),O(null),W(null))}else D("center"),O(null),W(null);eg(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("/"));f(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ea(r),n?r:t})}},[eg,ea,i]),ej=(0,s.useCallback)(e=>{if(p)g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!x.has(e);if(f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ea(r),r}),r){let r=ek(t,e);r&&r.isDirectory&&!r.children&&ed(e)}}},[p,ea,x,t,ed]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:l,expandedPaths:x,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:eo,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:y,matchedPaths:es,creatingItem:w,setCreatingItem:k,isLoadingFiles:N,fileError:E,searchInputRef:T,shouldScrollToSelected:R,setShouldScrollToSelected:$,targetLineNumber:P,setTargetLineNumber:I,targetScrollAlign:B,setTargetScrollAlign:D,initialCursorLine:F,initialCursorCol:A,setInitialCursorLine:O,setInitialCursorCol:W,selectedPath:d,setSelectedPath:u,fileContent:m,setFileContent:h,isLoadingContent:S,recentFiles:i,recentFilePaths:et,setRecentFiles:c,recentFilesTree:er,recentTreeDirPaths:en,showBlame:z,setShowBlame:H,blameLines:_,isLoadingBlame:q,blameError:K,blameSelectedCommit:X,setBlameSelectedCommit:Y,showMarkdownPreview:Q,setShowMarkdownPreview:G,showEditor:Z,setShowEditor:ee,saveExpandedPaths:ea,loadFiles:ei,loadFileIndex:ec,loadDirectory:ed,loadRecentFiles:em,addToRecentFiles:eh,updateRecentFilePosition:ex,getRecentFilePosition:ef,loadFileContent:eg,loadBlame:ep,handleToggleBlame:eb,handleSelectFile:ev,handleToggle:ej}}({cwd:t});u=ex.selectedPath,j=(0,s.useRef)(null),(0,s.useEffect)(()=>{!u||u===j.current||eq(u)&&(j.current=u,fetch("/api/lsp/warmup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,filePath:u})}).catch(()=>{}))},[t,u]);let ef=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,l]=(0,s.useState)([]),[a,i]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(new Set),[x,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){l([]),g(null);return}if(n.length<2)return void u(c.A.t("fileBrowser.searchMinChars"));i(!0),u(null);try{let n=new URLSearchParams({cwd:e,q:r,caseSensitive:String(x.caseSensitive),wholeWord:String(x.wholeWord),regex:String(x.regex),fileType:x.fileType}),s=await fetch(`/api/files/search?${n}`),o=await s.json();if(o.error)throw Error(o.error);l(o.results),g({totalFiles:o.totalFiles,totalMatches:o.totalMatches,truncated:o.truncated});let a=new Set(o.results.map(e=>e.path));h(a),o.results.length>0&&t?.()}catch(e){u(e instanceof Error?e.message:"Search failed"),l([])}finally{i(!1)}},[e,x,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:a,searchError:d,searchExpandedPaths:m,searchOptions:x,setSearchOptions:f,searchStats:p,contentSearchInputRef:b,performContentSearch:v,handleSearchToggle:(0,s.useCallback)(e=>{h(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>q(!0)}),eg=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)(null),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)([]),[y,w]=(0,s.useState)([]),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{l(!0),i(null);try{let t=`/api/git/status?cwd=${encodeURIComponent(e)}`,r=await fetch(t);if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to fetch git status")}let s=await r.json();n(s);let o=Y(s.staged),l=Y(s.unstaged);j(o),w(l);let a=new Set([...Q(o),...Q(l)]);b(a)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1)}},[e]),E=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),M=(0,s.useCallback)((e,r)=>{u({file:e,type:r}),t(e.path)},[t]),T=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to stage file");await L(),(0,g.oR)(c.A.t("toast.staged"),"success")}catch(e){console.error("Error staging file:",e),(0,g.oR)(c.A.t("toast.stageFailed"),"error")}},[e,L]),R=(0,s.useCallback)(async t=>{try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t]})})).ok)throw Error("Failed to unstage file");await L(),(0,g.oR)(c.A.t("toast.unstaged"),"success")}catch(e){console.error("Error unstaging file:",e),(0,g.oR)(c.A.t("toast.unstageFailed"),"error")}},[e,L]),$=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to stage files");await L(),(0,g.oR)(c.A.t("toast.stagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error staging files:",e),(0,g.oR)(c.A.t("toast.stageFailed"),"error")}},[e,L]),P=(0,s.useCallback)(async t=>{if(0!==t.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t})})).ok)throw Error("Failed to unstage files");await L(),(0,g.oR)(c.A.t("toast.unstagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error unstaging files:",e),(0,g.oR)(c.A.t("toast.unstageFailed"),"error")}},[e,L]),I=(0,s.useCallback)(async t=>{if(0!==t.length)try{let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path);if(r.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r,isUntracked:!0})})).ok)throw Error("Failed to discard untracked files");if(n.length>0&&!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})})).ok)throw Error("Failed to discard tracked files");await L(),(0,g.oR)(c.A.t("toast.discardedNFiles",{count:t.length}),"success")}catch(e){console.error("Error discarding files:",e),(0,g.oR)(c.A.t("toast.discardFailed"),"error")}},[e,L]),B=(0,s.useCallback)(async()=>{if(r?.unstaged.length)try{if(!(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.unstaged.map(e=>e.path)})})).ok)throw Error("Failed to stage all files");await L(),(0,g.oR)(c.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error staging all files:",e),(0,g.oR)(c.A.t("toast.stageFailed"),"error")}},[e,r,L]),D=(0,s.useCallback)(async()=>{if(r?.staged.length)try{if(!(await fetch("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:r.staged.map(e=>e.path)})})).ok)throw Error("Failed to unstage all files");await L(),(0,g.oR)(c.A.t("toast.unstagedNFiles",{count:r.staged.length}),"success")}catch(e){console.error("Error unstaging all files:",e),(0,g.oR)(c.A.t("toast.unstageFailed"),"error")}},[e,r,L]),F=(0,s.useCallback)(async t=>{try{let r="untracked"===t.status;if(!(await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:[t.path],isUntracked:r})})).ok)throw Error("Failed to discard file");await L(),(0,g.oR)(r?c.A.t("toast.deletedFile"):c.A.t("toast.discardedChanges"),"success")}catch(e){console.error("Error discarding file:",e),(0,g.oR)(c.A.t("toast.discardFailed"),"error")}},[e,L]),O=(0,s.useCallback)(async()=>{if(r?.unstaged.length&&await (0,g.lJ)(c.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))try{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);n.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:n,isUntracked:!1})}),t.length>0&&await fetch("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,files:t,isUntracked:!0})}),await L(),(0,g.oR)(c.A.t("toast.discardedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error discarding all:",e),(0,g.oR)(c.A.t("toast.discardFailed"),"error")}},[e,r,L]);return(0,s.useEffect)(()=>{d?(async()=>{f(!0);try{let t=new URLSearchParams({file:d.file.path,type:d.type});t.set("cwd",e);let r=await fetch(`/api/git/diff?${t}`);if(!r.ok)throw Error("Failed to fetch diff");let n=await r.json();h(n)}catch(e){console.error("Error fetching diff:",e)}finally{f(!1)}})():h(null)},[d,e,C]),{status:r,setStatus:n,statusLoading:o,statusError:a,statusSelectedFile:d,statusDiff:m,statusDiffLoading:x,statusExpandedPaths:p,setStatusExpandedPaths:b,stagedTree:v,setStagedTree:j,unstagedTree:y,setUnstagedTree:w,showStatusDiffPreview:k,setShowStatusDiffPreview:N,fetchStatus:L,handleStatusToggle:E,handleStatusFileSelect:M,handleStage:T,handleUnstage:R,handleStageFiles:$,handleUnstageFiles:P,handleDiscardFiles:I,handleStageAll:B,handleUnstageAll:D,handleDiscardFile:F,handleDiscardAll:O,refreshDiff:(0,s.useCallback)(()=>S(e=>e+1),[])}}({cwd:t,addToRecentFiles:ex.addToRecentFiles}),eb=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(""),[a,i]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)([]),[x,f]=(0,s.useState)([]),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(null),[j,y]=(0,s.useState)(null),[w,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(!0),[T,R]=(0,s.useState)(!1),[$,P]=(0,s.useState)(!1),[I,B]=(0,s.useState)(null),D=(0,s.useRef)(null),[F,O]=(0,s.useState)(null),[A,W]=(0,s.useState)(!1),[z,H]=(0,s.useState)(""),[_,U]=(0,s.useState)(""),[q,V]=(0,s.useState)([]),[K,J]=(0,s.useState)([]),[X,G]=(0,s.useState)(new Set),[Z,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(!1),[eo,el]=(0,s.useState)(!1),ea=(0,s.useCallback)(()=>{k(!0),B(null),fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{e.error?(B("Failed to get branches"===e.error?c.A.t("git.notGitRepo"):e.error),n(null)):e.local&&e.current?(n(e),l(e.current),e.upstream&&U(e.upstream)):(B(c.A.t("git.cannotGetBranches")),n(null))}).catch(e=>{console.error(e),B(c.A.t("git.getBranchesFailed")),n(null)}).finally(()=>k(!1))},[e]),ei=(0,s.useCallback)(t=>{C(!0),u(null),h([]),f([]),v(null),y(null),M(!0),fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=50`).then(e=>e.json()).then(e=>{let t=e.commits||[];i(t),M(t.length>=50)}).catch(console.error).finally(()=>C(!1))},[e]),ec=(0,s.useCallback)(()=>{if(S||!E||!o)return;L(!0);let t=a.length;fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(o)}&limit=50&offset=${t}`).then(e=>e.json()).then(e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),M(t.length>=50)}).catch(console.error).finally(()=>L(!1))},[e,o,a.length,S,E]),ed=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ec()},[ec]),eu=(0,s.useCallback)(t=>{u(t),v(null),y(null),R(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${t.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];h(t);let r=Y(t);f(r),g(new Set(Q(r)))}).catch(console.error).finally(()=>R(!1))},[e]),em=(0,s.useCallback)(r=>{d&&(v(r),t(r.path),P(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${d.hash}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>y(e)).catch(console.error).finally(()=>P(!1)))},[e,d,t]),eh=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ex=(0,s.useCallback)(t=>{es(!0),ee(null),er(null),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{let t=e.files||[];V(t);let r=Y(t);J(r),G(new Set(Q(r)))}).catch(console.error).finally(()=>es(!1))},[e]),ef=(0,s.useCallback)(r=>{ee(r),t(r.path),el(!0),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(o)}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>er(e)).catch(console.error).finally(()=>el(!1))},[e,o,t]),ep=(0,s.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eg=(0,s.useCallback)(e=>{if(W(e),e){H(o);let e=_||"origin/main";l(e),ex(e)}else V([]),J([]),ee(null),er(null),z&&(l(z),ei(z))},[o,z,_,ex,ei]);return{branches:r,selectedBranch:o,setSelectedBranch:l,commits:a,setCommits:i,selectedCommit:d,setSelectedCommit:u,historyFiles:m,historyFileTree:x,historyExpandedPaths:p,historySelectedFile:b,historyFileDiff:j,isLoadingBranches:w,isLoadingCommits:N,isLoadingMore:S,hasMoreCommits:E,setHasMoreCommits:M,isLoadingHistoryFiles:T,isLoadingHistoryDiff:$,historyError:I,commitListRef:D,tooltipPos:F,loadBranches:ea,loadCommits:ei,loadMoreCommits:ec,handleCommitListScroll:ed,handleSelectCommit:eu,handleSelectHistoryFile:em,handleHistoryToggle:eh,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{O({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{O(null)},[]),compareMode:A,toggleCompareMode:eg,compareFiles:q,compareFileTree:K,compareExpandedPaths:X,compareSelectedFile:Z,compareFileDiff:et,isLoadingCompareFiles:en,isLoadingCompareDiff:eo,handleSelectCompareFile:ef,handleCompareToggle:ep,loadCompareFiles:ex}}({cwd:t,addToRecentFiles:ex.addToRecentFiles}),ev=(0,s.useCallback)(e=>{ex.setFileContent(t=>t?.type==="text"?{...t,content:e}:t)},[ex]),ej=(0,s.useCallback)(e=>{ex.setShowEditor(!0)},[ex]),ey=(0,s.useCallback)(async()=>{if(ex.fileContent&&"text"===ex.fileContent.type&&ex.fileContent.content)try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:ex.selectedPath,content:ex.fileContent.content})});if(!e.ok)throw Error("Failed to save file");let r=await e.json();r.mtime&&ex.setFileContent(e=>e?.type==="text"?{...e,mtime:r.mtime}:e),(0,g.oR)(w("toast.savedSuccess"),"success")}catch{(0,g.oR)(w("toast.saveFailed"),"error")}},[t,ex]),ew=(0,s.useCallback)(()=>{if(!ex.selectedPath)return;let e=D.current,t=F.current;e>0&&ex.updateRecentFilePosition(ex.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ex]),eE=(0,s.useCallback)((e,t)=>{e!==ex.selectedPath&&ew(),ex.handleSelectFile(e,t)},[ex,ew]),eM=(0,s.useMemo)(()=>{let e=ef.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=eN(r),s=new Set(eC(n));return{files:n,expandDirs:s,matchMap:t}},[ef.contentSearchResults]),[eT,eR]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{eR(eM.expandDirs)},[eM.expandDirs]);let eP=(0,s.useCallback)(e=>{eR(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eI=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eM.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eM.matchMap]),eB=U&&ef.contentSearchResults.length>0,eD=!!ex.selectedPath&&null!==eq(ex.selectedPath),eF=(0,s.useCallback)(async(e,r)=>{if(!ex.selectedPath||!eD)return;let n=await eo.goToDefinition(ex.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",l=s.file.startsWith(o)?s.file.slice(o.length):s.file;ei.push({filePath:ex.selectedPath,lineNumber:D.current}),l===ex.selectedPath?ex.setTargetLineNumber(s.line):eE(l,s.line)},[ex,t,eD,eo,ei]),eO=(0,s.useCallback)((e,t,r)=>{ex.selectedPath&&eD&&el.onTokenMouseEnter(ex.selectedPath,e,t,r)},[ex.selectedPath,eD,el]),eW=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ex.selectedPath&&ei.push({filePath:ex.selectedPath,lineNumber:D.current}),n===ex.selectedPath?ex.setTargetLineNumber(e.line):eE(n,e.line)},[ex,t,ei]),eV=(0,s.useMemo)(()=>{if(!eg.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 eg.status.staged)e.set(r.path,t(r.status));for(let r of eg.status.unstaged)e.set(r.path,t(r.status));return e},[eg.status]);(0,s.useEffect)(()=>{M(S.current)},[]),(0,s.useEffect)(()=>{let e=S.current;if(!e)return;let t=t=>{let r=t;for(;r&&r!==e;){if(r.dataset.tooltip)return r.dataset.tooltip;r=r.parentElement}return null},r=e=>{let r=t(e.target);r?B({text:r,x:e.clientX,y:e.clientY}):B(null)},n=e=>{B(r=>{if(!r)return null;let n=t(e.target);return n?{text:n,x:e.clientX,y:e.clientY}:null})},s=r=>{let n=r.relatedTarget;n&&e.contains(n)&&t(n)||B(null)};return e.addEventListener("mouseover",r),e.addEventListener("mousemove",n),e.addEventListener("mouseout",s),()=>{e.removeEventListener("mouseover",r),e.removeEventListener("mousemove",n),e.removeEventListener("mouseout",s)}},[]),(0,s.useEffect)(()=>{C(r)},[r,l]),(0,s.useEffect)(()=>{i&&(C("search"),ef.setContentSearchQuery(i),ef.performContentSearch(i))},[d]);let eJ=(0,s.useCallback)(e=>{C(e),ex.setBlameSelectedCommit(null),"history"===e&&eb.selectedBranch&&eb.loadCommits(eb.selectedBranch)},[ex,eb.selectedBranch,eb.loadCommits]),eQ=(0,s.useCallback)(()=>{if(!ex.selectedPath)return;let e={filePath:ex.selectedPath,lineNumber:D.current},t=ei.goBack(e);t&&(t.filePath===ex.selectedPath?ex.setTargetLineNumber(t.lineNumber):eE(t.filePath,t.lineNumber))},[ex,ei]),eG=(0,s.useCallback)(()=>{if(!ex.selectedPath)return;let e={filePath:ex.selectedPath,lineNumber:D.current},t=ei.goForward(e);t&&(t.filePath===ex.selectedPath?ex.setTargetLineNumber(t.lineNumber):eE(t.filePath,t.lineNumber))},[ex,ei]),eZ=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;try{await fetch("/api/files/clipboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})}),(0,g.oR)(w("toast.copiedName",{name:r}),"success")}catch{(0,g.oR)(w("toast.copyFailed"),"error")}},[t]),e1=(0,s.useCallback)(async e=>{try{let r=await fetch("/api/files/clipboard"),n=await r.json();if(!n.path)return void(0,g.oR)(w("toast.noFileToPaste"),"info");let s=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,targetDir:e,sourceAbsPath:n.path})}),o=await s.json();s.ok?((0,g.oR)(w("toast.pastedFile",{name:o.newName}),"success"),ex.loadDirectory(e),ex.loadFileIndex()):(0,g.oR)(o.error||w("toast.pasteFailed"),"error")}catch{(0,g.oR)(w("toast.pasteFailed"),"error")}},[t,ex]),e2=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===k;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eG():eQ();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),P(e=>!e);return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===N||"recent"===N)&&ex.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eZ(ex.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===N||"recent"===N)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),e1(function(e,t){if(!e)return"";let r=ek(t,e);if(r?.isDirectory)return e;let n=e.split("/");return n.pop(),n.join("/")}(ex.selectedPath,ex.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(J){t.preventDefault(),es.open();return}if(V&&ex.selectedPath?.endsWith(".json")){t.preventDefault(),er.open();return}}if(r&&"Escape"===t.key){if($)return void P(!1);if(es.isVisible)return void es.close();if(er.isVisible)return void er.close();if(J)return void ee(null);let t=Date.now();if(t-e2.current<3e3)return;e2.current=t,ea.visible?ea.closeReferences():U?q(!1):ex.blameSelectedCommit?ex.setBlameSelectedCommit(null):ex.showBlame?ex.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ex.showBlame,ex.blameSelectedCommit,ex,$,ea.visible,ea.closeReferences,U,eQ,eG,V,er,J,es,N,eZ,e1,k]),(0,s.useEffect)(()=>{ex.loadFiles(),ex.loadFileIndex(),ex.loadRecentFiles(),eg.fetchStatus(),eb.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{eg.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[eg.fetchStatus]);let e5=(0,s.useRef)(ed);(0,s.useEffect)(()=>{ed&&!e5.current&&(ex.loadFiles(),ex.loadFileIndex(),ex.loadRecentFiles(),eg.fetchStatus(),eb.loadBranches()),e5.current=ed},[ed]),(0,s.useEffect)(()=>{eb.selectedBranch&&eb.loadCommits(eb.selectedBranch)},[eb.selectedBranch,eb.loadCommits]);let e4=(0,s.useRef)(N);(0,s.useEffect)(()=>{let e=e4.current;if(e4.current=N,("tree"===N||"recent"===N)&&ex.recentFiles.length>0){let t=ex.recentFiles[0].path;ex.selectedPath&&("status"!==e&&"history"!==e||ex.selectedPath===t)||(ex.setShouldScrollToSelected(!0),eE(t))}},[N,ex.recentFiles,ex.selectedPath,eE,ex]);let e3=(0,s.useRef)(eb.selectedBranch);e3.current=eb.selectedBranch;let e6=(0,s.useRef)(ex.selectedPath);e6.current=ex.selectedPath;let e8=(0,s.useRef)(ex.fileContent?.type);e8.current=ex.fileContent?.type;let e9=(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(fetch(`/api/files/init?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.error||ex.setFiles(e.files||[])})),o.push(fetch(`/api/files/index?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.paths&&ex.setFileIndex(e.paths)})),o.push(fetch(`/api/files/recent?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{ex.setRecentFiles(e.files||[])}))),n||s){o.push(fetch(`/api/git/status?cwd=${encodeURIComponent(t)}`).then(e=>{if(e.ok)return e.json().then(e=>{eg.setStatus(e);let t=Y(e.staged),r=Y(e.unstaged);eg.setStagedTree(t),eg.setUnstagedTree(r);let n=new Set([...Q(t),...Q(r)]);eg.setStatusExpandedPaths(e=>new Set([...e,...n]))})})),eg.refreshDiff(),n&&eb.loadBranches();let e=e3.current;e&&o.push(fetch(`/api/git/commits?cwd=${encodeURIComponent(t)}&branch=${encodeURIComponent(e)}&limit=50`).then(e=>e.json()).then(e=>{let t=e.commits||[];eb.setCommits(t),eb.setHasMoreCommits(t.length>=50)}))}let l=e6.current,a=e8.current;l&&"text"===a&&o.push(fetch(`/api/files/read?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(l)}`).then(e=>e.json()).then(e=>{"text"===e.type&&ex.setFileContent(e)})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,eH.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e9,enabled:ed});let e7=(0,s.useCallback)(e=>{let t=e.split("/");if(t.length>1){let e=[];for(let r=1;r<t.length;r++)e.push(t.slice(0,r).join("/"));ex.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return ex.saveExpandedPaths(r),r})}ex.setSelectedPath(e),ex.setShouldScrollToSelected(!0),C("tree")},[ex]);return(0,n.jsxs)(v,{container:E,children:[(0,n.jsxs)("div",{ref:S,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:()=>eJ("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===N?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:w("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eJ("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===N?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:w("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eJ("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===N?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:w("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eJ("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===N?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:w("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eJ("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===N?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:w("fileBrowser.historyTab")})]}),"tree"===N&&(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:ex.searchInputRef,type:"text",value:ex.searchQuery,onChange:e=>ex.setSearchQuery(e.target.value),placeholder:w("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"}),ex.searchQuery&&(0,n.jsx)("button",{onClick:()=>ex.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:w("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:()=>ex.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ex.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:ex.searchExactMatch?w("fileBrowser.exactMatchOn"):w("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ex.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:w("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:()=>ex.searchTreeExpandedPaths?ex.setSearchTreeExpandedPaths(new Set):ex.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:w("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"===N&&(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:ef.contentSearchInputRef,type:"text",value:ef.contentSearchQuery,onChange:e=>ef.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ef.performContentSearch(ef.contentSearchQuery)},placeholder:w("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"}),ef.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>ef.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:w("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:()=>ef.performContentSearch(ef.contentSearchQuery),disabled:ef.isSearching||!ef.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:ef.isSearching?"...":w("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:ef.searchOptions.caseSensitive,onChange:e=>ef.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:w("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ef.searchOptions.wholeWord,onChange:e=>ef.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:w("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ef.searchOptions.regex,onChange:e=>ef.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:w("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:ef.searchOptions.fileType,onChange:e=>ef.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:w("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===N&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:(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)(eU,{branches:eb.branches,selectedBranch:eb.selectedBranch,onSelect:e=>{eb.setSelectedBranch(e),eb.compareMode&&eb.loadCompareFiles(e)},isLoading:eb.isLoadingBranches})}),(0,n.jsx)("button",{onClick:()=>eb.toggleCompareMode(!eb.compareMode),className:`flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors ${eb.compareMode?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent border border-border"}`,title:eb.compareMode?w("fileBrowser.compareModeOff"):w("fileBrowser.compareModeOn"),children:w("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"===N?"":"hidden"}`,children:[ex.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:ex.creatingItem.parentPath?w("fileBrowser.createFileIn",{path:ex.creatingItem.parentPath}):w("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:w("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:()=>{L.current=!0},onCompositionEnd:()=>{L.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(L.current)return;let r=e.target.value.trim();if(!r)return;let n=ex.creatingItem.parentPath,s=n?`${n}/${r}`:r;try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:s,content:""})});if(e.ok)(0,g.oR)(w("toast.createdFile",{name:r}),"success"),ex.setCreatingItem(null),ex.loadDirectory(n),ex.loadFileIndex(),n&&ex.setExpandedPaths(e=>new Set([...e,n])),eE(s);else{let t=await e.json();(0,g.oR)(t.error||w("toast.createFailed"),"error")}}catch(e){(0,g.oR)(w("toast.createFailed"),"error")}}else"Escape"===e.key&&ex.setCreatingItem(null)},onBlur:()=>ex.setCreatingItem(null)})]}),ex.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:w("common.loading")}):ex.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ex.fileError}):(0,n.jsx)(ep,{files:ex.files,selectedPath:ex.selectedPath,expandedPaths:ex.effectiveExpandedPaths,matchedPaths:ex.matchedPaths,gitStatusMap:eV,loadingDirs:ex.loadingDirs,onSelect:e=>{ex.setShouldScrollToSelected(!1),eE(e)},onToggle:ex.handleToggle,cwd:t,shouldScrollToSelected:ex.shouldScrollToSelected,onScrolledToSelected:()=>ex.setShouldScrollToSelected(!1),onCreateFile:e=>ex.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>R({path:e,isDirectory:t,name:r}),onRefresh:()=>ex.loadFiles(),onCopyFile:eZ,onPaste:e1})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===N?"":"hidden"}`,children:ef.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"})}):ef.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ef.searchError}):0===ef.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ef.contentSearchQuery?w("fileBrowser.noContentSearchResults"):w("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[ef.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:[w("fileBrowser.nFilesNMatches",{files:ef.searchStats.totalFiles,matches:ef.searchStats.totalMatches}),ef.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",w("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(ep,{files:eM.files,selectedPath:ex.selectedPath,expandedPaths:eT,onSelect:e=>{let t=eM.matchMap.get(e);eE(e,t?.matches[0]?.lineNumber),U||q(!0)},onToggle:eP,cwd:t,renderActions:eI,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"===N?"":"hidden"}`,children:0===ex.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:w("fileBrowser.noRecentFiles")}):(0,n.jsx)(ep,{files:ex.recentFilesTree,selectedPath:ex.selectedPath,expandedPaths:ex.recentTreeDirPaths,onSelect:eE,onToggle:eL,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===N?"":"hidden"}`,children:eg.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"})}):eg.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:eg.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:w("fileBrowser.stagingArea",{count:eg.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>eg.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:w("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"})})})]}),(eg.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:eg.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:w("fileBrowser.unstageAll")})]}),(0,n.jsx)(X,{files:eg.stagedTree,selectedPath:eg.statusSelectedFile?.type==="staged"?eg.statusSelectedFile.file.path:null,expandedPaths:eg.statusExpandedPaths,onSelect:e=>e.file&&eg.handleStatusFileSelect(e.file,"staged"),onToggle:eg.handleStatusToggle,cwd:t,emptyMessage:w("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=G(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eg.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:w("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(),eg.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:w("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:w("fileBrowser.workspace",{count:eg.status?.unstaged.length||0})}),(eg.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:eg.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:w("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:eg.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:w("fileBrowser.stageAll")})]})]}),(0,n.jsx)(X,{files:eg.unstagedTree,selectedPath:eg.statusSelectedFile?.type==="unstaged"?eg.statusSelectedFile.file.path:null,expandedPaths:eg.statusExpandedPaths,onSelect:e=>e.file&&eg.handleStatusFileSelect(e.file,"unstaged"),onToggle:eg.handleStatusToggle,cwd:t,emptyMessage:w("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=G(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(),eg.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:w("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(),eg.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:w("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(),eg.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:w("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(),eg.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:w("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"===N?"":"hidden"}`,children:eb.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:eb.historyError})]})}):eb.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:eb.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:w("fileBrowser.loadingDiff")}):0===eb.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:w("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:w("fileBrowser.nFilesChanged",{count:eb.compareFiles.length,branch:eb.selectedBranch})})}),(0,n.jsx)(X,{files:eb.compareFileTree,expandedPaths:eb.compareExpandedPaths,onToggle:eb.handleCompareToggle,selectedPath:eb.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eb.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eb.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eb.handleCommitListScroll,children:eb.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:w("fileBrowser.loadingCommits")}):0===eb.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:w("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eb.commits.map(e=>{let t,r,s,o,l,a,i;return(0,n.jsxs)("div",{onClick:()=>eb.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eb.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 ",(t=new Date(e.date),r=new Date,s=t.getFullYear()===r.getFullYear(),o=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),i=String(t.getMinutes()).padStart(2,"0"),s?`${o}-${l} ${a}:${i}`:`${t.getFullYear()}-${o}-${l} ${a}:${i}`)]})]}),(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)}),eb.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"})}),!eb.hasMoreCommits&&eb.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:w("fileBrowser.allLoaded",{count:eb.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===N||"search"===N||"recent"===N)&&(ex.blameSelectedCommit?(0,n.jsx)(eh,{isOpen:!0,onClose:()=>ex.setBlameSelectedCommit(null),commit:ex.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ex.selectedPath||void 0,onContentSearch:e=>{C("search"),ef.setContentSearchQuery(e),ef.performContentSearch(e)}}):ex.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:ex.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ex.selectedPath}`),(0,g.oR)(w("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:w("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(),e7(ex.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:w("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:ex.showEditor?(0,n.jsxs)(n.Fragment,{children:[z.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:w("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>W.current?.save(),disabled:!z.isDirty||z.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${z.isDirty&&!z.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:z.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):w("common.save")}),(0,n.jsx)("button",{onClick:()=>W.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:w("fileBrowser.closeEdit"),children:w("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[ex.fileContent?.type==="text"&&ex.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ex.fileContent.content),(0,g.oR)(w("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:w("fileBrowser.copyFileContent"),children:w("common.copy")}),ex.selectedPath?.endsWith(".json")&&ex.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>K(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${V?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:w("fileBrowser.toggleJsonReadable"),children:w("common.readable")}),ex.fileContent?.type==="text"&&ec(ex.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ex.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:w("fileBrowser.previewMarkdown"),children:w("common.preview")}),ex.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:ex.handleToggleBlame,disabled:ex.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ex.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:w("fileBrowser.viewBlame"),children:ex.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ex.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ex.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:w("fileBrowser.editFile"),children:w("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ex.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"})}):ex.fileContent?"text"===ex.fileContent.type&&"string"==typeof ex.fileContent.content?ex.showBlame&&ex.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:ex.blameError}),(0,n.jsx)("button",{onClick:()=>ex.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:w("fileBrowser.backToPreview")})]})}):ex.showBlame&&0===ex.blameLines.length&&ex.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"})}):V&&ex.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(em,{search:er}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:et,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:Z(ex.fileContent.content)})})]}):(0,n.jsx)(e$,{ref:W,content:ex.fileContent.content,filePath:ex.selectedPath,cwd:t,enableComments:!0,scrollToLine:O??ex.targetLineNumber,scrollToLineAlign:null!=O?"start":ex.targetScrollAlign,onScrollToLineComplete:()=>{A(null),ex.setTargetLineNumber(null)},highlightKeyword:"search"===N?ef.contentSearchQuery:null,visibleLineRef:D,viStateRef:F,initialCursorLine:ex.initialCursorLine,initialCursorCol:ex.initialCursorCol,onInitialCursorSet:()=>{ex.setInitialCursorLine(null),ex.setInitialCursorCol(null)},onCmdClick:eD?eF:void 0,onTokenHover:eD?eO:void 0,onTokenHoverLeave:eD?el.onTokenMouseLeave:void 0,onTokenHoverCancel:eD?el.clearHover:void 0,blameLines:ex.showBlame&&ex.blameLines.length>0?ex.blameLines:void 0,inlineBlameLines:ex.blameLines.length>0?ex.blameLines:void 0,onSelectCommit:ex.setBlameSelectedCommit,editable:ex.showEditor,initialMtime:ex.fileContent.mtime,onEditorClose:e=>{ex.setShowEditor(!1),A(e)},onSaved:()=>{let e=D.current??1;ex.loadFileContent(ex.selectedPath),ex.setShowEditor(!1),A(e)},onEditorStateChange:_,viMode:!0,onContentMutate:ev,onEnterInsertMode:ej,onViSave:ey,onContentSearch:e=>{C("search"),ef.setContentSearchQuery(e),ef.performContentSearch(e)}}):"image"===ex.fileContent.type&&ex.fileContent.content?(0,n.jsx)("div",{className:"h-full flex items-center justify-center p-4 bg-secondary",children:(0,n.jsx)("img",{src:ex.fileContent.content,alt:ex.selectedPath,className:"max-w-full max-h-full object-contain"})}):(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:ex.fileContent.message||w("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:w("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:w("fileBrowser.selectFileToPreview")})]})})),"status"===N&&(eg.statusSelectedFile&&eg.statusDiff?(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",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:eg.statusSelectedFile.file.path}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${eg.statusSelectedFile.file.path}`),(0,g.oR)(w("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:w("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(),e7(eg.statusSelectedFile.file.path)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:w("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)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===eg.statusSelectedFile.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"===eg.statusSelectedFile.type?w("fileBrowser.staged"):w("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(m=eg.statusSelectedFile.file.path,y=m.split(".").pop()?.toLowerCase(),eS.has(y||""))?(0,n.jsx)("div",{className:"p-4 flex items-center justify-center",children:(0,n.jsx)("img",{src:`/api/files/read?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(eg.statusSelectedFile.file.path)}&raw=1`,alt:eg.statusSelectedFile.file.path,className:"max-w-full max-h-[60vh] object-contain"})}):(0,n.jsx)(H,{oldContent:eg.statusDiff.oldContent,newContent:eg.statusDiff.newContent,filePath:eg.statusDiff.filePath,isNew:eg.statusDiff.isNew,isDeleted:eg.statusDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eg.statusDiff.isDeleted&&ec(eg.statusSelectedFile.file.path)?()=>eg.setShowStatusDiffPreview(!0):!eg.statusDiff.isDeleted&&eg.statusSelectedFile.file.path.endsWith(".json")?()=>ee({content:eg.statusDiff.newContent,filePath:eg.statusDiff.filePath}):void 0,previewLabel:eg.statusSelectedFile.file.path.endsWith(".json")?w("common.readable"):w("common.preview"),onContentSearch:e=>{C("search"),ef.setContentSearchQuery(e),ef.performContentSearch(e)}})}),eg.showStatusDiffPreview&&eg.statusDiff&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>eg.setShowStatusDiffPreview(!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)(eA,{content:eg.statusDiff.newContent,filePath:eg.statusDiff.filePath,cwd:t,onClose:()=>eg.setShowStatusDiffPreview(!1)})})}),J&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ee(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:J.filePath}),(0,n.jsx)("button",{onClick:()=>ee(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)(em,{search:es}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:en,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:Z(J.content)})})]})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:w("fileBrowser.selectFileToViewDiff")})})),"history"===N&&!eb.historyError&&(eb.compareMode?eb.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:w("fileBrowser.loadingDiffContent")}):eb.compareFileDiff?(0,n.jsx)(H,{oldContent:eb.compareFileDiff.oldContent,newContent:eb.compareFileDiff.newContent,filePath:eb.compareFileDiff.filePath,isNew:eb.compareFileDiff.isNew,isDeleted:eb.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eb.compareFileDiff.isDeleted&&eb.compareFileDiff.filePath.endsWith(".json")?()=>ee({content:eb.compareFileDiff.newContent,filePath:eb.compareFileDiff.filePath}):void 0,previewLabel:w("common.readable"),onContentSearch:e=>{C("search"),ef.setContentSearchQuery(e),ef.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eb.compareFiles.length>0?w("fileBrowser.selectFileToViewDiff"):w("fileBrowser.clickCompareToLoad")})}):eb.selectedCommit?(0,n.jsx)(eh,{isOpen:!0,onClose:()=>eb.setSelectedCommit(null),commit:eb.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{C("search"),ef.setContentSearchQuery(e),ef.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:w("fileBrowser.selectCommitToView")})}))]})]}),ex.showMarkdownPreview&&ex.fileContent?.type==="text"&&ex.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ex.setShowMarkdownPreview(!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)(eA,{content:ex.fileContent.content||"",filePath:ex.selectedPath,cwd:t,onClose:()=>ex.setShowMarkdownPreview(!1)})})}),$&&(0,n.jsx)(ez,{files:ex.files,fileIndex:ex.fileIndex,recentFiles:ex.recentFilePaths,onSelectFile:e=>{eE(e),ex.setShouldScrollToSelected(!0),C("tree")},onClose:()=>P(!1)}),(eB||ea.visible)&&(0,n.jsxs)("div",{className:`flex ${ea.visible&&eB?"":"flex-col"}`,children:[eB&&(0,n.jsx)("div",{className:ea.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(eY,{results:ef.contentSearchResults,loading:ef.isSearching,totalMatches:ef.searchStats?.totalMatches??0,onSelect:(e,t)=>{ex.selectedPath&&ei.push({filePath:ex.selectedPath,lineNumber:D.current}),eE(e,t)},onClose:()=>q(!1)})}),ea.visible&&(0,n.jsx)("div",{className:eB?"flex-1 min-w-0":"",children:(0,n.jsx)(eX,{references:ea.references,loading:ea.loading,onSelect:eW,onClose:ea.closeReferences})})]})]}),I&&(0,a.createPortal)((0,n.jsx)("div",{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",style:{left:I.x+12,top:I.y+16},children:I.text}),document.body),T&&(0,a.createPortal)((0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>R(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:w("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:w("fileBrowser.confirmDeleteMessage",{name:T.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:()=>R(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:w("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=T;R(null);try{let n=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:e})});if(n.ok){(0,g.oR)(w("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ex.loadDirectory(t),ex.loadFileIndex(),ex.selectedPath===e&&eE("")}else{let e=await n.json();(0,g.oR)(e.error||w("toast.deleteFailed"),"error")}}catch{(0,g.oR)(w("toast.deleteFailed"),"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:w("common.delete")})]})]})}),document.body),el.hoverInfo&&E&&(0,a.createPortal)((0,n.jsx)(eK,{ref:e=>{el.tooltipElRef.current=e},displayString:el.hoverInfo.displayString,documentation:el.hoverInfo.documentation,x:el.hoverInfo.x,y:el.hoverInfo.y,container:E,onMouseEnter:el.onCardMouseEnter,onMouseLeave:el.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=el.hoverInfo;el.clearHover(),ea.findReferences(e,t,r)},onSearch:e=>{el.clearHover(),C("search"),ef.setContentSearchQuery(e),ef.performContentSearch(e)}}),E)]})}function e3({isOpen:e,onClose:t,cwd:r}){let l,{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)(!1),[k,N]=(0,s.useState)(""),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[M,T]=(0,s.useState)(""),[R,$]=(0,s.useState)(!1),P=(0,s.useCallback)(async()=>{f(!0);try{let e=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json();c(t.worktrees),u(t.nextPath),h(t.nextRandomWord),t.gitUserName&&N(t.gitUserName)}}catch(e){console.error("Failed to load worktrees:",e),(0,g.oR)(a("toast.worktreeLoadFailed"),"error")}finally{f(!1)}},[r]),I=(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&&(P(),j(null))},[e,P]);let B=async()=>{if(!d)return;let e="origin/main";try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(t.ok){let r=await t.json();e=I(r)}}catch{}let t=m||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}(),n=k?`${k}/${t}`:t;b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,newBranch:n,baseBranch:e})});if(t.ok)(0,g.oR)(a("toast.worktreeCreateSuccess",{name:n}),"success"),P();else{let e=await t.json();(0,g.oR)(e.error||a("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,g.oR)(a("toast.worktreeCreateFailed"),"error")}finally{b(!1)}},D=async()=>{$(!0),T(""),S(!0);try{let e=await fetch(`/api/git/branches?cwd=${encodeURIComponent(r)}`);if(e.ok){let t=await e.json(),r=new Set(i.map(e=>e.branch).filter(Boolean)),n=[...t.local.filter(e=>!r.has(e)),...t.remote.filter(e=>!r.has(e)&&!t.local.includes(e.replace(/^origin\//,"")))];E(n)}}catch{(0,g.oR)(a("toast.loadBranchFailed"),"error")}finally{$(!1)}},F=async e=>{if(d){S(!1),b(!0);try{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"add",cwd:r,path:d,branch:e})});if(t.ok)(0,g.oR)(a("toast.worktreeCreateSuccess",{name:e}),"success"),P();else{let e=await t.json();(0,g.oR)(e.error||a("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,g.oR)(a("toast.worktreeCreateFailed"),"error")}finally{b(!1)}}},O=async()=>{if(v){w(!0);try{let e=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"remove",cwd:r,path:v.path})});if(e.ok)(0,g.oR)(a("toast.worktreeDeleted"),"success"),j(null),P();else{let t=await e.json();(0,g.oR)(t.error||a("toast.worktreeDeleteFailed"),"error")}}catch(e){console.error("Failed to delete worktree:",e),(0,g.oR)(a("toast.worktreeDeleteFailed"),"error")}finally{w(!1)}}},A=async e=>{let t=e.isLocked?"unlock":"lock";try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,cwd:r,path:e.path})});if(n.ok)(0,g.oR)(e.isLocked?a("toast.worktreeUnlocked"):a("toast.worktreeLocked"),"success"),P();else{let e=await n.json();(0,g.oR)(e.error||a("toast.operationFailed"),"error")}}catch(e){console.error("Failed to toggle lock:",e),(0,g.oR)(a("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:a("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:x?(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:i.map(e=>{let s=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${s?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&(window.parent.postMessage({type:"OPEN_PROJECT",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 ${s?"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:a("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",a("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),A(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?a("git.worktree.unlock"):a("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(),j(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:a("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.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate pl-4",children:e.path}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),C&&(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:M,onChange:e=>T(e.target.value),placeholder:a("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:()=>S(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:a("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:R?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("common.loading")}):0===(l=L.filter(e=>e.toLowerCase().includes(M.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:a("git.worktree.noBranches")}):l.map(e=>(0,n.jsx)("button",{onClick:()=>F(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:a("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:D,disabled:!d||p,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!p?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:a("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:B,disabled:!d||p,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!p?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:p?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("git.worktree.addWorktree")})]})]}),v&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>j(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:a("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:a("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:v.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:a("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:v.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:a("common.cancel")}),(0,n.jsx)("button",{onClick:O,disabled:y,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:y?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):a("common.delete")})]})]})})]})}):null}var e6=r(67635),e8=r(73300),e9=r(20986),e7=r(61878),te=r(9921),tt=r(66088),tr=r(42790);function tn(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}let ts=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await l(),c(!1),(0,g.oR)(a("toast.disconnected",{id:e}));else{await r(),c(!0);let n=`${"3456"===window.location.port?"cock-dev":"cock"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,g.oR)(a("toast.copiedCommand",{command:n}))}},[i,e,t,r,l,a]);return(0,n.jsxs)("button",{onClick:d,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:i?a("shortIdBadge.clickToDisconnect"):a("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${i?"bg-green-500":"bg-muted-foreground/40"}`}),e]})});var to=r(72588);let tl=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(700)]).then(r.bind(r,80700)).then(e=>({default:e.XtermRenderer}))),ta={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},ti=/\x1b\[[0-9;]*m/g;function tc({output:e,query:t,mode:r,currentIdx:o,matchRefs:l}){let a=(0,s.useRef)(null);a.current||(a.current=new tr.v,a.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return l.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(ti,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=a.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],m=0,h=s.toLowerCase(),x=0;for(;x<h.length;){let e=h.indexOf(c,x);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{l.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}`)),x=m=e+c.length}return m<s.length&&u.push((0,n.jsx)("span",{children:s.slice(m)},`t${m}`)),(0,n.jsx)("div",{children:u},t)})})}let td=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:l,output:a,exitCode:i,isRunning:c,selected:d,onSelect:u,onInterrupt:m,onStdin:h,onDelete:x,onRerun:f,timestamp:p,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:y,onToggleMaximize:w,maximized:k,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:L}=(0,o.Bd)(),E=(0,s.useRef)(null),M=(0,s.useRef)(null),T=(0,s.useRef)(!0),R=(0,s.useRef)(null),$=(0,s.useRef)(null),P=(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}`})(p),I=e&&t?tn(t+e):void 0,[B,D]=(0,s.useState)(!1),[F,O]=(0,s.useState)(""),A=(0,s.useRef)(null),W=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>A.current?v(e,A.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=()=>A.current?j(e,A.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[z,H]=(0,s.useState)(!1),[_,U]=(0,s.useState)(""),[q,V]=(0,s.useState)("search"),[K,J]=(0,s.useState)(0),X=(0,s.useRef)([]),Y=(0,s.useRef)(null),Q=(0,s.useRef)(0);(0,s.useEffect)(()=>{Y.current||(Y.current=new tr.v,Y.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=M.current;if(e&&Y.current){if(a.length<Q.current&&(Y.current=new tr.v,Y.current.use_classes=!0,Q.current=0,e.innerHTML=""),a.length>Q.current){let t=a.slice(Q.current),r=Y.current.ansi_to_html(t);Q.current=a.length,e.insertAdjacentHTML("beforeend",r)}if(E.current){let e=E.current.scrollHeight>E.current.clientHeight;D(e),e&&(E.current.scrollTop=E.current.scrollHeight)}}},[a]),(0,s.useEffect)(()=>(c&&T.current&&E.current&&(null!==R.current&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight),R.current=null})),()=>{null!==R.current&&cancelAnimationFrame(R.current)}),[a,c]),(0,s.useEffect)(()=>{if(!k)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),w?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[k,w]);let G=a?a.split("\n").length:0,Z=(0,s.useCallback)(()=>{H(!0),requestAnimationFrame(()=>W.current?.focus())},[]),ee=(0,s.useCallback)(()=>{H(!1),U(""),J(0),A.current?.clearSearch()},[]),et=(0,s.useCallback)(e=>{e.trim()&&(b?A.current?.findNext(e):J(e=>{let t=e+1,r=X.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(X.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),er=(0,s.useCallback)(e=>{e.trim()&&(b?A.current?.findPrevious(e):J(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(!d)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),Z();return}if("Escape"===e.key&&z){e.preventDefault(),e.stopPropagation(),ee();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,z,Z,ee]);let en=k&&N?N-41:C??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 ${k?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${k?"":d?"border-brand":"border-brand/30"}`,onClick:u,children:[k?(0,n.jsxs)("div",{onDoubleClick:()=>w?.(),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:l}),c&&(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"}),L("console.runningText")]}),c&&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:()=>w?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.restoreTooltip",{modKey:(0,to.Mu)()}),children:(0,n.jsx)(eJ.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>S?.(),onDoubleClick:e=>{e.stopPropagation(),w?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${d?"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)(ts,{shortId:I,type:"terminal",onRegister:()=>{fetch("/api/terminal/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tabId:t,commandId:e,command:l,projectCwd:r})}).catch(()=>{})},onUnregister:()=>{fetch("/api/terminal/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({commandId:e})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:l}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(l),(0,g.oR)(L("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyCommand"),children:(0,n.jsx)(e6.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),B&&!c&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:G})}),a&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=a.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,g.oR)(L("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyOutput"),children:(0,n.jsx)(e8.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.rerun"),children:(0,n.jsx)(e9.A,{className:"w-3.5 h-3.5"})}),x&&(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:L("console.deleteRecord"),children:(0,n.jsx)(eJ.A,{className:"w-3.5 h-3.5"})})]}),z&&(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)(e7.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:W,value:_,onChange:e=>{let t=e.target.value;U(t),J(0),b&&(t.trim()?A.current?.findNext(t):A.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?er(_):et(_))},placeholder:L("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:()=>V("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:L("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>V("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:L("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>er(_),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(te.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>et(_),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tt.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:ee,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsx)("div",{style:{height:en,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:en},children:L("console.loadingTerminal")}),children:(0,n.jsx)(tl,{ref:A,output:a,isRunning:c,onInput:h,onResize:y,maximized:k,height:en,directWrite:!!v})})}):(0,n.jsx)("div",{ref:E,className:"overflow-auto px-4 py-2",style:{height:en},onScroll:()=>{if(E.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=E.current;T.current=t-e-r<50}},children:z&&_.trim()?(0,n.jsx)(tc,{output:a,query:_,mode:q,currentIdx:K,matchRefs:X}):(0,n.jsx)("pre",{ref:M,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),c&&!k&&(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:L("console.clickToInput")}):h?(0,n.jsx)("input",{ref:$,value:F,onChange:e=>O(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=ta[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(F+"\n"),O("")),"Tab"===e.key&&(e.preventDefault(),h(" "))},placeholder:L("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:L("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"}),P&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:P})]}),!c&&void 0!==i&&!k&&(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===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:L("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),P&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:P})]})]})})});var tu=r(68459),tm=r(51914);function th({cwd:e,tabId:t,onClose:r,onSave:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[x,f]=(0,s.useState)(!0);(0,s.useEffect)(()=>{p()},[e,t]);let p=async()=>{f(!0);try{let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=await fetch(`/api/terminal/env?${r}`);if(n.ok){let e=await n.json();c(e.env||{})}}catch(e){console.error("Failed to load env:",e)}finally{f(!1)}},g=()=>{d.trim()&&(c(e=>({...e,[d.trim()]:m})),u(""),h(""))},b=async()=>{try{(await fetch("/api/terminal/env",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,env:i})})).ok&&(l(i),r())}catch(e){console.error("Failed to save env:",e)}};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:a("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?a("envManager.tabScope"):a("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(i).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 c(t=>({...t,[e]:r}))},placeholder:a("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:()=>{c(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)(tu.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:d,onChange:e=>u(e.target.value),placeholder:a("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(),g())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),placeholder:a("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(),g())}}),(0,n.jsx)("button",{onClick:g,disabled:!d.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)(tm.A,{className:"w-4 h-4"})})]}),0===Object.keys(i).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:a("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:a("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:a("common.save")})]})]})})}var tx=r(10762);function tf({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0);(0,s.useEffect)(()=>{x()},[]);let x=async()=>{h(!0);try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();a(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}finally{h(!1)}},f=()=>{i.trim()&&d.trim()&&(a(e=>({...e,[i.trim()]:d.trim()})),c(""),u(""))},p=async()=>{try{(await fetch("/api/terminal/aliases",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({aliases:l})})).ok&&(t(l),e())}catch(e){console.error("Failed to save aliases:",e)}};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)(tx.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)(eJ.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(l).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 a(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:()=>{a(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)(tu.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:i,onChange:e=>c(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(),f())}})]}),(0,n.jsx)("input",{type:"text",value:d,onChange:e=>u(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(),f())}})]}),(0,n.jsx)("button",{onClick:f,disabled:!i.trim()||!d.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)(tm.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(l).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:p,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 tp=r(53961),tg=r(15813),tb=r(37595),tv=r(49698),tj=r(20232),ty=r(80777);let tw=null,tk="",tN=0,tC=null,tS=!1,tL=new Map,tE=null,tM=null;function tT(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){tE&&(tE(t.commands),tE=null);return}let n=t.commandId;if(!n)return;let s=tL.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)&&tL.delete(n)}}function tR(e){tw?.readyState===WebSocket.OPEN&&tw.send(JSON.stringify(e))}function t$(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);tk===r&&tw||(tW(),tS=!1,tk=r,function e(){if(tS||!tk)return;let t=new WebSocket(tk);tw=t,t.onopen=()=>{for(let e of(tN=0,tL.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=tT,t.onclose=()=>{if(tw!==t||(tw=null,tS))return;tC&&clearTimeout(tC);let r=Math.min(1e3*Math.pow(1.5,tN),1e4);tN++,tC=setTimeout(e,r)},t.onerror=()=>{}}())}function tP(){return new Promise((e,t)=>{if(tw?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{tw?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function tI(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:l,usePty:a,cols:i,rows:c,onData:d,onError:u}=e;t$(o);try{await tP()}catch{u("WebSocket connection failed");return}tL.delete(n),tL.set(n,{onData:d,onError:u}),tR({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:l,...a?{usePty:!0}:{},...i?{cols:i,rows:c}:{}})}async function tB(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;t$(r);try{await tP()}catch{s("WebSocket connection failed");return}tL.set(t,{onData:n,onError:s}),tR({type:"attach",commandId:t})}function tD(e,t){tR({type:"stdin",commandId:e,data:t})}function tF(e,t,r){tR({type:"resize",commandId:e,cols:t,rows:r})}function tO(e){tR({type:"interrupt",pid:e})}async function tA(e){try{t$(e);try{await tP()}catch{return[]}return await new Promise(e=>{tE=t=>{e(t)},tR({type:"running"}),setTimeout(()=>{tE&&(tE=null,e([]))},3e3)})}finally{tM=null}}function tW(){if(tS=!0,tC&&(clearTimeout(tC),tC=null),tw){let e=tw;tw=null,e.close()}tL.clear(),tE&&(tE([]),tE=null),tM=null,tk="",tN=0}let tz=new Map;function tH(e){tz.set(e.type,e)}function t_(e){return tz.get(e)}function tU(e){for(let t of tz.values())if(t.match(e))return t;return null}var tq=r(10611);function tV(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 tK(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 tJ(e){let t=(0,tq.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 tX(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function tY({url:e,id:t,selected:r,maximized:l,expandedHeight:a,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,onNewTab:m,timestamp:h,onTitleMouseDown:x,initialSleeping:f,onSleep:p,onWake:b}){let{t:v}=(0,o.Bd)(),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[N,C]=(0,s.useState)(e),[S,L]=(0,s.useState)(null),[E,M]=(0,s.useState)(f??!1),T=(0,s.useRef)(null),R=(0,s.useRef)(null),$=(0,s.useRef)(null);(0,s.useEffect)(()=>{C(e)},[e]);let P=(0,s.useRef)(!0),I=(0,s.useCallback)(()=>{E||(M(!0),L(null),p?.(t))},[E,t,p]),B=(0,s.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null)},[]),{shortId:D,connected:F,connect:O,disconnect:A}=function(e,t,r){let n=(0,s.useMemo)(()=>tn(e),[e]),[o,l]=(0,s.useState)(!1),a=(0,s.useRef)(null),i=(0,s.useRef)([]),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useRef)(r);(0,s.useEffect)(()=>{u.current=r});let m=(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=a.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}})),window.parent.postMessage({type:"SCREENSHOT_PREPARE",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}})),window.parent.postMessage({type:"SCREENSHOT_DONE"},"*");return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let h=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=a.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(!o)return;let r=!1;return d.current=!0,!function n(){if(r||!d.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",o=new WebSocket(`${s}//${window.location.host}/ws/browser?fullId=${encodeURIComponent(e)}`);a.current=o,o.onopen=()=>{for(let e of m.current)e();if(m.current=[],i.current.length>0){for(let e of i.current)h(e);i.current=[]}},o.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&u.current?h(e):i.current.push(e)}},o.onclose=()=>{a.current=null,!r&&d.current&&(c.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,d.current=!1,c.current&&clearTimeout(c.current),a.current&&(a.current.close(),a.current=null),m.current=[]}},[o,e,t,h]),(0,s.useEffect)(()=>{if(r&&i.current.length>0){for(let e of i.current)h(e);i.current=[]}},[r,h]);let x=(0,s.useCallback)(()=>o&&a.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{m.current.push(e),o||l(!0)}),[o]);return{shortId:n,connected:o,connect:x,disconnect:(0,s.useCallback)(()=>{l(!1)},[])}}(t,$,!!S&&!E&&!j),W=(0,s.useRef)(F);W.current=F,(0,s.useEffect)(()=>{let e=R.current;if(!e||E)return;let t=new IntersectionObserver(([e])=>{P.current=e.isIntersecting,e.isIntersecting||W.current?B():(T.current&&clearTimeout(T.current),T.current=setTimeout(I,3e5))});return t.observe(e),()=>t.disconnect()},[E,I,B]),(0,s.useEffect)(()=>{E?A():F?B():P.current||(T.current&&clearTimeout(T.current),T.current=setTimeout(I,3e5))},[F,E,A,B,I]),(0,s.useEffect)(()=>{f&&L(null)},[]);let z=(0,s.useCallback)(()=>{M(!1),b?.(t);let r=tV(e);tX(e)?L(r):tJ(e).then(()=>L(r))},[e,t,b]);(0,s.useEffect)(()=>{if(!e||E){e||L(null);return}let t=tV(e);if(tX(e))return void L(t);let r=!1;return tJ(e).then(()=>{r||L(t)}),()=>{r=!0}},[e,E]);let H=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=R.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,l=()=>{o&&t&&(t.scrollTop=s)},a=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",l)},i=()=>{o=!1,t.removeEventListener("scroll",l),t.style.overflow=n};return e.addEventListener("mouseenter",a),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",a),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",l),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=R.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?m?.(tK(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&C(tK(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,m]);let _=(0,s.useCallback)(()=>{y(!1),k(v("browser.pageLoadFailed"))},[]),U=(0,s.useCallback)(()=>{if(E)return void z();let e=R.current?.querySelector("iframe");if(e&&S){y(!0),k(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[E,z,S]);(0,s.useEffect)(()=>{e&&!E&&(y(!0),k(null))},[e,E]);let q=(0,s.useCallback)(()=>{N&&window.open(N,"_blank")},[N]);(0,s.useEffect)(()=>{if(!r&&!l)return;let e=e=>{"Escape"===e.key&&l&&(e.stopPropagation(),u()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),u())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[l,r,u]);let V=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(N),K=l&&a?a-41:i??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
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
4
+ ${l?"":r?"border-brand":"border-brand/30"}`,onClick:l?void 0:c,children:[l?(0,n.jsxs)("div",{onDoubleClick:u,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"})})}),D&&(0,n.jsx)(ts,{shortId:D,type:"browser",onRegister:()=>O(),onUnregister:async()=>{A(),await fetch("/api/browser/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:D})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:N||v("browser.blankPage")}),N&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(N),(0,g.oR)(v("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("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"}),j&&(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:U,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("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:v("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:u,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("browser.exitMaximize",{modKey:(0,to.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:()=>x?.(),onDoubleClick:e=>{e.stopPropagation(),u()},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"})})}),D&&(0,n.jsx)(ts,{shortId:D,type:"browser",onRegister:()=>O(),onUnregister:async()=>{A(),await fetch("/api/browser/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:D})}).catch(()=>{})}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:N||v("browser.blankPage")}),N&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(N),(0,g.oR)(v("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("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"}),j&&(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:v("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(),U()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:v("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(),d()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:v("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:R,className:"w-full",style:{height:K},children:E?(0,n.jsxs)("div",{className:"relative overflow-hidden cursor-pointer group h-full",onClick:e=>{e.stopPropagation(),U()},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:V})]}),(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"})}),v("browser.clickToWake")]})})]}):e?w?(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:w}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),U()},className:"mt-2 px-3 py-1 text-xs bg-secondary text-foreground rounded hover:bg-accent transition-colors",children:v("common.retry")})]}):(0,n.jsxs)("div",{className:"relative overflow-hidden h-full",style:{contain:"strict"},children:[j&&(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"})}),S?(0,n.jsx)("iframe",{ref:$,src:S,className:"border-0",allow:"clipboard-write; clipboard-read",style:l?{width:"100%",height:"100%"}:{position:"absolute",top:0,left:0,width:"200%",height:"200%",transform:"scale(0.5)",transformOrigin:"top left"},onLoad:H,onError:_,title:`Browser: ${V}`,"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:v("browser.blankPage")})]})}),!l&&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 ${E?"bg-yellow-500":j?"bg-brand animate-pulse":w?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:"truncate",children:E?v("browser.sleeping"):j?v("browser.loadingPage"):w?v("browser.loadFailed"):V}),(0,n.jsx)("span",{className:"flex-1"}),h&&(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}`}(h)})]})]})})}tH({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:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d,extra:u}){return(0,n.jsx)(tY,{id:e.id,url:e.url,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d,onNewTab:u?.addBrowserItem,initialSleeping:u?.initialSleeping,onSleep:u?.onSleep,onWake:u?.onWake})}});let tQ=[{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 tG(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 tZ(e){return`"${e.replace(/"/g,'""')}"`}function t0(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function t1({text:e}){let[t,r]=(0,s.useState)(!1),[o,l]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d.current||r(!1)},80)},[]),m=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),d.current=!1,c.current=setTimeout(()=>{let e=i.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=window.innerWidth,s=Math.min(600,n-t.left-8),o=s<200?Math.max(8,n-600-8):t.left,a=s<200?Math.min(600,n-16):s,c=window.innerHeight,d=t.top-8,u=c-t.bottom-8,m=d>u&&d>80;l({x:o,y:m?t.top-4:t.bottom+4,maxW:a,maxH:Math.max(60,m?d-4:u-4),above:m}),r(!0)},350)},[]),h=(0,s.useCallback)(()=>{u()},[u]),x=(0,s.useCallback)(()=>{d.current=!0,c.current&&clearTimeout(c.current)},[]),f=(0,s.useCallback)(()=>{d.current=!1,u()},[u]);return(0,n.jsxs)("span",{ref:i,className:"block truncate",onMouseEnter:m,onMouseLeave:h,children:[e,t&&(0,a.createPortal)((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:x,onMouseLeave:f,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)}),document.body)]})}async function t2(e,t){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(n.error||`HTTP ${r.status}`);return n}async function t5(e,t){let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(s.error||`HTTP ${n.status}`);return s}function t4({id:e,connectionString:t,displayName:r,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:m,timestamp:h,onTitleMouseDown:x}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,g.dj)(),[b,v]=(0,s.useState)("connecting"),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[N,C]=(0,s.useState)("public"),[S,L]=(0,s.useState)([]),[E,M]=(0,s.useState)(null),[T,R]=(0,s.useState)("table"),[$,P]=(0,s.useState)("data"),[I,B]=(0,s.useState)([]),[D,F]=(0,s.useState)([]),[O,A]=(0,s.useState)([]),[W,z]=(0,s.useState)([]),[H,_]=(0,s.useState)(null),[U,q]=(0,s.useState)(0),[V,K]=(0,s.useState)(!1),[J,X]=(0,s.useState)(0),[Y,Q]=(0,s.useState)(new Set),[G,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)({}),[ei,ec]=(0,s.useState)({}),[ed,eu]=(0,s.useState)(null),[em,eh]=(0,s.useState)(""),[ex,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ey=(0,s.useCallback)(async()=>{v("connecting"),y("");try{let r=await t2("/api/db/connect",{id:e,connectionString:t});k(r.schemas||[]),r.schemas?.length>0&&!r.schemas.includes("public")&&C(r.schemas[0]),v("connected")}catch(e){y(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{ey()},[ey]);let ew=(0,s.useCallback)(async()=>{if("connected"===b)try{let r=await t5("/api/db/schemas",{id:e,connectionString:t,schema:N});L(r.tables||[])}catch{}},[e,t,N,b]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async r=>{M(r),q(0),et(null),eo(!1),Q(new Set),Z(!1),ec({}),eu(null);try{let n=await t5("/api/db/columns",{id:e,connectionString:t,schema:N,table:r});B(n.columns||[]),F(n.primaryKeys||[]),A(n.foreignKeys||[]),z(n.indexes||[])}catch{}eN(r,0,{},null)},[e,t,N]),eN=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let l=s??ei,a=void 0!==o?o:ed;try{let s=`${tZ(N)}.${tZ(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=tZ(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 l=s.map(e=>(r.push(e),`$${n++}`));t.push(`${e}::text IN (${l.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}}(l),c=a?` ORDER BY ${tZ(a.column)} ${a.dir}`:"",d=`SELECT * FROM ${s}${o}${c} LIMIT 50 OFFSET ${50*n}`,u=await t2("/api/db/query",{id:e,connectionString:t,sql:d,params:i});_(u);let m=`SELECT count(*)::int AS cnt FROM ${s}${o}`,h=await t2("/api/db/query",{id:e,connectionString:t,sql:m,params:i});X(h.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,N,ei,ed]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await t2("/api/db/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!H||!E)return;let r=H.rows[ee],n=[],s=[],o=1;for(let e of I)void 0!==er[e.name]&&er[e.name]!==t0(r[e.name]??"")&&(n.push(`${tZ(e.name)} = $${o}`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]),o++);if(0===n.length)return void et(null);let l=D.length>0?D:I.map(e=>e.name),a=[];for(let e of l)null===r[e]||void 0===r[e]?a.push(`${tZ(e)} IS NULL`):(a.push(`${tZ(e)} = $${o}`),s.push(r[e]),o++);let i=`UPDATE ${tZ(N)}.${tZ(E)} SET ${n.join(", ")} WHERE ${a.join(" AND ")}`;try{await t2("/api/db/query",{id:e,connectionString:t,sql:i,params:s}),et(null),eN(E,U,ei,ed)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,H,E,I,D,er,e,t,N,eN,U,ei,ed]),eL=(0,s.useCallback)(async()=>{if(!E)return;let r=[],n=[],s=[],o=1;for(let e of I)void 0!==el[e.name]&&""!==el[e.name]&&(r.push(tZ(e.name)),n.push(el[e.name]),s.push(`$${o}`),o++);if(0===r.length)return;let l=`INSERT INTO ${tZ(N)}.${tZ(E)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await t2("/api/db/query",{id:e,connectionString:t,sql:l,params:n}),eo(!1),ea({}),eN(E,U,ei,ed)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[E,I,el,e,t,N,eN,U,ei,ed]),eE=(0,s.useCallback)(async()=>{if(0===Y.size||!H||!E)return;let r=D.length>0?D:I.map(e=>e.name),n=0;for(let s of Array.from(Y).sort((e,t)=>t-e)){let o=H.rows[s];if(!o)continue;let l=[],a=[],i=1;for(let e of r)null===o[e]||void 0===o[e]?l.push(`${tZ(e)} IS NULL`):(l.push(`${tZ(e)} = $${i}`),a.push(o[e]),i++);let c=`DELETE FROM ${tZ(N)}.${tZ(E)} WHERE ctid = (SELECT ctid FROM ${tZ(N)}.${tZ(E)} WHERE ${l.join(" AND ")} LIMIT 1)`;try{await t2("/api/db/query",{id:e,connectionString:t,sql:c,params:a})}catch{n++}}Q(new Set),Z(!1),eN(E,U,ei,ed),n>0&&alert(f("database.deleteRowsFailed",{count:n}))},[Y,H,E,D,I,e,t,N,eN,U,ei,ed]),eM=(0,s.useCallback)(async r=>{if(!E)return;if(Y.size>0&&H){let e,t=H.fields.map(e=>e.name),n=Array.from(Y).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 ${tZ(N)}.${tZ(E)}`;try{let s=await fetch("/api/db/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,connectionString:t,sql:n,format:r})});if(!s.ok)throw Error("Export failed");let o=await s.blob(),l=URL.createObjectURL(o),a=document.createElement("a");a.href=l,a.download=`${E}.${r}`,a.click(),URL.revokeObjectURL(l)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[E,e,t,N,Y,H]),eT=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eR=Math.max(1,Math.ceil(J/50)),e$=(0,s.useCallback)(e=>{E&&(q(e),eN(E,e,ei,ed))},[E,eN,ei,ed]),eP=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ec(r),q(0),Q(new Set),E&&eN(E,0,r,ed)},[ei,ed,E,eN]),eI=(0,s.useCallback)(()=>{ec({}),q(0),Q(new Set),E&&eN(E,0,{},ed)},[ed,E,eN]),eB=(0,s.useCallback)(e=>{eu(e),q(0),Q(new Set),E&&eN(E,0,ei,e)},[ei,E,eN]);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
+ ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
8
+ ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{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"===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:f("database.connectionFailed")}),"connected"===b&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:f("database.connected")}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:tG(h)}),(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:a?f("browser.exitMaximize",{modKey:(0,to.Mu)()}):f("browser.maximize",{modKey:(0,to.Mu)()}),children:a?(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:a&&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"}),f("database.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:ey,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"===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:[w.length>1?(0,n.jsx)("select",{value:N,onChange:e=>{C(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:N}),(0,n.jsx)("button",{onClick:ew,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:()=>R(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${T===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:[S.filter(e=>"table"===T?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>ek(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${E===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)(t1,{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===S.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:()=>P(e),className:`px-3 py-1.5 text-xs transition-colors ${$===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)),E&&"data"===$&&(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:eI,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:"|"})]}),Y.size>0&&!G&&(0,n.jsx)("button",{onClick:()=>Z(!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:Y.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:eE,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:()=>Z(!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:()=>eM("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("database.copyCsvSelected"):f("database.copyCsvAll"),children:Y.size>0?f("database.copyCSV"):f("database.CSV")}),(0,n.jsx)("button",{onClick:()=>eM("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("database.copyJsonSelected"):f("database.copyJsonAll"),children:Y.size>0?f("database.copyJSON"):f("database.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:E||"sql"===$?"structure"===$?(0,n.jsx)(t3,{columns:I,primaryKeys:D,foreignKeys:O,indexes:W}):"data"===$?(0,n.jsx)(t8,{result:H,loading:V,columns:I,page:U,totalPages:eR,totalRows:J,onPageChange:e$,filters:ei,sort:ed,onFilterChange:eP,onSortChange:eB,selectedRows:Y,onSelectedRowsChange:e=>{Q(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!H)return;let t=H.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":t0(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:el,onStartAdd:()=>{eo(!0),ea({})},onNewRowChange:(e,t)=>ea(r=>({...r,[e]:t})),onSaveNewRow:eL,onCancelAdd:()=>{eo(!1),ea({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(t9,{sqlInput:em,onSqlChange:eh,onExecute:eC,onKeyDown:eT,result:ex,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")})})]})]})]}),!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"===b?"bg-green-500":"error"===b?"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")}[b]}),"connected"===b&&E&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:E}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:tG(h)})]})]})})}function t3({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:l}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:l("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:l("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:l("database.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("database.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("database.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("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:l("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:l("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:l("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 t6({filter:e,onApply:t,onClear:r,onToggle:l,onClose:i,colName:c,anchorRect:d}){let{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)(e?.op||"="),[x,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[i]);let g="IS NULL"!==m&&"IS NOT NULL"!==m,b=()=>{(!g||x.trim())&&t({op:m,value:x.trim(),enabled:!0})},v=window.innerWidth,j=d.left;return j+220>v-8&&(j=v-220-8),j<8&&(j=8),(0,a.createPortal)((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:j,top:d.bottom+2},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=>l(e.target.checked),className:"w-3 h-3 accent-brand"}),u("database.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:c})]}),(0,n.jsx)("select",{value:m,onChange:e=>h(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:tQ.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),g&&(0,n.jsx)("input",{type:"text",value:x,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),b())},placeholder:u("IN"===m?"database.commaValues":"LIKE"===m?"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:b,disabled:g&&!x.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:u("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:u("database.clearFilter")})]})]}),document.body)}function t8({result:e,loading:t,columns:r,page:l,totalPages:a,totalRows:i,onPageChange:c,filters:d,sort:u,onFilterChange:m,onSortChange:h,selectedRows:x,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:y,isAddingRow:w,newRowValues:k,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:L,onCellCopy:E}){let{t:M}=(0,o.Bd)(),[T,R]=(0,s.useState)(null),[$,P]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==T?(e.stopPropagation(),R(null)):null!==p?(e.stopPropagation(),y()):w&&(e.stopPropagation(),L()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[T,p,w,y,L]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:M("database.selectTableForData")});let I=e?.fields||[],B=e?.rows||[],D={};for(let e of r)D[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let F=B.length>0&&x.size===B.length,O=x.size>0&&!F;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:F,ref:e=>{e&&(e.indeterminate=O)},onChange:()=>{F?f(new Set):f(new Set(B.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.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?h({column:t,dir:"DESC"}):h(null):h({column:t,dir:"ASC"}))},children:[e.name,D[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:D[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(),T===e.name)return void R(null);let r=t.currentTarget.closest("th").getBoundingClientRect();P({left:r.left,bottom:r.bottom}),R(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"})})}),T===e.name&&(0,n.jsx)(t6,{filter:r||null,onApply:t=>{m(e.name,t),R(null)},onClear:()=>{m(e.name,null),R(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>R(null),colName:e.name,anchorRect:$})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[w&&(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:M("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:L,className:"text-[10px] text-muted-foreground hover:text-foreground",title:M("common.cancel"),children:"✕"})]})}),I.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:k[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))]}),B.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-accent/50 ${x.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:M("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:y,className:"text-[10px] text-muted-foreground hover:text-foreground",title:M("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:x.has(t),onChange:()=>{let e;(e=new Set(x)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.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(),E(t0(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)(t1,{text:t0(e[r.name])})},r.name))]},t))]})]}),0===B.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:M("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:w,className:"px-1.5 py-0.5 text-[10px] text-emerald-500 hover:text-emerald-400 disabled:opacity-30",children:M("database.addRow")}),(0,n.jsx)("span",{children:M("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(l-1),disabled:0===l,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[l+1," / ",a]}),(0,n.jsx)("button",{onClick:()=>c(l+1),disabled:l>=a-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function t9({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:l,error:a,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,to.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")}),l?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[l.command&&!l.fields?u("database.rowsAffected",{command:l.command,count:l.rowCount,duration:l.duration}):u("database.queryRows",{count:l.rows?.length??0,duration:l.duration}),l.truncated&&` ${u("database.resultTruncated")}`]})]})]}),a&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:a}),l?.fields&&l.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:l.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:l.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:l.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(t0(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)(t1,{text:t0(e[t.name])})},t.name))},t))})]})})]})}tH({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:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(t4,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/db/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});var t7=r(91334),re=r(38194),rt=r(88522),rr=r(72816);let rn=new tr.v;function rs(e){return e?Array.isArray(e)?e.join(""):e:""}function ro(e,t){return e&&e[t]?rs(e[t]):""}rn.use_classes=!0;let rl=(0,s.memo)(function({output:e}){if("stream"===e.output_type){let t=rs(e.text);if(!t)return null;let r=rn.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=rn.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=ro(t,"image/png"),s=ro(t,"image/jpeg"),o=ro(t,"image/svg+xml"),l=ro(t,"text/html"),a=ro(t,"text/markdown"),i=ro(t,"text/latex"),c=ro(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(l)return(0,n.jsx)("div",{className:"px-3 py-1 overflow-x-auto notebook-html-output",dangerouslySetInnerHTML:{__html:l}});if(a)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)(eP.T,{content:a})});if(i)return(0,n.jsx)("div",{className:"px-3 py-1",children:(0,n.jsx)(eP.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}),ra=(0,s.memo)(function({cell:e,isActive:t,isEditing:r,onSelect:o,onEdit:l,onStopEdit:a,onSourceChange:i,onRun:c,onDelete:d,onMoveUp:u,onMoveDown:m,onToggleType:h,isFirst:x,isLast:f}){let{resolvedTheme:p}=(0,rr.D)(),g=(0,s.useRef)(null),[b,v]=(0,s.useState)(e.source),j=(0,s.useCallback)(()=>{v(e.source),l()},[e.source,l]);(0,s.useEffect)(()=>{if(r&&g.current){g.current.focus();let e=g.current.value.length;g.current.setSelectionRange(e,e)}},[r]);let y=(0,s.useCallback)(()=>{let e=g.current;e&&(e.style.height="auto",e.style.height=e.scrollHeight+"px")},[]);(0,s.useEffect)(()=>{r&&y()},[r,b,y]);let w=(0,s.useCallback)(e=>{v(e.target.value),y()},[y]),k=(0,s.useCallback)(()=>{b!==e.source&&i(b),a()},[b,e.source,i,a]),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(),k();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,k]),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:h,className:"px-1 hover:text-brand",title:"Toggle type",children:S}),!x&&(0,n.jsx)("button",{onClick:u,className:"px-1 hover:text-brand",title:"Move up",children:"↑"}),!f&&(0,n.jsx)("button",{onClick:m,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:w,onBlur:k,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)(t7.A,{language:"python",style:"dark"===p?re.A:rt.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)(eP.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)(rl,{output:e},t))})]})]})]})});function ri({id:e,filePath:t,displayName:r,cwd:o,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:c,timestamp:d,onSelect:u,onClose:m,onToggleMaximize:h,onTitleMouseDown:x}){let{showToast:f}=(0,g.dj)(),[p,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(!0),[y,w]=(0,s.useState)(null),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),[M,T]=(0,s.useState)(null),[R,$]=(0,s.useState)("disconnected"),[P,I]=(0,s.useState)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(new Map),F=(0,s.useRef)(null),O=(0,s.useRef)(p);O.current=p;let A=(0,s.useCallback)(async()=>{j(!0),w(null);try{let e=await fetch("/api/jupyter/load",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({filePath:t,cwd:o})}),r=await e.json();if(!e.ok)throw Error(r.error||"Failed to load notebook");b(r.cells.map((e,t)=>({...e,index:t,isExecuting:!1}))),N(!1)}catch(e){w(e.message)}finally{j(!1)}},[t,o]);(0,s.useEffect)(()=>{A()},[A]);let W=(0,s.useCallback)(async()=>{if(!C){S(!0);try{let e=await fetch("/api/jupyter/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({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}))})}),r=await e.json();if(!e.ok)throw Error(r.error||"Failed to save");N(!1),f("Saved","success")}catch(e){f(e.message,"error")}finally{S(!1)}}},[t,o,p,C,f]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),W())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[W]);let z=(0,s.useCallback)(()=>{if(B.current&&B.current.readyState<=1)return;$("starting"),I(null);let t="https:"===window.location.protocol?"wss:":"ws:",r=new WebSocket(`${t}//${window.location.host}/ws/jupyter?bubbleId=${encodeURIComponent(e)}&cwd=${encodeURIComponent(o)}`);B.current=r,r.onopen=()=>{},r.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ready"===r)$("idle"),I(null);else if("status"===r){let e=t.execution_state;"idle"===e?$("idle"):"busy"===e&&$("busy")}else if("output"===r){let e=t.msg_id,r=t.msg_type,n=t.content,s=D.current.get(e);if(void 0===s)return;b(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)$("error"),I(t.message);else if("kernel_died"===r){for(let[,e]of($("dead"),I("Kernel died"),D.current))b(t=>t.map((t,r)=>r===e?{...t,isExecuting:!1}:t));D.current.clear()}},r.onclose=()=>{"error"!==R&&"dead"!==R&&$("disconnected")},r.onerror=()=>{$("error")}},[e,o,R]);(0,s.useEffect)(()=>()=>{B.current?.close()},[]);let H=(0,s.useCallback)(e=>{let t=O.current[e];if(!t||"code"!==t.cell_type)return;if(!B.current||B.current.readyState!==WebSocket.OPEN){z();let t=setInterval(()=>{B.current?.readyState===WebSocket.OPEN&&(clearInterval(t),H(e))},200);setTimeout(()=>clearInterval(t),15e3);return}let r=`cell-${e}-${Date.now()}`;D.current.set(r,e),b(t=>t.map((t,r)=>r===e?{...t,outputs:[],isExecuting:!0,execution_count:null}:t)),B.current.send(JSON.stringify({type:"execute",msg_id:r,code:t.source})),setTimeout(()=>{D.current.has(r)&&(D.current.delete(r),b(t=>t.map((t,r)=>r===e?{...t,isExecuting:!1}:t)))},3e5)},[z]);(0,s.useEffect)(()=>{let e=B.current;if(!e)return;let t=e=>{let t=D.current.get(e);void 0!==t&&(D.current.delete(e),b(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 D.current)t(e)};return e.addEventListener("message",r),()=>{e.removeEventListener("message",r)}},[R]);let _=(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();H(r);let n=setInterval(()=>{let e=O.current[r];e&&!e.isExecuting&&(clearInterval(n),t())},200)};t()},[p,H]),U=(0,s.useCallback)(()=>{B.current?.send(JSON.stringify({type:"interrupt"}))},[]),q=(0,s.useCallback)((e,t)=>{b(r=>r.map((r,n)=>n===e?{...r,source:t}:r)),N(!0)},[]),V=(0,s.useCallback)(e=>{b(t=>t.filter((t,r)=>r!==e)),N(!0),L===e&&E(null)},[L]),K=(0,s.useCallback)((e,t)=>{b(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)}),N(!0),E("up"===t?e-1:e+1)},[]),J=(0,s.useCallback)(e=>{b(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:[]}})),N(!0)},[]),X=(0,s.useCallback)((e,t)=>{let r={index:0,cell_type:e,source:"",outputs:[],execution_count:null,metadata:{},isExecuting:!1};b(e=>{let n=[...e],s=void 0!==t?t+1:n.length;return n.splice(s,0,r),n}),N(!0);let n=void 0!==t?t+1:p.length;E(n),T(n)},[p.length]),Y=(0,s.useMemo)(()=>{switch(R){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:P||"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,P]);return(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
9
+ relative transition-colors cursor-pointer
10
+ ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
11
+ ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:u,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:h,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{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(),h()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:a?`Exit maximize (${(0,to.Mu)()}+M)`:`Maximize (${(0,to.Mu)()}+M)`,children:a?(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(),m()},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(),_()},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(),U()},className:"px-1.5 py-0.5 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",title:"Interrupt",disabled:"busy"!==R,children:"⬛ Stop"}),(0,n.jsx)("div",{className:"w-px h-3 bg-border/50 mx-1"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),X("code",L??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(),X("markdown",L??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(),W()},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,to.Mu)()}+S)`,disabled:C,children:C?"Saving...":"Save"}),(0,n.jsx)("span",{className:"flex-1"}),P&&(0,n.jsx)("span",{className:"text-[10px] text-red-400 truncate max-w-[50%]",title:P,children:P}),"dead"===R&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),z()},className:"px-1.5 py-0.5 rounded text-brand hover:bg-accent transition-colors",children:"Restart"})]}),(0,n.jsx)("div",{ref:F,className:"overflow-y-auto",style:{height:(a&&i?i-41:c??360)-30},children:v?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground text-sm",children:"Loading notebook..."}):y?(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:y}),(0,n.jsx)("button",{onClick:A,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:()=>X("code"),className:"text-xs text-brand hover:underline",children:"+ Code cell"}),(0,n.jsx)("button",{onClick:()=>X("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)(ra,{cell:e,isActive:L===t,isEditing:M===t,onSelect:()=>E(t),onEdit:()=>{E(t),T(t)},onStopEdit:()=>T(null),onSourceChange:e=>q(t,e),onRun:()=>{"code"===e.cell_type&&H(t),t<p.length-1&&E(t+1)},onDelete:()=>V(t),onMoveUp:()=>K(t,"up"),onMoveDown:()=>K(t,"down"),onToggleType:()=>J(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:()=>X("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:()=>X("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"})]})]})})]})}tH({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:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(ri,{id:e.id,filePath:e.filePath,displayName:e.displayName,cwd:e.cwd,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/jupyter/shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bubbleId:e.id})})}catch{}}});let rc=[{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 rd(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 ru(e){return`\`${e.replace(/`/g,"``")}\``}function rm(e){try{let t=e.match(/\/\/[^/]+\/([^?]+)/);if(t)return t[1]}catch{}return""}function rh(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rx({text:e}){let[t,r]=(0,s.useState)(!1),[o,l]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,s.useRef)(!1),u=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{d.current||r(!1)},80)},[]),m=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),d.current=!1,c.current=setTimeout(()=>{let e=i.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=window.innerWidth,s=Math.min(600,n-t.left-8),o=s<200?Math.max(8,n-600-8):t.left,a=s<200?Math.min(600,n-16):s,c=window.innerHeight,d=t.top-8,u=c-t.bottom-8,m=d>u&&d>80;l({x:o,y:m?t.top-4:t.bottom+4,maxW:a,maxH:Math.max(60,m?d-4:u-4),above:m}),r(!0)},350)},[]),h=(0,s.useCallback)(()=>{u()},[u]),x=(0,s.useCallback)(()=>{d.current=!0,c.current&&clearTimeout(c.current)},[]),f=(0,s.useCallback)(()=>{d.current=!1,u()},[u]);return(0,n.jsxs)("span",{ref:i,className:"block truncate",onMouseEnter:m,onMouseLeave:h,children:[e,t&&(0,a.createPortal)((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:x,onMouseLeave:f,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)}),document.body)]})}async function rf(e,t){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(n.error||`HTTP ${r.status}`);return n}async function rp(e,t){let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(s.error||`HTTP ${n.status}`);return s}function rg({id:e,connectionString:t,displayName:r,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:m,timestamp:h,onTitleMouseDown:x}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,g.dj)(),[b,v]=(0,s.useState)("connecting"),[j,y]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[N,C]=(0,s.useState)(()=>rm(t)),[S,L]=(0,s.useState)([]),[E,M]=(0,s.useState)(null),[T,R]=(0,s.useState)("table"),[$,P]=(0,s.useState)("data"),[I,B]=(0,s.useState)([]),[D,F]=(0,s.useState)([]),[O,A]=(0,s.useState)([]),[W,z]=(0,s.useState)([]),[H,_]=(0,s.useState)(null),[U,q]=(0,s.useState)(0),[V,K]=(0,s.useState)(!1),[J,X]=(0,s.useState)(0),[Y,Q]=(0,s.useState)(new Set),[G,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[el,ea]=(0,s.useState)({}),[ei,ec]=(0,s.useState)({}),[ed,eu]=(0,s.useState)(null),[em,eh]=(0,s.useState)(""),[ex,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ey=(0,s.useCallback)(async()=>{v("connecting"),y("");try{let r=await rf("/api/mysql/connect",{id:e,connectionString:t});k(r.schemas||[]);let n=rm(t);r.schemas?.length>0&&n&&r.schemas.includes(n)?C(n):r.schemas?.length>0&&C(r.schemas[0]),v("connected")}catch(e){y(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{ey()},[ey]);let ew=(0,s.useCallback)(async()=>{if("connected"===b)try{let r=await rp("/api/mysql/schemas",{id:e,connectionString:t,schema:N});L(r.tables||[])}catch{}},[e,t,N,b]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async r=>{M(r),q(0),et(null),eo(!1),Q(new Set),Z(!1),ec({}),eu(null);try{let n=await rp("/api/mysql/columns",{id:e,connectionString:t,schema:N,table:r});B(n.columns||[]),F(n.primaryKeys||[]),A(n.foreignKeys||[]),z(n.indexes||[])}catch{}eN(r,0,{},null)},[e,t,N]),eN=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let l=s??ei,a=void 0!==o?o:ed;try{let s=`${ru(N)}.${ru(r)}`,{where:o,params:i}=function(e){let t=[],r=[];for(let[n,s]of Object.entries(e)){if(!s.enabled)continue;let e=ru(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}}(l),c=a?` ORDER BY ${ru(a.column)} ${a.dir}`:"",d=`SELECT * FROM ${s}${o}${c} LIMIT 50 OFFSET ${50*n}`,u=await rf("/api/mysql/query",{id:e,connectionString:t,sql:d,params:i});_(u);let m=`SELECT count(*) AS cnt FROM ${s}${o}`,h=await rf("/api/mysql/query",{id:e,connectionString:t,sql:m,params:i});X(h.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,N,ei,ed]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await rf("/api/mysql/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!H||!E)return;let r=H.rows[ee],n=[],s=[];for(let e of I)void 0!==er[e.name]&&er[e.name]!==rh(r[e.name]??"")&&(n.push(`${ru(e.name)} = ?`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]));if(0===n.length)return void et(null);let o=D.length>0?D:I.map(e=>e.name),l=[];for(let e of o)null===r[e]||void 0===r[e]?l.push(`${ru(e)} IS NULL`):(l.push(`${ru(e)} = ?`),s.push(r[e]));let a=`UPDATE ${ru(N)}.${ru(E)} SET ${n.join(", ")} WHERE ${l.join(" AND ")}`;try{await rf("/api/mysql/query",{id:e,connectionString:t,sql:a,params:s}),et(null),eN(E,U,ei,ed)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,H,E,I,D,er,e,t,N,eN,U,ei,ed]),eL=(0,s.useCallback)(async()=>{if(!E)return;let r=[],n=[],s=[];for(let e of I)void 0!==el[e.name]&&""!==el[e.name]&&(r.push(ru(e.name)),n.push(el[e.name]),s.push("?"));if(0===r.length)return;let o=`INSERT INTO ${ru(N)}.${ru(E)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await rf("/api/mysql/query",{id:e,connectionString:t,sql:o,params:n}),eo(!1),ea({}),eN(E,U,ei,ed)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[E,I,el,e,t,N,eN,U,ei,ed]),eE=(0,s.useCallback)(async()=>{if(0===Y.size||!H||!E)return;let r=D.length>0?D:I.map(e=>e.name),n=0;for(let s of Array.from(Y).sort((e,t)=>t-e)){let o=H.rows[s];if(!o)continue;let l=[],a=[];for(let e of r)null===o[e]||void 0===o[e]?l.push(`${ru(e)} IS NULL`):(l.push(`${ru(e)} = ?`),a.push(o[e]));let i=`DELETE FROM ${ru(N)}.${ru(E)} WHERE ${l.join(" AND ")} LIMIT 1`;try{await rf("/api/mysql/query",{id:e,connectionString:t,sql:i,params:a})}catch{n++}}Q(new Set),Z(!1),eN(E,U,ei,ed),n>0&&alert(f("mysql.deleteRowsFailed",{count:n}))},[Y,H,E,D,I,e,t,N,eN,U,ei,ed]),eM=(0,s.useCallback)(async r=>{if(!E)return;if(Y.size>0&&H){let e,t=H.fields.map(e=>e.name),n=Array.from(Y).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 ${ru(N)}.${ru(E)}`;try{let s=await fetch("/api/mysql/export",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,connectionString:t,sql:n,format:r})});if(!s.ok)throw Error("Export failed");let o=await s.blob(),l=URL.createObjectURL(o),a=document.createElement("a");a.href=l,a.download=`${E}.${r}`,a.click(),URL.revokeObjectURL(l)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[E,e,t,N,Y,H]),eT=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eR=Math.max(1,Math.ceil(J/50)),e$=(0,s.useCallback)(e=>{E&&(q(e),eN(E,e,ei,ed))},[E,eN,ei,ed]),eP=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ec(r),q(0),Q(new Set),E&&eN(E,0,r,ed)},[ei,ed,E,eN]),eI=(0,s.useCallback)(()=>{ec({}),q(0),Q(new Set),E&&eN(E,0,{},ed)},[ed,E,eN]),eB=(0,s.useCallback)(e=>{eu(e),q(0),Q(new Set),E&&eN(E,0,ei,e)},[ei,E,eN]);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
+ ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
14
+ ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{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"===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:f("mysql.connectionFailed")}),"connected"===b&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:f("mysql.connected")}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rd(h)}),(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:a?f("browser.exitMaximize",{modKey:(0,to.Mu)()}):f("browser.maximize",{modKey:(0,to.Mu)()}),children:a?(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:a&&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"}),f("mysql.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:ey,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"===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:[w.length>1?(0,n.jsx)("select",{value:N,onChange:e=>{C(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:N}),(0,n.jsx)("button",{onClick:ew,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:()=>R(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${T===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:[S.filter(e=>"table"===T?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>ek(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${E===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)(rx,{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===S.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:()=>P(e),className:`px-3 py-1.5 text-xs transition-colors ${$===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)),E&&"data"===$&&(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:eI,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:"|"})]}),Y.size>0&&!G&&(0,n.jsx)("button",{onClick:()=>Z(!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:Y.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:eE,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:()=>Z(!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:()=>eM("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("mysql.copyCsvSelected"):f("mysql.copyCsvAll"),children:Y.size>0?f("mysql.copyCSV"):f("mysql.CSV")}),(0,n.jsx)("button",{onClick:()=>eM("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:Y.size>0?f("mysql.copyJsonSelected"):f("mysql.copyJsonAll"),children:Y.size>0?f("mysql.copyJSON"):f("mysql.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:E||"sql"===$?"structure"===$?(0,n.jsx)(rb,{columns:I,primaryKeys:D,foreignKeys:O,indexes:W}):"data"===$?(0,n.jsx)(rj,{result:H,loading:V,columns:I,page:U,totalPages:eR,totalRows:J,onPageChange:e$,filters:ei,sort:ed,onFilterChange:eP,onSortChange:eB,selectedRows:Y,onSelectedRowsChange:e=>{Q(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!H)return;let t=H.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":rh(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:el,onStartAdd:()=>{eo(!0),ea({})},onNewRowChange:(e,t)=>ea(r=>({...r,[e]:t})),onSaveNewRow:eL,onCancelAdd:()=>{eo(!1),ea({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(ry,{sqlInput:em,onSqlChange:eh,onExecute:eC,onKeyDown:eT,result:ex,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")})})]})]})]}),!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"===b?"bg-green-500":"error"===b?"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")}[b]}),"connected"===b&&E&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:E}),(0,n.jsx)("span",{className:"flex-1"}),h&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rd(h)})]})]})})}function rb({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:l}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:l("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:l("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:l("mysql.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("mysql.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("mysql.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:l("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:l("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:l("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:l("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 rv({filter:e,onApply:t,onClear:r,onToggle:l,onClose:i,colName:c,anchorRect:d}){let{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)(e?.op||"="),[x,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[i]);let g="IS NULL"!==m&&"IS NOT NULL"!==m,b=()=>{(!g||x.trim())&&t({op:m,value:x.trim(),enabled:!0})},v=window.innerWidth,j=d.left;return j+220>v-8&&(j=v-220-8),j<8&&(j=8),(0,a.createPortal)((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:j,top:d.bottom+2},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=>l(e.target.checked),className:"w-3 h-3 accent-brand"}),u("mysql.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:c})]}),(0,n.jsx)("select",{value:m,onChange:e=>h(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:rc.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),g&&(0,n.jsx)("input",{type:"text",value:x,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),b())},placeholder:u("IN"===m?"mysql.commaValues":"LIKE"===m?"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:b,disabled:g&&!x.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:u("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:u("mysql.clearFilter")})]})]}),document.body)}function rj({result:e,loading:t,columns:r,page:l,totalPages:a,totalRows:i,onPageChange:c,filters:d,sort:u,onFilterChange:m,onSortChange:h,selectedRows:x,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:y,isAddingRow:w,newRowValues:k,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:L,onCellCopy:E}){let{t:M}=(0,o.Bd)(),[T,R]=(0,s.useState)(null),[$,P]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==T?(e.stopPropagation(),R(null)):null!==p?(e.stopPropagation(),y()):w&&(e.stopPropagation(),L()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[T,p,w,y,L]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:M("mysql.selectTableForData")});let I=e?.fields||[],B=e?.rows||[],D={};for(let e of r)D[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let F=B.length>0&&x.size===B.length,O=x.size>0&&!F;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:F,ref:e=>{e&&(e.indeterminate=O)},onChange:()=>{F?f(new Set):f(new Set(B.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.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?h({column:t,dir:"DESC"}):h(null):h({column:t,dir:"ASC"}))},children:[e.name,D[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:D[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(),T===e.name)return void R(null);let r=t.currentTarget.closest("th").getBoundingClientRect();P({left:r.left,bottom:r.bottom}),R(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"})})}),T===e.name&&(0,n.jsx)(rv,{filter:r||null,onApply:t=>{m(e.name,t),R(null)},onClear:()=>{m(e.name,null),R(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>R(null),colName:e.name,anchorRect:$})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[w&&(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:M("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:L,className:"text-[10px] text-muted-foreground hover:text-foreground",title:M("common.cancel"),children:"✕"})]})}),I.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:k[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))]}),B.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-accent/50 ${x.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:M("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:y,className:"text-[10px] text-muted-foreground hover:text-foreground",title:M("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:x.has(t),onChange:()=>{let e;(e=new Set(x)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.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(),E(rh(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)(rx,{text:rh(e[r.name])})},r.name))]},t))]})]}),0===B.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:M("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:w,className:"px-1.5 py-0.5 text-[10px] text-emerald-500 hover:text-emerald-400 disabled:opacity-30",children:M("mysql.addRow")}),(0,n.jsx)("span",{children:M("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(l-1),disabled:0===l,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[l+1," / ",a]}),(0,n.jsx)("button",{onClick:()=>c(l+1),disabled:l>=a-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function ry({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:l,error:a,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,to.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")}),l?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[l.command&&!l.fields?u("mysql.rowsAffected",{command:l.command,count:l.rowCount,duration:l.duration}):u("mysql.queryRows",{count:l.rows?.length??0,duration:l.duration}),l.truncated&&` ${u("mysql.resultTruncated")}`]})]})]}),a&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:a}),l?.fields&&l.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:l.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:l.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:l.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(rh(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)(rx,{text:rh(e[t.name])})},t.name))},t))})]})})]})}async function rw(e,t){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(n.error||`HTTP ${r.status}`);return n}tH({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:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rg,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/mysql/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});let rk={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 rN({type:e}){let t=rk[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 rC({text:e}){let[t,r]=(0,s.useState)(!1),[o,l]=(0,s.useState)({x:0,y:0,above:!0}),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{let e=i.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=t.top>window.innerHeight/2;l({x:t.left,y:n?t.top-4:t.bottom+4,above:n}),r(!0)},350)},[]),u=(0,s.useCallback)(()=>{c.current&&clearTimeout(c.current),r(!1)},[]);return(0,n.jsxs)("span",{ref:i,className:"block truncate",onMouseEnter:d,onMouseLeave:u,children:[e,t&&(0,a.createPortal)((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}),document.body)]})}function rS({id:e,connectionString:t,displayName:r,selected:l,maximized:a,expandedHeight:i,bubbleContentHeight:c,onSelect:d,onClose:u,onToggleMaximize:m,timestamp:h,onTitleMouseDown:x}){var f;let{t:p}=(0,o.Bd)(),{showToast:b}=(0,g.dj)(),[v,j]=(0,s.useState)("connecting"),[y,w]=(0,s.useState)(""),[k,N]=(0,s.useState)(null),[C,S]=(0,s.useState)([]),[L,E]=(0,s.useState)("0"),[M,T]=(0,s.useState)(!1),[R,$]=(0,s.useState)("*"),[P,I]=(0,s.useState)(!1),[B,D]=(0,s.useState)(null),[F,O]=(0,s.useState)(null),[A,W]=(0,s.useState)(!1),[z,H]=(0,s.useState)(null),[_,U]=(0,s.useState)(!1),[q,V]=(0,s.useState)("data"),[K,J]=(0,s.useState)(""),[X,Y]=(0,s.useState)(""),[Q,G]=(0,s.useState)([]),[Z,ee]=(0,s.useState)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useCallback)(async()=>{j("connecting"),w("");try{let r=await rw("/api/redis/connect",{id:e,connectionString:t});N(r),j("connected")}catch(e){w(e instanceof Error?e.message:String(e)),j("error")}},[e,t]);(0,s.useEffect)(()=>{en()},[en]);let es=(0,s.useCallback)(async(r,n,s)=>{I(!0);try{let o=await rw("/api/redis/keys",{id:e,connectionString:t,pattern:r,cursor:n,count:200});S(e=>s?[...e,...o.keys]:o.keys),E(o.cursor),T(o.hasMore)}catch{}I(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===v&&es(R,"0",!1)},[v]);let eo=(0,s.useCallback)(()=>{D(null),O(null),es(R,"0",!1)},[R,es]),el=(0,s.useCallback)(async r=>{D(r),W(!0),H(null),U(!1);try{let n=await rw("/api/redis/get",{id:e,connectionString:t,key:r});O(n)}catch(e){O(null),b(e instanceof Error?e.message:p("redis.loadFailed"))}W(!1)},[e,t,b]),ea=(0,s.useCallback)(async()=>{if(B)try{await rw("/api/redis/delete",{id:e,connectionString:t,keys:[B]}),D(null),O(null),U(!1),es(R,"0",!1)}catch(e){b(e instanceof Error?e.message:p("redis.deleteFailed"))}},[B,e,t,R,es,b]),ei=(0,s.useCallback)(async()=>{if(B&&null!==z)try{await rw("/api/redis/set",{id:e,connectionString:t,key:B,value:z,type:"string"}),H(null),el(B),b(p("common.saved"))}catch(e){b(e instanceof Error?e.message:p("redis.saveFailed"))}},[B,z,e,t,el,b]),ec=(0,s.useCallback)(async()=>{try{let r=await rw("/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"===v&&"info"===q&&ec()},[v,q,ec]);let ed=(0,s.useCallback)(async()=>{let r,n=X.trim();if(!n)return;ee(!0),Y("");let s=[],o=/(?:"([^"]*)")|(?:'([^']*)')|(\S+)/g;for(;null!==(r=o.exec(n));)s.push(r[1]??r[2]??r[3]);let l=s[0]||"",a=s.slice(1);try{let r=await rw("/api/redis/command",{id:e,connectionString:t,command:l,args:a});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)},[X,e,t]);return(0,s.useEffect)(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[Q]),(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
+ ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
17
+ ${a?"":l?"border-brand":"border-brand/30"}`,onClick:a?void 0:d,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:x,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${a?"bg-card":"bg-card/50"}`,style:a?{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"===v&&(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"===v&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:p("common.connectionFailed")}),"connected"===v&&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"}),h&&(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}`}(h)}),(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:a?p("browser.exitMaximize",{modKey:(0,to.Mu)()}):p("browser.maximize",{modKey:(0,to.Mu)()}),children:a?(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:a&&i?i-41:c??360},className:"flex overflow-hidden",children:["connecting"===v&&(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"===v&&(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:y}),(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"===v&&(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:R,onChange:e=>$(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(R,"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:[C.map(e=>(0,n.jsxs)("div",{onClick:()=>el(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${B===e.key?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)(rN,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rC,{text:e.key})})]},e.key)),0===C.length&&!P&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:p("redis.noKeys")}),P&&(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&&!P&&(0,n.jsx)("button",{onClick:()=>es(R,L,!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:[C.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:()=>V(e),className:`px-3 py-1.5 text-xs transition-colors ${q===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)),B&&"data"===q&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[F&&(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`:""}`}(F.ttl,p),null!==F.size?` \xb7 ${null==(f=F.size)?"":f<1024?`${f} B`:f<1048576?`${(f/1024).toFixed(1)} KB`:`${(f/1048576).toFixed(1)} MB`}`:""]}),_?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-[10px] text-destructive",children:[p("common.confirm"),"?"]}),(0,n.jsx)("button",{onClick:ea,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:()=>U(!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:()=>U(!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"===q?(0,n.jsx)(rL,{selectedKey:B,keyValue:F,keyLoading:A,editingValue:z,onStartEdit:e=>H(e),onEditChange:H,onSaveEdit:ei,onCancelEdit:()=>H(null),onCellCopy:e=>{navigator.clipboard.writeText(e),b(p("common.copied"))}}):"info"===q?(0,n.jsx)(rE,{infoText:K,onRefresh:ec}):(0,n.jsx)(rM,{cliInput:X,onInputChange:Y,onExecute:ed,history:Q,loading:Z,endRef:et,inputRef:er})})]})]})]})]})})}function rL({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:l,onEditChange:a,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:m,value:h}=t;if("string"===m){let t=String(h??""),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)(rN,{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:()=>l(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=>a(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"===m){let t=Object.entries(h||{});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)(rN,{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)(rC,{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)(rC,{text:t})})]},e))})]})})]})}if("list"===m){let t=h?.items||[],r=h?.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)(rN,{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)(rC,{text:e})})]},t))})]})})]})}if("set"===m){let t=h?.items||[],r=h?.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)(rN,{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)(rC,{text:e})})},t))})]})})]})}if("zset"===m){let t=h?.items||[],r=h?.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)(rN,{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)(rC,{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"===m){let t=h?.entries||[],r=h?.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)(rN,{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)(rC,{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:m})})}function rE({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=[],l=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))l={title:e.replace(/^#\s*/,""),items:[]},s.push(l);else if(l&&e.includes(":")){let t=e.indexOf(":");l.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 rM({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:l,endRef:a,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:a})]}),(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||l||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:l}),l&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}tH({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:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rS,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/redis/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});let rT=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function rR(e,t){return rT[t.indexOf(e)%rT.length]}async function r$(e,t){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(n.error||`HTTP ${r.status}`);return n}function rP(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 rI({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),a=(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),[m,h]=(0,s.useState)(null),x=(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&&a.current.length>0){let e=t/n.w,s=r/n.h;a.current.forEach(t=>{t.x=(t.x||0)*e,t.y=(t.y||0)*s})}d.current={w:t,h:r};let s=l.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}),a.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(a.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=a.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),l=r/s*o,a=n/s*o;u[e].vx+=l,u[t].vx-=l,u[e].vy+=a,u[t].vy-=a}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),l=Math.sqrt(s*s+o*o)||1,a=(l-100)*.01,i=s/l*a,c=o/l*a;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 m=l.current?.getContext("2d");m&&(m.clearRect(0,0,s,o),m.lineWidth=1.5,t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;m.strokeStyle="#666",m.beginPath(),m.moveTo(r.x,r.y),m.lineTo(n.x,n.y),m.stroke();let s=Math.atan2(n.y-r.y,n.x-r.x),o=n.x-24*Math.cos(s),l=n.y-24*Math.sin(s);m.fillStyle="#666",m.beginPath(),m.moveTo(o,l),m.lineTo(o-8*Math.cos(s-.3),l-8*Math.sin(s-.3)),m.lineTo(o-8*Math.cos(s+.3),l-8*Math.sin(s+.3)),m.closePath(),m.fill(),m.font="9px system-ui",m.fillStyle="#999",m.textAlign="center",m.fillText(t.type,(r.x+n.x)/2,(r.y+n.y)/2-4)}),u.forEach(e=>{let t=e.labels[0]||"",n=t?rR(t,r):"#888";m.beginPath(),m.arc(e.x,e.y,20,0,2*Math.PI),m.fillStyle=n,m.fill();let s=x.current?.id===e.id;m.strokeStyle=s?"#fff":"rgba(255,255,255,0.3)",m.lineWidth=s?2.5:1,m.stroke(),m.font="10px system-ui",m.fillStyle="#fff",m.textAlign="center",m.textBaseline="middle";let o=String(e.properties.name||e.properties.title||e.properties.id||t||e.id);m.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=l.current?.getBoundingClientRect();if(!t)return null;let r=e.clientX-t.left,n=e.clientY-t.top;return a.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:l,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=f(e);if(t){let r=l.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=l.current.getBoundingClientRect(),r=a.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);x.current=t,h(t)}},onMouseUp:()=>{c.current=null},onMouseLeave:()=>{c.current=null,x.current=null,h(null)}}),m&&!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:[m.labels.join(", ")," #",String(m.id)]}),Object.entries(m.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 rB({id:e,connectionString:t,displayName:r,selected:o,maximized:l,expandedHeight:a,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,timestamp:m,onTitleMouseDown:h}){let[x,f]=(0,s.useState)("connecting"),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(null),[j,y]=(0,s.useState)(null),[w,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)("labels"),[S,L]=(0,s.useState)(""),[E,M]=(0,s.useState)(null),[T,R]=(0,s.useState)(!1),[$,P]=(0,s.useState)(""),I=(0,s.useRef)(null),[B,D]=(0,s.useState)([]),[F,O]=(0,s.useState)([]),[A,W]=(0,s.useState)("schema"),z=(0,s.useCallback)(async()=>{f("connecting");try{let r=await r$("/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)(()=>{z()},[z]);let H=(0,s.useCallback)(async()=>{k(!0);try{let r=await r$("/api/neo4j/schema",{id:e,connectionString:t});y(r)}catch{}k(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===x&&H()},[x,H]);let _=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){R(!0),P("");try{var s;let r,o,l=await r$("/api/neo4j/query",{id:e,connectionString:t,cypher:n});M(l);let{nodes:a,rels:i}=(s=l.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});a.length>0&&(D(a),O(i))}catch(e){P(e instanceof Error?e.message:String(e))}R(!1)}},[e,t,S]),U=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;L(t),W("cypher"),_(t)},[_]),q=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;L(t),W("graph"),_(t)},[_]);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:h,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"===x&&(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"===x&&(0,n.jsx)("span",{className:"text-[10px] text-emerald-500 flex-shrink-0",children:"Connected"}),"error"===x&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:"Error"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rP(m)}),"connected"===x&&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"===x&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),H(),z()},disabled:w,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 ${w?"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:l?(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:l&&a?a-41:i??360},className:"flex flex-col overflow-hidden",children:["connecting"===x&&(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"===x&&(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:z,className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Retry"})]}),"connected"===x&&(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:()=>W(e),className:`px-3 py-1.5 text-xs transition-colors ${A===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"===A&&(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:[w&&(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..."]}),!w&&"labels"===N&&j?.labels.map(e=>(0,n.jsxs)("div",{onClick:()=>U(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:rR(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)),!w&&"relationships"===N&&j?.relationshipTypes.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:"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)),!w&&"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)),!w&&"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)),!w&&"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"===A&&(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:I,value:S,onChange:e=>L(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),_())},placeholder:`Enter Cypher query (${(0,to.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,to.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>_(),disabled:T||!S.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:T?"Running...":"Execute"})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[$&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:$}),E&&!$&&(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:[E.records.length," rows"]}),(0,n.jsxs)("span",{children:[E.duration,"ms"]}),Object.entries(E.counters).filter(([,e])=>e>0).map(([e,t])=>(0,n.jsxs)("span",{children:[e,": ",t]},e))]}),E.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:E.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:E.records.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-accent/50",children:E.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"===A&&(0,n.jsx)("div",{className:"flex-1 relative",children:0===B.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),_(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)(rI,{nodes:B,rels:F,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!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"===x?"bg-green-500":"error"===x?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:"Connecting",connected:"Connected",error:"Error"}[x]}),"connected"===x&&b&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:b.edition}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rP(m)})]})]})})}function rD(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}tH({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:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d}){return(0,n.jsx)(rB,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:l,onSelect:a,onClose:i,onToggleMaximize:c,onTitleMouseDown:d})},async onClose(e){try{await fetch("/api/neo4j/disconnect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id})})}catch{}}});let rF=new Set(["zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]);function rO({onAdd:e,onCancel:t}){let{t:r}=(0,o.Bd)(),[l,a]=(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:l,onChange:e=>a(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(),l.trim()&&i.trim()&&e(l.trim(),i.trim()))}})]})}function rA({label:e,commands:t,isAdding:r,onStartAdd:s,onAdd:l,onCancelAdd:a,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)(tm.A,{className:"w-3.5 h-3.5"})})]}),r&&(0,n.jsx)(rO,{onAdd:(e,t)=>l(e,t),onCancel:a}),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)(ty.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)(tj.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)(eJ.A,{className:"w-3 h-3"})})]})},t))]})}function rW({cwd:e,show:t,onClose:r,onExecute:l,onAddPluginItem:a}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)([]),[h,x]=(0,s.useState)(null),f=(0,s.useRef)(null),p=(0,s.useCallback)(async()=>{try{let[t,r]=await Promise.all([fetch("/api/services/config?scope=global"),fetch(`/api/services/config?cwd=${encodeURIComponent(e)}`)]);if(t.ok){let e=await t.json();d(e.customCommands||[])}if(r.ok){let e=await r.json();m(e.customCommands||[])}}catch(e){console.error("Failed to load commands:",e)}},[e]);(0,s.useEffect)(()=>{t&&queueMicrotask(()=>p())},[t,p]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{f.current&&!f.current.contains(e.target)&&(r(),x(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let g=(0,s.useCallback)(async e=>{d(e);try{await fetch("/api/services/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:"global",customCommands:e})})}catch(e){console.error("Failed to save global commands:",e)}},[]),b=(0,s.useCallback)(async t=>{m(t);try{await fetch("/api/services/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,customCommands:t})})}catch(e){console.error("Failed to save project commands:",e)}},[e]),v=(0,s.useCallback)(e=>{r();let t=tU(e);t?a?.(t.type,e.trim()):l(e)},[r,l,a]);return t?(0,n.jsxs)("div",{ref:f,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)(rA,{label:i("console.globalCommands"),commands:c,isAdding:"global"===h,onStartAdd:()=>x("global"),onAdd:(e,t)=>{g([...c,{name:e,command:t}]),x(null)},onCancelAdd:()=>x(null),onDelete:e=>g(c.filter((t,r)=>r!==e)),onExecute:v}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(rA,{label:i("console.projectCommands"),commands:u,isAdding:"project"===h,onStartAdd:()=>x("project"),onAdd:(e,t)=>{b([...u,{name:e,command:t}]),x(null)},onCancelAdd:()=>x(null),onDelete:e=>b(u.filter((t,r)=>r!==e)),onExecute:v})]}):null}function rz({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:l,onGridLayoutChange:a,onExecute:i,onAddPluginItem:c,onShowEnvManager:d,onOpenZsh:u,onOpenNote:m}){let{t:h}=(0,o.Bd)(),[x,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(-1),[b,v]=(0,s.useState)(""),[j,y]=(0,s.useState)([]),[w,k]=(0,s.useState)(0),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)([]),[T,R]=(0,s.useState)(!1),[$,P]=(0,s.useState)(0),I=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(!1),{projectCommands:F,globalCommands:O,expandCustomCommand:A,loadQuickCommands:W}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),l=(0,s.useCallback)(async()=>{try{let[t,n]=await Promise.all([fetch(`/api/services/config?cwd=${encodeURIComponent(e)}`),fetch("/api/services/config?scope=global")]);if(t.ok){let e=await t.json();r(e.customCommands||[])}if(n.ok){let e=await n.json();o(e.customCommands||[])}}catch{}},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>l())},[l]);let a=[...t,...n],i=(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),l=t.find(e=>e.name===o)??n.find(e=>e.name===o);return l?l.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:a,projectCommands:t,globalCommands:n,expandCustomCommand:i,loadQuickCommands:l}}(e);(0,s.useEffect)(()=>{I.current?.focus()},[]),(0,s.useEffect)(()=>{if(x.startsWith("/")){let e=x.slice(1).toLowerCase(),t=[...F.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({...e,scope:"project"})),...O.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({...e,scope:"global"}))];queueMicrotask(()=>{M(t),R(t.length>0),P(0)})}else queueMicrotask(()=>R(!1))},[x,F,O]),(0,s.useEffect)(()=>{if(T&&B.current){let e=B.current.children[$];e?.scrollIntoView({block:"nearest"})}},[$,T]);let z=(0,s.useCallback)(e=>{R(!1);let t=e.command,r=tU(t);r?c?.(r.type,t.trim()):i(t),f("")},[i,c]),H=(0,s.useCallback)(e=>{if(e.preventDefault(),D.current||!x.trim())return;let t=A(x)??x,r=tU(t);r?c?.(r.type,t.trim()):i(t),f(""),g(-1),v("")},[x,i,c,A]),_=(0,s.useCallback)(async()=>{if(!I.current)return;let e=I.current.selectionStart||0;try{let r=await fetch("/api/terminal/autocomplete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,input:x,cursorPosition:e})});if(r.ok){let e=await r.json();if(e.suggestions&&e.suggestions.length>0&&(y(e.suggestions),k(0),C(!0),1===e.suggestions.length)){let t=x.substring(0,e.replaceStart),r=x.substring(e.replaceEnd),n=t+e.suggestions[0]+r;f(n),C(!1),setTimeout(()=>{if(I.current){let t=e.replaceStart+e.suggestions[0].length;I.current.setSelectionRange(t,t)}},0)}}}catch(e){console.error("Autocomplete error:",e)}},[t,x]),U=(0,s.useCallback)(e=>{if(!I.current)return;let t=I.current.selectionStart||0,r=x.substring(0,t),n=x.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;f(x.substring(0,o)+e+n),C(!1),setTimeout(()=>{if(I.current){let t=o+e.length;I.current.setSelectionRange(t,t)}},0)},[x]),q=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if(T&&E.length>0){if("ArrowUp"===e.key){e.preventDefault(),P(e=>(e-1+E.length)%E.length);return}if("ArrowDown"===e.key){e.preventDefault(),P(e=>(e+1)%E.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),z(E[$]);return}if("Escape"===e.key){e.preventDefault(),R(!1);return}}if("Tab"===e.key){if(e.preventDefault(),N&&j.length>0){let e=(w+1)%j.length;k(e),U(j[e])}else _();return}if("Escape"===e.key&&N){e.preventDefault(),C(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===p&&v(x);let r=-1===p?t.length-1:Math.max(0,p-1);g(r),f(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===p)return;let r=p+1;r>=t.length?(g(-1),f(b)):(g(r),f(t[r]))}}},[p,x,b,N,j,w,_,U,T,E,$,z,r]);return(0,n.jsx)("div",{className:"border-t border-border p-4",children:(0,n.jsxs)("form",{onSubmit:H,className:"relative flex gap-2 items-center",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{S||W(),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:h("console.quickCommands"),children:(0,n.jsx)(tp.A,{className:"w-4 h-4"})}),(0,n.jsx)(rW,{cwd:e,show:S,onClose:()=>L(!1),onExecute:i,onAddPluginItem:c})]}),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:()=>a(!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:l?h("console.singleColumn"):h("console.dualColumn"),children:l?(0,n.jsx)(tg.A,{className:"w-4 h-4"}):(0,n.jsx)(tb.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:d,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)(tv.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.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:I,type:"text",value:x,onChange:e=>{f(e.target.value),-1!==p&&(g(-1),v("")),C(!1)},onKeyDown:q,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"}),T&&E.length>0&&(0,n.jsx)("div",{ref:B,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:()=>z(e),className:`flex items-center gap-3 px-3 py-1.5 cursor-pointer text-sm ${t===$?"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}`))}),N&&j.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:j.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>U(e),className:`w-full px-3 py-1.5 text-left text-sm font-mono hover:bg-accent transition-colors ${t===w?"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 rH({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:l}=(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:l("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:l("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"})})})]})}function r_({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:l,onOpenNote:a}){let{t:i}=(0,o.Bd)(),{consoleItems:c,scrollRef:d,selectedCommandId:u,setSelectedCommandId:m,interruptCommand:h,sendStdin:x,deleteCommand:f,rerunCommand:p,ptySizeRef:g,resizePty:b,executeCommand:v,addPluginItem:j,closePluginItem:y,sleepingBubbles:w,handleBubbleSleep:k,handleBubbleWake:N,scrollToBottom:C,currentCwd:S,commandHistoryRef:L,setCustomEnv:E,setAliases:M,saveBubbleOrder:T,hasMoreHistory:R,loadHistory:$,currentPage:P,isLoadingHistory:I,subscribePtyOutput:B,subscribePtyReset:D}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,l]=(0,s.useState)([]),[a,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(new Set),[u,m]=(0,s.useState)(t||e),[h,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(null),[y,w]=(0,s.useState)({}),[k,N]=(0,s.useState)({}),[C,S]=(0,s.useState)(null),L=(0,s.useRef)(null),E=(0,s.useRef)(new Map),M=(0,s.useRef)(new Map),T=(0,s.useRef)(new Set),R=(0,s.useRef)([]),$=(0,s.useRef)(new Map),P=(0,s.useRef)(new Map),I=(0,s.useRef)(new Map),B=(0,s.useRef)(null),D=(0,s.useRef)(null),F=(0,s.useRef)([]),O=(0,s.useRef)(null);(0,s.useEffect)(()=>{n?.(e)},[]);let A=(0,s.useCallback)(()=>{if(E.current.size>0){let e=new Map(E.current);E.current.clear(),l(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}L.current=null},[]),W=(0,s.useCallback)((e,t)=>{if(T.current.has(e)){let r=P.current.get(e);if(r&&r.size>0)for(let e of r)e(t);else I.current.has(e)||I.current.set(e,[]),I.current.get(e).push(t);return}let r=(M.current.get(e)||"")+t;if(r.length>2097152){let t=function(e,t){let r=e.slice(-2097152),n=0;if(r.length>0){let e=r.charCodeAt(0);e>=56320&&e<=57343&&(n=1)}let s=Math.min(r.length,64);for(let e=n;e<s;e++){let t=r.charCodeAt(e);if(27===t){n=e;break}if((!(t>=48)||!(t<=63))&&59!==t&&63!==t&&32!==t){t>=64&&t<=126&&(n=e+1);break}}return n>0?r.slice(n):r}(r,0);M.current.set(e,t),E.current.set(e,t)}else M.current.set(e,r),E.current.set(e,r);null===L.current&&(L.current=requestAnimationFrame(A))},[A]),z=(0,s.useCallback)((e,t=!1)=>{M.current.delete(e),T.current.delete(e),E.current.delete(e),I.current.delete(e),t||(P.current.delete(e),_.current.delete(e))},[]),H=(0,s.useCallback)((e,t)=>{P.current.has(e)||P.current.set(e,new Set),P.current.get(e).add(t);let r=I.current.get(e);if(r&&r.length>0){for(let e of r)t(e);I.current.delete(e)}return()=>{P.current.get(e)?.delete(t)}},[]),_=(0,s.useRef)(new Map),U=(0,s.useCallback)((e,t)=>(_.current.has(e)||_.current.set(e,new Set),_.current.get(e).add(t),()=>{_.current.get(e)?.delete(t)}),[]),q=(0,s.useCallback)(e=>(null!==L.current&&(cancelAnimationFrame(L.current),L.current=null),A(),M.current.get(e)||""),[A]),V=(0,s.useCallback)(()=>{O.current&&(O.current.scrollTop=O.current.scrollHeight)},[]),K=(0,s.useCallback)(async(t=0)=>{if(r){x(!0);try{let n=await fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&page=${t}&pageSize=100`);if(n.ok){let e=await n.json(),r=[],s=[],o=new Set;for(let t of e.entries){let e=t_(t.type);if(e){let r=e.fromHistory(t);s.push({id:t.id,_type:t.type,timestamp:t.timestamp,...r}),t.sleeping&&o.add(t.id)}else{if(t.running)continue;r.push({id:t.id.includes("-")&&3===t.id.split("-").length?t.id:rD(),command:t.command,output:t.output,exitCode:t.exitCode,isRunning:!1,timestamp:t.timestamp,cwd:t.cwd,usePty:t.usePty})}}0===t?(l(r),i(s),o.size>0&&d(o)):(l(e=>{let t=new Set(e.map(e=>e.id)),n=r.filter(e=>!t.has(e.id));return[...e,...n]}),i(e=>{let t=new Set(e.map(e=>e.id)),r=s.filter(e=>!t.has(e.id));return[...e,...r]})),p(e.hasMore),b(t)}}catch(e){console.error("Failed to load history:",e)}finally{x(!1)}}},[e,r]),J=(0,s.useCallback)(async t=>{if(r)try{await fetch("/api/terminal/history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,entry:{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:u}})})}catch(e){console.error("Failed to save cd history:",e)}},[e,r,u]),X=(0,s.useCallback)(async t=>{try{let n=await (tM||(tM=tA(e)));if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;l(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}:{}}]),M.current.set(n,""),s.usePty&&T.current.add(n),await tB({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e);else if("stdout"===e||"stderr"===e)W(n,t.data);else if("exit"===e){let e=q(n);z(n),l(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{l(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,W,q,z]),Y=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),a=o[0],i=t;k[a]&&(i=k[a]+(o.length>1?" "+o.slice(1).join(" "):""));let c=tU(i);if(c)return void D.current?.(c.type,i.trim());let d=rD(),h=new Date().toISOString(),x=(s=i.trim().split(/\s+/)[0],rF.has(s)),f={id:d,command:t,output:i!==t?`→ ${i}
18
+ `:"",isRunning:!0,timestamp:h,cwd:u,...x?{usePty:!0}:{}};if(l(e=>e.some(e=>e.id===d)?e:[...e,f]),j(d),M.current.set(d,f.output),x&&T.current.add(d),setTimeout(V,100),i.trim().startsWith("cd ")){let e=i.trim().substring(3).trim(),t=u;e.startsWith("/")?t=e:".."===e?t=u.split("/").slice(0,-1).join("/")||"/":"."!==e&&(t=`${u}/${e}`.replace(/\/+/g,"/")),m(t),n?.(t),l(e=>e.map(e=>{if(e.id===d){let r={...e,output:`Changed directory to: ${t}`,exitCode:0,isRunning:!1};return J(r),r}return e}));return}try{await tI({cwd:u,command:i,commandId:d,tabId:r||"",projectCwd:e,env:y,usePty:x,onData:(e,t)=>{if("pid"===e)l(e=>e.map(e=>e.id===d?{...e,pid:t.pid}:e));else if("stdout"===e||"stderr"===e)W(d,t.data);else if("exit"===e){let e=q(d);z(d),l(r=>r.map(r=>r.id===d?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:e=>{let t=q(d);z(d),l(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=q(d);z(d),l(r=>r.map(r=>r.id===d?{...r,output:e+`
20
+ Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[k,u,y,r,e,W,q,z,V,n,J]),Q=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&tO(t.pid)},[o]),G=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&(tO(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),a=s[0],i=n.command;k[a]&&(i=k[a]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=_.current.get(t);if(e)for(let t of e)t()}z(t,c);let d=i!==n.command?`→ ${i}
21
+ `:"";c||M.current.set(t,d),c&&T.current.add(t),l(e=>e.map(e=>e.id===t?{...e,output:c?"":d,exitCode:void 0,isRunning:!0,pid:void 0}:e));let m=$.current.get(t);try{await tI({cwd:n.cwd||u,command:i,commandId:t,tabId:r||"",projectCwd:e,env:y,usePty:c,...c&&m?{cols:m.cols,rows:m.rows}:{},onData:(e,r)=>{if("pid"===e)l(e=>e.map(e=>e.id===t?{...e,pid:r.pid}:e));else if("stdout"===e||"stderr"===e)W(t,r.data);else if("exit"===e){let e=q(t);z(t),l(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=q(t);z(t),l(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=q(t);z(t),l(n=>n.map(n=>n.id===t?{...n,output:e+`
23
+ Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,k,u,y,r,e,W,q,z]),Z=(0,s.useCallback)(async t=>{if(l(e=>e.filter(e=>e.id!==t)),z(t),r)try{await fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"})}catch(e){console.error("Failed to delete command:",e)}},[e,r,z]),ee=(0,s.useCallback)((t,n,s)=>{var o;let l=t_(t);if(!l)return;let a=l.parse(n);"cwd"in a&&!a.cwd&&(a.cwd=u);let c={id:(o=l.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...a};if(i(e=>[...e,c]),j(c.id),setTimeout(V,100),s){let t=C&&C.length>0?[...C]:F.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,c.id):t.push(c.id),S(t),r&&fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})}).catch(()=>{})}if(r){let n=l.toHistory(c);fetch("/api/terminal/history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,entry:{type:t,id:c.id,timestamp:c.timestamp,...n}})}).catch(e=>console.error(`Failed to save ${t} item:`,e))}},[V,e,r,C]),et=(0,s.useCallback)(async t=>{let n=a.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),j(e=>e===t?null:e),d(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t_(n._type);e?.onClose?.(n)}r&&fetch(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}&commandId=${encodeURIComponent(t)}`,{method:"DELETE"}).catch(e=>console.error("Failed to delete plugin item:",e))},[a,e,r]);D.current=ee,B.current=Y;let er=(0,s.useCallback)((t,n)=>{r&&fetch("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,id:t,fields:{sleeping:n}})}).catch(()=>{})},[e,r]),en=(0,s.useCallback)(e=>{d(t=>new Set(t).add(e)),er(e,!0)},[er]),es=(0,s.useCallback)(e=>{d(t=>{let r=new Set(t);return r.delete(e),r}),er(e,!1)},[er]),eo=(0,s.useCallback)(async t=>{if(S(t),r)try{await fetch("/api/terminal/bubble-order",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:r,order:t})})}catch{}},[e,r]),el=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...a.map(e=>({type:e._type,data:e}))];if(!C||0===C.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(C.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,a,C]);F.current=el,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ea=async()=>{try{let t=new URLSearchParams({cwd:e});r&&t.set("tabId",r);let n=await fetch(`/api/terminal/env?${t}`);if(n.ok){let e=await n.json();w(e.env||{})}}catch(e){console.error("Failed to load env:",e)}},ei=async()=>{try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();N(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}},ec=async()=>{if(r)try{let t=await fetch(`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}`);if(t.ok){let e=await t.json();e.order&&e.order.length>0&&S(e.order)}}catch{}};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await K(0),e.current||await X(e)})(),ea(),ei(),ec(),()=>{e.current=!0}},[K,X]),(0,s.useEffect)(()=>()=>{null!==L.current&&cancelAnimationFrame(L.current)},[]),(0,s.useEffect)(()=>()=>{tW()},[]),{commands:o,pluginItems:a,sleepingBubbles:c,consoleItems:el,currentCwd:u,selectedCommandId:v,setSelectedCommandId:j,customEnv:y,setCustomEnv:w,aliases:k,setAliases:N,isLoadingHistory:h,hasMoreHistory:f,currentPage:g,scrollRef:O,commandHistoryRef:R,ptySizeRef:$,executeCommandRef:B,executeCommand:Y,interruptCommand:Q,rerunCommand:G,deleteCommand:Z,addPluginItem:ee,closePluginItem:et,handleBubbleSleep:en,handleBubbleWake:es,loadHistory:K,scrollToBottom:V,saveBubbleOrder:eo,sendStdin:tD,resizePty:tF,subscribePtyOutput:H,subscribePtyReset:U}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:l}),[F,O]=(0,s.useState)(null),[A,W]=(0,s.useState)(0),[z,H]=(0,s.useState)(0),[_,U]=(0,s.useState)(!0),[q,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(!1),[X,Y]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(!1),Z=(0,s.useRef)(null),ee=(0,s.useRef)(null),et=(0,s.useRef)(null),er=(0,s.useRef)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),eo=(0,s.useRef)([]);(0,s.useEffect)(()=>{eo.current=c},[c]);let el=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[d]),ea=(0,s.useCallback)(()=>{let e=d.current;return!e||e.scrollTop<50},[d]),ei=(0,s.useCallback)(()=>{Y(!ea()),G(!el())},[el,ea]),ec=(0,s.useCallback)(()=>{ee.current?.scrollIntoView({behavior:"smooth"})},[]),ed=async()=>{try{let t=await fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();e.settings?.gridLayout!==void 0&&U(e.settings.gridLayout)}}catch(e){console.error("Failed to load project settings:",e)}},eu=async t=>{try{await fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:t})})}catch(e){console.error("Failed to save project settings:",e)}};(0,s.useEffect)(()=>{queueMicrotask(()=>ed())},[]);let em=(0,s.useCallback)(()=>{er.current=!0},[]),eh=(0,s.useCallback)((e,t)=>{if(!er.current)return void e.preventDefault();er.current=!1,en.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))}},[]),ex=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",es.current=t},[]),ef=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ep=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),eg=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),eb=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=en.current,r=es.current;if(en.current=null,es.current=null,!t||!r||t===r)return;let n=eo.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let l=[...n];l[s]=r,l[o]=t,T(l)},[T]),ev=(0,s.useCallback)(e=>{O(t=>t===e?null:e)},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),u&&ev(u))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[u,ev]),(0,s.useEffect)(()=>{let e=d.current;if(!e)return;let t=new ResizeObserver(([e])=>{H(e.contentRect.height)});return t.observe(e),H(e.clientHeight),()=>t.disconnect()},[d]),(0,s.useEffect)(()=>{let e=d.current;if(e)return F?W(e.clientHeight):(e.style.overflow="",W(0)),()=>{e&&(e.style.overflow="")}},[F,d]),(0,s.useEffect)(()=>{let e=d.current;if(!e||!F||!A)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${F}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[F,A,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&v(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[v]);let ej=z>0?Math.floor((z-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:Z,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:d,onScroll:ei,className:`flex-1 overflow-y-auto ${F?"":"py-4 px-4"}`,children:0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:i("console.enterCommandOrUrl")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:ee}),R&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>$(P+1),disabled:I,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-50",children:i(I?"console.loadingMore":"console.loadMoreHistory")})}),(0,n.jsx)("div",{className:F?"flex flex-col gap-3":_?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>{let s={draggable:!0,onDragStart:e=>eh(e,t.data.id),onDragOver:e=>ex(e,t.data.id),onDragEnter:ef,onDragLeave:ep,onDrop:eg,onDragEnd:eb};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)(td,{commandId:o.id,tabId:r,projectCwd:e,command:o.command,output:o.output,exitCode:o.exitCode,isRunning:o.isRunning,selected:u===o.id,onSelect:()=>{m(o.id)},onInterrupt:o.isRunning?()=>h(o.id):void 0,onStdin:o.isRunning?e=>x(o.id,e):void 0,onDelete:()=>{o.isRunning&&o.pid&&tO(o.pid),f(o.id)},onRerun:()=>p(o.id),timestamp:o.timestamp,usePty:o.usePty,subscribePtyOutput:o.usePty?B:void 0,subscribePtyReset:o.usePty?D:void 0,onPtyResize:(e,t)=>{g.current.set(o.id,{cols:e,rows:t}),b(o.id,e,t)},onToggleMaximize:()=>ev(o.id),maximized:F===o.id,expandedHeight:A,bubbleContentHeight:ej,onTitleMouseDown:em})},o.id)}let o=t_(t.type);if(!o)return null;let l=o.Component,a=t.data;return(0,n.jsx)("div",{"data-bubble-id":a.id,className:"rounded-lg transition-shadow",...s,children:(0,n.jsx)(l,{item:a,selected:u===a.id,maximized:F===a.id,expandedHeight:A,bubbleContentHeight:ej,timestamp:a.timestamp,onSelect:()=>{m(a.id)},onClose:()=>y(a.id),onToggleMaximize:()=>ev(a.id),onTitleMouseDown:em,extra:{addBrowserItem:(e,t)=>j("browser",e,t),initialSleeping:w.has(a.id),onSleep:k,onWake:N}})},a.id)})}),(0,n.jsx)("div",{ref:et})]})}),!F&&c.length>0&&(0,n.jsx)(rH,{showTop:X,showBottom:Q,onScrollTop:ec,onScrollBottom:C}),(0,n.jsx)(rz,{cwd:e,currentCwd:S,commandHistoryRef:L,gridLayout:_,onGridLayoutChange:e=>{U(e),eu({gridLayout:e})},onExecute:v,onAddPluginItem:j,onShowEnvManager:()=>V(!0),onOpenZsh:()=>v("zsh"),onOpenNote:a}),q&&(0,n.jsx)(th,{cwd:e,tabId:r,onClose:()=>V(!1),onSave:e=>E(e)}),K&&(0,n.jsx)(tf,{onClose:()=>J(!1),onSave:e=>M(e)})]})}var rU=r(24750);let rq="review-last-viewed";function rV(){try{return JSON.parse(localStorage.getItem(rq)||"{}")}catch{return{}}}function rK(e,t){if(!e.lastCommentAt)return!1;let r=t[e.id];return!r||e.lastCommentAt>r}function rJ({cwd:e}){let{t}=(0,o.Bd)(),[r,l]=(0,s.useState)(!1),[a,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)({}),[f,p]=(0,s.useState)({open:!1,comments:[],title:"",userNameMap:{}}),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{queueMicrotask(()=>x(rV()))},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{g.current&&!g.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let y=(0,s.useCallback)(async()=>{d(!0);try{let e=await fetch("/api/review");if(e.ok){let t=await e.json();i(t.reviews||[])}}catch{}d(!1)},[]);(0,s.useEffect)(()=>{r&&queueMicrotask(()=>y())},[r,y]);let w=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"review"===e.type)&&y()},[y]);(0,eH.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"/")}`,onMessage:w,enabled:!!e}),(0,s.useEffect)(()=>{queueMicrotask(()=>y())},[y]);let k=(0,s.useMemo)(()=>a.filter(e=>e.active),[a]),N=(0,s.useMemo)(()=>k.some(e=>rK(e,h)),[k,h]),C=(0,s.useCallback)(e=>{let t;(t=rV())[e]=Date.now(),localStorage.setItem(rq,JSON.stringify(t)),x(rV()),window.open(`${window.location.origin}/review/${e}`,"_blank")},[]),S=(0,s.useCallback)(async(e,t)=>{e.stopPropagation();try{let[e,r]=await Promise.all([fetch(`/api/review/${t}`),fetch("/api/review/users")]);if(!e.ok)return;let{review:n}=await e.json(),s={};if(r.ok){let{users:e}=await r.json();for(let[t,r]of Object.entries(e))s[t]=r.name}p({open:!0,comments:n.comments||[],title:n.title,userNameMap:s})}catch{}},[]),L=(0,s.useCallback)((e,t)=>{b.current=t,e.dataTransfer.effectAllowed="move";let r=e.currentTarget;requestAnimationFrame(()=>r.classList.add("opacity-30"))},[]),E=(0,s.useCallback)(e=>{b.current=null,j(null),e.currentTarget instanceof HTMLElement&&e.currentTarget.classList.remove("opacity-30")},[]),M=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",b.current&&b.current!==t&&j(t)},[]),T=(0,s.useCallback)((e,t)=>{e.preventDefault(),j(null);let r=b.current;b.current=null,r&&r!==t&&i(e=>{let n=[...e],s=n.findIndex(e=>e.id===r),o=n.findIndex(e=>e.id===t);if(-1===s||-1===o)return e;let[l]=n.splice(s,1);return n.splice(o,0,l),fetch("/api/review/order",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({order:n.map(e=>e.id)})}).catch(()=>{}),n})},[]);return(0,n.jsxs)("div",{ref:g,className:"relative",children:[(0,n.jsxs)("button",{onClick:()=>l(e=>!e),className:`relative p-2 rounded-lg transition-colors ${r?"text-foreground bg-accent":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:t("review.reviewManagement"),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 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})}),N&&(0,n.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-red-500 rounded-full"})]}),r&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-64 bg-popover border border-border rounded-lg shadow-xl z-50 overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:t("review.allReviews")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground/60 ml-1.5",children:k.length})]}),(0,n.jsx)("button",{onClick:y,className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",title:t("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)("div",{className:"max-h-80 overflow-y-auto",children:c&&0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("common.loading")}):0===k.length?(0,n.jsx)("div",{className:"px-3 py-4 text-xs text-muted-foreground/50 text-center",children:t("review.noOpenReviews")}):k.map(e=>{let r,s,o,l,a,i=rK(e,h);return(0,n.jsxs)("div",{draggable:!0,onDragStart:t=>L(t,e.id),onDragEnd:E,onDragOver:t=>M(t,e.id),onDrop:t=>T(t,e.id),onMouseEnter:t=>{let r=t.currentTarget.getBoundingClientRect();m({id:e.id,text:e.title,top:r.top+r.height/2,left:r.left})},onMouseLeave:()=>m(t=>t?.id===e.id?null:t),onClick:()=>C(e.id),className:`group px-3 py-2 cursor-pointer border-b transition-colors ${v===e.id?"border-b-brand border-t border-t-transparent":"border-b-border/50"} hover:bg-accent/30`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${i?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:`text-xs truncate flex-1 ${i?"font-medium text-foreground":""}`,children:e.title}),e.commentCount>0&&(0,n.jsx)("button",{onClick:t=>S(t,e.id),className:"flex-shrink-0 p-0.5 rounded text-muted-foreground/0 group-hover:text-muted-foreground/60 hover:!text-brand hover:!bg-brand/10 transition-colors",title:t("review.viewComments"),children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{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)("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground/50 mt-0.5 pl-3",children:[(0,n.jsx)("span",{children:(s=String((r=new Date(e.updatedAt||e.createdAt)).getMonth()+1).padStart(2,"0"),o=String(r.getDate()).padStart(2,"0"),l=String(r.getHours()).padStart(2,"0"),a=String(r.getMinutes()).padStart(2,"0"),`${s}-${o} ${l}:${a}`)}),e.commentCount>0&&(0,n.jsx)("span",{children:t("review.nComments",{count:e.commentCount})})]})]},e.id)})})]}),u&&r&&(0,n.jsx)("div",{className:"fixed z-[60] px-2 py-1 text-xs bg-popover text-popover-foreground border border-border rounded shadow-md whitespace-nowrap pointer-events-none",style:{top:u.top,left:u.left-8,transform:"translate(-100%, -50%)"},children:u.text}),(0,n.jsx)(rU._,{isOpen:f.open,onClose:()=>p(e=>({...e,open:!1})),comments:f.comments,reviewTitle:f.title,userNameMap:f.userNameMap})]})}function rX({cwd:e,currentBranch:t,onSwitched:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(async()=>{m(!0);try{let t=await fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json(),r=[...e.local||[],...(e.remote||[]).filter(t=>!e.local.includes(t.replace(/^origin\//,"")))];d(r)}}catch{(0,g.oR)(l("toast.loadBranchFailed"),"error")}finally{m(!1)}},[e]),y=(0,s.useCallback)(()=>{i(!0),p(""),j()},[j]),w=(0,s.useCallback)(()=>{i(!1)},[]);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{b.current&&!b.current.contains(e.target)&&w()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a,w]),(0,s.useEffect)(()=>{a&&setTimeout(()=>v.current?.focus(),50)},[a]);let k=async t=>{x(!0);try{let n=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"checkout",cwd:e,path:e,branch:t})});if(n.ok){let e=t.replace(/^origin\//,"");(0,g.oR)(l("toast.switchedToBranch",{branch:e}),"success"),w(),r()}else{let e=await n.json();(0,g.oR)(e.error||l("toast.switchBranchFailed"),"error")}}catch{(0,g.oR)(l("toast.switchBranchFailed"),"error")}finally{x(!1)}},N=c.filter(e=>e!==t&&e.toLowerCase().includes(f.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsx)("button",{onClick:a?w:y,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:l("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:v,type:"text",value:f,onChange:e=>p(e.target.value),placeholder:l("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&&w()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:u?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===N.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:f?l("git.noMatchingBranches"):l("git.noBranches")}):N.map(e=>(0,n.jsx)("button",{onClick:()=>k(e),disabled:h,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 rY({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:l,onOpenProjectSessions:a,onOpenAliasManager:i,onBranchSwitched:c}){let{t:d}=(0,o.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:d("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,g.oR)(d("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,g.oR)(d("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:d("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:l,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)(rX,{cwd:e,currentBranch:s,onSwitched:()=>c?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(e5,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(rJ,{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:d("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"})})}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("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:async()=>{if(t?.cwd)try{await fetch("/api/open-vscode",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("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:async()=>{if(t?.cwd)try{await fetch("/api/open-cursor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t.cwd})})}catch{}},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("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,g.oR)(d("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("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:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("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:()=>window.parent.postMessage({type:"OPEN_TOKEN_STATS"},"*"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:d("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:d("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}function rQ({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 rG({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:l}){let[i,c]=(0,s.useState)(!1),d=(0,s.useRef)(null),u=(0,s.useRef)(null),[m,h]=(0,s.useState)({top:0,right:0});(0,s.useEffect)(()=>{if(!i)return;let e=e=>{u.current&&!u.current.contains(e.target)&&d.current&&!d.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let x=n=>{c(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?l?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:d,onClick:()=>{if(!i&&d.current){let e=d.current.getBoundingClientRect();h({top:e.bottom+4,right:window.innerWidth-e.right})}c(e=>!e)},className:"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"})})}),i&&(0,a.createPortal)((0,n.jsxs)("div",{ref:u,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:m.top,right:m.right},children:[(0,n.jsxs)("button",{onClick:()=>x("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:()=>x("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:()=>x("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"}),"OpenAI Codex"]}),(0,n.jsxs)("button",{onClick:()=>x("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:()=>x("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"]})]}),document.body)]})}function rZ({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:a,onTogglePin:i,onSwitchTab:c,onCloseTab:d,onNewTab:u,onNewClaude2Tab:m,onNewCodexTab:h,onNewKimiTab:x,onNewOllamaTab:f,onDragStart:p,onDragOver:g,onDrop:b,onDragEnd:v}){let{t:j}=(0,o.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((o,u)=>(0,n.jsx)(ty.m,{content:o.title,delay:200,children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>p(u),onDragOver:e=>g(e,u),onDrop:()=>b(u),onDragEnd:v,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${o.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===u?"opacity-50":""} ${l===u?"border-l-2 border-brand":""}`,onClick:()=>c(o.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(rQ,{number:u+1,isActive:o.id===t}),o.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!o.isLoading&&r.has(o.id)&&o.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),i&&a?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.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:j("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"})})}),i&&!a?.(o.id)&&!o.isLoading&&!(r.has(o.id)&&o.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i(o.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:j("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:"max-w-32 truncate",children:o.title}),"claude2"===o.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"===o.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"===o.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"===o.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"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(o.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:j("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"})})})]})},o.id)),(0,n.jsx)(rG,{onNewTab:u,onNewClaude2Tab:m,onNewCodexTab:h,onNewKimiTab:x,onNewOllamaTab:f})]})})}var r0=r(44810),r1=r(12651),r2=r(81165),r5=r(16950),r4=r(11019),r3=r(12612);function r6({filePath:e}){let[t,r]=(0,s.useState)(null),[o,l]=(0,s.useState)(!0),[a,i]=(0,s.useState)(null),c=(0,s.useRef)(!1),d=ec(e),u=ei(e);if((0,s.useEffect)(()=>{u?l(!1):c.current||(c.current=!0,(async()=>{l(!0),i(null);try{let t=await fetch(`/api/file?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Failed to load file: ${t.statusText}`);let n=await t.json();r(n.content)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{l(!1),c.current=!1}})())},[e,u]),a)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:a})});if(o)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"Loading..."})});if(ei(e)){let t=`/api/file?path=${encodeURIComponent(e)}&raw=true`;return(0,n.jsx)("div",{className:"flex items-center justify-center h-full overflow-auto",children:(0,n.jsx)("img",{src:t,alt:e.split("/").pop()||"image",className:"max-w-full max-h-full object-contain"})})}return t?d?(0,n.jsx)(r9,{content:t}):(0,n.jsx)(e$,{content:t,filePath:e,showLineNumbers:!0,showSearch:!0,className:"h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:"No content"})})}let r8=[eI.W];function r9({content:e}){let t=(0,s.useRef)(null);return(0,n.jsxs)("div",{className:"h-full flex",children:[(0,n.jsx)(eB.l,{content:e,containerRef:t}),(0,n.jsx)("div",{ref:t,className:"flex-1 overflow-auto p-4",children:(0,n.jsx)(eP.T,{content:e,rehypePlugins:r8})})]})}function r7({title:e,content:t,toolName:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){try{return JSON.parse(e),!0}catch{return!1}}(t),c=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path&&"string"==typeof t.old_string&&"string"==typeof t.new_string)return t}catch{}return null}(t),d=function(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path)return t.file_path}catch{let t=e.trim();if(t.startsWith("/")&&!t.includes("\n")&&t.length<500)return t}return null}(t),u=!!c,m=!!d,[h,x]=(0,s.useState)(("Read"===r||"Write"===r)&&m?"file":u?"diff-unified":i?"readable":"json"),f=(0,s.useRef)(null),p=eu(f);(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&"readable"===h&&i){e.preventDefault(),p.open();return}if("Escape"===e.key){if(p.isVisible)return void p.close();document.activeElement instanceof HTMLElement&&document.activeElement.blur(),l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[l,h,i,p]);let b=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:l,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",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.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:e}),d&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(d),(0,g.oR)(a("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:a("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.jsxs)("div",{className:"flex items-center gap-3",children:[i&&(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[u&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>x("diff-split"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-split"===h?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.sideBySide"),children:"Split"}),(0,n.jsx)("button",{onClick:()=>x("diff-unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"diff-unified"===h?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.unified"),children:"Unified"})]}),m&&(0,n.jsx)("button",{onClick:()=>x("file"),className:`px-2 py-1 text-xs rounded transition-colors ${"file"===h?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,title:a("diffViewer.previewFile"),children:"File"}),(0,n.jsx)("button",{onClick:()=>x("readable"),className:`px-2 py-1 text-xs rounded transition-colors ${"readable"===h?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:a("common.readable")}),(0,n.jsx)("button",{onClick:()=>x("json"),className:`px-2 py-1 text-xs rounded transition-colors ${"json"===h?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"JSON"})]}),(0,n.jsx)("button",{onClick:l,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.jsx)("div",{className:"flex-1 overflow-auto p-4",children:"file"===h&&d?(0,n.jsx)(r6,{filePath:d}):"diff-unified"===h&&c?(0,n.jsx)(_,{oldContent:c.old_string,newContent:c.new_string,filePath:c.file_path}):"diff-split"===h&&c?(0,n.jsx)(H,{oldContent:c.old_string,newContent:c.new_string,filePath:c.file_path}):"readable"===h&&i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(em,{search:p}),(0,n.jsx)("pre",{ref:f,className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:Z(t)})]}):(0,n.jsx)("pre",{className:"text-foreground whitespace-pre-wrap break-words",style:{fontSize:"0.8125rem"},children:i?function(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}(t):t})})]})});return(0,n.jsx)(r0.Z,{children:b})}let ne={Read:"\uD83D\uDCC4",Write:"✏️",Edit:"\uD83D\uDCDD",Bash:"\uD83D\uDCBB",Glob:"\uD83D\uDD0D",Grep:"\uD83D\uDD0E",WebFetch:"\uD83C\uDF10",WebSearch:"\uD83D\uDD0D"};function nt({toolCall:e,cwd:t}){let r,{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),u=ne[e.name]||"\uD83D\uDD27",m=(r=e.input,"Bash"===e.name&&r.command&&"string"==typeof r.command?r.command:"Glob"===e.name&&r.pattern&&"string"==typeof r.pattern||"Grep"===e.name&&r.pattern&&"string"==typeof r.pattern?r.pattern:r.file_path&&"string"==typeof r.file_path?r.file_path:r.path&&"string"==typeof r.path?r.path:null),h="Glob"===e.name||"Grep"===e.name||"Bash"===e.name,x=m?h?m:(e=>{if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}let r=e.split("/");return r.length>2?".../"+r.slice(-2).join("/"):e})(m):null,f=t=>{let r="input"===t?l("toolCall.inputParams"):l("toolCall.resultLabel"),n="input"===t?JSON.stringify(e.input,null,2):"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2);d({title:`${e.name}${x?` ${x}`:""} - ${r}`,content:n,toolName:e.name})};return(0,n.jsxs)("div",{className:"my-2 border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("button",{onClick:()=>i(!a),className:"w-full px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors",children:[(0,n.jsx)("span",{className:"text-base",children:u}),(0,n.jsx)("span",{className:"font-medium text-sm text-foreground flex-shrink-0",children:e.name}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate flex-1 min-w-0",title:m||"",children:x}),(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),m&&(navigator.clipboard.writeText(m),(0,g.oR)(l("common.copiedPath")))},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),m&&(navigator.clipboard.writeText(m),(0,g.oR)(l("common.copiedPath"))))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0 cursor-pointer",title:l("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.jsxs)("span",{className:"ml-auto flex items-center gap-2",children:[a&&!e.isLoading&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("input")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("input"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:l("toolCall.inputParamsTitle"),children:l("toolCall.input")}),e.result&&(0,n.jsx)("span",{role:"button",tabIndex:0,onClick:e=>{e.stopPropagation(),f("result")},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.stopPropagation(),f("result"))},className:"text-xs text-brand hover:text-teal-10 cursor-pointer",title:l("toolCall.resultTitle"),children:l("toolCall.result")})]}),e.isLoading?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:a?"▲":"▼"})]})]}),a&&(0,n.jsxs)("div",{className:"border-t border-border",children:[(0,n.jsxs)("div",{className:"px-3 py-2",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[l("toolCall.inputParams"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:JSON.stringify(e.input,null,2)})]}),e.result&&(0,n.jsxs)("div",{className:"px-3 py-2 border-t border-border",children:[(0,n.jsx)("div",{className:"mb-1",children:(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[l("toolCall.resultLabel"),":"]})}),(0,n.jsx)("pre",{className:"text-xs bg-secondary p-2 rounded overflow-x-auto max-h-24 overflow-y-auto text-foreground",children:"string"==typeof e.result?e.result:JSON.stringify(e.result,null,2)})]})]}),c&&(0,n.jsx)(r7,{title:c.title,content:c.content,toolName:c.toolName,onClose:()=>d(null)})]})}var nr=r(48368),nn=r(21362);function ns(e,t){if(t&&e.startsWith(t)){let r=e.slice(t.length);return r.startsWith("/")?r.slice(1):r}return e}function no({node:e,selectedUid:t,onSelect:r,depth:o=0}){let[l,a]=(0,s.useState)(!0);if(e.isFile&&e.change){let s=t===e.change.uid;return(0,n.jsxs)("button",{onClick:()=>r(e.change),className:`w-full flex items-center gap-1.5 px-2 py-1 text-xs text-left rounded transition-colors ${s?"bg-brand/15 text-brand":"text-foreground hover:bg-accent"}`,style:{paddingLeft:`${12*o+8}px`},"data-tooltip":e.fullPath,children:[(0,n.jsx)(nr.A,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-60"}),(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)("span",{className:`ml-auto text-[10px] flex-shrink-0 ${"write"===e.change.type?"text-green-500":"text-yellow-500"}`,children:"write"===e.change.type?"new":"edit"})]})}return(0,n.jsxs)("div",{children:[(0,n.jsxs)("button",{onClick:()=>a(!l),className:"w-full flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-foreground transition-colors",style:{paddingLeft:`${12*o+8}px`},children:[l?(0,n.jsx)(tt.A,{className:"w-3 h-3"}):(0,n.jsx)(nn.A,{className:"w-3 h-3"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]}),l&&e.children.map((e,s)=>(0,n.jsx)(no,{node:e,selectedUid:t,onSelect:r,depth:o+1},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${s}`))]})}function nl({toolCalls:e,cwd:t,onClose:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>(function(e,t){let r=[],n=0;for(let s of e)if("Edit"===s.name){let e=s.input;e.file_path&&"string"==typeof e.old_string&&"string"==typeof e.new_string&&r.push({filePath:ns(e.file_path,t),uid:`change-${n++}`,type:"edit",old_string:e.old_string,new_string:e.new_string})}else if("Write"===s.name){let e=s.input;e.file_path&&"string"==typeof e.content&&r.push({filePath:ns(e.file_path,t),uid:`change-${n++}`,type:"write",old_string:"",new_string:e.content})}return r})(e,t),[e,t]),i=(0,s.useMemo)(()=>(function e(t){return t.map(t=>{if(!t.isFile&&1===t.children.length&&!t.children[0].isFile){let r=t.children[0];return{...r,name:t.name+"/"+r.name,children:e(r.children)}}return{...t,children:e(t.children)}})})(function(e){let t=[];for(let r of e){let e=r.filePath.split("/").filter(Boolean),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/");if(o){let e={name:s,fullPath:l,isFile:!0,children:[],change:r};n.push(e)}else{let e=n.find(e=>e.name===s&&!e.isFile);e||(e={name:s,fullPath:l,isFile:!1,children:[]},n.push(e)),n=e.children}}}return t}(a)),[a]),[c,d]=(0,s.useState)(a[0]||null),[u,m]=(0,s.useState)("unified"),[h,x]=(0,s.useState)(null),f=(0,s.useRef)(null);if((0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r=t;for(;r&&r!==e;){if(r.dataset.tooltip)return r.dataset.tooltip;r=r.parentElement}return null},r=e=>{let r=t(e.target);x(r?{text:r,x:e.clientX,y:e.clientY}:null)},n=e=>{x(r=>{if(!r)return null;let n=t(e.target);return n?{text:n,x:e.clientX,y:e.clientY}:null})},s=r=>{let n=r.relatedTarget;n&&e.contains(n)&&t(n)||x(null)};return e.addEventListener("mouseover",r),e.addEventListener("mousemove",n),e.addEventListener("mouseout",s),()=>{e.removeEventListener("mouseover",r),e.removeEventListener("mousemove",n),e.removeEventListener("mouseout",s)}},[]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]),0===a.length)return null;let p=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:r,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col transition-all",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)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:l("diffViewer.fileChanges",{count:a.length})})}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-accent rounded p-0.5",children:[(0,n.jsx)("button",{onClick:()=>m("unified"),className:`px-2 py-1 text-xs rounded transition-colors ${"unified"===u?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Unified"}),(0,n.jsx)("button",{onClick:()=>m("split"),className:`px-2 py-1 text-xs rounded transition-colors ${"split"===u?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:"Split"})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)(eJ.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{ref:f,className:"w-56 flex-shrink-0 border-r border-border overflow-y-auto py-2",children:i.map((e,t)=>(0,n.jsx)(no,{node:e,selectedUid:c?.uid||"",onSelect:d},e.isFile&&e.change?e.change.uid:`${e.fullPath}-${t}`))}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:c?"unified"===u?(0,n.jsx)(_,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath}):(0,n.jsx)(H,{oldContent:c.old_string,newContent:c.new_string,filePath:c.filePath,isNew:"write"===c.type}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:l("diffViewer.selectFileToView")})})]})]})});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r0.Z,{children:p}),h&&(0,n.jsx)(r0.Z,{children:(0,n.jsx)("div",{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",style:{left:h.x+12,top:h.y+16},children:h.text})})]})}var na=r(58515),ni=r(36201),nc=r(55804),nd=r(37618);function nu(e){let t=e.input?.questions||[],r=e.input?.answers||{},n={};if(e.result)try{let t=JSON.parse(e.result);t?.answers&&(n=t.answers)}catch{}return{questions:t,answers:{...r,...n}}}function nm(e,t){return`${e}-${t}`}function nh({toolCalls:e,onClose:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)({}),[m,h]=(0,s.useState)({});(0,s.useEffect)(()=>{let t={};e.forEach((e,r)=>{let{questions:n,answers:s}=nu(e);n.forEach((e,n)=>{let o=s[e.question];if(o){let s=nm(r,n);t[s]=o,e.options.some(e=>e.label===o)||(c(e=>({...e,[s]:!0})),u(e=>({...e,[s]:o})))}})}),queueMicrotask(()=>a(t))},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&t()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let x=e.reduce((e,t)=>{let{questions:r}=nu(t);return e+r.length},0),f=Object.values(m).filter(Boolean).length,p=(0,s.useCallback)((e,t)=>{a(r=>({...r,[e]:t})),c(t=>({...t,[e]:!1}))},[]),b=(0,s.useCallback)(e=>{c(t=>{let r=!t[e];if(r){let t=d[e]||"";t&&a(r=>({...r,[e]:t}))}return{...t,[e]:r}})},[d]),v=(0,s.useCallback)((e,t)=>{u(r=>({...r,[e]:t})),t&&a(r=>({...r,[e]:t}))},[]),j=(0,s.useCallback)(e=>{h(t=>({...t,[e]:!t[e]}))},[]),y=(0,s.useCallback)(()=>{let t=f>0,n=[];e.forEach((e,s)=>{let{questions:o}=nu(e);o.forEach((e,o)=>{let a=nm(s,o);if(t&&!m[a])return;let i=l[a];n.push(`Q: ${e.question}`),n.push(`A: ${i||r("askQuestion.notSelected")}`),n.push("")})}),navigator.clipboard.writeText(n.join("\n").trim()),(0,g.oR)(t?r("toast.copiedQA",{count:f}):r("toast.copiedAllQA"))},[e,l,m,f,r]),w=(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-6xl h-[90vh] 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 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:r("askQuestion.title")}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[r("askQuestion.nQuestions",{count:x}),f>0&&` \xb7 ${r("askQuestion.checkedN",{count:f})}`]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:y,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f>0?r("askQuestion.copyChecked",{count:f}):r("askQuestion.copyAll"),children:(0,n.jsx)(e6.A,{className:"w-4 h-4"})}),(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)(eJ.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-6",children:e.map((t,s)=>{let{questions:o}=nu(t);return o.map((t,a)=>{let c=nm(s,a),u=l[c],h=i[c]||!1,x=m[c]||!1;return(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("button",{onClick:()=>j(c),className:"mt-0.5 flex-shrink-0 p-0.5 rounded hover:bg-accent transition-colors",title:r("askQuestion.checkToCopy"),children:x?(0,n.jsx)(na.A,{className:"w-4 h-4 text-brand"}):(0,n.jsx)(ni.A,{className:"w-4 h-4 text-muted-foreground"})}),t.header&&(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-brand/10 text-brand flex-shrink-0 mt-0.5",children:t.header}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:t.question})]}),(0,n.jsxs)("div",{className:"space-y-1 ml-7",children:[t.options.map((e,t)=>{let r=u===e.label&&!h;return(0,n.jsxs)("button",{onClick:()=>p(c,e.label),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${r?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:r?(0,n.jsx)(nc.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-sm ${r?"text-foreground font-medium":"text-foreground"}`,children:e.label}),e.description&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]})]},t)}),(0,n.jsxs)("button",{onClick:()=>b(c),className:`flex items-start gap-2 px-2.5 py-1.5 rounded-md transition-colors w-full text-left cursor-pointer hover:bg-accent/50 ${h?"bg-brand/10 hover:bg-brand/15":""}`,children:[(0,n.jsx)("div",{className:"mt-0.5 flex-shrink-0",children:h?(0,n.jsx)(nc.A,{className:"w-3.5 h-3.5 text-brand"}):(0,n.jsx)("div",{className:"w-3.5 h-3.5 rounded-full border border-muted-foreground"})}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(nd.A,{className:"w-3.5 h-3.5 text-muted-foreground"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:r("askQuestion.custom")})]})]}),h&&(0,n.jsx)("div",{className:"ml-6 mt-1",children:(0,n.jsx)("input",{type:"text",autoFocus:!0,value:d[c]||"",onChange:e=>v(c,e.target.value),placeholder:r("askQuestion.customPlaceholder"),className:"w-full px-3 py-1.5 text-sm bg-background border border-border rounded-md focus:outline-none focus:ring-1 focus:ring-brand text-foreground placeholder:text-muted-foreground"})})]}),(s!==e.length-1||a!==o.length-1)&&(0,n.jsx)("div",{className:"border-b border-border/50 mt-3"})]},c)})})})]})});return(0,n.jsx)(r0.Z,{children:w})}function nx({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-4 right-4 w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",children:(0,n.jsx)("svg",{className:"w-6 h-6",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)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:r("chat.imagePreview"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(r0.Z,{children:s})}function nf({filePath:e,content:t,cwd:r,onClose:o}){let[l,a]=(0,s.useState)(null);return(0,n.jsx)(r0.Z,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:o,children:(0,n.jsx)("div",{ref:a,className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-[90vh] flex flex-col relative",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(v,{container:l,children:(0,n.jsx)(eA,{content:t,filePath:e,cwd:r,onClose:o})})})})})}let np=(0,s.memo)(function({message:e,cwd:t,sessionId:r,onFork:l}){let a,i,c,d,{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),y="user"===e.role,w=e.images&&e.images.length>0,k=e.toolCalls?.length||0,N=k>1,C=!!r&&!!t&&!!l,S=(0,s.useMemo)(()=>e.toolCalls?.some(e=>"Edit"===e.name||"Write"===e.name)||!1,[e.toolCalls]),L=(0,s.useMemo)(()=>{if(!e.toolCalls)return null;for(let t=e.toolCalls.length-1;t>=0;t--)if("TodoWrite"===e.toolCalls[t].name)return e.toolCalls[t];return null},[e.toolCalls]),E=(0,s.useMemo)(()=>e.toolCalls?e.toolCalls.filter(e=>"AskUserQuestion"===e.name):[],[e.toolCalls]),M=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=new Set,r=[];for(let n of e.toolCalls)if("Read"===n.name||"Edit"===n.name||"Write"===n.name){let e=n.input.file_path;e&&e.toLowerCase().endsWith(".md")&&!t.has(e)&&(t.add(e),r.push(e))}return r},[e.toolCalls]),T=(0,s.useMemo)(()=>{if(!e.toolCalls)return[];let t=[];for(let r of e.toolCalls){let e=r.input?.thought;if(e&&"string"==typeof e){let n=e.match(/PREVIOUS:\s*(.*?)\s*→\s*THIS:\s*(.*?)\s*→\s*EXPECT:\s*(.*)/i);n?t.push({previous:n[1].trim(),current:n[2].trim(),expect:n[3].trim(),raw:e,toolName:r.name}):t.push({previous:"",current:e,expect:"",raw:e,toolName:r.name})}}return t},[e.toolCalls]),[R,$]=(0,s.useState)(null),[P,I]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!R)return void queueMicrotask(()=>I(null));let e=!1;return fetch(`/api/file?path=${encodeURIComponent(R)}`).then(e=>e.ok?e.json():Promise.reject()).then(t=>{e||I(t.content)}).catch(()=>{e||((0,g.oR)(u("toast.readFileFailed"),"error"),$(null))}),()=>{e=!0}},[R]);let B=()=>{e.content&&(navigator.clipboard.writeText(e.content),(0,g.oR)(u("toast.copiedMessage")))},D=()=>{C&&l(e.id)},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}`})(e.timestamp);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:`flex flex-col ${y?"items-end":"items-start"} mb-4 group`,"data-role":e.role,children:[F&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity mb-0.5 px-1",children:F}),(0,n.jsxs)("div",{className:`flex ${y?"justify-end":"justify-start"} w-full`,children:[y&&(0,n.jsxs)("div",{className:"self-start mt-2 mr-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:B,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.copyMessage"),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 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"})})}),C&&(0,n.jsx)("button",{onClick:D,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.forkSession"),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)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]}),(0,n.jsxs)("div",{className:`max-w-[80%] ${y?"bg-accent text-foreground border border-brand rounded-2xl rounded-br-md":"bg-accent text-foreground dark:text-slate-11 rounded-2xl rounded-bl-md"} px-4 py-2`,children:[w&&(0,n.jsx)("div",{className:`flex flex-wrap gap-2 ${e.content?"mb-2":""}`,children:e.images.map((e,t)=>(0,n.jsx)("div",{className:"relative w-16 h-16 rounded-lg overflow-hidden border border-white/20 cursor-pointer hover:opacity-90 transition-opacity",onClick:()=>h(e),children:(0,n.jsx)("img",{src:`data:${e.media_type};base64,${e.data}`,alt:u("chat.imageN",{index:t+1}),className:"w-full h-full object-cover"})},t))}),e.content&&(0,n.jsxs)("div",{className:"break-words",children:[(0,n.jsx)(eP.T,{content:e.content,isUser:y,isStreaming:e.isStreaming,enableMath:!1}),e.isStreaming&&(0,n.jsx)("span",{className:"inline-block w-2 h-4 ml-1 bg-current animate-pulse"})]}),L&&(c=(i=Array.isArray(a=L.input?.todos)?a:[]).filter(e=>"completed"===e.status).length,d=i.length,(0,n.jsx)("div",{className:`${e.content||w?"mt-2":""}`,children:(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("div",{className:"flex-1 h-1 bg-secondary rounded-full overflow-hidden",children:(0,n.jsx)("div",{className:"h-full bg-green-500 rounded-full transition-all duration-300",style:{width:`${d>0?c/d*100:0}%`}})}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:[c,"/",d]})]}),i.map((e,t)=>(0,n.jsxs)("div",{className:`flex items-center gap-1.5 ${"completed"===e.status?"opacity-50":""}`,children:["completed"===e.status?(0,n.jsx)(r1.A,{className:"w-3 h-3 text-green-500 flex-shrink-0"}):"in_progress"===e.status?(0,n.jsx)(r2.A,{className:"w-3 h-3 text-brand flex-shrink-0 animate-spin"}):(0,n.jsx)(r5.A,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs truncate ${"completed"===e.status?"text-muted-foreground":"text-foreground"}`,children:"in_progress"===e.status&&e.activeForm?e.activeForm:e.content})]},t))]})})),M.length>0&&(0,n.jsx)("div",{className:`${e.content||w||L?"mt-2":""}`,children:(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50 px-3 py-2 space-y-0.5",children:M.map(e=>(0,n.jsxs)("button",{onClick:()=>$(e),className:"flex items-center gap-1.5 w-full text-left hover:bg-accent rounded px-1 py-0.5 transition-colors group/md",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 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:"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:"text-xs text-muted-foreground group-hover/md:text-foreground truncate",children:e.split("/").pop()})]},e))})}),T.length>0&&(0,n.jsx)("div",{className:`${e.content||w||L||M.length>0?"mt-2":""}`,children:(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary/50",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"border-b border-border text-muted-foreground",children:[(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium w-[60px]",children:"Tool"}),(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Previous"}),(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Action"}),(0,n.jsx)("th",{className:"px-2 py-1.5 text-left font-medium",children:"Expect"})]})}),(0,n.jsx)("tbody",{children:T.map((e,t)=>(0,n.jsxs)("tr",{className:t<T.length-1?"border-b border-border/50":"",children:[(0,n.jsx)("td",{className:"px-2 py-1 text-muted-foreground font-mono",children:e.toolName}),(0,n.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.previous||"—"}),(0,n.jsx)("td",{className:"px-2 py-1 text-foreground",children:e.current}),(0,n.jsx)("td",{className:"px-2 py-1 text-muted-foreground",children:e.expect||"—"})]},t))})]})})}),e.toolCalls&&e.toolCalls.length>0&&(0,n.jsx)("div",{className:`${e.content||w?"mt-2":""}`,children:N?(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center",children:[(0,n.jsxs)("button",{onClick:()=>f(!x),className:"flex-1 px-3 py-2 flex items-center gap-2 text-left hover:bg-accent transition-colors active:bg-muted",children:[(0,n.jsx)("span",{className:"text-lg",children:"\uD83D\uDD27"}),(0,n.jsx)("span",{className:"font-medium text-foreground",children:u("chat.toolCalls",{count:k})}),(0,n.jsx)("span",{className:"ml-auto text-muted-foreground text-sm",children:x?u("chat.collapse"):u("chat.expand")})]}),E.length>0&&(0,n.jsx)("button",{onClick:()=>j(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:u("chat.viewQuestions"),children:(0,n.jsx)(r4.A,{className:"w-4 h-4"})}),S&&(0,n.jsx)("button",{onClick:()=>b(!0),className:"px-3 py-2 text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l border-border",title:u("chat.viewAllFileChanges"),children:(0,n.jsx)(r3.A,{className:"w-4 h-4"})})]}),x&&(0,n.jsx)("div",{className:"border-t border-border p-2 space-y-1",children:e.toolCalls.map((e,r)=>(0,n.jsx)(nt,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}):e.toolCalls.map((e,r)=>(0,n.jsx)(nt,{toolCall:e,cwd:t},`${e.id}-${r}`))})]}),!y&&(0,n.jsxs)("div",{className:"self-start mt-2 ml-1 flex flex-col gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.content&&(0,n.jsx)("button",{onClick:B,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.copyMessage"),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 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"})})}),C&&(0,n.jsx)("button",{onClick:D,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent",title:u("chat.forkSession"),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)("circle",{cx:"12",cy:"18",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9"}),(0,n.jsx)("path",{d:"M12 12v3"})]})})]})]})]}),m&&(0,n.jsx)(nx,{image:m,onClose:()=>h(null)}),p&&e.toolCalls&&(0,n.jsx)(nl,{toolCalls:e.toolCalls,cwd:t,onClose:()=>b(!1)}),v&&E.length>0&&(0,n.jsx)(nh,{toolCalls:E,onClose:()=>j(!1)}),R&&null!==P&&(0,n.jsx)(nf,{filePath:R,content:P,cwd:t||"",onClose:()=>$(null)})]})}),ng=(0,s.forwardRef)(function({messages:e,isLoading:t,cwd:r,sessionId:l,engine:a,hasMoreHistory:i,isLoadingMore:c,onLoadMore:d,onFork:u,isActive:g=!0,onContentSearch:b},v){let{t:j}=(0,o.Bd)(),y=(0,s.useRef)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null),N=(0,s.useRef)(null),[E,M]=(0,s.useState)(null),[T,R]=(0,s.useState)(!0),[$,P]=(0,s.useState)(!1),[I,B]=(0,s.useState)(!1);(0,s.useEffect)(()=>{M(N.current)},[]);let{isSearchVisible:D,searchQuery:F,setSearchQuery:O,matches:W,currentMatchIndex:z,goToNextMatch:H,goToPrevMatch:_,closeSearch:U,searchInputRef:q,handleSearchKeyDown:V}=function(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)([]),[i,c]=(0,s.useState)(0),d=(0,s.useRef)(null),u=(0,s.useRef)([]),m=(0,s.useCallback)(()=>{let t=e.current;t&&(t.querySelectorAll("mark.chat-search-match, mark.chat-search-current").forEach(e=>{let t=e.parentNode;t&&(t.replaceChild(document.createTextNode(e.textContent||""),e),t.normalize())}),u.current=[])},[e]),h=(0,s.useCallback)(t=>{if(m(),!t||!e.current){a([]),c(0);return}let r=[],n=[],s=t.toLowerCase();e.current.querySelectorAll("[data-message-id]").forEach(e=>{let o,l=e.getAttribute("data-message-id")||"",a=0,i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),c=[];for(;o=i.nextNode();)c.push(o);for(let e of c){let o=(e.textContent||"").toLowerCase(),i=0,c=[];for(;;){let e=o.indexOf(s,i);if(-1===e)break;c.push({start:e,end:e+t.length}),i=e+1}if(0!==c.length)for(let t=c.length-1;t>=0;t--){let s=c[t];e.splitText(s.end);let o=e.splitText(s.start),i=document.createElement("mark");i.className="chat-search-match",i.textContent=o.textContent,o.parentNode.replaceChild(i,o),r.push({messageId:l,markIndex:a}),n.push(i),a++}}}),r.reverse(),n.reverse(),u.current=n,a(r),c(r.length>0?0:-1)},[e,m]);(0,s.useEffect)(()=>{queueMicrotask(()=>h(n))},[n,h]),(0,s.useEffect)(()=>{let e=u.current;e.forEach((e,t)=>{e.className=t===i?"chat-search-current":"chat-search-match"}),i>=0&&i<e.length&&e[i].scrollIntoView({behavior:"smooth",block:"center"})},[i,l]);let x=(0,s.useCallback)(()=>{0!==l.length&&c(e=>(e+1)%l.length)},[l.length]),f=(0,s.useCallback)(()=>{0!==l.length&&c(e=>(e-1+l.length)%l.length)},[l.length]),p=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>d.current?.focus(),0)},[]),g=(0,s.useCallback)(()=>{r(!1),o(""),m(),a([]),c(0)},[m]),b=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?f():x()),"Escape"===e.key&&g()},[x,f,g]);return(0,s.useEffect)(()=>{let t=e.current;if(!t)return;let r=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),e.stopPropagation(),p())};return t.addEventListener("keydown",r),()=>t.removeEventListener("keydown",r)},[e,p]),{isSearchVisible:t,searchQuery:n,setSearchQuery:o,matches:l,currentMatchIndex:i,goToNextMatch:x,goToPrevMatch:f,openSearch:p,closeSearch:g,searchInputRef:d,handleSearchKeyDown:b}}(N),K=C(),J=(0,s.useRef)(null),X=(0,s.useRef)(()=>{}),{addComment:Y,refresh:Q}=p({cwd:r||"",filePath:x}),[G,Z]=(0,s.useState)(null),[ee,et]=(0,s.useState)(null),er=(0,s.useCallback)(e=>{if(G||ee)return;let t=window.getSelection();if(!t||t.isCollapsed||!t.rangeCount){J.current=null,X.current();return}let r=t.toString().trim();if(!r){J.current=null,X.current();return}let n=t.anchorNode instanceof HTMLElement?t.anchorNode:t.anchorNode?.parentElement;if(n?.closest('[data-role="user"]')){J.current=null,X.current();return}J.current={x:e.clientX,y:e.clientY,range:{start:0,end:0},selectedText:r},X.current()},[G,ee]),en=(0,s.useCallback)(e=>{let t=e.target;!(t.closest(".floating-toolbar")||t.closest('[class*="z-[200]"]'))&&J.current&&(J.current=null,X.current())},[]),es=(0,s.useCallback)(()=>{let e=J.current;e&&(Z({x:e.x,y:e.y,text:e.selectedText}),J.current=null,X.current(),window.getSelection()?.removeAllRanges())},[]),eo=(0,s.useCallback)(()=>{let e=J.current;e&&(et({x:e.x,y:e.y,text:e.selectedText}),J.current=null,X.current(),window.getSelection()?.removeAllRanges())},[]),el=(0,s.useCallback)(()=>{let e=J.current;if(!e||!b)return;let t=e.selectedText.trim();J.current=null,X.current(),window.getSelection()?.removeAllRanges(),t&&b(t)},[b]),ea=(0,s.useCallback)(async e=>{G&&(await Y(0,0,e,G.text),Z(null))},[G,Y]),ei=(0,s.useCallback)(async e=>{if(ee&&K&&r)try{let t=(await m(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));t.push({filePath:x,startLine:0,endLine:0,codeContent:ee.text});let n=f(t,e);K.sendMessage(n),await h(r),Q(),et(null)}catch(e){console.error("Failed to send to AI:",e)}},[ee,K,r,Q]),ec=(0,s.useMemo)(()=>{let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))},[e]),ed=(0,s.useRef)(0),eu=(0,s.useRef)(!1),em=(0,s.useCallback)(()=>{let e=k.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[]),eh=(0,s.useCallback)(()=>{let e=k.current;return!e||e.scrollTop<50},[]),ex=(0,s.useCallback)(()=>{let e=em(),t=eh();if(R(e),P(!t),B(!e),t&&i&&!c&&d){let e=k.current;e&&(ed.current=e.scrollHeight,eu.current=!0),d()}},[em,eh,i,c,d]),ef=(0,s.useCallback)(()=>{w.current?.scrollIntoView({behavior:"smooth"})},[]),ep=(0,s.useCallback)(()=>{y.current?.scrollIntoView({behavior:"smooth"})},[]),eg=(0,s.useCallback)(e=>{let t=k.current;if(!t)return;let r=t.querySelector(`[data-message-id="${e}"]`);r&&(r.scrollIntoView({behavior:"smooth",block:"center"}),r.classList.add("ring-2","ring-brand","ring-offset-2"),setTimeout(()=>{r.classList.remove("ring-2","ring-brand","ring-offset-2")},2e3))},[]);(0,s.useImperativeHandle)(v,()=>({scrollToMessage:eg}),[eg]);let eb=(0,s.useRef)(0),ev=(0,s.useRef)(!0);(0,s.useEffect)(()=>{let t=eb.current,r=e.length;eb.current=r,!ev.current&&T&&r>t&&y.current?.scrollIntoView({behavior:"smooth"})},[e,T]),(0,s.useEffect)(()=>{T&&t&&y.current?.scrollIntoView({behavior:"smooth"})},[t,T]),(0,s.useEffect)(()=>{if(eu.current&&!c){let e=k.current;if(e){let t=e.scrollHeight-ed.current;e.scrollTop=t,eu.current=!1}}},[e,c]);let ej=(0,s.useRef)(!1);return(0,s.useEffect)(()=>{g&&ej.current&&e.length>0&&(ej.current=!1,y.current?.scrollIntoView({behavior:"instant"}))},[g,e.length]),(0,s.useEffect)(()=>{ev.current&&e.length>0&&(ev.current=!1,g?y.current?.scrollIntoView({behavior:"instant"}):ej.current=!0)},[e.length,g]),(0,n.jsxs)("div",{ref:N,className:"relative flex-1 min-h-0 overflow-hidden flex flex-col outline-none",tabIndex:-1,onMouseUp:er,onMouseDown:en,children:[D&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:q,type:"text",value:F,onChange:e=>O(e.target.value),onKeyDown:V,placeholder:j("codeViewer.searchChat"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:W.length>0?`${z+1}/${W.length}`:j("common.noMatch")}),(0,n.jsx)("button",{onClick:_,disabled:0===W.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:j("codeViewer.prevShiftEnter"),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"})})}),(0,n.jsx)("button",{onClick:H,disabled:0===W.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:j("codeViewer.nextEnter"),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"})})}),(0,n.jsx)("button",{onClick:U,className:"p-1 rounded hover:bg-accent",title:j("codeViewer.closeEsc"),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)("div",{ref:k,onScroll:ex,className:"relative flex-1 min-h-0 overflow-y-auto p-4",children:0!==e.length||t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:w}),i&&(0,n.jsx)("div",{className:"flex justify-center py-3",children:c?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",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.jsx)("span",{children:j("chat.loadMoreHistory")})]}):(0,n.jsx)("button",{onClick:d,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:j("chat.scrollUpForMore")})}),ec.map(e=>(0,n.jsx)("div",{"data-message-id":e.id,className:"transition-[box-shadow] duration-300",children:(0,n.jsx)(np,{message:e,cwd:r,sessionId:l,onFork:u})},e.id)),t&&(0,n.jsx)("div",{className:"flex justify-start mb-4",children:(0,n.jsx)("div",{className:"bg-accent rounded-2xl rounded-bl-md px-4 py-3",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-5 h-5 border-2 border-brand border-t-transparent rounded-full animate-spin"}),(0,n.jsx)("span",{className:"text-sm",children:"claude2"===a?"Claude 2 is thinking...":"codex"===a?"Codex is thinking...":"kimi"===a?"Kimi is thinking...":"ollama"===a?"Ollama is thinking...":j("chat.claudeThinking")})]})})}),(0,n.jsx)("div",{ref:y})]}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-slate-9",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCAC"}),(0,n.jsx)("div",{children:j("chat.startConversation")})]})})}),$&&e.length>0&&(0,n.jsx)("button",{onClick:ef,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",title:j("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"})})}),I&&e.length>0&&(0,n.jsx)("button",{onClick:ep,className:"absolute bottom-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",title:j("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"})})}),E&&(0,n.jsx)(A,{floatingToolbarRef:J,bumpRef:X,container:E,onAddComment:es,onSendToAI:eo,onSearch:b?el:void 0,isChatLoading:K?.isLoading}),G&&E&&(0,n.jsx)(S,{x:G.x,y:G.y,range:{start:0,end:0},codeContent:G.text,container:E,onSubmit:ea,onClose:()=>Z(null)}),ee&&E&&(0,n.jsx)(L,{x:ee.x,y:ee.y,range:{start:0,end:0},codeContent:ee.text,container:E,onSubmit:ei,onClose:()=>et(null),isChatLoading:K?.isLoading})]})});function nb({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)(r0.Z,{children:s})}function nv({images:e,onRemove:t,disabled:r}){let{t:l}=(0,o.Bd)(),[a,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:l("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:l("imagePreview.deleteImage"),children:"✕"})]},e.id))}),a&&(0,n.jsx)(nb,{image:a,onClose:()=>i(null)})]})}var nj=r(28147);let ny=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:l,onShowGitStatus:a,onShowComments:i,onShowUserMessages:c,onOpenNote:d,onCreateScheduledTask:u}){let{t:m}=(0,o.Bd)(),[h,x]=(0,s.useState)(""),[f,p]=(0,s.useState)([]),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)(!1),[w,k]=(0,s.useState)(0),[N,C]=(0,s.useState)(!1),S=(0,s.useRef)(null),L=(0,s.useRef)(null),E=(0,s.useCallback)(()=>{let e=S.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)(()=>{E()},[h,E]),(0,s.useEffect)(()=>{(async()=>{try{let e=r?`/api/commands?cwd=${encodeURIComponent(r)}`:"/api/commands",t=await fetch(e);if(t.ok){let e=await t.json();v(e)}}catch(e){console.error("Failed to load commands:",e)}})()},[r]);let M=(0,s.useMemo)(()=>{if(!h.startsWith("/"))return[];let e=h.toLowerCase();return b.filter(t=>t.name.toLowerCase().startsWith(e))},[h,b]),T=!N&&h.startsWith("/")&&M.length>0,R=(0,s.useRef)(h);(0,s.useLayoutEffect)(()=>{R.current!==h&&(queueMicrotask(()=>k(0)),N&&queueMicrotask(()=>C(!1)),R.current=h)},[h,N]),(0,s.useLayoutEffect)(()=>{if(T&&L.current){let e=L.current.children[w];e&&e.scrollIntoView({block:"nearest"})}},[w,T]);let $=(0,s.useCallback)(()=>{let r=h.trim();(r||f.length>0)&&!t&&(e(r,f.length>0?f:void 0),x(""),p([]),S.current&&(S.current.style.height="auto"))},[h,f,t,e]),P=(0,s.useCallback)(e=>{x(e.name+" "),S.current?.focus()},[]),I=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(T&&M.length>0){if("ArrowDown"===e.key){e.preventDefault(),k(e=>(e+1)%M.length);return}if("ArrowUp"===e.key){e.preventDefault(),k(e=>(e-1+M.length)%M.length);return}if("Enter"===e.key){e.preventDefault(),P(M[w]);return}if("Escape"===e.key){e.preventDefault(),C(!0);return}if("Tab"===e.key){e.preventDefault(),P(M[w]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),$())}},[T,M,w,P,$]),B=(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(m("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};p(e=>[...e,s])},s.readAsDataURL(r)}}},[m]),D=(0,s.useCallback)(e=>{p(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nv,{images:f,onRemove:D,disabled:t}),T&&M.length>0&&(0,n.jsx)("div",{ref:L,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:M.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>P(e),className:`flex items-center gap-3 px-4 py-2 cursor-pointer ${t===w?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:e.name}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children: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"global":return"bg-green-9/15 text-green-11 dark:bg-green-9/25 dark:text-green-11";case"project":return"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25 dark:text-amber-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return m("common.builtin");case"global":return m("common.global");case"project":return m("common.project")}})(e.source)})]},e.name))}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{try{(await fetch("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:r,files:["."]})})).ok?((0,g.oR)(m("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(0,g.oR)(m("toast.stageFailed"),"error")}catch(e){console.error("Error staging files:",e),(0,g.oR)(m("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:m("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"})})}),a&&(0,n.jsx)("button",{onClick:a,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:m("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"})]})}),i&&(0,n.jsx)("button",{onClick:i,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:m("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"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:m("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"})})}),d&&(0,n.jsx)("button",{onClick:d,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:m("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"})})}),u&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>y(!j),className:`p-2 rounded-lg transition-all ${j?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:m("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"})]})}),j&&(0,n.jsx)(nj.E,{onClose:()=>y(!1),onCreate:u})]}),(0,n.jsx)("textarea",{ref:S,value:h,onChange:e=>x(e.target.value),onKeyDown:I,onPaste:B,placeholder:t?m("chat.placeholderDisabled"):m("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(97440),nk=r(31914);function nN(e){if(0===e.length)return"";let t=[c.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===x),n=e.filter(e=>e.filePath!==x);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(c.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 nC({isOpen:e,onClose:t,cwd:r,onNavigateToComment:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)([]),[d,f]=(0,s.useState)(!1),[p,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(!1),y=(0,s.useCallback)(async()=>{if(r){f(!0);try{let e=await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&all=true`);if(e.ok){let t=await e.json();c(t.comments||[])}}catch(e){console.error("Failed to load comments:",e)}finally{f(!1)}}},[r]);(0,s.useEffect)(()=>{e&&y()},[e,y]);let w=async e=>{try{(await fetch(`/api/comments?cwd=${encodeURIComponent(r)}&id=${encodeURIComponent(e)}`,{method:"DELETE"})).ok&&(c(t=>t.filter(t=>t.id!==e)),u())}catch(e){console.error("Failed to delete comment:",e)}},k=async e=>{b(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await fetch(`/api/files/read?cwd=${encodeURIComponent(r)}&path=${encodeURIComponent(e.filePath)}`);if(!n.ok)throw Error("Failed to read file");t=((await n.json()).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=nN([n]);await navigator.clipboard.writeText(s),(0,g.oR)(a("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{b(null)}},N=async()=>{if(0!==i.length){j(!0);try{let e=await m(r),t=nN(e);await navigator.clipboard.writeText(t),(0,g.oR)(a("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{j(!1)}}},C=i.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let S=(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:a("comments.allComments")}),i.length>0&&(0,n.jsx)("button",{onClick:N,disabled:v,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:a("comments.copyAllComments"),children:v?(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:d?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:a("common.loading")}):0===i.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:a("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(C).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===x?a("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",a("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:()=>l?.(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:[a("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",a("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:a("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},disabled:p===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:a("common.copy"),children:p===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(),w(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:a("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:a("comments.totalComments",{count:i.length})}),(0,n.jsx)("button",{onClick:async()=>{0===i.length||await h(r)&&c([])},disabled:0===i.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:a("comments.clearAll")})]})]})});return(0,n.jsx)(r0.Z,{children:S})}function nS({isOpen:e,onClose:t,messages:r,onSelectMessage:l}){let{t:a}=(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:a("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:a("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:i.map((e,r)=>{let s,o,a,i=(s=e.id.match(/^user-(\d+)/))?parseInt(s[1],10):null,c=i?(o=new Date(i),a=new Date,o.toDateString()===a.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:()=>{l(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)(r0.Z,{children:c})}function nL({cwd:e,sessionId:t,onOpenProjectSessions:r,onOpenSessionBrowser:l,onOpenSettings:a}){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:l,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:a,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 nE({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),s=t?.status==="rejected"?"text-red-500":t?.status==="allowed_warning"?"text-yellow-500":"text-muted-foreground",l=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,a=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-Date.now();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`},i=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&&l&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${s}`,title:[t.rateLimitType&&`Type: ${i(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${a(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:l}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${a(t.resetsAt)}`]})]}),t&&!l&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:[t.rateLimitType&&i(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${a(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:a(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 nM({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[l,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({top:0,left:0});(0,s.useEffect)(()=>{if(!r)return;let e=e=>{p.current&&!p.current.contains(e.target)&&f.current&&!f.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let v=(0,s.useCallback)(async()=>{d(!0),m(null);try{let e=await fetch("/api/ollama/models");if(503===e.status){x(!0);let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json();if(404===e.status){m(t.message||"Ollama is not installed"),x(!1);return}if(!e.ok){m("Failed to start Ollama"),x(!1);return}x(!1);let r=await fetch("/api/ollama/models");if(!r.ok)return void m("Ollama started but cannot fetch models");let n=await r.json();i(n.models||[])}else if(e.ok){let t=await e.json();i(t.models||[])}else m("Failed to fetch models")}catch{m("Connection error")}finally{d(!1)}},[]),j=e?e.replace(/:latest$/,""):"Select model",y=r?(0,a.createPortal)((0,n.jsx)("div",{ref:p,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:g.top,left:g.left},children:c||h?(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"}),h?"Starting Ollama...":"Loading models..."]}):u?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-400",children:u}):0===l.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>"})]}):l.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)})}),document.body):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,onClick:()=>{if(!r){if(f.current){let e=0,t=0,r=f.current.parentElement;for(;r;){let n=getComputedStyle(r).transform;if(n&&"none"!==n){let n=r.getBoundingClientRect();e=n.left-r.offsetLeft,t=n.top-r.offsetTop;break}r=r.parentElement}let n=f.current.getBoundingClientRect();b({top:n.bottom+4-t,left:n.left-e})}v()}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:j}),(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"})})]}),y]})}function nT({tabId:e,initialCwd:t,initialSessionId:r,engine:a,ollamaModel:i,onOllamaModelChange:d,hideHeader:u,hideSidebar:m,isActive:h=!0,onLoadingChange:x,onSessionIdChange:f,onTitleChange:p,onShowGitStatus:g,onOpenNote:b,onCreateScheduledTask:v,onOpenSession:j,onContentSearch:y}){let{t:w}=(0,o.Bd)(),k=C(),[N,S]=(0,s.useState)([]),[L,E]=(0,s.useState)(null),[M,T]=(0,s.useState)(!1),[R,$]=(0,s.useState)(!1),[P,I]=(0,s.useState)(!1),[B,D]=(0,s.useState)(!1),[F,O]=(0,s.useState)(!1),[A,W]=(0,s.useState)(!1),[z,H]=(0,s.useState)(null),_=(0,s.useRef)(null),U=(0,s.useRef)(null),q=(0,s.useCallback)(async e=>{if(t)try{let r=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,sessionId:e})});if(r.ok){let e=await r.json();e.title&&p?.(e.title)}}catch(e){console.error("Failed to fetch session title:",e)}},[t,p]),{isLoading:V,tokenUsage:K,rateLimitInfo:J,handleSend:X,handleStop:Y}=function(e,t,{sessionId:r,cwd:n,engine:o,ollamaModel:l,onSessionId:a,onFetchTitle:i}){let[d,u]=(0,s.useState)(!1),[m,h]=(0,s.useState)(null),[x,f]=(0,s.useState)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(r);g.current=r;let b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>{let e=b.current;if(e&&e.text){let{messageId:r,text:n}=e;t(e=>e.map(e=>e.id===r?{...e,content:(e.content||"")+n}:e)),b.current={messageId:r,text:""}}v.current=null},[t]),y=(0,s.useCallback)(()=>{p.current&&(p.current.abort(),p.current=null)},[]),w=(0,s.useCallback)((e,r)=>{let s=e.type;if("system"===s&&"init"===e.subtype){let t=e.session_id;a(t),g.current=t;return}if("rate_limit_event"===s){let t=e.rate_limit_info;t&&f({status:t.status||"allowed",resetsAt:t.resetsAt,rateLimitType:t.rateLimitType,utilization:t.utilization,overageStatus:t.overageStatus,overageDisabledReason:t.overageDisabledReason,isUsingOverage:t.isUsingOverage,surpassedThreshold:t.surpassedThreshold});return}if("stream_event"===s){let t=e.event;if(t?.type==="content_block_delta"&&t.delta?.type==="text_delta"){let e=t.delta.text||"";b.current&&b.current.messageId===r?b.current.text+=e:b.current={messageId:r,text:e},v.current||(v.current=setTimeout(j,50))}return}if("assistant"===s){let n=e.message;if(n?.content){if("codex"===o||"kimi"===o||"ollama"===o){let e=n.content.filter(e=>"text"===e.type&&e.text).map(e=>e.text);if(e.length>0){let n=e.join("");t(e=>e.map(e=>e.id===r?{...e,content:(e.content||"")+n}:e))}}for(let e of n.content)if("name"in e&&e.name){let n={id:e.id||`tool-${Date.now()}`,name:e.name,input:e.input||{},isLoading:!0};t(e=>e.map(e=>e.id!==r||e.toolCalls?.some(e=>e.id===n.id)?e:{...e,toolCalls:[...e.toolCalls||[],n]}))}}}if("user"===s){let n=e.message;if(n?.content){for(let e of n.content)if("tool_use_id"in e&&e.tool_use_id){let n=e.tool_use_id,s="string"==typeof e.content?e.content:JSON.stringify(e.content);t(e=>e.map(e=>e.id===r?{...e,toolCalls:e.toolCalls?.map(e=>e.id===n?{...e,result:s,isLoading:!1}:e)}:e))}}}if("result"===s){v.current&&(clearTimeout(v.current),v.current=null),j();let s=g.current;s&&n&&t(e=>(2===e.length&&i(s),e));let o=e.usage,l=e.total_cost_usd;o&&h({inputTokens:o.input_tokens||0,outputTokens:o.output_tokens||0,cacheCreationInputTokens:o.cache_creation_input_tokens||0,cacheReadInputTokens:o.cache_read_input_tokens||0,totalCostUsd:l||0}),t(e=>e.map(e=>e.id===r?{...e,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e))}},[t,j,a,i,n,o]);return{isLoading:d,tokenUsage:m,rateLimitInfo:x,handleSend:(0,s.useCallback)(async(e,r)=>{let s=r?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),a={id:`user-${Date.now()}`,role:"user",content:e,images:s};t(e=>[...e,a]),u(!0);let i=`assistant-${Date.now()}`,d={id:i,role:"assistant",content:"",toolCalls:[],isStreaming:!0};t(e=>[...e,d]),p.current=new AbortController;try{if("ollama"===o&&!l)throw Error("Please select an Ollama model first (click the model picker above)");let t="codex"===o?"/api/chat/codex":"kimi"===o?"/api/chat/kimi":"ollama"===o?"/api/chat/ollama":"/api/chat",r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:g.current,images:s,cwd:n,language:c.A.language,..."ollama"===o&&l&&{model:l},..."claude2"===o&&{engine:"claude2"}}),signal:p.current.signal});if(!r.ok)throw Error(c.A.t("chat.requestFailed"));let a=r.body?.getReader();if(!a)throw Error(c.A.t("chat.cannotReadStream"));let d=new TextDecoder,u="";for(;;){let{done:e,value:t}=await a.read();if(e)break;let r=(u+=d.decode(t,{stream:!0})).split("\n");for(let e of(u=r.pop()||"",r))if(e.startsWith("data: ")){let t=e.slice(6);if("[DONE]"===t)continue;try{let e=JSON.parse(t);w(e,i)}catch{}}}}catch(e){if(e instanceof Error&&"AbortError"===e.name);else{console.error("Chat error:",e);let r=e instanceof Error?e.message:c.A.t("chat.errorRetry");t(e=>e.map(e=>e.id===i?{...e,content:r,isStreaming:!1}:e))}}finally{p.current=null,u(!1),t(e=>e.map(e=>e.id===i?{...e,isStreaming:!1}:e))}},[n,o,l,t,w]),handleStop:y,abortControllerRef:p}}(0,S,{sessionId:L,cwd:t,engine:a,ollamaModel:i,onSessionId:E,onFetchTitle:q}),Q=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void X(e,r);let o=e.split("\n").slice(1).join("\n").trim();try{let e=await fetch("/api/bash",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({command:s,cwd:t})}),n=await e.json(),l=[n.stdout,n.stderr].filter(Boolean).join("\n")||"(no output)",a=n.exitCode?` (exit code: ${n.exitCode})`:"",i=w("chat.executedCommand",{command:s,exitInfo:a,output:l});o&&(i+=`
24
+
25
+ ${o}`),X(i,r)}catch(e){X(w("chat.executedCommandFailed",{command:s,error:e}),r)}return}X(e,r)},[X,t,w]),{isLoadingHistory:G,isLoadingMore:Z,hasMoreHistory:ee,loadMoreHistory:et,loadHistoryByCwdAndSessionId:er}=function(e,t,r,{cwd:n,initialSessionId:o,onSessionId:l,onTitleChange:a,onTokenUsage:i}){let[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(!1),[f,p]=(0,s.useState)(void 0),[g,b]=(0,s.useState)(0),v=(0,s.useRef)(a);v.current=a;let j=(0,s.useRef)(i);j.current=i;let y=(0,s.useRef)(void 0),w=(0,s.useRef)(0),k=(0,s.useCallback)(async(e,r,n=!1,s,o)=>{if(n){let e=Date.now();if(e-w.current<5e3)return;w.current=e}n||d(!0);try{let a={cwd:e,sessionId:r,limit:s,beforeTurnIndex:o};n&&y.current&&(a.ifFingerprint=y.current);let i=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(i.ok){let e=await i.json();if(e.notModified)return;e.fingerprint&&(y.current=e.fingerprint),void 0!==e.totalTurns&&b(e.totalTurns),void 0!==e.hasMore&&x(e.hasMore),e.messages&&e.messages.length>0&&(n?t(t=>{let r=e.messages;if(t.length===r.length&&t.length>0&&t[t.length-1].content===r[r.length-1].content)return t;let n=0;for(let e=0;e<Math.min(t.length,r.length)&&t[e].id===r[e].id&&t[e].content===r[e].content;e++)n=e+1;return n===t.length&&n<r.length?[...t,...r.slice(n)]:r}):t(e.messages)),e.sessionId&&l(e.sessionId),e.title&&v.current?.(e.title),e.usage&&j.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{n||d(!1)}},[t,l]),N=(0,s.useCallback)(async()=>{if(n&&r&&!u&&h){m(!0);try{let s=void 0!==f?f:g-Math.ceil(e.filter(e=>"user"===e.role).length),o=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:n,sessionId:r,limit:10,beforeTurnIndex:s>0?s:void 0})});if(o.ok){let e=await o.json();if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let r=e.messages.filter(e=>"user"===e.role).length;p(s-r)}void 0!==e.hasMore&&x(e.hasMore),e.fingerprint&&(y.current=e.fingerprint)}}catch(e){console.error("Failed to load more history:",e)}finally{m(!1)}}},[n,r,u,h,f,g,e,t]),C=(0,s.useCallback)(async e=>{d(!0);try{let r=await fetch(`/api/session/${e}/history`);if(r.ok){let e=await r.json();e.messages&&e.messages.length>0&&t(e.messages)}}catch(e){console.error("Failed to load history:",e)}finally{d(!1)}},[t]);return(0,s.useEffect)(()=>{n&&o&&k(n,o,!1,10)},[]),{isLoadingHistory:c,isLoadingMore:u,hasMoreHistory:h,loadMoreHistory:N,loadHistory:C,loadHistoryByCwdAndSessionId:k}}(N,S,L,{cwd:t,initialSessionId:r,onSessionId:E,onTitleChange:p,onTokenUsage:H}),en=(0,s.useRef)(h);(0,s.useEffect)(()=>{h&&!en.current&&L&&t&&!V&&er(t,L,!0,10),en.current=h},[h,L,t,V,er]);let es=K||z;(0,s.useEffect)(()=>{L&&f?.(L)},[L,f]);let eo=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(x?.(V),eo.current&&!V&&t&&L){let e;for(let t=N.length-1;t>=0;t--)if("user"===N[t].role&&N[t].content){e=N[t].content.slice(0,100);break}window.parent.postMessage({type:"SESSION_COMPLETE",cwd:t,sessionId:L,lastUserMessage:e},"*")}eo.current=V},[V,x,t]),(0,s.useEffect)(()=>{h&&k?.setIsLoading(V)},[V,h,k]),(0,s.useEffect)(()=>{if(e&&k)return k.registerChat(e=>{U.current?.(e)},e),()=>{k.unregisterChat(e)}},[e,k]),(0,s.useEffect)(()=>{e&&h&&k&&k.setActiveTab(e)},[e,h,k]),(0,s.useEffect)(()=>{U.current=Q},[Q]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&M&&V&&Y()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[M,V,Y]);let el=(0,s.useCallback)(async e=>{if(t&&L)try{let r=await fetch(`/api/session/${L}/fork`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,fromMessageUuid:e})});if(r.ok){let e=await r.json();j?j(e.newSessionId,"Fork"):window.parent.postMessage({type:"OPEN_PROJECT",cwd:t,sessionId:e.newSessionId},"*")}else console.error("Fork failed:",await r.text())}catch(e){console.error("Fork error:",e)}},[t,L,j]),ea=(0,s.useCallback)(()=>{O(!0)},[]),ei=(0,s.useCallback)(()=>{W(!0)},[]),ec=(0,s.useMemo)(()=>{if(v&&t&&e&&L)return r=>{v({...r,cwd:t,tabId:e,sessionId:L})}},[v,t,e,L]);return(0,n.jsxs)("div",{className:`flex ${u&&m?"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:()=>T(!0),onMouseLeave:()=>T(!1),children:[!u&&(0,n.jsx)(nL,{cwd:t,sessionId:L,onOpenProjectSessions:()=>I(!0),onOpenSessionBrowser:()=>$(!0),onOpenSettings:()=>D(!0)}),"ollama"===a&&d&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(nM,{currentModel:i,onModelChange:d})}),G?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:w("sessions.loadingHistory")})}):(0,n.jsx)(ng,{ref:_,messages:N,isLoading:V,cwd:t,sessionId:L,engine:a,hasMoreHistory:ee,isLoadingMore:Z,onLoadMore:et,onFork:el,isActive:h,onContentSearch:y}),es&&(0,n.jsx)(nE,{tokenUsage:es,rateLimitInfo:J}),(0,n.jsx)(ny,{onSend:Q,disabled:V,cwd:t,engine:a,onShowGitStatus:g,onShowComments:t?ea:void 0,onShowUserMessages:ei,onOpenNote:b,onCreateScheduledTask:ec})]}),!u&&(0,n.jsx)(nw.r,{isOpen:R,onClose:()=>$(!1)}),!u&&t&&(0,n.jsx)(l,{isOpen:P,onClose:()=>I(!1),cwd:t}),!u&&(0,n.jsx)(nk.b,{isOpen:B,onClose:()=>D(!1)}),t&&(0,n.jsx)(nC,{isOpen:F,onClose:()=>O(!1),cwd:t}),(0,n.jsx)(nS,{isOpen:A,onClose:()=>W(!1),messages:N,onSelectMessage:e=>{_.current?.scrollToMessage(e)}})]})}function nR({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:l,onOllamaModelChange:a,isActive:i,onStateChange:c,onShowGitStatus:d,onOpenNote:u,onCreateScheduledTask:m,onOpenSession:h,onContentSearch:x}){let f=(0,s.useCallback)(t=>{c(e,{isLoading:t})},[e,c]),p=(0,s.useCallback)(t=>{c(e,{sessionId:t})},[e,c]),g=(0,s.useCallback)(t=>{c(e,{title:t})},[e,c]),b=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]);return(0,n.jsx)(nT,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:l,onOllamaModelChange:b,hideHeader:!0,hideSidebar:!0,isActive:i,onLoadingChange:f,onSessionIdChange:p,onTitleChange:g,onShowGitStatus:d,onOpenNote:u,onCreateScheduledTask:m,onOpenSession:h,onContentSearch:x})}var n$=r(36998),nP=r(18658);function nI({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[a,i]=(0,s.useState)("agent"),{tabs:c,activeTabId:d,activeTab:u,unreadTabs:m,dragTabIndex:h,dragOverTabIndex:x,closeTab:f,switchTab:p,handleSelectSession:g,handleNewTab:b,handleNewClaude2Tab:v,handleNewCodexTab:j,handleNewKimiTab:y,handleNewOllamaTab:w,handleOpenSession:k,updateTabState:C,updateTabOllamaModel:S,handleTabDragStart:L,handleTabDragOver:E,handleTabDrop:M,handleTabDragEnd:T}=function({initialCwd:e,initialSessionId:t,activeView:r}){let n=(0,s.useRef)(!1),o=(0,s.useRef)(!0),l=(0,s.useRef)(r);(0,s.useEffect)(()=>{l.current=r},[r]);let a=e_(),i=(0,s.useRef)(a);(0,s.useEffect)(()=>{i.current=a},[a]);let[c,d]=(0,s.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[u,m]=(0,s.useState)(c[0].id),[h,x]=(0,s.useState)(new Set),f=(0,s.useRef)(c);(0,s.useEffect)(()=>{f.current=c},[c]);let p=(0,s.useCallback)((t,r)=>{e&&t&&fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})}).catch(()=>{})},[e]),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null);(0,s.useEffect)(()=>{!e||n.current||(n.current=!0,(async()=>{try{let r=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(r.ok){let n=await r.json(),s=n.sessions||[],l=n.activeSessionId,a=n.engines||{},i=n.ollamaModels||{},c=[...s];if(t&&!c.includes(t)&&(c=[t,...c]),c.length>0){let r=c.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:a[t]||void 0,ollamaModel:i[t]||void 0})),n=t||l,s=n?c.indexOf(n):-1;s<0&&(s=0);let u=r[s].id;d(r),m(u),setTimeout(()=>{o.current=!1},0)}else o.current=!1}}catch(e){console.error("Failed to load sessions:",e),o.current=!1}})())},[e,t]),(0,s.useEffect)(()=>{if(o.current||!e)return;let t=c.map(e=>e.sessionId).filter(e=>!!e),r=c.find(e=>e.id===u),n=r?.sessionId,s={},l={};for(let e of c)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(l[e.sessionId]=e.ollamaModel);fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:l})}).catch(e=>{console.error("Failed to save sessions:",e)})},[c,u,e]),(0,s.useEffect)(()=>{if(o.current||!e)return;let t=c.find(e=>e.id===u);t?.sessionId&&window.parent.postMessage({type:"SESSION_CHANGE",cwd:e,sessionId:t.sessionId},"*")},[u,c,e]);let y=(0,s.useCallback)((e,t,r,n,s)=>{let o={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s};d(e=>{let t=e.findIndex(e=>e.id===u);if(-1===t)return[...e,o];let r=[...e];return r.splice(t+1,0,o),r}),m(o.id)},[u]),w=(0,s.useCallback)(t=>{d(r=>{let n=r.filter(e=>e.id!==t);if(t===u&&n.length>0&&m(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return m(t.id),[t]}return n})},[u,e]),k=(0,s.useCallback)((t,r)=>{let n=c.find(e=>e.sessionId===t);n?m(n.id):y(e,t,r)},[c,e,y]),N=(0,s.useCallback)(()=>{y(e)},[e,y]),C=(0,s.useCallback)(()=>{y(e,void 0,"New Claude 2 Chat","claude2")},[e,y]),S=(0,s.useCallback)(()=>{y(e,void 0,"New Codex Chat","codex")},[e,y]),L=(0,s.useCallback)(()=>{y(e,void 0,"New Kimi Chat","kimi")},[e,y]),E=(0,s.useCallback)(t=>{y(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t)},[e,y]),M=(0,s.useCallback)((e,t)=>{d(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),T=(0,s.useCallback)((t,r)=>{y(e,t,r)},[e,y]),R=(0,s.useCallback)((e,t)=>{d(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!l.current||"agent"===l.current;if(e===u&&r&&i.current){let e=n.sessionId||t.sessionId;e&&p(e,"normal")}else x(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[u,p]);(0,s.useEffect)(()=>{(!r||"agent"===r)&&a&&x(e=>{if(!e.has(u))return e;let t=new Set(e);t.delete(u);let r=f.current.find(e=>e.id===u);return r?.sessionId&&(p(r.sessionId,"normal"),fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:r.sessionId}})}).catch(()=>{})),t})},[r,u,a,p]);let $=(0,s.useCallback)(e=>{m(e),x(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=f.current.find(t=>t.id===e);return n?.sessionId&&(p(n.sessionId,"normal"),fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:n.sessionId}})}).catch(()=>{})),r})},[p]),P=(0,s.useCallback)(e=>{b(e)},[]),I=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==g&&g!==t&&j(t)},[g]),B=(0,s.useCallback)(e=>{null!==g&&g!==e&&d(t=>{let r=[...t],[n]=r.splice(g,1);return r.splice(e,0,n),r}),b(null),j(null)},[g]),D=(0,s.useCallback)(()=>{b(null),j(null)},[]),F=c.find(e=>e.id===u);return{tabs:c,activeTabId:u,activeTab:F,unreadTabs:h,dragTabIndex:g,dragOverTabIndex:v,addTab:y,closeTab:w,switchTab:$,handleSelectSession:k,handleNewTab:N,handleNewClaude2Tab:C,handleNewCodexTab:S,handleNewKimiTab:L,handleNewOllamaTab:E,handleOpenSession:T,updateTabState:R,updateTabOllamaModel:M,handleTabDragStart:P,handleTabDragOver:I,handleTabDrop:B,handleTabDragEnd:D}}({initialCwd:e,initialSessionId:t,activeView:a}),{isPinned:R,pinSession:$,unpinSession:P}=(0,n$.P)(),{createTask:I}=(0,nP.n)(),B=(0,s.useCallback)(e=>{let t=c.find(t=>t.id===e);return!!t?.sessionId&&R(t.sessionId)},[c,R]),D=(0,s.useCallback)(t=>{let r=c.find(e=>e.id===t);r?.sessionId&&(R(r.sessionId)?P(r.sessionId):$(r.sessionId,r.cwd||e||"",r.title))},[c,R,$,P,e]),[F,O]=(0,s.useState)(!1),[A,W]=(0,s.useState)(!1),[z,H]=(0,s.useState)(!1),[_,U]=(0,s.useState)(null),[q,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)("tree"),[X,Y]=(0,s.useState)(0),[Q,G]=(0,s.useState)(null),[Z,ee]=(0,s.useState)(0);(0,s.useEffect)(()=>{e&&fetch(`/api/project-settings?cwd=${encodeURIComponent(e)}`).then(e=>e.ok?e.json():null).then(e=>{e?.settings?.activeView&&i(e.settings.activeView)}).catch(()=>{})},[e]);let[et,er]=(0,s.useState)(!1),en=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(en.current=a,i("console"),er(!0)):(er(!1),en.current&&"console"!==en.current&&i(en.current),en.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[a]);let es=(0,s.useCallback)(t=>{i(t),e&&(fetch("/api/project-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,settings:{activeView:t}})}).catch(()=>{}),window.parent.postMessage({type:"VIEW_CHANGE",cwd:e,view:t},"*"))},[e]),eo=(0,s.useCallback)(async()=>{if(e)try{let t=await fetch(`/api/git/worktree?cwd=${encodeURIComponent(e)}`);if(t.ok){let r=await t.json();if(V(r.isGitRepo),r.isGitRepo&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&U(t.branch)}}}catch(e){console.error("Failed to load git info:",e)}},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eo())},[eo]);let el=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&eo()},[eo]);(0,eH.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:el,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),es("agent")):"2"===e.key?(e.preventDefault(),es("explorer")):"3"===e.key&&(e.preventDefault(),es("console")))};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){g(r),n&&es("agent");let t=c.find(e=>e.sessionId===r);e&&!t?.isLoading&&fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:r,status:"normal"})}).catch(()=>{})}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[g,es,e,c]);let ea=(0,s.useCallback)(()=>{J("status"),Y(e=>e+1),es("explorer")},[es]),ei=(0,s.useCallback)(e=>{G(e),ee(e=>e+1),es("explorer")},[es]),ec=(0,s.useCallback)(()=>{e&&window.parent.postMessage({type:"OPEN_NOTE",cwd:e},"*")},[e]);return(0,n.jsx)(N,{children:(0,n.jsx)(e1,{activeView:a,onViewChange:es,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)(rY,{initialCwd:e,activeTab:u,isGitRepo:q,currentBranch:_,onOpenWorktree:()=>W(!0),onOpenProjectSessions:()=>O(!0),onOpenAliasManager:()=>H(!0),onBranchSwitched:eo}),et&&(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)(e2,{children:[(0,n.jsxs)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:[(0,n.jsx)(rZ,{tabs:c,activeTabId:d,unreadTabs:m,dragTabIndex:h,dragOverTabIndex:x,isPinned:B,onTogglePin:D,onSwitchTab:p,onCloseTab:f,onNewTab:b,onNewClaude2Tab:v,onNewCodexTab:j,onNewKimiTab:y,onNewOllamaTab:w,onDragStart:L,onDragOver:E,onDrop:M,onDragEnd:T}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:c.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===d?"block":"hidden"}`,children:(0,n.jsx)(nR,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:S,isActive:e.id===d&&"agent"===a,onStateChange:C,onShowGitStatus:ea,onContentSearch:ei,onOpenNote:ec,onCreateScheduledTask:I,onOpenSession:k})},e.id))})]}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(e4,{onClose:()=>es("agent"),cwd:e,initialTab:K,tabSwitchTrigger:X,initialSearchQuery:Q,searchQueryTrigger:Z})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(r_,{cwd:e,tabId:"default",onOpenNote:ec})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(rZ,{tabs:c,activeTabId:d,unreadTabs:m,dragTabIndex:h,dragOverTabIndex:x,isPinned:B,onTogglePin:D,onSwitchTab:p,onCloseTab:f,onNewTab:b,onNewClaude2Tab:v,onNewCodexTab:j,onNewKimiTab:y,onDragStart:L,onDragOver:E,onDrop:M,onDragEnd:T}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:c.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===d?"block":"hidden"}`,children:(0,n.jsx)(nR,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:S,isActive:e.id===d,onStateChange:C,onCreateScheduledTask:I,onOpenSession:k})},e.id))})]})]}),e&&(0,n.jsx)(l,{isOpen:F,onClose:()=>O(!1),cwd:e,onSelectSession:g}),e&&q&&(0,n.jsx)(e3,{isOpen:A,onClose:()=>W(!1),cwd:e}),z&&(0,n.jsx)(tf,{onClose:()=>H(!1),onSave:()=>H(!1)})]})})})}}},e=>{e.O(0,[8653,7330,9114,3700,2072,3530,5493,1593,8441,3794,7358],()=>e(e.s=60499)),_N_E=e.O()}]);