@surething/cockpit 1.0.200 → 1.0.202

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 (169) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +4 -4
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/prerender-manifest.json +3 -3
  5. package/.next-prod/required-server-files.js +2 -1
  6. package/.next-prod/required-server-files.json +2 -1
  7. package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
  8. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next-prod/server/app/_global-error.html +1 -1
  10. package/.next-prod/server/app/_global-error.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  13. package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  14. package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
  15. package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
  16. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  17. package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
  18. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  19. package/.next-prod/server/app/_not-found.html +2 -2
  20. package/.next-prod/server/app/_not-found.rsc +2 -2
  21. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
  22. package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
  23. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
  24. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  25. package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  26. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  27. package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
  28. package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
  29. package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
  30. package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
  31. package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
  32. package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
  33. package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
  34. package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
  35. package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
  36. package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
  37. package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
  38. package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
  39. package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
  40. package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
  41. package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
  42. package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
  43. package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
  44. package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
  45. package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
  46. package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
  47. package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
  48. package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
  49. package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
  50. package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
  51. package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
  52. package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
  53. package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
  54. package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
  55. package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
  56. package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
  57. package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
  58. package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
  59. package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
  60. package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
  61. package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
  62. package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
  63. package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
  64. package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
  65. package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
  66. package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
  67. package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
  68. package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
  69. package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
  70. package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
  71. package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
  72. package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
  73. package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
  74. package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
  75. package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
  76. package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
  77. package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
  78. package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
  79. package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
  80. package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
  81. package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
  82. package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
  83. package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
  84. package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
  85. package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
  86. package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
  87. package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
  88. package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
  89. package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
  90. package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
  91. package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
  92. package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
  93. package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
  94. package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
  95. package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
  96. package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
  97. package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
  98. package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
  99. package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
  100. package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
  101. package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
  102. package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
  103. package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
  104. package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
  105. package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
  106. package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
  107. package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
  108. package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
  109. package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
  110. package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
  111. package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
  112. package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
  113. package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
  114. package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
  115. package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
  116. package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
  117. package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
  118. package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
  119. package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
  120. package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
  121. package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
  122. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
  123. package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
  124. package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
  125. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
  126. package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
  127. package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
  128. package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
  129. package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
  130. package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
  131. package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
  132. package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
  133. package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
  134. package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
  135. package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
  136. package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
  137. package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
  138. package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
  139. package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
  140. package/.next-prod/server/app/page.js.nft.json +1 -1
  141. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  142. package/.next-prod/server/app/project/page.js +17 -20
  143. package/.next-prod/server/app/project/page.js.nft.json +1 -1
  144. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  145. package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
  146. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  147. package/.next-prod/server/app-paths-manifest.json +4 -4
  148. package/.next-prod/server/chunks/4098.js +1 -1
  149. package/.next-prod/server/chunks/7051.js +1 -0
  150. package/.next-prod/server/chunks/7514.js +1 -1
  151. package/.next-prod/server/middleware-build-manifest.js +1 -1
  152. package/.next-prod/server/pages/404.html +2 -2
  153. package/.next-prod/server/pages/500.html +1 -1
  154. package/.next-prod/server/server-reference-manifest.json +1 -1
  155. package/.next-prod/server/webpack-runtime.js +1 -1
  156. package/.next-prod/static/chunks/3530-7b425f5e2c9b3a6f.js +14 -0
  157. package/.next-prod/static/chunks/app/project/{page-cf0d2dc22fe0e7ec.js → page-f391e1786266d31a.js} +1 -1
  158. package/.next-prod/trace +12 -12
  159. package/.next-prod/trace-build +1 -1
  160. package/README.md +5 -0
  161. package/README.zh.md +5 -0
  162. package/next.config.mjs +8 -0
  163. package/package.json +1 -1
  164. package/.next-prod/server/chunks/2491.js +0 -1
  165. package/.next-prod/server/chunks/4796.js +0 -4
  166. package/.next-prod/server/chunks/static/media/web-tree-sitter.f7f7244f.wasm +0 -0
  167. package/.next-prod/static/chunks/3530-fc8a5ada5a6dc865.js +0 -14
  168. /package/.next-prod/static/{yaVe-Z92QwkIrhkztzo43 → Rpj4wF03IZGLp_Y727qmp}/_buildManifest.js +0 -0
  169. /package/.next-prod/static/{yaVe-Z92QwkIrhkztzo43 → Rpj4wF03IZGLp_Y727qmp}/_ssgManifest.js +0 -0
