wind-agent-cli 1.37.3 → 1.38.1

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 (266) hide show
  1. package/README.md +16 -1
  2. package/dist/api-docs.html +2 -2
  3. package/dist/assets/{CodeEditor-BqmxpZ_D.js → CodeEditor-Cx2QOPKS.js} +6 -6
  4. package/dist/assets/FileTree-CaCZBfXB.js +1 -0
  5. package/dist/assets/GitPanel-C8vu-HU9.js +4 -0
  6. package/dist/assets/{MarkdownPreview-93h_1tJa.js → MarkdownPreview-DM1I8sMC.js} +17 -27
  7. package/dist/assets/Shell-DrlLKa8f.css +1 -0
  8. package/dist/assets/Shell-eRBEAkRb.js +76 -0
  9. package/dist/assets/StandaloneShell-C_SgfnxT.js +1 -0
  10. package/dist/assets/TaskMasterPanel-ePMcx8a-.js +2 -0
  11. package/dist/assets/abnfDiagram-N423BO3Z-BcJZs1lF.js +1 -0
  12. package/dist/assets/arc-B53XXXxy.js +1 -0
  13. package/dist/assets/architectureDiagram-T3A2C74G-vTs0UDp_.js +36 -0
  14. package/dist/assets/{blockDiagram-VBNYF7ZC-oSjQ1SgE.js → blockDiagram-VBNYF7ZC-CRlmkPBH.js} +4 -4
  15. package/dist/assets/c4Diagram-5PPSVZJV-CDkarwX2.js +10 -0
  16. package/dist/assets/channel-BBmlxLKm.js +1 -0
  17. package/dist/assets/{chunk-2GRJ4B5K-B07uZ07O.js → chunk-2GRJ4B5K-CdVcURNG.js} +1 -1
  18. package/dist/assets/{chunk-2Q5K7J3B-DNSfO7xS.js → chunk-2Q5K7J3B-CSMQbOQx.js} +1 -1
  19. package/dist/assets/chunk-5RXB4S5H-DFW9zj_c.js +231 -0
  20. package/dist/assets/{chunk-5VM5RSS4-B7vZV0zC.js → chunk-5VM5RSS4-DBpthDmq.js} +1 -1
  21. package/dist/assets/{chunk-6Q2QTUOP-DuS_xUGG.js → chunk-6Q2QTUOP-BcUSTdgD.js} +1 -1
  22. package/dist/assets/chunk-GF5L2VYU-4m17UUNv.js +206 -0
  23. package/dist/assets/{chunk-JWPE2WC7-DD2hcXvs.js → chunk-JWPE2WC7-BQbCGGN3.js} +1 -1
  24. package/dist/assets/{chunk-KBJHAD2P-Cz-l38qp.js → chunk-KBJHAD2P-BSUyigrP.js} +1 -1
  25. package/dist/assets/{chunk-RYQCIY6F-DGFIU1YM.js → chunk-RYQCIY6F-IDx48cke.js} +1 -1
  26. package/dist/assets/{chunk-XXDRQBXY-CmfzoYFl.js → chunk-XXDRQBXY-CkptWWiw.js} +1 -1
  27. package/dist/assets/classDiagram-JCYQIIEL-Zuuh6WIs.js +1 -0
  28. package/dist/assets/classDiagram-v2-OCEON4UE-Zuuh6WIs.js +1 -0
  29. package/dist/assets/cose-bilkent-JH36ORCC-Di3RMB4X.js +1 -0
  30. package/dist/assets/{cynefin-VYW2F7L2-P1HecReO.js → cynefin-VYW2F7L2-DBEP-JNm.js} +11 -23
  31. package/dist/assets/cynefinDiagram-MW4NZA55-DCa5bQ3E.js +62 -0
  32. package/dist/assets/cytoscape.esm-yzknjiTM.js +321 -0
  33. package/dist/assets/dagre-VZM6K2ZE-N0N_WSj2.js +4 -0
  34. package/dist/assets/{diagram-7IWD3JNH-9CWGFMYR.js → diagram-7IWD3JNH-wYn0p431.js} +5 -5
  35. package/dist/assets/{diagram-B4RE2ZJO-TWK59T6V.js → diagram-B4RE2ZJO-Cse-jrwQ.js} +2 -2
  36. package/dist/assets/diagram-LBJQPF4R-Byhmgq5m.js +24 -0
  37. package/dist/assets/diagram-Q27KOJAE-BNsUkxU7.js +24 -0
  38. package/dist/assets/diagram-UB23O5K3-C3QHYX7n.js +41 -0
  39. package/dist/assets/ebnfDiagram-BXEA7PRR-BP6B3t_z.js +1 -0
  40. package/dist/assets/erDiagram-JOGREHBK-CjYRNWDj.js +85 -0
  41. package/dist/assets/feature-chat-CenAll-X.js +88 -0
  42. package/dist/assets/feature-workspace-X9kJZ4EG.js +39 -0
  43. package/dist/assets/{flowDiagram-UKHOOZJN-DEr2II5V.js → flowDiagram-UKHOOZJN-4H-yy-hv.js} +4 -4
  44. package/dist/assets/ganttDiagram-PKOTCBZU-CEjsxzjF.js +292 -0
  45. package/dist/assets/gitGraphDiagram-DS77QQ5N-CNEvMqer.js +106 -0
  46. package/dist/assets/graph-DOmOIIwC.js +1 -0
  47. package/dist/assets/index-BIKUx4Nd.js +1 -0
  48. package/dist/assets/index-BnTqIKbW.js +1 -0
  49. package/dist/assets/index-CblFvRGn.js +35 -0
  50. package/dist/assets/index-Cr5MbHuj.css +1 -0
  51. package/dist/assets/{index-BSe3UiFA.js → index-Dn_5mZup.js} +3 -3
  52. package/dist/assets/infoDiagram-6WML65LV-CaQEYwl_.js +2 -0
  53. package/dist/assets/ishikawaDiagram-WSZJBQD7-jvmcvqKv.js +70 -0
  54. package/dist/assets/journeyDiagram-NVQOT4AX-D3t6ZEEp.js +139 -0
  55. package/dist/assets/{kanban-definition-27J2QSJJ-DmlgiV7K.js → kanban-definition-27J2QSJJ-DndXvXlL.js} +6 -6
  56. package/dist/assets/{layout-D6BstSzF.js → layout-D-LzfAck.js} +1 -1
  57. package/dist/assets/{linear-Ct_eoJQk.js → linear-CRI9G1bv.js} +1 -1
  58. package/dist/assets/map-DxJ2ADlA.js +1 -0
  59. package/dist/assets/mermaid.core-Nej1-0Ug.js +306 -0
  60. package/dist/assets/{mindmap-definition-FAOFIHXS-DGtMgQhf.js → mindmap-definition-FAOFIHXS-7fzz0Exr.js} +4 -4
  61. package/dist/assets/pegDiagram-VL7TDLO6-DTiRFRfv.js +1 -0
  62. package/dist/assets/{pieDiagram-7S7Q4E2Y-DMkt_Zfr.js → pieDiagram-7S7Q4E2Y-BU4cScsB.js} +2 -2
  63. package/dist/assets/quadrantDiagram-CIZ2JOQS-Cc13j5j0.js +7 -0
  64. package/dist/assets/railroadDiagram-AXF67PYL-CfB467SJ.js +1 -0
  65. package/dist/assets/requirementDiagram-LRYGKXZP-BddSRoQa.js +84 -0
  66. package/dist/assets/sankeyDiagram-W5VNT64P-D33-L55R.js +40 -0
  67. package/dist/assets/sequenceDiagram-SI44F4Z6-BP7gKO1m.js +162 -0
  68. package/dist/assets/sizeCapture-X5ZJPWSS-DLmxTSos.js +1 -0
  69. package/dist/assets/stateDiagram-OKZ733FA-2fN5h0fl.js +1 -0
  70. package/dist/assets/stateDiagram-v2-UEYNNEHI-ddGXuRHz.js +1 -0
  71. package/dist/assets/swimlanes-SLNWSIFB-m6QzM3CR.js +2 -0
  72. package/dist/assets/swimlanesDiagram-ULZ7WXOC-DNmdh3Nm.js +8 -0
  73. package/dist/assets/timeline-definition-Z64GVDOM-B-4XL-3f.js +120 -0
  74. package/dist/assets/vendor-data-DsEZeNPr.js +4 -0
  75. package/dist/assets/vendor-i18n-B6HjLCnN.js +1 -0
  76. package/dist/assets/vendor-markdown-DkITEES2.js +298 -0
  77. package/dist/assets/vendor-react-C2GTiUCy.js +10 -0
  78. package/dist/assets/vendor-ui-CAUHSABu.js +49 -0
  79. package/dist/assets/vennDiagram-T6HMQDX7-C-2U26ta.js +34 -0
  80. package/dist/assets/{wardleyDiagram-T6FBY63Y-Db9dsaXv.js → wardleyDiagram-T6FBY63Y-BM4F1_6i.js} +2 -2
  81. package/dist/assets/workbox-window.prod.es5-BBnX5xw4.js +2 -0
  82. package/dist/assets/xychartDiagram-ELKLHX3M-BWBCnHJm.js +7 -0
  83. package/dist/favicon.png +0 -0
  84. package/dist/icons/icon-128x128.png +0 -0
  85. package/dist/icons/icon-144x144.png +0 -0
  86. package/dist/icons/icon-152x152.png +0 -0
  87. package/dist/icons/icon-180x180.png +0 -0
  88. package/dist/icons/icon-192x192.png +0 -0
  89. package/dist/icons/icon-384x384.png +0 -0
  90. package/dist/icons/icon-512x512.png +0 -0
  91. package/dist/icons/icon-72x72.png +0 -0
  92. package/dist/icons/icon-96x96.png +0 -0
  93. package/dist/icons/icon-maskable-192x192.png +0 -0
  94. package/dist/icons/icon-maskable-512x512.png +0 -0
  95. package/dist/icons/new-icon.png +0 -0
  96. package/dist/index.html +17 -27
  97. package/dist/logo-128.png +0 -0
  98. package/dist/logo-256.png +0 -0
  99. package/dist/manifest.webmanifest +1 -0
  100. package/dist/push-sw.js +48 -0
  101. package/dist/screenshots/setup-screen-mobile.png +0 -0
  102. package/dist/screenshots/setup-screen.png +0 -0
  103. package/dist/sw.js +1 -124
  104. package/dist/workbox-ae5c0bb2.js +1 -0
  105. package/dist-server/server/index.js +1 -1
  106. package/dist-server/server/index.js.map +1 -1
  107. package/dist-server/server/load-env.js +4 -2
  108. package/dist-server/server/load-env.js.map +1 -1
  109. package/dist-server/server/modules/agent/agent.routes.js +1 -1
  110. package/dist-server/server/modules/agent/agent.routes.js.map +1 -1
  111. package/dist-server/server/modules/browser-use/browser-use.service.js +1 -1
  112. package/dist-server/server/modules/browser-use/browser-use.service.js.map +1 -1
  113. package/dist-server/server/modules/cli/cli.service.js +5 -5
  114. package/dist-server/server/modules/cli/cli.service.js.map +1 -1
  115. package/dist-server/server/modules/cli/sandbox.service.js +7 -7
  116. package/dist-server/server/modules/cli/sandbox.service.js.map +1 -1
  117. package/dist-server/server/modules/commands/commands.routes.js +1 -1
  118. package/dist-server/server/modules/commands/commands.routes.js.map +1 -1
  119. package/dist-server/server/modules/commands/tests/commands.test.js +1 -1
  120. package/dist-server/server/modules/commands/tests/commands.test.js.map +1 -1
  121. package/dist-server/server/modules/database/connection.js +1 -1
  122. package/dist-server/server/modules/database/connection.js.map +1 -1
  123. package/dist-server/server/modules/database/repositories/sessions.db.js +1 -1
  124. package/dist-server/server/modules/database/tests/projects.db.integration.test.js +3 -2
  125. package/dist-server/server/modules/database/tests/projects.db.integration.test.js.map +1 -1
  126. package/dist-server/server/modules/database/tests/sessions-provider-mapping.test.js +4 -3
  127. package/dist-server/server/modules/database/tests/sessions-provider-mapping.test.js.map +1 -1
  128. package/dist-server/server/modules/database/tests/sessions.db.integration.test.js +2 -1
  129. package/dist-server/server/modules/database/tests/sessions.db.integration.test.js.map +1 -1
  130. package/dist-server/server/modules/notifications/services/notification-orchestrator.service.js +1 -1
  131. package/dist-server/server/modules/notifications/services/notification-orchestrator.service.js.map +1 -1
  132. package/dist-server/server/modules/notifications/vapid-keys.service.js +1 -1
  133. package/dist-server/server/modules/notifications/vapid-keys.service.js.map +1 -1
  134. package/dist-server/server/modules/projects/tests/project-management.service.test.js +2 -1
  135. package/dist-server/server/modules/projects/tests/project-management.service.test.js.map +1 -1
  136. package/dist-server/server/modules/providers/list/codex/codex-app-server.client.js +2 -2
  137. package/dist-server/server/modules/providers/list/codex/codex-app-server.client.js.map +1 -1
  138. package/dist-server/server/modules/providers/list/codex/codex-models.provider.js +1 -1
  139. package/dist-server/server/modules/providers/list/codex/codex-models.provider.js.map +1 -1
  140. package/dist-server/server/modules/providers/list/cursor/cursor-models.provider.js +1 -1
  141. package/dist-server/server/modules/providers/list/cursor/cursor-models.provider.js.map +1 -1
  142. package/dist-server/server/modules/providers/list/cursor/cursor-session-synchronizer.provider.js.map +1 -1
  143. package/dist-server/server/modules/providers/list/opencode/opencode-models.provider.js +1 -1
  144. package/dist-server/server/modules/providers/services/sessions.service.js +1 -1
  145. package/dist-server/server/modules/providers/tests/claude-auth.test.js +8 -0
  146. package/dist-server/server/modules/providers/tests/claude-auth.test.js.map +1 -1
  147. package/dist-server/server/modules/providers/tests/codex-sessions.test.js +1 -1
  148. package/dist-server/server/modules/providers/tests/codex-sessions.test.js.map +1 -1
  149. package/dist-server/server/modules/providers/tests/opencode-sessions.test.js +2 -2
  150. package/dist-server/server/modules/providers/tests/opencode-sessions.test.js.map +1 -1
  151. package/dist-server/server/modules/providers/tests/provider.routes.test.js +1 -1
  152. package/dist-server/server/modules/providers/tests/provider.routes.test.js.map +1 -1
  153. package/dist-server/server/modules/system/system.service.js +1 -1
  154. package/dist-server/server/modules/system/system.service.js.map +1 -1
  155. package/dist-server/server/modules/system/tests/system.service.test.js +1 -1
  156. package/dist-server/server/modules/system/tests/system.service.test.js.map +1 -1
  157. package/dist-server/server/modules/taskmaster/taskmaster.routes.js +4 -3
  158. package/dist-server/server/modules/taskmaster/taskmaster.routes.js.map +1 -1
  159. package/dist-server/server/modules/websocket/services/shell-websocket.service.js +1 -1
  160. package/dist-server/server/modules/websocket/services/shell-websocket.service.js.map +1 -1
  161. package/dist-server/server/modules/worktrees/services/worktree-list.service.js +1 -1
  162. package/dist-server/server/modules/worktrees/services/worktree-open.service.js +1 -1
  163. package/dist-server/server/modules/worktrees/services/worktree-remove.service.js +1 -1
  164. package/electron/cloud.js +3 -3
  165. package/electron/desktopNotifications.js +1 -1
  166. package/electron/desktopWindow.js +12 -12
  167. package/electron/launcher/index.html +1 -1
  168. package/electron/launcher/launcher.js +14 -14
  169. package/electron/localServer.js +5 -5
  170. package/electron/main.js +19 -19
  171. package/electron/serverInstaller.js +2 -2
  172. package/electron/viewHost.js +1 -1
  173. package/package.json +53 -37
  174. package/public/api-docs.html +2 -2
  175. package/scripts/build-client.mjs +30 -0
  176. package/scripts/generate-pwa-icons.ps1 +33 -0
  177. package/scripts/verify-pwa-build.mjs +37 -0
  178. package/server/index.ts +1 -1
  179. package/server/load-env.ts +4 -2
  180. package/server/modules/agent/agent.routes.ts +1 -1
  181. package/server/modules/browser-use/browser-use.service.ts +1 -1
  182. package/server/modules/cli/cli.service.ts +5 -5
  183. package/server/modules/cli/sandbox.service.ts +7 -7
  184. package/server/modules/commands/commands.routes.ts +1 -1
  185. package/server/modules/commands/tests/commands.test.ts +1 -1
  186. package/server/modules/database/connection.ts +2 -1
  187. package/server/modules/database/repositories/sessions.db.ts +1 -1
  188. package/server/modules/database/tests/projects.db.integration.test.ts +3 -2
  189. package/server/modules/database/tests/sessions-provider-mapping.test.ts +4 -3
  190. package/server/modules/database/tests/sessions.db.integration.test.ts +2 -1
  191. package/server/modules/notifications/services/notification-orchestrator.service.js +1 -1
  192. package/server/modules/notifications/vapid-keys.service.ts +1 -1
  193. package/server/modules/projects/tests/project-management.service.test.ts +2 -1
  194. package/server/modules/providers/list/codex/codex-app-server.client.ts +2 -2
  195. package/server/modules/providers/list/codex/codex-models.provider.ts +1 -1
  196. package/server/modules/providers/list/cursor/cursor-models.provider.ts +1 -1
  197. package/server/modules/providers/list/cursor/cursor-session-synchronizer.provider.ts +0 -1
  198. package/server/modules/providers/list/opencode/opencode-models.provider.ts +1 -1
  199. package/server/modules/providers/services/sessions.service.ts +1 -1
  200. package/server/modules/providers/tests/claude-auth.test.ts +7 -0
  201. package/server/modules/providers/tests/codex-sessions.test.ts +1 -1
  202. package/server/modules/providers/tests/opencode-sessions.test.ts +2 -2
  203. package/server/modules/providers/tests/provider.routes.test.ts +1 -1
  204. package/server/modules/system/system.service.ts +1 -1
  205. package/server/modules/system/tests/system.service.test.ts +1 -1
  206. package/server/modules/taskmaster/taskmaster.routes.ts +4 -3
  207. package/server/modules/websocket/services/shell-websocket.service.ts +1 -1
  208. package/server/modules/worktrees/services/worktree-list.service.ts +1 -1
  209. package/server/modules/worktrees/services/worktree-open.service.ts +1 -1
  210. package/server/modules/worktrees/services/worktree-remove.service.ts +1 -1
  211. package/server/shared/interfaces.ts +1 -1
  212. package/server/shared/types.ts +6 -6
  213. package/dist/assets/FileTree-DLE7Ioai.js +0 -127
  214. package/dist/assets/GitPanel-f8RMRa8D.js +0 -29
  215. package/dist/assets/PluginTabContent-DU1jjkXP.js +0 -1
  216. package/dist/assets/Shell-CN_2MRIM.js +0 -81
  217. package/dist/assets/Shell-qxJ8_QYu.css +0 -32
  218. package/dist/assets/StandaloneShell-D0avS8UE.js +0 -1
  219. package/dist/assets/TaskMasterPanel-Cpf1Q5Ph.js +0 -32
  220. package/dist/assets/abnfDiagram-N423BO3Z-p3aJIm4T.js +0 -1
  221. package/dist/assets/arc-CTeud6Fl.js +0 -1
  222. package/dist/assets/architectureDiagram-T3A2C74G-CG7kRCJU.js +0 -36
  223. package/dist/assets/c4Diagram-5PPSVZJV-RkzF0DJV.js +0 -10
  224. package/dist/assets/channel-BfQbarn9.js +0 -1
  225. package/dist/assets/chunk-5RXB4S5H-BTeYcgyb.js +0 -231
  226. package/dist/assets/chunk-GF5L2VYU-CKLZ3iVD.js +0 -206
  227. package/dist/assets/classDiagram-JCYQIIEL-Bpfe3kq7.js +0 -1
  228. package/dist/assets/classDiagram-v2-OCEON4UE-Bpfe3kq7.js +0 -1
  229. package/dist/assets/code-xml-CLpHzEOP.js +0 -6
  230. package/dist/assets/cose-bilkent-JH36ORCC-DlFcLXCB.js +0 -1
  231. package/dist/assets/cynefinDiagram-MW4NZA55-COgduz5P.js +0 -62
  232. package/dist/assets/cytoscape.esm-C10L9Icf.js +0 -331
  233. package/dist/assets/dagre-VZM6K2ZE-Bbb-siGp.js +0 -4
  234. package/dist/assets/diagram-LBJQPF4R-ErMC9yaa.js +0 -24
  235. package/dist/assets/diagram-Q27KOJAE-Dt_-C7hV.js +0 -24
  236. package/dist/assets/diagram-UB23O5K3-BJ1DnRAF.js +0 -41
  237. package/dist/assets/ebnfDiagram-BXEA7PRR-CE1YaQ9s.js +0 -1
  238. package/dist/assets/erDiagram-JOGREHBK-Bqk7N9aY.js +0 -85
  239. package/dist/assets/ganttDiagram-PKOTCBZU-CWYAUeYN.js +0 -292
  240. package/dist/assets/gitGraphDiagram-DS77QQ5N-tdEcEIM6.js +0 -106
  241. package/dist/assets/graph-Cx-EqisW.js +0 -1
  242. package/dist/assets/index-B-sTfSZq.js +0 -1
  243. package/dist/assets/index-B_FDMWar.js +0 -1174
  244. package/dist/assets/index-CWJtg2pR.js +0 -11
  245. package/dist/assets/index-t1w8KNxn.css +0 -1
  246. package/dist/assets/infoDiagram-6WML65LV-A3IqRUnO.js +0 -2
  247. package/dist/assets/ishikawaDiagram-WSZJBQD7-B2uL6bkK.js +0 -70
  248. package/dist/assets/journeyDiagram-NVQOT4AX-D9JB-hRW.js +0 -139
  249. package/dist/assets/map-CV9uif0g.js +0 -1
  250. package/dist/assets/mermaid.core-CQ698HNn.js +0 -312
  251. package/dist/assets/pegDiagram-VL7TDLO6-CO6vP4n9.js +0 -1
  252. package/dist/assets/quadrantDiagram-CIZ2JOQS-DgNxRz6t.js +0 -7
  253. package/dist/assets/railroadDiagram-AXF67PYL-DKz9UqA9.js +0 -1
  254. package/dist/assets/requirementDiagram-LRYGKXZP-L84XyGgV.js +0 -84
  255. package/dist/assets/sankeyDiagram-W5VNT64P-CQqWbJ3j.js +0 -40
  256. package/dist/assets/sequenceDiagram-SI44F4Z6--tnzS2tb.js +0 -162
  257. package/dist/assets/sizeCapture-X5ZJPWSS-DujwEOtm.js +0 -1
  258. package/dist/assets/stateDiagram-OKZ733FA-BK3TcZY2.js +0 -1
  259. package/dist/assets/stateDiagram-v2-UEYNNEHI-_medyomK.js +0 -1
  260. package/dist/assets/swimlanes-SLNWSIFB-naX-Uv1B.js +0 -2
  261. package/dist/assets/swimlanesDiagram-ULZ7WXOC-DstIv3TC.js +0 -8
  262. package/dist/assets/timeline-definition-Z64GVDOM-C-vP_ddU.js +0 -120
  263. package/dist/assets/vendor-react-whEHfigN.js +0 -59
  264. package/dist/assets/vennDiagram-T6HMQDX7-DN-I7o-7.js +0 -34
  265. package/dist/assets/xychartDiagram-ELKLHX3M-DE6OxW_p.js +0 -7
  266. package/dist/manifest.json +0 -61
@@ -0,0 +1 @@
1
+ import{r as a,j as t}from"./vendor-react-C2GTiUCy.js";import{c as ee,a5 as lt,a6 as at,a7 as st,a8 as it,f as U,I as Ne,B as z,a as ct,a9 as dt}from"./feature-workspace-X9kJZ4EG.js";import{Q as W,b4 as ce,$ as B,b5 as ge,b6 as be,ak as ye,S as A,b7 as de,b8 as te,b9 as we,ba as re,U as X,bb as je,a4 as Z,bc as ue,as as qe,bd as J,k as Y,be as ne,bf as le,bg as Q,w as ut,bh as H,bi as De,bj as ft,bk as Ie,ar as ae,a0 as se,J as Re,bl as pt,bm as mt,aO as ie,bn as Ae,bo as xt,bp as ht,bq as xe,aC as Le,r as Me,q as Ue,aa as Oe,l as ve,a1 as oe,R as Ce,t as gt,N as bt,F as Fe,T as Ke,b as Ze,L as Je,C as yt,ay as wt,a9 as jt,br as vt,X as Te,n as Ct,a2 as kt,o as Nt}from"./vendor-ui-CAUHSABu.js";import{J as Ft}from"./vendor-data-DsEZeNPr.js";import{u as V}from"./vendor-i18n-B6HjLCnN.js";import"./vendor-markdown-DkITEES2.js";const _e="w-4 h-4 flex-shrink-0",Pe={js:{icon:ae,color:"text-yellow-500"},jsx:{icon:ae,color:"text-yellow-500"},mjs:{icon:ae,color:"text-yellow-500"},cjs:{icon:ae,color:"text-yellow-500"},ts:{icon:se,color:"text-blue-500"},tsx:{icon:se,color:"text-blue-500"},mts:{icon:se,color:"text-blue-500"},py:{icon:xe,color:"text-emerald-500"},pyw:{icon:xe,color:"text-emerald-500"},pyi:{icon:xe,color:"text-emerald-400"},ipynb:{icon:ht,color:"text-orange-500"},rs:{icon:de,color:"text-orange-600"},toml:{icon:A,color:"text-gray-500"},go:{icon:ce,color:"text-cyan-500"},rb:{icon:je,color:"text-red-500"},erb:{icon:je,color:"text-red-400"},php:{icon:xt,color:"text-violet-500"},java:{icon:Ae,color:"text-red-600"},jar:{icon:Ae,color:"text-red-500"},kt:{icon:ce,color:"text-violet-500"},kts:{icon:ce,color:"text-violet-400"},c:{icon:ie,color:"text-blue-600"},h:{icon:ie,color:"text-blue-400"},cpp:{icon:ie,color:"text-blue-700"},hpp:{icon:ie,color:"text-blue-500"},cc:{icon:ie,color:"text-blue-700"},cs:{icon:ce,color:"text-purple-600"},swift:{icon:we,color:"text-orange-500"},lua:{icon:mt,color:"text-blue-500"},r:{icon:pt,color:"text-blue-600"},html:{icon:Re,color:"text-orange-600"},htm:{icon:Re,color:"text-orange-600"},css:{icon:te,color:"text-blue-500"},scss:{icon:te,color:"text-pink-500"},sass:{icon:te,color:"text-pink-400"},less:{icon:te,color:"text-indigo-500"},vue:{icon:se,color:"text-emerald-500"},svelte:{icon:se,color:"text-orange-500"},json:{icon:re,color:"text-yellow-600"},jsonc:{icon:re,color:"text-yellow-500"},json5:{icon:re,color:"text-yellow-500"},yaml:{icon:A,color:"text-purple-400"},yml:{icon:A,color:"text-purple-400"},xml:{icon:ae,color:"text-orange-500"},csv:{icon:Ie,color:"text-green-600"},tsv:{icon:Ie,color:"text-green-500"},sql:{icon:ft,color:"text-blue-500"},graphql:{icon:De,color:"text-pink-500"},gql:{icon:De,color:"text-pink-500"},proto:{icon:ue,color:"text-green-500"},env:{icon:Z,color:"text-yellow-600"},md:{icon:ye,color:"text-blue-500"},mdx:{icon:ye,color:"text-blue-400"},txt:{icon:B,color:"text-gray-500"},doc:{icon:B,color:"text-blue-600"},docx:{icon:B,color:"text-blue-600"},pdf:{icon:be,color:"text-red-600"},rtf:{icon:B,color:"text-gray-500"},tex:{icon:ge,color:"text-teal-600"},rst:{icon:B,color:"text-gray-400"},sh:{icon:X,color:"text-green-500"},bash:{icon:X,color:"text-green-500"},zsh:{icon:X,color:"text-green-400"},fish:{icon:X,color:"text-green-400"},ps1:{icon:X,color:"text-blue-400"},bat:{icon:X,color:"text-gray-500"},cmd:{icon:X,color:"text-gray-500"},png:{icon:H,color:"text-purple-500"},jpg:{icon:H,color:"text-purple-500"},jpeg:{icon:H,color:"text-purple-500"},gif:{icon:H,color:"text-purple-400"},webp:{icon:H,color:"text-purple-400"},ico:{icon:H,color:"text-purple-400"},bmp:{icon:H,color:"text-purple-400"},tiff:{icon:H,color:"text-purple-400"},svg:{icon:ut,color:"text-amber-500"},mp3:{icon:Q,color:"text-pink-500"},wav:{icon:Q,color:"text-pink-500"},ogg:{icon:Q,color:"text-pink-400"},flac:{icon:Q,color:"text-pink-400"},aac:{icon:Q,color:"text-pink-400"},m4a:{icon:Q,color:"text-pink-400"},mp4:{icon:le,color:"text-rose-500"},mov:{icon:le,color:"text-rose-500"},avi:{icon:le,color:"text-rose-500"},webm:{icon:le,color:"text-rose-400"},mkv:{icon:le,color:"text-rose-400"},ttf:{icon:ne,color:"text-red-500"},otf:{icon:ne,color:"text-red-500"},woff:{icon:ne,color:"text-red-400"},woff2:{icon:ne,color:"text-red-400"},eot:{icon:ne,color:"text-red-400"},zip:{icon:Y,color:"text-amber-600"},tar:{icon:Y,color:"text-amber-600"},gz:{icon:Y,color:"text-amber-600"},bz2:{icon:Y,color:"text-amber-600"},rar:{icon:Y,color:"text-amber-500"},"7z":{icon:Y,color:"text-amber-500"},lock:{icon:W,color:"text-gray-500"},exe:{icon:J,color:"text-gray-500"},bin:{icon:J,color:"text-gray-500"},dll:{icon:J,color:"text-gray-400"},so:{icon:J,color:"text-gray-400"},dylib:{icon:J,color:"text-gray-400"},wasm:{icon:J,color:"text-purple-500"},ini:{icon:A,color:"text-gray-500"},cfg:{icon:A,color:"text-gray-500"},conf:{icon:A,color:"text-gray-500"},log:{icon:ge,color:"text-gray-400"},map:{icon:qe,color:"text-gray-400"}},$e={Dockerfile:{icon:ue,color:"text-blue-500"},"docker-compose.yml":{icon:ue,color:"text-blue-500"},"docker-compose.yaml":{icon:ue,color:"text-blue-500"},".dockerignore":{icon:ue,color:"text-gray-500"},".gitignore":{icon:A,color:"text-gray-500"},".gitmodules":{icon:A,color:"text-gray-500"},".gitattributes":{icon:A,color:"text-gray-500"},".editorconfig":{icon:A,color:"text-gray-500"},".prettierrc":{icon:A,color:"text-pink-400"},".prettierignore":{icon:A,color:"text-gray-500"},".eslintrc":{icon:A,color:"text-violet-500"},".eslintrc.js":{icon:A,color:"text-violet-500"},".eslintrc.json":{icon:A,color:"text-violet-500"},".eslintrc.cjs":{icon:A,color:"text-violet-500"},"eslint.config.js":{icon:A,color:"text-violet-500"},"eslint.config.mjs":{icon:A,color:"text-violet-500"},".env":{icon:Z,color:"text-yellow-600"},".env.local":{icon:Z,color:"text-yellow-600"},".env.development":{icon:Z,color:"text-yellow-500"},".env.production":{icon:Z,color:"text-yellow-600"},".env.example":{icon:Z,color:"text-yellow-400"},"package.json":{icon:re,color:"text-green-500"},"package-lock.json":{icon:W,color:"text-gray-500"},"yarn.lock":{icon:W,color:"text-blue-400"},"pnpm-lock.yaml":{icon:W,color:"text-orange-400"},"bun.lockb":{icon:W,color:"text-gray-400"},"Cargo.toml":{icon:de,color:"text-orange-600"},"Cargo.lock":{icon:W,color:"text-orange-400"},Gemfile:{icon:je,color:"text-red-500"},"Gemfile.lock":{icon:W,color:"text-red-400"},Makefile:{icon:X,color:"text-gray-500"},"CMakeLists.txt":{icon:de,color:"text-blue-500"},"tsconfig.json":{icon:re,color:"text-blue-500"},"jsconfig.json":{icon:re,color:"text-yellow-500"},"vite.config.ts":{icon:we,color:"text-purple-500"},"vite.config.js":{icon:we,color:"text-purple-500"},"webpack.config.js":{icon:de,color:"text-blue-500"},"tailwind.config.js":{icon:te,color:"text-cyan-500"},"tailwind.config.ts":{icon:te,color:"text-cyan-500"},"postcss.config.js":{icon:de,color:"text-red-400"},"babel.config.js":{icon:A,color:"text-yellow-500"},".babelrc":{icon:A,color:"text-yellow-500"},"README.md":{icon:ye,color:"text-blue-500"},LICENSE:{icon:be,color:"text-gray-500"},"LICENSE.md":{icon:be,color:"text-gray-500"},"CHANGELOG.md":{icon:ge,color:"text-blue-400"},"requirements.txt":{icon:B,color:"text-emerald-400"},"go.mod":{icon:ce,color:"text-cyan-500"},"go.sum":{icon:W,color:"text-cyan-400"}};function Tt(e){if($e[e])return $e[e];if(e.startsWith(".env"))return{icon:Z,color:"text-yellow-600"};const r=e.split(".").pop()?.toLowerCase();return r&&Pe[r]?Pe[r]:{icon:qe,color:"text-muted-foreground"}}function Et(){const[e,r]=a.useState(()=>new Set),o=a.useCallback(s=>{r(u=>{const c=new Set(u);return c.has(s)?c.delete(s):c.add(s),c})},[]),l=a.useCallback(s=>{s.length!==0&&r(u=>{const c=new Set(u);return s.forEach(x=>c.add(x)),c})},[]),i=a.useCallback(()=>{r(new Set)},[]);return{expandedDirs:e,toggleDirectory:o,expandDirectories:l,collapseAll:i}}const ze="Unable to load the file tree for this project.";function St(e){try{const r=JSON.parse(e),o=typeof r=="object"&&r!==null&&"error"in r?r.error:null;return typeof o=="string"&&o.trim()?o:null}catch{return null}}function Dt(e){const[r,o]=a.useState([]),[l,i]=a.useState(!1),[s,u]=a.useState(null),[c,x]=a.useState(0),b=a.useRef(null),g=a.useCallback(()=>{x(v=>v+1)},[]);return a.useEffect(()=>{const v=e?.projectId;if(!v){o([]),i(!1),u(null);return}b.current&&b.current.abort(),b.current=new AbortController;let d=!0;return(async()=>{d&&(i(!0),u(null));try{const y=await ee.getFiles(v,{signal:b.current.signal});if(!y.ok){const N=await y.text();console.error("File fetch failed:",y.status,N),d&&(o([]),u(St(N)??ze));return}const E=await y.json();d&&o(E)}catch(y){if(y.name==="AbortError")return;console.error("Error fetching files:",y),d&&(o([]),u(ze))}finally{d&&i(!1)}})(),()=>{d=!1,b.current?.abort()}},[e?.projectId,c]),{files:r,loading:l,error:s,refreshFiles:g}}const It=/[<>:"/\\|?*\x00-\x1f]/,Rt=/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i;function At({selectedProject:e,onRefresh:r,showToast:o}){const{t:l}=V(),[i,s]=a.useState(null),[u,c]=a.useState(""),[x,b]=a.useState({isOpen:!1,item:null}),[g,v]=a.useState(!1),[d,f]=a.useState(""),[y,E]=a.useState("file"),[N,S]=a.useState(""),[L,D]=a.useState(!1),R=a.useCallback(m=>!m||!m.trim()?l("fileTree.validation.emptyName","Filename cannot be empty"):It.test(m)?l("fileTree.validation.invalidChars","Filename contains invalid characters"):Rt.test(m)?l("fileTree.validation.reserved","Filename is a reserved name"):/^\.+$/.test(m)?l("fileTree.validation.dotsOnly","Filename cannot be only dots"):null,[l]),M=a.useCallback(m=>{s(m),c(m.name),v(!1)},[]),h=a.useCallback(()=>{s(null),c("")},[]),n=a.useCallback(async()=>{if(!i||!e)return;const m=R(u);if(m){o(m,"error");return}if(u===i.name){h();return}D(!0);try{const k=await ee.renameFile(e.projectId,{oldPath:i.path,newName:u});if(!k.ok){const T=await k.json();throw new Error(T.error||"Failed to rename")}o(l("fileTree.toast.renamed","Renamed successfully"),"success"),r(),h()}catch(k){o(k.message,"error")}finally{D(!1)}},[i,u,e,R,o,l,r,h]),p=a.useCallback(m=>{b({isOpen:!0,item:m})},[]),w=a.useCallback(()=>{b({isOpen:!1,item:null})},[]),C=a.useCallback(async()=>{const{item:m}=x;if(!(!m||!e)){D(!0);try{const k=await ee.deleteFile(e.projectId,{path:m.path,type:m.type});if(!k.ok){const T=await k.json();throw new Error(T.error||"Failed to delete")}o(m.type==="directory"?l("fileTree.toast.folderDeleted","Folder deleted"):l("fileTree.toast.fileDeleted","File deleted"),"success"),r(),w()}catch(k){o(k.message,"error")}finally{D(!1)}}},[x,e,o,l,r,w]),F=a.useCallback((m,k)=>{f(m||""),E(k),S(k==="file"?"untitled.txt":"new-folder"),v(!0),s(null)},[]),I=a.useCallback(()=>{v(!1),f(""),S("")},[]),P=a.useCallback(async()=>{if(!e)return;const m=R(N);if(m){o(m,"error");return}D(!0);try{const k=await ee.createFile(e.projectId,{path:d,type:y,name:N});if(!k.ok){const T=await k.json();throw new Error(T.error||"Failed to create")}o(y==="file"?l("fileTree.toast.fileCreated","File created successfully"):l("fileTree.toast.folderCreated","Folder created successfully"),"success"),r(),I()}catch(k){o(k.message,"error")}finally{D(!1)}},[e,d,y,N,R,o,l,r,I]),G=a.useCallback(m=>{navigator.clipboard.writeText(m.path).catch(()=>{o(l("fileTree.toast.copyFailed","Failed to copy path"),"error")}),o(l("fileTree.toast.pathCopied","Path copied to clipboard"),"success")},[o,l]),_=a.useCallback((m,k)=>{const T=URL.createObjectURL(m),K=document.createElement("a");K.href=T,K.download=k,document.body.appendChild(K),K.click(),document.body.removeChild(K),URL.revokeObjectURL(T)},[]),O=a.useCallback(async m=>{if(!e)return;const k=await ee.readFileBlob(e.projectId,m.path);if(!k.ok)throw new Error("Failed to download file");const T=await k.blob();_(T,m.name)},[e,_]),q=a.useCallback(async m=>{if(!e)return;const k=new Ft,T=async($,Ee)=>{const Se=Ee?`${Ee}/${$.name}`:$.name;if($.type==="file"){const fe=await ee.readFileBlob(e.projectId,$.path);if(!fe.ok)throw new Error(`Failed to download "${$.name}" for ZIP export`);const nt=await fe.arrayBuffer();k.file(Se,nt)}else if($.type==="directory"&&$.children)for(const fe of $.children)await T(fe,Se)};if(m.children&&m.children.length>0)for(const $ of m.children)await T($,"");const K=await k.generateAsync({type:"blob"});_(K,`${m.name}.zip`),o(l("fileTree.toast.folderDownloaded","Folder downloaded as ZIP"),"success")},[e,o,l,_]),j=a.useCallback(async m=>{if(e){D(!0);try{m.type==="directory"?await q(m):await O(m)}catch(k){o(k.message,"error")}finally{D(!1)}}},[q,O,e,o]);return{renamingItem:i,renameValue:u,handleStartRename:M,handleCancelRename:h,handleConfirmRename:n,setRenameValue:c,deleteConfirmation:x,handleStartDelete:p,handleCancelDelete:w,handleConfirmDelete:C,isCreating:g,newItemParent:d,newItemType:y,newItemName:N,handleStartCreate:F,handleCancelCreate:I,handleConfirmCreate:P,setNewItemName:S,handleCopyPath:G,handleDownload:j,operationLoading:L,validateFilename:R}}const Be="file-tree-view-mode",Lt="detailed",Mt=["simple","compact","detailed"],Ye=200,Ut=Ye*1024*1024,ke=`${Ye}MB`,Ve=20,Ot=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function Qe(e,r){return e.reduce((o,l)=>{const i=l.name.toLowerCase().includes(r),s=l.type==="directory"&&l.children?Qe(l.children,r):[];return(i||s.length>0)&&o.push({...l,children:s}),o},[])}function _t(e){const r=[],o=l=>{l.forEach(i=>{i.type==="directory"&&i.children&&i.children.length>0&&(r.push(i.path),o(i.children))})};return o(e),r}function Pt(e){if(!e||e===0)return"0 B";const r=1024,o=["B","KB","MB","GB"],l=Math.floor(Math.log(e)/Math.log(r));return`${(e/Math.pow(r,l)).toFixed(1).replace(/\.0$/,"")} ${o[l]}`}function $t(e,r){if(!e)return"-";const o=new Date,l=new Date(e),i=Math.floor((o.getTime()-l.getTime())/1e3);return i<60?r("fileTree.justNow"):i<3600?r("fileTree.minAgo",{count:Math.floor(i/60)}):i<86400?r("fileTree.hoursAgo",{count:Math.floor(i/3600)}):i<2592e3?r("fileTree.daysAgo",{count:Math.floor(i/86400)}):l.toLocaleDateString()}function zt(e){const r=e.split(".").pop()?.toLowerCase();return!!(r&&Ot.has(r))}function Bt({files:e,expandDirectories:r}){const[o,l]=a.useState(""),[i,s]=a.useState(e);return a.useEffect(()=>{const u=o.trim().toLowerCase();if(!u){s(e);return}const c=Qe(e,u);s(c),r(_t(c))},[e,o,r]),{searchQuery:o,setSearchQuery:l,filteredFiles:i}}function Vt(){const[e,r]=a.useState(Lt);a.useEffect(()=>{try{const l=localStorage.getItem(Be);l&&Mt.includes(l)&&r(l)}catch{}},[]);const o=a.useCallback(l=>{r(l);try{localStorage.setItem(Be,l)}catch{}},[]);return{viewMode:e,changeViewMode:o}}const Gt=1400,Ht=3200,Ge=e=>e===1?"file":"files",et=e=>e.webkitRelativePath||e.name,tt=e=>et(e).split(/[\\/]/).pop()||e.name,Wt=e=>{if(e.length>Ve)return`You can upload up to ${Ve} files at once.`;const r=e.find(o=>o.size>Ut);return r?`${tt(r)} is larger than ${ke}.`:null},Xt=e=>{if(!e.responseText)return{};try{return JSON.parse(e.responseText)}catch{return{}}},qt=(e,r)=>e!==r?`Uploaded ${e} of ${r} ${Ge(r)}`:`Uploaded ${e} ${Ge(e)} successfully`,Kt=(e,r)=>{const o=new FormData,l=[];return o.append("targetPath",r),o.append("requestedFileCount",String(e.length)),e.forEach(i=>{const s=et(i),u=new File([i],s.split(/[\\/]/).pop()||i.name,{type:i.type,lastModified:i.lastModified});o.append("files",u),l.push(s)}),o.append("relativePaths",JSON.stringify(l)),o},Zt=(e,r,o)=>new Promise((l,i)=>{const s=new XMLHttpRequest;s.open("POST",`/api/file-tree/projects/${encodeURIComponent(e)}/files/upload`);const u=lt();!at&&u&&s.setRequestHeader("Authorization",`Bearer ${u}`),s.upload.onprogress=c=>{c.lengthComputable&&o(Math.min(99,Math.round(c.loaded/c.total*100)))},s.onload=()=>{const c=s.getResponseHeader("X-Refreshed-Token");c&&st(c),s.getResponseHeader("X-Auth-Error")&&it();const x=Xt(s);if(s.status>=200&&s.status<300){l(x);return}i(new Error(x.error||x.message||`Upload failed with status ${s.status}`))},s.onerror=()=>i(new Error("Upload failed. Check your connection and try again.")),s.onabort=()=>i(new Error("Upload canceled.")),s.send(r)}),rt=async(e,r="")=>{const o=[],l=e.createReader();let i=[],s;do s=await new Promise((c,x)=>{l.readEntries(c,x)}),i=i.concat(s);while(s.length>0);const u=[".DS_Store","Thumbs.db","desktop.ini"];for(const c of i){const x=r?`${r}/${c.name}`:c.name;if(c.isFile){const b=c,g=await new Promise((d,f)=>{b.file(d,f)});if(u.includes(g.name))continue;const v=new File([g],x,{type:g.type,lastModified:g.lastModified});o.push(v)}else if(c.isDirectory){const g=await rt(c,x);o.push(...g)}}return o},Jt=async e=>{const r=[],{items:o}=e;if(o){for(const l of Array.from(o)){if(l.kind!=="file")continue;const i=l.webkitGetAsEntry?l.webkitGetAsEntry():null;if(!i){const s=l.getAsFile();s&&r.push(s);continue}if(i.isFile){const s=await new Promise((u,c)=>{i.file(u,c)});r.push(s)}else if(i.isDirectory){const s=await rt(i,i.name);r.push(...s)}}return r}for(const l of Array.from(e.files))r.push(l);return r},Yt=({selectedProject:e,onRefresh:r,showToast:o})=>{const[l,i]=a.useState(!1),[s,u]=a.useState(null),[c,x]=a.useState(!1),[b,g]=a.useState(null),v=a.useRef(null),d=a.useRef(null),f=a.useCallback(()=>{d.current&&(clearTimeout(d.current),d.current=null)},[]),y=a.useCallback(n=>{f(),d.current=setTimeout(()=>{g(null),d.current=null},n)},[f]);a.useEffect(()=>f,[f]);const E=a.useCallback((n,p,w="",C,F=0)=>{g({status:"error",progress:F,fileCount:p,fileName:C,targetPath:w,error:n}),y(Ht)},[y]),N=a.useCallback(async(n,p="")=>{if(n.length===0){u(null);return}const w=n.length===1?tt(n[0]):void 0;if(!e){const I="Select a project before uploading files.";o(I,"error"),E(I,n.length,p,w);return}const C=Wt(n);if(C){o(C,"error"),E(C,n.length,p,w);return}f(),x(!0),g({status:"uploading",progress:0,fileCount:n.length,fileName:w,targetPath:p});let F=0;try{const I=await Zt(e.projectId,Kt(n,p),_=>{F=_,g(O=>O&&O.status==="uploading"?{...O,progress:_}:O)}),P=typeof I.uploadedCount=="number"?I.uploadedCount:I.files?.length??n.length,G=typeof I.requestedFileCount=="number"?I.requestedFileCount:n.length;g({status:"complete",progress:100,fileCount:G,uploadedCount:P,fileName:w,targetPath:p}),o(qt(P,G),"success"),y(Gt),r()}catch(I){const P=I instanceof Error?I.message:"Upload failed";console.error("Upload error:",I),o(P,"error"),E(P,n.length,p,w,F)}finally{x(!1),u(null)}},[f,r,y,e,E,o]),S=a.useCallback(async n=>{await N(Array.from(n),"")},[N]),L=a.useCallback(n=>{n.preventDefault(),n.stopPropagation(),i(!0)},[]),D=a.useCallback(n=>{n.preventDefault(),n.stopPropagation(),u(null)},[]),R=a.useCallback(n=>{n.preventDefault(),n.stopPropagation(),v.current&&!v.current.contains(n.relatedTarget)&&(i(!1),u(null))},[]),M=a.useCallback(async n=>{n.preventDefault(),n.stopPropagation(),i(!1);const p=s||"";try{const w=await Jt(n.dataTransfer);await N(w,p)}catch(w){const C=w instanceof Error?w.message:"Could not read dropped files";console.error("Upload error:",w),o(C,"error"),E(C,0,p),u(null)}},[s,E,o,N]),h=a.useCallback((n,p)=>{n.preventDefault(),n.stopPropagation(),u(p)},[]);return{isDragOver:l,dropTarget:s,operationLoading:c,uploadProgress:b,treeRef:v,uploadFiles:N,handleFileSelect:S,handleDragEnter:L,handleDragOver:D,handleDragLeave:R,handleDrop:M,handleItemDragOver:h,setDropTarget:u}};function he({icon:e,title:r,description:o}){return t.jsxs("div",{className:"py-8 text-center",children:[t.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-lg bg-muted",children:t.jsx(e,{className:"h-6 w-6 text-muted-foreground"})}),t.jsx("h4",{className:"mb-1 font-medium text-foreground",children:r}),t.jsx("p",{className:"text-sm text-muted-foreground",children:o})]})}const He=200,We=300,pe=10;function Qt(e,r){const o=e+He>window.innerWidth?window.innerWidth-He-pe:e,l=r+We>window.innerHeight?window.innerHeight-We-pe:r;return{x:Math.max(pe,o),y:Math.max(pe,l)}}function er({children:e,item:r,onRename:o,onDelete:l,onNewFile:i,onNewFolder:s,onUpload:u,onRefresh:c,onCopyPath:x,onDownload:b,isLoading:g=!1,className:v=""}){const{t:d}=V(),[f,y]=a.useState(!1),[E,N]=a.useState({x:0,y:0}),S=a.useRef(null),L=a.useCallback(()=>{y(!1)},[]),D=a.useCallback(h=>{h.preventDefault(),h.stopPropagation(),N(Qt(h.clientX,h.clientY)),y(!0)},[]),R=a.useCallback(h=>{L(),h?.()},[L]),M=a.useMemo(()=>r?.type==="file"?[{key:"rename",icon:Le,label:d("fileTree.context.rename","Rename"),onSelect:()=>o?.(r)},{key:"delete",icon:Me,label:d("fileTree.context.delete","Delete"),onSelect:()=>l?.(r),isDanger:!0},{key:"copyPath",icon:Ue,label:d("fileTree.context.copyPath","Copy Path"),onSelect:()=>x?.(r),showDividerBefore:!0},{key:"download",icon:Oe,label:d("fileTree.context.download","Download"),onSelect:()=>b?.(r)}]:r?.type==="directory"?[{key:"newFile",icon:B,label:d("fileTree.context.newFile","New File"),onSelect:()=>i?.(r.path)},{key:"newFolder",icon:ve,label:d("fileTree.context.newFolder","New Folder"),onSelect:()=>s?.(r.path)},{key:"upload",icon:oe,label:d("fileTree.context.upload","Upload Files"),onSelect:()=>u?.(r.path)},{key:"rename",icon:Le,label:d("fileTree.context.rename","Rename"),onSelect:()=>o?.(r),showDividerBefore:!0},{key:"delete",icon:Me,label:d("fileTree.context.delete","Delete"),onSelect:()=>l?.(r),isDanger:!0},{key:"copyPath",icon:Ue,label:d("fileTree.context.copyPath","Copy Path"),onSelect:()=>x?.(r),showDividerBefore:!0},{key:"download",icon:Oe,label:d("fileTree.context.download","Download"),onSelect:()=>b?.(r)}]:[{key:"newFile",icon:B,label:d("fileTree.context.newFile","New File"),onSelect:()=>i?.("")},{key:"newFolder",icon:ve,label:d("fileTree.context.newFolder","New Folder"),onSelect:()=>s?.("")},{key:"upload",icon:oe,label:d("fileTree.context.upload","Upload Files"),onSelect:()=>u?.("")},{key:"refresh",icon:Ce,label:d("fileTree.context.refresh","Refresh"),onSelect:c,showDividerBefore:!0}],[r,x,l,b,i,s,c,o,u,d]);return a.useEffect(()=>{if(!f)return;const h=p=>{const w=S.current;w&&!w.contains(p.target)&&L()},n=p=>{p.key==="Escape"&&L()};return document.addEventListener("mousedown",h),document.addEventListener("keydown",n),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",n)}},[L,f]),a.useEffect(()=>{if(!f)return;const h=n=>{const p=S.current?.querySelectorAll('[role="menuitem"]:not([disabled])');if(!p||p.length===0)return;const w=document.activeElement,C=Array.from(p).findIndex(F=>F===w);if(n.key==="ArrowDown"){n.preventDefault();const F=C<p.length-1?C+1:0;p[F]?.focus()}else if(n.key==="ArrowUp"){n.preventDefault();const F=C>0?C-1:p.length-1;p[F]?.focus()}else(n.key==="Enter"||n.key===" ")&&w?.hasAttribute("role")&&(n.preventDefault(),w.click())};return document.addEventListener("keydown",h),()=>{document.removeEventListener("keydown",h)}},[f]),t.jsxs(t.Fragment,{children:[t.jsx("div",{onContextMenu:D,className:U("contents",v),children:e}),f&&t.jsx("div",{ref:S,role:"menu","aria-label":d("fileTree.context.menuLabel","File context menu"),style:{position:"fixed",left:E.x,top:E.y,zIndex:9999},className:U("min-w-[180px] py-1 px-1","bg-popover border border-border rounded-lg shadow-lg","animate-in fade-in-0 zoom-in-95","data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95"),children:g?t.jsxs("div",{className:"flex items-center justify-center py-4",children:[t.jsx(Ce,{className:"h-4 w-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"ml-2 text-sm text-muted-foreground",children:d("fileTree.context.loading","Loading...")})]}):M.map(h=>t.jsxs(a.Fragment,{children:[h.showDividerBefore&&t.jsx("div",{className:"mx-2 my-1 h-px bg-border"}),t.jsxs("button",{role:"menuitem",tabIndex:h.isDisabled?-1:0,disabled:g||h.isDisabled,onClick:()=>R(h.onSelect),className:U("w-full flex items-center gap-3 px-3 py-2 text-sm text-left rounded-md transition-colors","focus:outline-none focus:bg-accent",h.isDisabled?"opacity-50 cursor-not-allowed":h.isDanger?"text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-950":"hover:bg-accent",g&&"pointer-events-none"),children:[h.icon&&t.jsx(h.icon,{className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{className:"flex-1",children:h.label}),h.shortcut&&t.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:h.shortcut})]})]},h.key))})]})}function tr(e){const r=e.split(/[\\/]/);return r.pop(),r.join("/")}function me({item:e,isOpen:r,renderFileIcon:o}){return e.type==="directory"?t.jsxs("span",{className:"flex flex-shrink-0 items-center gap-0.5",children:[t.jsx(gt,{className:U("w-3.5 h-3.5 text-muted-foreground/70 transition-transform duration-150",r&&"rotate-90")}),r?t.jsx(bt,{className:"h-4 w-4 flex-shrink-0 text-blue-500"}):t.jsx(Fe,{className:"h-4 w-4 flex-shrink-0 text-muted-foreground"})]}):t.jsx("span",{className:"ml-[18px] flex flex-shrink-0 items-center",children:o(e.name)})}function ot({item:e,level:r,viewMode:o,expandedDirs:l,onItemClick:i,renderFileIcon:s,formatFileSize:u,formatRelativeTime:c,onRename:x,onDelete:b,onNewFile:g,onNewFolder:v,onCopyPath:d,onDownload:f,onUpload:y,onRefresh:E,dropTarget:N,onItemDragOver:S,renamingItem:L,renameValue:D,setRenameValue:R,handleConfirmRename:M,handleCancelRename:h,renameInputRef:n,operationLoading:p}){const{t:w}=V(),C=e.type==="directory",F=C&&l.has(e.path),I=!!(C&&e.children&&e.children.length>0),P=L?.path===e.path,G=C?e.path:tr(e.path),_=C&&N===e.path,O=U("text-[13px] leading-tight truncate",C?"font-medium text-foreground":"text-foreground/90"),q=U(o==="detailed"?"group grid grid-cols-12 gap-2 py-[3px] pr-2 hover:bg-accent/60 cursor-pointer items-center rounded-sm transition-colors duration-100":o==="compact"?"group flex items-center justify-between py-[3px] pr-2 hover:bg-accent/60 cursor-pointer rounded-sm transition-colors duration-100":"group flex items-center gap-1.5 py-[3px] pr-2 cursor-pointer rounded-sm hover:bg-accent/60 transition-colors duration-100",C&&F&&"border-l-2 border-primary/30",C&&!F||!C?"border-l-2 border-transparent":"","relative",_&&"bg-blue-500/10 ring-1 ring-inset ring-blue-500/40");if(P&&R&&M&&h)return t.jsxs("div",{className:U(q,"bg-accent/30"),style:{paddingLeft:`${r*16+4}px`},onClick:T=>T.stopPropagation(),children:[t.jsx(me,{item:e,isOpen:F,renderFileIcon:s}),t.jsx(Ne,{ref:n,type:"text",value:D||"",onChange:T=>R(T.target.value),onKeyDown:T=>{T.stopPropagation(),T.key==="Enter"&&M(),T.key==="Escape"&&h()},onBlur:()=>{setTimeout(()=>{M()},100)},className:"h-6 flex-1 text-sm",disabled:p})]});const j=C&&y&&t.jsx("button",{type:"button",onClick:T=>{T.stopPropagation(),y(e.path)},title:w("fileTree.uploadToFolder",'Upload files to "{{folder}}"',{folder:e.name}),"aria-label":w("fileTree.uploadToFolder",'Upload files to "{{folder}}"',{folder:e.name}),className:U("absolute right-1 top-1/2 -translate-y-1/2 rounded p-1","bg-background/80 text-muted-foreground opacity-0 transition-opacity","group-hover:opacity-100 focus-visible:opacity-100 hover:bg-accent hover:text-foreground"),children:t.jsx(oe,{className:"h-3.5 w-3.5"})}),m=t.jsxs("div",{className:q,style:{paddingLeft:`${r*16+4}px`},onClick:()=>i(e),onDragOver:S?T=>S(T,G):void 0,children:[o==="detailed"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"col-span-5 flex min-w-0 items-center gap-1.5",children:[t.jsx(me,{item:e,isOpen:F,renderFileIcon:s}),t.jsx("span",{className:O,children:e.name})]}),t.jsx("div",{className:"col-span-2 text-sm tabular-nums text-muted-foreground",children:e.type==="file"?u(e.size):""}),t.jsx("div",{className:"col-span-3 text-sm text-muted-foreground",children:c(e.modified)}),t.jsx("div",{className:"col-span-2 font-mono text-sm text-muted-foreground",children:e.permissionsRwx||""})]}):o==="compact"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.jsx(me,{item:e,isOpen:F,renderFileIcon:s}),t.jsx("span",{className:O,children:e.name})]}),t.jsx("div",{className:"ml-2 flex flex-shrink-0 items-center gap-3 text-sm text-muted-foreground",children:e.type==="file"&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"tabular-nums",children:u(e.size)}),t.jsx("span",{className:"font-mono",children:e.permissionsRwx})]})})]}):t.jsxs(t.Fragment,{children:[t.jsx(me,{item:e,isOpen:F,renderFileIcon:s}),t.jsx("span",{className:O,children:e.name})]}),j]}),k=x||b||g||v||d||f||E;return t.jsxs("div",{className:"select-none",children:[k?t.jsx(er,{item:e,onRename:x,onDelete:b,onNewFile:g,onNewFolder:v,onUpload:y,onCopyPath:d,onDownload:f,onRefresh:E,children:m}):m,C&&F&&I&&t.jsxs("div",{className:"relative",children:[t.jsx("span",{className:"absolute bottom-0 top-0 border-l border-border/40",style:{left:`${r*16+14}px`},"aria-hidden":"true"}),e.children?.map(T=>t.jsx(ot,{item:T,level:r+1,viewMode:o,expandedDirs:l,onItemClick:i,renderFileIcon:s,formatFileSize:u,formatRelativeTime:c,onRename:x,onDelete:b,onNewFile:g,onNewFolder:v,onCopyPath:d,onDownload:f,onUpload:y,onRefresh:E,dropTarget:N,onItemDragOver:S,renamingItem:L,renameValue:D,setRenameValue:R,handleConfirmRename:M,handleCancelRename:h,renameInputRef:n,operationLoading:p},T.path))]})]})}function rr({items:e,viewMode:r,expandedDirs:o,onItemClick:l,renderFileIcon:i,formatFileSize:s,formatRelativeTime:u,onRename:c,onDelete:x,onNewFile:b,onNewFolder:g,onCopyPath:v,onDownload:d,onUpload:f,onRefresh:y,dropTarget:E,onItemDragOver:N,renamingItem:S,renameValue:L,setRenameValue:D,handleConfirmRename:R,handleCancelRename:M,renameInputRef:h,operationLoading:n}){return t.jsx("div",{children:e.map(p=>t.jsx(ot,{item:p,level:0,viewMode:r,expandedDirs:o,onItemClick:l,renderFileIcon:i,formatFileSize:s,formatRelativeTime:u,onRename:c,onDelete:x,onNewFile:b,onNewFolder:g,onCopyPath:v,onDownload:d,onUpload:f,onRefresh:y,dropTarget:E,onItemDragOver:N,renamingItem:S,renameValue:L,setRenameValue:D,handleConfirmRename:R,handleCancelRename:M,renameInputRef:h,operationLoading:n},p.path))})}function or({files:e,filteredFiles:r,error:o,searchQuery:l,viewMode:i,expandedDirs:s,onItemClick:u,renderFileIcon:c,formatFileSize:x,formatRelativeTime:b,onRename:g,onDelete:v,onNewFile:d,onNewFolder:f,onCopyPath:y,onDownload:E,onUpload:N,onRefresh:S,dropTarget:L,onItemDragOver:D,renamingItem:R,renameValue:M,setRenameValue:h,handleConfirmRename:n,handleCancelRename:p,renameInputRef:w,operationLoading:C}){const{t:F}=V();return t.jsx(t.Fragment,{children:o?t.jsx(he,{icon:Ke,title:F("fileTree.loadFailed"),description:o}):e.length===0?t.jsx(he,{icon:Fe,title:F("fileTree.noFilesFound"),description:F("fileTree.checkProjectPath")}):r.length===0&&l?t.jsx(he,{icon:Ze,title:F("fileTree.noMatchesFound"),description:F("fileTree.tryDifferentSearch")}):t.jsx(rr,{items:r,viewMode:i,expandedDirs:s,onItemClick:u,renderFileIcon:c,formatFileSize:x,formatRelativeTime:b,onRename:g,onDelete:v,onNewFile:d,onNewFolder:f,onCopyPath:y,onDownload:E,onUpload:N,onRefresh:S,dropTarget:L,onItemDragOver:D,renamingItem:R,renameValue:M,setRenameValue:h,handleConfirmRename:n,handleCancelRename:p,renameInputRef:w,operationLoading:C})})}function nr(){const{t:e}=V();return t.jsx("div",{className:"border-b border-border px-3 pb-1 pt-1.5",children:t.jsxs("div",{className:"grid grid-cols-12 gap-2 px-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground/70",children:[t.jsx("div",{className:"col-span-5",children:e("fileTree.name")}),t.jsx("div",{className:"col-span-2",children:e("fileTree.size")}),t.jsx("div",{className:"col-span-3",children:e("fileTree.modified")}),t.jsx("div",{className:"col-span-2",children:e("fileTree.permissions")})]})})}function lr({viewMode:e,onViewModeChange:r,searchQuery:o,onSearchQueryChange:l,onNewFile:i,onNewFolder:s,onUploadFiles:u,onRefresh:c,onCollapseAll:x,loading:b,operationLoading:g,isUploading:v,uploadProgress:d}){const{t:f}=V(),y=a.useRef(null),E=N=>{const{files:S}=N.target;S&&S.length>0&&u?.(S),N.target.value=""};return t.jsxs("div",{className:"space-y-2 border-b border-border px-3 pb-2 pt-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h3",{className:"text-sm font-medium text-foreground",children:f("fileTree.files")}),t.jsxs("div",{className:"flex items-center gap-0.5",children:[u&&t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:E,tabIndex:-1,"aria-hidden":"true"}),t.jsxs(z,{variant:"ghost",size:"sm",className:"relative h-7 w-7 p-0",onClick:()=>y.current?.click(),title:v?f("fileTree.uploadingFiles","Uploading files"):f("fileTree.uploadFiles","Upload files (max {{size}} each)",{size:ke}),"aria-label":f("fileTree.uploadFiles","Upload files (max {{size}} each)",{size:ke}),disabled:g,children:[v?t.jsx(Je,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(oe,{className:"h-3.5 w-3.5"}),v&&typeof d=="number"&&t.jsx("span",{className:"absolute bottom-0.5 left-1/2 h-0.5 w-4 -translate-x-1/2 overflow-hidden rounded-full bg-primary/20",children:t.jsx("span",{className:"block h-full rounded-full bg-primary transition-[width] duration-150",style:{width:`${d}%`}})})]})]}),i&&t.jsx(z,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:i,title:f("fileTree.newFile","New File (Cmd+N)"),"aria-label":f("fileTree.newFile","New File (Cmd+N)"),disabled:g,children:t.jsx(B,{className:"h-3.5 w-3.5"})}),s&&t.jsx(z,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:s,title:f("fileTree.newFolder","New Folder (Cmd+Shift+N)"),"aria-label":f("fileTree.newFolder","New Folder (Cmd+Shift+N)"),disabled:g,children:t.jsx(ve,{className:"h-3.5 w-3.5"})}),c&&t.jsx(z,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:c,title:f("fileTree.refresh","Refresh"),"aria-label":f("fileTree.refresh","Refresh"),disabled:g,children:t.jsx(Ce,{className:U("w-3.5 h-3.5",b&&"animate-spin")})}),x&&t.jsx(z,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:x,title:f("fileTree.collapseAll","Collapse All"),"aria-label":f("fileTree.collapseAll","Collapse All"),children:t.jsx(yt,{className:"h-3.5 w-3.5"})}),t.jsx("div",{className:"mx-0.5 h-4 w-px bg-border"}),t.jsx(z,{variant:e==="simple"?"default":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>r("simple"),title:f("fileTree.simpleView"),"aria-label":f("fileTree.simpleView"),children:t.jsx(wt,{className:"h-3.5 w-3.5"})}),t.jsx(z,{variant:e==="compact"?"default":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>r("compact"),title:f("fileTree.compactView"),"aria-label":f("fileTree.compactView"),children:t.jsx(jt,{className:"h-3.5 w-3.5"})}),t.jsx(z,{variant:e==="detailed"?"default":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>r("detailed"),title:f("fileTree.detailedView"),"aria-label":f("fileTree.detailedView"),children:t.jsx(vt,{className:"h-3.5 w-3.5"})})]})]}),t.jsxs("div",{className:"relative",children:[t.jsx(Ze,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(Ne,{type:"text",placeholder:f("fileTree.searchPlaceholder"),value:o,onChange:N=>l(N.target.value),className:"h-8 pl-8 pr-8 text-sm"}),o&&t.jsx(z,{variant:"ghost",size:"sm",className:"absolute right-0.5 top-1/2 h-5 w-5 -translate-y-1/2 p-0 hover:bg-accent",onClick:()=>l(""),title:f("fileTree.clearSearch"),"aria-label":f("fileTree.clearSearch"),children:t.jsx(Te,{className:"h-3 w-3"})})]})]})}function ar(){const{t:e}=V();return t.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsx("div",{className:"text-sm text-muted-foreground",children:e("fileTree.loading")})})}const sr=e=>Math.min(100,Math.max(0,e)),Xe=e=>e===1?"file":"files";function ir({upload:e}){const{t:r}=V();if(!e)return null;const o=sr(e.progress),l=e.status==="uploading",i=e.status==="complete",s=e.status==="error",u=e.fileCount===1&&e.fileName?e.fileName:`${e.fileCount} ${Xe(e.fileCount)}`,c=l?r("fileTree.uploadingFiles","Uploading files"):i?r("fileTree.uploadComplete","Upload complete"):r("fileTree.uploadFailed","Upload failed"),x=s?e.error:i&&typeof e.uploadedCount=="number"?r("fileTree.uploadedCount","Uploaded {{uploaded}} of {{total}} {{label}}",{uploaded:e.uploadedCount,total:e.fileCount,label:Xe(e.fileCount)}):u,b=s?Ct:i?kt:oe;return t.jsxs("div",{className:U("border-b px-3 py-2 transition-colors",s?"border-red-500/20 bg-red-500/10 text-red-700 dark:text-red-300":i?"border-emerald-500/20 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300":"border-primary/20 bg-primary/10 text-foreground"),children:[t.jsxs("div",{className:"flex min-h-[36px] items-center gap-2",children:[t.jsx("div",{className:U("flex h-7 w-7 shrink-0 items-center justify-center rounded-md",s?"bg-red-500/15":i?"bg-emerald-500/15":"bg-primary/15"),children:t.jsx(b,{className:U("h-3.5 w-3.5",l&&"animate-pulse")})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("span",{className:"truncate text-xs font-medium",children:c}),t.jsx("span",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:l?`${o}%`:i?r("common.done","Done"):r("common.failed","Failed")})]}),t.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground",children:x})]})]}),t.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full bg-background/80",children:t.jsx("div",{className:U("h-full rounded-full transition-[width] duration-200",s?"bg-red-500":i?"bg-emerald-500":"bg-primary"),style:{width:`${s?Math.max(o,8):o}%`}})})]})}function cr({file:e,onClose:r}){const o=`/api/file-tree/projects/${e.projectId}/files/content?path=${encodeURIComponent(e.path)}`,[l,i]=a.useState(null),[s,u]=a.useState(null),[c,x]=a.useState(!0);return a.useEffect(()=>{let b=null;const g=new AbortController;return(async()=>{try{x(!0),u(null),i(null);const d=await ct(o,{signal:g.signal});if(!d.ok)throw new Error(`Request failed with status ${d.status}`);const f=await d.blob();b=URL.createObjectURL(f),i(b)}catch(d){if(d instanceof Error&&d.name==="AbortError")return;console.error("Error loading image:",d),u("Unable to load image")}finally{x(!1)}})(),()=>{g.abort(),b&&URL.revokeObjectURL(b)}},[o]),t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50",children:t.jsxs("div",{className:"mx-4 max-h-[90vh] w-full max-w-4xl overflow-hidden rounded-lg bg-white shadow-xl dark:bg-gray-800",children:[t.jsxs("div",{className:"flex items-center justify-between border-b p-4",children:[t.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:e.name}),t.jsx(z,{variant:"ghost",size:"sm",onClick:r,className:"h-8 w-8 p-0",children:t.jsx(Te,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"flex min-h-[400px] items-center justify-center bg-gray-50 p-4 dark:bg-gray-900",children:[c&&t.jsx("div",{className:"text-center text-gray-500 dark:text-gray-400",children:t.jsx("p",{children:"Loading image..."})}),!c&&l&&t.jsx("img",{src:l,alt:e.name,className:"max-h-[70vh] max-w-full rounded-lg object-contain shadow-md"}),!c&&!l&&t.jsxs("div",{className:"text-center text-gray-500 dark:text-gray-400",children:[t.jsx("p",{children:s||"Unable to load image"}),t.jsx("p",{className:"mt-2 break-all text-sm",children:e.path})]})]}),t.jsx("div",{className:"border-t bg-gray-50 p-4 dark:bg-gray-800",children:t.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:e.path})})]})})}function hr({selectedProject:e,onFileOpen:r}){const{t:o}=V(),[l,i]=a.useState(null),[s,u]=a.useState(null),c=a.useRef(null),x=a.useRef(null),b=a.useCallback((j,m)=>{u({message:j,type:m})},[]);a.useEffect(()=>{if(s){const j=setTimeout(()=>u(null),3e3);return()=>clearTimeout(j)}},[s]);const{files:g,loading:v,error:d,refreshFiles:f}=Dt(e),{viewMode:y,changeViewMode:E}=Vt(),{expandedDirs:N,toggleDirectory:S,expandDirectories:L,collapseAll:D}=Et(),{searchQuery:R,setSearchQuery:M,filteredFiles:h}=Bt({files:g,expandDirectories:L}),n=At({selectedProject:e,onRefresh:f,showToast:b}),p=Yt({selectedProject:e,onRefresh:f,showToast:b}),w=n.operationLoading||p.operationLoading,C=a.useRef(null),F=a.useRef(""),{uploadFiles:I}=p,P=a.useCallback(j=>{F.current=j,C.current?.click()},[]),G=a.useCallback(j=>{const{files:m}=j.target;m&&m.length>0&&I(Array.from(m),F.current),j.target.value=""},[I]);a.useEffect(()=>{n.isCreating&&c.current&&(c.current.focus(),c.current.select())},[n.isCreating]),a.useEffect(()=>{n.renamingItem&&x.current&&(x.current.focus(),x.current.select())},[n.renamingItem]);const _=a.useCallback(j=>{const{icon:m,color:k}=Tt(j);return t.jsx(m,{className:U(_e,k)})},[]),O=a.useCallback(j=>{if(j.type==="directory"){S(j.path);return}if(zt(j.name)&&e){i({name:j.name,path:j.path,projectPath:e.path,projectId:e.projectId});return}r?.(j.path)},[r,e,S]),q=a.useCallback(j=>$t(j,o),[o]);return v?t.jsx(ar,{}):t.jsxs("div",{ref:p.treeRef,className:"relative flex h-full flex-col bg-background",onDragEnter:p.handleDragEnter,onDragOver:p.handleDragOver,onDragLeave:p.handleDragLeave,onDrop:p.handleDrop,children:[t.jsx("input",{ref:C,type:"file",multiple:!0,className:"hidden",onChange:G,tabIndex:-1,"aria-hidden":"true"}),p.isDragOver&&t.jsx("div",{className:"pointer-events-none absolute inset-0 z-50 flex items-center justify-center border-2 border-dashed border-blue-500 bg-blue-500/10",children:t.jsxs("div",{className:"flex items-center gap-3 rounded-lg bg-background/95 px-6 py-4 shadow-lg",children:[t.jsx(oe,{className:"h-6 w-6 text-blue-500"}),t.jsx("span",{className:"text-sm font-medium",children:p.dropTarget?o("fileTree.dropToUploadTo",'Drop files to upload to "{{folder}}"',{folder:p.dropTarget.split(/[\\/]/).pop()}):o("fileTree.dropToUpload","Drop files to upload")})]})}),t.jsx(lr,{viewMode:y,onViewModeChange:E,searchQuery:R,onSearchQueryChange:M,onUploadFiles:p.handleFileSelect,onNewFile:()=>n.handleStartCreate("","file"),onNewFolder:()=>n.handleStartCreate("","directory"),onRefresh:f,onCollapseAll:D,loading:v,operationLoading:w,isUploading:p.uploadProgress?.status==="uploading",uploadProgress:p.uploadProgress?.progress??null}),t.jsx(ir,{upload:p.uploadProgress}),y==="detailed"&&h.length>0&&t.jsx(nr,{}),t.jsxs(dt,{className:"flex-1 px-2 py-1",children:[n.isCreating&&t.jsxs("div",{className:"mb-1 flex items-center gap-1.5 py-[3px] pr-2",style:{paddingLeft:`${(n.newItemParent.split("/").length-1)*16+4}px`},children:[n.newItemType==="directory"?t.jsx(Fe,{className:U(_e,"text-blue-500")}):t.jsx("span",{className:"ml-[18px]",children:_(n.newItemName)}),t.jsx(Ne,{ref:c,type:"text",value:n.newItemName,onChange:j=>n.setNewItemName(j.target.value),onKeyDown:j=>{j.stopPropagation(),j.key==="Enter"&&n.handleConfirmCreate(),j.key==="Escape"&&n.handleCancelCreate()},onBlur:()=>{setTimeout(()=>{n.isCreating&&n.handleConfirmCreate()},100)},className:"h-6 flex-1 text-sm",disabled:w})]}),t.jsx(or,{files:g,filteredFiles:h,error:d,searchQuery:R,viewMode:y,expandedDirs:N,onItemClick:O,renderFileIcon:_,formatFileSize:Pt,formatRelativeTime:q,onRename:n.handleStartRename,onDelete:n.handleStartDelete,onNewFile:j=>n.handleStartCreate(j,"file"),onNewFolder:j=>n.handleStartCreate(j,"directory"),onCopyPath:n.handleCopyPath,onDownload:n.handleDownload,onUpload:P,onRefresh:f,dropTarget:p.dropTarget,onItemDragOver:p.handleItemDragOver,renamingItem:n.renamingItem,renameValue:n.renameValue,setRenameValue:n.setRenameValue,handleConfirmRename:n.handleConfirmRename,handleCancelRename:n.handleCancelRename,renameInputRef:x,operationLoading:w})]}),l&&t.jsx(cr,{file:l,onClose:()=>i(null)}),n.deleteConfirmation.isOpen&&n.deleteConfirmation.item&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/50",children:t.jsxs("div",{className:"mx-4 max-w-sm rounded-lg border border-border bg-background p-4 shadow-lg",children:[t.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[t.jsx("div",{className:"rounded-full bg-red-100 p-2 dark:bg-red-900/30",children:t.jsx(Ke,{className:"h-5 w-5 text-red-600 dark:text-red-400"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"font-medium text-foreground",children:o("fileTree.delete.title","Delete {{type}}",{type:n.deleteConfirmation.item.type==="directory"?"Folder":"File"})}),t.jsx("p",{className:"text-sm text-muted-foreground",children:n.deleteConfirmation.item.name})]})]}),t.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:n.deleteConfirmation.item.type==="directory"?o("fileTree.delete.folderWarning","This folder and all its contents will be permanently deleted."):o("fileTree.delete.fileWarning","This file will be permanently deleted.")}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:n.handleCancelDelete,disabled:w,className:"rounded-md px-3 py-1.5 text-sm transition-colors hover:bg-accent",children:o("common.cancel","Cancel")}),t.jsxs("button",{onClick:n.handleConfirmDelete,disabled:w,className:"flex items-center gap-2 rounded-md bg-red-600 px-3 py-1.5 text-sm text-white transition-colors hover:bg-red-700 disabled:opacity-50",children:[w&&t.jsx(Je,{className:"h-4 w-4 animate-spin"}),o("fileTree.delete.confirm","Delete")]})]})]})}),s&&t.jsxs("div",{className:U("fixed bottom-4 right-4 z-[9999] px-4 py-2 rounded-lg shadow-lg flex items-center gap-2 animate-in slide-in-from-bottom-2",s.type==="success"?"bg-green-600 text-white":"bg-red-600 text-white"),children:[s.type==="success"?t.jsx(Nt,{className:"h-4 w-4"}):t.jsx(Te,{className:"h-4 w-4"}),t.jsx("span",{className:"text-sm",children:s.message})]})]})}export{hr as default};
@@ -0,0 +1,4 @@
1
+ import{r as n,j as e}from"./vendor-react-C2GTiUCy.js";import{a as Z}from"./feature-workspace-X9kJZ4EG.js";import{bs as Te,C as xe,o as fe,t as Re,r as oe,I as ht,R as V,G as P,bt as ft,bu as Ke,h as he,b as Xe,X as Ne,J as pt,av as gt,bv as Ye,bw as we,bx as bt,by as yt,a1 as Fe,aa as Ze,u as Pe,n as jt,L as Nt,$ as wt,T as vt}from"./vendor-ui-CAUHSABu.js";import"./vendor-i18n-B6HjLCnN.js";import"./vendor-data-DsEZeNPr.js";import"./vendor-markdown-DkITEES2.js";const Ct="main",kt=50,et=[{key:"modified",status:"M"},{key:"added",status:"A"},{key:"deleted",status:"D"},{key:"untracked",status:"U"}],St={M:"Modified",A:"Added",D:"Deleted",U:"Untracked"},Be={M:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/40 dark:text-yellow-300 border-yellow-200 dark:border-yellow-800/50",A:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300 border-green-200 dark:border-green-800/50",D:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300 border-red-200 dark:border-red-800/50",U:"bg-muted text-muted-foreground border-border"},$t={discard:"Discard Changes",delete:"Delete File",commit:"Confirm Action",pull:"Confirm Pull",push:"Confirm Push",publish:"Publish Branch",revertLocalCommit:"Revert Local Commit",deleteBranch:"Delete Branch"},Et={discard:"Discard",delete:"Delete",commit:"Confirm",pull:"Pull",push:"Push",publish:"Publish",revertLocalCommit:"Revert Commit",deleteBranch:"Delete"},It={discard:"bg-red-600 hover:bg-red-700",delete:"bg-red-600 hover:bg-red-700",commit:"bg-primary hover:bg-primary/90",pull:"bg-green-600 hover:bg-green-700",push:"bg-orange-600 hover:bg-orange-700",publish:"bg-purple-600 hover:bg-purple-700",revertLocalCommit:"bg-yellow-600 hover:bg-yellow-700",deleteBranch:"bg-red-600 hover:bg-red-700"},Tt={discard:"bg-red-100 dark:bg-red-900/30",delete:"bg-red-100 dark:bg-red-900/30",commit:"bg-yellow-100 dark:bg-yellow-900/30",pull:"bg-yellow-100 dark:bg-yellow-900/30",push:"bg-yellow-100 dark:bg-yellow-900/30",publish:"bg-yellow-100 dark:bg-yellow-900/30",revertLocalCommit:"bg-yellow-100 dark:bg-yellow-900/30",deleteBranch:"bg-red-100 dark:bg-red-900/30"};function Ae(t){return t?et.flatMap(({key:r})=>t[r]||[]):[]}function tt(t){return Ae(t).length}function We(t){return tt(t)>0}function Ft(t){return St[t]||t}function De(t){return Be[t]||Be.U}function Lt(t){const r=[],s=t.split(/^diff --git /m).slice(1);for(const a of s){const o=a.split(`
2
+ `),i=(o[0]??"").match(/^a\/(.+?) b\/(.+)/);if(!i)continue;const g=i[1],x=i[2];let m="M";const f=o.slice(0,6).join(`
3
+ `);f.includes("new file mode")?m="A":f.includes("deleted file mode")&&(m="D");const v=m==="D"?g:x;let y=0,p=0;for(const h of o)h.startsWith("+++")||h.startsWith("---")||(h.startsWith("+")?y++:h.startsWith("-")&&p++);const j=v.lastIndexOf("/"),u=j>=0?v.substring(0,j+1):"",N=j>=0?v.substring(j+1):v;r.push({path:v,directory:u,filename:N,status:m,insertions:y,deletions:p})}return{files:r,totalFiles:r.length,totalInsertions:r.reduce((a,o)=>a+o.insertions,0),totalDeletions:r.reduce((a,o)=>a+o.deletions,0)}}function Rt(){const[t,r]=n.useState(()=>localStorage.getItem("selected-provider")||"claude");return n.useEffect(()=>{const s=()=>{const a=localStorage.getItem("selected-provider")||"claude";r(a)};return window.addEventListener("storage",s),()=>window.removeEventListener("storage",s)},[]),t}const W=Z;function Me(t){return t instanceof DOMException&&t.name==="AbortError"}async function O(t,r){if(r?.aborted)throw new DOMException("Request aborted","AbortError");const s=await t.json();if(r?.aborted)throw new DOMException("Request aborted","AbortError");return s}function At({selectedProject:t,activeView:r,onFileOpen:s}){const[a,o]=n.useState(null),[d,i]=n.useState({}),[g,x]=n.useState(!1),[m,f]=n.useState(""),[v,y]=n.useState([]),[p,j]=n.useState([]),[u,N]=n.useState(!1),[h,T]=n.useState(!1),[I,B]=n.useState({}),[M,w]=n.useState(null),[$,k]=n.useState([]),[L,S]=n.useState([]),[R,z]=n.useState(!1),[H,Y]=n.useState(!1),[_,C]=n.useState(!1),[A,J]=n.useState(!1),[Q,se]=n.useState(!1),[ie,ne]=n.useState(!1),[le,D]=n.useState(!1),[K,G]=n.useState(null),ve=n.useCallback(()=>G(null),[]),X=n.useRef(t?.projectId??null);n.useEffect(()=>{X.current=t?.projectId??null},[t]);const pe=Rt(),ge=n.useCallback(async(c,l)=>{if(!t)return;const b=t.projectId;try{const F=await W(`/api/git/diff?project=${encodeURIComponent(b)}&file=${encodeURIComponent(c)}`,{signal:l}),ye=await O(F,l);if(l?.aborted||X.current!==b)return;!ye.error&&ye.diff&&i(Ee=>({...Ee,[c]:ye.diff}))}catch(F){if(l?.aborted||Me(F))return;console.error("Error fetching file diff:",F)}},[t]),E=n.useCallback(async c=>{if(!t)return;const l=t.projectId;x(!0);try{const b=await W(`/api/git/status?project=${encodeURIComponent(l)}`,{signal:c}),F=await O(b,c);if(c?.aborted||X.current!==l)return;if(F.error){F.notGitRepository||console.error("Git status error:",F.error),o({error:F.error,details:F.details,notGitRepository:F.notGitRepository}),f("");return}o(F),f(F.branch||Ct),Ae(F).forEach(Ee=>{ge(Ee,c)})}catch(b){if(c?.aborted||Me(b)||X.current!==l)return;console.error("Error fetching git status:",b),o({error:"Git operation failed",details:String(b)}),f("")}finally{x(!1)}},[ge,t]),q=n.useCallback(async()=>{if(t)try{const c=await W(`/api/git/branches?project=${encodeURIComponent(t.projectId)}`),l=await O(c);if(!l.error&&l.branches){y(l.branches),k(l.localBranches??l.branches),S(l.remoteBranches??[]);return}y([]),k([]),S([])}catch(c){console.error("Error fetching branches:",c),y([]),k([]),S([])}},[t]),U=n.useCallback(async()=>{if(t)try{const c=await W(`/api/git/remote-status?project=${encodeURIComponent(t.projectId)}`),l=await O(c);if(!l.error){w(l);return}w(null)}catch(c){console.error("Error fetching remote status:",c),w(null)}},[t]),Ce=n.useCallback(async c=>{if(!t)return!1;try{const l=await W("/api/git/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:c})}),b=await O(l);return b.success?(f(c),E(),!0):(console.error("Failed to switch branch:",b.error),!1)}catch(l){return console.error("Error switching branch:",l),!1}},[E,t]),ke=n.useCallback(async c=>{const l=c.trim();if(!t||!l)return!1;z(!0);try{const b=await W("/api/git/create-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:l})}),F=await O(b);return F.success?(f(l),q(),E(),!0):(console.error("Failed to create branch:",F.error),!1)}catch(b){return console.error("Error creating branch:",b),!1}finally{z(!1)}},[q,E,t]),Se=n.useCallback(async(c,l=!1)=>{if(!t)return!1;try{const b=await W("/api/git/delete-branch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:c,force:l})}),F=await O(b);return F.success?(q(),!0):(G(F.error??"Delete branch failed"),!1)}catch(b){return G(b instanceof Error?b.message:"Delete branch failed"),!1}},[q,t]),$e=n.useCallback(async()=>{if(t){Y(!0);try{const c=await W("/api/git/fetch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success){E(),U(),q();return}G(l.error??"Fetch failed")}catch(c){G(c instanceof Error?c.message:"Fetch failed")}finally{Y(!1)}}},[q,E,U,t]),ce=n.useCallback(async()=>{if(t){C(!0);try{const c=await W("/api/git/pull",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success){E(),U();return}G(l.error??"Pull failed")}catch(c){G(c instanceof Error?c.message:"Pull failed")}finally{C(!1)}}},[E,U,t]),de=n.useCallback(async()=>{if(t){J(!0);try{const c=await W("/api/git/push",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success){E(),U();return}G(l.error??"Push failed")}catch(c){G(c instanceof Error?c.message:"Push failed")}finally{J(!1)}}},[E,U,t]),me=n.useCallback(async()=>{if(t){se(!0);try{const c=await W("/api/git/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,branch:m})}),l=await O(c);if(l.success){E(),U();return}console.error("Publish failed:",l.error)}catch(c){console.error("Error publishing branch:",c)}finally{se(!1)}}},[m,E,U,t]),be=n.useCallback(async c=>{if(t)try{const l=await W("/api/git/discard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,file:c})}),b=await O(l);if(b.success){E();return}console.error("Discard failed:",b.error)}catch(l){console.error("Error discarding changes:",l)}},[E,t]),nt=n.useCallback(async c=>{if(t)try{const l=await W("/api/git/delete-untracked",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,file:c})}),b=await O(l);if(b.success){E();return}console.error("Delete failed:",b.error)}catch(l){console.error("Error deleting untracked file:",l)}},[E,t]),at=n.useCallback(async c=>{if(!t||c.length===0)return!1;try{const l=await W("/api/git/stage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,files:c})}),b=await O(l);return b.success?(await E(),!0):(G(b.error??"Stage failed"),!1)}catch(l){return G(l instanceof Error?l.message:"Stage failed"),!1}},[E,t]),ot=n.useCallback(async c=>{if(!t||c.length===0)return!1;try{const l=await W("/api/git/unstage",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,files:c})}),b=await O(l);return b.success?(await E(),!0):(G(b.error??"Unstage failed"),!1)}catch(l){return G(l instanceof Error?l.message:"Unstage failed"),!1}},[E,t]),Oe=n.useCallback(async()=>{if(!t)return;const c=t.projectId;N(!0);try{const l=await W(`/api/git/commits?project=${encodeURIComponent(c)}&limit=${kt}`),b=await O(l);if(X.current!==c)return;!b.error&&b.commits&&j(b.commits)}catch(l){console.error("Error fetching commits:",l)}finally{X.current===c&&(N(!1),T(!0))}},[t]),it=n.useCallback(async c=>{if(t)try{const l=await W(`/api/git/commit-diff?project=${encodeURIComponent(t.projectId)}&commit=${c}`),b=await O(l);!b.error&&b.diff&&B(F=>({...F,[c]:b.diff}))}catch(l){console.error("Error fetching commit diff:",l)}},[t]),lt=n.useCallback(async c=>{if(!t||c.length===0)return null;try{const l=await Z("/api/git/generate-commit-message",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,files:c,provider:pe})}),b=await O(l);return b.message?b.message:(console.error("Failed to generate commit message:",b.error),null)}catch(l){return console.error("Error generating commit message:",l),null}},[pe,t]),ct=n.useCallback(async(c,l)=>{if(!t||!c.trim()||l.length===0)return!1;try{const b=await W("/api/git/commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,message:c,files:l})}),F=await O(b);return F.success?(E(),U(),!0):(console.error("Commit failed:",F.error),!1)}catch(b){return console.error("Error committing changes:",b),!1}},[E,U,t]),dt=n.useCallback(async()=>{if(!t)throw new Error("No project selected");ne(!0);try{const c=await W("/api/git/initial-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId})}),l=await O(c);if(l.success)return E(),U(),!0;throw new Error(l.error||"Failed to create initial commit")}catch(c){throw console.error("Error creating initial commit:",c),c}finally{ne(!1)}},[E,U,t]),mt=n.useCallback(async()=>{if(!t)return!1;const c=t.projectId;D(!0);try{const l=await W("/api/git/init",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:c})}),b=await O(l);return X.current!==c?!1:b.success?(E(),q(),U(),!0):(G(b.error??"Failed to initialize repository"),!1)}catch(l){return X.current===c&&G(l instanceof Error?l.message:"Failed to initialize repository"),!1}finally{D(!1)}},[q,E,U,t]),ut=n.useCallback(async c=>{if(s){if(!t){s(c);return}try{const l=await W(`/api/git/file-with-diff?project=${encodeURIComponent(t.projectId)}&file=${encodeURIComponent(c)}`),b=await O(l);if(b.error){console.error("Error fetching file with diff:",b.error),s(c);return}s(c,{old_string:b.oldContent||"",new_string:b.currentContent||""})}catch(l){console.error("Error opening file:",l),s(c)}}},[s,t]),xt=n.useCallback(()=>{E(),q(),U()},[q,E,U]);return n.useEffect(()=>{const c=new AbortController;return f(""),y([]),k([]),S([]),o(null),w(null),i({}),j([]),B({}),x(!1),N(!1),T(!1),G(null),t?(E(c.signal),q(),U(),()=>{c.abort()}):()=>{c.abort()}},[q,E,U,t]),n.useEffect(()=>{!t||r!=="history"||Oe()},[r,Oe,t]),{gitStatus:a,gitDiff:d,isLoading:g,isLoadingCommits:u||!h,currentBranch:m,branches:v,localBranches:$,remoteBranches:L,recentCommits:p,commitDiffs:I,remoteStatus:M,isCreatingBranch:R,isFetching:H,isPulling:_,isPushing:A,isPublishing:Q,isCreatingInitialCommit:ie,isInitializingRepository:le,operationError:K,clearOperationError:ve,refreshAll:xt,switchBranch:Ce,createBranch:ke,deleteBranch:Se,handleFetch:$e,handlePull:ce,handlePush:de,handlePublish:me,discardChanges:be,deleteUntrackedFile:nt,stageFiles:at,unstageFiles:ot,fetchCommitDiff:it,generateCommitMessage:lt,commitChanges:ct,createInitialCommit:dt,initRepository:mt,openFile:ut}}async function Dt(t){return await t.json()}function Ot({projectId:t,onSuccess:r}){const[s,a]=n.useState(!1),o=n.useCallback(async()=>{if(t){a(!0);try{const d=await Z("/api/git/revert-local-commit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t})}),i=await Dt(d);if(!i.success){console.error("Revert local commit failed:",i.error||i.details||"Unknown error");return}r?.()}catch(d){console.error("Error reverting local commit:",d)}finally{a(!1)}}},[r,t]);return{isRevertingLocalCommit:s,revertLatestLocalCommit:o}}const Ie=new Map;function Bt({isMobile:t,projectPath:r,selectedFileCount:s,isHidden:a,onCommit:o,onRequestConfirmation:d}){const[i,g]=n.useState(()=>Ie.get(r)??""),x=u=>{g(u),u?Ie.set(r,u):Ie.delete(r)},[m,f]=n.useState(!1),[v,y]=n.useState(t),p=async(u=i)=>{const N=u.trim();if(!N||s===0||m)return!1;f(!0);try{const h=await o(N);return h&&x(""),h}finally{f(!1)}},j=()=>{const u=i.trim();!u||s===0||m||d({type:"commit",message:`Commit ${s} file${s!==1?"s":""} with message: "${u}"?`,onConfirm:async()=>{await p(u)}})};return e.jsx("div",{className:`transition-all duration-300 ease-in-out ${a?"max-h-0 -translate-y-2 overflow-hidden opacity-0":"max-h-96 translate-y-0 opacity-100"}`,children:t&&v?e.jsx("div",{className:"border-b border-border/60 px-4 py-2",children:e.jsxs("button",{onClick:()=>y(!1),className:"flex w-full items-center justify-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsxs("span",{children:["Commit ",s," file",s!==1?"s":""]}),e.jsx(xe,{className:"h-3 w-3"})]})}):e.jsxs("div",{className:"border-b border-border/60 px-4 py-3",children:[t&&e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Commit Changes"}),e.jsx("button",{onClick:()=>y(!0),className:"rounded-lg p-1 transition-colors hover:bg-accent",children:e.jsx(xe,{className:"h-4 w-4 rotate-180"})})]}),e.jsx("textarea",{value:i,onChange:u=>x(u.target.value),placeholder:"Message (Ctrl+Enter to commit)",className:"w-full resize-none rounded-xl border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",rows:3,onKeyDown:u=>{u.key==="Enter"&&(u.ctrlKey||u.metaKey)&&(u.preventDefault(),p())}}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s," file",s!==1?"s":""," selected"]}),e.jsxs("button",{onClick:j,disabled:!i.trim()||s===0||m,className:"flex items-center space-x-1 rounded-lg bg-primary px-3 py-1.5 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(fe,{className:"h-3 w-3"}),e.jsx("span",{children:m?"Committing...":"Commit"})]})]})]})})}const Ue=2e5,_e=1500;function Wt(t){const r=t.length>Ue,a=(r?t.slice(0,Ue):t).split(`
4
+ `),o=a.length>_e;return{lines:o?a.slice(0,_e):a,isCharacterTruncated:r,isLineTruncated:o}}function rt({diff:t,isMobile:r,wrapText:s}){const a=n.useMemo(()=>Wt(t||""),[t]),o=a.isCharacterTruncated||a.isLineTruncated;if(!t)return e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No diff available"});const d=(i,g)=>{const x=i.startsWith("+")&&!i.startsWith("+++"),m=i.startsWith("-")&&!i.startsWith("---"),f=i.startsWith("@@");return e.jsx("div",{className:`px-3 py-0.5 font-mono text-xs ${r&&s?"whitespace-pre-wrap break-all":"overflow-x-auto whitespace-pre"} ${x?"bg-green-50 text-green-700 dark:bg-green-950/50 dark:text-green-300":m?"bg-red-50 text-red-700 dark:bg-red-950/50 dark:text-red-300":f?"bg-primary/5 text-primary":"text-muted-foreground/70"}`,children:i},g)};return e.jsxs("div",{className:"diff-viewer",children:[o&&e.jsx("div",{className:"mb-2 rounded-md border border-border bg-card px-3 py-2 text-xs text-muted-foreground",children:"Large diff preview: rendering is limited to keep the tab responsive."}),a.lines.map((i,g)=>d(i,g))]})}function Mt({filePath:t,status:r,isMobile:s,isExpanded:a,isSelected:o,diff:d,wrapText:i,onToggleSelected:g,onToggleExpanded:x,onOpenFile:m,onToggleWrapText:f,onRequestFileAction:v}){const y=Ft(r),p=De(r);return e.jsxs("div",{className:"border-b border-border last:border-0",children:[e.jsxs("div",{className:`flex items-center transition-colors hover:bg-accent/50 ${s?"px-2 py-1.5":"px-3 py-2"}`,children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>g(t),onClick:j=>j.stopPropagation(),className:`rounded border-border bg-background text-primary checked:bg-primary focus:ring-primary/40 ${s?"mr-1.5":"mr-2"}`}),e.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[e.jsx("button",{onClick:j=>{j.stopPropagation(),x(t)},className:`cursor-pointer rounded p-0.5 hover:bg-accent ${s?"mr-1":"mr-2"}`,title:a?"Collapse diff":"Expand diff",children:e.jsx(Re,{className:`h-3 w-3 transition-transform duration-200 ease-in-out ${a?"rotate-90":"rotate-0"}`})}),e.jsx("span",{className:`flex-1 truncate ${s?"text-xs":"text-sm"} cursor-pointer hover:text-primary hover:underline`,onClick:j=>{j.stopPropagation(),m(t)},title:"Click to open file",children:t}),e.jsxs("span",{className:"flex items-center gap-1",children:[(r==="M"||r==="D"||r==="U")&&e.jsxs("button",{onClick:j=>{j.stopPropagation(),v(t,r)},className:`${s?"px-2 py-1 text-xs":"p-1"} flex items-center gap-1 rounded font-medium text-destructive hover:bg-destructive/10`,title:r==="U"?"Delete untracked file":"Discard changes",children:[e.jsx(oe,{className:"h-3 w-3"}),s&&e.jsx("span",{children:r==="U"?"Delete":"Discard"})]}),e.jsx("span",{className:`inline-flex h-5 w-5 items-center justify-center rounded border text-[10px] font-bold ${p}`,title:y,children:r})]})]})]}),e.jsxs("div",{className:`duration-400 overflow-hidden bg-muted/50 transition-all ease-in-out ${a&&d?"max-h-[600px] translate-y-0 opacity-100":"max-h-0 -translate-y-1 opacity-0"}`,children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border p-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`inline-flex h-5 w-5 items-center justify-center rounded border text-[10px] font-bold ${p}`,children:r}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:y})]}),s&&e.jsx("button",{onClick:j=>{j.stopPropagation(),f()},className:"text-sm text-muted-foreground transition-colors hover:text-foreground",title:i?"Switch to horizontal scroll":"Switch to text wrap",children:i?"Scroll":"Wrap"})]}),e.jsx("div",{className:"max-h-96 overflow-y-auto",children:d&&e.jsx(rt,{diff:d,isMobile:s,wrapText:i})})]})]})}function Ge({gitStatus:t,gitDiff:r,expandedFiles:s,selectedFiles:a,isMobile:o,wrapText:d,filePaths:i,onToggleSelected:g,onToggleExpanded:x,onOpenFile:m,onToggleWrapText:f,onRequestFileAction:v}){return e.jsx(e.Fragment,{children:et.map(({key:y,status:p})=>(t[y]||[]).filter(j=>!i||i.has(j)).map(j=>e.jsx(Mt,{filePath:j,status:p,isMobile:o,isExpanded:s.has(j),isSelected:a.has(j),diff:r[j],wrapText:d,onToggleSelected:g,onToggleExpanded:x,onOpenFile:m,onToggleWrapText:f,onRequestFileAction:v},j)))})}const Ut=[{status:"M",label:"Modified"},{status:"A",label:"Added"},{status:"D",label:"Deleted"},{status:"U",label:"Untracked"}];function _t({isMobile:t}){const[r,s]=n.useState(!1);return t?null:e.jsxs("div",{className:"border-b border-border/60",children:[e.jsxs("button",{onClick:()=>s(a=>!a),className:"flex w-full items-center justify-center gap-1 bg-muted/30 px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-muted/50",children:[e.jsx(ht,{className:"h-3 w-3"}),e.jsx("span",{children:"File Status Guide"}),r?e.jsx(xe,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"})]}),r&&e.jsx("div",{className:"bg-muted/30 px-4 py-3 text-sm",children:e.jsx("div",{className:"flex justify-center gap-6",children:Ut.map(a=>e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`inline-flex h-5 w-5 items-center justify-center rounded border text-[10px] font-bold ${De(a.status)}`,children:a.status}),e.jsx("span",{className:"italic text-muted-foreground",children:a.label})]},a.status))})})]})}function Gt({isMobile:t,projectPath:r,gitStatus:s,gitDiff:a,isLoading:o,wrapText:d,isCreatingInitialCommit:i,onWrapTextChange:g,onCreateInitialCommit:x,onOpenFile:m,onDiscardFile:f,onDeleteFile:v,onStageFiles:y,onUnstageFiles:p,onCommitChanges:j,onRequestConfirmation:u,onExpandedFilesChange:N}){const[h,T]=n.useState(new Set),[I,B]=n.useState(new Set),[M,w]=n.useState(0),$=n.useRef(Promise.resolve()),k=n.useMemo(()=>Ae(s),[s]),L=h.size>0,S=n.useCallback(C=>{w(A=>A+1),$.current=$.current.catch(()=>{}).then(C).finally(()=>w(A=>A-1))},[]);n.useEffect(()=>{if(!s||s.error){B(new Set);return}M>0||B(new Set(s.staged??[]))},[s,M]),n.useEffect(()=>{N(L)},[L,N]),n.useEffect(()=>()=>{N(!1)},[N]);const R=n.useCallback(C=>{T(A=>{const J=new Set(A);return J.has(C)?J.delete(C):J.add(C),J})},[]),z=n.useCallback(C=>{const A=I.has(C);B(J=>{const Q=new Set(J);return A?Q.delete(C):Q.add(C),Q}),S(()=>A?p([C]):y([C]))},[S,y,p,I]),H=n.useCallback((C,A)=>{if(A==="U"){u({type:"delete",message:`Delete untracked file "${C}"? This action cannot be undone.`,onConfirm:async()=>{await v(C)}});return}u({type:"discard",message:`Discard all changes to "${C}"? This action cannot be undone.`,onConfirm:async()=>{await f(C)}})},[v,f,u]),Y=n.useCallback(C=>j(C,Array.from(I)),[j,I]),_=n.useMemo(()=>new Set(k.filter(C=>!I.has(C))),[k,I]);return e.jsxs(e.Fragment,{children:[e.jsx(Bt,{isMobile:t,projectPath:r,selectedFileCount:I.size,isHidden:L,onCommit:Y,onRequestConfirmation:u}),!s?.error&&e.jsx(_t,{isMobile:t}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:o?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):s?.hasCommits===!1&&We(s)?e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 text-center",children:[e.jsx("div",{className:"mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-muted/50",children:e.jsx(P,{className:"h-7 w-7 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-2 text-lg font-medium text-foreground",children:"No commits yet"}),e.jsx("p",{className:"mb-6 max-w-md text-sm text-muted-foreground",children:"This repository doesn't have any commits yet. Create your first commit to start tracking changes."}),e.jsx("button",{onClick:()=>{x()},disabled:i,className:"flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:i?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Creating Initial Commit..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{children:"Create Initial Commit"})]})})]}):!s||!We(s)?e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center text-muted-foreground",children:[e.jsx(Te,{className:"mb-2 h-10 w-10 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No changes detected"})]}):e.jsxs("div",{className:t?"pb-4":"",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/60 bg-muted/30 px-3 py-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:["Staged (",I.size,")"]}),I.size>0&&e.jsx("button",{onClick:()=>{const C=Array.from(I);B(new Set),S(()=>p(C))},className:"text-xs text-primary transition-colors hover:text-primary/80",children:"Unstage All"})]}),I.size===0?e.jsx("div",{className:"px-3 py-2 text-xs italic text-muted-foreground",children:"No staged files"}):e.jsx(Ge,{gitStatus:s,gitDiff:a,expandedFiles:h,selectedFiles:I,isMobile:t,wrapText:d,filePaths:I,onToggleSelected:z,onToggleExpanded:R,onOpenFile:C=>{m(C)},onToggleWrapText:()=>g(!d),onRequestFileAction:H}),e.jsxs("div",{className:"flex items-center justify-between border-b border-border/60 bg-muted/30 px-3 py-1.5",children:[e.jsxs("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:["Changes (",_.size,")"]}),_.size>0&&e.jsx("button",{onClick:()=>{const C=Array.from(_);B(new Set(k)),S(()=>y(C))},className:"text-xs text-primary transition-colors hover:text-primary/80",children:"Stage All"})]}),_.size===0?e.jsx("div",{className:"px-3 py-2 text-xs italic text-muted-foreground",children:"All changes staged"}):e.jsx(Ge,{gitStatus:s,gitDiff:a,expandedFiles:h,selectedFiles:I,isMobile:t,wrapText:d,filePaths:_,onToggleSelected:z,onToggleExpanded:R,onOpenFile:C=>{m(C)},onToggleWrapText:()=>g(!d),onRequestFileAction:H})]})})]})}const ze=["#0ea5e9","#f97316","#a855f7","#22c55e","#ef4444","#eab308","#14b8a6","#ec4899","#6366f1","#84cc16"],ae=t=>ze[t%ze.length];function zt(t){const r=[],s=[],a=()=>{const o=r.indexOf(null);return o!==-1?o:(r.push(null),r.length-1)};for(const o of t){const d=new Set;r.forEach((u,N)=>{u!==null&&d.add(N)});const i=[];r.forEach((u,N)=>{u===o.hash&&i.push(N)});const g=i.length>0,x=g?i[0]:a(),m=i.slice(1);for(const u of m)r[u]=null;const f=o.parents??[];r[x]=f.length>0?f[0]:null;const v=[];for(const u of f.slice(1)){const N=r.findIndex(h=>h===u);if(N!==-1&&N!==x)v.push(N);else{const h=a();r[h]=u,v.push(h)}}const y=[...d].filter(u=>u!==x&&!i.includes(u)).sort((u,N)=>u-N),p=[];r.forEach((u,N)=>{u!==null&&p.push(N)});const j=Math.max(r.length,x+1);for(;r.length>0&&r[r.length-1]===null;)r.pop();s.push({nodeLane:x,laneCount:j,hasTopContinuation:g,hasParentContinuation:f.length>0,inbound:m,outbound:v,passThrough:y,bottomLanes:p})}return s}const Le=12,ue=56,ee=28,Je=3.5,te=2,re=t=>t*Le+Le/2;function Jt({row:t}){const r=t.laneCount*Le,s=re(t.nodeLane),a=ae(t.nodeLane);return e.jsxs("div",{"aria-hidden":!0,className:"relative shrink-0 self-stretch overflow-hidden",style:{width:r},children:[e.jsxs("svg",{className:"absolute left-0 top-0",width:r,height:ue,fill:"none",children:[t.passThrough.map(o=>e.jsx("path",{d:`M ${re(o)} 0 V ${ue}`,stroke:ae(o),strokeWidth:te},`pass-${o}`)),t.hasTopContinuation&&e.jsx("path",{d:`M ${s} 0 V ${ee}`,stroke:a,strokeWidth:te}),t.hasParentContinuation&&e.jsx("path",{d:`M ${s} ${ee} V ${ue}`,stroke:a,strokeWidth:te}),t.inbound.map(o=>e.jsx("path",{d:`M ${re(o)} 0 Q ${re(o)} ${ee} ${s} ${ee}`,stroke:ae(o),strokeWidth:te},`in-${o}`)),t.outbound.map(o=>e.jsx("path",{d:`M ${s} ${ee} Q ${re(o)} ${ee} ${re(o)} ${ue}`,stroke:ae(o),strokeWidth:te},`out-${o}`)),e.jsx("circle",{cx:s,cy:ee,r:t.inbound.length>0||t.outbound.length>0?Je+.5:Je,fill:a})]}),t.bottomLanes.map(o=>e.jsx("div",{className:"absolute",style:{left:re(o)-te/2,top:ue,bottom:0,width:te,backgroundColor:ae(o)}},`rail-${o}`))]})}function Ht(t){return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function qt({refName:t,color:r}){const s=t.startsWith("tag: "),a=t.startsWith("HEAD -> "),o=s?t.slice(5):a?t.slice(8):t;return e.jsxs("span",{className:"inline-flex max-w-40 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium leading-4",style:{borderColor:r,color:r,backgroundColor:a?`${r}22`:"transparent"},title:t,children:[s?e.jsx(ft,{className:"h-2.5 w-2.5 shrink-0"}):e.jsx(P,{className:"h-2.5 w-2.5 shrink-0"}),e.jsx("span",{className:"truncate",children:o})]})}function Vt({commit:t,isExpanded:r,diff:s,isMobile:a,wrapText:o,graphRow:d,onToggle:i}){const g=n.useMemo(()=>s?Lt(s):null,[s]),x=d?ae(d.nodeLane):"#0ea5e9";return e.jsxs("div",{className:"flex border-b border-border last:border-0",children:[d&&e.jsx(Jt,{row:d}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("button",{type:"button","aria-expanded":r,className:"flex w-full cursor-pointer items-start border-0 bg-transparent p-3 text-left transition-colors hover:bg-accent/50",onClick:i,children:[e.jsx("span",{className:"mr-2 mt-1 rounded p-0.5 hover:bg-accent",children:r?e.jsx(xe,{className:"h-3 w-3"}):e.jsx(Re,{className:"h-3 w-3"})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[t.refs&&t.refs.length>0&&e.jsx("span",{className:"mb-0.5 flex flex-wrap gap-1",children:t.refs.map(m=>e.jsx(qt,{refName:m,color:x},m))}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:t.message}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[t.author," • ",t.date]})]}),e.jsx("span",{className:"flex-shrink-0 font-mono text-sm text-muted-foreground/60",children:t.hash.substring(0,7)})]})})]}),r&&s&&e.jsx("div",{className:"bg-muted/50",children:e.jsxs("div",{className:"max-h-[32rem] overflow-y-auto p-3",children:[e.jsx("p",{className:"mb-2 select-all font-mono text-xs text-muted-foreground/70",children:t.hash}),e.jsxs("div",{className:"mb-3 flex gap-4 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground/60",children:"Author "}),t.author]}),e.jsxs("span",{children:[e.jsx("span",{className:"text-muted-foreground/60",children:"Date "}),Ht(t.date)]})]}),g&&e.jsxs("div",{className:"mb-3 flex gap-4 rounded-md bg-muted/80 px-4 py-2 text-center text-xs",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground/60",children:"Files"}),e.jsx("div",{className:"font-semibold text-foreground",children:g.totalFiles})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground/60",children:"Added"}),e.jsxs("div",{className:"font-semibold text-green-600 dark:text-green-400",children:["+",g.totalInsertions]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground/60",children:"Removed"}),e.jsxs("div",{className:"font-semibold text-red-600 dark:text-red-400",children:["-",g.totalDeletions]})]})]}),g&&g.files.length>0&&e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"mb-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Changed Files"}),e.jsx("div",{className:"rounded-md border border-border/60",children:g.files.map((m,f)=>e.jsxs("div",{className:`flex items-center gap-2 px-2.5 py-1.5 text-xs ${f<g.files.length-1?"border-b border-border/40":""}`,children:[e.jsx("span",{className:`inline-flex h-4 w-4 flex-shrink-0 items-center justify-center rounded border text-[9px] font-bold ${De(m.status)}`,children:m.status}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[m.directory&&e.jsx("span",{className:"text-muted-foreground/60",children:m.directory}),e.jsx("span",{className:"font-medium text-foreground",children:m.filename})]}),e.jsxs("span",{className:"flex-shrink-0 font-mono text-muted-foreground/60",children:[m.insertions>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["+",m.insertions]}),m.insertions>0&&m.deletions>0&&"/",m.deletions>0&&e.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["-",m.deletions]})]})]},m.path))})]}),e.jsx(rt,{diff:s,isMobile:a,wrapText:o})]})})]})]})}function Qt({isMobile:t,isLoading:r,recentCommits:s,commitDiffs:a,wrapText:o,onFetchCommitDiff:d}){const[i,g]=n.useState(new Set),x=n.useMemo(()=>s.some(f=>f.parents!==void 0)?zt(s):null,[s]),m=n.useCallback(f=>{const v=!i.has(f);g(y=>{const p=new Set(y);return p.has(f)?p.delete(f):p.add(f),p}),v&&!a[f]&&d(f).catch(y=>{console.error("Failed to fetch commit diff:",y)})},[a,i,d,g]);return e.jsx("div",{className:"flex-1 overflow-y-auto",children:r?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):s.length===0?e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center text-muted-foreground",children:[e.jsx(Ke,{className:"mb-2 h-10 w-10 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No commits found"})]}):e.jsx("div",{className:t?"pb-4":"",children:s.map((f,v)=>e.jsx(Vt,{commit:f,isExpanded:i.has(f.hash),diff:a[f.hash],isMobile:t,wrapText:o,graphRow:x?.[v],onToggle:()=>m(f.hash)},f.hash))})})}function st({isOpen:t,currentBranch:r,isCreatingBranch:s,onClose:a,onCreateBranch:o}){const[d,i]=n.useState("");n.useEffect(()=>{t||i("")},[t]);const g=async()=>{const x=d.trim();if(!x)return!1;try{const m=await o(x);return m&&(i(""),a()),m}catch(m){return console.error("Failed to create branch:",m),!1}};return t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:a}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"new-branch-title",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"mb-4 text-lg font-semibold text-foreground",children:"Create New Branch"}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"git-new-branch-name",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Branch Name"}),e.jsx("input",{id:"git-new-branch-name",type:"text",value:d,onChange:x=>i(x.target.value),onKeyDown:x=>{if(x.key==="Enter"&&!s){x.preventDefault(),x.stopPropagation(),g();return}x.key==="Escape"&&!s&&(x.preventDefault(),x.stopPropagation(),a())},placeholder:"feature/new-feature",className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",autoFocus:!0})]}),e.jsxs("p",{className:"mb-4 text-sm text-muted-foreground",children:["This will create a new branch from the current branch (",r,")"]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:a,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{g()},disabled:!d.trim()||s,className:"flex items-center space-x-2 rounded-lg bg-primary px-4 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Creating..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{children:"Create Branch"})]})})]})]})})]}):null}function He({name:t,isCurrent:r,isRemote:s,aheadCount:a,behindCount:o,isMobile:d,onSwitch:i,onDelete:g}){return e.jsxs("div",{className:`group flex items-center gap-3 border-b border-border/40 px-4 transition-colors hover:bg-accent/40 ${d?"py-2.5":"py-3"} ${r?"bg-primary/5":""}`,children:[e.jsx("div",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md border ${r?"border-primary/30 bg-primary/10 text-primary":s?"border-border bg-muted text-muted-foreground":"border-border bg-muted/50 text-muted-foreground"}`,children:s?e.jsx(pt,{className:"h-3.5 w-3.5"}):e.jsx(P,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`truncate text-sm font-medium ${r?"text-foreground":"text-foreground/80"}`,children:t}),r&&e.jsx("span",{className:"shrink-0 rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary",children:"current"}),s&&!r&&e.jsx("span",{className:"shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:"remote"})]}),r&&(a>0||o>0)&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[a>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",children:["↑",a," ahead"]}),o>0&&e.jsxs("span",{className:"text-primary",children:["↓",o," behind"]})]})]}),e.jsx("div",{className:`flex shrink-0 items-center gap-1 ${r?"opacity-100":"opacity-0 group-hover:opacity-100"} transition-opacity`,children:r?e.jsx(fe,{className:"h-4 w-4 text-primary"}):s?null:e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:i,className:"rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:`Switch to ${t}`,children:"Switch"}),e.jsx("button",{onClick:g,className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",title:`Delete ${t}`,children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]})})]})}function qe({label:t,count:r}){return e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between bg-background/95 px-4 py-2 backdrop-blur-sm",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:r})]})}function Kt({isMobile:t,isLoading:r,currentBranch:s,localBranches:a,remoteBranches:o,remoteStatus:d,isCreatingBranch:i,onSwitchBranch:g,onCreateBranch:x,onDeleteBranch:m,onRequestConfirmation:f}){const[v,y]=n.useState(!1),[p,j]=n.useState(""),u=d?.ahead??0,N=d?.behind??0,h=p.trim().toLowerCase(),T=n.useMemo(()=>h?a.filter(w=>w.toLowerCase().includes(h)):a,[a,h]),I=n.useMemo(()=>h?o.filter(w=>w.toLowerCase().includes(h)):o,[h,o]),B=w=>{f({type:"commit",message:`Switch to branch "${w}"? Make sure you have no uncommitted changes.`,onConfirm:()=>{g(w)}})},M=w=>{f({type:"deleteBranch",message:`Delete branch "${w}"? A normal delete only succeeds when the branch is fully merged. This cannot be undone.`,onConfirm:()=>{m(w)},alternateConfirmation:{label:"Force delete this unmerged branch",description:"Permanently removes the branch even when it contains commits that have not been merged elsewhere.",actionLabel:"Force delete",onConfirm:()=>{m(w,!0)}}})};return r&&a.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/40 px-4 py-2.5",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[a.length," local",o.length>0?`, ${o.length} remote`:""]}),e.jsxs("button",{onClick:()=>y(!0),className:"flex items-center gap-1.5 rounded-lg bg-primary/10 px-3 py-1.5 text-sm font-medium text-primary transition-colors hover:bg-primary/20",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"New branch"]})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border/40 px-4 py-2",children:[e.jsx(Xe,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("input",{type:"text",value:p,onChange:w=>j(w.target.value),placeholder:"Search branches...",className:"w-full bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none"}),p&&e.jsx("button",{onClick:()=>j(""),className:"shrink-0 text-muted-foreground transition-colors hover:text-foreground",title:"Clear search",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(qe,{label:"Local",count:T.length}),T.map(w=>e.jsx(He,{name:w,isCurrent:w===s,isRemote:!1,aheadCount:w===s?u:0,behindCount:w===s?N:0,isMobile:t,onSwitch:()=>B(w),onDelete:()=>M(w)},`local:${w}`))]}),I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(qe,{label:"Remote",count:I.length}),I.map(w=>e.jsx(He,{name:w,isCurrent:!1,isRemote:!0,aheadCount:0,behindCount:0,isMobile:t,onSwitch:()=>B(w),onDelete:()=>M(w)},`remote:${w}`))]}),T.length===0&&I.length===0&&e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center gap-2 text-muted-foreground",children:[e.jsx(P,{className:"h-10 w-10 opacity-30"}),e.jsx("p",{className:"text-sm",children:h?"No branches match your search":"No branches found"})]})]}),e.jsx(st,{isOpen:v,currentBranch:s,isCreatingBranch:i,onClose:()=>y(!1),onCreateBranch:x})]})}function je(t,r){const s=t.error?.message||r,a=t.error?.details;return Array.isArray(a)&&a.length>0?`${s}: ${a.slice(0,5).join(", ")}${a.length>5?", …":""}`:typeof a=="string"&&a.trim()?`${s}: ${a.trim()}`:s}function Xt({selectedProject:t,onProjectSelect:r,onProjectsRefresh:s}){const[a,o]=n.useState(null),[d,i]=n.useState(!1),[g,x]=n.useState(!1),[m,f]=n.useState(!1),[v,y]=n.useState(null),p=n.useRef(null),[j,u]=n.useState(null),N=n.useCallback(()=>u(null),[]),h=n.useRef(t?.projectId??null);n.useEffect(()=>{h.current=t?.projectId??null},[t]);const T=n.useCallback(async()=>{if(!t)return;const $=t.projectId;i(!0);try{const k=await Z(`/api/worktrees?project=${encodeURIComponent($)}`),L=await k.json();if(h.current!==$)return;if(!k.ok||!L.data){o(null);return}o(L.data)}catch(k){console.error("Error fetching worktrees:",k),h.current===$&&o(null)}finally{h.current===$&&(i(!1),x(!0))}},[t]);n.useEffect(()=>{o(null),x(!1),u(null),T()},[T]);const I=n.useCallback(async($,k,L)=>{const S=$.trim();if(!t||!S)return!1;const R=t.projectId;f(!0),u(null);try{const z=await Z("/api/worktrees/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:R,branch:S,baseBranch:k})}),H=await z.json();return h.current!==R?!1:!z.ok||!H.data?(u(je(H,"Failed to create worktree")),!1):(s?.(),L&&H.data.project&&r?r(H.data.project):T(),!0)}catch(z){return h.current===R&&u(z instanceof Error?z.message:"Failed to create worktree"),!1}finally{f(!1)}},[T,r,s,t]),B=n.useCallback(async $=>{if(!t||p.current!==null)return!1;const k=t.projectId,L=Symbol("open-worktree");p.current=L,y($),u(null);try{const S=await Z("/api/worktrees/open",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:k,worktreePath:$})}),R=await S.json();return h.current!==k?!1:!S.ok||!R.data?.project?(u(je(R,"Failed to open worktree")),!1):(s?.(),r?.(R.data.project),!0)}catch(S){return h.current===k&&u(S instanceof Error?S.message:"Failed to open worktree"),!1}finally{p.current===L&&(p.current=null,y(null))}},[r,s,t]),M=n.useCallback(async($,k)=>{if(!t||p.current!==null)return!1;const L=Symbol("merge-worktree");p.current=L,y($),u(null);try{const S=await Z("/api/worktrees/merge",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,worktreePath:$,squash:k.squash,message:k.message,removeAfterMerge:k.removeAfterMerge})}),R=await S.json();return!S.ok||!R.success?(u(je(R,"Merge failed")),!1):(s?.(),T(),!0)}catch(S){return u(S instanceof Error?S.message:"Merge failed"),!1}finally{p.current===L&&(p.current=null,y(null))}},[T,s,t]),w=n.useCallback(async($,k)=>{if(!t||p.current!==null)return!1;const L=Symbol("remove-worktree");p.current=L,y($),u(null);try{const S=await Z("/api/worktrees/remove",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({project:t.projectId,worktreePath:$,force:k.force,deleteBranch:k.deleteBranch})}),R=await S.json();return!S.ok||!R.success?(u(je(R,"Failed to remove worktree")),!1):(s?.(),T(),!0)}catch(S){return u(S instanceof Error?S.message:"Failed to remove worktree"),!1}finally{p.current===L&&(p.current=null,y(null))}},[T,s,t]);return{worktreeData:a,isLoading:d||!g,isCreatingWorktree:m,busyWorktreePath:v,actionError:j,clearActionError:N,refreshWorktrees:T,createWorktree:I,openWorktree:B,mergeWorktree:M,removeWorktree:w}}function Ve(t,r){return t?r?`Squash merge branch '${t}'`:`Merge branch '${t}'`:""}function Yt({worktree:t,baseBranch:r,isMerging:s,onClose:a,onMerge:o}){const[d,i]=n.useState(!0),[g,x]=n.useState(""),[m,f]=n.useState(!0),[v,y]=n.useState(!1);n.useEffect(()=>{t&&(i(!0),f(!0),x(Ve(t.branch,!0)),y(!1))},[t]);const p=N=>{i(N),v||x(Ve(t?.branch??null,N))},j=async()=>{if(!t)return;await o(t.path,{squash:d,message:g.trim(),removeAfterMerge:m})&&a()};if(!t)return null;const u=`${t.ahead} commit${t.ahead===1?"":"s"}`;return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:a}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"merge-worktree-title",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{id:"merge-worktree-title",className:"mb-1 text-lg font-semibold text-foreground",children:"Merge Worktree"}),e.jsxs("div",{className:"mb-4 flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"max-w-[45%] truncate rounded-md bg-primary/10 px-2 py-1 font-mono text-primary",children:t.branch}),e.jsx(gt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"max-w-[45%] truncate rounded-md bg-muted px-2 py-1 font-mono text-foreground/80",children:r}),e.jsx("span",{className:"ml-auto shrink-0 text-xs text-muted-foreground",children:u})]}),e.jsxs("label",{className:"mb-3 flex cursor-pointer items-start gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:N=>p(N.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),e.jsxs("span",{children:["Squash commits",e.jsxs("span",{className:"block text-xs text-muted-foreground",children:["Combine all ",u," into a single commit on ",r]})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{htmlFor:"merge-worktree-message",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Commit message"}),e.jsx("textarea",{id:"merge-worktree-message",value:g,onChange:N=>{x(N.target.value),y(!0)},rows:2,className:"w-full resize-none rounded-xl border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20"})]}),e.jsxs("label",{className:"mb-4 flex cursor-pointer items-start gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:N=>f(N.target.checked),className:"mt-0.5 h-4 w-4 rounded border-border accent-primary"}),e.jsxs("span",{children:["Clean up after merge",e.jsx("span",{className:"block text-xs text-muted-foreground",children:"Remove the worktree and delete its branch once merged"})]})]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:a,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{j()},disabled:s||!g.trim(),className:"flex items-center space-x-2 rounded-lg bg-primary px-4 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Merging..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{className:"h-3 w-3"}),e.jsx("span",{children:d?"Squash & Merge":"Merge"})]})})]})]})})]})}function Zt(t){return t.replace(/[/\\:*?"<>|\s]+/g,"-").replace(/\.+$/g,"").replace(/^-+|-+$/g,"")}function Pt(t){const r=t.split(/[\\/]/).filter(Boolean);return r[r.length-1]??t}function er({isOpen:t,baseBranch:r,localBranches:s,repositoryRoot:a,isCreating:o,onClose:d,onCreate:i}){const[g,x]=n.useState(""),[m,f]=n.useState(""),[v,y]=n.useState(!0);n.useEffect(()=>{if(!t)x(""),y(!0);else{const h=r&&s.includes(r)?r:s[0]??"";f(h)}},[t,r,s]);const p=g.trim(),j=s.includes(p),u=n.useMemo(()=>{if(!p)return null;const h=Zt(p);return h?`${Pt(a)}-worktrees/${h}`:null},[a,p]),N=async()=>{if(!p)return!1;const h=await i(p,j?null:m||null,v);return h&&d(),h};return t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:d}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"new-worktree-title",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{id:"new-worktree-title",className:"mb-1 text-lg font-semibold text-foreground",children:"New Worktree"}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Check out a branch in its own folder and work on it in parallel."}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"worktree-branch-name",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Branch"}),e.jsx("input",{id:"worktree-branch-name",type:"text",value:g,onChange:h=>x(h.target.value),onKeyDown:h=>{if(h.key==="Enter"&&!o){h.preventDefault(),h.stopPropagation(),N();return}h.key==="Escape"&&!o&&(h.preventDefault(),h.stopPropagation(),d())},placeholder:"feature/new-feature",className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-foreground placeholder:text-muted-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",autoFocus:!0}),j&&e.jsx("p",{className:"mt-1.5 text-xs text-muted-foreground",children:"Existing branch — it will be checked out as-is."})]}),!j&&e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:"worktree-base-branch",className:"mb-2 block text-sm font-medium text-foreground/80",children:"Create from"}),e.jsx("select",{id:"worktree-base-branch",value:m,onChange:h=>f(h.target.value),className:"w-full rounded-xl border border-border bg-background px-3 py-2 text-foreground focus:border-primary/30 focus:outline-none focus:ring-2 focus:ring-primary/20",children:s.map(h=>e.jsx("option",{value:h,children:h},h))})]}),u&&e.jsxs("p",{className:"mb-4 rounded-lg bg-muted/50 px-3 py-2 text-xs text-muted-foreground",children:["Will be created in ",e.jsx("span",{className:"font-mono text-foreground/80",children:u})]}),e.jsxs("label",{className:"mb-4 flex cursor-pointer items-center gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:v,onChange:h=>y(h.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Switch to the worktree after creating it"]}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:d,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{N()},disabled:!p||o,className:"flex items-center space-x-2 rounded-lg bg-primary px-4 py-2 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Creating..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{className:"h-3 w-3"}),e.jsx("span",{children:"Create Worktree"})]})})]})]})})]}):null}function tr({worktree:t,isRemoving:r,onClose:s,onRemove:a}){const[o,d]=n.useState(!0),[i,g]=n.useState(!1);n.useEffect(()=>{t&&(d(!0),g(!1))},[t]);const x=async()=>{if(!t)return;await a(t.path,{force:i,deleteBranch:o})&&s()};if(!t)return null;const m=t.changedFileCount>0;return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:s}),e.jsx("div",{className:"relative w-full max-w-md overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":"remove-worktree-title",children:e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-4 flex items-center",children:[e.jsx("div",{className:"mr-3 rounded-full bg-red-100 p-2 dark:bg-red-900/30",children:e.jsx(oe,{className:"h-4 w-4 text-red-600 dark:text-red-400"})}),e.jsx("h3",{id:"remove-worktree-title",className:"text-lg font-semibold text-foreground",children:"Remove Worktree"})]}),e.jsxs("p",{className:"mb-3 text-sm text-muted-foreground",children:["Remove the worktree for"," ",e.jsx("span",{className:"font-mono text-foreground/80",children:t.branch??"detached HEAD"}),"? Its folder is deleted and the linked project is archived — chat sessions stay recoverable."]}),m&&e.jsxs("p",{className:"mb-3 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-600 dark:text-amber-400",children:["This worktree has ",t.changedFileCount," uncommitted change",t.changedFileCount===1?"":"s"," that will be lost."]}),t.branch&&e.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:f=>d(f.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Also delete branch ",e.jsx("span",{className:"font-mono",children:t.branch})]}),m&&e.jsxs("label",{className:"mb-2 flex cursor-pointer items-center gap-2 text-sm text-foreground/80",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:f=>g(f.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),"Discard uncommitted changes"]}),e.jsxs("div",{className:"mt-4 flex justify-end space-x-3",children:[e.jsx("button",{onClick:s,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsx("button",{onClick:()=>{x()},disabled:r||m&&!i,className:"flex items-center space-x-2 rounded-lg bg-red-600 px-4 py-2 text-sm text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50",children:r?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Removing..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3 w-3"}),e.jsx("span",{children:"Remove"})]})})]})]})})]})}function rr(t){return t.split(/[\\/]/).filter(Boolean).slice(-2).join("/")||t}function sr({worktree:t,isMobile:r,isBusy:s,onOpen:a,onMerge:o,onRemove:d}){const i=t.branch??(t.headSha?`detached @ ${t.headSha.slice(0,7)}`:"detached");return e.jsxs("div",{className:`group flex items-center gap-3 border-b border-border/40 px-4 transition-colors hover:bg-accent/40 ${r?"py-2.5":"py-3"} ${t.isCurrent?"bg-primary/5":""}`,children:[e.jsx("div",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md border ${t.isCurrent?"border-primary/30 bg-primary/10 text-primary":"border-border bg-muted/50 text-muted-foreground"}`,children:t.isMain?e.jsx(bt,{className:"h-3.5 w-3.5"}):e.jsx(we,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`truncate text-sm font-medium ${t.isCurrent?"text-foreground":"text-foreground/80"}`,children:i}),t.isCurrent&&e.jsx("span",{className:"shrink-0 rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary",children:"current"}),t.isMain&&e.jsx("span",{className:"shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:"main worktree"}),t.isLocked&&e.jsx("span",{className:"shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-xs text-muted-foreground",children:"locked"})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"shrink-0 font-mono",children:rr(t.path)}),t.ahead>0&&e.jsxs("span",{className:"shrink-0 text-green-600 dark:text-green-400",children:["↑",t.ahead]}),t.behind>0&&e.jsxs("span",{className:"shrink-0 text-primary",children:["↓",t.behind]}),t.changedFileCount>0&&e.jsxs("span",{className:"shrink-0 text-amber-600 dark:text-amber-400",children:["● ",t.changedFileCount," change",t.changedFileCount===1?"":"s"]}),t.lastCommitSubject&&e.jsx("span",{className:"truncate",children:t.lastCommitSubject})]})]}),e.jsx("div",{className:`flex shrink-0 items-center gap-1 ${t.isCurrent||s?"opacity-100":"opacity-100 sm:opacity-0 sm:focus-within:opacity-100 sm:group-hover:opacity-100"} transition-opacity`,children:s?e.jsx(V,{className:"h-4 w-4 animate-spin text-muted-foreground"}):t.isCurrent?e.jsx(fe,{className:"h-4 w-4 text-primary"}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:a,className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:`Switch to ${i}`,children:[e.jsx(yt,{className:"h-3 w-3"}),"Open"]}),!t.isMain&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:o,disabled:!t.branch||t.ahead===0,className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-primary/10 hover:text-primary disabled:cursor-not-allowed disabled:opacity-40",title:t.ahead===0?"Nothing to merge — no commits ahead of the base branch":`Merge ${i} into the base branch`,children:e.jsx(Ye,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:d,className:"rounded-md p-1 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive",title:`Remove worktree for ${i}`,children:e.jsx(oe,{className:"h-3.5 w-3.5"})})]})]})})]})}function nr({isMobile:t,selectedProject:r,localBranches:s,onProjectSelect:a,onProjectsRefresh:o}){const{worktreeData:d,isLoading:i,isCreatingWorktree:g,busyWorktreePath:x,actionError:m,clearActionError:f,refreshWorktrees:v,createWorktree:y,openWorktree:p,mergeWorktree:j,removeWorktree:u}=Xt({selectedProject:r,onProjectSelect:a,onProjectsRefresh:o}),[N,h]=n.useState(!1),[T,I]=n.useState(null),[B,M]=n.useState(null),w=d?.worktrees??[],$=w.filter(k=>!k.isMain).length;return i&&w.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(V,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/40 px-4 py-2.5",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:$===0?"No worktrees":`${$} worktree${$===1?"":"s"}`}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>{v()},className:"rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",title:"Refresh worktrees",children:e.jsx(V,{className:`h-3.5 w-3.5 ${i?"animate-spin":""}`})}),e.jsxs("button",{onClick:()=>h(!0),disabled:!d,className:"flex items-center gap-1.5 rounded-lg bg-primary/10 px-3 py-1.5 text-sm font-medium text-primary transition-colors hover:bg-primary/20 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"New worktree"]})]})]}),m&&e.jsxs("div",{className:"flex items-start gap-2 border-b border-destructive/30 bg-destructive/10 px-4 py-2.5",children:[e.jsx("p",{className:"min-w-0 flex-1 break-words text-xs text-destructive",children:m}),e.jsx("button",{onClick:f,className:"shrink-0 text-destructive/70 transition-colors hover:text-destructive",title:"Dismiss",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[w.map(k=>e.jsx(sr,{worktree:k,isMobile:t,isBusy:x===k.path,onOpen:()=>{p(k.path)},onMerge:()=>I(k),onRemove:()=>M(k)},k.path)),$===0&&e.jsxs("div",{className:"flex flex-col items-center gap-3 px-6 py-10 text-center",children:[e.jsx(we,{className:"h-10 w-10 text-muted-foreground opacity-30"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground/80",children:"Work on branches in parallel"}),e.jsx("p",{className:"mx-auto mt-1 max-w-xs text-xs text-muted-foreground",children:"A worktree checks out a branch in its own folder, so you can run separate chat sessions side by side and merge the results back when they're ready."})]}),e.jsxs("button",{onClick:()=>h(!0),disabled:!d,className:"flex items-center gap-1.5 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx(he,{className:"h-3.5 w-3.5"}),"Create your first worktree"]})]})]}),e.jsx(er,{isOpen:N,baseBranch:d?.baseBranch??null,localBranches:s,repositoryRoot:d?.repositoryRoot??"",isCreating:g,onClose:()=>h(!1),onCreate:y}),e.jsx(Yt,{worktree:T,baseBranch:d?.baseBranch??null,isMerging:T!==null&&x===T.path,onClose:()=>I(null),onMerge:j}),e.jsx(tr,{worktree:B,isRemoving:B!==null&&x===B.path,onClose:()=>M(null),onRemove:u})]})}function ar({isMobile:t,currentBranch:r,branches:s,remoteStatus:a,isLoading:o,isCreatingBranch:d,isFetching:i,isPulling:g,isPushing:x,isPublishing:m,isRevertingLocalCommit:f,operationError:v,onRefresh:y,onRevertLocalCommit:p,onSwitchBranch:j,onCreateBranch:u,onFetch:N,onPull:h,onPush:T,onPublish:I,onClearError:B,onRequestConfirmation:M}){const[w,$]=n.useState(!1),[k,L]=n.useState(!1),[S,R]=n.useState(""),z=n.useRef(null),H=n.useRef(null);n.useEffect(()=>{w?H.current?.focus():R("")},[w]);const Y=n.useMemo(()=>{const D=S.trim().toLowerCase();return D?s.filter(K=>K.toLowerCase().includes(D)):s},[s,S]);n.useEffect(()=>{const D=K=>{z.current&&!z.current.contains(K.target)&&$(!1)};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]);const _=a?.ahead??0,C=a?.behind??0,A=a?.remoteName??"remote",J=i||g||x||m,Q=()=>{M({type:"pull",message:`Pull ${C} commit${C!==1?"s":""} from ${A}?`,onConfirm:h})},se=()=>{M({type:"push",message:`Push ${_} commit${_!==1?"s":""} to ${A}?`,onConfirm:T})},ie=()=>{M({type:"publish",message:`Publish branch "${r}" to ${A}?`,onConfirm:I})},ne=()=>{M({type:"revertLocalCommit",message:"Revert the latest local commit? This removes the commit but keeps its changes staged.",onConfirm:p})},le=async D=>{try{await j(D)&&$(!1)}catch(K){console.error("[GitPanelHeader] Failed to switch branch:",K)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center justify-between border-b border-border/60 ${t?"px-3 py-2":"px-4 py-3"}`,children:[e.jsxs("div",{className:"relative",ref:z,children:[e.jsxs("button",{onClick:()=>$(D=>!D),className:`flex items-center rounded-lg transition-colors hover:bg-accent ${t?"space-x-1 px-2 py-1":"space-x-2 px-3 py-1.5"}`,children:[e.jsx(P,{className:`text-muted-foreground ${t?"h-3 w-3":"h-4 w-4"}`}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:`font-medium ${t?"text-xs":"text-sm"}`,children:r}),a?.hasRemote&&e.jsxs("span",{className:"flex items-center gap-0.5 text-xs",children:[_>0&&e.jsxs("span",{className:"text-green-600 dark:text-green-400",title:`${_} ahead`,children:["↑",_]}),C>0&&e.jsxs("span",{className:"text-primary",title:`${C} behind`,children:["↓",C]}),a.isUpToDate&&e.jsx("span",{className:"text-muted-foreground",title:"Up to date",children:"✓"})]})]}),e.jsx(xe,{className:`h-3 w-3 text-muted-foreground transition-transform ${w?"rotate-180":""}`})]}),w&&e.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 overflow-hidden rounded-xl border border-border bg-card shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2",children:[e.jsx(Xe,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("input",{ref:H,type:"text",value:S,onChange:D=>R(D.target.value),placeholder:"Search branches...",className:"w-full bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none"}),S&&e.jsx("button",{onClick:()=>R(""),className:"shrink-0 text-muted-foreground transition-colors hover:text-foreground",title:"Clear search",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto py-1",children:Y.length===0?e.jsx("div",{className:"px-4 py-3 text-center text-sm text-muted-foreground",children:"No matching branches"}):Y.map(D=>e.jsx("button",{onClick:()=>{le(D)},className:`w-full px-4 py-2 text-left text-sm transition-colors hover:bg-accent ${D===r?"bg-accent/50 text-foreground":"text-muted-foreground"}`,children:e.jsxs("span",{className:"flex items-center space-x-2",children:[D===r&&e.jsx(fe,{className:"h-3 w-3 text-primary"}),e.jsx("span",{className:D===r?"font-medium":"",children:D})]})},D))}),e.jsx("div",{className:"border-t border-border py-1",children:e.jsxs("button",{onClick:()=>{L(!0),$(!1)},className:"flex w-full items-center space-x-2 px-4 py-2 text-left text-sm transition-colors hover:bg-accent",children:[e.jsx(he,{className:"h-3 w-3"}),e.jsx("span",{children:"Create new branch"})]})})]})]}),e.jsxs("div",{className:`flex items-center ${t?"gap-1":"gap-2"}`,children:[a?.hasRemote&&e.jsx(e.Fragment,{children:a.hasUpstream?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>{N()},disabled:J,className:"flex items-center gap-1 rounded-lg bg-primary px-2.5 py-1 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",title:`Fetch from ${A}`,children:[e.jsx(V,{className:`h-3 w-3 ${i?"animate-spin":""}`}),!t&&e.jsx("span",{children:i?"Fetching…":"Fetch"})]}),C>0&&e.jsxs("button",{onClick:Q,disabled:J,className:"flex items-center gap-1 rounded-lg bg-green-600 px-2.5 py-1 text-sm text-white transition-colors hover:bg-green-700 disabled:opacity-50",title:`Pull ${C} from ${A}`,children:[e.jsx(Ze,{className:`h-3 w-3 ${g?"animate-pulse":""}`}),!t&&e.jsx("span",{children:g?"Pulling…":`Pull ${C}`})]}),_>0&&e.jsxs("button",{onClick:se,disabled:J,className:"flex items-center gap-1 rounded-lg bg-orange-600 px-2.5 py-1 text-sm text-white transition-colors hover:bg-orange-700 disabled:opacity-50",title:`Push ${_} to ${A}`,children:[e.jsx(Fe,{className:`h-3 w-3 ${x?"animate-pulse":""}`}),!t&&e.jsx("span",{children:x?"Pushing…":`Push ${_}`})]})]}):e.jsxs("button",{onClick:ie,disabled:J,className:"flex items-center gap-1 rounded-lg bg-primary px-2.5 py-1 text-sm text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",title:`Publish "${r}" to ${A}`,children:[e.jsx(Fe,{className:`h-3 w-3 ${m?"animate-pulse":""}`}),!t&&e.jsx("span",{children:m?"Publishing…":"Publish"})]})}),e.jsx("button",{onClick:ne,disabled:f,className:`rounded-lg transition-colors hover:bg-accent disabled:opacity-50 ${t?"p-1":"p-1.5"}`,title:"Revert latest local commit",children:e.jsx(Pe,{className:`text-muted-foreground ${f?"animate-pulse":""} ${t?"h-3 w-3":"h-4 w-4"}`})}),e.jsx("button",{onClick:y,disabled:o,className:`rounded-lg transition-colors hover:bg-accent ${t?"p-1":"p-1.5"}`,title:"Refresh git status",children:e.jsx(V,{className:`text-muted-foreground ${o?"animate-spin":""} ${t?"h-3 w-3":"h-4 w-4"}`})})]})]}),v&&e.jsxs("div",{className:"flex items-start gap-2 border-b border-destructive/20 bg-destructive/10 px-4 py-2.5 text-sm text-destructive",children:[e.jsx(jt,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{className:"flex-1 leading-snug",children:v}),e.jsx("button",{onClick:B,className:"shrink-0 rounded p-0.5 hover:bg-destructive/20","aria-label":"Dismiss error",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})]}),e.jsx(st,{isOpen:k,currentBranch:r,isCreatingBranch:d,onClose:()=>L(!1),onCreateBranch:u})]})}function or({error:t,details:r,canInitRepository:s=!1,isInitializingRepository:a=!1,initError:o,onInitRepository:d}){const i=s&&!!d;return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center px-6 py-12 text-muted-foreground",children:[e.jsx("div",{className:"mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-muted/50",children:e.jsx(P,{className:"h-8 w-8 opacity-40"})}),i?e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-3 text-center text-lg font-medium text-foreground",children:"No git repository"}),e.jsx("p",{className:"mb-6 max-w-md text-center text-sm leading-relaxed",children:"This project is not a git repository yet. Initialize one to start tracking changes and use source control features."}),e.jsx("button",{onClick:d,disabled:a,className:"flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:opacity-60",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"h-4 w-4 animate-spin"}),"Initializing repository..."]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-4 w-4"}),"Run git init"]})}),o&&e.jsx("p",{className:"mt-4 max-w-md text-center text-sm leading-relaxed text-destructive",children:o})]}):e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"mb-3 text-center text-lg font-medium text-foreground",children:t}),r&&e.jsx("p",{className:"max-w-md text-center text-sm leading-relaxed",children:r})]})]})}const ir=[{id:"changes",label:"Changes",Icon:wt},{id:"history",label:"Commits",Icon:Ke},{id:"branches",label:"Branches",Icon:P},{id:"worktrees",label:"Worktrees",Icon:we}];function lr({activeView:t,isHidden:r,changeCount:s,onChange:a}){return e.jsx("div",{className:`border-b border-border/60 transition-all duration-300 ease-in-out ${r?"max-h-0 -translate-y-2 overflow-hidden opacity-0":"max-h-16 translate-y-0 opacity-100"}`,children:e.jsx("div",{className:"scrollbar-hide flex w-full snap-x overflow-x-auto overscroll-x-contain [-webkit-overflow-scrolling:touch]",role:"tablist","aria-label":"Source control views",children:ir.map(({id:o,label:d,Icon:i})=>e.jsx("button",{type:"button",role:"tab","aria-selected":t===o,onClick:()=>a(o),className:`min-w-max flex-none snap-start px-4 py-2 text-sm font-medium transition-colors sm:min-w-0 sm:flex-1 ${t===o?"border-b-2 border-primary text-primary":"text-muted-foreground hover:text-foreground"}`,children:e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(i,{className:"h-4 w-4"}),e.jsx("span",{children:d}),o==="changes"&&s>0&&e.jsx("span",{className:"rounded-full bg-primary/15 px-1.5 py-0.5 text-xs font-semibold text-primary",children:s})]})},o))})})}function Qe(t){return t==="discard"||t==="delete"?e.jsx(oe,{className:"h-4 w-4"}):t==="commit"?e.jsx(fe,{className:"h-4 w-4"}):t==="pull"?e.jsx(Ze,{className:"h-4 w-4"}):t==="revertLocalCommit"?e.jsx(Pe,{className:"h-4 w-4"}):e.jsx(Fe,{className:"h-4 w-4"})}function cr({action:t,onCancel:r,onConfirm:s}){const[a,o]=n.useState(!1),d=t?`confirmation-title-${t.type}`:void 0,i=()=>{o(!1),r()},g=()=>{const x=a&&!!t?.alternateConfirmation;o(!1),s(x)};return n.useEffect(()=>{if(!t)return;const x=m=>{m.key==="Escape"&&(o(!1),r())};return window.addEventListener("keydown",x),()=>{window.removeEventListener("keydown",x)}},[t,r]),t?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",onClick:i}),e.jsxs("div",{className:"relative flex max-h-[calc(100dvh-2rem)] w-full max-w-md flex-col overflow-hidden rounded-xl border border-border bg-card shadow-2xl",role:"dialog","aria-modal":"true","aria-labelledby":d,children:[e.jsxs("div",{className:"flex shrink-0 items-center px-6 pt-6",children:[e.jsx("div",{className:`mr-3 rounded-full p-2 ${Tt[t.type]}`,children:Qe(t.type)}),e.jsx("h3",{id:d,className:"text-lg font-semibold text-foreground",children:$t[t.type]})]}),e.jsx("p",{className:"scrollbar-thin my-4 min-h-0 flex-1 overflow-y-auto overscroll-contain whitespace-pre-wrap break-words px-6 text-sm text-muted-foreground",children:t.message}),t.alternateConfirmation&&e.jsxs("label",{className:"mx-6 mb-5 flex cursor-pointer items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/5 p-3 transition-colors hover:bg-destructive/10",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:x=>o(x.target.checked),className:"mt-0.5 h-4 w-4 shrink-0 accent-destructive"}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-sm font-medium text-foreground",children:[e.jsx(vt,{className:"h-3.5 w-3.5 text-destructive"}),t.alternateConfirmation.label]}),e.jsx("span",{className:"mt-1 block text-xs leading-relaxed text-muted-foreground",children:t.alternateConfirmation.description})]})]}),e.jsxs("div",{className:"flex shrink-0 justify-end space-x-3 px-6 pb-6",children:[e.jsx("button",{onClick:i,className:"rounded-lg px-4 py-2 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:"Cancel"}),e.jsxs("button",{onClick:g,className:`flex items-center space-x-2 rounded-lg px-4 py-2 text-sm text-white transition-colors ${It[t.type]}`,children:[Qe(t.type),e.jsx("span",{children:a&&t.alternateConfirmation?t.alternateConfirmation.actionLabel:Et[t.type]})]})]})]})]}):null}function pr({selectedProject:t,isMobile:r=!1,onFileOpen:s,onProjectSelect:a,onProjectsRefresh:o}){const[d,i]=n.useState("changes"),[g,x]=n.useState(!0),[m,f]=n.useState(!1),[v,y]=n.useState(null),{gitStatus:p,gitDiff:j,isLoading:u,isLoadingCommits:N,currentBranch:h,branches:T,localBranches:I,remoteBranches:B,recentCommits:M,commitDiffs:w,remoteStatus:$,isCreatingBranch:k,isFetching:L,isPulling:S,isPushing:R,isPublishing:z,isCreatingInitialCommit:H,isInitializingRepository:Y,operationError:_,clearOperationError:C,refreshAll:A,switchBranch:J,createBranch:Q,deleteBranch:se,handleFetch:ie,handlePull:ne,handlePush:le,handlePublish:D,discardChanges:K,deleteUntrackedFile:G,stageFiles:ve,unstageFiles:X,fetchCommitDiff:pe,commitChanges:ge,createInitialCommit:E,initRepository:q,openFile:U}=At({selectedProject:t,activeView:d,onFileOpen:s}),{isRevertingLocalCommit:Ce,revertLatestLocalCommit:ke}=Ot({projectId:t?.projectId??null,onSuccess:A}),Se=n.useCallback(async(de=!1)=>{if(!v)return;const me=v;y(null);try{await(de?me.alternateConfirmation?.onConfirm??me.onConfirm:me.onConfirm)()}catch(be){console.error("Error executing confirmation action:",be)}},[v]),$e=tt(p),ce=!!p?.notGitRepository;return t?e.jsxs("div",{className:"flex h-full flex-col bg-background",children:[!ce&&e.jsx(ar,{isMobile:r,currentBranch:h,branches:T,remoteStatus:$,isLoading:u,isCreatingBranch:k,isFetching:L,isPulling:S,isPushing:R,isPublishing:z,isRevertingLocalCommit:Ce,operationError:_,onRefresh:A,onRevertLocalCommit:ke,onSwitchBranch:J,onCreateBranch:Q,onFetch:ie,onPull:ne,onPush:le,onPublish:D,onClearError:C,onRequestConfirmation:y}),p?.error?e.jsx(or,{error:p.error,details:p.details,canInitRepository:ce,isInitializingRepository:Y,initError:ce?_:null,onInitRepository:()=>{C(),q()}}):e.jsxs(e.Fragment,{children:[e.jsx(lr,{activeView:d,isHidden:m,changeCount:$e,onChange:i}),d==="changes"&&e.jsx(Gt,{isMobile:r,projectPath:t.fullPath,gitStatus:p,gitDiff:j,isLoading:u,wrapText:g,isCreatingInitialCommit:H,onWrapTextChange:x,onCreateInitialCommit:E,onOpenFile:U,onDiscardFile:K,onDeleteFile:G,onStageFiles:ve,onUnstageFiles:X,onCommitChanges:ge,onRequestConfirmation:y,onExpandedFilesChange:f},t.fullPath),d==="history"&&e.jsx(Qt,{isMobile:r,isLoading:u||M.length===0&&N,recentCommits:M,commitDiffs:w,wrapText:g,onFetchCommitDiff:pe}),d==="worktrees"&&e.jsx(nr,{isMobile:r,selectedProject:t,localBranches:I,onProjectSelect:a,onProjectsRefresh:o},t.fullPath),d==="branches"&&e.jsx(Kt,{isMobile:r,isLoading:u,currentBranch:h,localBranches:I,remoteBranches:B,remoteStatus:$,isCreatingBranch:k,onSwitchBranch:J,onCreateBranch:Q,onDeleteBranch:se,onRequestConfirmation:y})]}),e.jsx(cr,{action:v,onCancel:()=>y(null),onConfirm:de=>{Se(de)}})]}):e.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:e.jsx("p",{children:"Select a project to view source control"})})}export{pr as default};