@@ -1,4 +1,4 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6500],{31898:(e,t,r)=>{"use strict";r.d(t,{TabManager:()=>n2});var n=r(95155),s=r(12115),o=r(79114);function a({isOpen:e,onClose:t,cwd:r,onSelectSession:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(null),[f,p]=(0,s.useState)(""),g=(0,s.useRef)(null),b=(0,s.useCallback)(async()=>{if(r){m(!0),x(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();d(n)}catch(e){x(e instanceof Error?e.message:"Unknown error")}finally{m(!1)}}},[r]);(0,s.useEffect)(()=>{e&&(b(),setTimeout(()=>{g.current?.focus()},100))},[e,b]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let v=c.filter(e=>{if(!f)return!0;let t=f.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:i("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:g,type:"text",placeholder:i("sessions.searchSessions"),value:f,onChange:e=>p(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:[u&&(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:i("sessions.loadingSessions")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:h})}),!u&&!h&&0===v.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:i(f?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!u&&!h&&v.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:v.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 l=r(47650),i=r(44810),c=r(64702),d=r(71063),u=r(10222),m=r(57842),h=r(1531),x=r(91694);function f(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,a=n.length,l=Array(o+1).fill(null).map(()=>Array(a+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=a;t++)r[e-1]===n[t-1]?l[e][t]=l[e-1][t-1]+1:l[e][t]=Math.max(l[e-1][t],l[e][t-1]);let i=o,c=a,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||l[i][c-1]>=l[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 p=r(38093),g=r(82085),b=r(23193);function v({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,a]=(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)a({top:0,height:o});else{let e=o/n;a({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 l=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(),a=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,a),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*l}%`,height:`${Math.max(l,.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`}})]})}var j=r(74567),y=r(84392);let w=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:a,onSearch:l,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)(j.w,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:a,onSearch:l,isChatLoading:i})});function k({oldContent:e,newContent:t,filePath:r,isNew:a=!1,isDeleted:i=!1,cwd:j,enableComments:N=!1,onPreview:C,previewLabel:S,onContentSearch:L,targetLine:M}){let{t:E}=(0,o.Bd)(),$=S??E("common.preview"),T=(0,s.useMemo)(()=>f(e,t),[e,t]),R=(0,s.useRef)(null),P=(0,s.useRef)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(!1),[I,D]=(0,s.useState)(!1),O=(0,m.iN)(),A=(0,h.nH)(),_=N&&!!j,{comments:W,addComment:z,updateComment:H,deleteComment:q,refresh:U}=(0,d._)({cwd:j||"",filePath:r}),[V,K]=(0,s.useState)(null),J=(0,s.useRef)(null),Q=(0,s.useRef)(()=>{}),[X,Y]=(0,s.useState)(null),[G,Z]=(0,s.useState)(null);(0,s.useEffect)(()=>{D(!0)},[]);let ee=(0,s.useMemo)(()=>{let e=new Set;for(let t of W)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[W]),et=(0,s.useMemo)(()=>{let e=new Map;for(let t of W){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[W]);(0,s.useEffect)(()=>{if(!_)return;let e=B.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,J.current&&(J.current=null,Q.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,a=window.getSelection();if(!a||a.isCollapsed||!a.toString().trim()||!o){J.current&&(J.current=null,Q.current());return}let l=a.getRangeAt(0),i=B.current;if(!i||!i.contains(l.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(l.startContainer),u=c(l.endContainer);if(d&&u){let t=Math.min(d,u),r=Math.max(d,u),n=[],s=0;for(let e of T)("unchanged"===e.type||"added"===e.type)&&++s>=t&&s<=r&&n.push(e.content);let o=n.join("\n");J.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},codeContent:o},Q.current()}},a=()=>{if(t||!J.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(J.current=null,Q.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",a),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",a)}},[_,T]);let er=(0,s.useCallback)((e,t)=>{t.stopPropagation(),K({comment:e,x:t.clientX,y:t.clientY}),J.current=null,Q.current(),Y(null),Z(null)},[]),en=(0,s.useCallback)(()=>{let e=J.current;e&&(Y({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),J.current=null,Q.current())},[]),es=(0,s.useCallback)(()=>{let e=J.current;e&&(Z({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),J.current=null,Q.current())},[]),eo=(0,s.useCallback)(()=>{let e=J.current;if(!e||!L)return;let t=e.codeContent.trim();J.current=null,Q.current(),t&&L(t)},[L]),ea=(0,s.useCallback)(async e=>{if(G&&A&&j)try{let t=await (0,u.$3)(j),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:G.range.start,endLine:G.range.end,codeContent:G.codeContent});let s=(0,u.Gw)(n,e);A.sendMessage(s),await (0,u.RP)(j),U(),Z(null)}catch(e){console.error("Failed to send to AI:",e)}},[G,A,r,j,U]),el=(0,s.useCallback)(async e=>{X&&(await z(X.range.start,X.range.end,e),Y(null))},[X,z]);(0,s.useEffect)(()=>{let e=P.current,t=B.current;if(!e||!t)return;let r=(e,t)=>{F.current||(F.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{F.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:ei,rightLines:ec}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<T.length;s++){let o=T[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}},[T]),ed=(0,s.useMemo)(()=>T.map(e=>e.content),[T]),eu=(0,g.C)(ed,r),em=(0,c.Te)({count:ei.length,getScrollElement:()=>R.current,estimateSize:()=>20,overscan:20}),eh=a?"w-1/4":i?"w-3/4":"w-1/2",ex=a?"w-3/4":i?"w-1/4":"w-1/2",ef=(0,s.useMemo)(()=>ei.map((e,t)=>{let r=ec[t];return"removed"===e.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ei,ec]),ep=em.getTotalSize(),eg=em.getVirtualItems();return(0,s.useEffect)(()=>{if(!M)return;let e=("after"===M.side?ec:ei).findIndex(e=>e.lineNum===M.line);if(-1===e)return;let t=requestAnimationFrame(()=>{em.scrollToIndex(e,{align:"start"})});return()=>cancelAnimationFrame(t)},[M,ei,ec]),(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:a?"(New File)":i?"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:i?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[C&&(0,n.jsx)("button",{onClick:C,className:"text-muted-foreground hover:text-foreground transition-colors",children:$}),!i&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,p.oR)(E("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:E("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:R,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:P,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=ei[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]||(0,b.ZD)(t.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:B,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=ec[e.index],r=t?.lineNum||0,s=r>0&&ee.has(r),o=et.get(r),a=o?.[0],l=X&&r>=X.range.start&&r<=X.range.end,i=G&&r>=G.range.start&&r<=G.range.end,c=l||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:_?"52px":"40px"},children:[_&&r>0&&s&&a&&(0,n.jsx)("button",{onClick:e=>er(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:E("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"})})}),_&&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]||(0,b.ZD)(t?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(v,{lines:ef,containerRef:R})]}),I&&O&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w,{floatingToolbarRef:J,bumpRef:Q,container:O,onAddComment:en,onSendToAI:es,onSearch:L?eo:void 0,isChatLoading:A?.isLoading??!1}),X&&(0,n.jsx)(x.t,{x:X.x,y:X.y,range:X.range,codeContent:X.codeContent,container:O,onSubmit:el,onClose:()=>Y(null)}),G&&(0,n.jsx)(x.G,{x:G.x,y:G.y,range:G.range,container:O,onSubmit:ea,onClose:()=>Z(null)}),V&&(0,n.jsx)(y.t,{x:V.x,y:V.y,comment:V.comment,container:O,onClose:()=>K(null),onUpdateComment:H,onDeleteComment:q})]}),O)]})}function N({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>f(e,t),[e,t]),a=(0,s.useRef)(null),l=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,g.C)(l,r),d=(0,c.Te)({count:o.length,getScrollElement:()=>a.current,estimateSize:()=>20,overscan:20});return(0,n.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.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:i[e.index]||(0,b.ZD)(t.content||" ")}})]},e.key)})})})}let C={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"},S={"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 L({name:e,className:t="",size:r=16}){let s,o=S[s=e.toLowerCase()]?S[s]:C[e.split(".").pop()?.toLowerCase()||""]||C.default,a=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===a||"tsx"===a&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===a||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===a||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===a||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function M({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 E=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let m=o===t.path,h=a.has(t.path),x=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):l(t)},[t,l,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick: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:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${m?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)(L,{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)(M,{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 $({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,cwd:l,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:h}=(0,o.Bd)(),x=d??h("gitFileTree.noFiles"),{contextMenu:f,showContextMenu:p,hideContextMenu:g}=(0,m.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(E,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,onContextMenu:p,showChanges:i,renderActions:c},e.path)),f&&(0,n.jsx)(m.ft,{x:f.x,y:f.y,path:f.path,cwd:l,isDirectory:f.isDirectory,onClose:g})]})}function T(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,a=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===s);l||(l={name:s,path:a,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(l)),o||(n=l.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function R(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function P(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var B=r(87918);function F(e){try{let t=JSON.parse(e);return z(t,0)}catch{return e}}let I="#79c0ff",D="#a5d6ff",O="#ff7b72",A="#8b949e",_=(e,t)=>s.createElement("span",{style:{color:e}},t);function W({label:e,labelColor:t,value:r,indent:n}){let[o,a]=s.useState(!1),[l,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-l.x,r=e.clientY-l.y;t*t+r*r>25||(e.stopPropagation(),a(e=>!e))},style:{cursor:"pointer"}};if(c&&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",d,_(t,e),_(A,": "),_(D,n),_("#6e7681",` ${B.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,_(t,e),_(A,": "),z(r,n));return c?s.createElement("span",d,u):u}function z(e,t){let r=" ".repeat(t);if(null===e)return _(O,"null");if(void 0===e)return _(O,"undefined");if("string"==typeof e)return _(D,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return _("#79c0ff",String(e));if("boolean"==typeof e)return _(O,String(e));if(Array.isArray(e))return 0===e.length?_(A,"[]"):s.createElement(s.Fragment,null,_(A,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(W,{label:`[${o}]`,labelColor:I,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,_(A,","),"\n"):"\n")),r,_(A,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?_(A,"{}"):s.createElement(s.Fragment,null,_(A,"{"),"\n",...n.map(([e,o],a)=>s.createElement("span",{key:e},r+" ",s.createElement(W,{label:e,labelColor:I,value:o,indent:t+1}),a<n.length-1?s.createElement(s.Fragment,null,_(A,","),"\n"):"\n")),r,_(A,"}"))}return String(e)}let H=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function q(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return H.has(t)}function U(e){return e.toLowerCase().endsWith(".md")}let V="json-search-highlight-style";function K(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[a,l]=(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(V))return;let e=document.createElement("style");e.id=V,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=a?n:n.toLowerCase(),l=a?s:s.toLowerCase(),i=[],d=0;for(;d<l.length;){let e=l.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,a]),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:a,setCaseSensitive:l,matchCount:i,currentIndex:d,searchInputRef:m,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:y}}function J({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:B.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:B.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:B.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:B.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:B.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:B.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 Q({isOpen:e,onClose:t,commit:r,cwd:a,embedded:l=!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),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),E=K(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&S){e.preventDefault(),E.open();return}if("Escape"===e.key){if(E.isVisible)return void E.close();if(S)return void L(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,S,E]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{m([]),x([]),b(null),j(null),w(!0)}),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let n=T(t);if(x(n),p(new Set(R(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{b(e),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&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,a,i]);let P=(0,s.useCallback)(e=>{r&&(b(e),C(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>C(!1)))},[a,r]),B=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,a,l;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${a}:${l}`:`${e.getFullYear()}-${s}-${o} ${a}:${l}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let D=(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:I}),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)($,{files:h,selectedPath:g?.path||null,expandedPaths:f,onSelect:e=>e.file&&P(e.file),onToggle:B,cwd:a,showChanges:!0,emptyMessage:d("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:N?(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)(k,{oldContent:v.oldContent,newContent:v.newContent,filePath:v.filePath,isNew:v.isNew,isDeleted:v.isDeleted,cwd:a,enableComments:!0,onPreview:!v.isDeleted&&v.filePath.endsWith(".json")?()=>L({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")})})]})]}),O=S&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>L(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:S.filePath}),(0,n.jsx)("button",{onClick:()=>L(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)(J,{search:E}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(S.content)})})]})});return l?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title: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"})})}),D,O]}):(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"})})})]}),D,O]})})}let X={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"}},Y=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:a,onToggle:l,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:m,hasChangedChildren:h}=e,x=m?X[m]:null,f=(0,s.useCallback)(()=>{d.isDirectory?l(d.path):a(d.path)},[d.isDirectory,d.path,a,l]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=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)(L,{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 G({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:a=null,loadingDirs:l,onSelect:i,onToggle:d,cwd:u,shouldScrollToSelected:h=!1,onScrolledToSelected:x,className:f,renderActions:p,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y}){let w=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,m.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let a=[];for(let l of t){if(null!==n&&!n.has(l.path))continue;let t=s?.get(l.path),i=l.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(l.path,s):void 0;a.push({node:l,level:o,gitStatus:t,hasChangedChildren:i}),l.isDirectory&&l.children&&r.has(l.path)&&a.push(...e(l.children,r,n,s,o+1))}return a})(e,r,o,a),[e,r,o,a]),L=(0,c.Te)({count:S.length,getScrollElement:()=>w.current,estimateSize:()=>26,overscan:10}),M=(0,s.useRef)(x);return(M.current=x,(0,s.useEffect)(()=>{if(h&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{L.scrollToIndex(e,{align:"center"}),M.current?.()},150);return()=>clearTimeout(t)}}},[h,t,S,L]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:w,className:f||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.getVirtualItems().map(e=>{let s=S[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)(Y,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:l?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:p})},s.node.path)})}),k&&(0,n.jsx)(m.ft,{x:k.x,y:k.y,path:k.path,cwd:u,isDirectory:k.isDirectory,onClose:C,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y})]})}var Z=r(89662),ee=r(578),et=r(14978),er=r(95766),en=r(94002);function es({content:e,sourceFile:t}){let r,a,l,i,c,{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!0),[f,g]=(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()=>{g(!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,p.oR)(s.existing?d("toast.reviewUpdated"):d("toast.reviewCreated"),"success")}catch{(0,p.oR)(d("toast.reviewCreateFailed"),"error")}finally{g(!1)}},[e,t]),j=(0,s.useCallback)(async()=>{if(u){g(!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,p.oR)(d("toast.sharingClosed"),"success")}catch{(0,p.oR)(d("toast.sharingCloseFailed"),"error")}finally{g(!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:(a=String((r=new Date(u.updatedAt)).getMonth()+1).padStart(2,"0"),l=String(r.getDate()).padStart(2,"0"),i=String(r.getHours()).padStart(2,"0"),c=String(r.getMinutes()).padStart(2,"0"),`${a}-${l} ${i}:${c}`)}),(0,n.jsx)("button",{onClick:w,className:"text-[11px] text-brand hover:underline",children:d("review.view")})]})]})}function eo(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 ea=[er.W];function el({content:e,filePath:t,cwd:r,onClose:a,sourceFile:i}){let c=i||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(()=>{}),v=(0,m.iN)(),w=(0,h.nH)(),{comments:k,addComment:N,updateComment:C,deleteComment:S,refresh:L}=(0,d._)({cwd:r,filePath:t}),[M,E]=(0,s.useState)(!1),[$,T]=(0,s.useState)(null),[R,P]=(0,s.useState)(null),[B,F]=(0,s.useState)(null),I=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>E(!0))},[]),(0,s.useEffect)(()=>{let e=p.current;if(!e)return;let t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,g.current&&(g.current=null,b.current())},o=s=>{t=!1;let o=s.target;if(o.closest?.(".floating-toolbar")||o.closest?.("[data-comment-card]"))return;let a=Math.abs(s.clientX-r)>5||Math.abs(s.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed){g.current=null,b.current();return}let i=l.toString();if(!i.trim()||!a){g.current=null,b.current();return}let c=l.getRangeAt(0);if(!e.contains(c.commonAncestorContainer))return;let d=eo(c.startContainer),u=eo(c.endContainer);if(d&&u){let e=Math.min(d.start,u.start),t=Math.max(d.end,u.end);g.current={x:s.clientX,y:s.clientY,range:{start:e,end:t},selectedText:i},b.current()}},a=()=>{if(t||!g.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(g.current=null,b.current())};return e.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",a),()=>{e.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",a)}},[]);let D=(0,s.useCallback)(()=>{let e=g.current;e&&(T({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),O=(0,s.useCallback)(()=>{let e=g.current;e&&(P({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),A=(0,s.useCallback)(async e=>{$&&(await N($.range.start,$.range.end,e),T(null))},[$,N]),_=(0,s.useCallback)(async e=>{if(R&&w)try{let n=await (0,u.$3)(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,R.range.start-1),a=Math.min(I.length,R.range.end),l=I.slice(o,a).join("\n");s.push({filePath:t,startLine:R.range.start,endLine:R.range.end,codeContent:l});let i=(0,u.Gw)(s,e);w.sendMessage(i),await (0,u.RP)(r),L(),P(null)}catch(e){console.error("Failed to send to AI:",e)}},[R,w,t,r,I,L]),W=(0,s.useMemo)(()=>{if(0===k.length)return[];let e=new Map;for(let t of k){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}))},[k]),[z,H]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===W.length||!p.current)return void queueMicrotask(()=>H([]));let e=setTimeout(()=>{let e=p.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of W){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})}}H(t)},100);return()=>clearTimeout(e)},[W,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(R){P(null),e.stopPropagation();return}if($){T(null),e.stopPropagation();return}if(g.current){g.current=null,b.current(),e.stopPropagation();return}if(B){F(null),e.stopPropagation();return}a()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[R,$,B,a]),(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)(es,{content:e,sourceFile:c}),(0,n.jsx)("button",{onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f("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)(en.l,{content:e,containerRef:p}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:p,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(et.T,{content:e,rehypePlugins:ea})}),z.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(),F({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&&v&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:g,bumpRef:b,container:v,onAddComment:D,onSendToAI:O,isChatLoading:w?.isLoading}),$&&(0,n.jsx)(x.t,{x:$.x,y:$.y,range:$.range,codeContent:$.codeContent,container:v,onSubmit:A,onClose:()=>T(null)}),R&&(0,n.jsx)(x.G,{x:R.x,y:R.y,range:R.range,filePath:t,codeContent:R.codeContent,container:v,onSubmit:_,onClose:()=>P(null),isChatLoading:w?.isLoading}),B&&(0,n.jsx)(y.t,{x:B.x,y:B.y,comment:B.comment,container:v,onClose:()=>F(null),onUpdateComment:C,onDeleteComment:S})]}),v)]})}function ei({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),a=o>=0?e.slice(0,o+1):"",l=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],a="",l=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==l&&a&&(o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-${s}`):(0,n.jsx)("span",{children:a},`${t}-${s}`)),a=""),l=c,a+=e[s]}return a&&o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-end`):(0,n.jsx)("span",{children:a},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[a&&i(a,0,"text-muted-foreground"),i(l,a.length,"text-foreground")]})}function ec({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:l}){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,a=0,l=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),l===i-1&&(a+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(a+=10),i>e.lastIndexOf("/")&&(a+=3),e[i]===t[o]&&(a+=1),l=i,o++);return o<n.length?null:(a-=.1*e.length,{path:e,score:a,matchedIndices:s})}(t,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=>{a(e),l()},[a,l]),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(),l()}},[g,m,v,l]);return(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:l,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref: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)(L,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(ei,{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")]})]})]})})})}var ed=r(22552);function eu(){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}var em=r(61878),eh=r(33210),ex=r(48368),ef=r(91958),ep=r(45916),eg=r(31794),eb=r(69048),ev=r(97567),ej=r(68806),ey=r(52475);function ew({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ex.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(ep.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(eg.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(eb.A,{className:s});case"class":return(0,n.jsx)(ev.A,{className:s});case"interface":return(0,n.jsx)(ej.A,{className:s});default:return(0,n.jsx)(ey.A,{className:s})}}let ek=new Map,eN=new Map;async function eC(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){ek.clear(),eN.clear();return}let t=`${e}::`;for(let e of ek.keys())e.startsWith(t)&&ek.delete(e);for(let e of eN.keys())e.startsWith(t)&&eN.delete(e)}(e);else{let e=ek.get(n);if(e)return e;let t=eN.get(n);if(t)return t}let s=(async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let a=await o.json();return ek.set(n,a),a})().finally(()=>eN.delete(n));return eN.set(n,s),s}var eS=r(72816),eL=r(50538);function eM({entries:e,onSelect:t,onClear:r}){return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eL.A,{className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:0===e.length?"history":`history \xb7 ${e.length}/15`})]}),e.length>0&&(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",title:"Clear history",children:(0,n.jsx)(eh.A,{className:"w-3 h-3"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:"Click an input or output pin to begin tracing."}):e.map((e,r)=>{var s;let o;return(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:bg-secondary/60 transition-colors group flex items-start gap-1.5",title:`${e.qname} \xb7 ${e.filePath}`,children:[(0,n.jsx)(ew,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]},`${e.filePath}::${e.qname}::${r}`)})})]})}function eE(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}function e$(e,t,r){if(!document.contains(e))return null;let n=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!n)return null;let s=n.closest("[data-line]");if(!s||!t.contains(s)||r&&!s.closest(r))return null;let o=s.getAttribute("data-line");if(!o)return null;let a=parseInt(o,10);return Number.isFinite(a)?a:null}var eT=r(96035);function eR({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:a}){let l=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=l.get(n.endLine);e?e.push(n):l.set(n.endLine,[n])}return 0===l.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(l.entries()).map(([e,r])=>{let l=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsxs)("button",{onClick:e=>a(i,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-sm transition-colors",style:{top:`${l+s/2-8}px`},title:1===r.length?i.content:`${r.length} comments — click to view`,children:[(0,n.jsx)(eT.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]},e)})})}function eP({addedLines:e,totalLines:t,blockRanges:r,viewportRange:o,onJumpToLine:a}){let l,i,c=(0,s.useRef)(null),d=(0,s.useMemo)(()=>{if(t<=0||0===e.size)return[];let n=[...r].sort((e,t)=>e.startLine-t.startLine),s=[];for(let t of e){let e=n.find(e=>t>=e.startLine&&t<=e.endLine);e&&s.push({line:t,qname:e.qname})}s.sort((e,t)=>e.line-t.line);let o=[],a=null;for(let e of s)a&&e.line===a.end+1&&e.qname===a.qname?a.end=e.line:(a&&o.push(a),a={start:e.line,end:e.line,qname:e.qname});return a&&o.push(a),o},[e,r,t]);return t<=0||0===r.length?null:(0,n.jsxs)("div",{ref:c,onClick:e=>{let n=c.current;if(!n)return;let s=n.getBoundingClientRect();if(s.height<=0)return;let o=Math.max(1,Math.min(t,Math.round((e.clientY-s.top)/s.height*t))),l=d.find(e=>o>=e.start&&o<=e.end);if(l)return void a(l.qname,o);if(d.length>0){let e=Math.max(2,Math.round(.05*t)),r=null,n=1/0;for(let e of d){let t=o<e.start?e.start-o:o>e.end?o-e.end:0;t<n&&(r=e,n=t)}if(r&&n<=e){let e=o<r.start?r.start:o>r.end?r.end:o;a(r.qname,e);return}}let i=r.find(e=>o>=e.startLine&&o<=e.endLine);if(i)return void a(i.qname,i.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[d.map(e=>{let r=(e.start-1)/t*100,s=(e.end-e.start+1)/t*100;return(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${r}%`,height:`${s}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`)}),o&&o.end>=o.start&&(l=(o.start-1)/t*100,i=(o.end-o.start+1)/t*100,(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${l}%`,height:`${Math.max(1.2,i)}%`}}))]})}function eB(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eF({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:a,onCommentClick:l,addedLines:i}){let{resolvedTheme:c}=(0,eS.D)(),d=(0,s.useMemo)(()=>(0,b.sQ)(e.filePath),[e.filePath]),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void m(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,b.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,b.b8)(t)}</span></div>`}).join("");r||(m(s),x(null))}catch(e){r||x(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==h)&&o(e.qualifiedName)},[u,h,e.qualifiedName,o]),(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-secondary/40 text-xs",children:[(0,n.jsx)(ew,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eD}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),h&&(0,n.jsx)("span",{className:"text-red-11",children:h}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),a&&a.length>0&&l&&(0,n.jsx)(eR,{comments:a,startLine:e.startLine,endLine:e.endLine,lineHeight:eD,bodyTopOffset:eO+eA,onCommentClick:l})]})}function eI({side:e,pin:t,accent:r,onClick:s}){let o,a,l,i,c,d,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="ext",l="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="method",l="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="method (unresolved)",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",a="self",l="text-muted-foreground/70",i=t.external.name,c=null,d="same-file",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",a=e,l="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=eB(t.external.filePath),d="in"===e?"caller":"callee",u=t.external.filePath);let h=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${h} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${l} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:a}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",m,"\xd7"]})]})]})}let eD=18,eO=29,eA=8;function e_(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eW(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function ez(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function eH({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:a,onHighlighted:l,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let m=function(e,t){if(0===e.length)return[];let r=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eO+eA+(o-t.startLine)*eD,s);n[e]=r,s=r+22}return n}(o,e);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:"w-44 flex-shrink-0 flex flex-col gap-1 pt-1",children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(eI,{side:"in",pin:t,accent:eW(t,d),onClick:()=>a(t,e)},e_("in",t)))}),(0,n.jsx)(eF,{symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 flex-shrink-0 relative",children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${m[r]}px`},children:(0,n.jsx)(eI,{side:"out",pin:t,accent:eW(t,d),onClick:()=>a(t,e)})},e_("out",t)))})]})}function eq({cwd:e,onSelect:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(""),[c,d]=(0,s.useState)({files:[],symbols:[]}),[u,m]=(0,s.useState)(0),[h,x]=(0,s.useState)(!1),f=(0,s.useMemo)(()=>[...c.files,...c.symbols],[c]);(0,s.useEffect)(()=>{let t=l.trim();if(!t)return void d({files:[],symbols:[]});x(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await fetch(`/api/projectGraph/search?${r}`);if(n.ok){let e=await n.json();d(e),m(0)}}finally{x(!1)}},120);return()=>clearTimeout(r)},[l,e]);let p=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==f.length){if("ArrowDown"===e.key)e.preventDefault(),m(e=>Math.min(e+1,f.length-1));else if("ArrowUp"===e.key)e.preventDefault(),m(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=f[u];r&&t(r)}}},[f,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-2xl overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(em.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),onKeyDown:p,placeholder:a("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),h&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(eh.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===f.length&&l&&!h&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("blockViewer.search.noResults","No matches")}),(0,n.jsx)(eU,{label:a("blockViewer.search.files","Files"),hits:c.files,startIdx:0,activeIdx:u,onSelect:t,setActive:m}),(0,n.jsx)(eU,{label:a("blockViewer.search.symbols","Symbols"),hits:c.symbols,startIdx:c.files.length,activeIdx:u,onSelect:t,setActive:m})]})]})})}function eU({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:a}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let l=r+t,i=l===s;return(0,n.jsxs)("button",{onMouseEnter:()=>a(l),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.target.kind?(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(ew,{kind:e.target.symbolKind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function eV({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:a,enableComments:l=!1,onContentSearch:i,onFocalChange:c,qnameFilter:m,qnameFilterFile:f,accentQnames:p,accentFile:g,addedLines:b,addedLinesFile:v,headerExtraLeft:w,headerExtraRight:k}){let{t:N}=(0,o.Bd)(),[C,S]=(0,s.useState)(null),L=C??t??null;(0,s.useEffect)(()=>{S(null)},[t]),(0,s.useEffect)(()=>{c?.(L)},[L,c]);let{state:M,refresh:E}=function(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let a=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eC(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?a(e,t,!1):n({state:"idle"})},[e,t,a]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&a(e,t,!0)},[e,t,a])}}(e,L),[$,T]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!L)return void T(null);let t=!1;return T(null),(async()=>{try{let r=new URLSearchParams({cwd:e,path:L}),n=await fetch(`/api/files/text?${r}`);if(!n.ok)return;let s=await n.json();t||T(s.content)}catch(e){console.error("[BlockViewer] failed to load file source for",L,e)}})(),()=>{t=!0}},[e,L]);let[R,P]=(0,s.useState)([]),[B,F]=(0,s.useState)(!1),[I,D]=(0,s.useState)(null),O=(0,s.useRef)(0),A=(0,s.useRef)(0),[_,W]=(0,s.useState)(()=>new Set),z="ready"===M.state?M.data.filePath:null;(0,s.useEffect)(()=>{W(new Set)},[z]);let H=(0,s.useCallback)(e=>{W(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),F(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let q=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;O.current+=1,D({filePath:e,qname:"__imports__",nonce:O.current});return}let r=ez(t),n=ez(e.external);P(e=>eE(eE(e,r),n)),S(n.filePath),O.current+=1,D({filePath:n.filePath,qname:n.qname,nonce:O.current})},[]),U=(0,s.useCallback)(e=>{S(e.filePath),O.current+=1,D({filePath:e.filePath,qname:e.qname,nonce:O.current})},[]),V=(0,s.useCallback)(e=>{F(!1),S(e.target.filePath)},[]),K=(0,s.useCallback)((e,t)=>{L&&(O.current+=1,D({filePath:L,qname:e,line:t,nonce:O.current}))},[L]),[J,Q]=(0,s.useState)(null),[X,Y]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!J)return;let e=null,t=()=>{e=null;let t=J.getBoundingClientRect();if(t.height<=0)return;let r=J.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let a=Number(r),l=Number(o);if(!Number.isFinite(a)||!Number.isFinite(l))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=l-a+1,m=Math.floor(c/i.height*u),h=Math.ceil(d/i.height*u)-1,x=a+Math.max(0,m),f=a+Math.min(u-1,Math.max(0,h));x<n&&(n=x),f>s&&(s=f)}),n===1/0||s===-1/0?Y(null):Y(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),J.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(J);let s=new MutationObserver(r);return s.observe(J,{childList:!0,subtree:!0}),()=>{J.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[J]);let G=l&&!!e&&!!L,Z=(0,h.nH)(),{comments:ee,addComment:et,updateComment:er,deleteComment:en,refresh:es}=(0,d._)({cwd:e,filePath:L??""}),[eo,ea]=(0,s.useState)(null),{toolbar:el,clearToolbar:ei}=function({enabled:e,container:t,bodyScope:r}){let[n,o]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!e||!t)return;let n=!1,s=0,a=0,l=e=>{n=!0,s=e.clientX,a=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o(e=>e?null:e)},i=e=>{n=!1;let l=e.target;if(l?.closest?.(".floating-toolbar"))return;let i=Math.abs(e.clientX-s)>5||Math.abs(e.clientY-a)>5,c=window.getSelection();if(!c||c.isCollapsed||!c.toString().trim()||!i)return void o(e=>e?null:e);let d=c.getRangeAt(0);if(!t.contains(d.commonAncestorContainer))return void o(e=>e?null:e);let u=e$(d.startContainer,t,r),m=e$(d.endContainer,t,r);if(null==u||null==m)return void o(e=>e?null:e);let h=Math.min(u,m),x=Math.max(u,m);o({x:e.clientX,y:e.clientY,range:{start:h,end:x},selectedText:c.toString()})},c=()=>{if(n)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o(e=>e?null:e)};return t.addEventListener("mousedown",l),document.addEventListener("mouseup",i),document.addEventListener("selectionchange",c),()=>{t.removeEventListener("mousedown",l),document.removeEventListener("mouseup",i),document.removeEventListener("selectionchange",c)}},[e,t,r]),{toolbar:n,clearToolbar:()=>o(null)}}({enabled:G,container:eo}),[ec,ed]=(0,s.useState)(null),[eu,em]=(0,s.useState)(null),[eh,ex]=(0,s.useState)(null),ef=(0,s.useCallback)(()=>{el&&(ed({x:el.x,y:el.y,range:el.range,codeContent:el.selectedText}),ei())},[el,ei]),ep=(0,s.useCallback)(()=>{el&&(em({x:el.x,y:el.y,range:el.range,codeContent:el.selectedText}),ei())},[el,ei]),eg=(0,s.useCallback)(()=>{if(!el||!i)return;let e=el.selectedText.trim();ei(),e&&i(e)},[el,i,ei]),eb=(0,s.useCallback)(async e=>{ec&&(await et(ec.range.start,ec.range.end,e,ec.codeContent),ed(null))},[ec,et]),ev=(0,s.useCallback)(async t=>{if(eu&&Z&&e&&L)try{let r=(await (0,u.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:L,startLine:eu.range.start,endLine:eu.range.end,codeContent:eu.codeContent});let n=(0,u.Gw)(r,t);Z.sendMessage(n),await (0,u.RP)(e),es(),em(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[eu,Z,e,L,es]),ej=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ex({comment:e,x:t.clientX,y:t.clientY}),ei(),ed(null),em(null)},[ei]);if((0,s.useEffect)(()=>{let e;if(!I||A.current>=I.nonce||"ready"!==M.state||!$||M.data.filePath!==I.filePath)return;if(f&&f===M.data.filePath&&m){let t=0;for(let e of M.data.functions)m.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,M.data.functions.length);if(_.size<e)return;A.current=I.nonce;let t=null,r=requestAnimationFrame(()=>{let e=I.qname.indexOf(">"),r=e>=0?I.qname.slice(0,e):I.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof I.line){let e=n.querySelector(`[data-line="${I.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"smooth",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"smooth",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[I,M,$,_,m,f]),!L)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:null,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:N("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:N("blockViewer.empty.hint","or press ⌘K to search.")})]}),B&&(0,n.jsx)(eq,{cwd:e,onSelect:V,onClose:()=>F(!1)})]});if("idle"===M.state||"loading"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:N("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),B&&(0,n.jsx)(eq,{cwd:e,onSelect:V,onClose:()=>F(!1)})]});if("error"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:M.message}),(0,n.jsx)("button",{onClick:E,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:N("blockViewer.retry","Retry")})]})]});let ey=M.data,ew=ey.functions;if(0===ew.length&&$){let e=Math.max(1,$.split("\n").length);ew=[{filePath:ey.filePath,qualifiedName:"__file__",name:eB(ey.filePath),kind:"unknown",startLine:1,endLine:e}]}let ek=f&&f===ey.filePath,eN=g&&g===ey.filePath,eS=v&&v===ey.filePath;ek&&m&&(ew=ew.filter(e=>m.has(e.qualifiedName)));let eL=eN?p:void 0,eT=eS?b:void 0,eR=eK(ey.upstreamCalls),eF=eK(ey.downstreamCalls),eI=new Map(ew.map(e=>[e.qualifiedName,e])),eD=new Map,eO=new Map;for(let e of ey.intraCalls){let t=eI.get(e.to),r=eI.get(e.from);if(t){let r=eD.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eD.set(e.from,[n])}if(r){let t=eO.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):eO.set(e.to,[n])}}let eA=new Map;for(let e of ey.externalCalls??[]){let t=eA.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eA.set(e.focalQname,[r])}let e_=new Map;for(let e of ey.methodCalls??[]){let t=e_.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):e_.set(e.focalQname,[r])}let eW=r.has(ey.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:ey.fileCount,functionCount:ey.functions.length,upstreamCount:ey.upstreamCalls.length,downstreamCount:ey.downstreamCalls.length,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{ref:ea,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)("div",{ref:Q,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:ew.map(e=>{let t,r,s,o,a,l;return(0,n.jsx)(eH,{symbol:e,fileSource:$,hasChange:eW,upstream:(t=eR.get(e.qualifiedName),r=eO.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eF.get(e.qualifiedName),o=eD.get(e.qualifiedName),a=e_.get(e.qualifiedName),l=eA.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...a??[],...l??[]]),onPinClick:q,onHighlighted:H,comments:G?ee:void 0,onCommentClick:G?ej:void 0,accentQnames:eL,addedLines:eT},e.qualifiedName)})})}),G&&el&&eo&&(0,n.jsx)(j.w,{x:el.x,y:el.y,visible:!0,container:eo,onAddComment:ef,onSendToAI:ep,onSearch:i?eg:void 0,isChatLoading:Z?.isLoading}),G&&ec&&(0,n.jsx)(x.t,{x:ec.x,y:ec.y,range:ec.range,codeContent:ec.codeContent,container:eo,onSubmit:eb,onClose:()=>ed(null)}),G&&eu&&L&&(0,n.jsx)(x.G,{x:eu.x,y:eu.y,range:eu.range,filePath:L,codeContent:eu.codeContent,container:eo,onSubmit:ev,onClose:()=>em(null),isChatLoading:Z?.isLoading}),G&&eh&&(0,n.jsx)(y.t,{x:eh.x,y:eh.y,comment:eh.comment,container:eo,onClose:()=>ex(null),onUpdateComment:er,onDeleteComment:en}),eT&&eT.size>0&&$&&ew.length>0&&(0,n.jsx)(eP,{addedLines:eT,totalLines:Math.max(1,$.split("\n").length),blockRanges:ew.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:X,onJumpToLine:K}),(0,n.jsx)(eM,{entries:R,onSelect:U,onClear:()=>P([])}),B&&(0,n.jsx)(eq,{cwd:e,onSelect:V,onClose:()=>F(!1)})]})]})}function eK(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function eJ({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:a,onSwitchToCode:l,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:m}){let{t:h}=(0,o.Bd)(),x={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:a??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof a&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",a," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(x)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:m(x)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":h("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(em.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":h("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ef.A,{className:"w-3 h-3"})}),l&&(0,n.jsx)("button",{onClick:l,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function eQ(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function eX(e){return e.replace(/\s+/g," ").trim()}function eY(e,t){return e?`${e}>${t}`:t}function eG(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function eZ(e,t,r,n,s=[],o){return{qualifiedName:eY(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:eQ(eX(e.text)),children:s,params:o}}function e0(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}function e1(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";default:return null}}var e2=r(14066);let e5="/tree-sitter",e4=null,e3=new Map;async function e6(e){let t,r=await (!(t=e3.get(e))&&(t=(async()=>(await (!e4&&(e4=e2.iX.init({locateFile:e=>`${e5}/${e}`})),e4),e2.TM.load(`${e5}/tree-sitter-${e}.wasm`)))(),e3.set(e,t)),t),n=new e2.iX;return n.setLanguage(r),n}function e8(e){return!e.qualifiedName.startsWith("__code_")&&"__file__"!==e.qualifiedName}async function e9(e,t){if(!e)return[];let r=e1(t);if(!r)return null;let n=(await e6(r)).parse(e);if(!n)return null;try{return(function(e){let t=[],r=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:eQ(eX(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[eZ(t,eG(t),"function",r,[],e0(t))];case"class_declaration":case"abstract_class_declaration":{let e=eG(t),n=eY(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(eZ(s,eG(s),"method",t,[],e0(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(eZ(s,eG(s),"method",t,[],e0(e)))}}}return r}(t.childForFieldName("body"),n);return[eZ(t,e,"class",r,s)]}case"interface_declaration":return[eZ(t,eG(t),"interface",r)];case"type_alias_declaration":return[eZ(t,eG(t),"type",r)];case"enum_declaration":return[eZ(t,eG(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),a=s.childForFieldName("value");if(!o)continue;let l=o.text,i=a&&("arrow_function"===a.type||"function_expression"===a.type),c=i&&a?e0(a):void 0;if(r.push(eZ(e,l,i?"function":"const",t,[],c)),a&&"object"===a.type&&!i){let e=t?`${t}>${l}`:l;for(let t=0;t<a.namedChildCount;t++){let n=a.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(eZ(n,t.text,"method",e,[],e0(s)))}else if("method_definition"===n.type){let t=eG(n);t&&r.push(eZ(n,t,"method",e,[],e0(n)))}}}}}return r}(t,r);case"class_definition":{let e=eG(t),n=eY(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(eZ(o,eG(o),"method",r,[],e0(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...eZ(t,eG(t),"method",r,[],e0(t)),startLine:o.startPosition.row+1,contentHash:eQ(eX(o.text))});else if(t?.type==="class_definition"){let s=eG(t),a=eY(r,s),l=e(t.childForFieldName("body"),a);n.push({...eZ(t,s,"class",r,l),startLine:o.startPosition.row+1,contentHash:eQ(eX(o.text))})}}else if("class_definition"===o.type){let t=eG(o),s=eY(r,t),a=e(o.childForFieldName("body"),s);n.push(eZ(o,t,"class",r,a))}}}return n}(t.childForFieldName("body"),n);return[eZ(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:eQ(eX(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:eY(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:eQ(eX(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,a=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&a.push(t)}}if(0===a.length||!o)return[];let l=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=l?`${l} ${o}`:o;return a.map((e,r)=>eZ(e,a.length>1?`${i} #${r+1}`:i,"function",t,[],e0(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],a=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:eQ(eX(s)),children:[]})},l=-1;for(let e=1;e<=n;e++)s[e]?l>=0&&(a(l,e-1),l=-1):l<0&&(l=e);return l>=0&&a(l,n),o}(e,t)),t})(n.rootNode).filter(e8)}finally{n.delete()}}async function e7(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of f(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!e1(r))return{addedLines:o};let[a,l]=await Promise.all([e9(n?"":e,r),e9(s?"":t,r)]),i=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}(a??[],l??[]),c=new Set;for(let e of i)"deleted"!==e.changeKind&&c.add(e.qname);return{changedQnames:c,addedLines:o}}function te({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:a=!1,isDeleted:l=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:m,headerExtraRight:h}){let[x,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tt(x,t,r,o,a,l,i,c,e);if(n||!s)return;let d=await e7(s.oldContent,s.newContent,x,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[x,t,r,o,a,l,i,c,e]),(0,n.jsx)(eV,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:x,accentQnames:p?.changedQnames,accentFile:x,addedLines:p?.addedLines,addedLinesFile:x,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:m,headerExtraRight:h})}async function tt(e,t,r,n,s,o,a,l,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!a.has(e))return null;let c=l?.get(e);if(!c)return null;let d=new URLSearchParams({cwd:i,file:e,type:c}),u=await fetch(`/api/git/diff?${d}`);if(!u.ok)return null;let m=await u.json();return{oldContent:m.oldContent,newContent:m.newContent,isNew:m.isNew??!1,isDeleted:m.isDeleted??!1}}function tr(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:a}=e,l="absPath"in e&&"string"==typeof e.absPath,i=l?void 0:e.cwd,c=l?void 0:e.path,d=l?e.absPath:void 0,[u,m]=(0,s.useState)({kind:"loading"}),h=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++h.current;return m({kind:"loading"}),(async()=>{if(l){if(e!==h.current)return;m({kind:"ready",etag:null,size:0});return}try{let t=`/api/files/stat?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}`,r=await fetch(t,{cache:"no-store"});if(e!==h.current)return;if(!r.ok)return void m({kind:"error",message:`stat failed (${r.status})`});let n=await r.json();if(e!==h.current)return;if(!n.exists)return void m({kind:"missing"});if("too-large"===n.category)return void m({kind:"too-large",size:n.size??0});if("image"!==n.category)return void m({kind:"error",message:`Not an image (${n.category})`});let s=n.etag||`t-${n.mtimeMs??Date.now()}`;m({kind:"ready",etag:s,size:n.size??0})}catch(t){if(e!==h.current)return;m({kind:"error",message:t instanceof Error?t.message:"Unknown error"})}})(),()=>{h.current++}},[l,i,c,d,t]),"loading"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(u.size/1024/1024)," MB)"]})});if("error"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:u.message})});let x=l?`/api/file?path=${encodeURIComponent(d)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}&v=${encodeURIComponent(u.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:x,alt:a??(c||d),className:o})})}function tn({cwd:e,selected:t,diff:r,showMarkdownPreview:a,setShowMarkdownPreview:l,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:m,setJsonPreview:h,jsonPreviewSearch:x,jsonPreviewPreRef:f}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)("file"),j=t.file.path,y=(0,ee.u)(j);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[y||"block"!==b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:j}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${j}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("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(),u(j)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("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"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?g("fileBrowser.staged"):g("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!y&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","block"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-xs transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g(`common.${e}`)},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:y?(0,n.jsx)(tr,{cwd:e,path:j,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:j}):(0,n.jsx)(k,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,onPreview:!r.isDeleted&&U(j)?()=>l(!0):!r.isDeleted&&j.endsWith(".json")?()=>h({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:j.endsWith(".json")?g("common.readable"):g("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(te,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?g("fileBrowser.staged"):g("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","block"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g(`common.${e}`)},e))})}),a&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>l(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(el,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>l(!1)})})}),m&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>h(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:m.filePath}),(0,n.jsx)("button",{onClick:()=>h(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)(J,{search:x}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(m.content)})})]})})]})}function ts({branches:e,selectedBranch:t,onSelect:r,isLoading:a,pinnedBranches:l=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(""),h=(0,s.useRef)(null),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{h.current&&!h.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&x.current&&x.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=l.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],y=e=>{r(e),d(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:h,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:a,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${c?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:x,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground placeholder-slate-9"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>y(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}function to(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 ta(e){return e.replace(/^\([^)]+\)\s*/,"")}let tl=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:a,container:l,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=l.getBoundingClientRect(),p=r-f.left,g=a-f.top,b=(0,s.useMemo)(()=>ta(e),[e]),v=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,a=0,l=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=l.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},a++));let l=t[0];/^["']/.test(l)?s.push((0,n.jsx)("span",{className:"text-green-400",children:l},a++)):/^\d+$/.test(l)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:l},a++)):r.test(l)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:l},a++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:l},a++)),o=t.index+l.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},a++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!x.current)return;let e=x.current,t=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=a-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,a,l]),(0,n.jsxs)("div",{ref: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=ta(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")})]})]})]})});function ti({references:e,loading:t,onSelect:r,onClose:a}){let{t:l}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)();if(t!==a.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let a=(0,b.sQ)(r.file);if("text"!==a)try{let e=n.codeToTokens(r.lineText,{lang:a,theme:s}),l=(0,b.b8)(e.tokens[0]||[]);l&&o.set(t,l)}catch{}}t===a.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[l("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(eh.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.notFound")}):c.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tc({results:e,loading:t,totalMatches:r,onSelect:a,onClose:l}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)(),o=new Map;for(let t of e){let e=(0,b.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let a=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),l=(0,b.b8)(t.tokens[0]||[]);l&&o.set(a,l)}catch{}}}t===a.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:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(eh.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:()=>a(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}let td=["agent","explorer","console"],tu={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},tm=(0,s.createContext)(null);function th(){let e=(0,s.useContext)(tm);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function tx({activeView:e,onViewChange:t,children:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(!1),l=(0,s.useRef)(0),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(!1),m=td.indexOf(e),h=td.length-1;(0,s.useEffect)(()=>{l.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(),a.current&&(a.current=!1);let n=window.innerWidth,s=l.current-6*e.deltaX;!(m>0)&&s>0&&(s=0),!(m<h)&&s<0&&(s=0),l.current=s=Math.max(-n,Math.min(n,s)),c(s),u(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{let e=l.current,r=.12*n;u(!1),a.current=!0;let s=m;e<-r&&m<h?s=m+1:e>r&&m>0&&(s=m-1),l.current=0,c(0),s!==m&&t(td[s]),setTimeout(()=>{a.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)(tm.Provider,{value:p,children:r})}function tf({children:e}){let t,r,{activeView:o,dragOffset:a,isDragging:l}=th(),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=td.indexOf(o),u=td.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:l?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*td.length}%`,transform:(t=a/u*100,r=-(100/u*d)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function tp(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:o}=th(),a=(0,s.useRef)(null),l=(0,s.useRef)([]),[i,c]=(0,s.useState)({left:0,width:0}),d=td.indexOf(e),u=()=>{if(!a.current||0===l.current.length)return{left:0,width:0};let e=a.current.getBoundingClientRect(),t=l.current.filter(Boolean);if(t.length!==td.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(td.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(td.length-1,d-m)));return(0,n.jsxs)("div",{ref:a,className:"relative flex gap-4",children:[td.map((e,r)=>(0,n.jsx)("button",{ref:e=>{l.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:tu[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 tg({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:c,searchQueryTrigger:d}){var u;let h,x,f,g,b,v,j,y,w,{t:N}=(0,o.Bd)(),{activeView:C}=th(),[S,L]=(0,s.useState)(r),[M,E]=(0,s.useState)("code"),I=(0,s.useRef)(null),D=(0,s.useRef)(!1),[O,A]=(0,s.useState)(null),[_,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[q,V]=(0,s.useState)(null),X=(0,i.F2)(),Y=(0,s.useRef)(1),et=(0,s.useRef)(null),[er,en]=(0,s.useState)(null),es=(0,s.useRef)(null),[eo,ea]=(0,s.useState)({isDirty:!1,isSaving:!1}),[ei,em]=(0,s.useState)(!1),[eh,ex]=(0,s.useState)(!1),[ef,ep]=(0,s.useState)(null),eg=(0,s.useRef)(null),eb=K(eg),ev=(0,s.useRef)(null),ej=K(ev),ey=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),ew=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),a=(0,s.useRef)(0),l=(0,s.useRef)(!1),i=(0,s.useRef)(null),c=(0,s.useRef)({x:0,y:0}),d=(0,s.useCallback)(e=>{i.current=e},[]);(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 u=(0,s.useRef)(!1),m=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,m.current&&(i.current?.removeEventListener("mouseleave",m.current),m.current=null)},[]),x=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,l.current=!0,e.style.pointerEvents="auto";let t=()=>{l.current=!1,h(),a.current++,r(null)};m.current=t,e.addEventListener("mouseleave",t)},[h]),f=(0,s.useCallback)((t,s,l,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let c=++a.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:l})}),o=await n.json();if(c!==a.current)return;o.hover&&o.hover.displayString&&r({...o.hover,x:i.x,y:i.y,filePath:t,line:s,column:l})}catch{}},300)},[e]),p=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),a.current++,o.current=setTimeout(function(){if(l.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 x()}r(null)},150)},[x]),g=(0,s.useCallback)(()=>{l.current=!0,o.current&&clearTimeout(o.current)},[]),b=(0,s.useCallback)(()=>{l.current=!1,a.current++,r(null)},[]),v=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),l.current=!1,h(),a.current++,r(null)},[h]);return(0,s.useEffect)(()=>{t||h()},[t,h]),{hoverInfo:t,onTokenMouseEnter:f,onTokenMouseLeave:p,onCardMouseEnter:g,onCardMouseLeave:b,clearHover:v,setTooltipEl:d}}(t),ek=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1);return{references:t,loading:n,visible:a,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),l(!0);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})}),a=await o.json();r(a.references||[])}catch(e){console.error("[useLSP] references error:",e),r([])}finally{o(!1)}},[e]),closeReferences:(0,s.useCallback)(()=>{l(!1),r([])},[])}}(t),eN=(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=[]},[]),g=(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:g,goForward:b,canGoBack:(0,s.useCallback)(()=>h.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),eC=eu(),eS=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[a,l]=(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),[M,E]=(0,s.useState)(null),$=(0,s.useRef)(null),[T,R]=(0,s.useState)(!1),[P,B]=(0,s.useState)(null),[F,I]=(0,s.useState)("center"),[D,O]=(0,s.useState)(null),[A,_]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[H,q]=(0,s.useState)([]),[U,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(null),[Q,X]=(0,s.useState)(null),[Y,G]=(0,s.useState)(!1),[Z,et]=(0,s.useState)(!1),er=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),en=(0,s.useMemo)(()=>(0,ee.v3)(er),[er]),es=(0,s.useMemo)(()=>new Set((0,ee.tW)(en)),[en]),eo=(0,s.useMemo)(()=>b?n?(0,ee.KH)(n,b,j):(0,ee.q3)(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!eo||0===eo.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of eo)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&eo.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[eo,t,n]);let ea=p??x,el=(0,s.useRef)(null),ei=(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]),ec=(0,s.useCallback)(async()=>{C(!0),E(null);try{let t=await fetch(`/api/files/init?cwd=${encodeURIComponent(e)}`),n=await t.json();n.error?E(n.error):(r(n.files||[]),n.expandedPaths&&Array.isArray(n.expandedPaths)&&f(new Set(n.expandedPaths)))}catch(e){console.error("Error loading files:",e),E("Failed to load files")}finally{C(!1)}},[e]),ed=(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]),eu=(0,s.useCallback)(async t=>{l(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=(0,ee.MB)(r,t);return n&&(n.children=s.children),r})}catch(e){console.error("Error loading directory:",e)}finally{l(e=>{let r=new Set(e);return r.delete(t),r})}},[e]),em=(0,s.useRef)(a);em.current=a,(0,s.useEffect)(()=>{for(let e of p??x){let r=(0,ee.MB)(t,e);r&&r.isDirectory&&!r.children&&!em.current.has(e)&&eu(e)}},[t,x,p,eu]);let eh=(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]),ex=(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]),ef=(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]),ep=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),eg=(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):q(n.blame||[])}catch(e){console.error("Error loading blame:",e),J("Failed to load blame info")}finally{V(!1)}}},[e,d]),eb=(0,s.useCallback)(async t=>{L(!0),h(null),z(!1),q([]),J(null),X(null);try{let r=await fetch(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),n=await r.json();if(!r.ok)return void h({type:"error",message:n?.error||"Failed to stat file"});if(!n.exists)return void h({type:"error",message:"File not found"});if("dir"===n.kind)return void h({type:"error",message:"Path is a directory"});switch(n.category){case"image":h({type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}});break;case"binary":h({type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break;case"too-large":h({type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs});break;default:{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"});if(409===r.status){let e=await r.json().catch(()=>({}));h({type:"binary",message:e?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break}if(!r.ok){let e=await r.json().catch(()=>({}));h({type:"error",message:e?.error||"Failed to load file"});break}let s=await r.json();h({type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}})}}ex(t),eg(t)}catch(e){console.error("Error loading file content:",e),h({type:"error",message:"Failed to load file"})}finally{L(!1)}},[e,ex,eg]),ev=(0,s.useCallback)(()=>{W?z(!1):(z(!0),0===H.length&&eg())},[W,H.length,eg]),ej=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),B(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(B(t.scrollLine),I("start"),O(t.cursorLine??null),_(t.cursorCol??null)):(I("center"),O(null),_(null))}else I("center"),O(null),_(null);eb(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&&ei(r),n?r:t})}},[eb,ei,i]),ey=(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),ei(r),r}),r){let r=(0,ee.MB)(t,e);r&&r.isDirectory&&!r.children&&eu(e)}}},[p,ei,x,t,eu]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:a,expandedPaths:x,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:ea,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:y,matchedPaths:eo,creatingItem:w,setCreatingItem:k,isLoadingFiles:N,fileError:M,searchInputRef:$,shouldScrollToSelected:T,setShouldScrollToSelected:R,targetLineNumber:P,setTargetLineNumber:B,targetScrollAlign:F,setTargetScrollAlign:I,initialCursorLine:D,initialCursorCol:A,setInitialCursorLine:O,setInitialCursorCol:_,selectedPath:d,setSelectedPath:u,fileContent:m,setFileContent:h,isLoadingContent:S,recentFiles:i,recentFilePaths:er,setRecentFiles:c,recentFilesTree:en,recentTreeDirPaths:es,showBlame:W,setShowBlame:z,blameLines:H,isLoadingBlame:U,blameError:K,blameSelectedCommit:Q,setBlameSelectedCommit:X,showMarkdownPreview:Y,setShowMarkdownPreview:G,showEditor:Z,setShowEditor:et,saveExpandedPaths:ei,loadFiles:ec,loadFileIndex:ed,loadDirectory:eu,loadRecentFiles:eh,addToRecentFiles:ex,updateRecentFilePosition:ef,getRecentFilePosition:ep,loadFileContent:eb,loadBlame:eg,handleToggleBlame:ev,handleSelectFile:ej,handleToggle:ey}}({cwd:t});u=eS.selectedPath,v=(0,s.useRef)(null),(0,s.useEffect)(()=>{!u||u===v.current||to(u)&&(v.current=u,fetch("/api/lsp/warmup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,filePath:u})}).catch(()=>{}))},[t,u]);let eL=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(new Set),[h,x]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){a([]),p(null);return}if(n.length<2)return void d(B.A.t("fileBrowser.searchMinChars"));i(!0),d(null);try{let n=new URLSearchParams({cwd:e,q:r,caseSensitive:String(h.caseSensitive),wholeWord:String(h.wholeWord),regex:String(h.regex),fileType:h.fileType}),s=await fetch(`/api/files/search?${n}`),o=await s.json();if(o.error)throw Error(o.error);a(o.results),p({totalFiles:o.totalFiles,totalMatches:o.totalMatches,truncated:o.truncated});let l=new Set(o.results.map(e=>e.path));m(l),o.results.length>0&&t?.()}catch(e){d(e instanceof Error?e.message:"Search failed"),a([])}finally{i(!1)}},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:l,searchError:c,searchExpandedPaths:u,searchOptions:h,setSearchOptions:x,searchStats:f,contentSearchInputRef:g,performContentSearch:b,handleSearchToggle:(0,s.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>em(!0)}),eM=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!1),[f,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)([]),w=(0,s.useMemo)(()=>{let e=new Set([...R(b),...R(j)]);for(let t of f)e.delete(t);return e},[b,j,f]),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{a(!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=T(s.staged),a=T(s.unstaged);v(o),y(a)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{a(!1)}},[e]),M=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),E=(0,s.useCallback)((e,r)=>{d({file:e,type:r}),t(e.path)},[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,p.oR)(B.A.t("toast.staged"),"success")}catch(e){console.error("Error staging file:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,L]),P=(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,p.oR)(B.A.t("toast.unstaged"),"success")}catch(e){console.error("Error unstaging file:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,L]),F=(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,p.oR)(B.A.t("toast.stagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error staging files:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,L]),I=(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,p.oR)(B.A.t("toast.unstagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error unstaging files:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,L]),D=(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,p.oR)(B.A.t("toast.discardedNFiles",{count:t.length}),"success")}catch(e){console.error("Error discarding files:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,L]),O=(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,p.oR)(B.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error staging all files:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,r,L]),A=(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,p.oR)(B.A.t("toast.unstagedNFiles",{count:r.staged.length}),"success")}catch(e){console.error("Error unstaging all files:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,r,L]),_=(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,p.oR)(r?B.A.t("toast.deletedFile"):B.A.t("toast.discardedChanges"),"success")}catch(e){console.error("Error discarding file:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,L]),W=(0,s.useCallback)(async()=>{if(r?.unstaged.length&&await (0,p.lJ)(B.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,p.oR)(B.A.t("toast.discardedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error discarding all:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,r,L]);return(0,s.useEffect)(()=>{c?(async()=>{x(!0);try{let t=new URLSearchParams({file:c.file.path,type:c.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();m(n)}catch(e){console.error("Error fetching diff:",e)}finally{x(!1)}})():m(null)},[c,e,C]),{status:r,setStatus:n,statusLoading:o,statusError:l,statusSelectedFile:c,statusDiff:u,statusDiffLoading:h,statusExpandedPaths:w,stagedTree:b,setStagedTree:v,unstagedTree:j,setUnstagedTree:y,showStatusDiffPreview:k,setShowStatusDiffPreview:N,fetchStatus:L,handleStatusToggle:M,handleStatusFileSelect:E,handleStage:$,handleUnstage:P,handleStageFiles:F,handleUnstageFiles:I,handleDiscardFiles:D,handleStageAll:O,handleUnstageAll:A,handleDiscardFile:_,handleDiscardAll:W,refreshDiff:(0,s.useCallback)(()=>S(e=>e+1),[])}}({cwd:t,addToRecentFiles:eS.addToRecentFiles}),eE=(0,s.useMemo)(()=>{let e=new Set;if(eM.status){for(let t of eM.status.staged)e.add(t.path);for(let t of eM.status.unstaged)e.add(t.path)}return e},[eM.status]),e$=(0,s.useMemo)(()=>{let e=new Map;if(eM.status){for(let t of eM.status.staged)e.set(t.path,"staged");for(let t of eM.status.unstaged)e.set(t.path,"unstaged")}return e},[eM.status]),eT=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(null),[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)(!1),[L,M]=(0,s.useState)(!0),[E,$]=(0,s.useState)(!1),[P,F]=(0,s.useState)(!1),[I,D]=(0,s.useState)(null),O=(0,s.useRef)(null),[A,_]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[H,q]=(0,s.useState)(""),[U,V]=(0,s.useState)(""),[K,J]=(0,s.useState)([]),[Q,X]=(0,s.useState)([]),[Y,G]=(0,s.useState)(new Set),[Z,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),ei=(0,s.useCallback)(()=>{w(!0),D(null),fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{e.error?(D("Failed to get branches"===e.error?B.A.t("git.notGitRepo"):e.error),n(null)):e.local&&e.current?(n(e),a(e.current),e.upstream&&q(e.upstream)):(D(B.A.t("git.cannotGetBranches")),n(null))}).catch(e=>{console.error(e),D(B.A.t("git.getBranchesFailed")),n(null)}).finally(()=>w(!1))},[e]),ec=(0,s.useCallback)(t=>{N(!0),d(null),m([]),x([]),b(null),j(null),M(!0),fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${ee.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];i(t),M(t.length>=ee.B_)}).catch(console.error).finally(()=>N(!1))},[e]),ed=(0,s.useCallback)(()=>{if(C||!L||!o)return;S(!0);let t=l.length;fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(o)}&limit=${ee.B_}&offset=${t}`).then(e=>e.json()).then(e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),M(t.length>=ee.B_)}).catch(console.error).finally(()=>S(!1))},[e,o,l.length,C,L]),eu=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ed()},[ed]),em=(0,s.useCallback)(t=>{d(t),b(null),j(null),$(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${t.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let r=T(t);x(r),p(new Set(R(r)))}).catch(console.error).finally(()=>$(!1))},[e]),eh=(0,s.useCallback)(r=>{c&&(b(r),t(r.path),F(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${c.hash}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>F(!1)))},[e,c,t]),ex=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ef=(0,s.useCallback)(t=>{eo(!0),et(null),en(null),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{let t=e.files||[];J(t);let r=T(t);X(r),G(new Set(R(r)))}).catch(console.error).finally(()=>eo(!1))},[e]),ep=(0,s.useCallback)(r=>{et(r),t(r.path),el(!0),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(U)}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>en(e)).catch(console.error).finally(()=>el(!1))},[e,U,t]),eg=(0,s.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eb=(0,s.useCallback)(e=>{if(z(e),e){let e="origin/main";V(e),ef(e)}else J([]),X([]),et(null),en(null),V("")},[H,ef]);return{branches:r,selectedBranch:o,setSelectedBranch:a,commits:l,setCommits:i,selectedCommit:c,setSelectedCommit:d,historyFiles:u,historyFileTree:h,historyExpandedPaths:f,historySelectedFile:g,historyFileDiff:v,isLoadingBranches:y,isLoadingCommits:k,isLoadingMore:C,hasMoreCommits:L,setHasMoreCommits:M,isLoadingHistoryFiles:E,isLoadingHistoryDiff:P,historyError:I,commitListRef:O,tooltipPos:A,loadBranches:ei,loadCommits:ec,loadMoreCommits:ed,handleCommitListScroll:eu,handleSelectCommit:em,handleSelectHistoryFile:eh,handleHistoryToggle:ex,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{_({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{_(null)},[]),compareMode:W,toggleCompareMode:eb,compareBaseBranch:U,setCompareBaseBranch:V,upstreamBranch:H,compareFiles:K,compareFileTree:Q,compareExpandedPaths:Y,compareSelectedFile:Z,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:ea,handleSelectCompareFile:ep,handleCompareToggle:eg,loadCompareFiles:ef}}({cwd:t,addToRecentFiles:eS.addToRecentFiles}),eR=(0,s.useCallback)(e=>{eS.setFileContent(t=>t?.type==="text"?{...t,content:e}:t)},[eS]),eP=(0,s.useCallback)(e=>{eS.setShowEditor(!0)},[eS]),eB=(0,s.useCallback)(async()=>{if(eS.fileContent&&"text"===eS.fileContent.type&&eS.fileContent.content)try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:eS.selectedPath,content:eS.fileContent.content})});if(!e.ok)throw Error("Failed to save file");let r=await e.json();r.mtime&&eS.setFileContent(e=>e?.type==="text"?{...e,mtime:r.mtime}:e),(0,p.oR)(N("toast.savedSuccess"),"success")}catch{(0,p.oR)(N("toast.saveFailed"),"error")}},[t,eS]),eF=(0,s.useCallback)(()=>{if(!eS.selectedPath)return;let e=Y.current,t=et.current;e>0&&eS.updateRecentFilePosition(eS.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[eS]),eI=(0,s.useCallback)((e,t)=>{e!==eS.selectedPath&&eF(),eS.handleSelectFile(e,t)},[eS,eF]),eD=(0,s.useMemo)(()=>{let e=eL.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,ee.v3)(r),s=new Set((0,ee.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[eL.contentSearchResults]),[eO,eA]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{eA(eD.expandDirs)},[eD.expandDirs]);let e_=(0,s.useCallback)(e=>{eA(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eW=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eD.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eD.matchMap]),ez=ei&&eL.contentSearchResults.length>0,eH=!!eS.selectedPath&&null!==to(eS.selectedPath),eq=(0,s.useCallback)(async(e,r)=>{if(!eS.selectedPath||!eH)return;let n=await ey.goToDefinition(eS.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",a=s.file.startsWith(o)?s.file.slice(o.length):s.file;eN.push({filePath:eS.selectedPath,lineNumber:Y.current}),a===eS.selectedPath?eS.setTargetLineNumber(s.line):eI(a,s.line)},[eS,t,eH,ey,eN]),eU=(0,s.useCallback)((e,t,r)=>{eS.selectedPath&&eH&&ew.onTokenMouseEnter(eS.selectedPath,e,t,r)},[eS.selectedPath,eH,ew]),eK=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;eS.selectedPath&&eN.push({filePath:eS.selectedPath,lineNumber:Y.current}),n===eS.selectedPath?eS.setTargetLineNumber(e.line):eI(n,e.line)},[eS,t,eN]),eJ=(0,s.useMemo)(()=>{if(!eM.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 eM.status.staged)e.set(r.path,t(r.status));for(let r of eM.status.unstaged)e.set(r.path,t(r.status));return e},[eM.status]);(0,s.useEffect)(()=>{A(I.current)},[]),(0,s.useEffect)(()=>{let e=I.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?V({text:r,x:e.clientX,y:e.clientY}):V(null)},n=e=>{V(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)||V(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)(()=>{L(r)},[r,a]),(0,s.useEffect)(()=>{c&&(L("search"),eL.setContentSearchQuery(c),eL.performContentSearch(c))},[d]);let eQ=(0,s.useCallback)(e=>{L(e),eS.setBlameSelectedCommit(null),"history"===e&&eT.selectedBranch&&eT.loadCommits(eT.selectedBranch)},[eS,eT.selectedBranch,eT.loadCommits]),eX=(0,s.useCallback)(()=>{if(!eS.selectedPath)return;let e={filePath:eS.selectedPath,lineNumber:Y.current},t=eN.goBack(e);t&&(t.filePath===eS.selectedPath?eS.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[eS,eN]),eY=(0,s.useCallback)(()=>{if(!eS.selectedPath)return;let e={filePath:eS.selectedPath,lineNumber:Y.current},t=eN.goForward(e);t&&(t.filePath===eS.selectedPath?eS.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[eS,eN]),eG=(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,p.oR)(N("toast.copiedName",{name:r}),"success")}catch{(0,p.oR)(N("toast.copyFailed"),"error")}},[t]),eZ=(0,s.useCallback)(async e=>{try{let r=await fetch("/api/files/clipboard"),n=await r.json();if(!n.path)return void(0,p.oR)(N("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,p.oR)(N("toast.pastedFile",{name:o.newName}),"success"),eS.loadDirectory(e),eS.loadFileIndex()):(0,p.oR)(o.error||N("toast.pasteFailed"),"error")}catch{(0,p.oR)(N("toast.pasteFailed"),"error")}},[t,eS]),e0=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===C;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eY():eX();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),H(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"===S||"recent"===S)&&eS.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eG(eS.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===S||"recent"===S)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eZ((0,ee.S7)(eS.selectedPath,eS.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(ef){t.preventDefault(),ej.open();return}if(eh&&eS.selectedPath?.endsWith(".json")){t.preventDefault(),eb.open();return}}if(r&&"Escape"===t.key){if(z)return void H(!1);if(ej.isVisible)return void ej.close();if(eb.isVisible)return void eb.close();if(ef)return void ep(null);let t=Date.now();if(t-e0.current<3e3)return;e0.current=t,ek.visible?ek.closeReferences():ei?em(!1):eS.blameSelectedCommit?eS.setBlameSelectedCommit(null):eS.showBlame?eS.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,eS.showBlame,eS.blameSelectedCommit,eS,z,ek.visible,ek.closeReferences,ei,eX,eY,eh,eb,ef,ej,S,eG,eZ,C]),(0,s.useEffect)(()=>{eS.loadFiles(),eS.loadFileIndex(),eS.loadRecentFiles(),eM.fetchStatus(),eT.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{eM.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[eM.fetchStatus]);let e1=(0,s.useRef)(eC);(0,s.useEffect)(()=>{eC&&!e1.current&&(eS.loadFiles(),eS.loadFileIndex(),eS.loadRecentFiles(),eM.fetchStatus(),eT.loadBranches()),e1.current=eC},[eC]),(0,s.useEffect)(()=>{eT.selectedBranch&&eT.loadCommits(eT.selectedBranch)},[eT.selectedBranch,eT.loadCommits]);let e2=(0,s.useRef)(S);(0,s.useEffect)(()=>{let e=e2.current;if(e2.current=S,("tree"===S||"recent"===S)&&eS.recentFiles.length>0){let t=eS.recentFiles[0].path;eS.selectedPath&&("status"!==e&&"history"!==e||eS.selectedPath===t)||(eS.setShouldScrollToSelected(!0),eI(t))}},[S,eS.recentFiles,eS.selectedPath,eI,eS]);let e5=(0,s.useRef)(eT.selectedBranch);e5.current=eT.selectedBranch;let e4=(0,s.useRef)(eS.selectedPath);e4.current=eS.selectedPath;let e3=(0,s.useRef)(eS.fileContent?.type);e3.current=eS.fileContent?.type;let e6=(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||eS.setFiles(e.files||[])})),o.push(fetch(`/api/files/index?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.paths&&eS.setFileIndex(e.paths)})),o.push(fetch(`/api/files/recent?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{eS.setRecentFiles(e.files||[])}))),n||s){o.push(fetch(`/api/git/status?cwd=${encodeURIComponent(t)}`).then(e=>{if(e.ok)return e.json().then(e=>{eM.setStatus(e);let t=T(e.staged),r=T(e.unstaged);eM.setStagedTree(t),eM.setUnstagedTree(r)})})),eM.refreshDiff(),n&&eT.loadBranches();let e=e5.current;e&&o.push(fetch(`/api/git/commits?cwd=${encodeURIComponent(t)}&branch=${encodeURIComponent(e)}&limit=${ee.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];eT.setCommits(t),eT.setHasMoreCommits(t.length>=ee.B_)}))}let a=e4.current,l=e3.current;a&&"text"===l&&o.push(fetch(`/api/files/text?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(a)}`).then(e=>e.ok?e.json():null).then(e=>{e&&"string"==typeof e.content&&eS.setFileContent({type:"text",content:e.content,size:e.size,mtime:e.mtimeMs,...e.isSymlink?{isSymlink:!0,symlinkTarget:e.symlinkTarget}:{}})})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,ed.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e6,enabled:eC});let e8=(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("/"));eS.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return eS.saveExpandedPaths(r),r})}eS.setSelectedPath(e),eS.setShouldScrollToSelected(!0),L("tree")},[eS]);return(0,n.jsxs)(m.SU,{container:O,children:[(0,n.jsxs)("div",{ref:I,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:()=>eQ("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eQ("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eQ("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eQ("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eQ("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.historyTab")})]}),"tree"===S&&(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:eS.searchInputRef,type:"text",value:eS.searchQuery,onChange:e=>eS.setSearchQuery(e.target.value),placeholder:N("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"}),eS.searchQuery&&(0,n.jsx)("button",{onClick:()=>eS.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:N("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>eS.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${eS.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:eS.searchExactMatch?N("fileBrowser.exactMatchOn"):N("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>eS.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:N("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:()=>eS.searchTreeExpandedPaths?eS.setSearchTreeExpandedPaths(new Set):eS.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:N("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"===S&&(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:eL.contentSearchInputRef,type:"text",value:eL.contentSearchQuery,onChange:e=>eL.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eL.performContentSearch(eL.contentSearchQuery)},placeholder:N("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"}),eL.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>eL.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:N("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:()=>eL.performContentSearch(eL.contentSearchQuery),disabled:eL.isSearching||!eL.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:eL.isSearching?"...":N("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:eL.searchOptions.caseSensitive,onChange:e=>eL.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:N("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eL.searchOptions.wholeWord,onChange:e=>eL.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:N("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eL.searchOptions.regex,onChange:e=>eL.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:N("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:eL.searchOptions.fileType,onChange:e=>eL.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:N("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===S&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eT.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"truncate",children:eT.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eT.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:N("fileBrowser.compareModeOff"),children:N("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(ts,{branches:eT.branches,selectedBranch:eT.compareBaseBranch,onSelect:e=>{eT.setCompareBaseBranch(e),eT.loadCompareFiles(e)},isLoading:eT.isLoadingBranches,pinnedBranches:["origin/main",...eT.upstreamBranch&&"origin/main"!==eT.upstreamBranch?[eT.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(ts,{branches:eT.branches,selectedBranch:eT.selectedBranch,onSelect:e=>{eT.setSelectedBranch(e)},isLoading:eT.isLoadingBranches,pinnedBranches:["origin/main",...eT.upstreamBranch&&"origin/main"!==eT.upstreamBranch?[eT.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eT.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-accent border border-border",title:N("fileBrowser.compareModeOn"),children:N("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"===S?"":"hidden"}`,children:[eS.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:eS.creatingItem.parentPath?N("fileBrowser.createFileIn",{path:eS.creatingItem.parentPath}):N("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:N("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:()=>{D.current=!0},onCompositionEnd:()=>{D.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(D.current)return;let r=e.target.value.trim();if(!r)return;let n=eS.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,p.oR)(N("toast.createdFile",{name:r}),"success"),eS.setCreatingItem(null),eS.loadDirectory(n),eS.loadFileIndex(),n&&eS.setExpandedPaths(e=>new Set([...e,n])),eI(s);else{let t=await e.json();(0,p.oR)(t.error||N("toast.createFailed"),"error")}}catch(e){(0,p.oR)(N("toast.createFailed"),"error")}}else"Escape"===e.key&&eS.setCreatingItem(null)},onBlur:()=>eS.setCreatingItem(null)})]}),eS.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("common.loading")}):eS.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eS.fileError}):(0,n.jsx)(G,{files:eS.files,selectedPath:eS.selectedPath,expandedPaths:eS.effectiveExpandedPaths,matchedPaths:eS.matchedPaths,gitStatusMap:eJ,loadingDirs:eS.loadingDirs,onSelect:e=>{eS.setShouldScrollToSelected(!1),eI(e)},onToggle:eS.handleToggle,cwd:t,shouldScrollToSelected:eS.shouldScrollToSelected,onScrolledToSelected:()=>eS.setShouldScrollToSelected(!1),onCreateFile:e=>eS.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>W({path:e,isDirectory:t,name:r}),onRefresh:()=>eS.loadFiles(),onCopyFile:eG,onPaste:eZ})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===S?"":"hidden"}`,children:eL.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"})}):eL.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eL.searchError}):0===eL.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:eL.contentSearchQuery?N("fileBrowser.noContentSearchResults"):N("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[eL.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:[N("fileBrowser.nFilesNMatches",{files:eL.searchStats.totalFiles,matches:eL.searchStats.totalMatches}),eL.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",N("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(G,{files:eD.files,selectedPath:eS.selectedPath,expandedPaths:eO,onSelect:e=>{let t=eD.matchMap.get(e);eI(e,t?.matches[0]?.lineNumber),ei||em(!0)},onToggle:e_,cwd:t,renderActions:eW,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"===S?"":"hidden"}`,children:0===eS.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.noRecentFiles")}):(0,n.jsx)(G,{files:eS.recentFilesTree,selectedPath:eS.selectedPath,expandedPaths:eS.recentTreeDirPaths,onSelect:eI,onToggle:ee.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===S?"":"hidden"}`,children:eM.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"})}):eM.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:eM.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:N("fileBrowser.stagingArea",{count:eM.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>eM.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:N("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"})})})]}),(eM.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:eM.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:N("fileBrowser.unstageAll")})]}),(0,n.jsx)($,{files:eM.stagedTree,selectedPath:eM.statusSelectedFile?.type==="staged"?eM.statusSelectedFile.file.path:null,expandedPaths:eM.statusExpandedPaths,onSelect:e=>e.file&&eM.handleStatusFileSelect(e.file,"staged"),onToggle:eM.handleStatusToggle,cwd:t,emptyMessage:N("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=P(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eM.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:N("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(),eM.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:N("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:N("fileBrowser.workspace",{count:eM.status?.unstaged.length||0})}),(eM.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:eM.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:N("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:eM.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:N("fileBrowser.stageAll")})]})]}),(0,n.jsx)($,{files:eM.unstagedTree,selectedPath:eM.statusSelectedFile?.type==="unstaged"?eM.statusSelectedFile.file.path:null,expandedPaths:eM.statusExpandedPaths,onSelect:e=>e.file&&eM.handleStatusFileSelect(e.file,"unstaged"),onToggle:eM.handleStatusToggle,cwd:t,emptyMessage:N("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=P(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(),eM.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:N("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(),eM.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:N("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(),eM.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:N("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(),eM.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:N("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"===S?"":"hidden"}`,children:eT.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:eT.historyError})]})}):eT.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eT.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.loadingDiff")}):0===eT.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("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:N("fileBrowser.nFilesChanged",{count:eT.compareFiles.length,branch:eT.compareBaseBranch})})}),(0,n.jsx)($,{files:eT.compareFileTree,expandedPaths:eT.compareExpandedPaths,onToggle:eT.handleCompareToggle,selectedPath:eT.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eT.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eT.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eT.handleCommitListScroll,children:eT.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.loadingCommits")}):0===eT.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eT.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eT.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eT.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,ee.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),eT.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"})}),!eT.hasMoreCommits&&eT.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:N("fileBrowser.allLoaded",{count:eT.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===S||"search"===S||"recent"===S)&&(eS.blameSelectedCommit?(0,n.jsx)(Q,{isOpen:!0,onClose:()=>eS.setBlameSelectedCommit(null),commit:eS.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:eS.selectedPath||void 0,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):"map"===M?(0,n.jsx)(eV,{cwd:t,highlightedFilePath:eS.selectedPath,changedFiles:eE,onSwitchToCode:()=>E("code"),enableComments:!0,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,p.oR)(N("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),e8(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]})}):eS.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:eS.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${eS.selectedPath}`),(0,p.oR)(N("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("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(),e8(eS.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("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:eS.showEditor?(0,n.jsxs)(n.Fragment,{children:[eo.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:N("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>es.current?.save(),disabled:!eo.isDirty||eo.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eo.isDirty&&!eo.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:eo.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):N("common.save")}),(0,n.jsx)("button",{onClick:()=>es.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.closeEdit"),children:N("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[eS.fileContent?.type==="text"&&eS.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(eS.fileContent.content),(0,p.oR)(N("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.copyFileContent"),children:N("common.copy")}),eS.selectedPath?.endsWith(".json")&&eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ex(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eh?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:N("fileBrowser.toggleJsonReadable"),children:N("common.readable")}),eS.fileContent?.type==="text"&&U(eS.selectedPath)&&(0,n.jsx)("button",{onClick:()=>eS.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.previewMarkdown"),children:N("common.preview")}),eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:eS.handleToggleBlame,disabled:eS.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eS.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:N("fileBrowser.viewBlame"),children:eS.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>E("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("blockViewer.viewerToggle.toBlock"),children:N("common.block")}),eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>eS.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.editFile"),children:N("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:eS.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"})}):eS.fileContent?"text"===eS.fileContent.type&&"string"==typeof eS.fileContent.content?eS.showBlame&&eS.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:eS.blameError}),(0,n.jsx)("button",{onClick:()=>eS.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:N("fileBrowser.backToPreview")})]})}):eS.showBlame&&0===eS.blameLines.length&&eS.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"})}):eh&&eS.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(J,{search:eb}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:eg,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(eS.fileContent.content)})})]}):(0,n.jsx)(Z.Cv,{ref:es,content:eS.fileContent.content,filePath:eS.selectedPath,cwd:t,enableComments:!0,scrollToLine:er??eS.targetLineNumber,scrollToLineAlign:null!=er?"start":eS.targetScrollAlign,onScrollToLineComplete:()=>{en(null),eS.setTargetLineNumber(null)},highlightKeyword:"search"===S?eL.contentSearchQuery:null,visibleLineRef:Y,viStateRef:et,initialCursorLine:eS.initialCursorLine,initialCursorCol:eS.initialCursorCol,onInitialCursorSet:()=>{eS.setInitialCursorLine(null),eS.setInitialCursorCol(null)},onCmdClick:eH?eq:void 0,onTokenHover:eH?eU:void 0,onTokenHoverLeave:eH?ew.onTokenMouseLeave:void 0,onTokenHoverCancel:eH?ew.clearHover:void 0,blameLines:eS.showBlame&&eS.blameLines.length>0?eS.blameLines:void 0,inlineBlameLines:eS.blameLines.length>0?eS.blameLines:void 0,onSelectCommit:eS.setBlameSelectedCommit,editable:eS.showEditor,initialMtime:eS.fileContent.mtime,onEditorClose:e=>{eS.setShowEditor(!1),en(e)},onSaved:()=>{let e=Y.current??1;eS.loadFileContent(eS.selectedPath),eS.setShowEditor(!1),en(e)},onEditorStateChange:ea,viMode:!0,onContentMutate:eR,onEnterInsertMode:eP,onViSave:eB,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):"image"===eS.fileContent.type&&eS.selectedPath?(0,n.jsx)(tr,{cwd:t,path:eS.selectedPath,refreshKey:eS.fileContent.mtime,alt:eS.selectedPath}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:eS.fileContent.message||N("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:N("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:N("fileBrowser.selectFileToPreview")})]})})),"status"===S&&(eM.statusSelectedFile&&eM.statusDiff?(0,n.jsx)(tn,{cwd:t,selected:eM.statusSelectedFile,diff:eM.statusDiff,showMarkdownPreview:eM.showStatusDiffPreview,setShowMarkdownPreview:eM.setShowStatusDiffPreview,changedFiles:eE,fileGitStatusMap:e$,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)},locateInTree:e8,jsonPreview:ef,setJsonPreview:ep,jsonPreviewSearch:ej,jsonPreviewPreRef:ev}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:N("fileBrowser.selectFileToViewDiff")})})),"history"===S&&!eT.historyError&&(eT.compareMode?eT.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:N("fileBrowser.loadingDiffContent")}):eT.compareFileDiff?(0,n.jsx)(k,{oldContent:eT.compareFileDiff.oldContent,newContent:eT.compareFileDiff.newContent,filePath:eT.compareFileDiff.filePath,isNew:eT.compareFileDiff.isNew,isDeleted:eT.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eT.compareFileDiff.isDeleted&&eT.compareFileDiff.filePath.endsWith(".json")?()=>ep({content:eT.compareFileDiff.newContent,filePath:eT.compareFileDiff.filePath}):void 0,previewLabel:N("common.readable"),onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eT.compareFiles.length>0?N("fileBrowser.selectFileToViewDiff"):N("fileBrowser.clickCompareToLoad")})}):eT.selectedCommit?(0,n.jsx)(Q,{isOpen:!0,onClose:()=>eT.setSelectedCommit(null),commit:eT.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:N("fileBrowser.selectCommitToView")})}))]})]}),eS.showMarkdownPreview&&eS.fileContent?.type==="text"&&eS.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>eS.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)(el,{content:eS.fileContent.content||"",filePath:eS.selectedPath,cwd:t,onClose:()=>eS.setShowMarkdownPreview(!1)})})}),z&&(0,n.jsx)(ec,{files:eS.files,fileIndex:eS.fileIndex,recentFiles:eS.recentFilePaths,onSelectFile:e=>{eI(e),eS.setShouldScrollToSelected(!0),L("tree")},onClose:()=>H(!1)}),(ez||ek.visible)&&(0,n.jsxs)("div",{className:`flex ${ek.visible&&ez?"":"flex-col"}`,children:[ez&&(0,n.jsx)("div",{className:ek.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tc,{results:eL.contentSearchResults,loading:eL.isSearching,totalMatches:eL.searchStats?.totalMatches??0,onSelect:(e,t)=>{eS.selectedPath&&eN.push({filePath:eS.selectedPath,lineNumber:Y.current}),eI(e,t)},onClose:()=>em(!1)})}),ek.visible&&(0,n.jsx)("div",{className:ez?"flex-1 min-w-0":"",children:(0,n.jsx)(ti,{references:ek.references,loading:ek.loading,onSelect:eK,onClose:ek.closeReferences})})]})]}),q&&(j=X?.getBoundingClientRect(),y=j?.left??0,w=j?.top??0,(0,n.jsx)(i.ZL,{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:q.x+12-y,top:q.y+16-w},children:q.text})})),_&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>W(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:N("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:N("fileBrowser.confirmDeleteMessage",{name:_.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:()=>W(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:N("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=_;W(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,p.oR)(N("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";eS.loadDirectory(t),eS.loadFileIndex(),eS.selectedPath===e&&eI("")}else{let e=await n.json();(0,p.oR)(e.error||N("toast.deleteFailed"),"error")}}catch{(0,p.oR)(N("toast.deleteFailed"),"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:N("common.delete")})]})]})})}),ew.hoverInfo&&O&&(0,l.createPortal)((0,n.jsx)(tl,{ref:ew.setTooltipEl,displayString:ew.hoverInfo.displayString,documentation:ew.hoverInfo.documentation,x:ew.hoverInfo.x,y:ew.hoverInfo.y,container:O,onMouseEnter:ew.onCardMouseEnter,onMouseLeave:ew.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ew.hoverInfo;ew.clearHover(),ek.findReferences(e,t,r)},onSearch:e=>{ew.clearHover(),L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}),O)]})}function tb({isOpen:e,onClose:t,cwd:r}){let a,{t:l}=(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),[g,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,M]=(0,s.useState)([]),[E,$]=(0,s.useState)(""),[T,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,p.oR)(l("toast.worktreeLoadFailed"),"error")}finally{f(!1)}},[r]),B=(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 F=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=B(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,p.oR)(l("toast.worktreeCreateSuccess",{name:n}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||l("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(l("toast.worktreeCreateFailed"),"error")}finally{b(!1)}},I=async()=>{R(!0),$(""),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\//,"")))];M(n)}}catch{(0,p.oR)(l("toast.loadBranchFailed"),"error")}finally{R(!1)}},D=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,p.oR)(l("toast.worktreeCreateSuccess",{name:e}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||l("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(l("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,p.oR)(l("toast.worktreeDeleted"),"success"),j(null),P();else{let t=await e.json();(0,p.oR)(t.error||l("toast.worktreeDeleteFailed"),"error")}}catch(e){console.error("Failed to delete worktree:",e),(0,p.oR)(l("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,p.oR)(e.isLocked?l("toast.worktreeUnlocked"):l("toast.worktreeLocked"),"success"),P();else{let e=await n.json();(0,p.oR)(e.error||l("toast.operationFailed"),"error")}}catch(e){console.error("Failed to toggle lock:",e),(0,p.oR)(l("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:l("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:l("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",l("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?l("git.worktree.unlock"):l("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:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(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:E,onChange:e=>$(e.target.value),placeholder:l("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:l("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:T?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===(a=L.filter(e=>e.toLowerCase().includes(E.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("git.worktree.noBranches")}):a.map(e=>(0,n.jsx)("button",{onClick:()=>D(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:l("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:I,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:l("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:F,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("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:l("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:l("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("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:l("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:l("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"}):l("common.delete")})]})]})})]})}):null}var tv=r(67635),tj=r(73300),ty=r(20986),tw=r(9921),tk=r(66088),tN=r(42790);function tC(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:a}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await a(),c(!1),(0,p.oR)(l("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,p.oR)(l("toast.copiedCommand",{command:n}))}},[i,e,t,r,a,l]);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?l("shortIdBadge.clickToDisconnect"):l("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 tL=r(72588);let tM=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(700)]).then(r.bind(r,80700)).then(e=>({default:e.XtermRenderer}))),tE={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},t$=/\x1b\[[0-9;]*m/g;function tT({output:e,query:t,mode:r,currentIdx:o,matchListRef:a}){let l=(0,s.useRef)(null);l.current||(l.current=new tN.v,l.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return a.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(t$,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=l.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],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=>{a.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),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 tR=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:a,output:l,exitCode:i,isRunning:c,selected:d,onSelect:u,onInterrupt:m,onStdin:h,onDelete:x,onRerun:f,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:y,onToggleMaximize:w,maximized:k,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:L}=(0,o.Bd)(),M=(0,s.useRef)(null),E=(0,s.useRef)(null),$=(0,s.useRef)(!0),T=(0,s.useRef)(null),R=(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}`})(g),B=e&&t?tC(t+e):void 0,[F,I]=(0,s.useState)(!1),[D,O]=(0,s.useState)(""),A=(0,s.useRef)(null),_=(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[W,z]=(0,s.useState)(!1),[H,q]=(0,s.useState)(""),[U,V]=(0,s.useState)("search"),[K,J]=(0,s.useState)(0),Q=(0,s.useRef)([]),X=(0,s.useRef)(null),Y=(0,s.useRef)(0);(0,s.useEffect)(()=>{X.current||(X.current=new tN.v,X.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=E.current;if(e&&X.current){if(l.length<Y.current&&(X.current=new tN.v,X.current.use_classes=!0,Y.current=0,e.innerHTML=""),l.length>Y.current){let t=l.slice(Y.current),r=X.current.ansi_to_html(t);Y.current=l.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;I(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[l]),(0,s.useEffect)(()=>(c&&$.current&&M.current&&(null!==T.current&&cancelAnimationFrame(T.current),T.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),T.current=null})),()=>{null!==T.current&&cancelAnimationFrame(T.current)}),[l,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=l?l.split("\n").length:0,Z=(0,s.useCallback)(()=>{z(!0),requestAnimationFrame(()=>_.current?.focus())},[]),ee=(0,s.useCallback)(()=>{z(!1),q(""),J(0),A.current?.clearSearch()},[]),et=(0,s.useCallback)(e=>{e.trim()&&(b?A.current?.findNext(e):J(e=>{let t=e+1,r=Q.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(Q.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 Q.current[t]?.scrollIntoView({block:"nearest"}),t;let r=Q.current.length-1;return r>=0&&Q.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&&W){e.preventDefault(),e.stopPropagation(),ee();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,W,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:a}),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,tL.Mu)()}),children:(0,n.jsx)(eh.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:">_"}),B&&e&&t&&(0,n.jsx)(tS,{shortId:B,type:"terminal",onRegister:()=>{fetch("/api/terminal/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tabId:t,commandId:e,command:a,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:a}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),(0,p.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)(tv.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),F&&!c&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:G})}),l&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=l.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,p.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)(tj.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)(ty.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)(eh.A,{className:"w-3.5 h-3.5"})})]}),W&&(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)(em.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:_,value:H,onChange:e=>{let t=e.target.value;q(t),J(0),b&&(t.trim()?A.current?.findNext(t):A.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?er(H):et(H))},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"===U?"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"===U?"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(H),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(tw.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>et(H),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tk.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)(eh.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)(tM,{ref:A,output:l,isRunning:c,onInput:h,onResize:y,maximized:k,height:en,directWrite:!!v})})}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:en},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;$.current=t-e-r<50}},children:W&&H.trim()?(0,n.jsx)(tT,{output:l,query:H,mode:U,currentIdx:K,matchListRef:Q}):(0,n.jsx)("pre",{ref:E,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:R,value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tE[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(D+"\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 tP=r(68459),tB=r(51914);function tF({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[x,f]=(0,s.useState)(!0),p=(0,s.useCallback)(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)}},[e,t]);(0,s.useEffect)(()=>{p()},[p]);let 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&&(a(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:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(eh.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:l("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:l("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{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)(tP.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:l("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),placeholder:l("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),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)(tB.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:l("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var tI=r(10762);function tD({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0),x=(0,s.useCallback)(async()=>{h(!0);try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();l(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}finally{h(!1)}},[]);(0,s.useEffect)(()=>{x()},[x]);let f=()=>{i.trim()&&d.trim()&&(l(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:a})})).ok&&(t(a),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)(tI.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(eh.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(a).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void l(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{l(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(tP.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)(tB.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(a).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick: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 tO=r(53961),tA=r(15813),t_=r(37595),tW=r(49698),tz=r(20232),tH=r(80777);let tq=null,tU="",tV=0,tK=null,tJ=!1,tQ=new Map,tX=null,tY=null;function tG(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){tX&&(tX(t.commands),tX=null);return}let n=t.commandId;if(!n)return;let s=tQ.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)&&tQ.delete(n)}}function tZ(e){tq?.readyState===WebSocket.OPEN&&tq.send(JSON.stringify(e))}function t0(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);tU===r&&tq||(t9(),tJ=!1,tU=r,function e(){if(tJ||!tU)return;let t=new WebSocket(tU);tq=t,t.onopen=()=>{for(let e of(tV=0,tQ.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=tG,t.onclose=()=>{if(tq!==t||(tq=null,tJ))return;tK&&clearTimeout(tK);let r=Math.min(1e3*Math.pow(1.5,tV),1e4);tV++,tK=setTimeout(e,r)},t.onerror=()=>{}}())}function t1(){return new Promise((e,t)=>{if(tq?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{tq?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function t2(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:i,rows:c,onData:d,onError:u}=e;t0(o);try{await t1()}catch{u("WebSocket connection failed");return}tQ.delete(n),tQ.set(n,{onData:d,onError:u}),tZ({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...i?{cols:i,rows:c}:{}})}async function t5(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;t0(r);try{await t1()}catch{s("WebSocket connection failed");return}tQ.set(t,{onData:n,onError:s}),tZ({type:"attach",commandId:t})}function t4(e,t){tZ({type:"stdin",commandId:e,data:t})}function t3(e,t,r){tZ({type:"resize",commandId:e,cols:t,rows:r})}function t6(e){tZ({type:"interrupt",pid:e})}async function t8(e){try{t0(e);try{await t1()}catch{return[]}return await new Promise(e=>{tX=t=>{e(t)},tZ({type:"running"}),setTimeout(()=>{tX&&(tX=null,e([]))},3e3)})}finally{tY=null}}function t9(){if(tJ=!0,tK&&(clearTimeout(tK),tK=null),tq){let e=tq;tq=null,e.close()}tQ.clear(),tX&&(tX([]),tX=null),tY=null,tU="",tV=0}let t7=new Map;function re(e){t7.set(e.type,e)}function rt(e){return t7.get(e)}function rr(e){for(let t of t7.values())if(t.match(e))return t;return null}var rn=r(10611);function rs(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 ro(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 ra(e){let t=(0,rn.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 rl(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function ri({url:e,id:t,selected:r,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,onNewTab:m,timestamp:h,onTitleMouseDown:x,initialSleeping:f,onSleep:g,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),[M,E]=(0,s.useState)(f??!1),$=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useRef)(null);(0,s.useEffect)(()=>{C(e)},[e]);let P=(0,s.useRef)(!0),B=(0,s.useCallback)(()=>{M||(E(!0),L(null),g?.(t))},[M,t,g]),F=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null)},[]),{shortId:I,connected:D,connect:O,disconnect:A}=function(e,t,r){let n=(0,s.useMemo)(()=>tC(e),[e]),[o,a]=(0,s.useState)(!1),l=(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=l.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=l.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)}`);l.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=()=>{l.current=null,!r&&d.current&&(c.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,d.current=!1,c.current&&clearTimeout(c.current),l.current&&(l.current.close(),l.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&&l.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{m.current.push(e),o||a(!0)}),[o]);return{shortId:n,connected:o,connect:x,disconnect:(0,s.useCallback)(()=>{a(!1)},[])}}(t,R,!!S&&!M&&!j),_=(0,s.useRef)(D);_.current=D,(0,s.useEffect)(()=>{let e=T.current;if(!e||M)return;let t=new IntersectionObserver(([e])=>{P.current=e.isIntersecting,e.isIntersecting||_.current?F():($.current&&clearTimeout($.current),$.current=setTimeout(B,3e5))});return t.observe(e),()=>t.disconnect()},[M,B,F]),(0,s.useEffect)(()=>{M?A():D?F():P.current||($.current&&clearTimeout($.current),$.current=setTimeout(B,3e5))},[D,M,A,F,B]),(0,s.useEffect)(()=>{f&&L(null)},[]);let W=(0,s.useCallback)(()=>{E(!1),b?.(t);let r=rs(e);rl(e)?L(r):ra(e).then(()=>L(r))},[e,t,b]);(0,s.useEffect)(()=>{if(!e||M){e||L(null);return}let t=rs(e);if(rl(e))return void L(t);let r=!1;return ra(e).then(()=>{r||L(t)}),()=>{r=!0}},[e,M]);let z=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=T.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,a=()=>{o&&t&&(t.scrollTop=s)},l=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",a)},i=()=>{o=!1,t.removeEventListener("scroll",a),t.style.overflow=n};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",a),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=T.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?m?.(ro(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&C(ro(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,m]);let H=(0,s.useCallback)(()=>{y(!1),k(v("browser.pageLoadFailed"))},[]),q=(0,s.useCallback)(()=>{if(M)return void W();let e=T.current?.querySelector("iframe");if(e&&S){y(!0),k(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[M,W,S]);(0,s.useEffect)(()=>{e&&!M&&(y(!0),k(null))},[e,M]);let U=(0,s.useCallback)(()=>{N&&window.open(N,"_blank")},[N]);(0,s.useEffect)(()=>{if(!r&&!a)return;let e=e=>{"Escape"===e.key&&a&&(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)},[a,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=a&&l?l-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
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6500],{31898:(e,t,r)=>{"use strict";r.d(t,{TabManager:()=>n2});var n=r(95155),s=r(12115),o=r(79114);function a({isOpen:e,onClose:t,cwd:r,onSelectSession:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(!1),[h,x]=(0,s.useState)(null),[f,p]=(0,s.useState)(""),g=(0,s.useRef)(null),b=(0,s.useCallback)(async()=>{if(r){m(!0),x(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();d(n)}catch(e){x(e instanceof Error?e.message:"Unknown error")}finally{m(!1)}}},[r]);(0,s.useEffect)(()=>{e&&(b(),setTimeout(()=>{g.current?.focus()},100))},[e,b]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let v=c.filter(e=>{if(!f)return!0;let t=f.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:i("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:g,type:"text",placeholder:i("sessions.searchSessions"),value:f,onChange:e=>p(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:[u&&(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:i("sessions.loadingSessions")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:h})}),!u&&!h&&0===v.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:i(f?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!u&&!h&&v.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:v.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 l=r(47650),i=r(44810),c=r(64702),d=r(71063),u=r(10222),m=r(57842),h=r(1531),x=r(91694);function f(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,a=n.length,l=Array(o+1).fill(null).map(()=>Array(a+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=a;t++)r[e-1]===n[t-1]?l[e][t]=l[e-1][t-1]+1:l[e][t]=Math.max(l[e-1][t],l[e][t-1]);let i=o,c=a,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||l[i][c-1]>=l[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 p=r(38093),g=r(82085),b=r(23193);function v({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,a]=(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)a({top:0,height:o});else{let e=o/n;a({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 l=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(),a=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,a),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*l}%`,height:`${Math.max(l,.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`}})]})}var j=r(74567),y=r(84392);let w=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:a,onSearch:l,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)(j.w,{x:u?.x??0,y:u?.y??0,visible:!!u,container:r,onAddComment:o,onSendToAI:a,onSearch:l,isChatLoading:i})});function k({oldContent:e,newContent:t,filePath:r,isNew:a=!1,isDeleted:i=!1,cwd:j,enableComments:N=!1,onPreview:C,previewLabel:S,onContentSearch:L,targetLine:M}){let{t:E}=(0,o.Bd)(),$=S??E("common.preview"),T=(0,s.useMemo)(()=>f(e,t),[e,t]),R=(0,s.useRef)(null),P=(0,s.useRef)(null),B=(0,s.useRef)(null),F=(0,s.useRef)(!1),[I,D]=(0,s.useState)(!1),O=(0,m.iN)(),A=(0,h.nH)(),_=N&&!!j,{comments:W,addComment:z,updateComment:H,deleteComment:q,refresh:U}=(0,d._)({cwd:j||"",filePath:r}),[V,K]=(0,s.useState)(null),J=(0,s.useRef)(null),Q=(0,s.useRef)(()=>{}),[X,Y]=(0,s.useState)(null),[G,Z]=(0,s.useState)(null);(0,s.useEffect)(()=>{D(!0)},[]);let ee=(0,s.useMemo)(()=>{let e=new Set;for(let t of W)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[W]),et=(0,s.useMemo)(()=>{let e=new Map;for(let t of W){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[W]);(0,s.useEffect)(()=>{if(!_)return;let e=B.current,t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,J.current&&(J.current=null,Q.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,a=window.getSelection();if(!a||a.isCollapsed||!a.toString().trim()||!o){J.current&&(J.current=null,Q.current());return}let l=a.getRangeAt(0),i=B.current;if(!i||!i.contains(l.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(l.startContainer),u=c(l.endContainer);if(d&&u){let t=Math.min(d,u),r=Math.max(d,u),n=[],s=0;for(let e of T)("unchanged"===e.type||"added"===e.type)&&++s>=t&&s<=r&&n.push(e.content);let o=n.join("\n");J.current={x:e.clientX,y:e.clientY,range:{start:t,end:r},codeContent:o},Q.current()}},a=()=>{if(t||!J.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(J.current=null,Q.current())};return e?.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",a),()=>{e?.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",a)}},[_,T]);let er=(0,s.useCallback)((e,t)=>{t.stopPropagation(),K({comment:e,x:t.clientX,y:t.clientY}),J.current=null,Q.current(),Y(null),Z(null)},[]),en=(0,s.useCallback)(()=>{let e=J.current;e&&(Y({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),J.current=null,Q.current())},[]),es=(0,s.useCallback)(()=>{let e=J.current;e&&(Z({x:e.x,y:e.y,range:e.range,codeContent:e.codeContent}),J.current=null,Q.current())},[]),eo=(0,s.useCallback)(()=>{let e=J.current;if(!e||!L)return;let t=e.codeContent.trim();J.current=null,Q.current(),t&&L(t)},[L]),ea=(0,s.useCallback)(async e=>{if(G&&A&&j)try{let t=await (0,u.$3)(j),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:G.range.start,endLine:G.range.end,codeContent:G.codeContent});let s=(0,u.Gw)(n,e);A.sendMessage(s),await (0,u.RP)(j),U(),Z(null)}catch(e){console.error("Failed to send to AI:",e)}},[G,A,r,j,U]),el=(0,s.useCallback)(async e=>{X&&(await z(X.range.start,X.range.end,e),Y(null))},[X,z]);(0,s.useEffect)(()=>{let e=P.current,t=B.current;if(!e||!t)return;let r=(e,t)=>{F.current||(F.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{F.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:ei,rightLines:ec}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<T.length;s++){let o=T[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}},[T]),ed=(0,s.useMemo)(()=>T.map(e=>e.content),[T]),eu=(0,g.C)(ed,r),em=(0,c.Te)({count:ei.length,getScrollElement:()=>R.current,estimateSize:()=>20,overscan:20}),eh=a?"w-1/4":i?"w-3/4":"w-1/2",ex=a?"w-3/4":i?"w-1/4":"w-1/2",ef=(0,s.useMemo)(()=>ei.map((e,t)=>{let r=ec[t];return"removed"===e.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ei,ec]),ep=em.getTotalSize(),eg=em.getVirtualItems();return(0,s.useEffect)(()=>{if(!M)return;let e=("after"===M.side?ec:ei).findIndex(e=>e.lineNum===M.line);if(-1===e)return;let t=requestAnimationFrame(()=>{em.scrollToIndex(e,{align:"start"})});return()=>cancelAnimationFrame(t)},[M,ei,ec]),(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:a?"(New File)":i?"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:i?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[C&&(0,n.jsx)("button",{onClick:C,className:"text-muted-foreground hover:text-foreground transition-colors",children:$}),!i&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,p.oR)(E("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:E("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:R,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:P,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=ei[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]||(0,b.ZD)(t.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:B,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=ec[e.index],r=t?.lineNum||0,s=r>0&&ee.has(r),o=et.get(r),a=o?.[0],l=X&&r>=X.range.start&&r<=X.range.end,i=G&&r>=G.range.start&&r<=G.range.end,c=l||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:_?"52px":"40px"},children:[_&&r>0&&s&&a&&(0,n.jsx)("button",{onClick:e=>er(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:E("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"})})}),_&&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]||(0,b.ZD)(t?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(v,{lines:ef,containerRef:R})]}),I&&O&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w,{floatingToolbarRef:J,bumpRef:Q,container:O,onAddComment:en,onSendToAI:es,onSearch:L?eo:void 0,isChatLoading:A?.isLoading??!1}),X&&(0,n.jsx)(x.t,{x:X.x,y:X.y,range:X.range,codeContent:X.codeContent,container:O,onSubmit:el,onClose:()=>Y(null)}),G&&(0,n.jsx)(x.G,{x:G.x,y:G.y,range:G.range,container:O,onSubmit:ea,onClose:()=>Z(null)}),V&&(0,n.jsx)(y.t,{x:V.x,y:V.y,comment:V.comment,container:O,onClose:()=>K(null),onUpdateComment:H,onDeleteComment:q})]}),O)]})}function N({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>f(e,t),[e,t]),a=(0,s.useRef)(null),l=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,g.C)(l,r),d=(0,c.Te)({count:o.length,getScrollElement:()=>a.current,estimateSize:()=>20,overscan:20});return(0,n.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.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:i[e.index]||(0,b.ZD)(t.content||" ")}})]},e.key)})})})}let C={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"},S={"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 L({name:e,className:t="",size:r=16}){let s,o=S[s=e.toLowerCase()]?S[s]:C[e.split(".").pop()?.toLowerCase()||""]||C.default,a=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===a||"tsx"===a&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(a)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===a||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===a||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===a||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===a?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function M({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 E=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let m=o===t.path,h=a.has(t.path),x=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):l(t)},[t,l,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick: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:a,onSelect:l,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${m?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:x,onContextMenu:f,children:[(0,n.jsx)(L,{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)(M,{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 $({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,cwd:l,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:h}=(0,o.Bd)(),x=d??h("gitFileTree.noFiles"),{contextMenu:f,showContextMenu:p,hideContextMenu:g}=(0,m.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(E,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:a,onContextMenu:p,showChanges:i,renderActions:c},e.path)),f&&(0,n.jsx)(m.ft,{x:f.x,y:f.y,path:f.path,cwd:l,isDirectory:f.isDirectory,onClose:g})]})}function T(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,a=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===s);l||(l={name:s,path:a,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(l)),o||(n=l.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function R(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function P(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var B=r(87918);function F(e){try{let t=JSON.parse(e);return z(t,0)}catch{return e}}let I="#79c0ff",D="#a5d6ff",O="#ff7b72",A="#8b949e",_=(e,t)=>s.createElement("span",{style:{color:e}},t);function W({label:e,labelColor:t,value:r,indent:n}){let[o,a]=s.useState(!1),[l,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-l.x,r=e.clientY-l.y;t*t+r*r>25||(e.stopPropagation(),a(e=>!e))},style:{cursor:"pointer"}};if(c&&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",d,_(t,e),_(A,": "),_(D,n),_("#6e7681",` ${B.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,_(t,e),_(A,": "),z(r,n));return c?s.createElement("span",d,u):u}function z(e,t){let r=" ".repeat(t);if(null===e)return _(O,"null");if(void 0===e)return _(O,"undefined");if("string"==typeof e)return _(D,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return _("#79c0ff",String(e));if("boolean"==typeof e)return _(O,String(e));if(Array.isArray(e))return 0===e.length?_(A,"[]"):s.createElement(s.Fragment,null,_(A,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(W,{label:`[${o}]`,labelColor:I,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,_(A,","),"\n"):"\n")),r,_(A,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?_(A,"{}"):s.createElement(s.Fragment,null,_(A,"{"),"\n",...n.map(([e,o],a)=>s.createElement("span",{key:e},r+" ",s.createElement(W,{label:e,labelColor:I,value:o,indent:t+1}),a<n.length-1?s.createElement(s.Fragment,null,_(A,","),"\n"):"\n")),r,_(A,"}"))}return String(e)}let H=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function q(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return H.has(t)}function U(e){return e.toLowerCase().endsWith(".md")}let V="json-search-highlight-style";function K(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[a,l]=(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(V))return;let e=document.createElement("style");e.id=V,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=a?n:n.toLowerCase(),l=a?s:s.toLowerCase(),i=[],d=0;for(;d<l.length;){let e=l.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,a]),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:a,setCaseSensitive:l,matchCount:i,currentIndex:d,searchInputRef:m,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:y}}function J({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:B.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:B.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:B.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:B.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:B.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:B.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 Q({isOpen:e,onClose:t,commit:r,cwd:a,embedded:l=!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),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),M=(0,s.useRef)(null),E=K(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&S){e.preventDefault(),E.open();return}if("Escape"===e.key){if(E.isVisible)return void E.close();if(S)return void L(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,S,E]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{m([]),x([]),b(null),j(null),w(!0)}),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let n=T(t);if(x(n),p(new Set(R(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{b(e),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&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,a,i]);let P=(0,s.useCallback)(e=>{r&&(b(e),C(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(a)}&hash=${r.hash}&file=${encodeURIComponent(e.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>C(!1)))},[a,r]),B=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),I=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,a,l;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${a}:${l}`:`${e.getFullYear()}-${s}-${o} ${a}:${l}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let D=(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:I}),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)($,{files:h,selectedPath:g?.path||null,expandedPaths:f,onSelect:e=>e.file&&P(e.file),onToggle:B,cwd:a,showChanges:!0,emptyMessage:d("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:N?(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)(k,{oldContent:v.oldContent,newContent:v.newContent,filePath:v.filePath,isNew:v.isNew,isDeleted:v.isDeleted,cwd:a,enableComments:!0,onPreview:!v.isDeleted&&v.filePath.endsWith(".json")?()=>L({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")})})]})]}),O=S&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>L(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:S.filePath}),(0,n.jsx)("button",{onClick:()=>L(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)(J,{search:E}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(S.content)})})]})});return l?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title: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"})})}),D,O]}):(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"})})})]}),D,O]})})}let X={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"}},Y=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:a,onToggle:l,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:m,hasChangedChildren:h}=e,x=m?X[m]:null,f=(0,s.useCallback)(()=>{d.isDirectory?l(d.path):a(d.path)},[d.isDirectory,d.path,a,l]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=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)(L,{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 G({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:a=null,loadingDirs:l,onSelect:i,onToggle:d,cwd:u,shouldScrollToSelected:h=!1,onScrolledToSelected:x,className:f,renderActions:p,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y}){let w=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,m.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let a=[];for(let l of t){if(null!==n&&!n.has(l.path))continue;let t=s?.get(l.path),i=l.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(l.path,s):void 0;a.push({node:l,level:o,gitStatus:t,hasChangedChildren:i}),l.isDirectory&&l.children&&r.has(l.path)&&a.push(...e(l.children,r,n,s,o+1))}return a})(e,r,o,a),[e,r,o,a]),L=(0,c.Te)({count:S.length,getScrollElement:()=>w.current,estimateSize:()=>26,overscan:10}),M=(0,s.useRef)(x);return(M.current=x,(0,s.useEffect)(()=>{if(h&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{L.scrollToIndex(e,{align:"center"}),M.current?.()},150);return()=>clearTimeout(t)}}},[h,t,S,L]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:w,className:f||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.getVirtualItems().map(e=>{let s=S[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)(Y,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:l?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:p})},s.node.path)})}),k&&(0,n.jsx)(m.ft,{x:k.x,y:k.y,path:k.path,cwd:u,isDirectory:k.isDirectory,onClose:C,onCreateFile:g,onDelete:b,onRefresh:v,onCopyFile:j,onPaste:y})]})}var Z=r(89662),ee=r(578),et=r(14978),er=r(95766),en=r(94002);function es({content:e,sourceFile:t}){let r,a,l,i,c,{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!0),[f,g]=(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()=>{g(!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,p.oR)(s.existing?d("toast.reviewUpdated"):d("toast.reviewCreated"),"success")}catch{(0,p.oR)(d("toast.reviewCreateFailed"),"error")}finally{g(!1)}},[e,t]),j=(0,s.useCallback)(async()=>{if(u){g(!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,p.oR)(d("toast.sharingClosed"),"success")}catch{(0,p.oR)(d("toast.sharingCloseFailed"),"error")}finally{g(!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:(a=String((r=new Date(u.updatedAt)).getMonth()+1).padStart(2,"0"),l=String(r.getDate()).padStart(2,"0"),i=String(r.getHours()).padStart(2,"0"),c=String(r.getMinutes()).padStart(2,"0"),`${a}-${l} ${i}:${c}`)}),(0,n.jsx)("button",{onClick:w,className:"text-[11px] text-brand hover:underline",children:d("review.view")})]})]})}function eo(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 ea=[er.W];function el({content:e,filePath:t,cwd:r,onClose:a,sourceFile:i}){let c=i||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(()=>{}),v=(0,m.iN)(),w=(0,h.nH)(),{comments:k,addComment:N,updateComment:C,deleteComment:S,refresh:L}=(0,d._)({cwd:r,filePath:t}),[M,E]=(0,s.useState)(!1),[$,T]=(0,s.useState)(null),[R,P]=(0,s.useState)(null),[B,F]=(0,s.useState)(null),I=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>E(!0))},[]),(0,s.useEffect)(()=>{let e=p.current;if(!e)return;let t=!1,r=0,n=0,s=e=>{t=!0,r=e.clientX,n=e.clientY,g.current&&(g.current=null,b.current())},o=s=>{t=!1;let o=s.target;if(o.closest?.(".floating-toolbar")||o.closest?.("[data-comment-card]"))return;let a=Math.abs(s.clientX-r)>5||Math.abs(s.clientY-n)>5,l=window.getSelection();if(!l||l.isCollapsed){g.current=null,b.current();return}let i=l.toString();if(!i.trim()||!a){g.current=null,b.current();return}let c=l.getRangeAt(0);if(!e.contains(c.commonAncestorContainer))return;let d=eo(c.startContainer),u=eo(c.endContainer);if(d&&u){let e=Math.min(d.start,u.start),t=Math.max(d.end,u.end);g.current={x:s.clientX,y:s.clientY,range:{start:e,end:t},selectedText:i},b.current()}},a=()=>{if(t||!g.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(g.current=null,b.current())};return e.addEventListener("mousedown",s),document.addEventListener("mouseup",o),document.addEventListener("selectionchange",a),()=>{e.removeEventListener("mousedown",s),document.removeEventListener("mouseup",o),document.removeEventListener("selectionchange",a)}},[]);let D=(0,s.useCallback)(()=>{let e=g.current;e&&(T({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),O=(0,s.useCallback)(()=>{let e=g.current;e&&(P({x:e.x,y:e.y,range:e.range,codeContent:e.selectedText}),g.current=null,b.current())},[]),A=(0,s.useCallback)(async e=>{$&&(await N($.range.start,$.range.end,e),T(null))},[$,N]),_=(0,s.useCallback)(async e=>{if(R&&w)try{let n=await (0,u.$3)(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,R.range.start-1),a=Math.min(I.length,R.range.end),l=I.slice(o,a).join("\n");s.push({filePath:t,startLine:R.range.start,endLine:R.range.end,codeContent:l});let i=(0,u.Gw)(s,e);w.sendMessage(i),await (0,u.RP)(r),L(),P(null)}catch(e){console.error("Failed to send to AI:",e)}},[R,w,t,r,I,L]),W=(0,s.useMemo)(()=>{if(0===k.length)return[];let e=new Map;for(let t of k){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}))},[k]),[z,H]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===W.length||!p.current)return void queueMicrotask(()=>H([]));let e=setTimeout(()=>{let e=p.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of W){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})}}H(t)},100);return()=>clearTimeout(e)},[W,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(R){P(null),e.stopPropagation();return}if($){T(null),e.stopPropagation();return}if(g.current){g.current=null,b.current(),e.stopPropagation();return}if(B){F(null),e.stopPropagation();return}a()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[R,$,B,a]),(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)(es,{content:e,sourceFile:c}),(0,n.jsx)("button",{onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:f("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)(en.l,{content:e,containerRef:p}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:p,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(et.T,{content:e,rehypePlugins:ea})}),z.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(),F({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&&v&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:g,bumpRef:b,container:v,onAddComment:D,onSendToAI:O,isChatLoading:w?.isLoading}),$&&(0,n.jsx)(x.t,{x:$.x,y:$.y,range:$.range,codeContent:$.codeContent,container:v,onSubmit:A,onClose:()=>T(null)}),R&&(0,n.jsx)(x.G,{x:R.x,y:R.y,range:R.range,filePath:t,codeContent:R.codeContent,container:v,onSubmit:_,onClose:()=>P(null),isChatLoading:w?.isLoading}),B&&(0,n.jsx)(y.t,{x:B.x,y:B.y,comment:B.comment,container:v,onClose:()=>F(null),onUpdateComment:C,onDeleteComment:S})]}),v)]})}function ei({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),a=o>=0?e.slice(0,o+1):"",l=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],a="",l=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==l&&a&&(o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-${s}`):(0,n.jsx)("span",{children:a},`${t}-${s}`)),a=""),l=c,a+=e[s]}return a&&o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-end`):(0,n.jsx)("span",{children:a},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[a&&i(a,0,"text-muted-foreground"),i(l,a.length,"text-foreground")]})}function ec({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:l}){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,a=0,l=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),l===i-1&&(a+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(a+=10),i>e.lastIndexOf("/")&&(a+=3),e[i]===t[o]&&(a+=1),l=i,o++);return o<n.length?null:(a-=.1*e.length,{path:e,score:a,matchedIndices:s})}(t,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=>{a(e),l()},[a,l]),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(),l()}},[g,m,v,l]);return(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:l,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref: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)(L,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(ei,{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")]})]})]})})})}var ed=r(22552);function eu(){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}var em=r(61878),eh=r(33210),ex=r(48368),ef=r(91958),ep=r(45916),eg=r(31794),eb=r(69048),ev=r(97567),ej=r(68806),ey=r(52475);function ew({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ex.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(ep.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(eg.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(eb.A,{className:s});case"class":return(0,n.jsx)(ev.A,{className:s});case"interface":return(0,n.jsx)(ej.A,{className:s});default:return(0,n.jsx)(ey.A,{className:s})}}let ek=new Map,eN=new Map;async function eC(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){ek.clear(),eN.clear();return}let t=`${e}::`;for(let e of ek.keys())e.startsWith(t)&&ek.delete(e);for(let e of eN.keys())e.startsWith(t)&&eN.delete(e)}(e);else{let e=ek.get(n);if(e)return e;let t=eN.get(n);if(t)return t}let s=(async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let a=await o.json();return ek.set(n,a),a})().finally(()=>eN.delete(n));return eN.set(n,s),s}var eS=r(72816),eL=r(50538);function eM({entries:e,onSelect:t,onClear:r}){return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eL.A,{className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:0===e.length?"history":`history \xb7 ${e.length}/15`})]}),e.length>0&&(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",title:"Clear history",children:(0,n.jsx)(eh.A,{className:"w-3 h-3"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:"Click an input or output pin to begin tracing."}):e.map((e,r)=>{var s;let o;return(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:bg-secondary/60 transition-colors group flex items-start gap-1.5",title:`${e.qname} \xb7 ${e.filePath}`,children:[(0,n.jsx)(ew,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]},`${e.filePath}::${e.qname}::${r}`)})})]})}function eE(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}function e$(e,t,r){if(!document.contains(e))return null;let n=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!n)return null;let s=n.closest("[data-line]");if(!s||!t.contains(s)||r&&!s.closest(r))return null;let o=s.getAttribute("data-line");if(!o)return null;let a=parseInt(o,10);return Number.isFinite(a)?a:null}var eT=r(96035);function eR({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:a}){let l=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=l.get(n.endLine);e?e.push(n):l.set(n.endLine,[n])}return 0===l.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(l.entries()).map(([e,r])=>{let l=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsxs)("button",{onClick:e=>a(i,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-sm transition-colors",style:{top:`${l+s/2-8}px`},title:1===r.length?i.content:`${r.length} comments — click to view`,children:[(0,n.jsx)(eT.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]},e)})})}function eP({addedLines:e,totalLines:t,blockRanges:r,viewportRange:o,onJumpToLine:a}){let l,i,c=(0,s.useRef)(null),d=(0,s.useMemo)(()=>{if(t<=0||0===e.size)return[];let n=[...r].sort((e,t)=>e.startLine-t.startLine),s=[];for(let t of e){let e=n.find(e=>t>=e.startLine&&t<=e.endLine);e&&s.push({line:t,qname:e.qname})}s.sort((e,t)=>e.line-t.line);let o=[],a=null;for(let e of s)a&&e.line===a.end+1&&e.qname===a.qname?a.end=e.line:(a&&o.push(a),a={start:e.line,end:e.line,qname:e.qname});return a&&o.push(a),o},[e,r,t]);return t<=0||0===r.length?null:(0,n.jsxs)("div",{ref:c,onClick:e=>{let n=c.current;if(!n)return;let s=n.getBoundingClientRect();if(s.height<=0)return;let o=Math.max(1,Math.min(t,Math.round((e.clientY-s.top)/s.height*t))),l=d.find(e=>o>=e.start&&o<=e.end);if(l)return void a(l.qname,o);if(d.length>0){let e=Math.max(2,Math.round(.05*t)),r=null,n=1/0;for(let e of d){let t=o<e.start?e.start-o:o>e.end?o-e.end:0;t<n&&(r=e,n=t)}if(r&&n<=e){let e=o<r.start?r.start:o>r.end?r.end:o;a(r.qname,e);return}}let i=r.find(e=>o>=e.startLine&&o<=e.endLine);if(i)return void a(i.qname,i.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[d.map(e=>{let r=(e.start-1)/t*100,s=(e.end-e.start+1)/t*100;return(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${r}%`,height:`${s}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`)}),o&&o.end>=o.start&&(l=(o.start-1)/t*100,i=(o.end-o.start+1)/t*100,(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${l}%`,height:`${Math.max(1.2,i)}%`}}))]})}function eB(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eF({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:a,onCommentClick:l,addedLines:i}){let{resolvedTheme:c}=(0,eS.D)(),d=(0,s.useMemo)(()=>(0,b.sQ)(e.filePath),[e.filePath]),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void m(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,b.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,b.b8)(t)}</span></div>`}).join("");r||(m(s),x(null))}catch(e){r||x(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==h)&&o(e.qualifiedName)},[u,h,e.qualifiedName,o]),(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border bg-secondary/40 text-xs",children:[(0,n.jsx)(ew,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eD}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),h&&(0,n.jsx)("span",{className:"text-red-11",children:h}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),a&&a.length>0&&l&&(0,n.jsx)(eR,{comments:a,startLine:e.startLine,endLine:e.endLine,lineHeight:eD,bodyTopOffset:eO+eA,onCommentClick:l})]})}function eI({side:e,pin:t,accent:r,onClick:s}){let o,a,l,i,c,d,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="ext",l="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="method",l="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="method (unresolved)",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",a="self",l="text-muted-foreground/70",i=t.external.name,c=null,d="same-file",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",a=e,l="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=eB(t.external.filePath),d="in"===e?"caller":"callee",u=t.external.filePath);let h=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsxs)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${h} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${l} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:a}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",m,"\xd7"]})]})]})}let eD=18,eO=29,eA=8;function e_(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eW(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function ez(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function eH({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:a,onHighlighted:l,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let m=function(e,t){if(0===e.length)return[];let r=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eO+eA+(o-t.startLine)*eD,s);n[e]=r,s=r+22}return n}(o,e);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:"w-44 flex-shrink-0 flex flex-col gap-1 pt-1",children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(eI,{side:"in",pin:t,accent:eW(t,d),onClick:()=>a(t,e)},e_("in",t)))}),(0,n.jsx)(eF,{symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 flex-shrink-0 relative",children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${m[r]}px`},children:(0,n.jsx)(eI,{side:"out",pin:t,accent:eW(t,d),onClick:()=>a(t,e)})},e_("out",t)))})]})}function eq({cwd:e,onSelect:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(""),[c,d]=(0,s.useState)({files:[],symbols:[]}),[u,m]=(0,s.useState)(0),[h,x]=(0,s.useState)(!1),f=(0,s.useMemo)(()=>[...c.files,...c.symbols],[c]);(0,s.useEffect)(()=>{let t=l.trim();if(!t)return void d({files:[],symbols:[]});x(!0);let r=setTimeout(async()=>{try{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await fetch(`/api/projectGraph/search?${r}`);if(n.ok){let e=await n.json();d(e),m(0)}}finally{x(!1)}},120);return()=>clearTimeout(r)},[l,e]);let p=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==f.length){if("ArrowDown"===e.key)e.preventDefault(),m(e=>Math.min(e+1,f.length-1));else if("ArrowUp"===e.key)e.preventDefault(),m(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=f[u];r&&t(r)}}},[f,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-2xl overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(em.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),onKeyDown:p,placeholder:a("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),h&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(eh.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===f.length&&l&&!h&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("blockViewer.search.noResults","No matches")}),(0,n.jsx)(eU,{label:a("blockViewer.search.files","Files"),hits:c.files,startIdx:0,activeIdx:u,onSelect:t,setActive:m}),(0,n.jsx)(eU,{label:a("blockViewer.search.symbols","Symbols"),hits:c.symbols,startIdx:c.files.length,activeIdx:u,onSelect:t,setActive:m})]})]})})}function eU({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:a}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let l=r+t,i=l===s;return(0,n.jsxs)("button",{onMouseEnter:()=>a(l),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.target.kind?(0,n.jsx)(ex.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(ew,{kind:e.target.symbolKind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function eV({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:a,enableComments:l=!1,onContentSearch:i,onFocalChange:c,qnameFilter:m,qnameFilterFile:f,accentQnames:p,accentFile:g,addedLines:b,addedLinesFile:v,headerExtraLeft:w,headerExtraRight:k}){let{t:N}=(0,o.Bd)(),[C,S]=(0,s.useState)(null),L=C??t??null;(0,s.useEffect)(()=>{S(null)},[t]),(0,s.useEffect)(()=>{c?.(L)},[L,c]);let{state:M,refresh:E}=function(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let a=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eC(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?a(e,t,!1):n({state:"idle"})},[e,t,a]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&a(e,t,!0)},[e,t,a])}}(e,L),[$,T]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!L)return void T(null);let t=!1;return T(null),(async()=>{try{let r=new URLSearchParams({cwd:e,path:L}),n=await fetch(`/api/files/text?${r}`);if(!n.ok)return;let s=await n.json();t||T(s.content)}catch(e){console.error("[BlockViewer] failed to load file source for",L,e)}})(),()=>{t=!0}},[e,L]);let[R,P]=(0,s.useState)([]),[B,F]=(0,s.useState)(!1),[I,D]=(0,s.useState)(null),O=(0,s.useRef)(0),A=(0,s.useRef)(0),[_,W]=(0,s.useState)(()=>new Set),z="ready"===M.state?M.data.filePath:null;(0,s.useEffect)(()=>{W(new Set)},[z]);let H=(0,s.useCallback)(e=>{W(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),F(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let q=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;O.current+=1,D({filePath:e,qname:"__imports__",nonce:O.current});return}let r=ez(t),n=ez(e.external);P(e=>eE(eE(e,r),n)),S(n.filePath),O.current+=1,D({filePath:n.filePath,qname:n.qname,nonce:O.current})},[]),U=(0,s.useCallback)(e=>{S(e.filePath),O.current+=1,D({filePath:e.filePath,qname:e.qname,nonce:O.current})},[]),V=(0,s.useCallback)(e=>{F(!1),S(e.target.filePath)},[]),K=(0,s.useCallback)((e,t)=>{L&&(O.current+=1,D({filePath:L,qname:e,line:t,nonce:O.current}))},[L]),[J,Q]=(0,s.useState)(null),[X,Y]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!J)return;let e=null,t=()=>{e=null;let t=J.getBoundingClientRect();if(t.height<=0)return;let r=J.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let a=Number(r),l=Number(o);if(!Number.isFinite(a)||!Number.isFinite(l))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=l-a+1,m=Math.floor(c/i.height*u),h=Math.ceil(d/i.height*u)-1,x=a+Math.max(0,m),f=a+Math.min(u-1,Math.max(0,h));x<n&&(n=x),f>s&&(s=f)}),n===1/0||s===-1/0?Y(null):Y(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),J.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(J);let s=new MutationObserver(r);return s.observe(J,{childList:!0,subtree:!0}),()=>{J.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[J]);let G=l&&!!e&&!!L,Z=(0,h.nH)(),{comments:ee,addComment:et,updateComment:er,deleteComment:en,refresh:es}=(0,d._)({cwd:e,filePath:L??""}),[eo,ea]=(0,s.useState)(null),{toolbar:el,clearToolbar:ei}=function({enabled:e,container:t,bodyScope:r}){let[n,o]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!e||!t)return;let n=!1,s=0,a=0,l=e=>{n=!0,s=e.clientX,a=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o(e=>e?null:e)},i=e=>{n=!1;let l=e.target;if(l?.closest?.(".floating-toolbar"))return;let i=Math.abs(e.clientX-s)>5||Math.abs(e.clientY-a)>5,c=window.getSelection();if(!c||c.isCollapsed||!c.toString().trim()||!i)return void o(e=>e?null:e);let d=c.getRangeAt(0);if(!t.contains(d.commonAncestorContainer))return void o(e=>e?null:e);let u=e$(d.startContainer,t,r),m=e$(d.endContainer,t,r);if(null==u||null==m)return void o(e=>e?null:e);let h=Math.min(u,m),x=Math.max(u,m);o({x:e.clientX,y:e.clientY,range:{start:h,end:x},selectedText:c.toString()})},c=()=>{if(n)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o(e=>e?null:e)};return t.addEventListener("mousedown",l),document.addEventListener("mouseup",i),document.addEventListener("selectionchange",c),()=>{t.removeEventListener("mousedown",l),document.removeEventListener("mouseup",i),document.removeEventListener("selectionchange",c)}},[e,t,r]),{toolbar:n,clearToolbar:()=>o(null)}}({enabled:G,container:eo}),[ec,ed]=(0,s.useState)(null),[eu,em]=(0,s.useState)(null),[eh,ex]=(0,s.useState)(null),ef=(0,s.useCallback)(()=>{el&&(ed({x:el.x,y:el.y,range:el.range,codeContent:el.selectedText}),ei())},[el,ei]),ep=(0,s.useCallback)(()=>{el&&(em({x:el.x,y:el.y,range:el.range,codeContent:el.selectedText}),ei())},[el,ei]),eg=(0,s.useCallback)(()=>{if(!el||!i)return;let e=el.selectedText.trim();ei(),e&&i(e)},[el,i,ei]),eb=(0,s.useCallback)(async e=>{ec&&(await et(ec.range.start,ec.range.end,e,ec.codeContent),ed(null))},[ec,et]),ev=(0,s.useCallback)(async t=>{if(eu&&Z&&e&&L)try{let r=(await (0,u.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:L,startLine:eu.range.start,endLine:eu.range.end,codeContent:eu.codeContent});let n=(0,u.Gw)(r,t);Z.sendMessage(n),await (0,u.RP)(e),es(),em(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[eu,Z,e,L,es]),ej=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ex({comment:e,x:t.clientX,y:t.clientY}),ei(),ed(null),em(null)},[ei]);if((0,s.useEffect)(()=>{let e;if(!I||A.current>=I.nonce||"ready"!==M.state||!$||M.data.filePath!==I.filePath)return;if(f&&f===M.data.filePath&&m){let t=0;for(let e of M.data.functions)m.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,M.data.functions.length);if(_.size<e)return;A.current=I.nonce;let t=null,r=requestAnimationFrame(()=>{let e=I.qname.indexOf(">"),r=e>=0?I.qname.slice(0,e):I.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof I.line){let e=n.querySelector(`[data-line="${I.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"smooth",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"smooth",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[I,M,$,_,m,f]),!L)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:null,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:N("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:N("blockViewer.empty.hint","or press ⌘K to search.")})]}),B&&(0,n.jsx)(eq,{cwd:e,onSelect:V,onClose:()=>F(!1)})]});if("idle"===M.state||"loading"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,refreshDisabled:!0,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:N("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:N("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),B&&(0,n.jsx)(eq,{cwd:e,onSelect:V,onClose:()=>F(!1)})]});if("error"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:null,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:M.message}),(0,n.jsx)("button",{onClick:E,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:N("blockViewer.retry","Retry")})]})]});let ey=M.data,ew=ey.functions;if(0===ew.length&&$){let e=Math.max(1,$.split("\n").length);ew=[{filePath:ey.filePath,qualifiedName:"__file__",name:eB(ey.filePath),kind:"unknown",startLine:1,endLine:e}]}let ek=f&&f===ey.filePath,eN=g&&g===ey.filePath,eS=v&&v===ey.filePath;ek&&m&&(ew=ew.filter(e=>m.has(e.qualifiedName)));let eL=eN?p:void 0,eT=eS?b:void 0,eR=eK(ey.upstreamCalls),eF=eK(ey.downstreamCalls),eI=new Map(ew.map(e=>[e.qualifiedName,e])),eD=new Map,eO=new Map;for(let e of ey.intraCalls){let t=eI.get(e.to),r=eI.get(e.from);if(t){let r=eD.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eD.set(e.from,[n])}if(r){let t=eO.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):eO.set(e.to,[n])}}let eA=new Map;for(let e of ey.externalCalls??[]){let t=eA.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eA.set(e.focalQname,[r])}let e_=new Map;for(let e of ey.methodCalls??[]){let t=e_.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):e_.set(e.focalQname,[r])}let eW=r.has(ey.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(eJ,{focalFile:L,fileCount:ey.fileCount,functionCount:ey.functions.length,upstreamCount:ey.upstreamCalls.length,downstreamCount:ey.downstreamCalls.length,onSwitchToCode:a,onSearch:()=>F(!0),onRefresh:E,extraLeft:w,extraRight:k}),(0,n.jsxs)("div",{ref:ea,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)("div",{ref:Q,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:ew.map(e=>{let t,r,s,o,a,l;return(0,n.jsx)(eH,{symbol:e,fileSource:$,hasChange:eW,upstream:(t=eR.get(e.qualifiedName),r=eO.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eF.get(e.qualifiedName),o=eD.get(e.qualifiedName),a=e_.get(e.qualifiedName),l=eA.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...a??[],...l??[]]),onPinClick:q,onHighlighted:H,comments:G?ee:void 0,onCommentClick:G?ej:void 0,accentQnames:eL,addedLines:eT},e.qualifiedName)})})}),G&&el&&eo&&(0,n.jsx)(j.w,{x:el.x,y:el.y,visible:!0,container:eo,onAddComment:ef,onSendToAI:ep,onSearch:i?eg:void 0,isChatLoading:Z?.isLoading}),G&&ec&&(0,n.jsx)(x.t,{x:ec.x,y:ec.y,range:ec.range,codeContent:ec.codeContent,container:eo,onSubmit:eb,onClose:()=>ed(null)}),G&&eu&&L&&(0,n.jsx)(x.G,{x:eu.x,y:eu.y,range:eu.range,filePath:L,codeContent:eu.codeContent,container:eo,onSubmit:ev,onClose:()=>em(null),isChatLoading:Z?.isLoading}),G&&eh&&(0,n.jsx)(y.t,{x:eh.x,y:eh.y,comment:eh.comment,container:eo,onClose:()=>ex(null),onUpdateComment:er,onDeleteComment:en}),eT&&eT.size>0&&$&&ew.length>0&&(0,n.jsx)(eP,{addedLines:eT,totalLines:Math.max(1,$.split("\n").length),blockRanges:ew.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:X,onJumpToLine:K}),(0,n.jsx)(eM,{entries:R,onSelect:U,onClear:()=>P([])}),B&&(0,n.jsx)(eq,{cwd:e,onSelect:V,onClose:()=>F(!1)})]})]})}function eK(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function eJ({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:a,onSwitchToCode:l,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:m}){let{t:h}=(0,o.Bd)(),x={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:a??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof a&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",a," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(x)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:m(x)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":h("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(em.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":h("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ef.A,{className:"w-3 h-3"})}),l&&(0,n.jsx)("button",{onClick:l,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function eQ(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function eX(e){return e.replace(/\s+/g," ").trim()}function eY(e,t){return e?`${e}>${t}`:t}function eG(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function eZ(e,t,r,n,s=[],o){return{qualifiedName:eY(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:eQ(eX(e.text)),children:s,params:o}}function e0(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}function e1(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";default:return null}}var e2=r(14066);let e5="/tree-sitter",e4=null,e3=new Map;async function e6(e){let t,r=await (!(t=e3.get(e))&&(t=(async()=>(await (!e4&&(e4=e2.iX.init({locateFile:e=>`${e5}/${e}`})),e4),e2.TM.load(`${e5}/tree-sitter-${e}.wasm`)))(),e3.set(e,t)),t),n=new e2.iX;return n.setLanguage(r),n}function e8(e){return!e.qualifiedName.startsWith("__code_")&&"__file__"!==e.qualifiedName}async function e9(e,t){if(!e)return[];let r=e1(t);if(!r)return null;let n=(await e6(r)).parse(e);if(!n)return null;try{return(function(e){let t=[],r=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:eQ(eX(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[eZ(t,eG(t),"function",r,[],e0(t))];case"class_declaration":case"abstract_class_declaration":{let e=eG(t),n=eY(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(eZ(s,eG(s),"method",t,[],e0(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(eZ(s,eG(s),"method",t,[],e0(e)))}}}return r}(t.childForFieldName("body"),n);return[eZ(t,e,"class",r,s)]}case"interface_declaration":return[eZ(t,eG(t),"interface",r)];case"type_alias_declaration":return[eZ(t,eG(t),"type",r)];case"enum_declaration":return[eZ(t,eG(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),a=s.childForFieldName("value");if(!o)continue;let l=o.text,i=a&&("arrow_function"===a.type||"function_expression"===a.type),c=i&&a?e0(a):void 0;if(r.push(eZ(e,l,i?"function":"const",t,[],c)),a&&"object"===a.type&&!i){let e=t?`${t}>${l}`:l;for(let t=0;t<a.namedChildCount;t++){let n=a.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(eZ(n,t.text,"method",e,[],e0(s)))}else if("method_definition"===n.type){let t=eG(n);t&&r.push(eZ(n,t,"method",e,[],e0(n)))}}}}}return r}(t,r);case"class_definition":{let e=eG(t),n=eY(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(eZ(o,eG(o),"method",r,[],e0(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...eZ(t,eG(t),"method",r,[],e0(t)),startLine:o.startPosition.row+1,contentHash:eQ(eX(o.text))});else if(t?.type==="class_definition"){let s=eG(t),a=eY(r,s),l=e(t.childForFieldName("body"),a);n.push({...eZ(t,s,"class",r,l),startLine:o.startPosition.row+1,contentHash:eQ(eX(o.text))})}}else if("class_definition"===o.type){let t=eG(o),s=eY(r,t),a=e(o.childForFieldName("body"),s);n.push(eZ(o,t,"class",r,a))}}}return n}(t.childForFieldName("body"),n);return[eZ(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:eQ(eX(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:eY(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:eQ(eX(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,a=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&a.push(t)}}if(0===a.length||!o)return[];let l=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=l?`${l} ${o}`:o;return a.map((e,r)=>eZ(e,a.length>1?`${i} #${r+1}`:i,"function",t,[],e0(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],a=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:eQ(eX(s)),children:[]})},l=-1;for(let e=1;e<=n;e++)s[e]?l>=0&&(a(l,e-1),l=-1):l<0&&(l=e);return l>=0&&a(l,n),o}(e,t)),t})(n.rootNode).filter(e8)}finally{n.delete()}}async function e7(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of f(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!e1(r))return{addedLines:o};let[a,l]=await Promise.all([e9(n?"":e,r),e9(s?"":t,r)]),i=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}(a??[],l??[]),c=new Set;for(let e of i)"deleted"!==e.changeKind&&c.add(e.qname);return{changedQnames:c,addedLines:o}}function te({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:a=!1,isDeleted:l=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:m,headerExtraRight:h}){let[x,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tt(x,t,r,o,a,l,i,c,e);if(n||!s)return;let d=await e7(s.oldContent,s.newContent,x,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[x,t,r,o,a,l,i,c,e]),(0,n.jsx)(eV,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:x,accentQnames:p?.changedQnames,accentFile:x,addedLines:p?.addedLines,addedLinesFile:x,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:m,headerExtraRight:h})}async function tt(e,t,r,n,s,o,a,l,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!a.has(e))return null;let c=l?.get(e);if(!c)return null;let d=new URLSearchParams({cwd:i,file:e,type:c}),u=await fetch(`/api/git/diff?${d}`);if(!u.ok)return null;let m=await u.json();return{oldContent:m.oldContent,newContent:m.newContent,isNew:m.isNew??!1,isDeleted:m.isDeleted??!1}}function tr(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:a}=e,l="absPath"in e&&"string"==typeof e.absPath,i=l?void 0:e.cwd,c=l?void 0:e.path,d=l?e.absPath:void 0,[u,m]=(0,s.useState)({kind:"loading"}),h=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++h.current;return m({kind:"loading"}),(async()=>{if(l){if(e!==h.current)return;m({kind:"ready",etag:null,size:0});return}try{let t=`/api/files/stat?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}`,r=await fetch(t,{cache:"no-store"});if(e!==h.current)return;if(!r.ok)return void m({kind:"error",message:`stat failed (${r.status})`});let n=await r.json();if(e!==h.current)return;if(!n.exists)return void m({kind:"missing"});if("too-large"===n.category)return void m({kind:"too-large",size:n.size??0});if("image"!==n.category)return void m({kind:"error",message:`Not an image (${n.category})`});let s=n.etag||`t-${n.mtimeMs??Date.now()}`;m({kind:"ready",etag:s,size:n.size??0})}catch(t){if(e!==h.current)return;m({kind:"error",message:t instanceof Error?t.message:"Unknown error"})}})(),()=>{h.current++}},[l,i,c,d,t]),"loading"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(u.size/1024/1024)," MB)"]})});if("error"===u.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:u.message})});let x=l?`/api/file?path=${encodeURIComponent(d)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(i)}&path=${encodeURIComponent(c)}&v=${encodeURIComponent(u.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:x,alt:a??(c||d),className:o})})}function tn({cwd:e,selected:t,diff:r,showMarkdownPreview:a,setShowMarkdownPreview:l,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:m,setJsonPreview:h,jsonPreviewSearch:x,jsonPreviewPreRef:f}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)("file"),j=t.file.path,y=(0,ee.u)(j);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[y||"map"!==b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:j}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${j}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("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(),u(j)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("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"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?g("fileBrowser.staged"):g("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!y&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-xs transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:y?(0,n.jsx)(tr,{cwd:e,path:j,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:j}):(0,n.jsx)(k,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,onPreview:!r.isDeleted&&U(j)?()=>l(!0):!r.isDeleted&&j.endsWith(".json")?()=>h({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:j.endsWith(".json")?g("common.readable"):g("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(te,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,p.oR)(g("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:g("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?g("fileBrowser.staged"):g("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${b===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:g("file"===e?"common.file":"common.codeMap")},e))})}),a&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>l(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(el,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>l(!1)})})}),m&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>h(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:m.filePath}),(0,n.jsx)("button",{onClick:()=>h(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)(J,{search:x}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(m.content)})})]})})]})}function ts({branches:e,selectedBranch:t,onSelect:r,isLoading:a,pinnedBranches:l=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(""),h=(0,s.useRef)(null),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{h.current&&!h.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&x.current&&x.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=l.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],y=e=>{r(e),d(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:h,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:a,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-slate-9 transition-transform ${c?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:x,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground placeholder-slate-9"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>y(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-secondary sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>y(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-accent text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}function to(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 ta(e){return e.replace(/^\([^)]+\)\s*/,"")}let tl=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:a,container:l,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=l.getBoundingClientRect(),p=r-f.left,g=a-f.top,b=(0,s.useMemo)(()=>ta(e),[e]),v=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,a=0,l=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=l.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},a++));let l=t[0];/^["']/.test(l)?s.push((0,n.jsx)("span",{className:"text-green-400",children:l},a++)):/^\d+$/.test(l)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:l},a++)):r.test(l)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:l},a++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:l},a++)),o=t.index+l.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},a++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!x.current)return;let e=x.current,t=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=a-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,a,l]),(0,n.jsxs)("div",{ref: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=ta(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")})]})]})]})});function ti({references:e,loading:t,onSelect:r,onClose:a}){let{t:l}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)();if(t!==a.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let a=(0,b.sQ)(r.file);if("text"!==a)try{let e=n.codeToTokens(r.lineText,{lang:a,theme:s}),l=(0,b.b8)(e.tokens[0]||[]);l&&o.set(t,l)}catch{}}t===a.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[l("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(eh.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.notFound")}):c.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card/30 sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tc({results:e,loading:t,totalMatches:r,onSelect:a,onClose:l}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,b.kS)(),o=new Map;for(let t of e){let e=(0,b.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let a=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),l=(0,b.b8)(t.tokens[0]||[]);l&&o.set(a,l)}catch{}}}t===a.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:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(eh.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:()=>a(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}let td=["agent","explorer","console"],tu={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},tm=(0,s.createContext)(null);function th(){let e=(0,s.useContext)(tm);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function tx({activeView:e,onViewChange:t,children:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(!1),l=(0,s.useRef)(0),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(!1),m=td.indexOf(e),h=td.length-1;(0,s.useEffect)(()=>{l.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(),a.current&&(a.current=!1);let n=window.innerWidth,s=l.current-6*e.deltaX;!(m>0)&&s>0&&(s=0),!(m<h)&&s<0&&(s=0),l.current=s=Math.max(-n,Math.min(n,s)),c(s),u(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{let e=l.current,r=.12*n;u(!1),a.current=!0;let s=m;e<-r&&m<h?s=m+1:e>r&&m>0&&(s=m-1),l.current=0,c(0),s!==m&&t(td[s]),setTimeout(()=>{a.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)(tm.Provider,{value:p,children:r})}function tf({children:e}){let t,r,{activeView:o,dragOffset:a,isDragging:l}=th(),i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=td.indexOf(o),u=td.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:l?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*td.length}%`,transform:(t=a/u*100,r=-(100/u*d)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function tp(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:o}=th(),a=(0,s.useRef)(null),l=(0,s.useRef)([]),[i,c]=(0,s.useState)({left:0,width:0}),d=td.indexOf(e),u=()=>{if(!a.current||0===l.current.length)return{left:0,width:0};let e=a.current.getBoundingClientRect(),t=l.current.filter(Boolean);if(t.length!==td.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(td.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(td.length-1,d-m)));return(0,n.jsxs)("div",{ref:a,className:"relative flex gap-4",children:[td.map((e,r)=>(0,n.jsx)("button",{ref:e=>{l.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:tu[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 tg({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:c,searchQueryTrigger:d}){var u;let h,x,f,g,b,v,j,y,w,{t:N}=(0,o.Bd)(),{activeView:C}=th(),[S,L]=(0,s.useState)(r),[M,E]=(0,s.useState)("code"),I=(0,s.useRef)(null),D=(0,s.useRef)(!1),[O,A]=(0,s.useState)(null),[_,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(!1),[q,V]=(0,s.useState)(null),X=(0,i.F2)(),Y=(0,s.useRef)(1),et=(0,s.useRef)(null),[er,en]=(0,s.useState)(null),es=(0,s.useRef)(null),[eo,ea]=(0,s.useState)({isDirty:!1,isSaving:!1}),[ei,em]=(0,s.useState)(!1),[eh,ex]=(0,s.useState)(!1),[ef,ep]=(0,s.useState)(null),eg=(0,s.useRef)(null),eb=K(eg),ev=(0,s.useRef)(null),ej=K(ev),ey=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),ew=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),a=(0,s.useRef)(0),l=(0,s.useRef)(!1),i=(0,s.useRef)(null),c=(0,s.useRef)({x:0,y:0}),d=(0,s.useCallback)(e=>{i.current=e},[]);(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 u=(0,s.useRef)(!1),m=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,m.current&&(i.current?.removeEventListener("mouseleave",m.current),m.current=null)},[]),x=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,l.current=!0,e.style.pointerEvents="auto";let t=()=>{l.current=!1,h(),a.current++,r(null)};m.current=t,e.addEventListener("mouseleave",t)},[h]),f=(0,s.useCallback)((t,s,l,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let c=++a.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:l})}),o=await n.json();if(c!==a.current)return;o.hover&&o.hover.displayString&&r({...o.hover,x:i.x,y:i.y,filePath:t,line:s,column:l})}catch{}},300)},[e]),p=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),a.current++,o.current=setTimeout(function(){if(l.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 x()}r(null)},150)},[x]),g=(0,s.useCallback)(()=>{l.current=!0,o.current&&clearTimeout(o.current)},[]),b=(0,s.useCallback)(()=>{l.current=!1,a.current++,r(null)},[]),v=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),l.current=!1,h(),a.current++,r(null)},[h]);return(0,s.useEffect)(()=>{t||h()},[t,h]),{hoverInfo:t,onTokenMouseEnter:f,onTokenMouseLeave:p,onCardMouseEnter:g,onCardMouseLeave:b,clearHover:v,setTooltipEl:d}}(t),ek=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1);return{references:t,loading:n,visible:a,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),l(!0);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})}),a=await o.json();r(a.references||[])}catch(e){console.error("[useLSP] references error:",e),r([])}finally{o(!1)}},[e]),closeReferences:(0,s.useCallback)(()=>{l(!1),r([])},[])}}(t),eN=(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=[]},[]),g=(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:g,goForward:b,canGoBack:(0,s.useCallback)(()=>h.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),eC=eu(),eS=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[a,l]=(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),[M,E]=(0,s.useState)(null),$=(0,s.useRef)(null),[T,R]=(0,s.useState)(!1),[P,B]=(0,s.useState)(null),[F,I]=(0,s.useState)("center"),[D,O]=(0,s.useState)(null),[A,_]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[H,q]=(0,s.useState)([]),[U,V]=(0,s.useState)(!1),[K,J]=(0,s.useState)(null),[Q,X]=(0,s.useState)(null),[Y,G]=(0,s.useState)(!1),[Z,et]=(0,s.useState)(!1),er=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),en=(0,s.useMemo)(()=>(0,ee.v3)(er),[er]),es=(0,s.useMemo)(()=>new Set((0,ee.tW)(en)),[en]),eo=(0,s.useMemo)(()=>b?n?(0,ee.KH)(n,b,j):(0,ee.q3)(t,b,j):null,[t,n,b,j]);(0,s.useEffect)(()=>{if(!eo||0===eo.size)return void g(null);let e=new Set;if(n){let t=new Set(n);for(let r of eo)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&eo.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}g(e)},[eo,t,n]);let ea=p??x,el=(0,s.useRef)(null),ei=(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]),ec=(0,s.useCallback)(async()=>{C(!0),E(null);try{let t=await fetch(`/api/files/init?cwd=${encodeURIComponent(e)}`),n=await t.json();n.error?E(n.error):(r(n.files||[]),n.expandedPaths&&Array.isArray(n.expandedPaths)&&f(new Set(n.expandedPaths)))}catch(e){console.error("Error loading files:",e),E("Failed to load files")}finally{C(!1)}},[e]),ed=(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]),eu=(0,s.useCallback)(async t=>{l(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=(0,ee.MB)(r,t);return n&&(n.children=s.children),r})}catch(e){console.error("Error loading directory:",e)}finally{l(e=>{let r=new Set(e);return r.delete(t),r})}},[e]),em=(0,s.useRef)(a);em.current=a,(0,s.useEffect)(()=>{for(let e of p??x){let r=(0,ee.MB)(t,e);r&&r.isDirectory&&!r.children&&!em.current.has(e)&&eu(e)}},[t,x,p,eu]);let eh=(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]),ex=(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]),ef=(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]),ep=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),eg=(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):q(n.blame||[])}catch(e){console.error("Error loading blame:",e),J("Failed to load blame info")}finally{V(!1)}}},[e,d]),eb=(0,s.useCallback)(async t=>{L(!0),h(null),z(!1),q([]),J(null),X(null);try{let r=await fetch(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),n=await r.json();if(!r.ok)return void h({type:"error",message:n?.error||"Failed to stat file"});if(!n.exists)return void h({type:"error",message:"File not found"});if("dir"===n.kind)return void h({type:"error",message:"Path is a directory"});switch(n.category){case"image":h({type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}});break;case"binary":h({type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break;case"too-large":h({type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs});break;default:{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"});if(409===r.status){let e=await r.json().catch(()=>({}));h({type:"binary",message:e?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs});break}if(!r.ok){let e=await r.json().catch(()=>({}));h({type:"error",message:e?.error||"Failed to load file"});break}let s=await r.json();h({type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}})}}ex(t),eg(t)}catch(e){console.error("Error loading file content:",e),h({type:"error",message:"Failed to load file"})}finally{L(!1)}},[e,ex,eg]),ev=(0,s.useCallback)(()=>{W?z(!1):(z(!0),0===H.length&&eg())},[W,H.length,eg]),ej=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),B(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(B(t.scrollLine),I("start"),O(t.cursorLine??null),_(t.cursorCol??null)):(I("center"),O(null),_(null))}else I("center"),O(null),_(null);eb(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&&ei(r),n?r:t})}},[eb,ei,i]),ey=(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),ei(r),r}),r){let r=(0,ee.MB)(t,e);r&&r.isDirectory&&!r.children&&eu(e)}}},[p,ei,x,t,eu]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:a,expandedPaths:x,setExpandedPaths:f,searchTreeExpandedPaths:p,setSearchTreeExpandedPaths:g,effectiveExpandedPaths:ea,searchQuery:b,setSearchQuery:v,searchExactMatch:j,setSearchDirExact:y,matchedPaths:eo,creatingItem:w,setCreatingItem:k,isLoadingFiles:N,fileError:M,searchInputRef:$,shouldScrollToSelected:T,setShouldScrollToSelected:R,targetLineNumber:P,setTargetLineNumber:B,targetScrollAlign:F,setTargetScrollAlign:I,initialCursorLine:D,initialCursorCol:A,setInitialCursorLine:O,setInitialCursorCol:_,selectedPath:d,setSelectedPath:u,fileContent:m,setFileContent:h,isLoadingContent:S,recentFiles:i,recentFilePaths:er,setRecentFiles:c,recentFilesTree:en,recentTreeDirPaths:es,showBlame:W,setShowBlame:z,blameLines:H,isLoadingBlame:U,blameError:K,blameSelectedCommit:Q,setBlameSelectedCommit:X,showMarkdownPreview:Y,setShowMarkdownPreview:G,showEditor:Z,setShowEditor:et,saveExpandedPaths:ei,loadFiles:ec,loadFileIndex:ed,loadDirectory:eu,loadRecentFiles:eh,addToRecentFiles:ex,updateRecentFilePosition:ef,getRecentFilePosition:ep,loadFileContent:eb,loadBlame:eg,handleToggleBlame:ev,handleSelectFile:ej,handleToggle:ey}}({cwd:t});u=eS.selectedPath,v=(0,s.useRef)(null),(0,s.useEffect)(()=>{!u||u===v.current||to(u)&&(v.current=u,fetch("/api/lsp/warmup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,filePath:u})}).catch(()=>{}))},[t,u]);let eL=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(new Set),[h,x]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){a([]),p(null);return}if(n.length<2)return void d(B.A.t("fileBrowser.searchMinChars"));i(!0),d(null);try{let n=new URLSearchParams({cwd:e,q:r,caseSensitive:String(h.caseSensitive),wholeWord:String(h.wholeWord),regex:String(h.regex),fileType:h.fileType}),s=await fetch(`/api/files/search?${n}`),o=await s.json();if(o.error)throw Error(o.error);a(o.results),p({totalFiles:o.totalFiles,totalMatches:o.totalMatches,truncated:o.truncated});let l=new Set(o.results.map(e=>e.path));m(l),o.results.length>0&&t?.()}catch(e){d(e instanceof Error?e.message:"Search failed"),a([])}finally{i(!1)}},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:l,searchError:c,searchExpandedPaths:u,searchOptions:h,setSearchOptions:x,searchStats:f,contentSearchInputRef:g,performContentSearch:b,handleSearchToggle:(0,s.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>em(!0)}),eM=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[c,d]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[h,x]=(0,s.useState)(!1),[f,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)([]),[j,y]=(0,s.useState)([]),w=(0,s.useMemo)(()=>{let e=new Set([...R(b),...R(j)]);for(let t of f)e.delete(t);return e},[b,j,f]),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{a(!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=T(s.staged),a=T(s.unstaged);v(o),y(a)}catch(e){i(e instanceof Error?e.message:"Unknown error")}finally{a(!1)}},[e]),M=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),E=(0,s.useCallback)((e,r)=>{d({file:e,type:r}),t(e.path)},[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,p.oR)(B.A.t("toast.staged"),"success")}catch(e){console.error("Error staging file:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,L]),P=(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,p.oR)(B.A.t("toast.unstaged"),"success")}catch(e){console.error("Error unstaging file:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,L]),F=(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,p.oR)(B.A.t("toast.stagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error staging files:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,L]),I=(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,p.oR)(B.A.t("toast.unstagedNFiles",{count:t.length}),"success")}catch(e){console.error("Error unstaging files:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,L]),D=(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,p.oR)(B.A.t("toast.discardedNFiles",{count:t.length}),"success")}catch(e){console.error("Error discarding files:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,L]),O=(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,p.oR)(B.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error staging all files:",e),(0,p.oR)(B.A.t("toast.stageFailed"),"error")}},[e,r,L]),A=(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,p.oR)(B.A.t("toast.unstagedNFiles",{count:r.staged.length}),"success")}catch(e){console.error("Error unstaging all files:",e),(0,p.oR)(B.A.t("toast.unstageFailed"),"error")}},[e,r,L]),_=(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,p.oR)(r?B.A.t("toast.deletedFile"):B.A.t("toast.discardedChanges"),"success")}catch(e){console.error("Error discarding file:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,L]),W=(0,s.useCallback)(async()=>{if(r?.unstaged.length&&await (0,p.lJ)(B.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,p.oR)(B.A.t("toast.discardedNFiles",{count:r.unstaged.length}),"success")}catch(e){console.error("Error discarding all:",e),(0,p.oR)(B.A.t("toast.discardFailed"),"error")}},[e,r,L]);return(0,s.useEffect)(()=>{c?(async()=>{x(!0);try{let t=new URLSearchParams({file:c.file.path,type:c.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();m(n)}catch(e){console.error("Error fetching diff:",e)}finally{x(!1)}})():m(null)},[c,e,C]),{status:r,setStatus:n,statusLoading:o,statusError:l,statusSelectedFile:c,statusDiff:u,statusDiffLoading:h,statusExpandedPaths:w,stagedTree:b,setStagedTree:v,unstagedTree:j,setUnstagedTree:y,showStatusDiffPreview:k,setShowStatusDiffPreview:N,fetchStatus:L,handleStatusToggle:M,handleStatusFileSelect:E,handleStage:$,handleUnstage:P,handleStageFiles:F,handleUnstageFiles:I,handleDiscardFiles:D,handleStageAll:O,handleUnstageAll:A,handleDiscardFile:_,handleDiscardAll:W,refreshDiff:(0,s.useCallback)(()=>S(e=>e+1),[])}}({cwd:t,addToRecentFiles:eS.addToRecentFiles}),eE=(0,s.useMemo)(()=>{let e=new Set;if(eM.status){for(let t of eM.status.staged)e.add(t.path);for(let t of eM.status.unstaged)e.add(t.path)}return e},[eM.status]),e$=(0,s.useMemo)(()=>{let e=new Map;if(eM.status){for(let t of eM.status.staged)e.set(t.path,"staged");for(let t of eM.status.unstaged)e.set(t.path,"unstaged")}return e},[eM.status]),eT=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)([]),[c,d]=(0,s.useState)(null),[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)(!1),[L,M]=(0,s.useState)(!0),[E,$]=(0,s.useState)(!1),[P,F]=(0,s.useState)(!1),[I,D]=(0,s.useState)(null),O=(0,s.useRef)(null),[A,_]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[H,q]=(0,s.useState)(""),[U,V]=(0,s.useState)(""),[K,J]=(0,s.useState)([]),[Q,X]=(0,s.useState)([]),[Y,G]=(0,s.useState)(new Set),[Z,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),ei=(0,s.useCallback)(()=>{w(!0),D(null),fetch(`/api/git/branches?cwd=${encodeURIComponent(e)}`).then(e=>e.json()).then(e=>{e.error?(D("Failed to get branches"===e.error?B.A.t("git.notGitRepo"):e.error),n(null)):e.local&&e.current?(n(e),a(e.current),e.upstream&&q(e.upstream)):(D(B.A.t("git.cannotGetBranches")),n(null))}).catch(e=>{console.error(e),D(B.A.t("git.getBranchesFailed")),n(null)}).finally(()=>w(!1))},[e]),ec=(0,s.useCallback)(t=>{N(!0),d(null),m([]),x([]),b(null),j(null),M(!0),fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${ee.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];i(t),M(t.length>=ee.B_)}).catch(console.error).finally(()=>N(!1))},[e]),ed=(0,s.useCallback)(()=>{if(C||!L||!o)return;S(!0);let t=l.length;fetch(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(o)}&limit=${ee.B_}&offset=${t}`).then(e=>e.json()).then(e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),M(t.length>=ee.B_)}).catch(console.error).finally(()=>S(!1))},[e,o,l.length,C,L]),eu=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ed()},[ed]),em=(0,s.useCallback)(t=>{d(t),b(null),j(null),$(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${t.hash}`).then(e=>e.json()).then(e=>{let t=e.files||[];m(t);let r=T(t);x(r),p(new Set(R(r)))}).catch(console.error).finally(()=>$(!1))},[e]),eh=(0,s.useCallback)(r=>{c&&(b(r),t(r.path),F(!0),fetch(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${c.hash}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>j(e)).catch(console.error).finally(()=>F(!1)))},[e,c,t]),ex=(0,s.useCallback)(e=>{p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ef=(0,s.useCallback)(t=>{eo(!0),et(null),en(null),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{let t=e.files||[];J(t);let r=T(t);X(r),G(new Set(R(r)))}).catch(console.error).finally(()=>eo(!1))},[e]),ep=(0,s.useCallback)(r=>{et(r),t(r.path),el(!0),fetch(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(U)}&file=${encodeURIComponent(r.path)}`).then(e=>e.json()).then(e=>en(e)).catch(console.error).finally(()=>el(!1))},[e,U,t]),eg=(0,s.useCallback)(e=>{G(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eb=(0,s.useCallback)(e=>{if(z(e),e){let e="origin/main";V(e),ef(e)}else J([]),X([]),et(null),en(null),V("")},[H,ef]);return{branches:r,selectedBranch:o,setSelectedBranch:a,commits:l,setCommits:i,selectedCommit:c,setSelectedCommit:d,historyFiles:u,historyFileTree:h,historyExpandedPaths:f,historySelectedFile:g,historyFileDiff:v,isLoadingBranches:y,isLoadingCommits:k,isLoadingMore:C,hasMoreCommits:L,setHasMoreCommits:M,isLoadingHistoryFiles:E,isLoadingHistoryDiff:P,historyError:I,commitListRef:O,tooltipPos:A,loadBranches:ei,loadCommits:ec,loadMoreCommits:ed,handleCommitListScroll:eu,handleSelectCommit:em,handleSelectHistoryFile:eh,handleHistoryToggle:ex,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{_({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{_(null)},[]),compareMode:W,toggleCompareMode:eb,compareBaseBranch:U,setCompareBaseBranch:V,upstreamBranch:H,compareFiles:K,compareFileTree:Q,compareExpandedPaths:Y,compareSelectedFile:Z,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:ea,handleSelectCompareFile:ep,handleCompareToggle:eg,loadCompareFiles:ef}}({cwd:t,addToRecentFiles:eS.addToRecentFiles}),eR=(0,s.useCallback)(e=>{eS.setFileContent(t=>t?.type==="text"?{...t,content:e}:t)},[eS]),eP=(0,s.useCallback)(e=>{eS.setShowEditor(!0)},[eS]),eB=(0,s.useCallback)(async()=>{if(eS.fileContent&&"text"===eS.fileContent.type&&eS.fileContent.content)try{let e=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:t,path:eS.selectedPath,content:eS.fileContent.content})});if(!e.ok)throw Error("Failed to save file");let r=await e.json();r.mtime&&eS.setFileContent(e=>e?.type==="text"?{...e,mtime:r.mtime}:e),(0,p.oR)(N("toast.savedSuccess"),"success")}catch{(0,p.oR)(N("toast.saveFailed"),"error")}},[t,eS]),eF=(0,s.useCallback)(()=>{if(!eS.selectedPath)return;let e=Y.current,t=et.current;e>0&&eS.updateRecentFilePosition(eS.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[eS]),eI=(0,s.useCallback)((e,t)=>{e!==eS.selectedPath&&eF(),eS.handleSelectFile(e,t)},[eS,eF]),eD=(0,s.useMemo)(()=>{let e=eL.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,ee.v3)(r),s=new Set((0,ee.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[eL.contentSearchResults]),[eO,eA]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{eA(eD.expandDirs)},[eD.expandDirs]);let e_=(0,s.useCallback)(e=>{eA(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eW=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eD.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eD.matchMap]),ez=ei&&eL.contentSearchResults.length>0,eH=!!eS.selectedPath&&null!==to(eS.selectedPath),eq=(0,s.useCallback)(async(e,r)=>{if(!eS.selectedPath||!eH)return;let n=await ey.goToDefinition(eS.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",a=s.file.startsWith(o)?s.file.slice(o.length):s.file;eN.push({filePath:eS.selectedPath,lineNumber:Y.current}),a===eS.selectedPath?eS.setTargetLineNumber(s.line):eI(a,s.line)},[eS,t,eH,ey,eN]),eU=(0,s.useCallback)((e,t,r)=>{eS.selectedPath&&eH&&ew.onTokenMouseEnter(eS.selectedPath,e,t,r)},[eS.selectedPath,eH,ew]),eK=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;eS.selectedPath&&eN.push({filePath:eS.selectedPath,lineNumber:Y.current}),n===eS.selectedPath?eS.setTargetLineNumber(e.line):eI(n,e.line)},[eS,t,eN]),eJ=(0,s.useMemo)(()=>{if(!eM.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 eM.status.staged)e.set(r.path,t(r.status));for(let r of eM.status.unstaged)e.set(r.path,t(r.status));return e},[eM.status]);(0,s.useEffect)(()=>{A(I.current)},[]),(0,s.useEffect)(()=>{let e=I.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?V({text:r,x:e.clientX,y:e.clientY}):V(null)},n=e=>{V(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)||V(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)(()=>{L(r)},[r,a]),(0,s.useEffect)(()=>{c&&(L("search"),eL.setContentSearchQuery(c),eL.performContentSearch(c))},[d]);let eQ=(0,s.useCallback)(e=>{L(e),eS.setBlameSelectedCommit(null),"history"===e&&eT.selectedBranch&&eT.loadCommits(eT.selectedBranch)},[eS,eT.selectedBranch,eT.loadCommits]),eX=(0,s.useCallback)(()=>{if(!eS.selectedPath)return;let e={filePath:eS.selectedPath,lineNumber:Y.current},t=eN.goBack(e);t&&(t.filePath===eS.selectedPath?eS.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[eS,eN]),eY=(0,s.useCallback)(()=>{if(!eS.selectedPath)return;let e={filePath:eS.selectedPath,lineNumber:Y.current},t=eN.goForward(e);t&&(t.filePath===eS.selectedPath?eS.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[eS,eN]),eG=(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,p.oR)(N("toast.copiedName",{name:r}),"success")}catch{(0,p.oR)(N("toast.copyFailed"),"error")}},[t]),eZ=(0,s.useCallback)(async e=>{try{let r=await fetch("/api/files/clipboard"),n=await r.json();if(!n.path)return void(0,p.oR)(N("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,p.oR)(N("toast.pastedFile",{name:o.newName}),"success"),eS.loadDirectory(e),eS.loadFileIndex()):(0,p.oR)(o.error||N("toast.pasteFailed"),"error")}catch{(0,p.oR)(N("toast.pasteFailed"),"error")}},[t,eS]),e0=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===C;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eY():eX();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),H(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"===S||"recent"===S)&&eS.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eG(eS.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===S||"recent"===S)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eZ((0,ee.S7)(eS.selectedPath,eS.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(ef){t.preventDefault(),ej.open();return}if(eh&&eS.selectedPath?.endsWith(".json")){t.preventDefault(),eb.open();return}}if(r&&"Escape"===t.key){if(z)return void H(!1);if(ej.isVisible)return void ej.close();if(eb.isVisible)return void eb.close();if(ef)return void ep(null);let t=Date.now();if(t-e0.current<3e3)return;e0.current=t,ek.visible?ek.closeReferences():ei?em(!1):eS.blameSelectedCommit?eS.setBlameSelectedCommit(null):eS.showBlame?eS.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,eS.showBlame,eS.blameSelectedCommit,eS,z,ek.visible,ek.closeReferences,ei,eX,eY,eh,eb,ef,ej,S,eG,eZ,C]),(0,s.useEffect)(()=>{eS.loadFiles(),eS.loadFileIndex(),eS.loadRecentFiles(),eM.fetchStatus(),eT.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{eM.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[eM.fetchStatus]);let e1=(0,s.useRef)(eC);(0,s.useEffect)(()=>{eC&&!e1.current&&(eS.loadFiles(),eS.loadFileIndex(),eS.loadRecentFiles(),eM.fetchStatus(),eT.loadBranches()),e1.current=eC},[eC]),(0,s.useEffect)(()=>{eT.selectedBranch&&eT.loadCommits(eT.selectedBranch)},[eT.selectedBranch,eT.loadCommits]);let e2=(0,s.useRef)(S);(0,s.useEffect)(()=>{let e=e2.current;if(e2.current=S,("tree"===S||"recent"===S)&&eS.recentFiles.length>0){let t=eS.recentFiles[0].path;eS.selectedPath&&("status"!==e&&"history"!==e||eS.selectedPath===t)||(eS.setShouldScrollToSelected(!0),eI(t))}},[S,eS.recentFiles,eS.selectedPath,eI,eS]);let e5=(0,s.useRef)(eT.selectedBranch);e5.current=eT.selectedBranch;let e4=(0,s.useRef)(eS.selectedPath);e4.current=eS.selectedPath;let e3=(0,s.useRef)(eS.fileContent?.type);e3.current=eS.fileContent?.type;let e6=(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||eS.setFiles(e.files||[])})),o.push(fetch(`/api/files/index?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{e.paths&&eS.setFileIndex(e.paths)})),o.push(fetch(`/api/files/recent?cwd=${encodeURIComponent(t)}`).then(e=>e.json()).then(e=>{eS.setRecentFiles(e.files||[])}))),n||s){o.push(fetch(`/api/git/status?cwd=${encodeURIComponent(t)}`).then(e=>{if(e.ok)return e.json().then(e=>{eM.setStatus(e);let t=T(e.staged),r=T(e.unstaged);eM.setStagedTree(t),eM.setUnstagedTree(r)})})),eM.refreshDiff(),n&&eT.loadBranches();let e=e5.current;e&&o.push(fetch(`/api/git/commits?cwd=${encodeURIComponent(t)}&branch=${encodeURIComponent(e)}&limit=${ee.B_}`).then(e=>e.json()).then(e=>{let t=e.commits||[];eT.setCommits(t),eT.setHasMoreCommits(t.length>=ee.B_)}))}let a=e4.current,l=e3.current;a&&"text"===l&&o.push(fetch(`/api/files/text?cwd=${encodeURIComponent(t)}&path=${encodeURIComponent(a)}`).then(e=>e.ok?e.json():null).then(e=>{e&&"string"==typeof e.content&&eS.setFileContent({type:"text",content:e.content,size:e.size,mtime:e.mtimeMs,...e.isSymlink?{isSymlink:!0,symlinkTarget:e.symlinkTarget}:{}})})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,ed.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e6,enabled:eC});let e8=(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("/"));eS.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return eS.saveExpandedPaths(r),r})}eS.setSelectedPath(e),eS.setShouldScrollToSelected(!0),L("tree")},[eS]);return(0,n.jsxs)(m.SU,{container:O,children:[(0,n.jsxs)("div",{ref:I,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:()=>eQ("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eQ("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eQ("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eQ("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eQ("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===S?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:N("fileBrowser.historyTab")})]}),"tree"===S&&(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:eS.searchInputRef,type:"text",value:eS.searchQuery,onChange:e=>eS.setSearchQuery(e.target.value),placeholder:N("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"}),eS.searchQuery&&(0,n.jsx)("button",{onClick:()=>eS.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:N("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>eS.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${eS.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:eS.searchExactMatch?N("fileBrowser.exactMatchOn"):N("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>eS.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:N("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:()=>eS.searchTreeExpandedPaths?eS.setSearchTreeExpandedPaths(new Set):eS.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:N("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"===S&&(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:eL.contentSearchInputRef,type:"text",value:eL.contentSearchQuery,onChange:e=>eL.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eL.performContentSearch(eL.contentSearchQuery)},placeholder:N("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"}),eL.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>eL.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:N("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:()=>eL.performContentSearch(eL.contentSearchQuery),disabled:eL.isSearching||!eL.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:eL.isSearching?"...":N("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:eL.searchOptions.caseSensitive,onChange:e=>eL.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:N("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eL.searchOptions.wholeWord,onChange:e=>eL.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:N("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eL.searchOptions.regex,onChange:e=>eL.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:N("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:eL.searchOptions.fileType,onChange:e=>eL.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:N("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===S&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eT.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"truncate",children:eT.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eT.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:N("fileBrowser.compareModeOff"),children:N("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(ts,{branches:eT.branches,selectedBranch:eT.compareBaseBranch,onSelect:e=>{eT.setCompareBaseBranch(e),eT.loadCompareFiles(e)},isLoading:eT.isLoadingBranches,pinnedBranches:["origin/main",...eT.upstreamBranch&&"origin/main"!==eT.upstreamBranch?[eT.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(ts,{branches:eT.branches,selectedBranch:eT.selectedBranch,onSelect:e=>{eT.setSelectedBranch(e)},isLoading:eT.isLoadingBranches,pinnedBranches:["origin/main",...eT.upstreamBranch&&"origin/main"!==eT.upstreamBranch?[eT.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eT.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-accent border border-border",title:N("fileBrowser.compareModeOn"),children:N("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"===S?"":"hidden"}`,children:[eS.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:eS.creatingItem.parentPath?N("fileBrowser.createFileIn",{path:eS.creatingItem.parentPath}):N("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:N("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:()=>{D.current=!0},onCompositionEnd:()=>{D.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(D.current)return;let r=e.target.value.trim();if(!r)return;let n=eS.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,p.oR)(N("toast.createdFile",{name:r}),"success"),eS.setCreatingItem(null),eS.loadDirectory(n),eS.loadFileIndex(),n&&eS.setExpandedPaths(e=>new Set([...e,n])),eI(s);else{let t=await e.json();(0,p.oR)(t.error||N("toast.createFailed"),"error")}}catch(e){(0,p.oR)(N("toast.createFailed"),"error")}}else"Escape"===e.key&&eS.setCreatingItem(null)},onBlur:()=>eS.setCreatingItem(null)})]}),eS.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("common.loading")}):eS.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eS.fileError}):(0,n.jsx)(G,{files:eS.files,selectedPath:eS.selectedPath,expandedPaths:eS.effectiveExpandedPaths,matchedPaths:eS.matchedPaths,gitStatusMap:eJ,loadingDirs:eS.loadingDirs,onSelect:e=>{eS.setShouldScrollToSelected(!1),eI(e)},onToggle:eS.handleToggle,cwd:t,shouldScrollToSelected:eS.shouldScrollToSelected,onScrolledToSelected:()=>eS.setShouldScrollToSelected(!1),onCreateFile:e=>eS.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>W({path:e,isDirectory:t,name:r}),onRefresh:()=>eS.loadFiles(),onCopyFile:eG,onPaste:eZ})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===S?"":"hidden"}`,children:eL.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"})}):eL.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eL.searchError}):0===eL.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:eL.contentSearchQuery?N("fileBrowser.noContentSearchResults"):N("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[eL.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:[N("fileBrowser.nFilesNMatches",{files:eL.searchStats.totalFiles,matches:eL.searchStats.totalMatches}),eL.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",N("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(G,{files:eD.files,selectedPath:eS.selectedPath,expandedPaths:eO,onSelect:e=>{let t=eD.matchMap.get(e);eI(e,t?.matches[0]?.lineNumber),ei||em(!0)},onToggle:e_,cwd:t,renderActions:eW,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"===S?"":"hidden"}`,children:0===eS.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.noRecentFiles")}):(0,n.jsx)(G,{files:eS.recentFilesTree,selectedPath:eS.selectedPath,expandedPaths:eS.recentTreeDirPaths,onSelect:eI,onToggle:ee.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===S?"":"hidden"}`,children:eM.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"})}):eM.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:eM.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:N("fileBrowser.stagingArea",{count:eM.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>eM.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:N("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"})})})]}),(eM.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:eM.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:N("fileBrowser.unstageAll")})]}),(0,n.jsx)($,{files:eM.stagedTree,selectedPath:eM.statusSelectedFile?.type==="staged"?eM.statusSelectedFile.file.path:null,expandedPaths:eM.statusExpandedPaths,onSelect:e=>e.file&&eM.handleStatusFileSelect(e.file,"staged"),onToggle:eM.handleStatusToggle,cwd:t,emptyMessage:N("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=P(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eM.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:N("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(),eM.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:N("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:N("fileBrowser.workspace",{count:eM.status?.unstaged.length||0})}),(eM.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:eM.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:N("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:eM.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:N("fileBrowser.stageAll")})]})]}),(0,n.jsx)($,{files:eM.unstagedTree,selectedPath:eM.statusSelectedFile?.type==="unstaged"?eM.statusSelectedFile.file.path:null,expandedPaths:eM.statusExpandedPaths,onSelect:e=>e.file&&eM.handleStatusFileSelect(e.file,"unstaged"),onToggle:eM.handleStatusToggle,cwd:t,emptyMessage:N("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=P(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(),eM.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:N("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(),eM.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:N("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(),eM.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:N("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(),eM.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:N("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"===S?"":"hidden"}`,children:eT.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:eT.historyError})]})}):eT.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eT.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.loadingDiff")}):0===eT.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("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:N("fileBrowser.nFilesChanged",{count:eT.compareFiles.length,branch:eT.compareBaseBranch})})}),(0,n.jsx)($,{files:eT.compareFileTree,expandedPaths:eT.compareExpandedPaths,onToggle:eT.handleCompareToggle,selectedPath:eT.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eT.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eT.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eT.handleCommitListScroll,children:eT.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.loadingCommits")}):0===eT.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:N("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eT.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eT.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eT.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,ee.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),eT.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"})}),!eT.hasMoreCommits&&eT.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:N("fileBrowser.allLoaded",{count:eT.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===S||"search"===S||"recent"===S)&&(eS.blameSelectedCommit?(0,n.jsx)(Q,{isOpen:!0,onClose:()=>eS.setBlameSelectedCommit(null),commit:eS.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:eS.selectedPath||void 0,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):"map"===M?(0,n.jsx)(eV,{cwd:t,highlightedFilePath:eS.selectedPath,changedFiles:eE,onSwitchToCode:()=>E("code"),enableComments:!0,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,p.oR)(N("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),e8(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]})}):eS.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:eS.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${eS.selectedPath}`),(0,p.oR)(N("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("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(),e8(eS.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:N("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:eS.showEditor?(0,n.jsxs)(n.Fragment,{children:[eo.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:N("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>es.current?.save(),disabled:!eo.isDirty||eo.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eo.isDirty&&!eo.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:eo.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):N("common.save")}),(0,n.jsx)("button",{onClick:()=>es.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.closeEdit"),children:N("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[eS.fileContent?.type==="text"&&eS.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(eS.fileContent.content),(0,p.oR)(N("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.copyFileContent"),children:N("common.copy")}),eS.selectedPath?.endsWith(".json")&&eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ex(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eh?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:N("fileBrowser.toggleJsonReadable"),children:N("common.readable")}),eS.fileContent?.type==="text"&&U(eS.selectedPath)&&(0,n.jsx)("button",{onClick:()=>eS.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.previewMarkdown"),children:N("common.preview")}),eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:eS.handleToggleBlame,disabled:eS.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eS.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:N("fileBrowser.viewBlame"),children:eS.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>E("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("blockViewer.viewerToggle.toBlock"),children:N("common.codeMap")}),eS.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>eS.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:N("fileBrowser.editFile"),children:N("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:eS.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"})}):eS.fileContent?"text"===eS.fileContent.type&&"string"==typeof eS.fileContent.content?eS.showBlame&&eS.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:eS.blameError}),(0,n.jsx)("button",{onClick:()=>eS.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:N("fileBrowser.backToPreview")})]})}):eS.showBlame&&0===eS.blameLines.length&&eS.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"})}):eh&&eS.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(J,{search:eb}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:eg,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:F(eS.fileContent.content)})})]}):(0,n.jsx)(Z.Cv,{ref:es,content:eS.fileContent.content,filePath:eS.selectedPath,cwd:t,enableComments:!0,scrollToLine:er??eS.targetLineNumber,scrollToLineAlign:null!=er?"start":eS.targetScrollAlign,onScrollToLineComplete:()=>{en(null),eS.setTargetLineNumber(null)},highlightKeyword:"search"===S?eL.contentSearchQuery:null,visibleLineRef:Y,viStateRef:et,initialCursorLine:eS.initialCursorLine,initialCursorCol:eS.initialCursorCol,onInitialCursorSet:()=>{eS.setInitialCursorLine(null),eS.setInitialCursorCol(null)},onCmdClick:eH?eq:void 0,onTokenHover:eH?eU:void 0,onTokenHoverLeave:eH?ew.onTokenMouseLeave:void 0,onTokenHoverCancel:eH?ew.clearHover:void 0,blameLines:eS.showBlame&&eS.blameLines.length>0?eS.blameLines:void 0,inlineBlameLines:eS.blameLines.length>0?eS.blameLines:void 0,onSelectCommit:eS.setBlameSelectedCommit,editable:eS.showEditor,initialMtime:eS.fileContent.mtime,onEditorClose:e=>{eS.setShowEditor(!1),en(e)},onSaved:()=>{let e=Y.current??1;eS.loadFileContent(eS.selectedPath),eS.setShowEditor(!1),en(e)},onEditorStateChange:ea,viMode:!0,onContentMutate:eR,onEnterInsertMode:eP,onViSave:eB,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):"image"===eS.fileContent.type&&eS.selectedPath?(0,n.jsx)(tr,{cwd:t,path:eS.selectedPath,refreshKey:eS.fileContent.mtime,alt:eS.selectedPath}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-slate-7 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:eS.fileContent.message||N("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:N("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:N("fileBrowser.selectFileToPreview")})]})})),"status"===S&&(eM.statusSelectedFile&&eM.statusDiff?(0,n.jsx)(tn,{cwd:t,selected:eM.statusSelectedFile,diff:eM.statusDiff,showMarkdownPreview:eM.showStatusDiffPreview,setShowMarkdownPreview:eM.setShowStatusDiffPreview,changedFiles:eE,fileGitStatusMap:e$,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)},locateInTree:e8,jsonPreview:ef,setJsonPreview:ep,jsonPreviewSearch:ej,jsonPreviewPreRef:ev}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:N("fileBrowser.selectFileToViewDiff")})})),"history"===S&&!eT.historyError&&(eT.compareMode?eT.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:N("fileBrowser.loadingDiffContent")}):eT.compareFileDiff?(0,n.jsx)(k,{oldContent:eT.compareFileDiff.oldContent,newContent:eT.compareFileDiff.newContent,filePath:eT.compareFileDiff.filePath,isNew:eT.compareFileDiff.isNew,isDeleted:eT.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eT.compareFileDiff.isDeleted&&eT.compareFileDiff.filePath.endsWith(".json")?()=>ep({content:eT.compareFileDiff.newContent,filePath:eT.compareFileDiff.filePath}):void 0,previewLabel:N("common.readable"),onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eT.compareFiles.length>0?N("fileBrowser.selectFileToViewDiff"):N("fileBrowser.clickCompareToLoad")})}):eT.selectedCommit?(0,n.jsx)(Q,{isOpen:!0,onClose:()=>eT.setSelectedCommit(null),commit:eT.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:N("fileBrowser.selectCommitToView")})}))]})]}),eS.showMarkdownPreview&&eS.fileContent?.type==="text"&&eS.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>eS.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)(el,{content:eS.fileContent.content||"",filePath:eS.selectedPath,cwd:t,onClose:()=>eS.setShowMarkdownPreview(!1)})})}),z&&(0,n.jsx)(ec,{files:eS.files,fileIndex:eS.fileIndex,recentFiles:eS.recentFilePaths,onSelectFile:e=>{eI(e),eS.setShouldScrollToSelected(!0),L("tree")},onClose:()=>H(!1)}),(ez||ek.visible)&&(0,n.jsxs)("div",{className:`flex ${ek.visible&&ez?"":"flex-col"}`,children:[ez&&(0,n.jsx)("div",{className:ek.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tc,{results:eL.contentSearchResults,loading:eL.isSearching,totalMatches:eL.searchStats?.totalMatches??0,onSelect:(e,t)=>{eS.selectedPath&&eN.push({filePath:eS.selectedPath,lineNumber:Y.current}),eI(e,t)},onClose:()=>em(!1)})}),ek.visible&&(0,n.jsx)("div",{className:ez?"flex-1 min-w-0":"",children:(0,n.jsx)(ti,{references:ek.references,loading:ek.loading,onSelect:eK,onClose:ek.closeReferences})})]})]}),q&&(j=X?.getBoundingClientRect(),y=j?.left??0,w=j?.top??0,(0,n.jsx)(i.ZL,{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:q.x+12-y,top:q.y+16-w},children:q.text})})),_&&(0,n.jsx)(i.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>W(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:N("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:N("fileBrowser.confirmDeleteMessage",{name:_.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:()=>W(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:N("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=_;W(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,p.oR)(N("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";eS.loadDirectory(t),eS.loadFileIndex(),eS.selectedPath===e&&eI("")}else{let e=await n.json();(0,p.oR)(e.error||N("toast.deleteFailed"),"error")}}catch{(0,p.oR)(N("toast.deleteFailed"),"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:N("common.delete")})]})]})})}),ew.hoverInfo&&O&&(0,l.createPortal)((0,n.jsx)(tl,{ref:ew.setTooltipEl,displayString:ew.hoverInfo.displayString,documentation:ew.hoverInfo.documentation,x:ew.hoverInfo.x,y:ew.hoverInfo.y,container:O,onMouseEnter:ew.onCardMouseEnter,onMouseLeave:ew.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ew.hoverInfo;ew.clearHover(),ek.findReferences(e,t,r)},onSearch:e=>{ew.clearHover(),L("search"),eL.setContentSearchQuery(e),eL.performContentSearch(e)}}),O)]})}function tb({isOpen:e,onClose:t,cwd:r}){let a,{t:l}=(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),[g,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,M]=(0,s.useState)([]),[E,$]=(0,s.useState)(""),[T,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,p.oR)(l("toast.worktreeLoadFailed"),"error")}finally{f(!1)}},[r]),B=(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 F=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=B(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,p.oR)(l("toast.worktreeCreateSuccess",{name:n}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||l("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(l("toast.worktreeCreateFailed"),"error")}finally{b(!1)}},I=async()=>{R(!0),$(""),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\//,"")))];M(n)}}catch{(0,p.oR)(l("toast.loadBranchFailed"),"error")}finally{R(!1)}},D=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,p.oR)(l("toast.worktreeCreateSuccess",{name:e}),"success"),P();else{let e=await t.json();(0,p.oR)(e.error||l("toast.worktreeCreateFailed"),"error")}}catch(e){console.error("Failed to create worktree:",e),(0,p.oR)(l("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,p.oR)(l("toast.worktreeDeleted"),"success"),j(null),P();else{let t=await e.json();(0,p.oR)(t.error||l("toast.worktreeDeleteFailed"),"error")}}catch(e){console.error("Failed to delete worktree:",e),(0,p.oR)(l("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,p.oR)(e.isLocked?l("toast.worktreeUnlocked"):l("toast.worktreeLocked"),"success"),P();else{let e=await n.json();(0,p.oR)(e.error||l("toast.operationFailed"),"error")}}catch(e){console.error("Failed to toggle lock:",e),(0,p.oR)(l("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:l("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:l("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",l("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?l("git.worktree.unlock"):l("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:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(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:E,onChange:e=>$(e.target.value),placeholder:l("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:l("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:T?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===(a=L.filter(e=>e.toLowerCase().includes(E.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("git.worktree.noBranches")}):a.map(e=>(0,n.jsx)("button",{onClick:()=>D(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:l("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:I,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:l("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:F,disabled:!d||g,className:`px-3 py-1.5 text-sm rounded transition-colors ${d&&!g?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:g?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("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:l("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:l("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("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:l("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:l("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"}):l("common.delete")})]})]})})]})}):null}var tv=r(67635),tj=r(73300),ty=r(20986),tw=r(9921),tk=r(66088),tN=r(42790);function tC(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:a}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await a(),c(!1),(0,p.oR)(l("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,p.oR)(l("toast.copiedCommand",{command:n}))}},[i,e,t,r,a,l]);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?l("shortIdBadge.clickToDisconnect"):l("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 tL=r(72588);let tM=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(700)]).then(r.bind(r,80700)).then(e=>({default:e.XtermRenderer}))),tE={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},t$=/\x1b\[[0-9;]*m/g;function tT({output:e,query:t,mode:r,currentIdx:o,matchListRef:a}){let l=(0,s.useRef)(null);l.current||(l.current=new tN.v,l.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return a.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(t$,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=l.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],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=>{a.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),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 tR=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:a,output:l,exitCode:i,isRunning:c,selected:d,onSelect:u,onInterrupt:m,onStdin:h,onDelete:x,onRerun:f,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:y,onToggleMaximize:w,maximized:k,expandedHeight:N,bubbleContentHeight:C,onTitleMouseDown:S}){let{t:L}=(0,o.Bd)(),M=(0,s.useRef)(null),E=(0,s.useRef)(null),$=(0,s.useRef)(!0),T=(0,s.useRef)(null),R=(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}`})(g),B=e&&t?tC(t+e):void 0,[F,I]=(0,s.useState)(!1),[D,O]=(0,s.useState)(""),A=(0,s.useRef)(null),_=(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[W,z]=(0,s.useState)(!1),[H,q]=(0,s.useState)(""),[U,V]=(0,s.useState)("search"),[K,J]=(0,s.useState)(0),Q=(0,s.useRef)([]),X=(0,s.useRef)(null),Y=(0,s.useRef)(0);(0,s.useEffect)(()=>{X.current||(X.current=new tN.v,X.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=E.current;if(e&&X.current){if(l.length<Y.current&&(X.current=new tN.v,X.current.use_classes=!0,Y.current=0,e.innerHTML=""),l.length>Y.current){let t=l.slice(Y.current),r=X.current.ansi_to_html(t);Y.current=l.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;I(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[l]),(0,s.useEffect)(()=>(c&&$.current&&M.current&&(null!==T.current&&cancelAnimationFrame(T.current),T.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),T.current=null})),()=>{null!==T.current&&cancelAnimationFrame(T.current)}),[l,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=l?l.split("\n").length:0,Z=(0,s.useCallback)(()=>{z(!0),requestAnimationFrame(()=>_.current?.focus())},[]),ee=(0,s.useCallback)(()=>{z(!1),q(""),J(0),A.current?.clearSearch()},[]),et=(0,s.useCallback)(e=>{e.trim()&&(b?A.current?.findNext(e):J(e=>{let t=e+1,r=Q.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(Q.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 Q.current[t]?.scrollIntoView({block:"nearest"}),t;let r=Q.current.length-1;return r>=0&&Q.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&&W){e.preventDefault(),e.stopPropagation(),ee();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,W,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:a}),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,tL.Mu)()}),children:(0,n.jsx)(eh.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:">_"}),B&&e&&t&&(0,n.jsx)(tS,{shortId:B,type:"terminal",onRegister:()=>{fetch("/api/terminal/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tabId:t,commandId:e,command:a,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:a}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),(0,p.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)(tv.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),F&&!c&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:G})}),l&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=l.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,p.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)(tj.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)(ty.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)(eh.A,{className:"w-3.5 h-3.5"})})]}),W&&(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)(em.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:_,value:H,onChange:e=>{let t=e.target.value;q(t),J(0),b&&(t.trim()?A.current?.findNext(t):A.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?er(H):et(H))},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"===U?"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"===U?"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(H),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(tw.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>et(H),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tk.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)(eh.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)(tM,{ref:A,output:l,isRunning:c,onInput:h,onResize:y,maximized:k,height:en,directWrite:!!v})})}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:en},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;$.current=t-e-r<50}},children:W&&H.trim()?(0,n.jsx)(tT,{output:l,query:H,mode:U,currentIdx:K,matchListRef:Q}):(0,n.jsx)("pre",{ref:E,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:R,value:D,onChange:e=>O(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tE[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(D+"\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 tP=r(68459),tB=r(51914);function tF({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)({}),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[x,f]=(0,s.useState)(!0),p=(0,s.useCallback)(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)}},[e,t]);(0,s.useEffect)(()=>{p()},[p]);let 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&&(a(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:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(eh.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:l("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:l("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{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)(tP.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:l("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),g())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),placeholder:l("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),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)(tB.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:l("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:b,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var tI=r(10762);function tD({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0),x=(0,s.useCallback)(async()=>{h(!0);try{let e=await fetch("/api/terminal/aliases");if(e.ok){let t=await e.json();l(t.aliases||{})}}catch(e){console.error("Failed to load aliases:",e)}finally{h(!1)}},[]);(0,s.useEffect)(()=>{x()},[x]);let f=()=>{i.trim()&&d.trim()&&(l(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:a})})).ok&&(t(a),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)(tI.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(eh.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(a).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void l(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{l(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(tP.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)(tB.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(a).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-accent transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick: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 tO=r(53961),tA=r(15813),t_=r(37595),tW=r(49698),tz=r(20232),tH=r(80777);let tq=null,tU="",tV=0,tK=null,tJ=!1,tQ=new Map,tX=null,tY=null;function tG(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){tX&&(tX(t.commands),tX=null);return}let n=t.commandId;if(!n)return;let s=tQ.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)&&tQ.delete(n)}}function tZ(e){tq?.readyState===WebSocket.OPEN&&tq.send(JSON.stringify(e))}function t0(e){let t,r=(t="https:"===window.location.protocol?"wss:":"ws:",`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`);tU===r&&tq||(t9(),tJ=!1,tU=r,function e(){if(tJ||!tU)return;let t=new WebSocket(tU);tq=t,t.onopen=()=>{for(let e of(tV=0,tQ.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=tG,t.onclose=()=>{if(tq!==t||(tq=null,tJ))return;tK&&clearTimeout(tK);let r=Math.min(1e3*Math.pow(1.5,tV),1e4);tV++,tK=setTimeout(e,r)},t.onerror=()=>{}}())}function t1(){return new Promise((e,t)=>{if(tq?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{tq?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(n),e())},50),n=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function t2(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:i,rows:c,onData:d,onError:u}=e;t0(o);try{await t1()}catch{u("WebSocket connection failed");return}tQ.delete(n),tQ.set(n,{onData:d,onError:u}),tZ({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...i?{cols:i,rows:c}:{}})}async function t5(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;t0(r);try{await t1()}catch{s("WebSocket connection failed");return}tQ.set(t,{onData:n,onError:s}),tZ({type:"attach",commandId:t})}function t4(e,t){tZ({type:"stdin",commandId:e,data:t})}function t3(e,t,r){tZ({type:"resize",commandId:e,cols:t,rows:r})}function t6(e){tZ({type:"interrupt",pid:e})}async function t8(e){try{t0(e);try{await t1()}catch{return[]}return await new Promise(e=>{tX=t=>{e(t)},tZ({type:"running"}),setTimeout(()=>{tX&&(tX=null,e([]))},3e3)})}finally{tY=null}}function t9(){if(tJ=!0,tK&&(clearTimeout(tK),tK=null),tq){let e=tq;tq=null,e.close()}tQ.clear(),tX&&(tX([]),tX=null),tY=null,tU="",tV=0}let t7=new Map;function re(e){t7.set(e.type,e)}function rt(e){return t7.get(e)}function rr(e){for(let t of t7.values())if(t.match(e))return t;return null}var rn=r(10611);function rs(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 ro(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 ra(e){let t=(0,rn.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 rl(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function ri({url:e,id:t,selected:r,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:c,onClose:d,onToggleMaximize:u,onNewTab:m,timestamp:h,onTitleMouseDown:x,initialSleeping:f,onSleep:g,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),[M,E]=(0,s.useState)(f??!1),$=(0,s.useRef)(null),T=(0,s.useRef)(null),R=(0,s.useRef)(null);(0,s.useEffect)(()=>{C(e)},[e]);let P=(0,s.useRef)(!0),B=(0,s.useCallback)(()=>{M||(E(!0),L(null),g?.(t))},[M,t,g]),F=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null)},[]),{shortId:I,connected:D,connect:O,disconnect:A}=function(e,t,r){let n=(0,s.useMemo)(()=>tC(e),[e]),[o,a]=(0,s.useState)(!1),l=(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=l.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=l.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)}`);l.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=()=>{l.current=null,!r&&d.current&&(c.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,d.current=!1,c.current&&clearTimeout(c.current),l.current&&(l.current.close(),l.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&&l.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{m.current.push(e),o||a(!0)}),[o]);return{shortId:n,connected:o,connect:x,disconnect:(0,s.useCallback)(()=>{a(!1)},[])}}(t,R,!!S&&!M&&!j),_=(0,s.useRef)(D);_.current=D,(0,s.useEffect)(()=>{let e=T.current;if(!e||M)return;let t=new IntersectionObserver(([e])=>{P.current=e.isIntersecting,e.isIntersecting||_.current?F():($.current&&clearTimeout($.current),$.current=setTimeout(B,3e5))});return t.observe(e),()=>t.disconnect()},[M,B,F]),(0,s.useEffect)(()=>{M?A():D?F():P.current||($.current&&clearTimeout($.current),$.current=setTimeout(B,3e5))},[D,M,A,F,B]),(0,s.useEffect)(()=>{f&&L(null)},[]);let W=(0,s.useCallback)(()=>{E(!1),b?.(t);let r=rs(e);rl(e)?L(r):ra(e).then(()=>L(r))},[e,t,b]);(0,s.useEffect)(()=>{if(!e||M){e||L(null);return}let t=rs(e);if(rl(e))return void L(t);let r=!1;return ra(e).then(()=>{r||L(t)}),()=>{r=!0}},[e,M]);let z=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=T.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,a=()=>{o&&t&&(t.scrollTop=s)},l=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",a)},i=()=>{o=!1,t.removeEventListener("scroll",a),t.style.overflow=n};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",a),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=T.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?m?.(ro(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&C(ro(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,m]);let H=(0,s.useCallback)(()=>{y(!1),k(v("browser.pageLoadFailed"))},[]),q=(0,s.useCallback)(()=>{if(M)return void W();let e=T.current?.querySelector("iframe");if(e&&S){y(!0),k(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[M,W,S]);(0,s.useEffect)(()=>{e&&!M&&(y(!0),k(null))},[e,M]);let U=(0,s.useCallback)(()=>{N&&window.open(N,"_blank")},[N]);(0,s.useEffect)(()=>{if(!r&&!a)return;let e=e=>{"Escape"===e.key&&a&&(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)},[a,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=a&&l?l-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
2
  relative transition-colors cursor-pointer
3
3
  ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
4
4
  ${a?"":r?"border-brand":"border-brand/30"}`,onClick:a?void 0:c,children:[a?(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"})})}),I&&(0,n.jsx)(tS,{shortId:I,type:"browser",onRegister:()=>O(),onUnregister:async()=>{A(),await fetch("/api/browser/unregister",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:I})}).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,p.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:q,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:U,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,tL.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