termdock 1.4.263 → 1.4.264

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 (312) hide show
  1. package/dist/client/assets/{App-Be0tsVAS.js → App-C-sArfYM.js} +29 -29
  2. package/dist/client/assets/App-C-sArfYM.js.br +0 -0
  3. package/dist/client/assets/App-C-sArfYM.js.gz +0 -0
  4. package/dist/client/assets/{ChangeWalkthroughPanel-CzrJ6gJP.js → ChangeWalkthroughPanel-xq2AwXOA.js} +1 -1
  5. package/dist/client/assets/ChangeWalkthroughPanel-xq2AwXOA.js.br +0 -0
  6. package/dist/client/assets/ChangeWalkthroughPanel-xq2AwXOA.js.gz +0 -0
  7. package/dist/client/assets/{DagPlayground-C7RaD0hD.js → DagPlayground-C3ljSBdz.js} +1 -1
  8. package/dist/client/assets/DagPlayground-C3ljSBdz.js.br +0 -0
  9. package/dist/client/assets/DagPlayground-C3ljSBdz.js.gz +0 -0
  10. package/dist/client/assets/{DiffLab-Cl8rs4sk.js → DiffLab-Ducnm_Zp.js} +1 -1
  11. package/dist/client/assets/DiffLab-Ducnm_Zp.js.br +0 -0
  12. package/dist/client/assets/DiffLab-Ducnm_Zp.js.gz +0 -0
  13. package/dist/client/assets/{DiffReview-D4715gv-.js → DiffReview-zTuUIB7N.js} +1 -1
  14. package/dist/client/assets/DiffReview-zTuUIB7N.js.br +0 -0
  15. package/dist/client/assets/DiffReview-zTuUIB7N.js.gz +0 -0
  16. package/dist/client/assets/{DiffReviewLab-DelgnRri.js → DiffReviewLab-CBlF880M.js} +1 -1
  17. package/dist/client/assets/DiffReviewLab-CBlF880M.js.br +0 -0
  18. package/dist/client/assets/DiffReviewLab-CBlF880M.js.gz +0 -0
  19. package/dist/client/assets/{DiffViewer-DxGkdCpG.js → DiffViewer-D4UreLzY.js} +1 -1
  20. package/dist/client/assets/DiffViewer-D4UreLzY.js.br +0 -0
  21. package/dist/client/assets/DiffViewer-D4UreLzY.js.gz +0 -0
  22. package/dist/client/assets/{ModelPreview-COGEMw6A.js → ModelPreview-BPPustvB.js} +1 -1
  23. package/dist/client/assets/ModelPreview-BPPustvB.js.br +0 -0
  24. package/dist/client/assets/ModelPreview-BPPustvB.js.gz +0 -0
  25. package/dist/client/assets/{RightSidebar-B4lwUjHl.js → RightSidebar-BaDQ7Gpm.js} +44 -44
  26. package/dist/client/assets/RightSidebar-BaDQ7Gpm.js.br +0 -0
  27. package/dist/client/assets/RightSidebar-BaDQ7Gpm.js.gz +0 -0
  28. package/dist/client/assets/{abnfDiagram-VCTEODGH-COWpaiS-.js → abnfDiagram-VCTEODGH-CqyKSrWN.js} +1 -1
  29. package/dist/client/assets/abnfDiagram-VCTEODGH-CqyKSrWN.js.br +0 -0
  30. package/dist/client/assets/abnfDiagram-VCTEODGH-CqyKSrWN.js.gz +0 -0
  31. package/dist/client/assets/{app-DHnc6XU3.js → app-CacB_zmS.js} +9 -9
  32. package/dist/client/assets/app-CacB_zmS.js.br +0 -0
  33. package/dist/client/assets/app-CacB_zmS.js.gz +0 -0
  34. package/dist/client/assets/{arc-B5ZIGNkR.js → arc-BgwdpkOZ.js} +1 -1
  35. package/dist/client/assets/arc-BgwdpkOZ.js.br +0 -0
  36. package/dist/client/assets/arc-BgwdpkOZ.js.gz +0 -0
  37. package/dist/client/assets/{architectureDiagram-5GKGNRK7-D9KCt4gq.js → architectureDiagram-5GKGNRK7-N1kpYkPE.js} +1 -1
  38. package/dist/client/assets/architectureDiagram-5GKGNRK7-N1kpYkPE.js.br +0 -0
  39. package/dist/client/assets/architectureDiagram-5GKGNRK7-N1kpYkPE.js.gz +0 -0
  40. package/dist/client/assets/{blockDiagram-I7D4REHJ-wwBKtSqS.js → blockDiagram-I7D4REHJ-Dw81yows.js} +1 -1
  41. package/dist/client/assets/blockDiagram-I7D4REHJ-Dw81yows.js.br +0 -0
  42. package/dist/client/assets/blockDiagram-I7D4REHJ-Dw81yows.js.gz +0 -0
  43. package/dist/client/assets/{c4Diagram-7LVT6UL2-BSWUY2m8.js → c4Diagram-7LVT6UL2-D32t58M4.js} +1 -1
  44. package/dist/client/assets/c4Diagram-7LVT6UL2-D32t58M4.js.br +0 -0
  45. package/dist/client/assets/c4Diagram-7LVT6UL2-D32t58M4.js.gz +0 -0
  46. package/dist/client/assets/channel-DhLuwycJ.js +1 -0
  47. package/dist/client/assets/{chunk-2Q5K7J3B-C6tBCDpG.js → chunk-2Q5K7J3B-C9UvOdT5.js} +1 -1
  48. package/dist/client/assets/{chunk-5VM5RSS4-BboWsUGn.js → chunk-5VM5RSS4-CFC27MFf.js} +1 -1
  49. package/dist/client/assets/{chunk-F27PBJKO-t8LC2p6f.js → chunk-F27PBJKO-B4-9Xrnz.js} +1 -1
  50. package/dist/client/assets/chunk-F27PBJKO-B4-9Xrnz.js.br +0 -0
  51. package/dist/client/assets/chunk-F27PBJKO-B4-9Xrnz.js.gz +0 -0
  52. package/dist/client/assets/{chunk-IMKFNOWR-BLpilR76.js → chunk-IMKFNOWR-CsBaOmDp.js} +1 -1
  53. package/dist/client/assets/chunk-IMKFNOWR-CsBaOmDp.js.br +0 -0
  54. package/dist/client/assets/chunk-IMKFNOWR-CsBaOmDp.js.gz +0 -0
  55. package/dist/client/assets/{chunk-JWPE2WC7-UAJgqWvI.js → chunk-JWPE2WC7-Ck04aXnz.js} +1 -1
  56. package/dist/client/assets/{chunk-POPQ4Y6H-CpVzK8jo.js → chunk-POPQ4Y6H-BqcqNVVk.js} +1 -1
  57. package/dist/client/assets/{chunk-SVP7TREG-irhVxs6O.js → chunk-SVP7TREG-OpdssCsG.js} +1 -1
  58. package/dist/client/assets/chunk-SVP7TREG-OpdssCsG.js.br +0 -0
  59. package/dist/client/assets/chunk-SVP7TREG-OpdssCsG.js.gz +0 -0
  60. package/dist/client/assets/{chunk-TICWLB2K-Au4c5Tnt.js → chunk-TICWLB2K-CDexR7sW.js} +1 -1
  61. package/dist/client/assets/chunk-TICWLB2K-CDexR7sW.js.br +0 -0
  62. package/dist/client/assets/chunk-TICWLB2K-CDexR7sW.js.gz +0 -0
  63. package/dist/client/assets/{chunk-XXDRQBXY-NlJK-TD4.js → chunk-XXDRQBXY-DNtcUYbk.js} +1 -1
  64. package/dist/client/assets/{classDiagram-ZZMXUADV-ECZW8RQZ.js → classDiagram-ZZMXUADV-WqsEmR1Y.js} +1 -1
  65. package/dist/client/assets/{classDiagram-v2-VYDZK3BY-ECZW8RQZ.js → classDiagram-v2-VYDZK3BY-WqsEmR1Y.js} +1 -1
  66. package/dist/client/assets/{cose-bilkent-JH36ORCC-CBucN9Xa.js → cose-bilkent-JH36ORCC-cTbTSxj8.js} +1 -1
  67. package/dist/client/assets/cose-bilkent-JH36ORCC-cTbTSxj8.js.br +0 -0
  68. package/dist/client/assets/{cose-bilkent-JH36ORCC-CBucN9Xa.js.gz → cose-bilkent-JH36ORCC-cTbTSxj8.js.gz} +0 -0
  69. package/dist/client/assets/{cynefin-OW5HDTMX-DBkqdsPg.js → cynefin-OW5HDTMX-Rm2aJeBM.js} +1 -1
  70. package/dist/client/assets/cynefin-OW5HDTMX-Rm2aJeBM.js.br +0 -0
  71. package/dist/client/assets/cynefin-OW5HDTMX-Rm2aJeBM.js.gz +0 -0
  72. package/dist/client/assets/{cynefinDiagram-5FMLGOSQ-g-mNhqWP.js → cynefinDiagram-5FMLGOSQ-CBBrWwPa.js} +1 -1
  73. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-CBBrWwPa.js.br +0 -0
  74. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-CBBrWwPa.js.gz +0 -0
  75. package/dist/client/assets/{dagre-GXQ25YYZ-aMhTipKP.js → dagre-GXQ25YYZ-srDwDfcU.js} +1 -1
  76. package/dist/client/assets/dagre-GXQ25YYZ-srDwDfcU.js.br +0 -0
  77. package/dist/client/assets/dagre-GXQ25YYZ-srDwDfcU.js.gz +0 -0
  78. package/dist/client/assets/{diagram-S7CK7UJ4-FTXlqV5C.js → diagram-S7CK7UJ4-CTwLQY9V.js} +1 -1
  79. package/dist/client/assets/diagram-S7CK7UJ4-CTwLQY9V.js.br +0 -0
  80. package/dist/client/assets/diagram-S7CK7UJ4-CTwLQY9V.js.gz +0 -0
  81. package/dist/client/assets/{diagram-UQ7AKVKN-CWKlCxDh.js → diagram-UQ7AKVKN-BT_rALfG.js} +1 -1
  82. package/dist/client/assets/diagram-UQ7AKVKN-BT_rALfG.js.br +0 -0
  83. package/dist/client/assets/diagram-UQ7AKVKN-BT_rALfG.js.gz +0 -0
  84. package/dist/client/assets/{diagram-VSXAHHWV-DuCN1zfS.js → diagram-VSXAHHWV-BKsGk0lY.js} +1 -1
  85. package/dist/client/assets/diagram-VSXAHHWV-BKsGk0lY.js.br +0 -0
  86. package/dist/client/assets/diagram-VSXAHHWV-BKsGk0lY.js.gz +0 -0
  87. package/dist/client/assets/{diagram-VX7I27RA-BYYvrnH1.js → diagram-VX7I27RA-BYbtwhbM.js} +1 -1
  88. package/dist/client/assets/diagram-VX7I27RA-BYbtwhbM.js.br +0 -0
  89. package/dist/client/assets/diagram-VX7I27RA-BYbtwhbM.js.gz +0 -0
  90. package/dist/client/assets/{diagram-Z3DM3KII-BJ_UXuWt.js → diagram-Z3DM3KII-Db0I7mu4.js} +1 -1
  91. package/dist/client/assets/diagram-Z3DM3KII-Db0I7mu4.js.br +0 -0
  92. package/dist/client/assets/diagram-Z3DM3KII-Db0I7mu4.js.gz +0 -0
  93. package/dist/client/assets/{ebnfDiagram-PWID7BFC-BLb31-CG.js → ebnfDiagram-PWID7BFC-BWizg7gn.js} +1 -1
  94. package/dist/client/assets/ebnfDiagram-PWID7BFC-BWizg7gn.js.br +0 -0
  95. package/dist/client/assets/ebnfDiagram-PWID7BFC-BWizg7gn.js.gz +0 -0
  96. package/dist/client/assets/{erDiagram-RLTQ6QDP-Dt5T_zZr.js → erDiagram-RLTQ6QDP-BwUS8fPZ.js} +1 -1
  97. package/dist/client/assets/erDiagram-RLTQ6QDP-BwUS8fPZ.js.br +0 -0
  98. package/dist/client/assets/erDiagram-RLTQ6QDP-BwUS8fPZ.js.gz +0 -0
  99. package/dist/client/assets/{flowDiagram-HODETNUW-CC8Rn9fH.js → flowDiagram-HODETNUW-MAzdNa6g.js} +1 -1
  100. package/dist/client/assets/flowDiagram-HODETNUW-MAzdNa6g.js.br +0 -0
  101. package/dist/client/assets/flowDiagram-HODETNUW-MAzdNa6g.js.gz +0 -0
  102. package/dist/client/assets/{ganttDiagram-EL5Y4UJY-Bki2eBkC.js → ganttDiagram-EL5Y4UJY-C8VaA5zH.js} +1 -1
  103. package/dist/client/assets/ganttDiagram-EL5Y4UJY-C8VaA5zH.js.br +0 -0
  104. package/dist/client/assets/ganttDiagram-EL5Y4UJY-C8VaA5zH.js.gz +0 -0
  105. package/dist/client/assets/{gestureArbiter-BX-zjr4n.js → gestureArbiter-BkdwKXjM.js} +1 -1
  106. package/dist/client/assets/gestureArbiter-BkdwKXjM.js.br +0 -0
  107. package/dist/client/assets/gestureArbiter-BkdwKXjM.js.gz +0 -0
  108. package/dist/client/assets/{gitGraphDiagram-WWUBYQGX-DlR3hAyj.js → gitGraphDiagram-WWUBYQGX-BX2iDm_R.js} +1 -1
  109. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-BX2iDm_R.js.br +0 -0
  110. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-BX2iDm_R.js.gz +0 -0
  111. package/dist/client/assets/{index-ddQQwU7M.css → index-BbK6xNAN.css} +1 -1
  112. package/dist/client/assets/index-BbK6xNAN.css.br +0 -0
  113. package/dist/client/assets/{index-ddQQwU7M.css.gz → index-BbK6xNAN.css.gz} +0 -0
  114. package/dist/client/assets/{infoDiagram-27XIBGKW-C-5zXbqy.js → infoDiagram-27XIBGKW-Ns3hP0eV.js} +1 -1
  115. package/dist/client/assets/{ishikawaDiagram-5VMMS53U-D_KAjhux.js → ishikawaDiagram-5VMMS53U-Bv4pVCgQ.js} +1 -1
  116. package/dist/client/assets/ishikawaDiagram-5VMMS53U-Bv4pVCgQ.js.br +0 -0
  117. package/dist/client/assets/ishikawaDiagram-5VMMS53U-Bv4pVCgQ.js.gz +0 -0
  118. package/dist/client/assets/{journeyDiagram-3NMN7TZE-DasVMhbH.js → journeyDiagram-3NMN7TZE-DRRi377b.js} +1 -1
  119. package/dist/client/assets/journeyDiagram-3NMN7TZE-DRRi377b.js.br +0 -0
  120. package/dist/client/assets/journeyDiagram-3NMN7TZE-DRRi377b.js.gz +0 -0
  121. package/dist/client/assets/{kanban-definition-UXKFOSKX-BeDZ9x71.js → kanban-definition-UXKFOSKX-B7L-csMZ.js} +1 -1
  122. package/dist/client/assets/kanban-definition-UXKFOSKX-B7L-csMZ.js.br +0 -0
  123. package/dist/client/assets/kanban-definition-UXKFOSKX-B7L-csMZ.js.gz +0 -0
  124. package/dist/client/assets/{layout-BonFkvNe.js → layout-BxSxAk6Q.js} +1 -1
  125. package/dist/client/assets/{layout-BonFkvNe.js.br → layout-BxSxAk6Q.js.br} +0 -0
  126. package/dist/client/assets/layout-BxSxAk6Q.js.gz +0 -0
  127. package/dist/client/assets/{linear-amKhUz-E.js → linear-BXjh9BXc.js} +1 -1
  128. package/dist/client/assets/linear-BXjh9BXc.js.br +0 -0
  129. package/dist/client/assets/linear-BXjh9BXc.js.gz +0 -0
  130. package/dist/client/assets/{mermaid.core-C743W_cw.js → mermaid.core-5r_1zWs_.js} +5 -5
  131. package/dist/client/assets/mermaid.core-5r_1zWs_.js.br +0 -0
  132. package/dist/client/assets/mermaid.core-5r_1zWs_.js.gz +0 -0
  133. package/dist/client/assets/{mindmap-definition-YA3MSWOX-dnSMIb-2.js → mindmap-definition-YA3MSWOX-DUhDC9wQ.js} +1 -1
  134. package/dist/client/assets/mindmap-definition-YA3MSWOX-DUhDC9wQ.js.br +0 -0
  135. package/dist/client/assets/mindmap-definition-YA3MSWOX-DUhDC9wQ.js.gz +0 -0
  136. package/dist/client/assets/{passwordBootstrap-Z-zMfeRE.js → passwordBootstrap-Cwjat0qO.js} +1 -1
  137. package/dist/client/assets/passwordBootstrap-Cwjat0qO.js.br +0 -0
  138. package/dist/client/assets/passwordBootstrap-Cwjat0qO.js.gz +0 -0
  139. package/dist/client/assets/{pegDiagram-XKGWAZYB-BMMrDjH3.js → pegDiagram-XKGWAZYB-C-SLAJDe.js} +1 -1
  140. package/dist/client/assets/pegDiagram-XKGWAZYB-C-SLAJDe.js.br +0 -0
  141. package/dist/client/assets/pegDiagram-XKGWAZYB-C-SLAJDe.js.gz +0 -0
  142. package/dist/client/assets/{pieDiagram-E7YTZNPT-CGZ4yhWL.js → pieDiagram-E7YTZNPT-qRG_HAda.js} +1 -1
  143. package/dist/client/assets/pieDiagram-E7YTZNPT-qRG_HAda.js.br +0 -0
  144. package/dist/client/assets/pieDiagram-E7YTZNPT-qRG_HAda.js.gz +0 -0
  145. package/dist/client/assets/{quadrantDiagram-AXDQQJYC-BfUxBRZx.js → quadrantDiagram-AXDQQJYC-Cx85SpAC.js} +1 -1
  146. package/dist/client/assets/quadrantDiagram-AXDQQJYC-Cx85SpAC.js.br +0 -0
  147. package/dist/client/assets/quadrantDiagram-AXDQQJYC-Cx85SpAC.js.gz +0 -0
  148. package/dist/client/assets/{railroadDiagram-O6MQD6OU-DRtstXqY.js → railroadDiagram-O6MQD6OU-CHUzbbuc.js} +1 -1
  149. package/dist/client/assets/railroadDiagram-O6MQD6OU-CHUzbbuc.js.br +0 -0
  150. package/dist/client/assets/railroadDiagram-O6MQD6OU-CHUzbbuc.js.gz +0 -0
  151. package/dist/client/assets/{referenceLongPress-OgQ-br0J.js → referenceLongPress-CkmKcttc.js} +1 -1
  152. package/dist/client/assets/referenceLongPress-CkmKcttc.js.br +0 -0
  153. package/dist/client/assets/referenceLongPress-CkmKcttc.js.gz +0 -0
  154. package/dist/client/assets/{requirementDiagram-BXWQKSXE-jIWvwxYZ.js → requirementDiagram-BXWQKSXE-BMLDFHF4.js} +1 -1
  155. package/dist/client/assets/requirementDiagram-BXWQKSXE-BMLDFHF4.js.br +0 -0
  156. package/dist/client/assets/requirementDiagram-BXWQKSXE-BMLDFHF4.js.gz +0 -0
  157. package/dist/client/assets/{sankeyDiagram-P5KCCOFB-CmV9o38-.js → sankeyDiagram-P5KCCOFB-BWS5I_IL.js} +1 -1
  158. package/dist/client/assets/sankeyDiagram-P5KCCOFB-BWS5I_IL.js.br +0 -0
  159. package/dist/client/assets/sankeyDiagram-P5KCCOFB-BWS5I_IL.js.gz +0 -0
  160. package/dist/client/assets/{sequenceDiagram-WJ2MYXX4-C37VhGXR.js → sequenceDiagram-WJ2MYXX4-BPdGEV61.js} +1 -1
  161. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BPdGEV61.js.br +0 -0
  162. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-BPdGEV61.js.gz +0 -0
  163. package/dist/client/assets/{sizeCapture-INFHLROL-D3aZUvMq.js → sizeCapture-INFHLROL-oxQ5oK3g.js} +1 -1
  164. package/dist/client/assets/sizeCapture-INFHLROL-oxQ5oK3g.js.br +0 -0
  165. package/dist/client/assets/sizeCapture-INFHLROL-oxQ5oK3g.js.gz +0 -0
  166. package/dist/client/assets/{sparkles-BwJHncXI.js → sparkles-MZp-tT_G.js} +1 -1
  167. package/dist/client/assets/{stateDiagram-D77RDMKH-B3W9KWRf.js → stateDiagram-D77RDMKH-DtSfST46.js} +1 -1
  168. package/dist/client/assets/stateDiagram-D77RDMKH-DtSfST46.js.br +0 -0
  169. package/dist/client/assets/stateDiagram-D77RDMKH-DtSfST46.js.gz +0 -0
  170. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-BF_rwi5O.js +1 -0
  171. package/dist/client/assets/{swimlanes-42K2YHIH-CgFI-TZF.js → swimlanes-42K2YHIH-BqUlkZ_F.js} +1 -1
  172. package/dist/client/assets/swimlanes-42K2YHIH-BqUlkZ_F.js.br +0 -0
  173. package/dist/client/assets/swimlanes-42K2YHIH-BqUlkZ_F.js.gz +0 -0
  174. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-DP9kFtCd.js +8 -0
  175. package/dist/client/assets/{timeline-definition-24CTP7MA-Ad00a495.js → timeline-definition-24CTP7MA-B__ZTuwu.js} +1 -1
  176. package/dist/client/assets/timeline-definition-24CTP7MA-B__ZTuwu.js.br +0 -0
  177. package/dist/client/assets/timeline-definition-24CTP7MA-B__ZTuwu.js.gz +0 -0
  178. package/dist/client/assets/{triangle-alert-DDQ67k7N.js → triangle-alert-DN7qGh3M.js} +1 -1
  179. package/dist/client/assets/{vennDiagram-4TSXK5OY-CSawzFTi.js → vennDiagram-4TSXK5OY-C6JudjQT.js} +1 -1
  180. package/dist/client/assets/vennDiagram-4TSXK5OY-C6JudjQT.js.br +0 -0
  181. package/dist/client/assets/vennDiagram-4TSXK5OY-C6JudjQT.js.gz +0 -0
  182. package/dist/client/assets/{wardleyDiagram-VM6X3IG4-Emoh-n_o.js → wardleyDiagram-VM6X3IG4-BHt61gtN.js} +1 -1
  183. package/dist/client/assets/wardleyDiagram-VM6X3IG4-BHt61gtN.js.br +0 -0
  184. package/dist/client/assets/wardleyDiagram-VM6X3IG4-BHt61gtN.js.gz +0 -0
  185. package/dist/client/assets/{xychartDiagram-S5SC5T6Z-BPgImmcN.js → xychartDiagram-S5SC5T6Z-C0rZbFNo.js} +1 -1
  186. package/dist/client/assets/xychartDiagram-S5SC5T6Z-C0rZbFNo.js.br +0 -0
  187. package/dist/client/assets/xychartDiagram-S5SC5T6Z-C0rZbFNo.js.gz +0 -0
  188. package/dist/client/index.html +2 -2
  189. package/dist/client/index.html.br +0 -0
  190. package/dist/client/index.html.gz +0 -0
  191. package/dist/client/sw.js +1 -1
  192. package/dist/client/sw.js.br +0 -0
  193. package/dist/client/sw.js.gz +0 -0
  194. package/dist/server/routes/filesystem.js +13 -3
  195. package/package.json +1 -1
  196. package/runtime-manifest.json +3 -3
  197. package/dist/client/assets/App-Be0tsVAS.js.br +0 -0
  198. package/dist/client/assets/App-Be0tsVAS.js.gz +0 -0
  199. package/dist/client/assets/ChangeWalkthroughPanel-CzrJ6gJP.js.br +0 -0
  200. package/dist/client/assets/ChangeWalkthroughPanel-CzrJ6gJP.js.gz +0 -0
  201. package/dist/client/assets/DagPlayground-C7RaD0hD.js.br +0 -0
  202. package/dist/client/assets/DagPlayground-C7RaD0hD.js.gz +0 -0
  203. package/dist/client/assets/DiffLab-Cl8rs4sk.js.br +0 -0
  204. package/dist/client/assets/DiffLab-Cl8rs4sk.js.gz +0 -0
  205. package/dist/client/assets/DiffReview-D4715gv-.js.br +0 -0
  206. package/dist/client/assets/DiffReview-D4715gv-.js.gz +0 -0
  207. package/dist/client/assets/DiffReviewLab-DelgnRri.js.br +0 -0
  208. package/dist/client/assets/DiffReviewLab-DelgnRri.js.gz +0 -0
  209. package/dist/client/assets/DiffViewer-DxGkdCpG.js.br +0 -0
  210. package/dist/client/assets/DiffViewer-DxGkdCpG.js.gz +0 -0
  211. package/dist/client/assets/ModelPreview-COGEMw6A.js.br +0 -0
  212. package/dist/client/assets/ModelPreview-COGEMw6A.js.gz +0 -0
  213. package/dist/client/assets/RightSidebar-B4lwUjHl.js.br +0 -0
  214. package/dist/client/assets/RightSidebar-B4lwUjHl.js.gz +0 -0
  215. package/dist/client/assets/abnfDiagram-VCTEODGH-COWpaiS-.js.br +0 -0
  216. package/dist/client/assets/abnfDiagram-VCTEODGH-COWpaiS-.js.gz +0 -0
  217. package/dist/client/assets/app-DHnc6XU3.js.br +0 -0
  218. package/dist/client/assets/app-DHnc6XU3.js.gz +0 -0
  219. package/dist/client/assets/arc-B5ZIGNkR.js.br +0 -0
  220. package/dist/client/assets/arc-B5ZIGNkR.js.gz +0 -0
  221. package/dist/client/assets/architectureDiagram-5GKGNRK7-D9KCt4gq.js.br +0 -0
  222. package/dist/client/assets/architectureDiagram-5GKGNRK7-D9KCt4gq.js.gz +0 -0
  223. package/dist/client/assets/blockDiagram-I7D4REHJ-wwBKtSqS.js.br +0 -0
  224. package/dist/client/assets/blockDiagram-I7D4REHJ-wwBKtSqS.js.gz +0 -0
  225. package/dist/client/assets/c4Diagram-7LVT6UL2-BSWUY2m8.js.br +0 -0
  226. package/dist/client/assets/c4Diagram-7LVT6UL2-BSWUY2m8.js.gz +0 -0
  227. package/dist/client/assets/channel-TGPTnJaC.js +0 -1
  228. package/dist/client/assets/chunk-F27PBJKO-t8LC2p6f.js.br +0 -0
  229. package/dist/client/assets/chunk-F27PBJKO-t8LC2p6f.js.gz +0 -0
  230. package/dist/client/assets/chunk-IMKFNOWR-BLpilR76.js.br +0 -0
  231. package/dist/client/assets/chunk-IMKFNOWR-BLpilR76.js.gz +0 -0
  232. package/dist/client/assets/chunk-SVP7TREG-irhVxs6O.js.br +0 -0
  233. package/dist/client/assets/chunk-SVP7TREG-irhVxs6O.js.gz +0 -0
  234. package/dist/client/assets/chunk-TICWLB2K-Au4c5Tnt.js.br +0 -0
  235. package/dist/client/assets/chunk-TICWLB2K-Au4c5Tnt.js.gz +0 -0
  236. package/dist/client/assets/cose-bilkent-JH36ORCC-CBucN9Xa.js.br +0 -0
  237. package/dist/client/assets/cynefin-OW5HDTMX-DBkqdsPg.js.br +0 -0
  238. package/dist/client/assets/cynefin-OW5HDTMX-DBkqdsPg.js.gz +0 -0
  239. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-g-mNhqWP.js.br +0 -0
  240. package/dist/client/assets/cynefinDiagram-5FMLGOSQ-g-mNhqWP.js.gz +0 -0
  241. package/dist/client/assets/dagre-GXQ25YYZ-aMhTipKP.js.br +0 -0
  242. package/dist/client/assets/dagre-GXQ25YYZ-aMhTipKP.js.gz +0 -0
  243. package/dist/client/assets/diagram-S7CK7UJ4-FTXlqV5C.js.br +0 -0
  244. package/dist/client/assets/diagram-S7CK7UJ4-FTXlqV5C.js.gz +0 -0
  245. package/dist/client/assets/diagram-UQ7AKVKN-CWKlCxDh.js.br +0 -0
  246. package/dist/client/assets/diagram-UQ7AKVKN-CWKlCxDh.js.gz +0 -0
  247. package/dist/client/assets/diagram-VSXAHHWV-DuCN1zfS.js.br +0 -0
  248. package/dist/client/assets/diagram-VSXAHHWV-DuCN1zfS.js.gz +0 -0
  249. package/dist/client/assets/diagram-VX7I27RA-BYYvrnH1.js.br +0 -0
  250. package/dist/client/assets/diagram-VX7I27RA-BYYvrnH1.js.gz +0 -0
  251. package/dist/client/assets/diagram-Z3DM3KII-BJ_UXuWt.js.br +0 -0
  252. package/dist/client/assets/diagram-Z3DM3KII-BJ_UXuWt.js.gz +0 -0
  253. package/dist/client/assets/ebnfDiagram-PWID7BFC-BLb31-CG.js.br +0 -0
  254. package/dist/client/assets/ebnfDiagram-PWID7BFC-BLb31-CG.js.gz +0 -0
  255. package/dist/client/assets/erDiagram-RLTQ6QDP-Dt5T_zZr.js.br +0 -0
  256. package/dist/client/assets/erDiagram-RLTQ6QDP-Dt5T_zZr.js.gz +0 -0
  257. package/dist/client/assets/flowDiagram-HODETNUW-CC8Rn9fH.js.br +0 -0
  258. package/dist/client/assets/flowDiagram-HODETNUW-CC8Rn9fH.js.gz +0 -0
  259. package/dist/client/assets/ganttDiagram-EL5Y4UJY-Bki2eBkC.js.br +0 -0
  260. package/dist/client/assets/ganttDiagram-EL5Y4UJY-Bki2eBkC.js.gz +0 -0
  261. package/dist/client/assets/gestureArbiter-BX-zjr4n.js.br +0 -0
  262. package/dist/client/assets/gestureArbiter-BX-zjr4n.js.gz +0 -0
  263. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-DlR3hAyj.js.br +0 -0
  264. package/dist/client/assets/gitGraphDiagram-WWUBYQGX-DlR3hAyj.js.gz +0 -0
  265. package/dist/client/assets/index-ddQQwU7M.css.br +0 -0
  266. package/dist/client/assets/ishikawaDiagram-5VMMS53U-D_KAjhux.js.br +0 -0
  267. package/dist/client/assets/ishikawaDiagram-5VMMS53U-D_KAjhux.js.gz +0 -0
  268. package/dist/client/assets/journeyDiagram-3NMN7TZE-DasVMhbH.js.br +0 -0
  269. package/dist/client/assets/journeyDiagram-3NMN7TZE-DasVMhbH.js.gz +0 -0
  270. package/dist/client/assets/kanban-definition-UXKFOSKX-BeDZ9x71.js.br +0 -0
  271. package/dist/client/assets/kanban-definition-UXKFOSKX-BeDZ9x71.js.gz +0 -0
  272. package/dist/client/assets/layout-BonFkvNe.js.gz +0 -0
  273. package/dist/client/assets/linear-amKhUz-E.js.br +0 -0
  274. package/dist/client/assets/linear-amKhUz-E.js.gz +0 -0
  275. package/dist/client/assets/mermaid.core-C743W_cw.js.br +0 -0
  276. package/dist/client/assets/mermaid.core-C743W_cw.js.gz +0 -0
  277. package/dist/client/assets/mindmap-definition-YA3MSWOX-dnSMIb-2.js.br +0 -0
  278. package/dist/client/assets/mindmap-definition-YA3MSWOX-dnSMIb-2.js.gz +0 -0
  279. package/dist/client/assets/passwordBootstrap-Z-zMfeRE.js.br +0 -0
  280. package/dist/client/assets/passwordBootstrap-Z-zMfeRE.js.gz +0 -0
  281. package/dist/client/assets/pegDiagram-XKGWAZYB-BMMrDjH3.js.br +0 -0
  282. package/dist/client/assets/pegDiagram-XKGWAZYB-BMMrDjH3.js.gz +0 -0
  283. package/dist/client/assets/pieDiagram-E7YTZNPT-CGZ4yhWL.js.br +0 -0
  284. package/dist/client/assets/pieDiagram-E7YTZNPT-CGZ4yhWL.js.gz +0 -0
  285. package/dist/client/assets/quadrantDiagram-AXDQQJYC-BfUxBRZx.js.br +0 -0
  286. package/dist/client/assets/quadrantDiagram-AXDQQJYC-BfUxBRZx.js.gz +0 -0
  287. package/dist/client/assets/railroadDiagram-O6MQD6OU-DRtstXqY.js.br +0 -0
  288. package/dist/client/assets/railroadDiagram-O6MQD6OU-DRtstXqY.js.gz +0 -0
  289. package/dist/client/assets/referenceLongPress-OgQ-br0J.js.br +0 -0
  290. package/dist/client/assets/referenceLongPress-OgQ-br0J.js.gz +0 -0
  291. package/dist/client/assets/requirementDiagram-BXWQKSXE-jIWvwxYZ.js.br +0 -0
  292. package/dist/client/assets/requirementDiagram-BXWQKSXE-jIWvwxYZ.js.gz +0 -0
  293. package/dist/client/assets/sankeyDiagram-P5KCCOFB-CmV9o38-.js.br +0 -0
  294. package/dist/client/assets/sankeyDiagram-P5KCCOFB-CmV9o38-.js.gz +0 -0
  295. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-C37VhGXR.js.br +0 -0
  296. package/dist/client/assets/sequenceDiagram-WJ2MYXX4-C37VhGXR.js.gz +0 -0
  297. package/dist/client/assets/sizeCapture-INFHLROL-D3aZUvMq.js.br +0 -0
  298. package/dist/client/assets/sizeCapture-INFHLROL-D3aZUvMq.js.gz +0 -0
  299. package/dist/client/assets/stateDiagram-D77RDMKH-B3W9KWRf.js.br +0 -0
  300. package/dist/client/assets/stateDiagram-D77RDMKH-B3W9KWRf.js.gz +0 -0
  301. package/dist/client/assets/stateDiagram-v2-MP3YSRHH-D9yMXUEN.js +0 -1
  302. package/dist/client/assets/swimlanes-42K2YHIH-CgFI-TZF.js.br +0 -0
  303. package/dist/client/assets/swimlanes-42K2YHIH-CgFI-TZF.js.gz +0 -0
  304. package/dist/client/assets/swimlanesDiagram-VR7AAH4N-DfgFmAr4.js +0 -8
  305. package/dist/client/assets/timeline-definition-24CTP7MA-Ad00a495.js.br +0 -0
  306. package/dist/client/assets/timeline-definition-24CTP7MA-Ad00a495.js.gz +0 -0
  307. package/dist/client/assets/vennDiagram-4TSXK5OY-CSawzFTi.js.br +0 -0
  308. package/dist/client/assets/vennDiagram-4TSXK5OY-CSawzFTi.js.gz +0 -0
  309. package/dist/client/assets/wardleyDiagram-VM6X3IG4-Emoh-n_o.js.br +0 -0
  310. package/dist/client/assets/wardleyDiagram-VM6X3IG4-Emoh-n_o.js.gz +0 -0
  311. package/dist/client/assets/xychartDiagram-S5SC5T6Z-BPgImmcN.js.br +0 -0
  312. package/dist/client/assets/xychartDiagram-S5SC5T6Z-BPgImmcN.js.gz +0 -0
@@ -1,17 +1,17 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-COGEMw6A.js","assets/app-DHnc6XU3.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-ddQQwU7M.css","assets/App-Be0tsVAS.js","assets/gestureArbiter-BX-zjr4n.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-DDQ67k7N.js","assets/referenceLongPress-OgQ-br0J.js","assets/DiffReview-D4715gv-.js","assets/sparkles-BwJHncXI.js","assets/DiffViewer-DxGkdCpG.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-CzrJ6gJP.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-C743W_cw.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
2
- import{a4 as Tr,bf as e,cJ as jt,cT as $t,bx as ut,a as Ps,aO as Zd,C as Ci,c as Ts,X as Kt,cG as Ni,b3 as Ah,z as ks,am as Ph,cN as J,b7 as Th,b9 as Ji,ba as Ih,bb as Qd,b8 as Ss,az as Dh,E as Fh,i as _h,b6 as Bh,bz as Oh,bB as Uh,bC as Hh,a_ as zh,bA as Zc,y as kt,f as Wh,L as St,v as Gh,b as Kh,cI as Qc,aZ as ed,av as td,ar as qh,aD as Pa,aE as rd,cU as Es,ai as js,aF as Vh,cH as Ta,br as Yh,cs as nd,ax as Xh,cE as Jh,c0 as Zh,aI as Qh,O as sd,N as em,as as tm,aw as rm,aB as ad,c2 as nm,s as sm,d as Ia,g as Mi,m as od,w as eu,ae as am,_ as Is,bW as om,cR as im,bm as lm,ag as cm}from"./app-DHnc6XU3.js";import{q as tu,k as dm,r as id,v as Ya,g as um,V as fm,P as hm,o as mm,i as pm,M as gm,R as Ei,w as ru,x as bm,S as Zn,D as xm,e as nu,c as vm,J as su,A as ld,I as ym,B as Da,y as wm,z as km,E as cd,K as dd,T as ud,H as fd,f as hd,n as ii,m as Fa,d as Sm,s as jm,l as Rm,h as Cm,t as Nm,F as md,C as Mm,a as Em,G as $m}from"./App-Be0tsVAS.js";import{b as a,r as rn}from"./dnd-BCFAPC0L.js";import{a as pd,S as gd,b as au,c as $i,F as Lm}from"./gestureArbiter-BX-zjr4n.js";import{D as Li,C as $s,L as ou,f as Am,n as Pm}from"./DiffReview-D4715gv-.js";import{T as Tm,L as Qa,M as iu,G as Ar}from"./triangle-alert-DDQ67k7N.js";import{S as Ds}from"./sparkles-BwJHncXI.js";import{C as lu,M as cu}from"./ChangeWalkthroughPanel-CzrJ6gJP.js";import{r as du,s as uu,l as fu,a as bd,h as Ai,u as Im,g as Pi,b as hu}from"./DiffViewer-DxGkdCpG.js";import{u as mu,G as pu}from"./referenceLongPress-OgQ-br0J.js";const Dm=[["path",{d:"m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16",key:"d5nyq2"}],["path",{d:"M22 9v7",key:"pvm9v3"}],["path",{d:"M3.304 13h6.392",key:"1q3zxz"}],["circle",{cx:"18.5",cy:"12.5",r:"3.5",key:"z97x68"}]],Fm=Tr("case-sensitive",Dm);const _m=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],Bm=Tr("eye-off",_m);const Om=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Ti=Tr("eye",Om);const Um=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Ii=Tr("file-text",Um);const Hm=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],zm=Tr("image-plus",Hm);const Wm=[["path",{d:"M17 3v10",key:"15fgeh"}],["path",{d:"m12.67 5.5 8.66 5",key:"1gpheq"}],["path",{d:"m12.67 10.5 8.66-5",key:"1dkfa6"}],["path",{d:"M9 17a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2v-2z",key:"swwfx4"}]],Gm=Tr("regex",Wm);const Km=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]],qm=Tr("scan",Km);const Vm=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Ym=Tr("upload",Vm);const Xm=[["circle",{cx:"7",cy:"12",r:"3",key:"12clwm"}],["path",{d:"M10 9v6",key:"17i7lo"}],["circle",{cx:"17",cy:"12",r:"3",key:"gl7c2s"}],["path",{d:"M14 7v8",key:"dl84cr"}],["path",{d:"M22 17v1c0 .5-.5 1-1 1H3c-.5 0-1-.5-1-1v-1",key:"lt2kga"}]],Jm=Tr("whole-word",Xm);async function Zm(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function Qm({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:u,load:c}){a.useEffect(()=>{if(!r||!n||s||u.current===n)return;const h=window.setTimeout(()=>{u.current=n,c(n)},l);return()=>window.clearTimeout(h)},[r,n,s,l,u,c])}function ep(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,u=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!u)return Promise.resolve(null);const c=r instanceof HTMLImageElement?1400/Math.max(l,u):Math.min(1,1400/Math.max(l,u)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*c)),h.height=Math.max(1,Math.round(u*c));const p=h.getContext("2d");if(!p)return Promise.resolve(null);const g=getComputedStyle(document.documentElement);if(p.fillStyle=g.getPropertyValue("--surface").trim()||"white",p.fillRect(0,0,h.width,h.height),p.drawImage(r,0,0,h.width,h.height),s){const b=Math.max(10,Math.min(16,h.width/35));p.font=`${b}px sans-serif`;const f=[];let k="";for(const y of s.split(" "))k&&p.measureText(`${k} ${y}`).width>h.width-20?(f.push(k),k=y):k=k?`${k} ${y}`:y;k&&f.push(k),p.fillStyle=g.getPropertyValue("--surface").trim()||"white",p.fillRect(0,0,h.width,f.length*(b+4)+12),p.fillStyle=g.getPropertyValue("--foreground").trim()||"black",f.forEach((y,C)=>p.fillText(y,10,8+b+C*(b+4)))}if(n){const b=n.xPercent*h.width/100,f=n.yPercent*h.height/100,k=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=k*1.6;p.strokeStyle=g.getPropertyValue("--primary").trim()||"black",p.lineWidth=Math.max(1,k/3),p.beginPath(),p.arc(b,f,k,0,Math.PI*2),p.stroke(),p.beginPath(),p.moveTo(b-y,f),p.lineTo(b+y,f),p.moveTo(b,f-y),p.lineTo(b,f+y),p.stroke()}return new Promise(b=>h.toBlob(b,"image/png"))}catch{return Promise.resolve(null)}}function tp(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
- `)}function Qb(r,n,s){const l=n*Math.PI/360,u=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(u)*1.15}async function rp(r,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(r,n);return}const u=new Date().toISOString(),c=new AbortController;let h,p;try{p=await Promise.race([(async()=>{const g=await s.snapshot;if(!(!g||c.signal.aborted||!l.isCurrent()))return l.upload(new File([g],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(g=>{h=setTimeout(()=>{c.abort(),g(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(p?tp(r,"",u,p):r,n)}function np(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function xd(r,n){return`${r??""}\0${n}`}function sp(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=xd(n,s);let u=0,c=0;for(const h of r){const p=[h.filePath,h.newPath,h.oldPath].filter(b=>typeof b=="string"&&b.length>0);(p.some(b=>xd(h.repoRoot,b)===l)||p.some(b=>np(b,s)))&&(u+=1)}return{explained:u,stale:c}}function ap({status:r}){if(!r)return null;const n=r.stale>0&&r.explained===0;if(!(r.explained>0||r.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(Tm,{size:10}):e.jsx(Ds,{size:10})})}function Di({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(ap,{status:n})]})}const gu="termdock:right-sidebar:diff-change-list-mode:v1";function op(r){return r==="list"||r==="tree"}function ip(){return ut(gu,op)??"tree"}function lp(r){for(const l of r){const u=l.hunk;if(u.oldPath&&u.newPath&&u.oldPath!==u.newPath)return"renamed";if(!u.oldPath&&u.newPath)return"added";if(u.oldPath&&!u.newPath)return"deleted"}const n=r.some(l=>l.hunk.additions>0),s=r.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function cp(r){const n=new Map;for(const l of r){const u=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};u.items.push(l),u.additions+=l.hunk.additions,u.deletions+=l.hunk.deletions,l.current&&(u.explained+=1),l.stale&&(u.stale+=1),n.set(l.hunk.filePath,u)}const s=Array.from(n.values()).sort((l,u)=>l.filePath.localeCompare(u.filePath));for(const l of s)l.changeType=lp(l.items);return s}function dp(r){const n=r.filePath.split("/").pop()??r.filePath;return{key:r.key,path:r.filePath,displayName:n,displayDir:r.filePath.includes("/")?r.filePath.slice(0,-n.length-1):"",status:r.changeType,title:r.filePath}}function up(r,n){const s=r.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],u=new Set;for(const[c,h]of s.entries()){const p=h.split(`
4
- `),g=p.findIndex(k=>k.startsWith("@@ "));if(g<0){l.push(...p);continue}c===0&&l.push(...p.slice(0,g));const b=n[c];let f=g;for(;f>=0&&f<p.length;){const k=p.findIndex((E,N)=>N>f&&E.startsWith("@@ ")),y=k>=0?k:p.length,C=p.slice(f,y),D=C[0]??"",_=b?D===b:!0,B=D||b||C.join(`
5
- `);_&&!u.has(B)&&(l.push(...C),u.add(B)),f=k}}return l.join(`
6
- `)}function fp({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=up(s.items.map(p=>p.hunk.diff||p.current?.diff||p.stale?.diff||""),s.items.map(p=>p.hunk.hunkHeader)),u=s.items.map(p=>p.current??p.stale).filter(p=>!!p).map(p=>({id:p.id,repoRoot:p.repoRoot,filePath:p.filePath,oldPath:p.oldPath,newPath:p.newPath,hunkHeader:p.hunkHeader,hunkIndex:p.hunkIndex,fingerprint:p.fingerprint,diff:p.diff,explanation:p.explanation,summary:p.summary,workspaceRoot:p.workspaceRoot,generatedBy:p.generatedBy,injectedAt:p.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"";return{key:s.key,path:s.filePath,absolutePath:u[0]?.repoRoot?`${u[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:u[0]?.repoRoot??null,displayName:c,displayDir:h,diffOverride:l,auditRecords:u,onInsertDiffReference:n}})}function hp(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=r.getBoundingClientRect().top+48;let h=null,p=Number.POSITIVE_INFINITY;for(const b of l){const f=b.getBoundingClientRect();if(f.bottom<c)continue;const k=Math.abs(f.top-c);k<p&&(h=b,p=k)}const g=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!g||g===n||s(g),g}function vd({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:u=!1,backLabel:c="Back",headerTitle:h,headerMeta:p,onClose:g,closeLabel:b="Back",wrap:f=!0,onToggleWrap:k,wrapTitle:y,wrapOnLabel:C="Wrap on",wrapOffLabel:D="Wrap off",desktopLayout:_="split",onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:N,copiedReferenceKey:$,onClearAuditRecord:T,onRefresh:U,refreshing:F,refreshLabel:m,refreshTitle:i,walkthroughs:O=[],onWalkthroughNavigate:R,initialDetailScrollTop:G,onDetailScrollPositionChange:fe,scrollToKey:te,scrollToKeyNonce:xe,externalSwiperRef:W,onMobileSlideChange:Y}){const{t:L}=jt(),I=a.useMemo(()=>cp(r),[r]),K=a.useMemo(()=>new Map(I.map(q=>[q.key,q])),[I]),[re,ce]=a.useState(()=>ip()),[ve,pe]=a.useState(()=>new Set),[Me,M]=a.useState({key:null,nonce:0}),Z=I.find(q=>q.explained>0||q.stale>0)?.key??I[0]?.key??null,he=n&&I.some(q=>q.key===n)?n:Z,Ne=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:I.map(dp)}],[I]),Ve=a.useMemo(()=>fp({groups:I,onInsertDiffReference:B}),[I,B]),Ce=a.useRef(Z),Ye=a.useRef(s);Ce.current=Z,Ye.current=s,a.useEffect(()=>{!n&&Ce.current&&Ye.current(Ce.current)},[n]);const Ie=k?e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?C:D})]}):null,S=U?e.jsxs("button",{type:"button",onClick:U,disabled:F,title:i??m,"aria-label":i??m,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(tu,{size:12,className:F?"animate-spin":""}),m&&e.jsx("span",{children:m})]}):null,Q=q=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),p&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:p})]}),g&&e.jsxs("button",{type:"button",onClick:g,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[e.jsx(Ps,{size:14}),b]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[q,S,Ie]})]});if(r.length===0){const q=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!g?q:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[Q(null),q]})}const le=k||U?({slideToList:q})=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:q,children:[e.jsx(Ps,{size:14}),c]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[S,k&&e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?C:D})]})]})]}):void 0;return e.jsx(Li,{mobile:u,desktopLayout:_,backLabel:c,groups:Ne,selectedKey:he,mode:re,onModeChange:q=>{ce(q),q!=="ai"&&$t(gu,q)},compact:u,collapsedDirectoryKeys:ve,onToggleDirectory:q=>{pe(me=>{const Ae=new Set(me);return Ae.has(q)?Ae.delete(q):Ae.add(q),Ae})},onSelectFile:q=>{s(q.key),M(me=>({key:q.key,nonce:me.nonce+1}))},renderLeading:q=>{const me=K.get(q.key);return e.jsx(Di,{changeStatus:q.status,auditStatus:me,renderChangeBadge:Ae=>e.jsx($s,{status:Ae})})},renderTrailing:q=>{const me=K.get(q.key);return me?e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",me.additions," -",me.deletions]}):null},renderListHeader:Q,aiContent:({slideToDetail:q,fullscreen:me,toggleFullscreen:Ae})=>O.length>0&&R?e.jsx(lu,{walkthroughs:O,repoRoot:O[0]?.repoRoot,fullscreen:me,onToggleFullscreen:Ae,onNavigate:oe=>{u&&window.requestAnimationFrame(q),R(oe)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:L("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:le,externalSwiperRef:W,onMobileSlideChange:Y,detailContainerClassName:u?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:G,scrollToKey:te??Me.key,scrollToKeyNonce:te==null?Me.nonce:xe,onDetailScroll:q=>{hp(q,he,s),fe?.(q.scrollTop)},files:Ve,activePane:!0,wrap:f,renderStreamBadge:(q,me)=>{const Ae=K.get(me.key);return e.jsx(Di,{changeStatus:q,auditStatus:Ae,renderChangeBadge:oe=>e.jsx($s,{status:oe})})},onInsertDiffReference:B,onReferenceCopied:E,insertedReferenceKey:N,copiedReferenceKey:$,onClearAuditRecord:T,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function mp(r){return r.replace(/\/+$/,"")||"/"}function pp(r){return[...new Set(Array.from(r,mp))].sort((n,s)=>n.localeCompare(s))}function gp(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function bp(r){let n=null;return{applicableEvents:r.filter(l=>{const u=l.type==="rescan-required"&&!gp(l.reason);return u&&l.reason&&!n&&(n=l.reason),!u}),unavailableReason:n}}const xp=1400,vp=1200,bu=44,yp=.7;function li(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function Fi(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function wp(r){try{const n=window.localStorage.getItem(Fi(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=bu?s:null}catch{return null}}function yd(r,n){try{n===null?window.localStorage.removeItem(Fi(r)):window.localStorage.setItem(Fi(r),String(n))}catch{}}function _a(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function kp({value:r,collapsed:n,labels:s,focusRequest:l,insertError:u,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:p,onAutoCollapseAfterSendChange:g,onDisable:b,onClear:f,onInsert:k,onInsertAndSend:y}){const[C,D]=a.useState(null),[_,B]=a.useState(!1),[E,N]=a.useState(()=>wp(li())),$=a.useRef(E),T=a.useRef(null),U=a.useRef(null),F=a.useRef(r),m=a.useRef(null),i=a.useRef(null),O=!!r.trim(),R=r.trim().split(`
7
- `)[0]??"",G=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>()=>{T.current!==null&&window.clearTimeout(T.current),U.current!==null&&window.clearTimeout(U.current)},[]),a.useEffect(()=>{let M=!1;const Z=li();return Zd().then(he=>{if(M)return;const Ne=he.contextDraftHeight?.[Z]??null;yd(Z,Ne),$.current=Ne,N(Ne)}).catch(()=>{}),()=>{M=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const M=m.current;if(!M)return;_a()||M.focus(),M.setSelectionRange(M.value.length,M.value.length),M.scrollTop=M.scrollHeight}},[l]),a.useEffect(()=>{const M=F.current;F.current=r,!(!n||r.length<=M.length)&&(B(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,B(!1)},vp))},[r,n]),a.useEffect(()=>{if(n)return;const M=m.current;M&&(M.style.height=E!==null?`${E}px`:"")},[r,n,E]),a.useEffect(()=>{if(n)return;const M=m.current;!M||document.activeElement===M||(M.scrollTop=M.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||_a())return;const M=m.current;!M||document.activeElement===M||(M.focus(),M.setSelectionRange(M.value.length,M.value.length))},[n]);const fe=a.useRef(null);a.useLayoutEffect(()=>{if(!_a())return;const M=window.visualViewport;if(!M)return;const Z=()=>{const he=fe.current;if(!he)return;if(M.height>=window.innerHeight*.75){he.style.transform="";return}const Ne=he.getBoundingClientRect(),Ve=Math.round(M.height-Ne.bottom);he.style.transform=Ve!==0?`translateY(${Ve}px)`:""};return Z(),M.addEventListener("resize",Z),M.addEventListener("scroll",Z),()=>{M.removeEventListener("resize",Z),M.removeEventListener("scroll",Z),fe.current&&(fe.current.style.transform="")}},[n]);const te=M=>{D(M),T.current!==null&&window.clearTimeout(T.current),T.current=window.setTimeout(()=>{T.current=null,D(null)},xp)},xe=M=>{p(!1),_a()&&window.requestAnimationFrame(()=>{const Z=m.current;if(!Z)return;Z.focus();const he=Z.value.length;Z.setSelectionRange(he,he),window.requestAnimationFrame(()=>{Z.setSelectionRange(he,he)})})},W=()=>{k(),te("inserted")},Y=()=>{O&&(y(),te("sent"))},L=M=>{if(M.key==="Escape"){M.preventDefault(),p(!0);return}M.key!=="Enter"||!M.metaKey&&!M.ctrlKey||(M.preventDefault(),Y())},I=M=>{M.preventDefault()},K=M=>{M.preventDefault();const Z=m.current;Z&&(i.current={startY:M.clientY,startHeight:Z.getBoundingClientRect().height},M.currentTarget.setPointerCapture?.(M.pointerId))},re=M=>{const Z=i.current;if(!Z)return;const he=window.visualViewport?.height??window.innerHeight,Ne=Math.round(Math.min(Math.max(Z.startHeight+(Z.startY-M.clientY),bu),he*yp));$.current=Ne,N(Ne)},ce=M=>{const Z=li();yd(Z,M),Ni({contextDraftHeight:{[Z]:M}}).catch(()=>{})},ve=()=>{i.current&&(i.current=null,$.current!==null&&ce($.current))},pe=()=>{$.current=null,N(null),ce(null)},Me=r.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(r.length)});return n?e.jsx("section",{ref:fe,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:e.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[e.jsxs("button",{type:"button",onClick:()=>xe(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":s.expand,title:s.expand,children:[e.jsx(dm,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${u?"text-destructive":_?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:u??(_?s.appended:O?R:s.title)})]}),Me,e.jsx("button",{type:"button",onClick:Y,disabled:!O,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${O?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:C==="sent"?e.jsx(Ci,{size:12}):e.jsx(id,{size:12})})]})}):e.jsxs("section",{ref:fe,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[e.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:K,onPointerMove:re,onPointerUp:ve,onPointerCancel:ve,onDoubleClick:pe,title:s.resize,"aria-hidden":"true",children:e.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),e.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[e.jsxs("button",{type:"button",onPointerDown:I,onClick:()=>p(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(Ts,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:"truncate text-[10px] font-medium text-foreground/75",children:s.title}),Me]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:I,onClick:()=>g(!c),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${c?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${c?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:I,onClick:b,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Kt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:m,value:r,onChange:M=>h(M.target.value),onKeyDown:L,placeholder:s.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),e.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[e.jsx("button",{type:"button",onPointerDown:I,onClick:f,disabled:!O,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":s.clear,title:s.clear,children:e.jsx(Ya,{size:11})}),u?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:u}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:I,onClick:W,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(um,{size:11}),e.jsx("span",{children:C==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:I,onClick:Y,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${s.insertAndSend} · ${G}`,children:[C==="sent"?e.jsx(Ci,{size:11}):e.jsx(id,{size:11}),e.jsx("span",{children:C==="sent"?s.sent:s.send})]})]})]})})]})}function Sp(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ModelPreview-BPPustvB.js","assets/app-CacB_zmS.js","assets/react-XDCjal2T.js","assets/dnd-BCFAPC0L.js","assets/terminal-C7X98Amf.js","assets/index-BbK6xNAN.css","assets/App-C-sArfYM.js","assets/gestureArbiter-BkdwKXjM.js","assets/gestureArbiter-C2J0D0kV.css","assets/triangle-alert-DN7qGh3M.js","assets/referenceLongPress-CkmKcttc.js","assets/DiffReview-zTuUIB7N.js","assets/sparkles-MZp-tT_G.js","assets/DiffViewer-D4UreLzY.js","assets/DiffViewer-T3uj2-aP.css","assets/ChangeWalkthroughPanel-xq2AwXOA.js","assets/katex-55ZPZeOF.css","assets/mermaid.core-5r_1zWs_.js","assets/purify.es-4eNOHKSq.js"])))=>i.map(i=>d[i]);
2
+ import{a4 as Tr,bf as e,cJ as wt,cT as $t,bx as ut,a as Ts,aO as tu,C as Ni,c as Is,X as Kt,cG as Ei,L as yt,cH as Ns,b3 as Ih,z as ks,am as Dh,cN as J,b7 as Fh,b9 as Zi,ba as _h,bb as ru,b8 as Ss,az as Bh,E as Oh,i as Uh,b6 as Hh,bz as zh,bB as Wh,bC as Gh,a_ as Kh,bA as td,y as jt,f as qh,v as Vh,b as Yh,cI as rd,aZ as nd,av as sd,ar as Xh,aD as Ta,aE as ad,cU as $s,ai as js,aF as Jh,br as Zh,cs as od,ax as Qh,cE as em,c0 as tm,aI as rm,O as id,N as nm,as as sm,aw as am,aB as ld,c2 as om,s as im,d as Ia,g as Mi,m as cd,w as nu,ae as lm,_ as Ds,bW as cm,cR as dm,bm as um,ag as fm}from"./app-CacB_zmS.js";import{r as su,l as hm,s as dd,w as Ya,g as mm,D as pm,V as gm,P as bm,p as xm,j as vm,M as ym,R as $i,x as au,y as wm,S as Zn,h as km,e as ou,c as Sm,K as iu,A as ud,J as jm,E as Da,z as Rm,B as Cm,I as fd,N as hd,T as md,H as pd,f as gd,o as li,n as Fa,d as Nm,t as Em,m as Mm,i as $m,u as Lm,F as bd,C as Am,a as Pm,G as Tm}from"./App-C-sArfYM.js";import{b as a,r as Ir}from"./dnd-BCFAPC0L.js";import{a as xd,S as vd,b as lu,c as Li,F as Im}from"./gestureArbiter-BkdwKXjM.js";import{D as Ai,C as Ls,L as cu,f as Dm,n as Fm}from"./DiffReview-zTuUIB7N.js";import{T as _m,L as Qa,M as du,G as Ar}from"./triangle-alert-DN7qGh3M.js";import{S as Fs}from"./sparkles-MZp-tT_G.js";import{C as uu,M as fu}from"./ChangeWalkthroughPanel-xq2AwXOA.js";import{r as hu,s as mu,l as pu,a as yd,h as Pi,u as Bm,g as Ti,b as gu}from"./DiffViewer-D4UreLzY.js";import{u as bu,G as xu}from"./referenceLongPress-CkmKcttc.js";const Om=[["path",{d:"m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16",key:"d5nyq2"}],["path",{d:"M22 9v7",key:"pvm9v3"}],["path",{d:"M3.304 13h6.392",key:"1q3zxz"}],["circle",{cx:"18.5",cy:"12.5",r:"3.5",key:"z97x68"}]],Um=Tr("case-sensitive",Om);const Hm=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],zm=Tr("eye-off",Hm);const Wm=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],Ii=Tr("eye",Wm);const Gm=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Di=Tr("file-text",Gm);const Km=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],qm=Tr("image-plus",Km);const Vm=[["path",{d:"M17 3v10",key:"15fgeh"}],["path",{d:"m12.67 5.5 8.66 5",key:"1gpheq"}],["path",{d:"m12.67 10.5 8.66-5",key:"1dkfa6"}],["path",{d:"M9 17a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2v-2z",key:"swwfx4"}]],Ym=Tr("regex",Vm);const Xm=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}]],Jm=Tr("scan",Xm);const Zm=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Qm=Tr("upload",Zm);const ep=[["circle",{cx:"7",cy:"12",r:"3",key:"12clwm"}],["path",{d:"M10 9v6",key:"17i7lo"}],["circle",{cx:"17",cy:"12",r:"3",key:"gl7c2s"}],["path",{d:"M14 7v8",key:"dl84cr"}],["path",{d:"M22 17v1c0 .5-.5 1-1 1H3c-.5 0-1-.5-1-1v-1",key:"lt2kga"}]],tp=Tr("whole-word",ep);async function rp(r){let n;try{await Promise.race([r(),new Promise(s=>{n=setTimeout(s,3e3)})])}catch{}finally{clearTimeout(n)}}function np({active:r,rootPath:n,loading:s,delay:l,lastStartedRoot:u,load:c}){a.useEffect(()=>{if(!r||!n||s||u.current===n)return;const h=window.setTimeout(()=>{u.current=n,c(n)},l);return()=>window.clearTimeout(h)},[r,n,s,l,u,c])}function sp(r,n,s){try{const l=r instanceof HTMLImageElement?r.naturalWidth:r.width,u=r instanceof HTMLImageElement?r.naturalHeight:r.height;if(!l||!u)return Promise.resolve(null);const c=r instanceof HTMLImageElement?1400/Math.max(l,u):Math.min(1,1400/Math.max(l,u)),h=document.createElement("canvas");h.width=Math.max(1,Math.round(l*c)),h.height=Math.max(1,Math.round(u*c));const m=h.getContext("2d");if(!m)return Promise.resolve(null);const g=getComputedStyle(document.documentElement);if(m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,h.height),m.drawImage(r,0,0,h.width,h.height),s){const b=Math.max(10,Math.min(16,h.width/35));m.font=`${b}px sans-serif`;const f=[];let k="";for(const y of s.split(" "))k&&m.measureText(`${k} ${y}`).width>h.width-20?(f.push(k),k=y):k=k?`${k} ${y}`:y;k&&f.push(k),m.fillStyle=g.getPropertyValue("--surface").trim()||"white",m.fillRect(0,0,h.width,f.length*(b+4)+12),m.fillStyle=g.getPropertyValue("--foreground").trim()||"black",f.forEach((y,N)=>m.fillText(y,10,8+b+N*(b+4)))}if(n){const b=n.xPercent*h.width/100,f=n.yPercent*h.height/100,k=Math.max(4,Math.min(12,Math.min(h.width,h.height)*.015)),y=k*1.6;m.strokeStyle=g.getPropertyValue("--primary").trim()||"black",m.lineWidth=Math.max(1,k/3),m.beginPath(),m.arc(b,f,k,0,Math.PI*2),m.stroke(),m.beginPath(),m.moveTo(b-y,f),m.lineTo(b+y,f),m.moveTo(b,f-y),m.lineTo(b,f+y),m.stroke()}return new Promise(b=>h.toBlob(b,"image/png"))}catch{return Promise.resolve(null)}}function ap(r,n,s,l){return[r.trim(),n.trim(),l?`截图:${l}`:""].filter(Boolean).join(`
3
+ `)}function sx(r,n,s){const l=n*Math.PI/360,u=Math.min(l,Math.atan(Math.tan(l)*Math.max(s,.05)));return Math.max(r,1e-6)/Math.sin(u)*1.15}async function op(r,n,s,l){if(!s?.snapshot){l.isCurrent()&&l.insert(r,n);return}const u=new Date().toISOString(),c=new AbortController;let h,m;try{m=await Promise.race([(async()=>{const g=await s.snapshot;if(!(!g||c.signal.aborted||!l.isCurrent()))return l.upload(new File([g],`termdock-review-${crypto.randomUUID()}.png`,{type:"image/png"}),c.signal)})(),new Promise(g=>{h=setTimeout(()=>{c.abort(),g(void 0)},3e3)})])}catch{}finally{clearTimeout(h),c.abort()}l.isCurrent()&&l.insert(m?ap(r,"",u,m):r,n)}function ip(r,n){return r===n||n.endsWith(`/${r}`)||r.endsWith(`/${n}`)}function wd(r,n){return`${r??""}\0${n}`}function lp(r,n,s){if(!r||r.length===0||!s)return{explained:0,stale:0};const l=wd(n,s);let u=0,c=0;for(const h of r){const m=[h.filePath,h.newPath,h.oldPath].filter(b=>typeof b=="string"&&b.length>0);(m.some(b=>wd(h.repoRoot,b)===l)||m.some(b=>ip(b,s)))&&(u+=1)}return{explained:u,stale:c}}function cp({status:r}){if(!r)return null;const n=r.stale>0&&r.explained===0;if(!(r.explained>0||r.stale>0))return null;const l=n?"AI audit explanation is stale":"AI audit explanation available";return e.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full ${n?"bg-[color:var(--warning)]/15 text-[color:var(--warning)]":"bg-accent/10 text-accent"}`,title:l,"aria-label":l,children:n?e.jsx(_m,{size:10}):e.jsx(Fs,{size:10})})}function Fi({changeStatus:r,auditStatus:n,renderChangeBadge:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[s(r),e.jsx(cp,{status:n})]})}const vu="termdock:right-sidebar:diff-change-list-mode:v1";function dp(r){return r==="list"||r==="tree"}function up(){return ut(vu,dp)??"tree"}function fp(r){for(const l of r){const u=l.hunk;if(u.oldPath&&u.newPath&&u.oldPath!==u.newPath)return"renamed";if(!u.oldPath&&u.newPath)return"added";if(u.oldPath&&!u.newPath)return"deleted"}const n=r.some(l=>l.hunk.additions>0),s=r.some(l=>l.hunk.deletions>0);return n&&!s?"added":!n&&s?"deleted":"modified"}function hp(r){const n=new Map;for(const l of r){const u=n.get(l.hunk.filePath)??{key:l.hunk.filePath,filePath:l.hunk.filePath,items:[],additions:0,deletions:0,explained:0,stale:0,changeType:"modified"};u.items.push(l),u.additions+=l.hunk.additions,u.deletions+=l.hunk.deletions,l.current&&(u.explained+=1),l.stale&&(u.stale+=1),n.set(l.hunk.filePath,u)}const s=Array.from(n.values()).sort((l,u)=>l.filePath.localeCompare(u.filePath));for(const l of s)l.changeType=fp(l.items);return s}function mp(r){const n=r.filePath.split("/").pop()??r.filePath;return{key:r.key,path:r.filePath,displayName:n,displayDir:r.filePath.includes("/")?r.filePath.slice(0,-n.length-1):"",status:r.changeType,title:r.filePath}}function pp(r,n){const s=r.filter(c=>c.trim().length>0);if(s.length<=1)return s[0]??"";const l=[],u=new Set;for(const[c,h]of s.entries()){const m=h.split(`
4
+ `),g=m.findIndex(k=>k.startsWith("@@ "));if(g<0){l.push(...m);continue}c===0&&l.push(...m.slice(0,g));const b=n[c];let f=g;for(;f>=0&&f<m.length;){const k=m.findIndex((R,E)=>E>f&&R.startsWith("@@ ")),y=k>=0?k:m.length,N=m.slice(f,y),I=N[0]??"",B=b?I===b:!0,_=I||b||N.join(`
5
+ `);B&&!u.has(_)&&(l.push(...N),u.add(_)),f=k}}return l.join(`
6
+ `)}function gp({groups:r,onInsertDiffReference:n}){return r.map(s=>{const l=pp(s.items.map(m=>m.hunk.diff||m.current?.diff||m.stale?.diff||""),s.items.map(m=>m.hunk.hunkHeader)),u=s.items.map(m=>m.current??m.stale).filter(m=>!!m).map(m=>({id:m.id,repoRoot:m.repoRoot,filePath:m.filePath,oldPath:m.oldPath,newPath:m.newPath,hunkHeader:m.hunkHeader,hunkIndex:m.hunkIndex,fingerprint:m.fingerprint,diff:m.diff,explanation:m.explanation,summary:m.summary,workspaceRoot:m.workspaceRoot,generatedBy:m.generatedBy,injectedAt:m.injectedAt})),c=s.filePath.split("/").pop()??s.filePath,h=s.filePath.includes("/")?s.filePath.slice(0,-c.length-1):"";return{key:s.key,path:s.filePath,absolutePath:u[0]?.repoRoot?`${u[0].repoRoot}/${s.filePath}`:s.filePath,status:s.changeType,repoRoot:u[0]?.repoRoot??null,displayName:c,displayDir:h,diffOverride:l,auditRecords:u,onInsertDiffReference:n}})}function bp(r,n,s){const l=Array.from(r.querySelectorAll("[data-diff-stream-item]"));if(l.length===0)return null;const c=r.getBoundingClientRect().top+48;let h=null,m=Number.POSITIVE_INFINITY;for(const b of l){const f=b.getBoundingClientRect();if(f.bottom<c)continue;const k=Math.abs(f.top-c);k<m&&(h=b,m=k)}const g=h?.dataset.diffSelectionPath??h?.dataset.diffStreamItem??null;return!g||g===n||s(g),g}function kd({items:r,selectedKey:n,onSelect:s,emptyText:l,mobile:u=!1,backLabel:c="Back",headerTitle:h,headerMeta:m,onClose:g,closeLabel:b="Back",wrap:f=!0,onToggleWrap:k,wrapTitle:y,wrapOnLabel:N="Wrap on",wrapOffLabel:I="Wrap off",desktopLayout:B="split",onInsertDiffReference:_,onReferenceCopied:R,insertedReferenceKey:E,copiedReferenceKey:$,onClearAuditRecord:P,onRefresh:U,refreshing:F,refreshLabel:p,refreshTitle:i,walkthroughs:O=[],onWalkthroughNavigate:C,initialDetailScrollTop:G,onDetailScrollPositionChange:fe,scrollToKey:te,scrollToKeyNonce:xe,externalSwiperRef:W,onMobileSlideChange:Y}){const{t:L}=wt(),D=a.useMemo(()=>hp(r),[r]),K=a.useMemo(()=>new Map(D.map(q=>[q.key,q])),[D]),[re,ce]=a.useState(()=>up()),[ve,pe]=a.useState(()=>new Set),[Ee,M]=a.useState({key:null,nonce:0}),Z=D.find(q=>q.explained>0||q.stale>0)?.key??D[0]?.key??null,he=n&&D.some(q=>q.key===n)?n:Z,Ne=a.useMemo(()=>[{key:"branch-audit",label:"Branch audit",files:D.map(mp)}],[D]),Ve=a.useMemo(()=>gp({groups:D,onInsertDiffReference:_}),[D,_]),Ce=a.useRef(Z),Ye=a.useRef(s);Ce.current=Z,Ye.current=s,a.useEffect(()=>{!n&&Ce.current&&Ye.current(Ce.current)},[n]);const Ie=k?e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2.5 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?N:I})]}):null,S=U?e.jsxs("button",{type:"button",onClick:U,disabled:F,title:i??p,"aria-label":i??p,className:"inline-flex h-7 shrink-0 items-center gap-1 rounded-full bg-surface-2 px-2.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:cursor-not-allowed disabled:opacity-60",children:[e.jsx(su,{size:12,className:F?"animate-spin":""}),p&&e.jsx("span",{children:p})]}):null,Q=q=>e.jsxs("div",{className:"px-0 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[h&&e.jsx("div",{className:"truncate text-[12px] font-semibold text-foreground",children:h}),m&&e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:m})]}),g&&e.jsxs("button",{type:"button",onClick:g,className:"inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:[e.jsx(Ts,{size:14}),b]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[q,S,Ie]})]});if(r.length===0){const q=e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l});return!h&&!g?q:e.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-2",children:[Q(null),q]})}const le=k||U?({slideToList:q})=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",onClick:q,children:[e.jsx(Ts,{size:14}),c]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[S,k&&e.jsxs("button",{type:"button",onClick:k,"aria-pressed":f,title:y,className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${f?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:f?N:I})]})]})]}):void 0;return e.jsx(Ai,{mobile:u,desktopLayout:B,backLabel:c,groups:Ne,selectedKey:he,mode:re,onModeChange:q=>{ce(q),q!=="ai"&&$t(vu,q)},compact:u,collapsedDirectoryKeys:ve,onToggleDirectory:q=>{pe(me=>{const Ae=new Set(me);return Ae.has(q)?Ae.delete(q):Ae.add(q),Ae})},onSelectFile:q=>{s(q.key),M(me=>({key:q.key,nonce:me.nonce+1}))},renderLeading:q=>{const me=K.get(q.key);return e.jsx(Fi,{changeStatus:q.status,auditStatus:me,renderChangeBadge:Ae=>e.jsx(Ls,{status:Ae})})},renderTrailing:q=>{const me=K.get(q.key);return me?e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:["+",me.additions," -",me.deletions]}):null},renderListHeader:Q,aiContent:({slideToDetail:q,fullscreen:me,toggleFullscreen:Ae})=>O.length>0&&C?e.jsx(uu,{walkthroughs:O,repoRoot:O[0]?.repoRoot,fullscreen:me,onToggleFullscreen:Ae,onNavigate:oe=>{u&&window.requestAnimationFrame(q),C(oe)}}):e.jsx("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:L("rightSidebar.changeWalkthroughEmpty")}),renderMobileDetailHeader:le,externalSwiperRef:W,onMobileSlideChange:Y,detailContainerClassName:u?"termdock-native-select termdock-diff-stream-scroller min-h-0":void 0,initialDetailScrollTop:G,scrollToKey:te??Ee.key,scrollToKeyNonce:te==null?Ee.nonce:xe,onDetailScroll:q=>{bp(q,he,s),fe?.(q.scrollTop)},files:Ve,activePane:!0,wrap:f,renderStreamBadge:(q,me)=>{const Ae=K.get(me.key);return e.jsx(Fi,{changeStatus:q,auditStatus:Ae,renderChangeBadge:oe=>e.jsx(Ls,{status:oe})})},onInsertDiffReference:_,onReferenceCopied:R,insertedReferenceKey:E,copiedReferenceKey:$,onClearAuditRecord:P,emptyContent:e.jsx("div",{className:"rounded-lg bg-surface-2 px-3 py-6 text-center text-xs text-muted-foreground",children:l})})}function xp(r){return r.replace(/\/+$/,"")||"/"}function vp(r){return[...new Set(Array.from(r,xp))].sort((n,s)=>n.localeCompare(s))}function yp(r){return r==="event-storm"||r==="reconnected"||r==="directory-rescan"||r==="polling-fallback"}function wp(r){let n=null;return{applicableEvents:r.filter(l=>{const u=l.type==="rescan-required"&&!yp(l.reason);return u&&l.reason&&!n&&(n=l.reason),!u}),unavailableReason:n}}const kp=1400,Sp=1200,yu=44,jp=.7;function ci(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches?"mobile":"desktop"}function _i(r){return`termdock:right-sidebar:context-draft-height:${r}:v1`}function Rp(r){try{const n=window.localStorage.getItem(_i(r)),s=n===null?NaN:Number(n);return Number.isFinite(s)&&s>=yu?s:null}catch{return null}}function Sd(r,n){try{n===null?window.localStorage.removeItem(_i(r)):window.localStorage.setItem(_i(r),String(n))}catch{}}function _a(){return typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches}function Cp({value:r,collapsed:n,labels:s,focusRequest:l,insertError:u,autoCollapseAfterSend:c,onChange:h,onCollapsedChange:m,onAutoCollapseAfterSendChange:g,onDisable:b,onClear:f,onInsert:k,onInsertAndSend:y}){const[N,I]=a.useState(null),[B,_]=a.useState(!1),[R,E]=a.useState(()=>Rp(ci())),$=a.useRef(R),P=a.useRef(null),U=a.useRef(null),F=a.useRef(r),p=a.useRef(null),i=a.useRef(null),O=!!r.trim(),C=r.trim().split(`
7
+ `)[0]??"",G=/Mac|iPhone|iPad/.test(window.navigator?.platform??"")?"⌘↵":"Ctrl+↵";a.useEffect(()=>()=>{P.current!==null&&window.clearTimeout(P.current),U.current!==null&&window.clearTimeout(U.current)},[]),a.useEffect(()=>{let M=!1;const Z=ci();return tu().then(he=>{if(M)return;const Ne=he.contextDraftHeight?.[Z]??null;Sd(Z,Ne),$.current=Ne,E(Ne)}).catch(()=>{}),()=>{M=!0}},[]),a.useEffect(()=>{if(l!==void 0&&l>0){const M=p.current;if(!M)return;_a()||M.focus(),M.setSelectionRange(M.value.length,M.value.length),M.scrollTop=M.scrollHeight}},[l]),a.useEffect(()=>{const M=F.current;F.current=r,!(!n||r.length<=M.length)&&(_(!0),U.current!==null&&window.clearTimeout(U.current),U.current=window.setTimeout(()=>{U.current=null,_(!1)},Sp))},[r,n]),a.useEffect(()=>{if(n)return;const M=p.current;M&&(M.style.height=R!==null?`${R}px`:"")},[r,n,R]),a.useEffect(()=>{if(n)return;const M=p.current;!M||document.activeElement===M||(M.scrollTop=M.scrollHeight)},[r,n]),a.useEffect(()=>{if(n||_a())return;const M=p.current;!M||document.activeElement===M||(M.focus(),M.setSelectionRange(M.value.length,M.value.length))},[n]);const fe=a.useRef(null);a.useLayoutEffect(()=>{if(!_a())return;const M=window.visualViewport;if(!M)return;const Z=()=>{const he=fe.current;if(!he)return;if(M.height>=window.innerHeight*.75){he.style.transform="";return}const Ne=he.getBoundingClientRect(),Ve=Math.round(M.height-Ne.bottom);he.style.transform=Ve!==0?`translateY(${Ve}px)`:""};return Z(),M.addEventListener("resize",Z),M.addEventListener("scroll",Z),()=>{M.removeEventListener("resize",Z),M.removeEventListener("scroll",Z),fe.current&&(fe.current.style.transform="")}},[n]);const te=M=>{I(M),P.current!==null&&window.clearTimeout(P.current),P.current=window.setTimeout(()=>{P.current=null,I(null)},kp)},xe=M=>{m(!1),_a()&&window.requestAnimationFrame(()=>{const Z=p.current;if(!Z)return;Z.focus();const he=Z.value.length;Z.setSelectionRange(he,he),window.requestAnimationFrame(()=>{Z.setSelectionRange(he,he)})})},W=()=>{k(),te("inserted")},Y=()=>{O&&(y(),te("sent"))},L=M=>{if(M.key==="Escape"){M.preventDefault(),m(!0);return}M.key!=="Enter"||!M.metaKey&&!M.ctrlKey||(M.preventDefault(),Y())},D=M=>{M.preventDefault()},K=M=>{M.preventDefault();const Z=p.current;Z&&(i.current={startY:M.clientY,startHeight:Z.getBoundingClientRect().height},M.currentTarget.setPointerCapture?.(M.pointerId))},re=M=>{const Z=i.current;if(!Z)return;const he=window.visualViewport?.height??window.innerHeight,Ne=Math.round(Math.min(Math.max(Z.startHeight+(Z.startY-M.clientY),yu),he*jp));$.current=Ne,E(Ne)},ce=M=>{const Z=ci();Sd(Z,M),Ei({contextDraftHeight:{[Z]:M}}).catch(()=>{})},ve=()=>{i.current&&(i.current=null,$.current!==null&&ce($.current))},pe=()=>{$.current=null,E(null),ce(null)},Ee=r.length>0&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/50",children:s.characterCount(r.length)});return n?e.jsx("section",{ref:fe,className:"shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:e.jsxs("div",{className:"flex h-8 items-center gap-1 px-2",children:[e.jsxs("button",{type:"button",onClick:()=>xe(),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!1,"aria-label":s.expand,title:s.expand,children:[e.jsx(hm,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:`truncate text-[11px] ${u?"text-destructive":B?"text-primary":O?"text-foreground/80":"text-muted-foreground/50"}`,children:u??(B?s.appended:O?C:s.title)})]}),Ee,e.jsx("button",{type:"button",onClick:Y,disabled:!O,className:`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full transition active:scale-95 disabled:opacity-30 ${O?"bg-primary text-primary-foreground hover:bg-primary/90":"text-muted-foreground"}`,"aria-label":s.send,title:s.send,children:N==="sent"?e.jsx(Ni,{size:12}):e.jsx(dd,{size:12})})]})}):e.jsxs("section",{ref:fe,className:"relative shrink-0 border-t border-border/15 text-foreground","data-context-draft-dock":!0,children:[e.jsx("div",{className:"group absolute left-1/2 top-0 z-10 flex h-3 w-16 -translate-x-1/2 -translate-y-1/2 cursor-ns-resize touch-none items-center justify-center",onPointerDown:K,onPointerMove:re,onPointerUp:ve,onPointerCancel:ve,onDoubleClick:pe,title:s.resize,"aria-hidden":"true",children:e.jsx("span",{className:"h-1 w-8 rounded-full bg-border/50 transition group-hover:bg-border"})}),e.jsxs("div",{className:"flex h-7 items-center gap-0.5 px-2",children:[e.jsxs("button",{type:"button",onPointerDown:D,onClick:()=>m(!0),className:"group flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-surface/70","aria-expanded":!0,"aria-label":s.collapse,title:s.collapse,children:[e.jsx(Is,{size:11,className:"shrink-0 text-muted-foreground/55 transition-colors group-hover:text-muted-foreground","aria-hidden":"true"}),e.jsx("span",{className:"truncate text-[10px] font-medium text-foreground/75",children:s.title}),Ee]}),e.jsx("button",{type:"button",role:"switch","aria-checked":c,onPointerDown:D,onClick:()=>g(!c),className:"inline-flex h-6 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground/70 transition-colors hover:bg-surface/70 hover:text-foreground","aria-label":s.autoCollapseAfterSend,title:s.autoCollapseAfterSend,children:e.jsx("span",{"aria-hidden":"true",className:`relative h-3 w-5 rounded-full transition-colors ${c?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute top-0.5 h-2 w-2 rounded-full bg-primary-foreground transition-transform ${c?"translate-x-2.5":"translate-x-0.5"}`})})}),e.jsx("button",{type:"button",onPointerDown:D,onClick:b,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/50 transition hover:bg-surface/70 hover:text-foreground active:scale-95","aria-label":s.disable,title:s.disable,children:e.jsx(Kt,{size:11})})]}),e.jsx("div",{className:"px-2 pb-2",children:e.jsxs("div",{className:"overflow-hidden rounded-lg bg-surface/80 ring-1 ring-border/10 transition focus-within:ring-primary/35",children:[e.jsx("textarea",{ref:p,value:r,onChange:M=>h(M.target.value),onKeyDown:L,placeholder:s.title,rows:1,className:"block min-h-11 w-full resize-none bg-transparent px-2.5 py-2 font-mono text-[12px] leading-relaxed text-foreground placeholder:text-muted-foreground/30 focus:outline-none",autoCapitalize:"sentences",spellCheck:!0,"data-context-draft-input":!0}),e.jsxs("div",{className:"flex items-center gap-0.5 border-t border-border/10 px-1 py-1",children:[e.jsx("button",{type:"button",onPointerDown:D,onClick:f,disabled:!O,className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground/65 transition hover:bg-surface-2 hover:text-foreground active:scale-95 disabled:opacity-30","aria-label":s.clear,title:s.clear,children:e.jsx(Ya,{size:11})}),u?e.jsx("span",{className:"min-w-0 flex-1 truncate px-1 text-[10px] text-destructive",role:"alert",children:u}):e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button",onPointerDown:D,onClick:W,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[10px] font-medium text-foreground/75 transition hover:bg-surface-2 hover:text-foreground active:scale-[0.98] disabled:opacity-30",children:[e.jsx(mm,{size:11}),e.jsx("span",{children:N==="inserted"?s.inserted:s.insert})]}),e.jsxs("button",{type:"button",onPointerDown:D,onClick:Y,disabled:!O,className:"inline-flex h-6 shrink-0 items-center justify-center gap-1 rounded-md bg-primary px-2 text-[10px] font-semibold text-primary-foreground transition hover:bg-primary/90 active:scale-[0.98] disabled:opacity-30",title:`${s.insertAndSend} · ${G}`,children:[N==="sent"?e.jsx(Ni,{size:11}):e.jsx(dd,{size:11}),e.jsx("span",{children:N==="sent"?s.sent:s.send})]})]})]})})]})}function Np({file:r,initialPath:n,onInsert:s,onDone:l}){const{t:u}=wt(),[c,h]=a.useState(!1),[m,g]=a.useState(!1),[b,f]=a.useState(!1),[k,y]=a.useState(null),N=a.useRef(!1),I=a.useRef(null);a.useEffect(()=>{if(c)return;I.current?.focus();const _=R=>{if(R.stopPropagation(),R.key==="Escape"&&R.preventDefault(),R.key!=="Tab")return;const E=Array.from(I.current?.querySelectorAll("button:not(:disabled)")??[]),$=E[0],P=E.at(-1);R.shiftKey&&(document.activeElement===$||document.activeElement===I.current)?(R.preventDefault(),P?.focus()):!R.shiftKey&&document.activeElement===P&&(R.preventDefault(),$?.focus())};return document.addEventListener("keydown",_,!0),()=>document.removeEventListener("keydown",_,!0)},[c]);const B=async _=>{if(!N.current){N.current=!0,g(!0),f(_!==void 0),h(!1),y(null);try{if(_!==void 0){if(!(await Ns(_,[r])).files[0]?.path)throw new Error(u("rightSidebar.uploadFailed"))}else await s(r);l()}catch(R){y(R instanceof Error?R.message:String(R))}finally{N.current=!1,g(!1)}}};return c?e.jsx(pm,{open:!0,initialPath:n||"/",title:u("android.recordingSave"),onCancel:()=>h(!1),onConfirm:_=>{B(_)}}):Ir.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-panel flex items-center justify-center bg-[var(--app-backdrop)] p-4",children:e.jsxs("div",{ref:I,role:"dialog","aria-modal":"true","aria-labelledby":"recording-save-title",tabIndex:-1,"aria-busy":m,className:"w-full max-w-sm rounded-xl border border-border bg-surface p-4 text-foreground shadow-xl outline-none",children:[e.jsx("h2",{id:"recording-save-title",className:"text-sm font-semibold",children:u("android.recordingConfirm")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:u("android.recordingSaveHint")}),e.jsxs("p",{className:"mt-2 break-all text-xs text-muted-foreground",children:[r.name," · ",(r.size/1024/1024).toFixed(1)," MB"]}),k&&e.jsx("p",{role:"alert",className:"mt-3 break-words text-xs text-destructive",children:k}),m&&e.jsxs("p",{role:"status",className:"mt-3 flex items-center gap-2 text-sm text-primary",children:[e.jsx(yt,{size:16,className:"animate-spin"}),u(b?"android.recordingSaving":"android.captureInserting")]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsx("button",{type:"button",disabled:m,onClick:()=>{B()},className:"min-h-10 rounded-lg bg-primary px-3 text-sm text-primary-foreground disabled:opacity-40",children:u("android.recordingInsert")}),e.jsx("button",{type:"button",disabled:m,onClick:()=>h(!0),className:"min-h-10 rounded-lg bg-surface-2 px-3 text-sm disabled:opacity-40",children:u("android.recordingSave")}),e.jsx("button",{type:"button",disabled:m,onClick:l,className:"min-h-10 rounded-lg px-3 text-sm text-muted-foreground disabled:opacity-40",children:u("android.recordingDiscard")})]})]})}),document.body)}function Ep(r,n){const s=n.trim();if(!s)return r;if(!r.trim())return s;const l=r.endsWith(`
8
8
 
9
9
  `)?"":r.endsWith(`
10
10
  `)?`
11
11
  `:`
12
12
 
13
- `;return`${r}${l}${s}`}function jp(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}const _i="termdock:right-sidebar:html-view-mode-by-file:v1";function Rp(r){return r==="preview"||r==="source"}function xu(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(Rp)}function vu(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function wd(r,n){const s=vu(r,n);return s?ut(_i,xu)?.[s]??"source":"source"}function Cp(r,n,s){const l=vu(r,n);if(!l)return;const u=ut(_i,xu)??{};$t(_i,{...u,[l]:s})}function Np(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const Mp=1500,kd=256*1024*1024;async function Ep(r,n){const s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",u=s.body?.getReader();if(!u){const p=await s.blob();if(p.size>kd)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(p)}const c=[];let h=0;try{for(;;){const{done:p,value:g}=await u.read();if(p)break;if(h+=g.byteLength,h>kd)throw new Error("Media too large for encrypted fallback");c.push(g)}}catch(p){throw await u.cancel().catch(()=>{}),p}return URL.createObjectURL(new Blob(c,{type:l}))}function io(r,n){const s=Np(r),[l,u]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,h]=a.useState(void 0),p=a.useRef(n);return p.current=n,a.useEffect(()=>{if(!s||l)return;const g=navigator.serviceWorker,b=()=>u(!!g?.controller);return g?.addEventListener("controllerchange",b),b(),()=>g?.removeEventListener("controllerchange",b)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let g=!1,b;const f=new AbortController,k=window.setTimeout(()=>{Ep(r,f.signal).then(y=>{if(g){URL.revokeObjectURL(y);return}b=y,h(y)}).catch(()=>{g||f.signal.aborted||p.current?.()})},Mp);return()=>{g=!0,window.clearTimeout(k),f.abort(),b&&URL.revokeObjectURL(b)}},[s,l,r]),!s||l?r:c}function ci(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),u=n%60,c=String(l).padStart(2,"0"),h=String(u).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function $p(r,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(r-n.left)/n.width))*s}const tn=2,Lp=8,Ap=60,Ba=5,Sd=.05,Pp=900;function Tp(r){return!Number.isFinite(r)||r<=0?tn:Math.min(Lp,tn+Math.floor(r/Ap))}const Ip=350,Dp=6,Fp=90;function _p({url:r,onLoadError:n}){const s=io(r,n),{t:l}=jt(),u=a.useRef(null),c=a.useRef(null),h=a.useRef(null),p=a.useRef(null),g=a.useRef(!1),b=a.useRef(null),f=a.useRef(null),k=a.useRef(0),y=a.useRef(!1),C=a.useRef(!1),D=a.useRef(!1),_=a.useRef(null),B=a.useRef(null),E=a.useRef(!1),N=a.useRef(1),$=a.useRef(!1),[T,U]=a.useState(0),[F,m]=a.useState(0),[i,O]=a.useState(!1),[R,G]=a.useState(!1),[fe,te]=a.useState(null),[xe,W]=a.useState(!1),[Y,L]=a.useState(0),[I,K]=a.useState(!1),[re,ce]=a.useState({width:0,height:0}),[ve,pe]=a.useState(tn),[Me,M]=a.useState(1),[Z,he]=a.useState(null),Ne=a.useRef(tn),Ve=a.useRef(null),Ce=a.useCallback(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),Ye=a.useCallback(()=>{Ce();const H=B.current;if(B.current=null,!E.current)return!1;const se=h.current;if(se&&(se.playbackRate=N.current,H))try{se.releasePointerCapture?.(H.id)}catch{}return E.current=!1,Ne.current=tn,W(!1),!0},[Ce]);a.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),f.current!==null&&clearTimeout(f.current),Ve.current!==null&&clearTimeout(Ve.current),Ce();const H=h.current;H&&E.current&&(H.playbackRate=N.current)},[Ce]),a.useEffect(()=>{const H=c.current;if(!H||typeof ResizeObserver>"u")return;const se=new ResizeObserver(([be])=>{be&&ce({width:be.contentRect.width,height:be.contentRect.height})});return se.observe(H),()=>se.disconnect()},[]),a.useEffect(()=>{const H=()=>K(document.fullscreenElement===u.current);return document.addEventListener("fullscreenchange",H),()=>document.removeEventListener("fullscreenchange",H)},[]);const Ie=a.useCallback((H,se=!1)=>{const be=h.current;if(!be)return!1;const We=Number.isFinite(be.duration)?be.duration:H,ft=Math.min(Math.max(H,0),We);if(m(ft),Math.abs(be.currentTime-ft)<1/120)return!1;const dr=be.fastSeek;return se&&typeof dr=="function"?dr.call(be,ft):be.currentTime=ft,!0},[]),S=a.useCallback(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const H=h.current;if(!H||!y.current||C.current||H.seeking)return;const se=D.current;D.current=!1,C.current=Ie(k.current,!se)}))},[Ie]),Q=a.useCallback(H=>{const se=p.current,be=h.current;if(!se||!be)return;const We=se.getBoundingClientRect(),ft=$p(H,We,be.duration);k.current=ft,te(ft),D.current=!1,S(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,D.current=!0,S()},Fp)},[S]),le=a.useCallback(()=>{b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),D.current=!1,C.current=!1,Ie(k.current)},[Ie]),q=a.useCallback(H=>{const se=h.current;if(!(!se||!Number.isFinite(se.duration)||se.duration<=0)){g.current=!se.paused,se.pause(),y.current=!0,G(!0);try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}Q(H.clientX)}},[Q]),me=a.useCallback(()=>{y.current=!1,le(),G(!1),te(null);const H=h.current;H&&g.current&&!H.ended&&H.play().catch(()=>{}),g.current=!1},[le]),Ae=a.useCallback(()=>{const H=h.current;if(H){if($.current){$.current=!1;return}H.paused?H.play().catch(()=>{}):H.pause()}},[]),oe=a.useCallback(H=>{const se=h.current;if(!se)return;const be=Math.min(1,Math.max(0,Math.round((se.volume+H)*100)/100));se.volume=be,be>0&&(se.muted=!1),M(be),he(be),Ve.current!==null&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>{Ve.current=null,he(null)},Pp)},[]),Ee=a.useCallback(H=>{const se=h.current;if(se){if(H.key==="ArrowLeft"){H.preventDefault(),Ie(se.currentTime-(H.shiftKey?Ba*2:Ba));return}if(H.key==="ArrowRight"){H.preventDefault(),Ie(se.currentTime+(H.shiftKey?Ba*2:Ba));return}if(H.key==="ArrowUp"){H.preventDefault(),oe(Sd);return}if(H.key==="ArrowDown"){H.preventDefault(),oe(-Sd);return}(H.key===" "||H.key==="Spacebar"||H.key==="k"||H.key==="K")&&(H.preventDefault(),se.paused?se.play().catch(()=>{}):se.pause())}},[Ie,oe]),st=a.useCallback(H=>{const se=h.current;!se||se.paused||H.button!==0||(Ce(),B.current={id:H.pointerId,x:H.clientX,y:H.clientY},_.current=setTimeout(()=>{_.current=null;const be=B.current;if(N.current=se.playbackRate,se.playbackRate=tn,Ne.current=tn,pe(tn),E.current=!0,W(!0),be)try{se.setPointerCapture?.(be.id)}catch{}},Ip))},[Ce]),Pe=a.useCallback(H=>{const se=B.current;if(!se||se.id!==H.pointerId)return;if(!E.current){Math.hypot(H.clientX-se.x,H.clientY-se.y)>Dp&&(Ce(),B.current=null);return}const be=Tp(H.clientX-se.x);if(be===Ne.current)return;Ne.current=be,pe(be);const We=h.current;We&&(We.playbackRate=be)},[Ce]),ke=a.useCallback(()=>{Ye()&&($.current=!0)},[Ye]);a.useEffect(()=>(window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",ke)}),[ke]);const at=a.useCallback(async()=>{const H=u.current,se=h.current;if(!(!H||!se))try{document.fullscreenElement===H?await document.exitFullscreen():H.requestFullscreen?await H.requestFullscreen():se.webkitEnterFullscreen?.()}catch{se.webkitEnterFullscreen?.()}},[]),et=a.useCallback(()=>L(H=>(H+90)%360),[]),qt=a.useCallback(H=>{const se=h.current;if(!se||!Number.isFinite(se.duration))return;const be=H.shiftKey?10:5;let We=null;H.key==="ArrowLeft"?We=se.currentTime-be:H.key==="ArrowRight"?We=se.currentTime+be:H.key==="Home"?We=0:H.key==="End"&&(We=se.duration),We!==null&&(H.preventDefault(),Ie(We))},[Ie]),lt=R&&fe!==null?fe:F,ct=T>0?Math.min(1,Math.max(0,lt/T)):0,Ft=(Y===90||Y===270)&&re.width>0&&re.height>0?{width:`${re.height}px`,height:`${re.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:u,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":Y,children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:`absolute left-1/2 top-1/2 max-w-none object-contain outline-none transition-transform duration-200 focus-visible:ring-2 focus-visible:ring-primary/60${xe?` ${pd}`:""}`,style:{...Ft,transform:`translate(-50%, -50%) rotate(${Y}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...xe?{[gd]:""}:{},onClick:Ae,onKeyDown:Ee,onVolumeChange:H=>M(H.currentTarget.volume),onPointerDown:st,onPointerMove:Pe,onPointerUp:ke,onPointerCancel:ke,onContextMenu:H=>{E.current&&H.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:H=>m(H.currentTarget.currentTime),onSeeked:H=>{const se=H.currentTarget;if(m(se.currentTime),C.current=!1,!y.current)return;const be=se.requestVideoFrameCallback;typeof be=="function"?be.call(se,()=>{y.current&&S()}):requestAnimationFrame(()=>{y.current&&S()})},onLoadedMetadata:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onDurationChange:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),xe&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed",{rate:String(ve)})}),Z!==null&&e.jsxs("div",{className:"pointer-events-none absolute right-3 top-3 z-10 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md","data-testid":"file-preview-video-volume",children:[e.jsx(fm,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round(Me*100)})]}),R&&fe!==null&&e.jsx("div",{className:"pointer-events-none absolute bottom-1 z-10 -translate-x-1/2 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground shadow-md",style:{left:`${ct*100}%`},"data-testid":"file-preview-video-scrub-time",children:ci(fe)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${pd}`,[gd]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ae,"aria-label":l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:i?e.jsx(hm,{size:14}):e.jsx(mm,{size:14})}),e.jsxs("div",{ref:p,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(T),"aria-valuenow":Math.floor(lt),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:q,onPointerMove:H=>{R&&Q(H.clientX)},onPointerUp:me,onPointerCancel:me,onKeyDown:qt,children:[e.jsx("div",{className:"h-1 w-full rounded-full bg-surface-elevated"}),e.jsx("div",{className:"absolute inset-y-0 left-0 my-auto h-1 rounded-full bg-primary",style:{width:`${ct*100}%`}}),e.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow",style:{left:`${ct*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[ci(lt)," / ",ci(T)]}),e.jsx("button",{type:"button",onClick:et,"aria-label":l("rightSidebar.videoRotate"),title:l("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:e.jsx(tu,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{at()},"aria-label":l(I?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(I?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:I?e.jsx(pm,{size:14}):e.jsx(gm,{size:14})})]})})]})}function Bp(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function lo({anchor:r,children:n,disabled:s=!1,onClick:l,title:u}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:u,style:Bp(r),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Qa,{size:11}),n]})}function Op(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const u=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(u)||u<=0)return null;const c=l.width*u,h=l.height*u,p=s.left+(s.width-c)/2,g=s.top+(s.height-h)/2,b=r-p,f=n-g;if(b<0||f<0||b>c||f>h)return null;const k=b/c*100,y=f/h*100;return{x:l.x+l.width*k/100,y:l.y+l.height*y/100,xPercent:k,yPercent:y}}function Up(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function Hp(r){const n=new DOMParser().parseFromString(r,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const u of Array.from(l.attributes)){const c=u.name.toLowerCase(),h=u.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(u.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function zp(r,n,s){let l=null;for(const u of Array.from(r.querySelectorAll("text"))){const c=(u.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(u.getAttribute("x")),p=Number(u.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(p))continue;const g=Math.hypot(h-n,p-s);(!l||g<l.distance)&&(l={text:c,distance:g})}return l?.text.slice(0,120)}function yu({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const u=a.useRef(null),c=a.useRef(null),[h,p]=a.useState(null),[g,b]=a.useState(null),[f,k]=a.useState(1),[y,C]=a.useState(!1),[D,_]=a.useState(null),B=a.useRef(new Map),E=a.useRef(null),N=a.useRef(!1),$=a.useRef(null),T=a.useRef(f);T.current=f,a.useEffect(()=>{const L=new AbortController;return p(null),b(null),_(null),k(1),fetch(r,{signal:L.signal}).then(I=>I.text()).then(I=>p(Hp(I))).catch(I=>{L.signal.aborted||b(I instanceof Error?I.message:"SVG preview failed")}),()=>L.abort()},[r]),a.useEffect(()=>{if(!y)return;const L=I=>{I.key==="Escape"&&C(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[y]),a.useLayoutEffect(()=>{const L=c.current,I=L?.querySelector("[data-svg-document] > svg");if(!L||!I)return;let K;try{K=I.getBBox()}catch{return}if(!K.width||!K.height)return;const re=Math.max(2,Math.min(K.width,K.height)*.025);I.setAttribute("viewBox",`${K.x-re} ${K.y-re} ${K.width+2*re} ${K.height+2*re}`),I.style.width=`${f*100}%`,I.style.height=`${f*100}%`,I.style.minWidth=`${f*100}%`,I.style.minHeight=`${f*100}%`,I.style.display="block"},[h,f]);const U=a.useMemo(()=>D?Up(n,s,D):null,[n,D,s]),F=L=>{if(N.current){N.current=!1;return}const I=c.current,K=I?.querySelector("[data-svg-document] > svg"),re=u.current;if(!I||!K||!re)return;const ce=K.viewBox.baseVal,ve=Op(L.clientX,L.clientY,K.getBoundingClientRect(),ce);if(!ve)return;const pe=re.getBoundingClientRect();_({...ve,nearestText:zp(K,ve.x,ve.y),stageX:L.clientX-pe.left,stageY:L.clientY-pe.top,stageXPercent:(L.clientX-pe.left)/pe.width*100,stageYPercent:(L.clientY-pe.top)/pe.height*100})},m=L=>Math.max(1,Math.min(12,L)),i=(L,I)=>{const K=m(I),re=L.querySelector("[data-svg-document] > svg");if(!re)return K;const ce=`${K*100}%`;return re.style.width=ce,re.style.height=ce,re.style.minWidth=ce,re.style.minHeight=ce,T.current=K,K},O=(L,I,K,re)=>{const ce=T.current,ve=L.getBoundingClientRect(),pe=K-ve.left,Me=re-ve.top,M=(L.scrollLeft+pe)/ce,Z=(L.scrollTop+Me)/ce,he=i(L,I);return L.scrollLeft=M*he-pe,L.scrollTop=Z*he-Me,he},R=()=>{const L=Array.from(B.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},G=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const I=c.current;I&&(B.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),I.setPointerCapture?.(L.pointerId),B.current.size>=2?(E.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:I.scrollLeft,startScrollTop:I.scrollTop,startDistance:R(),startZoom:T.current,moved:!1},N.current=!0):T.current>1&&(E.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:I.scrollLeft,startScrollTop:I.scrollTop,startZoom:T.current,moved:!1}))},fe=L=>{if(!B.current.has(L.pointerId))return;B.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const I=c.current,K=E.current;if(!(!I||!K)){if(B.current.size>=2&&K.kind==="pinch"){const re=R();if(!K.startDistance||!re)return;const ce=m(K.startZoom*re/K.startDistance);if(Math.abs(ce-T.current)<.01)return;const ve=Array.from(B.current.values()),pe=(ve[0].x+ve[1].x)/2,Me=(ve[0].y+ve[1].y)/2;K.moved=!0,N.current=!0,O(I,ce,pe,Me),L.preventDefault();return}if(K.kind==="pan"&&B.current.size===1){const re=L.clientX-K.startX,ce=L.clientY-K.startY;if(!K.moved&&Math.hypot(re,ce)<6)return;K.moved=!0,N.current=!0,I.scrollLeft=K.startScrollLeft-re,I.scrollTop=K.startScrollTop-ce,L.preventDefault()}}},te=L=>{const I=c.current,K=E.current,re=B.current.size===1&&!K?.moved;B.current.delete(L.pointerId);try{I?.releasePointerCapture?.(L.pointerId)}catch{}if(B.current.size===1&&K?.kind==="pinch"){const pe=Array.from(B.current.values())[0];E.current=I?{kind:"pan",startX:pe.x,startY:pe.y,startScrollLeft:I.scrollLeft,startScrollTop:I.scrollTop,startZoom:T.current,moved:!1}:null;return}if(B.current.size>0||(E.current=null,K?.kind==="pinch"&&k(T.current),!re||N.current))return;const ce=Date.now(),ve=$.current;ve&&ce-ve.time<350&&Math.hypot(L.clientX-ve.x,L.clientY-ve.y)<24?($.current=null,N.current=!0,k(pe=>pe>1?1:2.5)):$.current={time:ce,x:L.clientX,y:L.clientY}},xe=L=>{if(!L.ctrlKey&&!L.metaKey)return;const I=c.current;if(!I)return;L.preventDefault();const K=O(I,T.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);k(K)},W=()=>{k(1),T.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},Y=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:u,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:F,onDoubleClick:L=>{L.preventDefault(),k(I=>I>1?1:2.5)},onPointerDown:G,onPointerMove:fe,onPointerUp:te,onPointerCancel:te,onWheel:xe,onScroll:()=>_(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:g?e.jsx("div",{className:"p-4 text-sm text-destructive",children:g}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),D&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:D.stageX,top:D.stageY}}),D&&U&&e.jsx(lo,{anchor:{xPercent:D.stageXPercent,yPercent:D.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${D.x.toFixed(2)}:${D.y.toFixed(2)}`),_(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[f>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.stopPropagation(),W()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(qm,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),C(I=>!I)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(cu,{size:14}):e.jsx(iu,{size:14})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:D?`SVG (${D.x.toFixed(2)}, ${D.y.toFixed(2)}) · ${D.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?rn.createPortal(Y,document.body):Y}function Xa(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function Wp(r,n,s,l){const u=[`电子标注: ${r}`,`视图: ${Xa(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(u.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&u.push(`显示层: ${l.layer}`),l.nearest)){const c=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");u.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${u.join(" / ")}"`}function Gp({blobUrl:r,filePath:n,view:s,board:l,onViewChange:u,onInsertAnnotation:c,onRefresh:h,interactive3d:p}){const{t:g}=jt(),b=a.useRef(null),f=a.useRef(null),k=a.useRef(null),[y,C]=a.useState(null),[D,_]=a.useState(!1);a.useEffect(()=>(k.current?.abort(),C(null),_(!1),()=>k.current?.abort()),[r,s]);const B=a.useMemo(()=>y?Wp(n,s,y,y.inspection):null,[n,y,s]),E=$=>{const T=b.current,U=f.current;if(!T||!U||!U.naturalWidth||!U.naturalHeight)return;const F=T.getBoundingClientRect(),m=U.getBoundingClientRect(),i=Math.min(m.width/U.naturalWidth,m.height/U.naturalHeight),O=U.naturalWidth*i,R=U.naturalHeight*i,G=m.left+(m.width-O)/2,fe=m.top+(m.height-R)/2,te=$.clientX-G,xe=$.clientY-fe;if(te<0||xe<0||te>O||xe>R)return;const W={xPercent:Math.max(0,Math.min(100,te/O*100)),yPercent:Math.max(0,Math.min(100,xe/R*100)),stageXPercent:($.clientX-F.left)/F.width*100,stageYPercent:($.clientY-F.top)/F.height*100,inspecting:l&&s!=="pcb-3d"};if(C(W),k.current?.abort(),!W.inspecting)return;const Y=new AbortController;k.current=Y,Ah(n,s,W.xPercent,W.yPercent,Y.signal).then(L=>C(I=>I===W?{...I,inspection:L,inspecting:!1}:I)).catch(()=>{Y.signal.aborted||C(L=>L===W?{...L,inspection:{available:!1},inspecting:!1}:L)})},N=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:N.map($=>e.jsx("button",{type:"button",onClick:()=>u($),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${$===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Xa($)},$))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:g("rightSidebar.edaRefresh"),"aria-label":g("rightSidebar.edaRefresh"),children:e.jsx(Ei,{size:13})})]}),l&&p?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:p}):null,l?s==="pcb-3d"?p?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:b,role:"button",tabIndex:0,onClick:E,onKeyDown:$=>{$.key!=="Enter"&&$.key!==" "||($.preventDefault(),C({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:g("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:r,alt:`${n} ${Xa(s)}`,onLoad:()=>_(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${D?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&B&&e.jsx(lo,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:g("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(B,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?ep(f.current,y):Promise.resolve(null)}),C(null)},children:g("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?g("rightSidebar.edaInspecting"):y.inspection?.available?g("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??g("rightSidebar.edaNoNearbyObject")}):g("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):g("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(yu,{blobUrl:r,filePath:n,viewLabel:Xa(s),onInsertAnnotation:c})})]})}function Kp(r){const n=[];let s=[],l="",u=!1;for(let c=0;c<r.length;c+=1){const h=r[c];u?h==='"'&&r[c+1]==='"'?(l+='"',c+=1):h==='"'?u=!1:l+=h:h==='"'?u=!0:h===","?(s.push(l),l=""):h===`
14
- `?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=h}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function qp(r,n,s,l,u){const c=n[u]||`第${u+1}列`,h=s[u]??"",p=n.map((g,b)=>`${g||`第${b+1}列`}=${s[b]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${c} / 值: ${h} / 记录: ${p}"`}function Vp({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=jt(),u=a.useMemo(()=>Kp(r),[r]),c=u[0]??[],h=u.slice(1),p=a.useRef(null),[g,b]=a.useState(null),f=g?h[g.row]:null,k=g&&f?qp(n,c,f,g.row+1,g.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:p,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((y,C)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||l("rightSidebar.csvUnnamedColumn",{index:C+1})},`${y}:${C}`))]})}),e.jsx("tbody",{children:h.map((y,C)=>e.jsxs("tr",{className:"hover:bg-surface-2",children:[e.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:C+1}),c.map((D,_)=>{const B=g?.row===C&&g.column===_;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${B?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:E=>{const N=p.current?.getBoundingClientRect(),$=E.currentTarget.getBoundingClientRect();if(!N?.width||!N.height)return;const T=E.clientX||$.left+$.width/2,U=E.clientY||$.top+$.height/2;b({row:C,column:_,xPercent:(T-N.left)/N.width*100,yPercent:(U-N.top)/N.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[_]||" "})},`cell:${C}:${_}`)})]},`row:${C}`))})]})}),g&&k&&e.jsx(lo,{anchor:{xPercent:g.xPercent,yPercent:g.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(k,`csv:${n}:${g.row+1}:${g.column+1}`),b(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:g&&f?l("rightSidebar.csvSelectedCell",{row:g.row+1,column:c[g.column]||g.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:c.length})})})]})}function Vn(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function Yp(r,n){const s=JSON.parse(r),l=Vn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Vn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Vn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Vn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const u=Vn(s,["net_settings","classes"]),c=Array.isArray(u)?u.find(p=>p&&typeof p=="object"&&p.name==="Default"):void 0,h=Vn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(u)?u.length:0)},{label:"默认间距",value:c?.clearance!==void 0?`${c.clearance} mm`:"未设置"},{label:"默认线宽",value:c?.track_width!==void 0?`${c.track_width} mm`:"未设置"},{label:"默认过孔",value:c?.via_diameter!==void 0?`${c.via_diameter} / ${c.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function Xp(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function Jp({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:u}=jt(),c=a.useRef(null),[h,p]=a.useState(null),g=a.useMemo(()=>{try{return{items:Yp(r,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[r,s]),b=h===null?null:g.items[h.index];return g.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:r}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:u("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:g.items.map((f,k)=>e.jsxs("button",{type:"button",onClick:y=>{const C=c.current?.getBoundingClientRect(),D=y.currentTarget.getBoundingClientRect();if(!C?.width||!C.height)return;const _=y.clientX||D.left+D.width/2,B=y.clientY||D.top+D.height/2;p({index:k,xPercent:(_-C.left)/C.width*100,yPercent:(B-C.top)/C.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${h?.index===k?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:f.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:f.value})]},f.label))}),e.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:u("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),b&&h&&e.jsx(lo,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:u("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(Xp(n,b),`kicad-project:${n}:${b.label}`),p(null)},children:u("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?`${b.label}: ${b.value}`:u("rightSidebar.kicadProjectPickHint")})})]})}const Zp=`/** ES Module Shims Wasm @version 2.8.4 */
13
+ `;return`${r}${l}${s}`}function Mp(r,n){const s=r.trim();return s?n?`${s}\r`:/\s$/.test(r)?r:`${s} `:""}const Bi="termdock:right-sidebar:html-view-mode-by-file:v1";function $p(r){return r==="preview"||r==="source"}function wu(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every($p)}function ku(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function jd(r,n){const s=ku(r,n);return s?ut(Bi,wu)?.[s]??"source":"source"}function Lp(r,n,s){const l=ku(r,n);if(!l)return;const u=ut(Bi,wu)??{};$t(Bi,{...u,[l]:s})}function Ap(r){try{return new URL(r,location.href).pathname.startsWith("/api/")}catch{return!1}}const Pp=1500,Rd=256*1024*1024;async function Tp(r,n){const s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Media fallback failed: HTTP ${s.status}`);const l=s.headers.get("content-type")??"",u=s.body?.getReader();if(!u){const m=await s.blob();if(m.size>Rd)throw new Error("Media too large for encrypted fallback");return URL.createObjectURL(m)}const c=[];let h=0;try{for(;;){const{done:m,value:g}=await u.read();if(m)break;if(h+=g.byteLength,h>Rd)throw new Error("Media too large for encrypted fallback");c.push(g)}}catch(m){throw await u.cancel().catch(()=>{}),m}return URL.createObjectURL(new Blob(c,{type:l}))}function io(r,n){const s=Ap(r),[l,u]=a.useState(()=>!!navigator.serviceWorker?.controller),[c,h]=a.useState(void 0),m=a.useRef(n);return m.current=n,a.useEffect(()=>{if(!s||l)return;const g=navigator.serviceWorker,b=()=>u(!!g?.controller);return g?.addEventListener("controllerchange",b),b(),()=>g?.removeEventListener("controllerchange",b)},[s,l]),a.useEffect(()=>{if(!s||l){h(void 0);return}let g=!1,b;const f=new AbortController,k=window.setTimeout(()=>{Tp(r,f.signal).then(y=>{if(g){URL.revokeObjectURL(y);return}b=y,h(y)}).catch(()=>{g||f.signal.aborted||m.current?.()})},Pp);return()=>{g=!0,window.clearTimeout(k),f.abort(),b&&URL.revokeObjectURL(b)}},[s,l,r]),!s||l?r:c}function di(r){const n=Number.isFinite(r)&&r>0?Math.floor(r):0,s=Math.floor(n/3600),l=Math.floor(n%3600/60),u=n%60,c=String(l).padStart(2,"0"),h=String(u).padStart(2,"0");return s>0?`${s}:${c}:${h}`:`${c}:${h}`}function Ip(r,n,s){return!Number.isFinite(s)||s<=0||!n.width?0:Math.min(1,Math.max(0,(r-n.left)/n.width))*s}const rn=2,Dp=8,Fp=60,Ba=5,Cd=.05,_p=900;function Bp(r){return!Number.isFinite(r)||r<=0?rn:Math.min(Dp,rn+Math.floor(r/Fp))}const Op=350,Up=6,Hp=90;function zp({url:r,onLoadError:n}){const s=io(r,n),{t:l}=wt(),u=a.useRef(null),c=a.useRef(null),h=a.useRef(null),m=a.useRef(null),g=a.useRef(!1),b=a.useRef(null),f=a.useRef(null),k=a.useRef(0),y=a.useRef(!1),N=a.useRef(!1),I=a.useRef(!1),B=a.useRef(null),_=a.useRef(null),R=a.useRef(!1),E=a.useRef(1),$=a.useRef(!1),[P,U]=a.useState(0),[F,p]=a.useState(0),[i,O]=a.useState(!1),[C,G]=a.useState(!1),[fe,te]=a.useState(null),[xe,W]=a.useState(!1),[Y,L]=a.useState(0),[D,K]=a.useState(!1),[re,ce]=a.useState({width:0,height:0}),[ve,pe]=a.useState(rn),[Ee,M]=a.useState(1),[Z,he]=a.useState(null),Ne=a.useRef(rn),Ve=a.useRef(null),Ce=a.useCallback(()=>{B.current!==null&&(clearTimeout(B.current),B.current=null)},[]),Ye=a.useCallback(()=>{Ce();const H=_.current;if(_.current=null,!R.current)return!1;const se=h.current;if(se&&(se.playbackRate=E.current,H))try{se.releasePointerCapture?.(H.id)}catch{}return R.current=!1,Ne.current=rn,W(!1),!0},[Ce]);a.useEffect(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current),f.current!==null&&clearTimeout(f.current),Ve.current!==null&&clearTimeout(Ve.current),Ce();const H=h.current;H&&R.current&&(H.playbackRate=E.current)},[Ce]),a.useEffect(()=>{const H=c.current;if(!H||typeof ResizeObserver>"u")return;const se=new ResizeObserver(([be])=>{be&&ce({width:be.contentRect.width,height:be.contentRect.height})});return se.observe(H),()=>se.disconnect()},[]),a.useEffect(()=>{const H=()=>K(document.fullscreenElement===u.current);return document.addEventListener("fullscreenchange",H),()=>document.removeEventListener("fullscreenchange",H)},[]);const Ie=a.useCallback((H,se=!1)=>{const be=h.current;if(!be)return!1;const We=Number.isFinite(be.duration)?be.duration:H,ft=Math.min(Math.max(H,0),We);if(p(ft),Math.abs(be.currentTime-ft)<1/120)return!1;const dr=be.fastSeek;return se&&typeof dr=="function"?dr.call(be,ft):be.currentTime=ft,!0},[]),S=a.useCallback(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null;const H=h.current;if(!H||!y.current||N.current||H.seeking)return;const se=I.current;I.current=!1,N.current=Ie(k.current,!se)}))},[Ie]),Q=a.useCallback(H=>{const se=m.current,be=h.current;if(!se||!be)return;const We=se.getBoundingClientRect(),ft=Ip(H,We,be.duration);k.current=ft,te(ft),I.current=!1,S(),f.current!==null&&clearTimeout(f.current),f.current=setTimeout(()=>{f.current=null,I.current=!0,S()},Hp)},[S]),le=a.useCallback(()=>{b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),f.current!==null&&(clearTimeout(f.current),f.current=null),I.current=!1,N.current=!1,Ie(k.current)},[Ie]),q=a.useCallback(H=>{const se=h.current;if(!(!se||!Number.isFinite(se.duration)||se.duration<=0)){g.current=!se.paused,se.pause(),y.current=!0,G(!0);try{H.currentTarget.setPointerCapture(H.pointerId)}catch{}Q(H.clientX)}},[Q]),me=a.useCallback(()=>{y.current=!1,le(),G(!1),te(null);const H=h.current;H&&g.current&&!H.ended&&H.play().catch(()=>{}),g.current=!1},[le]),Ae=a.useCallback(()=>{const H=h.current;if(H){if($.current){$.current=!1;return}H.paused?H.play().catch(()=>{}):H.pause()}},[]),oe=a.useCallback(H=>{const se=h.current;if(!se)return;const be=Math.min(1,Math.max(0,Math.round((se.volume+H)*100)/100));se.volume=be,be>0&&(se.muted=!1),M(be),he(be),Ve.current!==null&&clearTimeout(Ve.current),Ve.current=setTimeout(()=>{Ve.current=null,he(null)},_p)},[]),Me=a.useCallback(H=>{const se=h.current;if(se){if(H.key==="ArrowLeft"){H.preventDefault(),Ie(se.currentTime-(H.shiftKey?Ba*2:Ba));return}if(H.key==="ArrowRight"){H.preventDefault(),Ie(se.currentTime+(H.shiftKey?Ba*2:Ba));return}if(H.key==="ArrowUp"){H.preventDefault(),oe(Cd);return}if(H.key==="ArrowDown"){H.preventDefault(),oe(-Cd);return}(H.key===" "||H.key==="Spacebar"||H.key==="k"||H.key==="K")&&(H.preventDefault(),se.paused?se.play().catch(()=>{}):se.pause())}},[Ie,oe]),st=a.useCallback(H=>{const se=h.current;!se||se.paused||H.button!==0||(Ce(),_.current={id:H.pointerId,x:H.clientX,y:H.clientY},B.current=setTimeout(()=>{B.current=null;const be=_.current;if(E.current=se.playbackRate,se.playbackRate=rn,Ne.current=rn,pe(rn),R.current=!0,W(!0),be)try{se.setPointerCapture?.(be.id)}catch{}},Op))},[Ce]),Pe=a.useCallback(H=>{const se=_.current;if(!se||se.id!==H.pointerId)return;if(!R.current){Math.hypot(H.clientX-se.x,H.clientY-se.y)>Up&&(Ce(),_.current=null);return}const be=Bp(H.clientX-se.x);if(be===Ne.current)return;Ne.current=be,pe(be);const We=h.current;We&&(We.playbackRate=be)},[Ce]),ke=a.useCallback(()=>{Ye()&&($.current=!0)},[Ye]);a.useEffect(()=>(window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",ke),()=>{window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",ke)}),[ke]);const at=a.useCallback(async()=>{const H=u.current,se=h.current;if(!(!H||!se))try{document.fullscreenElement===H?await document.exitFullscreen():H.requestFullscreen?await H.requestFullscreen():se.webkitEnterFullscreen?.()}catch{se.webkitEnterFullscreen?.()}},[]),et=a.useCallback(()=>L(H=>(H+90)%360),[]),qt=a.useCallback(H=>{const se=h.current;if(!se||!Number.isFinite(se.duration))return;const be=H.shiftKey?10:5;let We=null;H.key==="ArrowLeft"?We=se.currentTime-be:H.key==="ArrowRight"?We=se.currentTime+be:H.key==="Home"?We=0:H.key==="End"&&(We=se.duration),We!==null&&(H.preventDefault(),Ie(We))},[Ie]),lt=C&&fe!==null?fe:F,ct=P>0?Math.min(1,Math.max(0,lt/P)):0,Ft=(Y===90||Y===270)&&re.width>0&&re.height>0?{width:`${re.height}px`,height:`${re.width}px`}:{width:"100%",height:"100%"};return e.jsxs("div",{ref:u,className:"flex h-full min-h-0 flex-col overflow-hidden rounded-lg bg-background fullscreen:h-screen fullscreen:w-screen fullscreen:rounded-none","data-testid":"file-preview-video-player","data-rotation":Y,children:[e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1 overflow-hidden bg-background",children:[e.jsx("video",{ref:h,"data-testid":"file-preview-video",className:`absolute left-1/2 top-1/2 max-w-none object-contain outline-none transition-transform duration-200 focus-visible:ring-2 focus-visible:ring-primary/60${xe?` ${xd}`:""}`,style:{...Ft,transform:`translate(-50%, -50%) rotate(${Y}deg)`},src:s,preload:"auto",playsInline:!0,tabIndex:0,...xe?{[vd]:""}:{},onClick:Ae,onKeyDown:Me,onVolumeChange:H=>M(H.currentTarget.volume),onPointerDown:st,onPointerMove:Pe,onPointerUp:ke,onPointerCancel:ke,onContextMenu:H=>{R.current&&H.preventDefault()},onPlay:()=>O(!0),onPause:()=>O(!1),onTimeUpdate:H=>p(H.currentTarget.currentTime),onSeeked:H=>{const se=H.currentTarget;if(p(se.currentTime),N.current=!1,!y.current)return;const be=se.requestVideoFrameCallback;typeof be=="function"?be.call(se,()=>{y.current&&S()}):requestAnimationFrame(()=>{y.current&&S()})},onLoadedMetadata:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onDurationChange:H=>U(Number.isFinite(H.currentTarget.duration)?H.currentTarget.duration:0),onError:n,children:l("rightSidebar.videoUnsupported")}),xe&&e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-3 z-10 -translate-x-1/2 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md",children:l("rightSidebar.videoLongPressSpeed",{rate:String(ve)})}),Z!==null&&e.jsxs("div",{className:"pointer-events-none absolute right-3 top-3 z-10 inline-flex items-center gap-1 rounded-full bg-surface-elevated px-3 py-1 text-xs font-semibold tabular-nums text-foreground shadow-md","data-testid":"file-preview-video-volume",children:[e.jsx(gm,{size:13}),l("rightSidebar.videoVolume",{percent:Math.round(Ee*100)})]}),C&&fe!==null&&e.jsx("div",{className:"pointer-events-none absolute bottom-1 z-10 -translate-x-1/2 rounded-md bg-surface-elevated px-2 py-1 text-[11px] font-medium text-foreground shadow-md",style:{left:`${ct*100}%`},"data-testid":"file-preview-video-scrub-time",children:di(fe)})]}),e.jsx("div",{"data-testid":"file-preview-video-controls",className:`shrink-0 border-t border-border/60 bg-background px-2 py-1.5 ${xd}`,[vd]:"",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Ae,"aria-label":l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),title:l(i?"rightSidebar.videoPause":"rightSidebar.videoPlay"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-play",children:i?e.jsx(bm,{size:14}):e.jsx(xm,{size:14})}),e.jsxs("div",{ref:m,role:"slider","aria-label":"Seek","aria-valuemin":0,"aria-valuemax":Math.floor(P),"aria-valuenow":Math.floor(lt),tabIndex:0,className:"group relative h-5 min-w-0 flex-1 cursor-pointer touch-none py-2","data-testid":"file-preview-video-track",onPointerDown:q,onPointerMove:H=>{C&&Q(H.clientX)},onPointerUp:me,onPointerCancel:me,onKeyDown:qt,children:[e.jsx("div",{className:"h-1 w-full rounded-full bg-surface-elevated"}),e.jsx("div",{className:"absolute inset-y-0 left-0 my-auto h-1 rounded-full bg-primary",style:{width:`${ct*100}%`}}),e.jsx("div",{className:"absolute top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow",style:{left:`${ct*100}%`}})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground","data-testid":"file-preview-video-time",children:[di(lt)," / ",di(P)]}),e.jsx("button",{type:"button",onClick:et,"aria-label":l("rightSidebar.videoRotate"),title:l("rightSidebar.videoRotate"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-rotate",children:e.jsx(su,{size:14})}),e.jsx("button",{type:"button",onClick:()=>{at()},"aria-label":l(D?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),title:l(D?"rightSidebar.videoFullscreenExit":"rightSidebar.videoFullscreenEnter"),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-foreground transition hover:bg-surface-elevated active:scale-95","data-testid":"file-preview-video-fullscreen",children:D?e.jsx(vm,{size:14}):e.jsx(ym,{size:14})})]})})]})}function Wp(r){const n=Math.max(0,Math.min(100,r.xPercent)),s=Math.max(0,Math.min(100,r.yPercent));return{...n<=50?{left:`calc(${n}% + 8px)`}:{right:`calc(${100-n}% + 8px)`},...s<=50?{top:`calc(${s}% + 8px)`}:{bottom:`calc(${100-s}% + 8px)`}}}function lo({anchor:r,children:n,disabled:s=!1,onClick:l,title:u}){return e.jsxs("button",{type:"button","data-floating-annotation-button":!0,disabled:s,onClick:c=>{c.stopPropagation(),l()},title:u,style:Wp(r),className:"absolute z-30 inline-flex h-7 items-center gap-1 rounded-full bg-primary px-3 text-[11px] font-semibold text-primary-foreground shadow-lg ring-1 ring-primary/30 transition hover:bg-primary/90 active:scale-95 disabled:cursor-wait disabled:opacity-50",children:[e.jsx(Qa,{size:11}),n]})}function Gp(r,n,s,l){if(s.width<=0||s.height<=0||l.width<=0||l.height<=0)return null;const u=Math.min(s.width/l.width,s.height/l.height);if(!Number.isFinite(u)||u<=0)return null;const c=l.width*u,h=l.height*u,m=s.left+(s.width-c)/2,g=s.top+(s.height-h)/2,b=r-m,f=n-g;if(b<0||f<0||b>c||f>h)return null;const k=b/c*100,y=f/h*100;return{x:l.x+l.width*k/100,y:l.y+l.height*y/100,xPercent:k,yPercent:y}}function Kp(r,n,s){const l=[`SVG标注: ${r}`,`视图: ${n}`,`SVG坐标: (${s.x.toFixed(2)},${s.y.toFixed(2)}) [viewBox坐标]`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对内容边界左上角]`];return s.nearestText&&l.push(`最近文字: ${s.nearestText}`),`"${l.join(" / ")}"`}function qp(r){const n=new DOMParser().parseFromString(r,"image/svg+xml"),s=n.documentElement;if(s.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))throw new Error("Invalid SVG document");return n.querySelectorAll("script,foreignObject,iframe,object,embed").forEach(l=>l.remove()),n.querySelectorAll("*").forEach(l=>{for(const u of Array.from(l.attributes)){const c=u.name.toLowerCase(),h=u.value.trim();(c.startsWith("on")||(c==="href"||c.endsWith(":href"))&&h&&!h.startsWith("#"))&&l.removeAttribute(u.name)}}),s.removeAttribute("width"),s.removeAttribute("height"),s.setAttribute("preserveAspectRatio","xMidYMid meet"),new XMLSerializer().serializeToString(s)}function Vp(r,n,s){let l=null;for(const u of Array.from(r.querySelectorAll("text"))){const c=(u.textContent??"").replace(/\s+/g," ").trim();if(!c)continue;const h=Number(u.getAttribute("x")),m=Number(u.getAttribute("y"));if(!Number.isFinite(h)||!Number.isFinite(m))continue;const g=Math.hypot(h-n,m-s);(!l||g<l.distance)&&(l={text:c,distance:g})}return l?.text.slice(0,120)}function Su({blobUrl:r,filePath:n,viewLabel:s,onInsertAnnotation:l}){const u=a.useRef(null),c=a.useRef(null),[h,m]=a.useState(null),[g,b]=a.useState(null),[f,k]=a.useState(1),[y,N]=a.useState(!1),[I,B]=a.useState(null),_=a.useRef(new Map),R=a.useRef(null),E=a.useRef(!1),$=a.useRef(null),P=a.useRef(f);P.current=f,a.useEffect(()=>{const L=new AbortController;return m(null),b(null),B(null),k(1),fetch(r,{signal:L.signal}).then(D=>D.text()).then(D=>m(qp(D))).catch(D=>{L.signal.aborted||b(D instanceof Error?D.message:"SVG preview failed")}),()=>L.abort()},[r]),a.useEffect(()=>{if(!y)return;const L=D=>{D.key==="Escape"&&N(!1)};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[y]),a.useLayoutEffect(()=>{const L=c.current,D=L?.querySelector("[data-svg-document] > svg");if(!L||!D)return;let K;try{K=D.getBBox()}catch{return}if(!K.width||!K.height)return;const re=Math.max(2,Math.min(K.width,K.height)*.025);D.setAttribute("viewBox",`${K.x-re} ${K.y-re} ${K.width+2*re} ${K.height+2*re}`),D.style.width=`${f*100}%`,D.style.height=`${f*100}%`,D.style.minWidth=`${f*100}%`,D.style.minHeight=`${f*100}%`,D.style.display="block"},[h,f]);const U=a.useMemo(()=>I?Kp(n,s,I):null,[n,I,s]),F=L=>{if(E.current){E.current=!1;return}const D=c.current,K=D?.querySelector("[data-svg-document] > svg"),re=u.current;if(!D||!K||!re)return;const ce=K.viewBox.baseVal,ve=Gp(L.clientX,L.clientY,K.getBoundingClientRect(),ce);if(!ve)return;const pe=re.getBoundingClientRect();B({...ve,nearestText:Vp(K,ve.x,ve.y),stageX:L.clientX-pe.left,stageY:L.clientY-pe.top,stageXPercent:(L.clientX-pe.left)/pe.width*100,stageYPercent:(L.clientY-pe.top)/pe.height*100})},p=L=>Math.max(1,Math.min(12,L)),i=(L,D)=>{const K=p(D),re=L.querySelector("[data-svg-document] > svg");if(!re)return K;const ce=`${K*100}%`;return re.style.width=ce,re.style.height=ce,re.style.minWidth=ce,re.style.minHeight=ce,P.current=K,K},O=(L,D,K,re)=>{const ce=P.current,ve=L.getBoundingClientRect(),pe=K-ve.left,Ee=re-ve.top,M=(L.scrollLeft+pe)/ce,Z=(L.scrollTop+Ee)/ce,he=i(L,D);return L.scrollLeft=M*he-pe,L.scrollTop=Z*he-Ee,he},C=()=>{const L=Array.from(_.current.values());return L.length>=2?Math.hypot(L[0].x-L[1].x,L[0].y-L[1].y):0},G=L=>{if(L.pointerType==="mouse"&&L.button!==0)return;const D=c.current;D&&(_.current.set(L.pointerId,{x:L.clientX,y:L.clientY}),D.setPointerCapture?.(L.pointerId),_.current.size>=2?(R.current={kind:"pinch",startX:L.clientX,startY:L.clientY,startScrollLeft:D.scrollLeft,startScrollTop:D.scrollTop,startDistance:C(),startZoom:P.current,moved:!1},E.current=!0):P.current>1&&(R.current={kind:"pan",startX:L.clientX,startY:L.clientY,startScrollLeft:D.scrollLeft,startScrollTop:D.scrollTop,startZoom:P.current,moved:!1}))},fe=L=>{if(!_.current.has(L.pointerId))return;_.current.set(L.pointerId,{x:L.clientX,y:L.clientY});const D=c.current,K=R.current;if(!(!D||!K)){if(_.current.size>=2&&K.kind==="pinch"){const re=C();if(!K.startDistance||!re)return;const ce=p(K.startZoom*re/K.startDistance);if(Math.abs(ce-P.current)<.01)return;const ve=Array.from(_.current.values()),pe=(ve[0].x+ve[1].x)/2,Ee=(ve[0].y+ve[1].y)/2;K.moved=!0,E.current=!0,O(D,ce,pe,Ee),L.preventDefault();return}if(K.kind==="pan"&&_.current.size===1){const re=L.clientX-K.startX,ce=L.clientY-K.startY;if(!K.moved&&Math.hypot(re,ce)<6)return;K.moved=!0,E.current=!0,D.scrollLeft=K.startScrollLeft-re,D.scrollTop=K.startScrollTop-ce,L.preventDefault()}}},te=L=>{const D=c.current,K=R.current,re=_.current.size===1&&!K?.moved;_.current.delete(L.pointerId);try{D?.releasePointerCapture?.(L.pointerId)}catch{}if(_.current.size===1&&K?.kind==="pinch"){const pe=Array.from(_.current.values())[0];R.current=D?{kind:"pan",startX:pe.x,startY:pe.y,startScrollLeft:D.scrollLeft,startScrollTop:D.scrollTop,startZoom:P.current,moved:!1}:null;return}if(_.current.size>0||(R.current=null,K?.kind==="pinch"&&k(P.current),!re||E.current))return;const ce=Date.now(),ve=$.current;ve&&ce-ve.time<350&&Math.hypot(L.clientX-ve.x,L.clientY-ve.y)<24?($.current=null,E.current=!0,k(pe=>pe>1?1:2.5)):$.current={time:ce,x:L.clientX,y:L.clientY}},xe=L=>{if(!L.ctrlKey&&!L.metaKey)return;const D=c.current;if(!D)return;L.preventDefault();const K=O(D,P.current*Math.exp(-L.deltaY*.01),L.clientX,L.clientY);k(K)},W=()=>{k(1),P.current=1,c.current&&(c.current.scrollLeft=0,c.current.scrollTop=0)},Y=e.jsxs("div",{className:y?"fixed inset-0 z-modal-panel flex min-h-0 flex-col bg-surface pt-[env(safe-area-inset-top,0px)]":"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{ref:u,className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:c,role:"button",tabIndex:0,onClick:F,onDoubleClick:L=>{L.preventDefault(),k(D=>D>1?1:2.5)},onPointerDown:G,onPointerMove:fe,onPointerUp:te,onPointerCancel:te,onWheel:xe,onScroll:()=>B(null),className:"h-full touch-none cursor-crosshair overflow-auto bg-white p-3 text-slate-900",children:g?e.jsx("div",{className:"p-4 text-sm text-destructive",children:g}):h?e.jsx("div",{"data-svg-document":!0,className:"h-full min-h-[240px] w-full",dangerouslySetInnerHTML:{__html:h}}):e.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading SVG…"})}),I&&e.jsx("span",{"data-svg-pick-marker":!0,className:"pointer-events-none absolute z-10 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-white shadow-sm",style:{left:I.stageX,top:I.stageY}}),I&&U&&e.jsx(lo,{anchor:{xPercent:I.stageXPercent,yPercent:I.stageYPercent},title:"引用 SVG 标注",onClick:()=>{l?.(U,`svg:${I.x.toFixed(2)}:${I.y.toFixed(2)}`),B(null)},children:"引用 SVG 标注"}),e.jsxs("div",{"data-svg-toolbar":!0,className:"absolute right-2 top-2 z-20 flex gap-1",children:[f>1.001&&e.jsx("button",{type:"button","aria-label":"适合窗口",title:"适合窗口",onClick:L=>{L.stopPropagation(),W()},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:e.jsx(Jm,{size:14})}),e.jsx("button",{type:"button","aria-label":y?"退出全屏 SVG":"全屏 SVG",title:y?"退出全屏 SVG":"全屏 SVG",onClick:L=>{L.stopPropagation(),N(D=>!D)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-slate-200 bg-white/95 text-slate-600 shadow-sm backdrop-blur transition active:scale-95",children:y?e.jsx(fu,{size:14}):e.jsx(du,{size:14})})]})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:I?`SVG (${I.x.toFixed(2)}, ${I.y.toFixed(2)}) · ${I.nearestText??"附近无文字"}`:"点击 SVG 的问题位置生成精确引用"})})]});return y?Ir.createPortal(Y,document.body):Y}function Xa(r){switch(r){case"schematic":return"原理图第1页";case"pcb-front":return"PCB正面";case"pcb-back":return"PCB背面(镜像)";case"pcb-3d":return"PCB 3D正面"}}function Yp(r,n,s,l){const u=[`电子标注: ${r}`,`视图: ${Xa(n)}`,`图片位置: (${s.xPercent.toFixed(1)}%,${s.yPercent.toFixed(1)}%) [相对渲染图左上角]`];if(l?.available&&l.xMm!==void 0&&l.yMm!==void 0&&(u.push(`PCB坐标: (${l.xMm.toFixed(2)},${l.yMm.toFixed(2)})mm [KiCad板坐标]`),l.layer&&u.push(`显示层: ${l.layer}`),l.nearest)){const c=[l.nearest.net?`网络 ${l.nearest.net}`:null,`对象层 ${l.nearest.layer}`,`距离 ${l.nearest.distanceMm.toFixed(2)}mm`].filter(Boolean).join(",");u.push(`最近对象: ${l.nearest.label}${c?`(${c})`:""}`)}return`"${u.join(" / ")}"`}function Xp({blobUrl:r,filePath:n,view:s,board:l,onViewChange:u,onInsertAnnotation:c,onRefresh:h,interactive3d:m}){const{t:g}=wt(),b=a.useRef(null),f=a.useRef(null),k=a.useRef(null),[y,N]=a.useState(null),[I,B]=a.useState(!1);a.useEffect(()=>(k.current?.abort(),N(null),B(!1),()=>k.current?.abort()),[r,s]);const _=a.useMemo(()=>y?Yp(n,s,y,y.inspection):null,[n,y,s]),R=$=>{const P=b.current,U=f.current;if(!P||!U||!U.naturalWidth||!U.naturalHeight)return;const F=P.getBoundingClientRect(),p=U.getBoundingClientRect(),i=Math.min(p.width/U.naturalWidth,p.height/U.naturalHeight),O=U.naturalWidth*i,C=U.naturalHeight*i,G=p.left+(p.width-O)/2,fe=p.top+(p.height-C)/2,te=$.clientX-G,xe=$.clientY-fe;if(te<0||xe<0||te>O||xe>C)return;const W={xPercent:Math.max(0,Math.min(100,te/O*100)),yPercent:Math.max(0,Math.min(100,xe/C*100)),stageXPercent:($.clientX-F.left)/F.width*100,stageYPercent:($.clientY-F.top)/F.height*100,inspecting:l&&s!=="pcb-3d"};if(N(W),k.current?.abort(),!W.inspecting)return;const Y=new AbortController;k.current=Y,Ih(n,s,W.xPercent,W.yPercent,Y.signal).then(L=>N(D=>D===W?{...D,inspection:L,inspecting:!1}:D)).catch(()=>{Y.signal.aborted||N(L=>L===W?{...L,inspection:{available:!1},inspecting:!1}:L)})},E=l?["pcb-front","pcb-back","pcb-3d"]:["schematic"];return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-b border-border/15 px-3 py-2",children:[e.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:E.map($=>e.jsx("button",{type:"button",onClick:()=>u($),className:`h-8 shrink-0 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${$===s?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:Xa($)},$))}),e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:g("rightSidebar.edaRefresh"),"aria-label":g("rightSidebar.edaRefresh"),children:e.jsx($i,{size:13})})]}),l&&m?e.jsx("div",{className:s==="pcb-3d"?"flex min-h-0 flex-1 flex-col overflow-hidden":"hidden",children:m}):null,l?s==="pcb-3d"?m?null:e.jsx("div",{className:"min-h-0 flex-1"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:b,role:"button",tabIndex:0,onClick:R,onKeyDown:$=>{$.key!=="Enter"&&$.key!==" "||($.preventDefault(),N({xPercent:50,yPercent:50,stageXPercent:50,stageYPercent:50}))},className:"relative min-h-0 flex-1 cursor-crosshair overflow-hidden bg-surface p-3 outline-none",title:g("rightSidebar.edaPickHint"),children:[e.jsx("img",{ref:f,src:r,alt:`${n} ${Xa(s)}`,onLoad:()=>B(!0),className:`pointer-events-none h-full w-full object-contain transition-opacity ${I?"opacity-100":"opacity-0"}`}),y&&e.jsx("span",{className:"pointer-events-none absolute h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-primary bg-surface shadow-sm",style:{left:`${y.stageXPercent}%`,top:`${y.stageYPercent}%`}}),y&&_&&e.jsx(lo,{anchor:{xPercent:y.stageXPercent,yPercent:y.stageYPercent},disabled:y.inspecting,title:g("rightSidebar.edaInsertAnnotation"),onClick:()=>{c?.(_,`eda:${s}:${y.xPercent.toFixed(1)}:${y.yPercent.toFixed(1)}`,{snapshot:f.current?sp(f.current,y):Promise.resolve(null)}),N(null)},children:g("rightSidebar.edaInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:y?y.inspecting?g("rightSidebar.edaInspecting"):y.inspection?.available?g("rightSidebar.edaPickedBoardPosition",{x:y.inspection.xMm?.toFixed(2)??"—",y:y.inspection.yMm?.toFixed(2)??"—",object:y.inspection.nearest?.label??g("rightSidebar.edaNoNearbyObject")}):g("rightSidebar.edaPickedPosition",{x:y.xPercent.toFixed(1),y:y.yPercent.toFixed(1)}):g("rightSidebar.edaPickHint")})})]}):e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Su,{blobUrl:r,filePath:n,viewLabel:Xa(s),onInsertAnnotation:c})})]})}function Jp(r){const n=[];let s=[],l="",u=!1;for(let c=0;c<r.length;c+=1){const h=r[c];u?h==='"'&&r[c+1]==='"'?(l+='"',c+=1):h==='"'?u=!1:l+=h:h==='"'?u=!0:h===","?(s.push(l),l=""):h===`
14
+ `?(s.push(l.replace(/\r$/,"")),n.push(s),s=[],l=""):l+=h}return(l||s.length>0)&&(s.push(l.replace(/\r$/,"")),n.push(s)),n}function Zp(r,n,s,l,u){const c=n[u]||`第${u+1}列`,h=s[u]??"",m=n.map((g,b)=>`${g||`第${b+1}列`}=${s[b]??""}`).join(";");return`"表格标注: ${r} / 数据行: ${l+1} / 列: ${c} / 值: ${h} / 记录: ${m}"`}function Qp({content:r,filePath:n,onInsertAnnotation:s}){const{t:l}=wt(),u=a.useMemo(()=>Jp(r),[r]),c=u[0]??[],h=u.slice(1),m=a.useRef(null),[g,b]=a.useState(null),f=g?h[g.row]:null,k=g&&f?Zp(n,c,f,g.row+1,g.column):null;return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[e.jsxs("div",{ref:m,className:"relative min-h-0 flex-1",children:[e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs("table",{className:"min-w-full border-separate border-spacing-0 text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 top-0 z-20 border-b border-r border-border/20 bg-surface-elevated px-2 py-2 text-[10px] font-semibold text-muted-foreground",children:"#"}),c.map((y,N)=>e.jsx("th",{className:"sticky top-0 z-10 min-w-28 border-b border-r border-border/20 bg-surface-elevated px-3 py-2 font-semibold text-foreground",children:y||l("rightSidebar.csvUnnamedColumn",{index:N+1})},`${y}:${N}`))]})}),e.jsx("tbody",{children:h.map((y,N)=>e.jsxs("tr",{className:"hover:bg-surface-2",children:[e.jsx("th",{className:"sticky left-0 z-10 border-b border-r border-border/15 bg-surface px-2 py-2 text-right text-[10px] font-normal text-muted-foreground",children:N+1}),c.map((I,B)=>{const _=g?.row===N&&g.column===B;return e.jsx("td",{className:`border-b border-r border-border/15 p-0 ${_?"bg-primary/15":""}`,children:e.jsx("button",{type:"button",onClick:R=>{const E=m.current?.getBoundingClientRect(),$=R.currentTarget.getBoundingClientRect();if(!E?.width||!E.height)return;const P=R.clientX||$.left+$.width/2,U=R.clientY||$.top+$.height/2;b({row:N,column:B,xPercent:(P-E.left)/E.width*100,yPercent:(U-E.top)/E.height*100})},className:"block h-full min-h-9 w-full whitespace-pre-wrap px-3 py-2 text-left text-foreground outline-none hover:bg-primary/10 focus-visible:bg-primary/10",children:y[B]||" "})},`cell:${N}:${B}`)})]},`row:${N}`))})]})}),g&&k&&e.jsx(lo,{anchor:{xPercent:g.xPercent,yPercent:g.yPercent},title:l("rightSidebar.csvInsertAnnotation"),onClick:()=>{s?.(k,`csv:${n}:${g.row+1}:${g.column+1}`),b(null)},children:l("rightSidebar.csvInsertAnnotation")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:g&&f?l("rightSidebar.csvSelectedCell",{row:g.row+1,column:c[g.column]||g.column+1}):l("rightSidebar.csvPickHint",{rows:h.length,columns:c.length})})})]})}function Vn(r,n){let s=r;for(const l of n){if(!s||typeof s!="object")return;s=s[l]}return s}function eg(r,n){const s=JSON.parse(r),l=Vn(s,["meta","version"]);if(n)return[{label:"文件性质",value:"KiCad 本机界面状态,不属于电气设计源文件"},{label:"格式版本",value:String(l??"未知")},{label:"活动层编号",value:String(Vn(s,["board","active_layer"])??"未知")},{label:"可见层掩码",value:String(Vn(s,["board","visible_layers"])??"未知")},{label:"Git 集成",value:Vn(s,["git","integration_disabled"])===!0?"已禁用":"未禁用"}];const u=Vn(s,["net_settings","classes"]),c=Array.isArray(u)?u.find(m=>m&&typeof m=="object"&&m.name==="Default"):void 0,h=Vn(s,["board","design_settings","drc_exclusions"]);return[{label:"文件性质",value:"KiCad 工程配置"},{label:"格式版本",value:String(l??"未知")},{label:"网络类数量",value:String(Array.isArray(u)?u.length:0)},{label:"默认间距",value:c?.clearance!==void 0?`${c.clearance} mm`:"未设置"},{label:"默认线宽",value:c?.track_width!==void 0?`${c.track_width} mm`:"未设置"},{label:"默认过孔",value:c?.via_diameter!==void 0?`${c.via_diameter} / ${c.via_drill??"—"} mm(外径/钻孔)`:"未设置"},{label:"DRC 排除项",value:String(Array.isArray(h)?h.length:0)}]}function tg(r,n){return`"KiCad项目标注: ${r} / 项: ${n.label} / 值: ${n.value}"`}function rg({content:r,filePath:n,localState:s,onInsertAnnotation:l}){const{t:u}=wt(),c=a.useRef(null),[h,m]=a.useState(null),g=a.useMemo(()=>{try{return{items:eg(r,s),error:null}}catch(f){return{items:[],error:f instanceof Error?f.message:String(f)}}},[r,s]),b=h===null?null:g.items[h.index];return g.error?e.jsx("pre",{className:"min-h-0 flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-xs text-foreground",children:r}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col bg-surface",children:[s&&e.jsx("div",{className:"border-b border-[color:var(--warning)]/20 bg-[color:var(--warning)]/5 px-3 py-2 text-xs text-[color:var(--warning)]",children:u("rightSidebar.kicadLocalStateNotice")}),e.jsxs("div",{ref:c,className:"relative min-h-0 flex-1",children:[e.jsxs("div",{className:"h-full overflow-auto px-3 py-2",children:[e.jsx("div",{className:"divide-y divide-border/15",children:g.items.map((f,k)=>e.jsxs("button",{type:"button",onClick:y=>{const N=c.current?.getBoundingClientRect(),I=y.currentTarget.getBoundingClientRect();if(!N?.width||!N.height)return;const B=y.clientX||I.left+I.width/2,_=y.clientY||I.top+I.height/2;m({index:k,xPercent:(B-N.left)/N.width*100,yPercent:(_-N.top)/N.height*100})},className:`grid w-full grid-cols-[minmax(7rem,0.8fr)_minmax(0,1.4fr)] gap-3 px-2 py-3 text-left transition hover:bg-surface-2 ${h?.index===k?"bg-primary/10":""}`,children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:f.label}),e.jsx("span",{className:"break-words text-xs text-foreground",children:f.value})]},f.label))}),e.jsxs("details",{className:"mt-3 border-t border-border/15 pt-3",children:[e.jsx("summary",{className:"cursor-pointer text-xs font-semibold text-muted-foreground",children:u("rightSidebar.kicadShowRawJson")}),e.jsx("pre",{className:"mt-2 overflow-auto whitespace-pre p-2 font-mono text-[10px] leading-relaxed text-foreground",children:r})]})]}),b&&h&&e.jsx(lo,{anchor:{xPercent:h.xPercent,yPercent:h.yPercent},title:u("rightSidebar.kicadInsertSetting"),onClick:()=>{l?.(tg(n,b),`kicad-project:${n}:${b.label}`),m(null)},children:u("rightSidebar.kicadInsertSetting")})]}),e.jsx("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border/15 px-3 py-2",children:e.jsx("span",{className:"min-w-0 truncate text-[11px] text-muted-foreground",children:b?`${b.label}: ${b.value}`:u("rightSidebar.kicadProjectPickHint")})})]})}const ng=`/** ES Module Shims Wasm @version 2.8.4 */
15
15
  (function () {
16
16
 
17
17
  const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
@@ -1497,7 +1497,7 @@ import{a4 as Tr,bf as e,cJ as jt,cT as $t,bx as ut,a as Ps,aO as Zd,C as Ci,c as
1497
1497
  };
1498
1498
 
1499
1499
  })();
1500
- `,Qp=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1500
+ `,sg=`/* Runs only in the opaque preview frame. All local reads use its directory capability. */
1501
1501
  function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
1502
1502
  const external = new Set(externalOrigins);
1503
1503
  const report = () => parent.postMessage({ type: 'preview-error', capability }, '*');
@@ -1632,47 +1632,47 @@ function installPreviewRuntime(capability, base, externalOrigins, shimUrl) {
1632
1632
  window.addEventListener('error', report, true);
1633
1633
  window.addEventListener('unhandledrejection', report);
1634
1634
  }
1635
- `,Oa="/api/terminal/fs/preview/",eg=8*1024*1024,tg=32*1024*1024,rg=128,ng="data:,";function Et(r){throw new Error(r)}function sg(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function jd(r,n,s){let l="",u=0;for(const c of r.matchAll(n))l+=r.slice(u,c.index)+await s(c),u=c.index+c[0].length;return l+r.slice(u)}async function wu(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!ks(l.pathname)?.startsWith(Oa))&&Et("预览地址不是有效的本地文件入口");const u=crypto.randomUUID(),c=`https://termdock-preview.invalid/${u}/`,h=[],p=W=>{!h.includes(W)&&h.length<20&&h.push(W)},g=new Set,b=[],f=new Set,k=new Map,y=new Map;let C=0,D=!1;const _=new Set,B=()=>{D=!0;for(const W of[..._])W();g.clear(),b.length=0};async function E(W){W.ok||Et(`预览资源读取失败(${W.status})`);const Y=W.body?.getReader(),L=[];let I=0;try{if(Y)for(;;){const ce=await Y.read();if(ce.done)break;I+=ce.value.byteLength,C+=ce.value.byteLength,(I>eg||C>tg)&&Et("预览资源超出大小限制"),L.push(ce.value)}}catch(ce){throw await Y?.cancel().catch(()=>{}),ce}finally{Y?.releaseLock()}const K=new Uint8Array(I);let re=0;for(const ce of L)K.set(ce,re),re+=ce.length;return{bytes:K,type:W.headers.get("content-type")??"application/octet-stream",status:W.status}}let N=l,$;for(let W=0;W<4;W++){const Y=await n.fetch(N.pathname+N.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(Y.status)){$=Y;break}const L=Y.headers.get("location");await Y.body?.cancel(),L||Et("预览重定向缺少目标");const I=new URL(L,N);(I.origin!==s||!ks(I.pathname)?.startsWith(Oa))&&Et("预览重定向越出文件范围"),N=I}$||Et("预览重定向次数过多");const T=ks(N.pathname),U=T.slice(Oa.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||Et("服务未提供有效的预览资源授权");const F=ks(l.pathname).slice(Oa.length).split("/");/^[a-f0-9]{32}$/.test(F[0])&&F.shift(),F.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&Et("预览重定向改变了文件范围");const m=T.endsWith("/")?T:T.slice(0,T.lastIndexOf("/")+1),i=new URL(N.pathname.endsWith("/")?N.pathname:N.pathname.slice(0,N.pathname.lastIndexOf("/")+1),s);function O(W,Y){const L=new URL(W,Y);return L.origin!==s?null:(ks(L.pathname)?.startsWith(m)||Et("已阻止预览访问目录之外的资源"),L)}function R(W){const Y=new URL(W,c);(Y.origin!==new URL(c).origin||!Y.pathname.startsWith(new URL(c).pathname))&&Et("已阻止预览访问服务接口或目录之外的资源");const L=Y.pathname.slice(new URL(c).pathname.length)+Y.search;return O(L,i)??Et("预览资源无效")}function G(W){const Y=W.pathname+W.search,L=k.get(Y);if(L)return L;if(D||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(k.size>=rg)return Promise.reject(new Error("预览资源数量超出限制"));const I=n.fetch(Y,{signal:n.signal,redirect:"manual"}).then(E);return k.set(Y,I),I}function fe(W,Y){D&&Et("预览已关闭");const L=`termdock-resource-${u}-${b.length}`;return b.push({token:L,data:W,type:Y}),g.add(L),L}async function te(W,Y,L,I=new Set){if(!W||W.startsWith("#")||/^data:(?:image|font)\//i.test(W)&&L==="resource")return W;try{const K=O(W,Y);if(!K){const Me=new URL(W,Y);return(Me.protocol!=="https:"||Me.username||Me.password||Me.origin===new URL(c).origin)&&Et("已阻止不安全的外部资源"),f.add(Me.origin),Me.href}const re=`${L}:${K.href}`;(I.has(re)||I.size>=8)&&Et("预览资源存在循环或过深引用");const ce=y.get(re);if(ce)return ce;const ve=new Set(I);ve.add(re);const pe=(async()=>{const Me=await G(K);return L==="css"?fe(await xe(new TextDecoder().decode(Me.bytes),K,ve),"text/css"):L==="script"?fe(Me.bytes,"text/javascript"):fe(Me.bytes,Me.type)})();return y.set(re,pe),await pe}catch(K){return p(K instanceof Error?K.message:"部分预览资源未能加载"),ng}}async function xe(W,Y,L){return W=await jd(W,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async I=>`@import url("${await te(I[1],Y,"css",L)}")${I[2]};`),jd(W,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async I=>{const K=(I[1]??I[2]??I[3]).trim();return g.has(K)?I[0]:`url("${await te(K,Y,"resource",L)}")`})}try{const W=await E($),Y=fe(Zp,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(W.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(M=>M.remove());for(const M of L.querySelectorAll("*")){if(M.removeAttribute("ping"),M.removeAttribute("srcdoc"),M.hasAttribute("style")&&M.setAttribute("style",await xe(M.getAttribute("style"),N,new Set)),M.tagName==="STYLE"&&(M.textContent=await xe(M.textContent??"",N,new Set)),M.tagName==="A"||M.tagName==="AREA"){const Z=M.getAttribute("href");try{if(Z&&!Z.startsWith("#")){const he=O(Z,N);if(he)M.setAttribute("href",new URL(he.pathname.slice(i.pathname.length)+he.search+he.hash,c).href);else{const Ne=new URL(Z,N);if(Ne.protocol!=="https:"){M.removeAttribute("href");continue}f.add(Ne.origin),M.setAttribute("href",Ne.href)}}}catch(he){M.removeAttribute("href"),p(he instanceof Error?he.message:"预览链接无法加载")}}for(const Z of["data","manifest"])M.removeAttribute(Z);if(M.tagName==="SCRIPT"&&M.getAttribute("type")==="module"){M.setAttribute("type","module-shim");const Z=M.getAttribute("src");if(Z){const he=O(Z,N);if(he)M.setAttribute("src",new URL(he.pathname.slice(i.pathname.length)+he.search,c).href);else{const Ne=new URL(Z,N);if(Ne.protocol!=="https:"){M.remove();continue}f.add(Ne.origin),M.setAttribute("src",Ne.href)}}continue}if(M.tagName==="SCRIPT"&&M.getAttribute("type")==="importmap"){M.setAttribute("type","importmap-shim");continue}if(M.tagName==="LINK"){const Z=(M.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(Z)){M.remove();continue}const he=M.getAttribute("href");he&&M.setAttribute("href",await te(he,N,Z==="stylesheet"?"css":"resource"))}if(M.hasAttribute("src")&&M.setAttribute("src",await te(M.getAttribute("src"),N,M.tagName==="SCRIPT"?"script":"resource")),M.hasAttribute("poster")&&M.setAttribute("poster",await te(M.getAttribute("poster"),N,"resource")),M.hasAttribute("srcset")){const Z=M.getAttribute("srcset");/data:/i.test(Z)?(M.removeAttribute("srcset"),p("混合内嵌图片候选暂不支持安全预览")):M.setAttribute("srcset",(await Promise.all(Z.split(",").map(async he=>{const[Ne,...Ve]=he.trim().split(/\s+/);return`${await te(Ne,N,"resource")} ${Ve.join(" ")}`}))).join(", "))}M.setAttribute("referrerpolicy","no-referrer"),M.removeAttribute("integrity"),M.removeAttribute("crossorigin")}const I=[...f].join(" "),K=L.createElement("meta");K.httpEquiv="Content-Security-Policy",K.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${I}; style-src 'unsafe-inline' blob: ${I}; img-src blob: data: ${I}; font-src blob: data: ${I}; media-src blob: data: ${I}; connect-src blob: ${I} ${[...f].map(M=>M.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const re=L.createElement("base");re.href=c;const ce=L.createElement("meta");ce.name="referrer",ce.content="no-referrer";const ve=L.createElement("script");ve.textContent=Qp+`
1636
- installPreviewRuntime(`+[u,c,[...f],Y].map(sg).join(",")+");";const pe=L.createElement("script");pe.src=Y,L.head.prepend(K,ce,re,ve,pe);const Me=`<!doctype html>
1637
- `+L.documentElement.outerHTML;return{html:Me,shellUrl:`/preview-shell.html#${u}`,errors:h,attach(M,Z){const he=new Set,Ne=Ce=>{if(Ce.source!==M.contentWindow||Ce.data?.capability!==u)return;if(Ce.data.type==="preview-ready"){M.contentWindow?.postMessage({type:"preview-init",capability:u,html:Me,resources:b},"*");return}if(Ce.data.type==="preview-error"){Z("部分动态内容被安全预览限制");return}if(Ce.data.type==="preview-navigate"){(async()=>{const Ie=R(String(Ce.data.url)),S=await wu(Ie.pathname+Ie.search,n);if(D){S.dispose();return}const Q=S.attach(M,Z);_.add(()=>{Q(),S.dispose()}),M.src=S.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(Ie=>Z(Ie instanceof Error?Ie.message:"无法打开预览页面"));return}if(Ce.data.type==="preview-external"){try{const Ie=new URL(String(Ce.data.url));Ie.protocol==="https:"&&f.has(Ie.origin)&&window.open(Ie.href,"_blank","noopener,noreferrer")}catch{}return}if(Ce.data.type!=="preview-fetch"||Ce.ports.length!==1)return;const Ye=Ce.ports[0];if(he.size>=8||!["GET","HEAD"].includes(Ce.data.method)){Ye.postMessage({error:"预览仅允许读取已授权目录资源"}),Ye.close();return}he.add(Ye),(async()=>{const Ie=R(String(Ce.data.url)),S=await G(Ie);if(!he.has(Ye)||D)return;const Q=Ce.data.method==="HEAD"?new Uint8Array:S.bytes.slice();Ye.postMessage({status:S.status,headers:{"content-type":S.type},data:Q.buffer},[Q.buffer])})().catch(()=>{Ye.postMessage({error:"预览资源不在授权范围或无法加载"}),Z("部分动态资源不可用或超出预览目录")}).finally(()=>{he.delete(Ye),Ye.close()})};window.addEventListener("message",Ne);const Ve=()=>{window.removeEventListener("message",Ne);for(const Ce of he)Ce.close();he.clear(),_.delete(Ve)};return _.add(Ve),Ve},dispose:B}}catch(W){throw B(),W}}const ag=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:u},c){const h=a.useRef(null),[p,g]=a.useState(null),[b,f]=a.useState(),[k,y]=a.useState("");a.useEffect(()=>{const T=new AbortController;let U;return f(void 0),y(""),(async()=>{const F=await Ph();if(U=await wu(n,{fetch:(m,i)=>F.fetch(m,i),signal:T.signal}),T.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(F=>{T.signal.aborted||y(F instanceof Error?F.message:"安全预览加载失败")}),()=>{T.abort(),U?.dispose()}},[n]),a.useEffect(()=>{if(!(!b||!p))return b.attach(p,y)},[b,p]);const[C,D]=a.useState(!1),[_,B]=a.useState(!1),E=C||_;a.useEffect(()=>{u?.(E)},[E,u]),a.useEffect(()=>{const T=()=>{D(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",T),()=>document.removeEventListener("fullscreenchange",T)},[]),a.useEffect(()=>{if(!_)return;const T=U=>{U.key==="Escape"&&B(!1)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[_]);const N=a.useCallback(async()=>{const T=h.current;if(T){if(_){B(!1);return}if(document.fullscreenElement===T){await document.exitFullscreen();return}if(T.requestFullscreen&&document.fullscreenEnabled!==!1)try{await T.requestFullscreen();return}catch{}B(!0)}},[_]);a.useImperativeHandle(c,()=>({toggleFullscreen:N}),[N]);const $=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:E?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[E&&e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[e.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:s}),e.jsx("button",{type:"button",onClick:()=>{N()},"aria-label":l,title:`${l} (Esc)`,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:e.jsx(cu,{size:15})})]}),k&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:k}),!b&&!k&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:g,src:b?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return _?rn.createPortal($,document.body):$}),ku="termdock-file-search-match",Bi="termdock-file-search-current";function og(r){const n=r.metaKey||r.ctrlKey,s=r.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||r.key==="F3"?r.shiftKey?"previous":"next":r.key==="Escape"?"close":null}function ig(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function lg(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let u="",c=null;const h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const k=ig(f);if(!k)continue;c&&c!==k&&(u+=`
1638
- `);const y=u.length;u+=f.data,l.push({node:f,start:y,end:u.length,group:k}),c=k}const p=u.toLocaleLowerCase(),g=[];let b=0;for(;b<=p.length-s.length;){const f=p.indexOf(s,b);if(f<0)break;const k=f+s.length,y=l.find(D=>D.start<=f&&D.end>f),C=l.find(D=>D.start<k&&D.end>=k);if(y&&C&&y.group===C.group){const D=document.createRange();D.setStart(y.node,f-y.start),D.setEnd(C.node,k-C.start),g.push(D)}b=f+Math.max(s.length,1)}return g}function Su(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Ua(){const r=Su();r?.delete(ku),r?.delete(Bi)}function Rd(r,n){const s=Su();if(!s||typeof Highlight>"u")return;s.set(ku,new Highlight(...r));const l=r[n];l?s.set(Bi,new Highlight(l)):s.delete(Bi)}function Cd(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function cg(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function dg(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function ug(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function ju(r,n,s){return n?r:rn.createPortal(r,s)}const Zi="termdock:right-sidebar:file-tree-scroll:v1",Qi="termdock:right-sidebar:file-preview-reading-state:v1",Ns="termdock:right-sidebar:file-tree-width:v1",Ru="termdock:right-sidebar:markdown-view-mode:v1",Cu="termdock:right-sidebar:diff-change-list-mode:v1",Nu="termdock:right-sidebar:diff-wrap:v1",Mu="termdock:diff-viewer:view-type:v1",Eu="termdock:right-sidebar:file-search-mode:v1",di="termdock:right-sidebar:collapsed-git-repo-groups:v1",Nd="termdock:right-sidebar:collapsed-diff-directories:v1",ui="termdock:right-sidebar:branch-audit-module-open:v1",$u="termdock:right-sidebar:branch-audit-module:v1",fg=150,Md="termdock:right-sidebar:context-draft-enabled:v1",Ed="termdock:right-sidebar:context-draft-collapsed:v1",$d="termdock:right-sidebar:context-draft-auto-collapse:v1",fi="termdock:right-sidebar:context-draft-text:v1",hg=300,mg=20,pg=120,gg=250,bg=250,xg=120,vg=700,hi=600,yg=6e4;function Yn(r){return!!(r&&J.getState().nestedGitScanRoots[r])}const Ld=[2e3,5e3,15e3,3e4],wg=320,kg=500,Sg=20,jg=12e3,Oi=300,Ad=240,Rg=560,Lu="border-r px-2 py-1.5 sm:px-3 sm:py-2",eo="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Au=`${Lu} border-b border-border/15 font-semibold last:border-r-0`,Pu=`${Lu} border-border/10 align-top text-muted-foreground last:border-r-0`,el="termdock-file-preview-horizontal-scroll",Pd=a.lazy(()=>Is(()=>import("./ModelPreview-COGEMw6A.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Tu=`${el} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function Iu(r,n,s){return r&&!n?"unified":s}const Cg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Ng(r){return r==="preview"||r==="source"}function Mg(r){return r==="list"||r==="tree"||r==="ai"}function Td(){return ut(Ru,Ng)??"preview"}function Eg(){return ut(Cu,Mg)??"tree"}function Ms(r){return typeof r=="boolean"}function $g(r){return typeof r=="string"}function Lg(){return ut(Nu,Ms)??!0}function Ag(r){return r==="unified"||r==="split"}function Pg(){return ut(Mu,Ag)??"unified"}function Tg(r){return r==="name"||r==="content"||r==="regex"}function Ig(){return ut(Eu,Tg)??"name"}function Du(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:vt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function Dg(r,n){if(!n)return null;const s=new Set((r.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(r.repositories??[]).some(l=>l.root===n)?n:null}function Ui(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function Fu(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function Hi(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function Id(r){const n=ut(r,Hi);return n?new Set(n):new Set}function mi(r,n){$t(r,[...n])}function Fg(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function _g(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||Hi(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(Fg))&&(n.commits===void 0||Hi(n.commits))&&(n.commitCount===void 0||typeof n.commitCount=="number")&&(n.diff===void 0||typeof n.diff=="string")&&(n.truncated===void 0||typeof n.truncated=="boolean")&&(n.error===void 0||typeof n.error=="string")}function Bg(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&_g(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function Og(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(Bg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Dd(){return ut($u,Og)??{}}function Fd(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function _d(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function _u(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||_d(s)===_d(l)}function Bd(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!_u(l,n))??""}function zi(r,n){const s=Math.max(Ad,n-320),l=Math.min(Rg,s);return Math.min(l,Math.max(Ad,r))}function Ug(r){return typeof r=="number"&&Number.isFinite(r)}function Hg(r){return zi(ut(Ns,Ug)??Oi,r)}function Bu(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function Rs(r){return Cg.has(Bu(r))}function Ou(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Wi(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||Ou(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function Uu(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const Hu=a.createContext(null);function Ja(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function zu(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function Wu(r){return r.replace(/\s+#+\s*$/,"").trim()}function Gi(r,n){const l=zu(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",u=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,u+1),u===0?l:`${l}-${u}`}function Od(r){return zu(r)||r.trim()}function to(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=qi(n[2]);return s?{id:Ja(n[1]),definition:{href:s.href,title:s.title}}:null}function zg(r){const n=new Map;for(const s of r){const l=to(s);l&&n.set(l.id,l.definition)}return n}function Gu(r){return r.trim().toLowerCase()}function Ku(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Gu(n[1]),text:n[2]}:null}function Wg(r){const n=new Map;let s=null;for(const l of r){const u=Ku(l);if(u){s=u.id,n.set(u.id,{id:u.id,text:u.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const c=n.get(s);c&&(c.text=`${c.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function qu(r){const n=new Set;let s=!1;return r.forEach((l,u)=>{if(Ku(l)){n.add(u),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(u);return}l.trim()&&(s=!1)}),n}function Gg(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const u=r[s].trim();if(u.startsWith("<!--")){if(n[s]="",!u.includes("-->")){for(s+=1;s<r.length&&!r[s].includes("-->");)n[s]="",s+=1;s<r.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Vu(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function Ls(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function tl(r,n,s){const l=r.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const u=l.indexOf("#"),c=u>=0?l.slice(0,u):l,h=u>=0?l.slice(u+1):"",p=c.split("?",1)[0];if(!p)return null;let g,b=null;try{g=decodeURIComponent(p),b=h?decodeURIComponent(h):null}catch{return null}const f=s?Ls(s):null;let k;if(g.startsWith("/")){const y=f&&(g===f||g.startsWith(`${f}/`));k=Ls(f&&!y?`${f}/${g.slice(1)}`:g)}else{if(!n)return null;k=Ls(`${Vu(n)}/${g}`)}return f&&k!==f&&!k.startsWith(`${f}/`)?null:{path:k,fragment:b,directory:/\/$/.test(p)}}function rl(r,n,s,l,u){const c=r.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let h;if(c.startsWith("/")){const p=s&&(c===s||c.startsWith(`${s}/`));h=Ls(s&&!p?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=Ls(`${Vu(n)}/${c}`)}return u(h)}function Kg(r,n,s){return rl(r,n,s,Ji,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function qg(r,n,s){return rl(r,n,s,Qd,eu)}const Ki=128,Vg=360,pi=480;function co(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function Yu(r,n,s,l,u=0){if(!n||!s)return null;let c,h;return u>0?(c=l>0?Math.min(u,l):u,h=s*c/n):co(r)?(h=Math.min(Math.max(s,Ki),Vg),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>pi&&(c=c*pi/h,h=pi),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function Yg(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function Xu(r){const n=Yg(r),s=J(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function Xg({src:r,alt:n,title:s,requestedWidthPx:l}){const u=co(r),c=Xu(r),h=io(c),p=a.useRef(null),[g,b]=a.useState(!1),[f,k]=a.useState(0),[y,C]=a.useState({status:"loading"}),[D,_]=a.useState(null);a.useLayoutEffect(()=>{const N=p.current,$=N?.parentElement?.parentElement??N?.parentElement;if(!$)return;const T=()=>k($.clientWidth);if(T(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(T);return U.observe($),()=>U.disconnect()},[]),a.useEffect(()=>{if(g)return;const N=p.current;if(!N||typeof IntersectionObserver>"u"){b(!0);return}const $=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(b(!0),$.disconnect())},{rootMargin:"400px"});return $.observe(N),()=>$.disconnect()},[g]),a.useEffect(()=>{if(!g)return;const N=new AbortController;let $=null;C({status:"loading"});const T=window.setTimeout(()=>{N.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return cm(c,{signal:N.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=Number(U.headers.get("X-Image-Width"))||0,m=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:F,height:m}}).then(({blob:U,width:F,height:m})=>{N.signal.aborted||($=URL.createObjectURL(U),F>0&&m>0&&_({width:F,height:m}),C({status:"ready",objectUrl:$}))}).catch(()=>{const U=N.signal.reason;N.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||C({status:"fallback"})}).finally(()=>{window.clearTimeout(T)}),()=>{window.clearTimeout(T),N.abort(),$&&URL.revokeObjectURL($)}},[g,c]);const B=Yu(r,D?.width??0,D?.height??0,f,l??0),E=B??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:Ki*2,height:Ki});return e.jsx("div",{ref:p,className:"block max-w-full",style:B?{width:B.width,height:B.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${u?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:B?{width:B.width,height:B.height}:void 0,onLoad:N=>{if(D)return;const $=N.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&_({width:$.naturalWidth,height:$.naturalHeight})}}):y.status==="fallback"?e.jsx("img",{src:h,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:B?{width:B.width,height:B.height}:void 0,onLoad:N=>{if(D)return;const $=N.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&_({width:$.naturalWidth,height:$.naturalHeight})}}):e.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:E.width,height:E.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function As(r,n,s,l,u,c){const h=Kg(s,u.markdownFilePath,u.rootPath);if(!h)return c?.fallbackText??`![${n}](${s})`;const p=u.images.length;u.images.push({kind:"image",src:h,alt:n,title:l});const g=e.jsx(Xg,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return u.onImageOpen&&c?.interactive!==!1?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:b=>{b.stopPropagation(),u.onImageOpen?.(p)},children:g},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:g},r)}function gi(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function Ud(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function qi(r){const n=r.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const Ju="",Jg=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function Zg(r){return r.replace(Jg,(n,s)=>`${Ju}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Hd(r){return r.replace(new RegExp(`${Ju}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function Qg(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const Zu={ALLOWED_TAGS:["a","abbr","b","blockquote","br","code","del","details","div","em","i","kbd","li","mark","ol","p","pre","s","span","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],ALLOWED_ATTR:["href","title","class","id","colspan","rowspan"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0};let Ha=null;function Qu(){return Ha||(Ha=Is(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw Ha=null,r})),Ha}function ef({html:r}){const{t:n}=jt(),[s,l]=a.useState(null);return a.useEffect(()=>{let u=!1;return l(null),Qu().then(c=>{u||l(c.sanitize(r,Zu))}).catch(()=>{u||l("")}),()=>{u=!0}},[r]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function eb({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),Qu().then(u=>{l||s(u.sanitize(r,Zu))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function tf(r){const n=r.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(r)}}let za=null;function tb(){return za||(za=Promise.all([Is(()=>import("./katex-DnlPpQZa.js"),[]),Is(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([r])=>r.default??r).catch(r=>{throw za=null,r})),za}function Fs({tex:r,display:n=!1}){const[s,l]=a.useState(null),[u,c]=a.useState(!1);if(a.useEffect(()=>{let p=!1;return l(null),c(!1),tb().then(g=>{p||l(g.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{p||c(!0)}),()=>{p=!0}},[n,r]),u)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function nl(r){const n=new Map;for(const s of r.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function zd(r){const n=nl(r),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function rb(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=nl(s),u=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),p=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:u,fallbackText:p,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function nb({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:u}=jt(),[c,h]=a.useState(!1),p=io(r,()=>h(!0));return p?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||u("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:p,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function sb(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const h=r.slice(0,r.indexOf(">")+1),p=nl(h).get("href")?.trim()??"",g=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:b,alt:f,title:k,widthPx:y}=zd(g);if(!b)return null;const C=rl(b,s.markdownFilePath,s.rootPath,Ji,N=>N);if(!C)return null;const D=p?tl(p,s.markdownFilePath,s.rootPath):null,B=!!!(D&&D.path===C)&&p?Uu(p):null,E=As(n,f??"",b,k,s,{requestedWidthPx:y,interactive:B?!1:void 0});return B?e.jsx("a",{href:B,target:"_blank",rel:"noreferrer",children:E},n):E}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:h,alt:p,title:g,widthPx:b}=zd(r);return h?As(n,p??"",h,g,s,{fallbackText:r,requestedWidthPx:b}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:h,fallbackText:p,widthPx:g,controls:b}=rb(r);if(!h)return null;const f=qg(h,s.markdownFilePath,s.rootPath);return f?e.jsx(nb,{url:f,fallbackText:p,widthPx:g,hasControls:b},n):null}if(/^<br\s*\/?>$/i.test(r))return e.jsx("br",{},n);const l=r.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(r)?e.jsx(eb,{html:r},n):null;const u=l[1].toLowerCase(),c=it(l[2],`${n}-${u}`,!0,s);return u==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:c},n):u==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):u==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function it(r,n,s=!0,l){const u=Zg(r),c=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\s*>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let p=0,g;for(;(g=c.exec(u))!==null;){g.index>p&&h.push(Hd(u.slice(p,g.index)));const b=g[0],f=`${n}-${g.index}`,k=b.startsWith("<")?sb(b,f,l):null;if(k)h.push(k);else if(b.startsWith("\\(")&&b.endsWith("\\)"))h.push(e.jsx(Fs,{tex:b.slice(2,-2)},f));else if(b.startsWith("$")&&b.endsWith("$"))h.push(e.jsx(Fs,{tex:b.slice(1,-1)},f));else if(b.startsWith("`")){const y=b.match(/^`+/)?.[0].length??1;h.push(e.jsx("code",{className:`${s?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:Qg(b.slice(y,-y))},f))}else if(b.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:it(b.slice(2,-2),`${f}-del`,s,l)},f));else if(b.startsWith("**")||b.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:it(b.slice(2,-2),`${f}-strong`,s,l)},f));else if(b.startsWith("*")||b.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:it(b.slice(1,-1),`${f}-em`,s,l)},f));else if(b.startsWith("![")){const y=b.match(/^!\[([^\]]*)\]\((.*)\)$/),C=b.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),D=b.match(/^!\[([^\]]+)\]$/);if(y){const _=qi(y[2]);h.push(_?As(f,y[1],_.href,_.title,l):b)}else if(C){const _=C[2]||C[1],B=l.referenceDefinitions.get(Ja(_));h.push(B?As(f,C[1],B.href,B.title,l):b)}else if(D){const _=l.referenceDefinitions.get(Ja(D[1]));h.push(_?As(f,D[1],_.href,_.title,l):b)}else h.push(b)}else if(b.startsWith("[^")){const y=Gu(b.slice(2,-1)),C=l.footnoteDefinitions.get(y);h.push(C?e.jsx("sup",{id:`fnref-${C.id}`,title:C.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${C.id}`,className:"text-primary no-underline",children:C.index})},f):b)}else if(b.startsWith("<http")){const y=b.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(b.startsWith("<")&&b.endsWith(">")&&Ud(b.slice(1,-1))){const y=b.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(Ud(gi(b).linkText)){const{linkText:y,suffix:C}=gi(b);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),C&&h.push(C)}else if(b.startsWith("http")||b.startsWith("www.")){const{linkText:y,suffix:C}=gi(b),D=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:D,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),C&&h.push(C)}else{const y=b.match(/^\[([^\]]+)\]\((.*)\)$/),C=b.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),D=b.match(/^\[([^\]]+)\]$/),_=C?C[2]||C[1]:D?.[1]??null,B=_?l.referenceDefinitions.get(Ja(_)):null,E=y?qi(y[2]):null,N=E?.href??B?.href??null,$=N?Uu(N):null,T=y?.[1]??C?.[1]??D?.[1]??"";h.push($?e.jsx("a",{href:$,title:E?.title??B?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:it(T,`${f}-link`,s,l)},f):b)}p=c.lastIndex}return p<u.length&&h.push(Hd(u.slice(p))),h.length>0?h:[r]}function rf(r){return/(?: {2,}|\\)$/.test(r)}function nf(r){return r.replace(/(?: {2,}|\\)$/,"")}function ro(r){return/^(?: {4}|\t)/.test(r)}function sf(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function af(r,n,s){const l=[];return r.forEach((u,c)=>{const h=rf(u);l.push(...it(nf(u),`${n}-${c}`,!0,s)),c<r.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function Vi(r,n,s){const l=[],u=[];return r.forEach((c,h)=>{u.push(rf(c)),l.push(it(nf(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:u}}function Yi(r,n,s,l,u){const c=[];return r.forEach((h,p)=>{const g=s[p]??0,b=!!(u&&g>=u.start&&g<=u.end);c.push(e.jsx("span",{"data-md-ref-start":g,"data-md-ref-end":g,"data-selected":b?"true":void 0,children:h},`${l}-ref-${p}`)),p<r.length-1&&c.push(n[p]?e.jsx("br",{},`${l}-${p}-br`):" ")}),c}function _s(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",u=!1,c=0,h=0;for(let p=0;p<n.length;p+=1){const g=n[p];if(u){l+=g,u=!1;continue}if(g==="\\"){u=!0;continue}if(g==="`"){const b=p;for(;p+1<n.length&&n[p+1]==="`";)p+=1;const f=p-b+1;l+="`".repeat(f),c===0?c=f:c===f&&(c=0);continue}if(c===0&&g==="["?h+=1:c===0&&g==="]"&&h>0&&(h-=1),g==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=g}return u&&(l+="\\"),s.push(l.trim()),s}function of(r){return _s(r).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function no(r){return r==="center"?"text-center":r==="right"?"text-right":"text-left"}function so(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function lf(r,n){return r>96||r>44&&n>.35}function uo(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Bs(r){const n=r.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function sl(r,n,s,l,u,c=new Set){const h=[],p=[];let g=n;for(;g<r.length;){const b=r[g];if(u&&(to(b)||c.has(g))){g+=1;continue}const f=Bs(b),k=uo(b);if(!f){if(k>s&&p.length>0){([...p].reverse().find(_=>_.indent<k)?.item??p[p.length-1].item).paragraphs.push(b.trim());for(const _ of p)_.item.lineEnd=g+1;g+=1;continue}break}if(k<s||k===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:g+1,lineEnd:g+1};for(;p.length>0&&p[p.length-1].indent>=k;)p.pop();const C=p[p.length-1]?.item??null;C?C.children.push(y):h.push(y),p.push({indent:k,item:y});for(const D of p)D.item.lineEnd=g+1;g+=1}return{items:h,nextIndex:g}}function ab(r){const n=r.find(l=>Bs(l));if(!n)return[];const s=Bs(n);return s?sl(r,0,uo(n),s.ordered,!0,qu(r)).items:[]}function al(r,n,s,l=0){return r.map((u,c)=>{const h=u.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:u.lineStart+l,refEnd:u.lineEnd+l,content:e.jsxs(e.Fragment,{children:[h?e.jsx("input",{type:"checkbox",checked:h[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,it(h?.[2]??u.content,`li-${n}-${c}`,!0,s),u.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:u.paragraphs.map((p,g)=>e.jsx("p",{children:it(p,`li-${n}-${c}-p-${g}`,!0,s)},`paragraph-${g}`))})]}),groups:ob(u.children,`${n}-${c}`,s,l)}})}function ob(r,n,s,l=0){const u=[];for(const c of r){const h=u[u.length-1];h&&h.ordered===c.ordered?h.items.push(c):u.push({ordered:c.ordered,items:[c]})}return u.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:al(c.items,`${n}-g${h}`,s,l)}))}function ol(r,n){return r.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&ib(s.groups,n)]},s.key)})}function ib(r,n){return r.map((s,l)=>{const u=s.ordered?"ol":"ul";return e.jsx(u,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:ol(s.items,n)},`nested-${l}`)})}function lb(r){const n=Array.from(r.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:r.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[it(s.text,`footnote-${s.id}`,!0,r)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":r.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function cb(r,n,s,l){const u=[];let c=0;const h=p=>l?.[p]??p+1;for(;c<r.length;){const p=r[c],g=p.trim();if(!g){c+=1;continue}if(/^<details>\s*$/i.test(g)){const E=c;let N="Details";const $=[];for(c+=1;c<r.length&&!/^<\/details>\s*$/i.test(r[c].trim());){const T=r[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);T?N=T[1].trim()||N:$.push(r[c].trimStart()),c+=1}c<r.length&&(c+=1),u.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:it(N,`${n}-details-${E}-summary`,!0,s)}),$.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:af($,`${n}-details-${E}`,s)})]},`${n}-details-${E}`)});continue}const b=tf(p);if(b){const E=[p],N=c;for(c+=1;c<r.length&&!b.selfContained&&!new RegExp(`</${b.tag}>`,"i").test(r[c]);)E.push(r[c]),c+=1;c<r.length&&!b.selfContained&&(E.push(r[c]),c+=1),u.push({kind:"static",node:e.jsx(ef,{html:E.join(`
1639
- `)},`${n}-html-${N}`)});continue}const f=g.match(/^(```|~~~)\s*(.*)$/);if(f){const E=[],N=f[1],$=f[2]?.trim(),T=c;for(c+=1;c<r.length&&!r[c].trim().startsWith(N);)E.push(r[c]),c+=1;c<r.length&&(c+=1),$.toLowerCase()==="mermaid"?u.push({kind:"static",node:e.jsx(df,{code:E.join(`
1640
- `),blockKey:`${n}-code-${T}`},`${n}-code-${T}`)}):["math","latex","tex"].includes($.toLowerCase())?u.push({kind:"static",node:e.jsx(Fs,{tex:E.join(`
1641
- `),display:!0},`${n}-code-${T}`)}):u.push({kind:"code",key:`${n}-code-${T}`,code:E.join(`
1642
- `),lang:$,blockKey:`${n}-code-${T}`,codeStartLine:h(T)+1});continue}if(ro(p)){const E=[],N=c;for(;c<r.length&&(ro(r[c])||!r[c].trim());)E.push(r[c].trim()?sf(r[c]):""),c+=1;u.push({kind:"code",key:`${n}-indented-code-${N}`,code:E.join(`
1643
- `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${N}`,codeStartLine:h(N)});continue}const k=g.match(/^(#{1,6})\s+(.+)$/);if(k){const N=`h${Math.min(6,k[1].length+1)}`,$=Wu(k[2]),T=Gi($,s);u.push({kind:"static",node:e.jsx(N,{id:T,className:"scroll-mt-16 font-semibold text-foreground",children:it($,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<r.length&&p.includes("|")&&so(r[c+1])){const E=_s(p),N=of(r[c+1]),$=[],T=c;for(c+=2;c<r.length&&r[c].includes("|")&&r[c].trim();)$.push(_s(r[c])),c+=1;u.push({kind:"static",node:e.jsx("div",{className:Tu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{children:E.map((U,F)=>e.jsx("th",{className:`${Au} ${no(N[F]??null)}`,children:e.jsx("div",{className:eo,children:it(U,`${n}-th-${T}-${F}`,!0,s)})},`h-${F}`))})}),e.jsx("tbody",{children:$.map((U,F)=>e.jsx("tr",{className:"border-t border-border/10",children:E.map((m,i)=>e.jsx("td",{className:`${Pu} ${no(N[i]??null)}`,children:e.jsx("div",{className:eo,children:it(U[i]??"",`${n}-td-${T}-${F}-${i}`,!0,s)})},`c-${i}`))},`r-${F}`))})]})},`${n}-table-${T}`)});continue}const y=Bs(p);if(y){const E=y.ordered,N=uo(p),$=y.start,T=c,U=sl(r,c,N,E,!1);c=U.nextIndex,u.push({kind:"list",keyPrefix:`${n}-list-${T}`,ordered:E,start:E?$:void 0,renders:al(U.items,`${n}-list-${T}`,s,h(0)-1)});continue}const C=[p.trimStart()],D=[h(c)],_=c;for(c+=1;c<r.length&&r[c].trim()&&!Wi(r[c])&&!(c+1<r.length&&r[c].includes("|")&&so(r[c+1]));)C.push(r[c].trimStart()),D.push(h(c)),c+=1;const B=Vi(C,`${n}-p-${_}`,s);u.push({kind:"paragraph",keyPrefix:`${n}-p-${_}`,perLine:B.perLine,hardBreaks:B.hardBreaks,lineNums:D})}return u}function db(r,n){return r.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:Yi(s.perLine,s.hardBreaks,s.lineNums,s.keyPrefix,n)},s.keyPrefix);case"list":{const l=s.ordered?"ol":"ul";return e.jsx(l,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} space-y-0.5 pl-4 marker:text-muted-foreground/70`,children:ol(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(ao,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Wa=null,Wd=!1;const Ga=16,cf=192;function ub(){return Wa||(Wa=Is(()=>import("./mermaid.core-C743W_cw.js").then(r=>r.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(r=>r.default??r).catch(r=>{throw Wa=null,r})),Wa}function fb(r){Wd||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),Wd=!0)}function hb(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,u,c]=l;if(!Number.isFinite(u)||!Number.isFinite(c)||u<=0||c<=0)return r;const h=Math.max(cf,Math.ceil(u)),p=Math.ceil(h/u*c);return r.replace(/<svg\b([^>]*)>/i,(g,b)=>`<svg${b.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${p}">`)}function mb(r){const n=r?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-Ga,u=s.y-Ga,c=s.width+Ga*2,h=s.height+Ga*2,p=Math.max(cf,Math.ceil(c)),g=Math.ceil(p/c*h);n.setAttribute("viewBox",`${l} ${u} ${c} ${h}`),n.setAttribute("width",String(p)),n.setAttribute("height",String(g)),n.removeAttribute("style")}function pb(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return du(`code.${s}`)??s}function df({code:r,blockKey:n}){const{t:s}=jt(),[l,u]=a.useState(null),[c,h]=a.useState(!1),p=a.useRef(null),g=a.useContext(Hu);a.useEffect(()=>{let f=!1;return u(null),h(!1),ub().then(async k=>{fb(k);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:C}=await k.render(y,r);f||u(hb(C))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,r]),a.useLayoutEffect(()=>{l&&mb(p.current)},[l]);const b=a.useCallback(()=>{const f=p.current?.querySelector("svg")?.outerHTML??l;f&&g?.(f)},[g,l]);return c?e.jsx(ao,{code:r,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:f=>{f.stopPropagation(),b()},children:e.jsx("span",{ref:p,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function ao({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:u}){const c=pb(n),[h,p]=a.useState(null);a.useEffect(()=>{if(!c||!uu(r)){p(null);return}let b=!1;return fu().then(f=>{if(b||!f.registered(c)){b||p(null);return}try{p(hu(f,r,c))}catch{b||p(null)}}).catch(()=>{b||p(null)}),()=>{b=!0}},[s,r,c]);const g=h??(r||" ").split(`
1644
- `).map(b=>[b||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${el} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:g.map((b,f)=>{const k=l!=null?l+f:null,y=!!(u&&k!=null&&k>=u.start&&k<=u.end);return e.jsxs("span",{"data-md-ref-start":k??void 0,"data-md-ref-end":k??void 0,"data-selected":y?"true":void 0,children:[b,f<g.length-1?`
1645
- `:null]},`${s}-line-${f}`)})})})]})}function il(r,n,s,l,u){r=Gg(r);const c=zg(r),h=qu(r),p=[],g={markdownFilePath:n,rootPath:s,referenceDefinitions:c,footnoteDefinitions:Wg(r),headingSlugCounts:new Map,images:p,onImageOpen:l,footnotesLabel:u?.footnotes??"Footnotes",backToFootnoteLabel:u?.backToFootnote??(y=>`Back to footnote ${y}`)},b=[];let f=0;for(;f<r.length;){const y=r[f],C=y.trim();if(to(y)||h.has(f)){f+=1;continue}if(!C){f+=1;continue}if(/^<details>\s*$/i.test(C)){const F=f;let m="Details";const i=[];for(f+=1;f<r.length&&!/^<\/details>\s*$/i.test(r[f].trim());){const O=r[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?m=O[1].trim()||m:i.push(r[f].trimStart()),f+=1}f<r.length&&(f+=1),b.push({key:`details-${F}`,startLine:F+1,endLine:f,content:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:it(m,`details-${F}-summary`,!0,g)}),i.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:af(i,`details-${F}`,g)})]})});continue}const D=tf(y);if(D){const F=[y],m=f;for(f+=1;f<r.length&&!D.selfContained&&!new RegExp(`</${D.tag}>`,"i").test(r[f]);)F.push(r[f]),f+=1;f<r.length&&!D.selfContained&&(F.push(r[f]),f+=1),b.push({key:`html-${m}`,startLine:m+1,endLine:f,content:e.jsx(ef,{html:F.join(`
1646
- `)})});continue}const _=C.match(/^(```|~~~)\s*(.*)$/);if(_){const F=[],m=_[1],i=_[2]?.trim(),O=f;for(f+=1;f<r.length&&!r[f].trim().startsWith(m);)F.push(r[f]),f+=1;f<r.length&&(f+=1),b.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:i.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(i.toLowerCase()),content:i.toLowerCase()==="mermaid"?e.jsx(df,{code:F.join(`
1647
- `),blockKey:`code-${O}`}):["math","latex","tex"].includes(i.toLowerCase())?e.jsx(Fs,{tex:F.join(`
1648
- `),display:!0}):R=>e.jsx(ao,{code:F.join(`
1649
- `),lang:i,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:R})});continue}if(ro(y)){const F=[],m=f;for(f+=0;f<r.length&&(ro(r[f])||!r[f].trim());)F.push(r[f].trim()?sf(r[f]):""),f+=1;b.push({key:`indented-code-${m}`,startLine:m+1,endLine:f,fineGrained:!0,content:i=>e.jsx(ao,{code:F.join(`
1650
- `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${m}`,codeStartLine:m+1,lineRange:i})});continue}if(C.startsWith("$$")){const F=[],m=f,i=C.replace(/^\$\$\s*/,"");if(i.endsWith("$$")&&i.length>2)F.push(i.replace(/\s*\$\$$/,"")),f+=1;else{for(i&&F.push(i),f+=1;f<r.length&&!r[f].trim().endsWith("$$");)F.push(r[f]),f+=1;if(f<r.length){const O=r[f].trim().replace(/\s*\$\$$/,"");O&&F.push(O),f+=1}}b.push({key:`math-${m}`,startLine:m+1,endLine:f,content:e.jsx(Fs,{tex:F.join(`
1651
- `),display:!0})});continue}if(f+1<r.length&&C&&!Wi(y)&&/^(=+|-+)\s*$/.test(r[f+1].trim())){const F=r[f+1].trim().startsWith("=")?1:2,m=`h${F}`,i=Gi(C,g),O={level:F,text:Od(C),id:i};b.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(m,{id:i,className:`scroll-mt-16 font-semibold text-foreground ${F===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:it(C,`setext-heading-${f}`,!0,g)})}),f+=2;continue}const B=C.match(/^(#{1,6})\s+(.+)$/);if(B){const F=B[1].length,m=Wu(B[2]),i={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},O=`h${F}`,R=Gi(m,g),G={level:F,text:Od(m),id:R};b.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:G,content:e.jsx(O,{id:R,className:`scroll-mt-16 font-semibold text-foreground ${i[F]}`,children:it(m,`heading-${f}`,!0,g)})}),f+=1;continue}if(Ou(y)){b.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(C.startsWith(">")){const F=[],m=[],i=f;for(;f<r.length&&/^>\s?/.test(r[f].trim());)F.push(r[f].trim().replace(/^>\s?/,"")),m.push(f+1),f+=1;const O=F[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const G=O[1].toUpperCase(),fe=O[2]?.trim(),te=[...fe?[fe]:[],...F.slice(1)],xe=[...fe?[m[0]]:[],...m.slice(1)],W=Vi(te,`callout-${i}`,g);b.push({key:`callout-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:Y=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:G}),te.length>0&&e.jsx("div",{children:Yi(W.perLine,W.hardBreaks,xe,`callout-${i}`,Y)})]})});continue}const R=cb(F,`quote-${i}`,g,m);b.push({key:`quote-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:G=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:db(R,G)})});continue}if(f+1<r.length&&y.includes("|")&&so(r[f+1])){const F=_s(y),m=of(r[f+1]),i=[],O=f;for(f+=2;f<r.length&&r[f].includes("|")&&r[f].trim();)i.push(_s(r[f])),f+=1;const R=F.map((fe,te)=>it(fe,`th-${O}-${te}`,!0,g)),G=i.map((fe,te)=>F.map((xe,W)=>it(fe[W]??"",`td-${O}-${te}-${W}`,!0,g)));b.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:fe=>{const te=xe=>!!(fe&&xe>=fe.start&&xe<=fe.end);return e.jsx("div",{className:Tu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{"data-markdown-table-row-line":O+1,"data-md-ref-start":O+1,"data-md-ref-end":O+1,"data-selected":te(O+1)?"true":void 0,children:R.map((xe,W)=>e.jsx("th",{className:`${Au} ${no(m[W]??null)}`,children:e.jsx("div",{className:eo,children:xe})},`h-${W}`))})}),e.jsx("tbody",{children:G.map((xe,W)=>{const Y=O+W+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":Y,"data-md-ref-start":Y,"data-md-ref-end":Y,"data-selected":te(Y)?"true":void 0,children:F.map((L,I)=>e.jsx("td",{className:`${Pu} ${no(m[I]??null)}`,children:e.jsx("div",{className:eo,children:xe[I]})},`c-${I}`))},`r-${W}`)})})]})})}});continue}const E=Bs(y);if(E){const F=E.ordered,m=uo(y),i=E.start,O=f,R=sl(r,f,m,F,!0,h);f=R.nextIndex;const G=F?"ol":"ul",fe=al(R.items,`list-${O}`,g);b.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:te=>e.jsx(G,{start:F?i:void 0,className:`${F?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:ol(fe,te)})});continue}const N=[y.trimStart()],$=[f+1],T=f;for(f+=1;f<r.length&&r[f].trim()&&!Wi(r[f])&&!(f+1<r.length&&r[f].includes("|")&&so(r[f+1]));){if(to(r[f])||h.has(f)){f+=1;continue}N.push(r[f].trimStart()),$.push(f+1),f+=1}const U=Vi(N,`p-${T}`,g);b.push({key:`p-${T}`,startLine:T+1,endLine:f,fineGrained:!0,content:F=>e.jsx("p",{className:"text-muted-foreground",children:Yi(U.perLine,U.hardBreaks,$,`p-${T}`,F)})})}const k=lb(g);return k&&b.push({key:"footnotes",startLine:r.length,endLine:r.length,content:k}),{blocks:b,images:p}}function gb(r,n,s){return il(r,n,s).blocks}function uf(r,n){const s=[];for(const l of r){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function ff(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function bb({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const u=Xu(r);return e.jsx(Rf,{src:u,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function hf({images:r,index:n,onChange:s,onClose:l}){const{t:u}=jt(),c=r[n],h=r.length>1,p=a.useRef(null),g=a.useRef(null),b=a.useRef(null),f=a.useRef(0),[k,y]=a.useState(!1),[C,D]=a.useState(0),[_,B]=a.useState(!1),E=a.useCallback(()=>{b.current!==null&&(window.clearTimeout(b.current),b.current=null)},[]),N=a.useCallback(()=>{k||Date.now()<f.current||(E(),b.current=window.setTimeout(()=>{b.current=null,l()},450))},[E,k,l]),$=a.useCallback(m=>{if(r.length===0)return;const i=(m+r.length)%r.length;p.current?.slideTo(i),s(i)},[r.length,s]),T=a.useCallback(()=>$(n-1),[$,n]),U=a.useCallback(()=>$(n+1),[$,n]);if(a.useEffect(()=>{E(),D(0),B(!1),y(!1)},[E,n]),a.useEffect(()=>{const m=p.current;m&&(m.allowTouchMove=h&&!k)},[h,k]),a.useEffect(()=>{const m=p.current;!m||m.activeIndex===n||m.slideTo(n,0)},[n]),a.useEffect(()=>E,[E]),a.useEffect(()=>{const m=i=>{if(i.key==="Escape"){i.preventDefault(),l();return}h&&(i.key==="ArrowLeft"?(i.preventDefault(),T()):i.key==="ArrowRight"&&(i.preventDefault(),U()))};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[h,U,T,l]),su({onDrag:({movement:[m,i],pinching:O})=>{O||k||Math.abs(i)<Math.abs(m)*1.15&&C===0||(B(!0),Math.abs(i)>8&&(f.current=Date.now()+300),D(Math.max(0,i)))},onDragEnd:({movement:[m,i],velocity:[,O],pinching:R,canceled:G})=>{if(B(!1),R||G||k||Math.abs(i)<Math.abs(m)*1.15){D(0);return}if(Math.abs(i)>8&&(f.current=Date.now()+300),lf(i,O)){l();return}D(0)}},{target:g,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const F=c.title||c.alt||(c.kind==="mermaid"?u("rightSidebar.mermaidDiagram"):u("rightSidebar.image"));return typeof document>"u"?null:rn.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:F}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:T,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.previousImage"),title:u("common.previous"),children:e.jsx(Ps,{size:17})}),e.jsx("button",{type:"button",onClick:U,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.nextImage"),title:u("common.next"),children:e.jsx(Kh,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":u("rightSidebar.closeImagePreview"),title:u("common.close"),children:e.jsx(Kt,{size:18})})]})]}),e.jsx("div",{ref:g,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:N,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${C}px, 0) scale(${Math.max(.86,1-C/900)})`,opacity:Math.max(.35,1-C/360),transition:_?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(au,{onSwiper:m=>{p.current=m,m.allowTouchMove=h&&!k},onSlideChange:m=>{m.activeIndex!==n&&s(m.activeIndex)},onSliderMove:()=>{E(),f.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((m,i)=>e.jsx($i,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:m.kind==="image"?e.jsx(bb,{src:m.src,alt:m.alt||m.title||u("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:E}):e.jsx(Pb,{svg:m.svg,title:m.title||m.alt||u("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:E})})},`${m.kind}-${i}-${m.alt}`))})})})]})]}),document.body)}function mf({content:r,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:u,onLineRangeDrag:c,scrollTop:h,outlineOpen:p,outlineCloseSignal:g,onOutlineOpen:b,onOutlineClose:f,lightboxOpen:k,lightboxCloseSignal:y,onLightboxOpen:C,onLightboxClose:D,onLocalLinkOpen:_}){const{t:B}=jt(),[E,N]=a.useState(null),[$,T]=a.useState(null),[U,F]=a.useState(1),[m,i]=a.useState(null),O=a.useRef(null),R=a.useRef(null),{blocks:G,images:fe}=a.useMemo(()=>il(r.split(`
1652
- `),n,s,S=>{T(null),N(S),C?.()},{footnotes:B("rightSidebar.footnotes"),backToFootnote:S=>B("rightSidebar.backToFootnote",{index:S})}),[r,n,s,C,B]),te=a.useMemo(()=>$?[...fe,$]:fe,[fe,$]),xe=a.useCallback(S=>{T({kind:"mermaid",svg:S,alt:"Mermaid diagram",title:"Mermaid diagram"}),N(fe.length),C?.()},[fe.length,C]);a.useEffect(()=>{N(null),T(null)},[r,n]),a.useEffect(()=>{N(null),T(null)},[y]),a.useEffect(()=>{k||(N(null),T(null))},[k]),a.useEffect(()=>{F(1)},[r,n]),a.useLayoutEffect(()=>{const S=O.current;if(!S||G.length===0)return;const Q=Array.from(S.querySelectorAll("[data-markdown-preview-block-start]"));let le=1;const q=28;for(const me of Q)if(me.offsetTop-h<=q)le=Number(me.dataset.markdownPreviewBlockStart)||le;else break;F(me=>me===le?me:le)},[G,h]);const W=a.useMemo(()=>uf(G,U),[U,G]),Y=a.useMemo(()=>ff(G),[G]),L=`${n??""}
1653
- ${r}`,I=a.useRef(L),K=a.useRef(null),re=a.useRef(null),ce=a.useRef(!1);a.useEffect(()=>{I.current!==L&&(I.current=L,f?.())},[f,L]),a.useEffect(()=>{g!==void 0&&i(null)},[g]),a.useLayoutEffect(()=>{if(!p){i(null);return}const S=()=>{const Q=R.current;if(!Q)return;const le=Q.getBoundingClientRect(),q=window.innerWidth;i({top:le.bottom+6,right:Math.max(8,q-le.right)})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[p,h,W]);const ve=a.useCallback(S=>{const Q=O.current,le=Q?.closest("[data-markdown-preview-scroller]"),q=Q?.querySelector(`[data-markdown-preview-block-start="${S.startLine}"]`);if(!le||!q)return;const me=le.getBoundingClientRect(),Ae=q.getBoundingClientRect(),Ee=Q?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,st=Ae.top-me.top+le.scrollTop;le.scrollTo({top:Math.max(0,st-Ee-8),behavior:"smooth"}),F(S.startLine),f?.()},[f]),pe=a.useCallback(S=>{S.pointerType==="mouse"&&S.button!==0||Si(S.target)||(K.current={pointerId:S.pointerId,startX:S.clientX,startY:S.clientY})},[]),Me=a.useCallback((S,Q,le)=>{const q=K.current;if(K.current=null,!q||q.pointerId!==S.pointerId)return;const me=Math.abs(S.clientX-q.startX),Ae=Math.abs(S.clientY-q.startY);if(me>8||Ae>8)return;const oe=S.target;if(Si(oe)||Ai())return;const Ee=Jd(oe,Q,le);u(S,Ee.start,Ee.end)},[u]),M=a.useCallback(S=>{K.current?.pointerId===S.pointerId&&(K.current=null)},[]),Z=a.useCallback((S,Q)=>{const le=O.current;if(!le||typeof document.elementFromPoint!="function")return null;const q=document.elementFromPoint(S,Q);if(!(q instanceof HTMLElement)||!le.contains(q))return null;const me=q.closest("[data-md-ref-start]");if(me){const ke=Number(me.dataset.mdRefStart);if(Number.isFinite(ke)&&ke>0)return ke}const Ae=q.closest("[data-markdown-preview-block-start]");if(!Ae)return null;const oe=Number(Ae.dataset.markdownPreviewBlockStart),Ee=G.find(ke=>ke.startLine===oe);if(!Ee)return Number.isFinite(oe)&&oe>0?oe:null;if(Ee.endLine<=Ee.startLine)return Ee.startLine;const st=Ae.getBoundingClientRect(),Pe=st.height>0?Math.min(1,Math.max(0,(Q-st.top)/st.height)):0;return Math.round(Ee.startLine+Pe*(Ee.endLine-Ee.startLine))},[G]),he=a.useCallback(S=>{if(!c||S.pointerType==="mouse"&&S.button!==0)return;const Q=Z(S.clientX+24,S.clientY);if(Q!=null){re.current={pointerId:S.pointerId,anchorLine:Q,moved:!1};try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}}},[c,Z]),Ne=a.useCallback(S=>{const Q=re.current;if(!Q||Q.pointerId!==S.pointerId||!c)return;const le=Z(S.clientX+16,S.clientY);le!=null&&(!Q.moved&&le===Q.anchorLine||(Q.moved=!0,ce.current=!0,c(S,Math.min(Q.anchorLine,le),Math.max(Q.anchorLine,le),"move")))},[c,Z]),Ve=a.useCallback(S=>{const Q=re.current;if(re.current=null,!Q||Q.pointerId!==S.pointerId||!c||!Q.moved)return;const le=Z(S.clientX+16,S.clientY)??Q.anchorLine;c(S,Math.min(Q.anchorLine,le),Math.max(Q.anchorLine,le),"end")},[c,Z]),Ce=a.useCallback(S=>{re.current?.pointerId===S.pointerId&&(re.current=null)},[]),Ye={onPointerDown:he,onPointerMove:Ne,onPointerUp:Ve,onPointerCancel:Ce},Ie=()=>ce.current?(ce.current=!1,!0):!1;return G.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:B("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:S=>{const Q=S.target instanceof Element?S.target.closest("a[href]"):null;if(!Q||!_)return;const le=Q.getAttribute("href");if(!le)return;const q=tl(le,n,s);q&&(S.preventDefault(),_(q))},children:[W.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:W.map(S=>S.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:W[W.length-1].text}),Y.length>1&&e.jsxs("button",{ref:R,type:"button",onClick:()=>{p?f?.():b?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${p?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":p,"aria-label":B("rightSidebar.markdownOutline"),title:B("rightSidebar.markdownOutline"),children:[e.jsx(ou,{size:12}),e.jsx("span",{children:B("rightSidebar.markdownOutlineShort")})]})]})}),p&&typeof document<"u"&&rn.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:f}),e.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:m?{top:`${m.top}px`,right:`${m.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:Y.map(S=>{const Q=W[W.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>ve(S),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`desktop-${S.id}-${S.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:B("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:f,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":B("rightSidebar.closeMarkdownOutline"),title:B("common.close"),children:e.jsx(Kt,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:Y.map(S=>{const Q=W[W.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>ve(S),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`${S.id}-${S.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(Hu.Provider,{value:xe,children:G.map(S=>{const Q=!!(l&&S.startLine<=l.end&&S.endLine>=l.start),le=!!(l&&l.start<=S.startLine&&l.end>=S.endLine),q=S.kind==="table"?!1:S.fineGrained?le:Q,me=S.kind==="table"&&l?.start===S.startLine&&l.end===S.endLine;let Ae=null;if(S.kind!=="table"&&S.fineGrained&&Q&&!le&&l){const Pe=S.endLine-S.startLine+1,ke=Math.max(l.start,S.startLine),at=Math.min(l.end,S.endLine),et=(ke-S.startLine)/Pe,qt=(at-ke+1)/Pe;Ae=e.jsx("span",{"aria-hidden":"true","data-md-rail-segment":!0,className:"absolute left-1/2 w-0.5 -translate-x-1/2 rounded-full bg-primary transition sm:w-1",style:{top:`calc(0.25rem + (100% - 0.5rem) * ${et})`,height:`calc((100% - 0.5rem) * ${qt})`}})}const oe=typeof S.content=="function"?S.content(l):S.content,Ee=S.startLine===S.endLine?String(S.startLine):`${S.startLine}-${S.endLine}`,st=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:yi(q),"aria-hidden":"true",...Ye,children:[e.jsx("span",{className:wi(q)}),Ae]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:oe})]});return S.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":S.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${q?"bg-primary/10":""}`,title:`Line ${Ee}`,"aria-label":`Line ${Ee}`,children:[S.kind==="table"?e.jsx("button",{type:"button",className:yi(me,"self"),onClick:Pe=>{Pe.preventDefault(),!Ie()&&u(Pe,S.startLine,S.endLine)},title:`Reference table lines ${Ee}`,"aria-label":`Reference table lines ${Ee}`,...Ye,children:e.jsx("span",{className:wi(me,"self")})}):e.jsxs("span",{className:yi(q,"none"),"aria-hidden":"true",...Ye,children:[e.jsx("span",{className:wi(q,"none")}),Ae]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:pe,onPointerUp:Pe=>Me(Pe,S.startLine,S.endLine),onPointerCancel:M,onKeyDown:Pe=>{Pe.key!=="Enter"&&Pe.key!==" "||(Pe.preventDefault(),u(Pe,S.startLine,S.endLine))},title:`Reference line ${Ee}`,"aria-label":`Reference line ${Ee}`,children:oe})]},S.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":S.startLine,onClick:Pe=>{const ke=Pe.target;if(Si(ke)||Ai()||Ie())return;const at=Jd(ke,S.startLine,S.endLine);u(Pe,at.start,at.end)},onKeyDown:Pe=>{Pe.key!=="Enter"&&Pe.key!==" "||(Pe.preventDefault(),u(Pe,S.startLine,S.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${q?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Ee}`,"aria-label":`Reference line ${Ee}`,children:st},S.key)})})})]}),k&&E!==null&&te[E]&&e.jsx(hf,{images:te,index:E,onChange:N,onClose:()=>{N(null),T(null),D?.()}})]})}function Xn({label:r,value:n,options:s,placeholder:l,searchPlaceholder:u,emptyText:c,disabled:h,onChange:p}){const{t:g}=jt(),[b,f]=a.useState(!1),[k,y]=a.useState(""),[C,D]=a.useState(null),_=a.useRef(null),B=a.useRef(null),E=k.trim().toLowerCase(),N=a.useMemo(()=>E?s.filter(m=>`${m.label} ${m.meta??""}`.toLowerCase().includes(E)):s,[E,s]),$=s.find(m=>m.value===n),T=()=>{const m=k.trim();m&&(p(m),f(!1),y(""))},U=a.useCallback(()=>{const m=_.current?.getBoundingClientRect();if(!m)return!1;const i=12,O=Math.max(220,Math.min(m.width,window.innerWidth-i*2)),R=Math.min(Math.max(i,m.left),window.innerWidth-O-i),G=window.innerHeight-m.bottom-i,fe=m.top-i,te=G>=180||G>=fe,xe=Math.max(96,(te?G:fe)-4),W=Math.min(320,xe);return D({left:R,top:te?m.bottom+4:Math.max(i,m.top-W-4),width:O,maxHeight:W}),!0},[]),F=()=>{U(),f(!0)};return a.useEffect(()=>{if(!b)return;let m=0;const i=()=>{m||(m=window.requestAnimationFrame(()=>{m=0,U()}))},O=R=>{const G=R.target;G instanceof Node&&(_.current?.contains(G)||B.current?.contains(G)||(f(!1),y("")))};return window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),document.addEventListener("pointerdown",O,!0),()=>{m&&window.cancelAnimationFrame(m),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),document.removeEventListener("pointerdown",O,!0)}},[b,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:_,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),b){f(!1);return}F()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:$?.label??(n||l)})]}),e.jsx(Ts,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${b?"rotate-180":""}`})]}),b&&!h&&typeof document<"u"&&rn.createPortal(e.jsxs("div",{ref:B,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:m=>m.stopPropagation(),style:{left:C?.left??12,top:C?.top??12,width:C?.width??260,maxHeight:C?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(Zn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:k,onChange:m=>y(m.target.value),onKeyDown:m=>{if(m.key==="Escape"){m.preventDefault(),f(!1),y("");return}m.key==="Enter"&&(m.preventDefault(),T())},onBlur:()=>{k.trim()&&N.length===0&&T()},placeholder:u,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(C?.maxHeight??320)-46)},children:[k.trim()&&!s.some(m=>m.value===k.trim())&&e.jsxs("button",{type:"button",onMouseDown:m=>m.preventDefault(),onClick:T,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:k.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:g("common.use")})]}),N.length>0?N.map(m=>e.jsxs("button",{type:"button",onClick:()=>{p(m.value),f(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${m.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:m.label}),m.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:m.meta})]},m.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function Gd({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:u,selectedRoots:c,onToggleRepo:h,onGenerate:p,onSecondaryAction:g,disabled:b,generateDisabled:f,secondaryDisabled:k,inserted:y,buttonLabel:C,insertedLabel:D,title:_,ariaLabel:B,scopeTitle:E,scopeLabel:N,allLabel:$,generateLabel:T,secondaryLabel:U,secondaryTitle:F,secondaryLoading:m,loading:i,error:O,statusTitle:R,extraContent:G,renderRepoExtra:fe}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!r):f||p()},disabled:b,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":B,title:R??(s?`${E}: ${N}`:_),children:[i?e.jsx(St,{size:13,className:"animate-spin"}):e.jsx(Ds,{size:13}),e.jsx("span",{children:y?D:C}),s&&e.jsx(Ts,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&rn.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>n(!1),children:e.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:te=>te.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:E}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:N})]}),e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:e.jsx(Kt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[G,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:$}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),u.map(te=>{const xe=c.includes(te.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${xe?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(te.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${xe?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:te.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:te.label}),te.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:te.branch})]}),xe&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),fe&&(l||xe)&&e.jsx("div",{className:"px-2 pb-2",children:fe(te)})]},te.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${g&&U?"sm:grid-cols-2":""}`,children:[g&&U&&e.jsxs("button",{type:"button",onClick:()=>{k||(n(!1),g())},disabled:k,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:F,children:[m?e.jsx(St,{size:12,className:"animate-spin"}):e.jsx(pu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),p())},disabled:f,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:_,children:[e.jsx(Ds,{size:12}),T]})]})]})}),document.body)]})}function xb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function pf(){return ut(Zi,xb)??{}}function vb(r,n){const s=pf(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,u],[,c])=>c.updatedAt-u.updatedAt).slice(0,mg);Es(Zi,Object.fromEntries(l),gg)}function yb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function wb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!yb(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function ll(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function gf(){return ut(Qi,wb)??{}}function Kd(r,n){const s=ll(r,n);return s?gf()[s]??null:null}function bi(r,n,s){const l=ll(r,n);if(!l)return;const u=gf(),c=u[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...u,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,p],[,g])=>g.updatedAt-p.updatedAt).slice(0,pg);Es(Qi,Object.fromEntries(h),bg)}function Ka({active:r,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${r?"block":"hidden"}`,"aria-hidden":!r,children:n?typeof l=="function"?l():l:s})}function xi({slow:r}){return e.jsx($m,{slow:r})}function qa({message:r,onRetry:n}){const{t:s}=jt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:r}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function Za(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function vt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function vi(r){if(!r)return null;const n=r.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function kb(r,n,s){return Pi(r,n,s)}function yi(r,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${r?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function wi(r,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${r?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function bf(r){const n=new Map;for(const s of r)n.set(cl(s),s);return n}function xf(r,n){const s=new Map(r);for(const l of n)s.set(cl(l),l);return s}function qd(r,n){let s=0;for(const l of r){const u=mt(l,n);u&&n&&u!==n&&(s+=1)}return s}function Sb(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function jb(r,n){return Array.from(xf(bf(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function Rb(r,n){const s=r.relativeRoot==="."?vt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||vt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:Sb(r.files)}}function vf(r,n){const s=vt(n??"")||n||"";return r.map(l=>Rb(l,n)).sort((l,u)=>s&&l.label===s?-1:s&&u.label===s?1:l.label.localeCompare(u.label))}function yf(r,n,s,l,u){const c=Du(s),h=c.find(_=>_.root===l)??c[0]??null,p=n.find(_=>_.root===l)??null,g=p?.relativeRoot??h?.relativeRoot??".",b=p?.name??h?.name??(vt(l)||l),f=(h?.files??s.files).map(_=>({..._,repoRoot:l,repoRelativeRoot:g,repoName:b})),k=h?.context??s.context,y={...p??h??{id:l,root:l,relativeRoot:g,name:b,depth:0,nested:!!(u&&l!==u),available:s.available,files:[],context:null},...h??{},id:p?.id??h?.id??l,root:l,displayRoot:p?.displayRoot??h?.displayRoot,relativeRoot:g,name:b,depth:p?.depth??h?.depth??0,nested:p?.nested??h?.nested??!!(u&&l!==u),available:h?.available??s.available,deferred:h?.deferred??!1,files:f,context:k?{...k,root:l,changedFiles:f.map(_=>({path:_.path,absolutePath:_.absolutePath,status:_.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},C=p?n.map(_=>_.root===l?y:_):[...n,y];return{files:Array.from(r).filter(_=>mt(_,u)!==l).concat(f),repositories:C,repoFilters:vf(C,u)}}function mt(r,n){return r.repoRoot??n}function cl(r){return`${r.repoRoot??""}\0${r.path}`}function xt(r){return r.absolutePath||r.path}function ki(r){return cl(r)}function Cb(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function Vd(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Yd(r){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of r)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Jn(r){let n=0;const s=r??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function Cs(r,n){return typeof r!="number"||!Number.isFinite(r)||r<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r))}function Pr(r){return r instanceof DOMException&&r.name==="AbortError"}function Nb(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Xd(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function Si(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function Jd(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,u=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(u)&&u>0&&Number.isFinite(c)&&c>0?{start:Math.min(u,c),end:Math.max(u,c)}:{start:n,end:s}}function Mb({actions:r,running:n,completed:s}){const{t:l}=jt(),[u,c]=a.useState(!1),h=a.useRef(null),p=r.find(b=>n?.action===b.key),g=r.find(b=>s?.action===b.key);return r.length===0?null:(a.useEffect(()=>{if(!u)return;const b=k=>{const y=k.target;y instanceof Node&&h.current?.contains(y)||c(!1)},f=k=>{k.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",b),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",f)}},[u]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),c(f=>!f)},disabled:r.every(b=>b.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${u?"bg-surface-elevated text-foreground":g?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:p?.label??g?.label??l("rightSidebar.gitQuickActions"),children:p?e.jsx(St,{size:13,className:"animate-spin"}):g?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(Mi,{size:14})}),u&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:r.map(b=>{const f=n?.action===b.key,k=s?.action===b.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),b.onClick(),c(!1)},disabled:b.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${k?"bg-accent/10 text-accent":b.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:f?e.jsx(St,{size:13,className:"animate-spin"}):k?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label})]},b.key)})})]}))}function Eb(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function wf(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Eb(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function Qn(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const ji=new WeakMap;function oo(r){const n=ji.get(r);n!==void 0&&window.clearTimeout(n),r.classList.remove("diff-walkthrough-target"),r.offsetWidth,r.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{r.classList.remove("diff-walkthrough-target"),ji.delete(r)},1700);ji.set(r,s)}function $b(r){const n=CSS.escape(r),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let u=null;for(const p of l){if(!Qn(p))continue;const g=p.querySelector(s);if(g&&Qn(g)){u=g;break}}if(u??=Array.from(document.querySelectorAll(s)).find(Qn)??null,!u)return;const c=wf(u);if(!c){u.scrollIntoView({block:"start",behavior:"smooth"}),oo(u);return}const h=u.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),oo(u)}function kn(r){const n=CSS.escape(r.filePath),s=typeof r.sectionIndex=="number"?String(r.sectionIndex):null,l=typeof r.hunkIndex=="number"?String(r.hunkIndex):null,u=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,c=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,h=[s!==null&&u?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null&&u?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&c?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${c}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(D=>!!D),p=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let g=null;for(const D of p)if(Qn(D)){for(const _ of h){const B=D.querySelector(_);if(B&&Qn(B)){g=B;break}}if(g)break}if(g??=h.flatMap(D=>Array.from(document.querySelectorAll(D))).find(Qn)??null,!g){$b(r.filePath);return}const b=wf(g);if(!b){g.scrollIntoView({block:"center",behavior:"smooth"}),oo(g);return}const f=g.getBoundingClientRect(),k=b.getBoundingClientRect(),C=f.top-k.top+b.scrollTop-Math.max(24,(b.clientHeight-f.height)/2);b.scrollTo({top:Math.max(0,C),behavior:"instant"}),oo(g)}const kf=1,Sf=8;function Lb(r){return Math.min(Sf,Math.max(kf,r))}function jf({resetKey:r,onZoomChange:n,onDoubleTap:s,children:l}){const u=a.useRef(null),[c,h]=a.useState({scale:1,x:0,y:0}),[p,g]=a.useState(!1),b=a.useRef(null),f=a.useRef(new Set),k=a.useRef(!1),y=a.useRef(null),C=a.useRef(0),D=a.useRef(c);D.current=c,a.useEffect(()=>{h({scale:1,x:0,y:0})},[r]);const _=a.useCallback(($,T,U)=>{const F=u.current;if(!F)return{x:T,y:U};const m=F.firstElementChild instanceof HTMLElement?F.firstElementChild:null,i=m?.clientWidth||F.clientWidth,O=m?.clientHeight||F.clientHeight,R=Math.max(0,(i*$-F.clientWidth)/2),G=Math.max(0,(O*$-F.clientHeight)/2);return{x:Math.min(R,Math.max(-R,T)),y:Math.min(G,Math.max(-G,U))}},[]),B=a.useCallback(($,T,U)=>{h(F=>{const m=Lb($),i=u.current;if(!i||m===1)return{scale:m,x:0,y:0};const O=i.getBoundingClientRect(),R=(T??O.left+O.width/2)-O.left-O.width/2,G=(U??O.top+O.height/2)-O.top-O.height/2,fe=m/F.scale,te=R-(R-F.x)*fe,xe=G-(G-F.y)*fe;return{scale:m,..._(m,te,xe)}})},[_]),E=a.useCallback(($,T)=>{g(!0),D.current.scale>1?h({scale:1,x:0,y:0}):B(2.5,$,T),window.setTimeout(()=>g(!1),220)},[B]);a.useEffect(()=>{const $=u.current;if(!$)return;const T=m=>{if(m.pointerType==="mouse"&&m.button!==0)return;const i=f.current.size===0;if(f.current.add(m.pointerId),i){const O=Date.now(),R=y.current;if(R&&O-R.time<350&&Math.hypot(m.clientX-R.x,m.clientY-R.y)<24){y.current=null,C.current=O,s?.(),E(m.clientX,m.clientY);return}}if(f.current.size>1){k.current=!0,b.current=null;return}if(!(D.current.scale<=1)){m.preventDefault(),b.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,originX:D.current.x,originY:D.current.y,moved:!1};try{$.setPointerCapture?.(m.pointerId)}catch{}g(!1)}},U=m=>{const i=b.current;if(!i||i.pointerId!==m.pointerId)return;const O=m.clientX-i.startX,R=m.clientY-i.startY;if(!i.moved){if(Math.hypot(O,R)<6)return;i.moved=!0}m.stopPropagation(),m.preventDefault(),h(G=>({...G,..._(G.scale,i.originX+O,i.originY+R)}))},F=m=>{const i=b.current,O=i?.pointerId===m.pointerId&&i.moved;if(i?.pointerId===m.pointerId){i.moved&&m.stopPropagation(),b.current=null;try{$.releasePointerCapture?.(m.pointerId)}catch{}}f.current.delete(m.pointerId)&&f.current.size===0&&(!k.current&&!O&&(y.current={time:Date.now(),x:m.clientX,y:m.clientY}),k.current=!1)};return $.addEventListener("pointerdown",T,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",F,{capture:!0}),window.addEventListener("pointercancel",F,{capture:!0}),()=>{$.removeEventListener("pointerdown",T,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",F,{capture:!0}),window.removeEventListener("pointercancel",F,{capture:!0})}},[_,s,E]),su({onPinch:({offset:[$],origin:[T,U]})=>{g(!1),B($,T,U)},onWheel:({event:$,delta:[T,U],ctrlKey:F})=>{if(F){$.preventDefault(),$.stopPropagation(),g(!1),B(D.current.scale*(1-U*.01),$.clientX,$.clientY);return}D.current.scale<=1||($.preventDefault(),$.stopPropagation(),g(!1),h(m=>({...m,..._(m.scale,m.x-T,m.y-U)})))}},{target:u,eventOptions:{passive:!1},pinch:{scaleBounds:{min:kf,max:Sf},from:()=>[D.current.scale,0],rubberband:!0}});const N=c.scale>1;return a.useEffect(()=>{n?.(N)},[n,N]),e.jsx("div",{ref:u,"data-sidebar-gesture-ignore":N?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:N?"grab":"zoom-in"},onDoubleClick:$=>{$.stopPropagation(),!(Date.now()-C.current<500)&&(s?.(),E($.clientX,$.clientY))},children:l({scale:c.scale,zoomed:N,animateTransform:p,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:p?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0)`,transformOrigin:"center center",transition:p?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Rf({src:r,alt:n,vector:s,onLoad:l,onError:u,onZoomChange:c,onDoubleTap:h}){const p=io(r,u),[g,b]=a.useState(null),f=s??co(r);return a.useEffect(()=>{b(null)},[r]),e.jsx(jf,{resetKey:r,onZoomChange:c,onDoubleTap:h,children:({transformStyle:k,vectorTransformStyle:y,scale:C,animateTransform:D})=>{const _=e.jsx("img",{src:p,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&g?{position:"absolute",left:"50%",top:"50%",width:g.width*C,height:g.height*C,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:D?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:g?{...k,width:g.width,height:g.height}:f?y:k,onLoad:B=>{const E=B.currentTarget,N=E.parentElement;if(N&&E.naturalWidth>0&&E.naturalHeight>0){const $=Math.max(1,N.clientWidth-2),T=Math.max(1,N.clientHeight-2),U=Math.min($/E.naturalWidth,T/E.naturalHeight),F=f?U:Math.min(U,1);b({width:Math.max(1,Math.round(E.naturalWidth*F)),height:Math.max(1,Math.round(E.naturalHeight*F))})}l(B)},onError:u});return!f||!g?_:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:g.width,height:g.height},children:_})}})}function Ab({svg:r,title:n,scale:s,vectorTransformStyle:l}){const u=a.useRef(null);return a.useLayoutEffect(()=>{const c=u.current,h=c?.querySelector("svg");if(!c||!h)return;const p=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let k=f[2],y=f[3];if((!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)&&(k=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)return;const C=Math.max(1,c.clientWidth-24),D=Math.max(1,c.clientHeight-24),_=Math.min(C/k,D/y,1);h.style.width=`${Math.max(1,Math.floor(k*_*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*_*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};p();const g=typeof ResizeObserver>"u"?null:new ResizeObserver(p);return g?.observe(c),()=>g?.disconnect()},[s,r,l]),e.jsx("div",{ref:u,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:r}})}function Pb({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(jf,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:u,scale:c})=>e.jsx(Ab,{svg:r,title:n,scale:c,vectorTransformStyle:u})})}let Tb=0,Ib=0,Db=0,Fb=0,_b=0;function Ri(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${r}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function nt(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="error"||r==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${r}`,data:{seq:++Ib,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Va(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++Fb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Bb(){return`diff-ui-${Date.now().toString(36)}-${(++_b).toString(36)}`}function Ob(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function Ub(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Xi({onReviewReference:r,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:u,onReferenceCopied:c,onClose:h,onDirectoryLinkOpen:p,isMobile:g,markdownOutlineOpen:b,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:k,onCloseMarkdownOutline:y,markdownImageLightboxOpen:C,markdownImageLightboxCloseSignal:D,onOpenMarkdownImageLightbox:_,onCloseMarkdownImageLightbox:B,lineRange:E,onLineRangeChange:N,insertedReferenceKey:$,copiedReferenceKey:T,scrollToLine:U,onScrollToLineHandled:F}){const{t:m}=jt(),i=J(P=>P.rootPath),O=J(P=>P.selectFile),[R,G]=a.useState({kind:"idle"}),[fe,te]=a.useState("schematic"),[xe,W]=a.useState(null),Y=a.useRef(null),[L,I]=a.useState(null),K=a.useRef(new Map),re=a.useRef(null),[ce,ve]=a.useState(null),[pe,Me]=a.useState(()=>Td()),[M,Z]=a.useState(()=>wd(i,n)),he=a.useRef(null),[Ne,Ve]=a.useState(!1),[Ce,Ye]=a.useState(null),[Ie,S]=a.useState(0),[Q,le]=a.useState([]),[q,me]=a.useState(null),Ae=a.useRef(null),oe=a.useRef(n),[Ee,st]=a.useState(null),[Pe,ke]=a.useState({status:"idle"}),[at,et]=a.useState(!1),[qt,lt]=a.useState(""),[ct,Ir]=a.useState([]),[Ft,H]=a.useState(0),se=a.useRef(null),be=mu(c),We=ll(i,n);a.useEffect(()=>{if(oe.current===n)return;oe.current=n;const P=n&&i&&!n.startsWith("/")?`${i}/${n}`:n;if(Ae.current===P){Ae.current=null;return}Ae.current=null,le([]),me(null),et(!1),lt("")},[n,i]);const ft=n?i&&!n.startsWith("/")?`${i}/${n}`:n:null,dr=J(P=>ft?(P.fileChangeVersions.get(ft)??0)+P.fileWatchEpoch:P.fileWatchEpoch),ur=a.useRef(null),_t=a.useRef(null),[fr,hr]=a.useState(0),Sn=a.useCallback(()=>hr(P=>P+1),[]);a.useEffect(()=>{const P=Y.current;return Y.current=null,W(null),P&&URL.revokeObjectURL(P.objectUrl),()=>{const z=Y.current;Y.current=null,z&&URL.revokeObjectURL(z.objectUrl)}},[ft,dr,fr]),a.useEffect(()=>{if(!n){ur.current=null,G({kind:"idle"});return}const P=i&&!n.startsWith("/")?`${i}/${n}`:n,z=new AbortController,ae=++Tb,Se=`right-sidebar-file-preview:${ae}`,He=performance.now();let Fe=!1;const Oe=(X,ze={})=>{Fe||(Fe=!0,Ri("end",{loadingId:ae,reason:X,durationMs:Math.round(performance.now()-He),filePath:n,fullPath:P,rootPath:i,...ze}))};let Ge=null;const tt=Th(P),Ct=tt?P.toLowerCase().endsWith(".kicad_pcb")?fe==="schematic"?"pcb-front":fe:"schematic":fe,rr=!tt&&Ji(P),Xt=!tt&&!rr&&Ih(P),Mn=!tt&&!rr&&!Xt&&Qd(P),os=Rs(P),on=Ss(P),Hr=tt?"eda":rr?"image":Xt?"model3d":Mn?"video":"text",Sr=ur.current!==P;if(ur.current=P,Sr){Ri("start",{loadingId:ae,filePath:n,fullPath:P,rootPath:i,mode:Hr,externalVersion:dr}),ke({status:"idle"}),G({kind:"loading",mode:Hr}),_t.current=null;const X=Kd(i,n);N(X?.lineRange??null),Me(os?Td():"source"),Z(on?wd(i,n):"source"),tt&&te(Dh(P))}Sr||G(X=>X.kind==="error"?{kind:"loading",mode:Hr}:X);const ho=window.setTimeout(()=>{Fe||z.signal.aborted||Ri("still_active",{loadingId:ae,filePath:n,fullPath:P,rootPath:i,mode:Hr,durationMs:Math.round(performance.now()-He),isPathChange:Sr})},3e3),ln=window.setTimeout(()=>{if(Fe||z.signal.aborted)return;const X=tt?m("rightSidebar.edaTimeout"):Xt?m("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";z.abort(new DOMException(X,"TimeoutError")),G({kind:"error",message:X}),Oe("stuck_timeout",{error:X})},tt?Fh+5e3:Xt?_h+5e3:Bh(P)?35e3:jg);if(tt){const X=Ct==="pcb-3d"?Y.current:null;X?(G(X),Oe("eda_3d_client_cache_hit",{bytes:X.meta.size,view:X.view,mimeType:X.meta.mimeType})):Oh(P,Ct,z.signal,"view_file",Se).then(ze=>{if(z.signal.aborted)return;Ge=URL.createObjectURL(ze.blob);const Pt={kind:"eda",sourcePath:ze.path||P,objectUrl:Ge,view:ze.view,meta:{size:ze.size,mimeType:ze.mimeType,modified:ze.modified}};if(ze.view==="pcb-3d"){const zr=Y.current;zr&&zr.objectUrl!==Ge&&URL.revokeObjectURL(zr.objectUrl),Y.current=Pt,W(Pt),Ge=null}G(Pt),Oe("eda_loaded",{bytes:ze.size,view:ze.view,mimeType:ze.mimeType})}).catch(ze=>{z.signal.aborted||(G({kind:"error",message:ze instanceof Error&&/timed out/i.test(ze.message)?m("rightSidebar.edaTimeout"):ze instanceof Error?ze.message:m("rightSidebar.edaLoadFailed")}),Oe("error",{error:ze instanceof Error?ze.message:String(ze)}))})}else if(rr)Uh(P,z.signal,"view_file",Se).then(X=>{Ge=URL.createObjectURL(X.blob),G({kind:"image",objectUrl:Ge,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Oe("image_loaded",{bytes:X.size,mimeType:X.mimeType})}).catch(X=>{z.signal.aborted||(G({kind:"error",message:X instanceof Error?X.message:m("rightSidebar.imageLoadFailed")}),Oe("error",{error:X instanceof Error?X.message:String(X)}))});else if(Xt)Hh(P,z.signal,"view_file",Se).then(X=>{z.signal.aborted||(Ge=URL.createObjectURL(X.blob),G({kind:"model3d",sourcePath:X.path||P,objectUrl:Ge,ext:X.ext,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Oe("model3d_loaded",{bytes:X.size,ext:X.ext}))}).catch(X=>{z.signal.aborted||(G({kind:"error",message:X instanceof Error&&(X.name==="TimeoutError"||/timed out/i.test(X.message))?m("rightSidebar.model3dTimeout"):X instanceof Error?X.message:m("rightSidebar.model3dLoadFailed")}),Oe("error",{error:X instanceof Error?X.message:String(X)}))});else if(Mn){const X=zh(P)??"",ze=eu(P);G(Pt=>Pt.kind==="video"&&Pt.url===ze?Pt:{kind:"video",url:ze,meta:{size:null,mimeType:X,modified:null}}),Oe("video_ready",{mimeType:X})}else Zc(P,z.signal,"view_file",Se).then(X=>{if(!z.signal.aborted){if(X.binary){G({kind:"binary"});return}G({kind:"text",content:X.content,sourcePath:X.path||P,meta:{size:X.size,truncated:X.truncated}}),Oe("text_loaded",{bytes:X.size,truncated:!!X.truncated})}}).catch(X=>{z.signal.aborted||(G({kind:"error",message:X instanceof Error?X.message:"Failed to read file"}),Oe("error",{error:X instanceof Error?X.message:String(X)}))});return()=>{z.abort(),kt(Se),window.clearTimeout(ho),window.clearTimeout(ln),Ge&&URL.revokeObjectURL(Ge),Oe("cleanup")}},[n,i,dr,fr,N,m,fe]),a.useEffect(()=>{if(R.kind!=="model3d"||!n){I(null);return}let P=!1;const z=n.lastIndexOf("/"),ae=z>=0?n.slice(z+1):n,Se=z>=0?n.slice(0,z):"",He=Se.lastIndexOf("/"),Fe=He>=0?Se.slice(0,He):"",Oe=ae.replace(/\.(stl|glb|gltf)$/i,""),Ge=`${Fe?`${Fe}/`:""}features/${Oe}.json`;return Zc(Ge).then(tt=>{if(!P)try{const Ct=JSON.parse(tt.content);I(Ct.version===1&&Array.isArray(Ct.features)&&Ct.features.length>0?Ct.features:null)}catch{I(null)}}).catch(()=>{P||I(null)}),()=>{P=!0}},[R,n]),a.useEffect(()=>{if(R.kind!=="text"){st(null);return}const P=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=du(P),ae=R.content,Se=Rs(P??"")&&pe==="preview",He=Ss(P??"")&&M==="preview";if(!z||Se||He||!uu(ae)){st(null);return}let Fe=!1;const Oe=Ge=>{if(Fe||!Ge.registered(z)){Fe||st(null);return}try{st(hu(Ge,ae,z))}catch{st(null)}};return Ce?Oe(Ce):(st(null),fu().then(Ge=>{Fe||(Ye(Ge),Oe(Ge))}).catch(()=>{})),()=>{Fe=!0}},[R,Ce,n,i,pe,M]),a.useLayoutEffect(()=>{if(!We||R.kind!=="text")return;const P=`${We}:${pe}:${M}`;if(_t.current===P)return;const z=Kd(i,n);if(_t.current=P,!z)return;const ae=requestAnimationFrame(()=>{const Se=re.current;if(!Se)return;const He=pe==="preview"?z.markdownTop??z.top:z.top;Se.scrollTo({top:Math.max(0,He??0),left:Math.max(0,z.left??0)}),S(pe==="preview"?Math.max(0,He??0):0)});return()=>cancelAnimationFrame(ae)},[n,pe,M,R.kind,We,i]),a.useEffect(()=>{We&&bi(i,n,{lineRange:E})},[n,E,We,i]),a.useEffect(()=>{if(U==null||R.kind!=="text")return;ve(null),N({start:U,end:U});const P=U,z=requestAnimationFrame(()=>{const ae=K.current.get(P);ae&&ae.scrollIntoView({block:"center"}),F?.()});return()=>cancelAnimationFrame(z)},[U,R,N,F]);const jn=a.useCallback(P=>{const z=re.current;if(!z)return!1;const ae=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(P):P.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Se=z.querySelector(`#${ae}`);return Se?(Se.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const P=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=R.kind==="text"&&Rs(P??"")&&pe==="preview";if(!q||!z)return;const ae=requestAnimationFrame(()=>{jn(q)&&me(null)});return()=>cancelAnimationFrame(ae)},[n,jn,pe,q,R,i]),a.useLayoutEffect(()=>{const P=re.current;if(!P||!E){ve(null);return}if(ce)return;const z=R.kind==="image"||R.kind==="loading"&&R.mode==="image",ae=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,Se=R.kind==="text"&&Rs(ae??"")&&pe==="preview",He=R.kind==="text"&&Ss(ae??"")&&M==="preview";if(R.kind!=="text"||z||Se||He){ve(null);return}const Fe=()=>{const Ge=K.current.get(E.end);if(!Ge||!P){ve(null);return}const tt=Ge.offsetTop+Ge.offsetHeight/2,Ct=P.scrollLeft+Math.max(8,P.clientWidth-120);ve({top:tt,left:Ct})};Fe();const Oe=new ResizeObserver(()=>Fe());return Oe.observe(P),()=>Oe.disconnect()},[E,ce,R,pe,M,n,i,Ee]);const Dr=R.kind==="text"&&!(Ss(ft??"")&&M==="preview")&&!ft?.toLowerCase().endsWith(".csv")&&!ft?.toLowerCase().endsWith(".kicad_pro")&&!ft?.toLowerCase().endsWith(".kicad_prl"),mr=a.useCallback(()=>{et(!1),lt(""),Ir([]),H(0),Ua()},[]),Rn=a.useCallback(()=>{Dr&&(et(!0),requestAnimationFrame(()=>{se.current?.focus(),se.current?.select()}))},[Dr]),pt=a.useCallback(P=>{H(z=>ct.length===0?0:(z+P+ct.length)%ct.length)},[ct.length]);if(a.useEffect(()=>{const P=z=>{const ae=og(z);if(ae==="open"&&Dr){z.preventDefault(),Rn();return}at&&(ae==="close"?(z.preventDefault(),mr()):(ae==="next"||ae==="previous")&&(z.preventDefault(),pt(ae==="previous"?-1:1)))};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[mr,at,pt,Rn,Dr]),a.useLayoutEffect(()=>{if(Ua(),!at||!qt.trim()||!re.current){Ir([]),H(0);return}const P=lg(re.current,qt);return Ir(P),H(0),Rd(P,0),Cd(P[0]),Ua},[at,qt,Ee,pe,R]),a.useEffect(()=>{at&&(Rd(ct,Ft),Cd(ct[Ft]))},[Ft,ct,at]),a.useEffect(()=>Ua,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:m("rightSidebar.selectFilePrompt")});const Ue=i&&!n.startsWith("/")?`${i}/${n}`:n,Lt=Za(Ue,i),pr=ru(Ue,i),gr=R.kind==="text"&&R.content?R.content.split(`
1654
- `):[],Os=Math.max(2,String(gr.length).length)+1,br=R.kind==="text"||R.kind==="image"||R.kind==="model3d"||R.kind==="video"||R.kind==="eda"?R.meta:null,xr=Rs(Ue),Us=Ue.toLowerCase().endsWith(".csv"),At=Ue.toLowerCase().endsWith(".kicad_pro"),es=Ue.toLowerCase().endsWith(".kicad_prl"),Bt=R.kind==="text"&&xr&&pe==="preview",Hs=Ss(Ue),vr=R.kind==="text"&&Hs&&M==="preview",zs=R.kind==="image"||R.kind==="loading"&&R.mode==="image",fo=R.kind==="model3d"||R.kind==="loading"&&R.mode==="model3d",Rt=R.kind==="video"||R.kind==="loading"&&R.mode==="video",nn=R.kind==="eda"||R.kind==="loading"&&R.mode==="eda",ts=R.kind==="text"?R.sourcePath:Ue,Fr=bm(ts,i,E),_r=(()=>{if(!E||R.kind!=="text"||gr.length===0)return Fr;const P=[];for(let Se=E.start;Se<=E.end;Se+=1)P.push(`${Se} ${gr[Se-1]??""}`);const z=Bu(Ue).replace(/^\./,""),ae="```";return`${Fr}
1635
+ `,Oa="/api/terminal/fs/preview/",ag=8*1024*1024,og=32*1024*1024,ig=128,lg="data:,";function Mt(r){throw new Error(r)}function cg(r){return JSON.stringify(r).replace(/</g,"\\u003c")}async function Nd(r,n,s){let l="",u=0;for(const c of r.matchAll(n))l+=r.slice(u,c.index)+await s(c),u=c.index+c[0].length;return l+r.slice(u)}async function ju(r,n){const s=n.origin??location.origin,l=new URL(r,s);(l.origin!==s||!ks(l.pathname)?.startsWith(Oa))&&Mt("预览地址不是有效的本地文件入口");const u=crypto.randomUUID(),c=`https://termdock-preview.invalid/${u}/`,h=[],m=W=>{!h.includes(W)&&h.length<20&&h.push(W)},g=new Set,b=[],f=new Set,k=new Map,y=new Map;let N=0,I=!1;const B=new Set,_=()=>{I=!0;for(const W of[...B])W();g.clear(),b.length=0};async function R(W){W.ok||Mt(`预览资源读取失败(${W.status})`);const Y=W.body?.getReader(),L=[];let D=0;try{if(Y)for(;;){const ce=await Y.read();if(ce.done)break;D+=ce.value.byteLength,N+=ce.value.byteLength,(D>ag||N>og)&&Mt("预览资源超出大小限制"),L.push(ce.value)}}catch(ce){throw await Y?.cancel().catch(()=>{}),ce}finally{Y?.releaseLock()}const K=new Uint8Array(D);let re=0;for(const ce of L)K.set(ce,re),re+=ce.length;return{bytes:K,type:W.headers.get("content-type")??"application/octet-stream",status:W.status}}let E=l,$;for(let W=0;W<4;W++){const Y=await n.fetch(E.pathname+E.search,{signal:n.signal,redirect:"manual"});if(![301,302,303,307,308].includes(Y.status)){$=Y;break}const L=Y.headers.get("location");await Y.body?.cancel(),L||Mt("预览重定向缺少目标");const D=new URL(L,E);(D.origin!==s||!ks(D.pathname)?.startsWith(Oa))&&Mt("预览重定向越出文件范围"),E=D}$||Mt("预览重定向次数过多");const P=ks(E.pathname),U=P.slice(Oa.length).split("/");/^[a-f0-9]{32}$/.test(U[0])||Mt("服务未提供有效的预览资源授权");const F=ks(l.pathname).slice(Oa.length).split("/");/^[a-f0-9]{32}$/.test(F[0])&&F.shift(),F.join("/").replace(/\/$/,"")!==U.slice(1).join("/").replace(/\/$/,"")&&Mt("预览重定向改变了文件范围");const p=P.endsWith("/")?P:P.slice(0,P.lastIndexOf("/")+1),i=new URL(E.pathname.endsWith("/")?E.pathname:E.pathname.slice(0,E.pathname.lastIndexOf("/")+1),s);function O(W,Y){const L=new URL(W,Y);return L.origin!==s?null:(ks(L.pathname)?.startsWith(p)||Mt("已阻止预览访问目录之外的资源"),L)}function C(W){const Y=new URL(W,c);(Y.origin!==new URL(c).origin||!Y.pathname.startsWith(new URL(c).pathname))&&Mt("已阻止预览访问服务接口或目录之外的资源");const L=Y.pathname.slice(new URL(c).pathname.length)+Y.search;return O(L,i)??Mt("预览资源无效")}function G(W){const Y=W.pathname+W.search,L=k.get(Y);if(L)return L;if(I||n.signal?.aborted)return Promise.reject(new Error("预览已关闭"));if(k.size>=ig)return Promise.reject(new Error("预览资源数量超出限制"));const D=n.fetch(Y,{signal:n.signal,redirect:"manual"}).then(R);return k.set(Y,D),D}function fe(W,Y){I&&Mt("预览已关闭");const L=`termdock-resource-${u}-${b.length}`;return b.push({token:L,data:W,type:Y}),g.add(L),L}async function te(W,Y,L,D=new Set){if(!W||W.startsWith("#")||/^data:(?:image|font)\//i.test(W)&&L==="resource")return W;try{const K=O(W,Y);if(!K){const Ee=new URL(W,Y);return(Ee.protocol!=="https:"||Ee.username||Ee.password||Ee.origin===new URL(c).origin)&&Mt("已阻止不安全的外部资源"),f.add(Ee.origin),Ee.href}const re=`${L}:${K.href}`;(D.has(re)||D.size>=8)&&Mt("预览资源存在循环或过深引用");const ce=y.get(re);if(ce)return ce;const ve=new Set(D);ve.add(re);const pe=(async()=>{const Ee=await G(K);return L==="css"?fe(await xe(new TextDecoder().decode(Ee.bytes),K,ve),"text/css"):L==="script"?fe(Ee.bytes,"text/javascript"):fe(Ee.bytes,Ee.type)})();return y.set(re,pe),await pe}catch(K){return m(K instanceof Error?K.message:"部分预览资源未能加载"),lg}}async function xe(W,Y,L){return W=await Nd(W,/@import\s+(?:url\(\s*)?["']([^"']+)["']\s*\)?([^;]*);/gi,async D=>`@import url("${await te(D[1],Y,"css",L)}")${D[2]};`),Nd(W,/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))\s*\)/gi,async D=>{const K=(D[1]??D[2]??D[3]).trim();return g.has(K)?D[0]:`url("${await te(K,Y,"resource",L)}")`})}try{const W=await R($),Y=fe(ng,"text/javascript"),L=new DOMParser().parseFromString(new TextDecoder().decode(W.bytes),"text/html");L.querySelectorAll("base,meta[http-equiv],iframe,frame,object,embed").forEach(M=>M.remove());for(const M of L.querySelectorAll("*")){if(M.removeAttribute("ping"),M.removeAttribute("srcdoc"),M.hasAttribute("style")&&M.setAttribute("style",await xe(M.getAttribute("style"),E,new Set)),M.tagName==="STYLE"&&(M.textContent=await xe(M.textContent??"",E,new Set)),M.tagName==="A"||M.tagName==="AREA"){const Z=M.getAttribute("href");try{if(Z&&!Z.startsWith("#")){const he=O(Z,E);if(he)M.setAttribute("href",new URL(he.pathname.slice(i.pathname.length)+he.search+he.hash,c).href);else{const Ne=new URL(Z,E);if(Ne.protocol!=="https:"){M.removeAttribute("href");continue}f.add(Ne.origin),M.setAttribute("href",Ne.href)}}}catch(he){M.removeAttribute("href"),m(he instanceof Error?he.message:"预览链接无法加载")}}for(const Z of["data","manifest"])M.removeAttribute(Z);if(M.tagName==="SCRIPT"&&M.getAttribute("type")==="module"){M.setAttribute("type","module-shim");const Z=M.getAttribute("src");if(Z){const he=O(Z,E);if(he)M.setAttribute("src",new URL(he.pathname.slice(i.pathname.length)+he.search,c).href);else{const Ne=new URL(Z,E);if(Ne.protocol!=="https:"){M.remove();continue}f.add(Ne.origin),M.setAttribute("src",Ne.href)}}continue}if(M.tagName==="SCRIPT"&&M.getAttribute("type")==="importmap"){M.setAttribute("type","importmap-shim");continue}if(M.tagName==="LINK"){const Z=(M.getAttribute("rel")??"").toLowerCase();if(!["stylesheet","icon"].includes(Z)){M.remove();continue}const he=M.getAttribute("href");he&&M.setAttribute("href",await te(he,E,Z==="stylesheet"?"css":"resource"))}if(M.hasAttribute("src")&&M.setAttribute("src",await te(M.getAttribute("src"),E,M.tagName==="SCRIPT"?"script":"resource")),M.hasAttribute("poster")&&M.setAttribute("poster",await te(M.getAttribute("poster"),E,"resource")),M.hasAttribute("srcset")){const Z=M.getAttribute("srcset");/data:/i.test(Z)?(M.removeAttribute("srcset"),m("混合内嵌图片候选暂不支持安全预览")):M.setAttribute("srcset",(await Promise.all(Z.split(",").map(async he=>{const[Ne,...Ve]=he.trim().split(/\s+/);return`${await te(Ne,E,"resource")} ${Ve.join(" ")}`}))).join(", "))}M.setAttribute("referrerpolicy","no-referrer"),M.removeAttribute("integrity"),M.removeAttribute("crossorigin")}const D=[...f].join(" "),K=L.createElement("meta");K.httpEquiv="Content-Security-Policy",K.content=`default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' blob: ${D}; style-src 'unsafe-inline' blob: ${D}; img-src blob: data: ${D}; font-src blob: data: ${D}; media-src blob: data: ${D}; connect-src blob: ${D} ${[...f].map(M=>M.replace(/^https:/,"wss:")).join(" ")}; worker-src blob:; frame-src 'none'; object-src 'none'; base-uri https://termdock-preview.invalid; form-action 'none'`;const re=L.createElement("base");re.href=c;const ce=L.createElement("meta");ce.name="referrer",ce.content="no-referrer";const ve=L.createElement("script");ve.textContent=sg+`
1636
+ installPreviewRuntime(`+[u,c,[...f],Y].map(cg).join(",")+");";const pe=L.createElement("script");pe.src=Y,L.head.prepend(K,ce,re,ve,pe);const Ee=`<!doctype html>
1637
+ `+L.documentElement.outerHTML;return{html:Ee,shellUrl:`/preview-shell.html#${u}`,errors:h,attach(M,Z){const he=new Set,Ne=Ce=>{if(Ce.source!==M.contentWindow||Ce.data?.capability!==u)return;if(Ce.data.type==="preview-ready"){M.contentWindow?.postMessage({type:"preview-init",capability:u,html:Ee,resources:b},"*");return}if(Ce.data.type==="preview-error"){Z("部分动态内容被安全预览限制");return}if(Ce.data.type==="preview-navigate"){(async()=>{const Ie=C(String(Ce.data.url)),S=await ju(Ie.pathname+Ie.search,n);if(I){S.dispose();return}const Q=S.attach(M,Z);B.add(()=>{Q(),S.dispose()}),M.src=S.shellUrl.replace("#","?navigation="+crypto.randomUUID()+"#")})().catch(Ie=>Z(Ie instanceof Error?Ie.message:"无法打开预览页面"));return}if(Ce.data.type==="preview-external"){try{const Ie=new URL(String(Ce.data.url));Ie.protocol==="https:"&&f.has(Ie.origin)&&window.open(Ie.href,"_blank","noopener,noreferrer")}catch{}return}if(Ce.data.type!=="preview-fetch"||Ce.ports.length!==1)return;const Ye=Ce.ports[0];if(he.size>=8||!["GET","HEAD"].includes(Ce.data.method)){Ye.postMessage({error:"预览仅允许读取已授权目录资源"}),Ye.close();return}he.add(Ye),(async()=>{const Ie=C(String(Ce.data.url)),S=await G(Ie);if(!he.has(Ye)||I)return;const Q=Ce.data.method==="HEAD"?new Uint8Array:S.bytes.slice();Ye.postMessage({status:S.status,headers:{"content-type":S.type},data:Q.buffer},[Q.buffer])})().catch(()=>{Ye.postMessage({error:"预览资源不在授权范围或无法加载"}),Z("部分动态资源不可用或超出预览目录")}).finally(()=>{he.delete(Ye),Ye.close()})};window.addEventListener("message",Ne);const Ve=()=>{window.removeEventListener("message",Ne);for(const Ce of he)Ce.close();he.clear(),B.delete(Ve)};return B.add(Ve),Ve},dispose:_}}catch(W){throw _(),W}}const dg=a.forwardRef(function({src:n,title:s,exitFullscreenLabel:l,onFullscreenChange:u},c){const h=a.useRef(null),[m,g]=a.useState(null),[b,f]=a.useState(),[k,y]=a.useState("");a.useEffect(()=>{const P=new AbortController;let U;return f(void 0),y(""),(async()=>{const F=await Dh();if(U=await ju(n,{fetch:(p,i)=>F.fetch(p,i),signal:P.signal}),P.signal.aborted){U.dispose();return}f(U),U.errors.length&&y(U.errors.join(";"))})().catch(F=>{P.signal.aborted||y(F instanceof Error?F.message:"安全预览加载失败")}),()=>{P.abort(),U?.dispose()}},[n]),a.useEffect(()=>{if(!(!b||!m))return b.attach(m,y)},[b,m]);const[N,I]=a.useState(!1),[B,_]=a.useState(!1),R=N||B;a.useEffect(()=>{u?.(R)},[R,u]),a.useEffect(()=>{const P=()=>{I(document.fullscreenElement===h.current)};return document.addEventListener("fullscreenchange",P),()=>document.removeEventListener("fullscreenchange",P)},[]),a.useEffect(()=>{if(!B)return;const P=U=>{U.key==="Escape"&&_(!1)};return document.addEventListener("keydown",P),()=>document.removeEventListener("keydown",P)},[B]);const E=a.useCallback(async()=>{const P=h.current;if(P){if(B){_(!1);return}if(document.fullscreenElement===P){await document.exitFullscreen();return}if(P.requestFullscreen&&document.fullscreenEnabled!==!1)try{await P.requestFullscreen();return}catch{}_(!0)}},[B]);a.useImperativeHandle(c,()=>({toggleFullscreen:E}),[E]);const $=e.jsxs("div",{ref:h,"data-html-preview-frame":!0,className:R?"fixed inset-0 z-modal-panel flex min-h-0 flex-col overflow-hidden bg-surface pt-[env(safe-area-inset-top,0px)] text-foreground":"flex h-full min-h-0 flex-col overflow-hidden bg-surface",children:[R&&e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/15 bg-[var(--chrome-bg)] px-3",children:[e.jsx("span",{className:"min-w-0 truncate text-[12px] font-semibold",children:s}),e.jsx("button",{type:"button",onClick:()=>{E()},"aria-label":l,title:`${l} (Esc)`,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",children:e.jsx(fu,{size:15})})]}),k&&e.jsx("div",{role:"status",className:"shrink-0 border-b border-border px-3 py-2 text-xs text-muted-foreground",children:k}),!b&&!k&&e.jsx("div",{role:"status",className:"p-3 text-xs text-muted-foreground",children:"正在安全加载预览资源…"}),e.jsx("iframe",{ref:g,src:b?.shellUrl,referrerPolicy:"no-referrer",title:s,sandbox:"allow-scripts",className:"block min-h-0 w-full flex-1 border-0 bg-white"})]});return B?Ir.createPortal($,document.body):$}),Ru="termdock-file-search-match",Oi="termdock-file-search-current";function ug(r){const n=r.metaKey||r.ctrlKey,s=r.key.toLocaleLowerCase();return n&&s==="f"?"open":n&&s==="g"||r.key==="F3"?r.shiftKey?"previous":"next":r.key==="Escape"?"close":null}function fg(r){return r.parentElement?.closest("[data-markdown-preview-block-start], [data-file-preview-line]")??null}function hg(r,n){const s=n.trim().toLocaleLowerCase();if(!s)return[];const l=[];let u="",c=null;const h=document.createTreeWalker(r,NodeFilter.SHOW_TEXT);for(let f=h.nextNode();f;f=h.nextNode()){if(!(f instanceof Text)||!f.data)continue;const k=fg(f);if(!k)continue;c&&c!==k&&(u+=`
1638
+ `);const y=u.length;u+=f.data,l.push({node:f,start:y,end:u.length,group:k}),c=k}const m=u.toLocaleLowerCase(),g=[];let b=0;for(;b<=m.length-s.length;){const f=m.indexOf(s,b);if(f<0)break;const k=f+s.length,y=l.find(I=>I.start<=f&&I.end>f),N=l.find(I=>I.start<k&&I.end>=k);if(y&&N&&y.group===N.group){const I=document.createRange();I.setStart(y.node,f-y.start),I.setEnd(N.node,k-N.start),g.push(I)}b=f+Math.max(s.length,1)}return g}function Cu(){return typeof CSS<"u"&&CSS.highlights?CSS.highlights:null}function Ua(){const r=Cu();r?.delete(Ru),r?.delete(Oi)}function Ed(r,n){const s=Cu();if(!s||typeof Highlight>"u")return;s.set(Ru,new Highlight(...r));const l=r[n];l?s.set(Oi,new Highlight(l)):s.delete(Oi)}function Md(r){r?.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest",behavior:"smooth"})}function mg(r){return Array.from(new Set(r.split(/[\n,]/).map(n=>n.trim().replace(/^!+/,"")).filter(Boolean))).slice(0,24)}function pg(r,n){const s=n.trim();return!s||s==="."?r:/^(?:[/\\]|[A-Za-z]:[/\\])/.test(s)?s.replace(/[\\/]+$/,""):`${r.replace(/[\\/]+$/,"")}/${s.replace(/^\.?[\\/]+/,"").replace(/[\\/]+$/,"")}`}function gg(r,n){if(n===r)return".";const s=`${r.replace(/[\\/]+$/,"")}/`;return n.startsWith(s)?n.slice(s.length):n}function Nu(r,n,s){return n?r:Ir.createPortal(r,s)}const Qi="termdock:right-sidebar:file-tree-scroll:v1",el="termdock:right-sidebar:file-preview-reading-state:v1",Es="termdock:right-sidebar:file-tree-width:v1",Eu="termdock:right-sidebar:markdown-view-mode:v1",Mu="termdock:right-sidebar:diff-change-list-mode:v1",$u="termdock:right-sidebar:diff-wrap:v1",Lu="termdock:diff-viewer:view-type:v1",Au="termdock:right-sidebar:file-search-mode:v1",ui="termdock:right-sidebar:collapsed-git-repo-groups:v1",$d="termdock:right-sidebar:collapsed-diff-directories:v1",fi="termdock:right-sidebar:branch-audit-module-open:v1",Pu="termdock:right-sidebar:branch-audit-module:v1",bg=150,Ld="termdock:right-sidebar:context-draft-enabled:v1",Ad="termdock:right-sidebar:context-draft-collapsed:v1",Pd="termdock:right-sidebar:context-draft-auto-collapse:v1",hi="termdock:right-sidebar:context-draft-text:v1",xg=300,vg=20,yg=120,wg=250,kg=250,Sg=120,jg=700,mi=600,Rg=6e4;function Yn(r){return!!(r&&J.getState().nestedGitScanRoots[r])}const Td=[2e3,5e3,15e3,3e4],Cg=320,Ng=500,Eg=20,Mg=12e3,Ui=300,Id=240,$g=560,Tu="border-r px-2 py-1.5 sm:px-3 sm:py-2",eo="max-w-[18rem] whitespace-normal break-words sm:max-w-[27rem]",Iu=`${Tu} border-b border-border/15 font-semibold last:border-r-0`,Du=`${Tu} border-border/10 align-top text-muted-foreground last:border-r-0`,tl="termdock-file-preview-horizontal-scroll",Dd=a.lazy(()=>Ds(()=>import("./ModelPreview-BPPustvB.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]))),Fu=`${tl} termdock-md-table-scroll max-w-full overflow-x-auto overflow-y-hidden rounded-lg border border-border/20 bg-surface`;function _u(r,n,s){return r&&!n?"unified":s}const Lg=new Set([".md",".markdown",".mdown",".mkdn",".mkd"]);function Ag(r){return r==="preview"||r==="source"}function Pg(r){return r==="list"||r==="tree"||r==="ai"}function Fd(){return ut(Eu,Ag)??"preview"}function Tg(){return ut(Mu,Pg)??"tree"}function Ms(r){return typeof r=="boolean"}function Ig(r){return typeof r=="string"}function Dg(){return ut($u,Ms)??!0}function Fg(r){return r==="unified"||r==="split"}function _g(){return ut(Lu,Fg)??"unified"}function Bg(r){return r==="name"||r==="content"||r==="regex"}function Og(){return ut(Au,Bg)??"name"}function Bu(r){return r.repositories??(r.context?.root?[{id:r.context.root,root:r.context.root,relativeRoot:".",name:vt(r.context.root)||r.context.root,depth:0,nested:!1,available:r.available,files:r.files,context:r.context,error:r.error}]:[])}function Ug(r,n){if(!n)return null;const s=new Set((r.repoFilters??[]).map(l=>l.root));return s.has(n)?n:s.size>0?null:(r.repositories??[]).some(l=>l.root===n)?n:null}function Hi(r){return!r.activeGitRepoRoot&&(r.groupCount>1||r.label!==r.rootName)}function Ou(...r){const n=new Set;for(const s of r)for(const l of s)n.add(l.root);return n}function zi(r){return Array.isArray(r)&&r.every(n=>typeof n=="string")}function _d(r){const n=ut(r,zi);return n?new Set(n):new Set}function pi(r,n){$t(r,[...n])}function Hg(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.filePath=="string"&&typeof n.hunkHeader=="string"&&typeof n.hunkIndex=="number"&&typeof n.fingerprint=="string"&&typeof n.additions=="number"&&typeof n.deletions=="number"&&typeof n.diff=="string"&&(n.oldPath===void 0||n.oldPath===null||typeof n.oldPath=="string")&&(n.newPath===void 0||n.newPath===null||typeof n.newPath=="string")&&(n.source===void 0||n.source==="committed"||n.source==="uncommitted"||n.source==="unknown")&&(n.commit===void 0||n.commit===null||typeof n.commit=="string")}function zg(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.available=="boolean"&&(n.repoRoot===void 0||typeof n.repoRoot=="string")&&(n.workspaceRoot===void 0||typeof n.workspaceRoot=="string")&&(n.baseRef===void 0||typeof n.baseRef=="string")&&(n.baseBranch===void 0||typeof n.baseBranch=="string")&&(n.currentBranch===void 0||n.currentBranch===null||typeof n.currentBranch=="string")&&(n.headRef===void 0||n.headRef===null||typeof n.headRef=="string")&&(n.diffFingerprint===void 0||typeof n.diffFingerprint=="string")&&(n.stat===void 0||typeof n.stat=="string")&&(n.files===void 0||zi(n.files))&&(n.hunks===void 0||Array.isArray(n.hunks)&&n.hunks.every(Hg))&&(n.commits===void 0||zi(n.commits))&&(n.commitCount===void 0||typeof n.commitCount=="number")&&(n.diff===void 0||typeof n.diff=="string")&&(n.truncated===void 0||typeof n.truncated=="boolean")&&(n.error===void 0||typeof n.error=="string")}function Wg(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.key=="string"&&zg(n.diff)&&typeof n.repoLabel=="string"&&typeof n.createdAt=="number"}function Gg(r){return!r||typeof r!="object"||Array.isArray(r)?!1:Object.values(r).every(n=>{if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;return Array.isArray(s.selectedRepoRoots)&&s.selectedRepoRoots.every(l=>typeof l=="string")&&!!s.repoTargetBranches&&typeof s.repoTargetBranches=="object"&&!Array.isArray(s.repoTargetBranches)&&Object.values(s.repoTargetBranches).every(l=>typeof l=="string")&&(s.repoBaseBranches===void 0||!!s.repoBaseBranches&&typeof s.repoBaseBranches=="object"&&!Array.isArray(s.repoBaseBranches)&&Object.values(s.repoBaseBranches).every(l=>typeof l=="string"))&&(s.previewEntries===void 0||Array.isArray(s.previewEntries)&&s.previewEntries.every(Wg))&&(s.selectedPreviewKey===void 0||s.selectedPreviewKey===null||typeof s.selectedPreviewKey=="string")&&(s.selectedPreviewFileKey===void 0||s.selectedPreviewFileKey===null||typeof s.selectedPreviewFileKey=="string")&&(s.previewDetailOpen===void 0||typeof s.previewDetailOpen=="boolean")&&(s.previewScrollTops===void 0||!!s.previewScrollTops&&typeof s.previewScrollTops=="object"&&!Array.isArray(s.previewScrollTops)&&Object.values(s.previewScrollTops).every(l=>typeof l=="number"))&&(s.previewMobileSlideIndex===void 0||typeof s.previewMobileSlideIndex=="number")&&(s.includeUncommitted===void 0||typeof s.includeUncommitted=="boolean")&&typeof s.updatedAt=="number"})}function Bd(){return ut(Pu,Gg)??{}}function Od(r){return[r.repoRoot,r.baseRef,r.branchName??"",r.headRef??"",r.diffFingerprint??""].join("\0")}function Ud(r){const n=r?.trim()??"",s=n.indexOf("/");return s>=0?n.slice(s+1):n}function Uu(r,n){const s=r?.trim(),l=n?.trim();return!s||!l?!1:s===l||Ud(s)===Ud(l)}function Hd(r){const n=r?.branch??null;return[r?.upstream,...r?.remoteBranches??[],...r?.branches??[]].find(l=>l&&!Uu(l,n))??""}function Wi(r,n){const s=Math.max(Id,n-320),l=Math.min($g,s);return Math.min(l,Math.max(Id,r))}function Kg(r){return typeof r=="number"&&Number.isFinite(r)}function qg(r){return Wi(ut(Es,Kg)??Ui,r)}function Hu(r){const n=r.split(/[\\/]/).pop()??r,s=n.lastIndexOf(".");return s>=0?n.slice(s).toLowerCase():""}function Rs(r){return Lg.has(Hu(r))}function zu(r){const n=r.trim().replace(/\s+/g,"");return/^-{3,}$/.test(n)||/^\*{3,}$/.test(n)||/^_{3,}$/.test(n)}function Gi(r){const n=r.trim();return/^#{1,6}\s+/.test(n)||zu(r)||/^>\s?/.test(n)||/^(```|~~~)/.test(n)||/^(?:[-+*]|\d+[.)])\s+/.test(n)}function Wu(r){const n=r.trim();return/^(https?:|mailto:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/[<>]/.test(n)?n:null}const Gu=a.createContext(null);function Ja(r){return r.trim().replace(/\s+/g," ").toLowerCase()}function Ku(r){return r.replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\[([^\]]+)\]\[[^\]]*\]/g,"$1").replace(/[`*_~]/g,"").replace(/<[^>]+>/g,"").trim()}function qu(r){return r.replace(/\s+#+\s*$/,"").trim()}function Ki(r,n){const l=Ku(r).toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").trim().replace(/\s+/g,"-")||"section",u=n.headingSlugCounts.get(l)??0;return n.headingSlugCounts.set(l,u+1),u===0?l:`${l}-${u}`}function zd(r){return Ku(r)||r.trim()}function to(r){const n=r.match(/^\s{0,3}\[([^\]]+)\]:\s+(.+?)\s*$/);if(!n)return null;const s=Vi(n[2]);return s?{id:Ja(n[1]),definition:{href:s.href,title:s.title}}:null}function Vg(r){const n=new Map;for(const s of r){const l=to(s);l&&n.set(l.id,l.definition)}return n}function Vu(r){return r.trim().toLowerCase()}function Yu(r){const n=r.match(/^\s{0,3}\[\^([^\]]+)\]:\s+(.+)\s*$/);return n?{id:Vu(n[1]),text:n[2]}:null}function Yg(r){const n=new Map;let s=null;for(const l of r){const u=Yu(l);if(u){s=u.id,n.set(u.id,{id:u.id,text:u.text,index:n.size+1});continue}if(s&&/^\s{4,}\S/.test(l)){const c=n.get(s);c&&(c.text=`${c.text} ${l.trim()}`);continue}l.trim()&&(s=null)}return n}function Xu(r){const n=new Set;let s=!1;return r.forEach((l,u)=>{if(Yu(l)){n.add(u),s=!0;return}if(s&&/^\s{4,}\S/.test(l)){n.add(u);return}l.trim()&&(s=!1)}),n}function Xg(r){const n=[...r];let s=0;const l=r[0]?.trim();if(l==="---"||l==="+++"){for(n[0]="",s=1;s<r.length&&r[s].trim()!==l;)n[s]="",s+=1;s<r.length&&(n[s]="",s+=1)}for(;s<r.length;){const u=r[s].trim();if(u.startsWith("<!--")){if(n[s]="",!u.includes("-->")){for(s+=1;s<r.length&&!r[s].includes("-->");)n[s]="",s+=1;s<r.length&&(n[s]="")}s+=1;continue}s+=1}return n}function Ju(r){const n=r.replace(/\/+$/,""),s=n.lastIndexOf("/");return s<=0?s===0?"/":"":n.slice(0,s)}function As(r){const n=r.split(/[?#]/,1)[0],s=n.startsWith("/"),l=[];for(const c of n.split("/"))if(!(!c||c===".")){if(c===".."){l.length>0&&l.pop();continue}l.push(c)}return`${s?"/":""}${l.join("/")}`||(s?"/":".")}function rl(r,n,s){const l=r.trim();if(!l||/^(?:https?:|mailto:|javascript:|data:)/i.test(l)||/^[a-z][a-z0-9+.-]*:/i.test(l))return null;if(l.startsWith("#")){if(!n)return null;try{return{path:n,fragment:decodeURIComponent(l.slice(1))||null,directory:!1}}catch{return null}}const u=l.indexOf("#"),c=u>=0?l.slice(0,u):l,h=u>=0?l.slice(u+1):"",m=c.split("?",1)[0];if(!m)return null;let g,b=null;try{g=decodeURIComponent(m),b=h?decodeURIComponent(h):null}catch{return null}const f=s?As(s):null;let k;if(g.startsWith("/")){const y=f&&(g===f||g.startsWith(`${f}/`));k=As(f&&!y?`${f}/${g.slice(1)}`:g)}else{if(!n)return null;k=As(`${Ju(n)}/${g}`)}return f&&k!==f&&!k.startsWith(`${f}/`)?null:{path:k,fragment:b,directory:/\/$/.test(m)}}function nl(r,n,s,l,u){const c=r.trim();if(!c||/^(?:javascript|data):/i.test(c))return null;if(/^https?:\/\//i.test(c))return c;if(!l(c.split(/[?#]/,1)[0]))return null;let h;if(c.startsWith("/")){const m=s&&(c===s||c.startsWith(`${s}/`));h=As(s&&!m?`${s}/${c.slice(1)}`:c)}else{if(!n)return null;h=As(`${Ju(n)}/${c}`)}return u(h)}function Jg(r,n,s){return nl(r,n,s,Zi,l=>`/api/terminal/fs/blob?path=${encodeURIComponent(l)}`)}function Zg(r,n,s){return nl(r,n,s,ru,nu)}const qi=128,Qg=360,gi=480;function co(r){try{return/\.svg(?=$|[?#&])/i.test(decodeURIComponent(r))}catch{return!1}}function Zu(r,n,s,l,u=0){if(!n||!s)return null;let c,h;return u>0?(c=l>0?Math.min(u,l):u,h=s*c/n):co(r)?(h=Math.min(Math.max(s,qi),Qg),c=n*h/s):(c=n,h=s),l>0&&c>l&&(h=h*l/c,c=l),h>gi&&(c=c*gi/h,h=gi),{width:Math.max(1,Math.round(c)),height:Math.max(1,Math.round(h))}}function eb(r){if(!r.startsWith("/api/terminal/fs/blob?"))return null;try{return new URLSearchParams(r.slice(r.indexOf("?"))).get("path")}catch{return null}}function Qu(r){const n=eb(r),s=J(l=>n?(l.fileChangeVersions.get(n)??0)+l.fileWatchEpoch:0);return n&&s>0?`${r}&v=${s}`:r}function tb({src:r,alt:n,title:s,requestedWidthPx:l}){const u=co(r),c=Qu(r),h=io(c),m=a.useRef(null),[g,b]=a.useState(!1),[f,k]=a.useState(0),[y,N]=a.useState({status:"loading"}),[I,B]=a.useState(null);a.useLayoutEffect(()=>{const E=m.current,$=E?.parentElement?.parentElement??E?.parentElement;if(!$)return;const P=()=>k($.clientWidth);if(P(),typeof ResizeObserver>"u")return;const U=new ResizeObserver(P);return U.observe($),()=>U.disconnect()},[]),a.useEffect(()=>{if(g)return;const E=m.current;if(!E||typeof IntersectionObserver>"u"){b(!0);return}const $=new IntersectionObserver(P=>{P.some(U=>U.isIntersecting)&&(b(!0),$.disconnect())},{rootMargin:"400px"});return $.observe(E),()=>$.disconnect()},[g]),a.useEffect(()=>{if(!g)return;const E=new AbortController;let $=null;N({status:"loading"});const P=window.setTimeout(()=>{E.abort(new DOMException("Image fetch timed out","TimeoutError"))},15e3);return fm(c,{signal:E.signal}).then(async U=>{if(!U.ok)throw new Error(`HTTP ${U.status}`);const F=Number(U.headers.get("X-Image-Width"))||0,p=Number(U.headers.get("X-Image-Height"))||0;return{blob:await U.blob(),width:F,height:p}}).then(({blob:U,width:F,height:p})=>{E.signal.aborted||($=URL.createObjectURL(U),F>0&&p>0&&B({width:F,height:p}),N({status:"ready",objectUrl:$}))}).catch(()=>{const U=E.signal.reason;E.signal.aborted&&!(U instanceof DOMException&&U.name==="TimeoutError")||N({status:"fallback"})}).finally(()=>{window.clearTimeout(P)}),()=>{window.clearTimeout(P),E.abort(),$&&URL.revokeObjectURL($)}},[g,c]);const _=Zu(r,I?.width??0,I?.height??0,f,l??0),R=_??(l?{width:f>0?Math.min(l,f):l,height:Math.round(l*.75)}:{width:qi*2,height:qi});return e.jsx("div",{ref:m,className:"block max-w-full",style:_?{width:_.width,height:_.height}:void 0,children:y.status==="ready"?e.jsx("img",{src:y.objectUrl,alt:n,title:s,decoding:"async",className:`${u?"":"termdock-fade-in "}block max-h-[480px] max-w-full object-contain`,style:_?{width:_.width,height:_.height}:void 0,onLoad:E=>{if(I)return;const $=E.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&B({width:$.naturalWidth,height:$.naturalHeight})}}):y.status==="fallback"?e.jsx("img",{src:h,alt:n,title:s,loading:"lazy",decoding:"async",className:"block max-h-[480px] max-w-full object-contain",style:_?{width:_.width,height:_.height}:void 0,onLoad:E=>{if(I)return;const $=E.currentTarget;$.naturalWidth>0&&$.naturalHeight>0&&B({width:$.naturalWidth,height:$.naturalHeight})}}):e.jsx("div",{"aria-hidden":!0,className:"flex max-w-full animate-pulse items-center justify-center rounded bg-surface-elevated/60",style:{width:R.width,height:R.height},children:e.jsx("span",{className:"text-[10px] text-muted-foreground/60",children:n||"…"})})})}function Ps(r,n,s,l,u,c){const h=Jg(s,u.markdownFilePath,u.rootPath);if(!h)return c?.fallbackText??`![${n}](${s})`;const m=u.images.length;u.images.push({kind:"image",src:h,alt:n,title:l});const g=e.jsx(tb,{src:h,alt:n,title:l,requestedWidthPx:c?.requestedWidthPx});return u.onImageOpen&&c?.interactive!==!1?e.jsx("button",{type:"button",className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2 text-left transition hover:border-border-strong focus:outline-none focus:ring-2 focus:ring-ring/45",title:l||n||"Open image",onClick:b=>{b.stopPropagation(),u.onImageOpen?.(m)},children:g},r):e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:g},r)}function bi(r){let n=r,s="";for(;/[.,;:!?)]$/.test(n);)s=`${n.slice(-1)}${s}`,n=n.slice(0,-1);return{linkText:n,suffix:s}}function Wd(r){return/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/.test(r)}function Vi(r){const n=r.trim(),s=n.match(/^<([^>]+)>(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);if(s)return{href:s[1],title:s[2]??s[3]??s[4]};const l=n.match(/^(\S+)(?:\s+(?:"([^"]*)"|'([^']*)'|\(([^)]*)\)))?$/);return l?{href:l[1],title:l[2]??l[3]??l[4]}:null}const ef="",rb=/\\([\\`*{}\[\]#+\-.!_|~>$])/g;function nb(r){return r.replace(rb,(n,s)=>`${ef}${s.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Gd(r){return r.replace(new RegExp(`${ef}([0-9a-f]{4})`,"g"),(n,s)=>String.fromCharCode(Number.parseInt(s,16))).replace(/\\([()])/g,"$1")}function sb(r){const n=r.replace(/[\r\n]+/g," ");return/^ .+ $/.test(n)&&/[^ ]/.test(n.slice(1,-1))?n.slice(1,-1):n}const tf={ALLOWED_TAGS:["a","abbr","b","blockquote","br","code","del","details","div","em","i","kbd","li","mark","ol","p","pre","s","span","strong","sub","summary","sup","table","tbody","td","th","thead","tr","u","ul"],ALLOWED_ATTR:["href","title","class","id","colspan","rowspan"],ALLOW_DATA_ATTR:!1,ALLOW_ARIA_ATTR:!0};let Ha=null;function rf(){return Ha||(Ha=Ds(()=>import("./purify.es-4eNOHKSq.js"),[]).then(r=>r.default??r).catch(r=>{throw Ha=null,r})),Ha}function nf({html:r}){const{t:n}=wt(),[s,l]=a.useState(null);return a.useEffect(()=>{let u=!1;return l(null),rf().then(c=>{u||l(c.sanitize(r,tf))}).catch(()=>{u||l("")}),()=>{u=!0}},[r]),s===null?e.jsx("div",{className:"py-2 text-xs text-muted-foreground",children:n("rightSidebar.renderingHtml")}):s?e.jsx("div",{className:"text-muted-foreground",dangerouslySetInnerHTML:{__html:s}}):null}function ab({html:r}){const[n,s]=a.useState(null);return a.useEffect(()=>{let l=!1;return s(null),rf().then(u=>{l||s(u.sanitize(r,tf))}).catch(()=>{l||s("")}),()=>{l=!0}},[r]),n===null?null:n?e.jsx("span",{dangerouslySetInnerHTML:{__html:n}}):r}function sf(r){const n=r.trim().match(/^<(div|section|article|aside|table|p|ul|ol|li|blockquote|pre|figure|figcaption)\b[^>]*>/i);if(!n)return null;const s=n[1].toLowerCase();return{tag:s,selfContained:new RegExp(`</${s}>`,"i").test(r)}}let za=null;function ob(){return za||(za=Promise.all([Ds(()=>import("./katex-DnlPpQZa.js"),[]),Ds(()=>Promise.resolve({}),__vite__mapDeps([16]))]).then(([r])=>r.default??r).catch(r=>{throw za=null,r})),za}function _s({tex:r,display:n=!1}){const[s,l]=a.useState(null),[u,c]=a.useState(!1);if(a.useEffect(()=>{let m=!1;return l(null),c(!1),ob().then(g=>{m||l(g.renderToString(r,{displayMode:n,throwOnError:!1,trust:!1,strict:"ignore"}))}).catch(()=>{m||c(!0)}),()=>{m=!0}},[n,r]),u)return e.jsx("code",{className:"rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground",children:n?`$$${r}$$`:`$${r}$`});if(!s)return e.jsx("span",{className:"text-muted-foreground/70",children:n?"Rendering formula...":r});const h=n?"my-2 overflow-auto rounded-md bg-surface-2 px-3 py-2 text-center":"inline-block align-middle";return e.jsx("span",{className:h,dangerouslySetInnerHTML:{__html:s}})}function sl(r){const n=new Map;for(const s of r.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+))/gi))n.set(s[1].toLowerCase(),s[2]??s[3]??s[4]);return n}function Kd(r){const n=sl(r),s=n.get("src")?.trim()??"",l=n.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i);return{src:s,alt:n.get("alt"),title:n.get("title"),widthPx:l?Number(l[1]):void 0}}function ib(r){const n=r.indexOf(">"),s=n<0?r:r.slice(0,n+1),l=sl(s),u=l.get("src")?.trim()??"",c=l.get("width")?.trim().match(/^(\d+(?:\.\d+)?)(?:px)?$/i),h=s.replace(/=\s*(?:"[^"]*"|'[^']*')/g," "),m=n<0?"":r.slice(n+1).replace(/<\/video\s*>$/i,"").replace(/<[^>]*>/g,"").trim();return{src:u,fallbackText:m,widthPx:c?Number(c[1]):void 0,controls:/\bcontrols\b/i.test(h)}}function lb({url:r,fallbackText:n,widthPx:s,hasControls:l}){const{t:u}=wt(),[c,h]=a.useState(!1),m=io(r,()=>h(!0));return m?e.jsx("span",{className:"my-2 block max-w-full overflow-hidden rounded-md border border-border/20 bg-surface-2",children:c?e.jsx("span",{className:"block px-3 py-2 text-xs text-muted-foreground",children:n?.trim()||u("rightSidebar.videoUnsupported")}):e.jsx("video",{className:"block max-w-full",src:m,style:s?{width:`${s}px`}:void 0,controls:l,preload:"metadata",playsInline:!0,onError:()=>h(!0)})}):null}function cb(r,n,s){if(/^<a\b[^>]*>\s*<\s*img\b[^>]*>\s*<\/a\s*>$/i.test(r)){const h=r.slice(0,r.indexOf(">")+1),m=sl(h).get("href")?.trim()??"",g=r.match(/<\s*img\b[^>]*>/i)?.[0]??"",{src:b,alt:f,title:k,widthPx:y}=Kd(g);if(!b)return null;const N=nl(b,s.markdownFilePath,s.rootPath,Zi,E=>E);if(!N)return null;const I=m?rl(m,s.markdownFilePath,s.rootPath):null,_=!!!(I&&I.path===N)&&m?Wu(m):null,R=Ps(n,f??"",b,k,s,{requestedWidthPx:y,interactive:_?!1:void 0});return _?e.jsx("a",{href:_,target:"_blank",rel:"noreferrer",children:R},n):R}if(/^<\s*img\b[^>]*>$/i.test(r)){const{src:h,alt:m,title:g,widthPx:b}=Kd(r);return h?Ps(n,m??"",h,g,s,{fallbackText:r,requestedWidthPx:b}):null}if(/^<\s*video\b[^>]*>[\s\S]*?<\/video\s*>$/i.test(r)){const{src:h,fallbackText:m,widthPx:g,controls:b}=ib(r);if(!h)return null;const f=Zg(h,s.markdownFilePath,s.rootPath);return f?e.jsx(lb,{url:f,fallbackText:m,widthPx:g,hasControls:b},n):null}if(/^<br\s*\/?>$/i.test(r))return e.jsx("br",{},n);const l=r.match(/^<(kbd|mark|sub|sup)>(.*?)<\/\1>$/i);if(!l)return/^<(a|abbr|span|b|strong|em|i|u|s|del|code)\b[\s\S]*<\/\1>$/i.test(r)?e.jsx(ab,{html:r},n):null;const u=l[1].toLowerCase(),c=it(l[2],`${n}-${u}`,!0,s);return u==="kbd"?e.jsx("kbd",{className:"rounded border border-border/30 bg-surface-2 px-1.5 py-0.5 font-mono text-[0.85em] text-foreground shadow-sm",children:c},n):u==="mark"?e.jsx("mark",{className:"rounded bg-warning/25 px-0.5 text-foreground",children:c},n):u==="sub"?e.jsx("sub",{children:c},n):e.jsx("sup",{children:c},n)}function it(r,n,s=!0,l){const u=nb(r),c=/(\\\([^)]*\\\)|\$[^$\n]+\$|<br\s*\/?>|<\s*img\b[^>]*>|<\s*video\b[^>]*>[\s\S]*?<\/video\s*>|<(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)\b[\s\S]*?<\/(?:a|abbr|span|b|strong|em|i|u|s|del|code|kbd|mark|sub|sup)>|!?\[[^\]]*\]\((?:<[^>]+>|(?:[^\s()]+|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\)|!?\[[^\]]+\]\[[^\]]*\]|!?\[[^\]]+\]|\[\^[^\]]+\]|(`+)([\s\S]*?)\2|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|\*[^*\s][^*]*\*|_[^_\s][^_]*_|<https?:\/\/[^>\s]+>|<[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+>|https?:\/\/[^\s<]+|www\.[^\s<]+|[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+)/gi,h=[];let m=0,g;for(;(g=c.exec(u))!==null;){g.index>m&&h.push(Gd(u.slice(m,g.index)));const b=g[0],f=`${n}-${g.index}`,k=b.startsWith("<")?cb(b,f,l):null;if(k)h.push(k);else if(b.startsWith("\\(")&&b.endsWith("\\)"))h.push(e.jsx(_s,{tex:b.slice(2,-2)},f));else if(b.startsWith("$")&&b.endsWith("$"))h.push(e.jsx(_s,{tex:b.slice(1,-1)},f));else if(b.startsWith("`")){const y=b.match(/^`+/)?.[0].length??1;h.push(e.jsx("code",{className:`${s?"break-all":"whitespace-nowrap"} rounded bg-surface-2 px-1 py-0.5 font-mono text-[0.92em] text-foreground`,children:sb(b.slice(y,-y))},f))}else if(b.startsWith("~~"))h.push(e.jsx("del",{className:"text-muted-foreground decoration-border-strong",children:it(b.slice(2,-2),`${f}-del`,s,l)},f));else if(b.startsWith("**")||b.startsWith("__"))h.push(e.jsx("strong",{className:"font-semibold text-foreground",children:it(b.slice(2,-2),`${f}-strong`,s,l)},f));else if(b.startsWith("*")||b.startsWith("_"))h.push(e.jsx("em",{className:"italic",children:it(b.slice(1,-1),`${f}-em`,s,l)},f));else if(b.startsWith("![")){const y=b.match(/^!\[([^\]]*)\]\((.*)\)$/),N=b.match(/^!\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^!\[([^\]]+)\]$/);if(y){const B=Vi(y[2]);h.push(B?Ps(f,y[1],B.href,B.title,l):b)}else if(N){const B=N[2]||N[1],_=l.referenceDefinitions.get(Ja(B));h.push(_?Ps(f,N[1],_.href,_.title,l):b)}else if(I){const B=l.referenceDefinitions.get(Ja(I[1]));h.push(B?Ps(f,I[1],B.href,B.title,l):b)}else h.push(b)}else if(b.startsWith("[^")){const y=Vu(b.slice(2,-1)),N=l.footnoteDefinitions.get(y);h.push(N?e.jsx("sup",{id:`fnref-${N.id}`,title:N.text,className:"ml-0.5 rounded bg-surface-2 px-1 text-[0.72em] font-semibold text-primary",children:e.jsx("a",{href:`#fn-${N.id}`,className:"text-primary no-underline",children:N.index})},f):b)}else if(b.startsWith("<http")){const y=b.slice(1,-1);h.push(e.jsx("a",{href:y,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(b.startsWith("<")&&b.endsWith(">")&&Wd(b.slice(1,-1))){const y=b.slice(1,-1);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f))}else if(Wd(bi(b).linkText)){const{linkText:y,suffix:N}=bi(b);h.push(e.jsx("a",{href:`mailto:${y}`,className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),N&&h.push(N)}else if(b.startsWith("http")||b.startsWith("www.")){const{linkText:y,suffix:N}=bi(b),I=y.startsWith("www.")?`https://${y}`:y;h.push(e.jsx("a",{href:I,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:y},f)),N&&h.push(N)}else{const y=b.match(/^\[([^\]]+)\]\((.*)\)$/),N=b.match(/^\[([^\]]+)\]\[([^\]]*)\]$/),I=b.match(/^\[([^\]]+)\]$/),B=N?N[2]||N[1]:I?.[1]??null,_=B?l.referenceDefinitions.get(Ja(B)):null,R=y?Vi(y[2]):null,E=R?.href??_?.href??null,$=E?Wu(E):null,P=y?.[1]??N?.[1]??I?.[1]??"";h.push($?e.jsx("a",{href:$,title:R?.title??_?.title,target:"_blank",rel:"noreferrer",className:`${s?"break-all":"whitespace-nowrap"} text-primary underline decoration-primary/40 underline-offset-2 hover:decoration-primary`,children:it(P,`${f}-link`,s,l)},f):b)}m=c.lastIndex}return m<u.length&&h.push(Gd(u.slice(m))),h.length>0?h:[r]}function af(r){return/(?: {2,}|\\)$/.test(r)}function of(r){return r.replace(/(?: {2,}|\\)$/,"")}function ro(r){return/^(?: {4}|\t)/.test(r)}function lf(r){return r.startsWith(" ")?r.slice(1):r.replace(/^ {4}/,"")}function cf(r,n,s){const l=[];return r.forEach((u,c)=>{const h=af(u);l.push(...it(of(u),`${n}-${c}`,!0,s)),c<r.length-1&&l.push(h?e.jsx("br",{},`${n}-${c}-br`):" ")}),l}function Yi(r,n,s){const l=[],u=[];return r.forEach((c,h)=>{u.push(af(c)),l.push(it(of(c),`${n}-${h}`,!0,s))}),{perLine:l,hardBreaks:u}}function Xi(r,n,s,l,u){const c=[];return r.forEach((h,m)=>{const g=s[m]??0,b=!!(u&&g>=u.start&&g<=u.end);c.push(e.jsx("span",{"data-md-ref-start":g,"data-md-ref-end":g,"data-selected":b?"true":void 0,children:h},`${l}-ref-${m}`)),m<r.length-1&&c.push(n[m]?e.jsx("br",{},`${l}-${m}-br`):" ")}),c}function Bs(r){const n=r.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let l="",u=!1,c=0,h=0;for(let m=0;m<n.length;m+=1){const g=n[m];if(u){l+=g,u=!1;continue}if(g==="\\"){u=!0;continue}if(g==="`"){const b=m;for(;m+1<n.length&&n[m+1]==="`";)m+=1;const f=m-b+1;l+="`".repeat(f),c===0?c=f:c===f&&(c=0);continue}if(c===0&&g==="["?h+=1:c===0&&g==="]"&&h>0&&(h-=1),g==="|"&&c===0&&h===0){s.push(l.trim()),l="";continue}l+=g}return u&&(l+="\\"),s.push(l.trim()),s}function df(r){return Bs(r).map(n=>/^:-+:$/.test(n)?"center":/^-+:$/.test(n)?"right":/^:-+$/.test(n)?"left":null)}function no(r){return r==="center"?"text-center":r==="right"?"text-right":"text-left"}function so(r){return/^\|?\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?$/.test(r.trim())}function uf(r,n){return r>96||r>44&&n>.35}function uo(r){return(r.match(/^\s*/)?.[0]??"").replace(/\t/g," ").length}function Os(r){const n=r.trim().match(/^([-+*]|\d+[.)])\s+(.+)$/);if(!n)return null;const s=/^\d+[.)]$/.test(n[1]);return{ordered:s,start:s?Number.parseInt(n[1],10):void 0,content:n[2]}}function al(r,n,s,l,u,c=new Set){const h=[],m=[];let g=n;for(;g<r.length;){const b=r[g];if(u&&(to(b)||c.has(g))){g+=1;continue}const f=Os(b),k=uo(b);if(!f){if(k>s&&m.length>0){([...m].reverse().find(B=>B.indent<k)?.item??m[m.length-1].item).paragraphs.push(b.trim());for(const B of m)B.item.lineEnd=g+1;g+=1;continue}break}if(k<s||k===s&&f.ordered!==l)break;const y={content:f.content,ordered:f.ordered,start:f.start,children:[],paragraphs:[],lineStart:g+1,lineEnd:g+1};for(;m.length>0&&m[m.length-1].indent>=k;)m.pop();const N=m[m.length-1]?.item??null;N?N.children.push(y):h.push(y),m.push({indent:k,item:y});for(const I of m)I.item.lineEnd=g+1;g+=1}return{items:h,nextIndex:g}}function db(r){const n=r.find(l=>Os(l));if(!n)return[];const s=Os(n);return s?al(r,0,uo(n),s.ordered,!0,Xu(r)).items:[]}function ol(r,n,s,l=0){return r.map((u,c)=>{const h=u.content.match(/^\[([ xX])\]\s+(.+)$/);return{key:`item-${c}`,taskItem:!!h,refStart:u.lineStart+l,refEnd:u.lineEnd+l,content:e.jsxs(e.Fragment,{children:[h?e.jsx("input",{type:"checkbox",checked:h[1].toLowerCase()==="x",readOnly:!0,className:"mr-2 align-[-2px] accent-primary"}):null,it(h?.[2]??u.content,`li-${n}-${c}`,!0,s),u.paragraphs.length>0&&e.jsx("div",{className:"mt-1 space-y-1 text-muted-foreground",children:u.paragraphs.map((m,g)=>e.jsx("p",{children:it(m,`li-${n}-${c}-p-${g}`,!0,s)},`paragraph-${g}`))})]}),groups:ub(u.children,`${n}-${c}`,s,l)}})}function ub(r,n,s,l=0){const u=[];for(const c of r){const h=u[u.length-1];h&&h.ordered===c.ordered?h.items.push(c):u.push({ordered:c.ordered,items:[c]})}return u.map((c,h)=>({ordered:c.ordered,start:c.ordered?c.items[0]?.start:void 0,items:ol(c.items,`${n}-g${h}`,s,l)}))}function il(r,n){return r.map(s=>{const l=!!(n&&s.refStart<=n.end&&s.refEnd>=n.start);return e.jsxs("li",{className:s.taskItem?"list-none":void 0,"data-md-ref-start":s.refStart,"data-md-ref-end":s.refEnd,"data-selected":l?"true":void 0,children:[s.content,s.groups.length>0&&fb(s.groups,n)]},s.key)})}function fb(r,n){return r.map((s,l)=>{const u=s.ordered?"ol":"ul";return e.jsx(u,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} mt-1 space-y-0.5 pl-4 marker:text-muted-foreground/60`,children:il(s.items,n)},`nested-${l}`)})}function hb(r){const n=Array.from(r.footnoteDefinitions.values()).sort((s,l)=>s.index-l.index);return n.length===0?null:e.jsxs("section",{className:"mt-3 border-t border-border/20 pt-2 text-[12px] leading-5 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/80",children:r.footnotesLabel}),e.jsx("ol",{className:"list-decimal space-y-1 pl-5",children:n.map(s=>e.jsxs("li",{id:`fn-${s.id}`,children:[it(s.text,`footnote-${s.id}`,!0,r)," ",e.jsx("a",{href:`#fnref-${s.id}`,className:"text-primary no-underline","aria-label":r.backToFootnoteLabel(s.index),children:"↩"})]},s.id))})]})}function mb(r,n,s,l){const u=[];let c=0;const h=m=>l?.[m]??m+1;for(;c<r.length;){const m=r[c],g=m.trim();if(!g){c+=1;continue}if(/^<details>\s*$/i.test(g)){const R=c;let E="Details";const $=[];for(c+=1;c<r.length&&!/^<\/details>\s*$/i.test(r[c].trim());){const P=r[c].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);P?E=P[1].trim()||E:$.push(r[c].trimStart()),c+=1}c<r.length&&(c+=1),u.push({kind:"static",node:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:it(E,`${n}-details-${R}-summary`,!0,s)}),$.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:cf($,`${n}-details-${R}`,s)})]},`${n}-details-${R}`)});continue}const b=sf(m);if(b){const R=[m],E=c;for(c+=1;c<r.length&&!b.selfContained&&!new RegExp(`</${b.tag}>`,"i").test(r[c]);)R.push(r[c]),c+=1;c<r.length&&!b.selfContained&&(R.push(r[c]),c+=1),u.push({kind:"static",node:e.jsx(nf,{html:R.join(`
1639
+ `)},`${n}-html-${E}`)});continue}const f=g.match(/^(```|~~~)\s*(.*)$/);if(f){const R=[],E=f[1],$=f[2]?.trim(),P=c;for(c+=1;c<r.length&&!r[c].trim().startsWith(E);)R.push(r[c]),c+=1;c<r.length&&(c+=1),$.toLowerCase()==="mermaid"?u.push({kind:"static",node:e.jsx(hf,{code:R.join(`
1640
+ `),blockKey:`${n}-code-${P}`},`${n}-code-${P}`)}):["math","latex","tex"].includes($.toLowerCase())?u.push({kind:"static",node:e.jsx(_s,{tex:R.join(`
1641
+ `),display:!0},`${n}-code-${P}`)}):u.push({kind:"code",key:`${n}-code-${P}`,code:R.join(`
1642
+ `),lang:$,blockKey:`${n}-code-${P}`,codeStartLine:h(P)+1});continue}if(ro(m)){const R=[],E=c;for(;c<r.length&&(ro(r[c])||!r[c].trim());)R.push(r[c].trim()?lf(r[c]):""),c+=1;u.push({kind:"code",key:`${n}-indented-code-${E}`,code:R.join(`
1643
+ `).replace(/\n+$/,""),lang:"",blockKey:`${n}-indented-code-${E}`,codeStartLine:h(E)});continue}const k=g.match(/^(#{1,6})\s+(.+)$/);if(k){const E=`h${Math.min(6,k[1].length+1)}`,$=qu(k[2]),P=Ki($,s);u.push({kind:"static",node:e.jsx(E,{id:P,className:"scroll-mt-16 font-semibold text-foreground",children:it($,`${n}-heading-${c}`,!0,s)},`${n}-heading-${c}`)}),c+=1;continue}if(c+1<r.length&&m.includes("|")&&so(r[c+1])){const R=Bs(m),E=df(r[c+1]),$=[],P=c;for(c+=2;c<r.length&&r[c].includes("|")&&r[c].trim();)$.push(Bs(r[c])),c+=1;u.push({kind:"static",node:e.jsx("div",{className:Fu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{children:R.map((U,F)=>e.jsx("th",{className:`${Iu} ${no(E[F]??null)}`,children:e.jsx("div",{className:eo,children:it(U,`${n}-th-${P}-${F}`,!0,s)})},`h-${F}`))})}),e.jsx("tbody",{children:$.map((U,F)=>e.jsx("tr",{className:"border-t border-border/10",children:R.map((p,i)=>e.jsx("td",{className:`${Du} ${no(E[i]??null)}`,children:e.jsx("div",{className:eo,children:it(U[i]??"",`${n}-td-${P}-${F}-${i}`,!0,s)})},`c-${i}`))},`r-${F}`))})]})},`${n}-table-${P}`)});continue}const y=Os(m);if(y){const R=y.ordered,E=uo(m),$=y.start,P=c,U=al(r,c,E,R,!1);c=U.nextIndex,u.push({kind:"list",keyPrefix:`${n}-list-${P}`,ordered:R,start:R?$:void 0,renders:ol(U.items,`${n}-list-${P}`,s,h(0)-1)});continue}const N=[m.trimStart()],I=[h(c)],B=c;for(c+=1;c<r.length&&r[c].trim()&&!Gi(r[c])&&!(c+1<r.length&&r[c].includes("|")&&so(r[c+1]));)N.push(r[c].trimStart()),I.push(h(c)),c+=1;const _=Yi(N,`${n}-p-${B}`,s);u.push({kind:"paragraph",keyPrefix:`${n}-p-${B}`,perLine:_.perLine,hardBreaks:_.hardBreaks,lineNums:I})}return u}function pb(r,n){return r.map(s=>{switch(s.kind){case"static":return s.node;case"paragraph":return e.jsx("p",{children:Xi(s.perLine,s.hardBreaks,s.lineNums,s.keyPrefix,n)},s.keyPrefix);case"list":{const l=s.ordered?"ol":"ul";return e.jsx(l,{start:s.start,className:`${s.ordered?"list-decimal":"list-disc"} space-y-0.5 pl-4 marker:text-muted-foreground/70`,children:il(s.renders,n)},s.keyPrefix)}case"code":return e.jsx(ao,{code:s.code,lang:s.lang,blockKey:s.blockKey,codeStartLine:s.codeStartLine,lineRange:n},s.key)}})}let Wa=null,qd=!1;const Ga=16,ff=192;function gb(){return Wa||(Wa=Ds(()=>import("./mermaid.core-5r_1zWs_.js").then(r=>r.bl),__vite__mapDeps([17,1,2,3,4,5,18])).then(r=>r.default??r).catch(r=>{throw Wa=null,r})),Wa}function bb(r){qd||(r.initialize({startOnLoad:!1,securityLevel:"strict",theme:"neutral"}),qd=!0)}function xb(r){const n=r.match(/\sviewBox=(["'])([^"']+)\1/i);if(!n)return r;const[,,s]=n,l=s.trim().split(/[\s,]+/).map(Number),[,,u,c]=l;if(!Number.isFinite(u)||!Number.isFinite(c)||u<=0||c<=0)return r;const h=Math.max(ff,Math.ceil(u)),m=Math.ceil(h/u*c);return r.replace(/<svg\b([^>]*)>/i,(g,b)=>`<svg${b.replace(/\s(?:width|height)=(["']).*?\1/gi,"").replace(/\sstyle=(["']).*?\1/gi,"")} width="${h}" height="${m}">`)}function vb(r){const n=r?.querySelector("svg");if(!n)return;let s;try{s=n.getBBox()}catch{return}if(!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<=0||s.height<=0)return;const l=s.x-Ga,u=s.y-Ga,c=s.width+Ga*2,h=s.height+Ga*2,m=Math.max(ff,Math.ceil(c)),g=Math.ceil(m/c*h);n.setAttribute("viewBox",`${l} ${u} ${c} ${h}`),n.setAttribute("width",String(m)),n.setAttribute("height",String(g)),n.removeAttribute("style")}function yb(r){const n=r.trim().split(/\s+/,1)[0]?.toLowerCase();if(!n)return null;const s=n.replace(/^language-/,"");return hu(`code.${s}`)??s}function hf({code:r,blockKey:n}){const{t:s}=wt(),[l,u]=a.useState(null),[c,h]=a.useState(!1),m=a.useRef(null),g=a.useContext(Gu);a.useEffect(()=>{let f=!1;return u(null),h(!1),gb().then(async k=>{bb(k);const y=`termdock-md-mermaid-${n.replace(/[^a-zA-Z0-9_-]/g,"-")}`,{svg:N}=await k.render(y,r);f||u(xb(N))}).catch(()=>{f||h(!0)}),()=>{f=!0}},[n,r]),a.useLayoutEffect(()=>{l&&vb(m.current)},[l]);const b=a.useCallback(()=>{const f=m.current?.querySelector("svg")?.outerHTML??l;f&&g?.(f)},[g,l]);return c?e.jsx(ao,{code:r,lang:"mermaid",blockKey:`${n}-fallback`}):e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"mermaid"}),e.jsx("div",{className:"bg-surface p-3",children:l?e.jsx("button",{type:"button",className:"block max-w-full rounded text-left focus:outline-none focus:ring-2 focus:ring-ring/45",title:s("rightSidebar.openMermaidDiagram"),onClick:f=>{f.stopPropagation(),b()},children:e.jsx("span",{ref:m,role:"img","aria-label":s("rightSidebar.mermaidDiagram"),className:"block max-h-[70vh] max-w-full overflow-auto rounded bg-white p-2 text-slate-900 [&_svg]:block [&_svg]:h-auto [&_svg]:max-w-full",dangerouslySetInnerHTML:{__html:l}})}):e.jsx("div",{className:"py-6 text-center text-xs text-muted-foreground",children:s("rightSidebar.renderingDiagram")})})]})}function ao({code:r,lang:n,blockKey:s,codeStartLine:l,lineRange:u}){const c=yb(n),[h,m]=a.useState(null);a.useEffect(()=>{if(!c||!mu(r)){m(null);return}let b=!1;return pu().then(f=>{if(b||!f.registered(c)){b||m(null);return}try{m(gu(f,r,c))}catch{b||m(null)}}).catch(()=>{b||m(null)}),()=>{b=!0}},[s,r,c]);const g=h??(r||" ").split(`
1644
+ `).map(b=>[b||" "]);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface shadow-sm",children:[n&&e.jsx("div",{className:"border-b border-border/15 bg-surface-2 px-3 py-1.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("pre",{className:`${tl} termdock-code overflow-auto p-3 text-[11px] leading-relaxed text-foreground`,children:e.jsx("code",{children:g.map((b,f)=>{const k=l!=null?l+f:null,y=!!(u&&k!=null&&k>=u.start&&k<=u.end);return e.jsxs("span",{"data-md-ref-start":k??void 0,"data-md-ref-end":k??void 0,"data-selected":y?"true":void 0,children:[b,f<g.length-1?`
1645
+ `:null]},`${s}-line-${f}`)})})})]})}function ll(r,n,s,l,u){r=Xg(r);const c=Vg(r),h=Xu(r),m=[],g={markdownFilePath:n,rootPath:s,referenceDefinitions:c,footnoteDefinitions:Yg(r),headingSlugCounts:new Map,images:m,onImageOpen:l,footnotesLabel:u?.footnotes??"Footnotes",backToFootnoteLabel:u?.backToFootnote??(y=>`Back to footnote ${y}`)},b=[];let f=0;for(;f<r.length;){const y=r[f],N=y.trim();if(to(y)||h.has(f)){f+=1;continue}if(!N){f+=1;continue}if(/^<details>\s*$/i.test(N)){const F=f;let p="Details";const i=[];for(f+=1;f<r.length&&!/^<\/details>\s*$/i.test(r[f].trim());){const O=r[f].trim().match(/^<summary>(.*?)<\/summary>\s*$/i);O?p=O[1].trim()||p:i.push(r[f].trimStart()),f+=1}f<r.length&&(f+=1),b.push({key:`details-${F}`,startLine:F+1,endLine:f,content:e.jsxs("details",{className:"overflow-hidden rounded-lg border border-border/20 bg-surface px-3 py-2 text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-foreground",children:it(p,`details-${F}-summary`,!0,g)}),i.length>0&&e.jsx("div",{className:"mt-2 text-sm leading-6",children:cf(i,`details-${F}`,g)})]})});continue}const I=sf(y);if(I){const F=[y],p=f;for(f+=1;f<r.length&&!I.selfContained&&!new RegExp(`</${I.tag}>`,"i").test(r[f]);)F.push(r[f]),f+=1;f<r.length&&!I.selfContained&&(F.push(r[f]),f+=1),b.push({key:`html-${p}`,startLine:p+1,endLine:f,content:e.jsx(nf,{html:F.join(`
1646
+ `)})});continue}const B=N.match(/^(```|~~~)\s*(.*)$/);if(B){const F=[],p=B[1],i=B[2]?.trim(),O=f;for(f+=1;f<r.length&&!r[f].trim().startsWith(p);)F.push(r[f]),f+=1;f<r.length&&(f+=1),b.push({key:`code-${O}`,startLine:O+1,endLine:f,fineGrained:i.toLowerCase()!=="mermaid"&&!["math","latex","tex"].includes(i.toLowerCase()),content:i.toLowerCase()==="mermaid"?e.jsx(hf,{code:F.join(`
1647
+ `),blockKey:`code-${O}`}):["math","latex","tex"].includes(i.toLowerCase())?e.jsx(_s,{tex:F.join(`
1648
+ `),display:!0}):C=>e.jsx(ao,{code:F.join(`
1649
+ `),lang:i,blockKey:`code-${O}`,codeStartLine:O+2,lineRange:C})});continue}if(ro(y)){const F=[],p=f;for(f+=0;f<r.length&&(ro(r[f])||!r[f].trim());)F.push(r[f].trim()?lf(r[f]):""),f+=1;b.push({key:`indented-code-${p}`,startLine:p+1,endLine:f,fineGrained:!0,content:i=>e.jsx(ao,{code:F.join(`
1650
+ `).replace(/\n+$/,""),lang:"",blockKey:`indented-code-${p}`,codeStartLine:p+1,lineRange:i})});continue}if(N.startsWith("$$")){const F=[],p=f,i=N.replace(/^\$\$\s*/,"");if(i.endsWith("$$")&&i.length>2)F.push(i.replace(/\s*\$\$$/,"")),f+=1;else{for(i&&F.push(i),f+=1;f<r.length&&!r[f].trim().endsWith("$$");)F.push(r[f]),f+=1;if(f<r.length){const O=r[f].trim().replace(/\s*\$\$$/,"");O&&F.push(O),f+=1}}b.push({key:`math-${p}`,startLine:p+1,endLine:f,content:e.jsx(_s,{tex:F.join(`
1651
+ `),display:!0})});continue}if(f+1<r.length&&N&&!Gi(y)&&/^(=+|-+)\s*$/.test(r[f+1].trim())){const F=r[f+1].trim().startsWith("=")?1:2,p=`h${F}`,i=Ki(N,g),O={level:F,text:zd(N),id:i};b.push({key:`setext-heading-${f}`,startLine:f+1,endLine:f+2,heading:O,content:e.jsx(p,{id:i,className:`scroll-mt-16 font-semibold text-foreground ${F===1?"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl":"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg"}`,children:it(N,`setext-heading-${f}`,!0,g)})}),f+=2;continue}const _=N.match(/^(#{1,6})\s+(.+)$/);if(_){const F=_[1].length,p=qu(_[2]),i={1:"mt-1 border-b border-border/20 pb-1.5 text-lg sm:pb-2 sm:text-xl",2:"mt-1 border-b border-border/15 pb-1 text-base sm:pb-1.5 sm:text-lg",3:"text-sm sm:text-base",4:"text-[13px] sm:text-sm",5:"text-[11px] uppercase tracking-wide sm:text-xs",6:"text-[11px] uppercase tracking-wide text-muted-foreground"},O=`h${F}`,C=Ki(p,g),G={level:F,text:zd(p),id:C};b.push({key:`heading-${f}`,startLine:f+1,endLine:f+1,heading:G,content:e.jsx(O,{id:C,className:`scroll-mt-16 font-semibold text-foreground ${i[F]}`,children:it(p,`heading-${f}`,!0,g)})}),f+=1;continue}if(zu(y)){b.push({key:`hr-${f}`,startLine:f+1,endLine:f+1,content:e.jsx("hr",{className:"border-border/20"})}),f+=1;continue}if(N.startsWith(">")){const F=[],p=[],i=f;for(;f<r.length&&/^>\s?/.test(r[f].trim());)F.push(r[f].trim().replace(/^>\s?/,"")),p.push(f+1),f+=1;const O=F[0]?.match(/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i);if(O){const G=O[1].toUpperCase(),fe=O[2]?.trim(),te=[...fe?[fe]:[],...F.slice(1)],xe=[...fe?[p[0]]:[],...p.slice(1)],W=Yi(te,`callout-${i}`,g);b.push({key:`callout-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:Y=>e.jsxs("aside",{className:"rounded-lg border border-primary/20 bg-primary/5 px-3 py-2 text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] font-semibold uppercase tracking-wide text-primary",children:G}),te.length>0&&e.jsx("div",{children:Xi(W.perLine,W.hardBreaks,xe,`callout-${i}`,Y)})]})});continue}const C=mb(F,`quote-${i}`,g,p);b.push({key:`quote-${i}`,startLine:i+1,endLine:f,fineGrained:!0,content:G=>e.jsx("blockquote",{className:"space-y-2 border-l-2 border-border-strong bg-surface-2/70 py-1.5 pl-2.5 pr-2 text-muted-foreground sm:py-2 sm:pl-3",children:pb(C,G)})});continue}if(f+1<r.length&&y.includes("|")&&so(r[f+1])){const F=Bs(y),p=df(r[f+1]),i=[],O=f;for(f+=2;f<r.length&&r[f].includes("|")&&r[f].trim();)i.push(Bs(r[f])),f+=1;const C=F.map((fe,te)=>it(fe,`th-${O}-${te}`,!0,g)),G=i.map((fe,te)=>F.map((xe,W)=>it(fe[W]??"",`td-${O}-${te}-${W}`,!0,g)));b.push({key:`table-${O}`,startLine:O+1,endLine:f,interactive:!1,kind:"table",content:fe=>{const te=xe=>!!(fe&&xe>=fe.start&&xe<=fe.end);return e.jsx("div",{className:Fu,"data-markdown-table-scroll":!0,children:e.jsxs("table",{className:"w-max min-w-full max-w-none table-auto border-collapse text-left text-[11px] sm:text-xs",children:[e.jsx("thead",{className:"bg-surface-2 text-foreground",children:e.jsx("tr",{"data-markdown-table-row-line":O+1,"data-md-ref-start":O+1,"data-md-ref-end":O+1,"data-selected":te(O+1)?"true":void 0,children:C.map((xe,W)=>e.jsx("th",{className:`${Iu} ${no(p[W]??null)}`,children:e.jsx("div",{className:eo,children:xe})},`h-${W}`))})}),e.jsx("tbody",{children:G.map((xe,W)=>{const Y=O+W+3;return e.jsx("tr",{className:"border-t border-border/10","data-markdown-table-row-line":Y,"data-md-ref-start":Y,"data-md-ref-end":Y,"data-selected":te(Y)?"true":void 0,children:F.map((L,D)=>e.jsx("td",{className:`${Du} ${no(p[D]??null)}`,children:e.jsx("div",{className:eo,children:xe[D]})},`c-${D}`))},`r-${W}`)})})]})})}});continue}const R=Os(y);if(R){const F=R.ordered,p=uo(y),i=R.start,O=f,C=al(r,f,p,F,!0,h);f=C.nextIndex;const G=F?"ol":"ul",fe=ol(C.items,`list-${O}`,g);b.push({key:`list-${O}`,startLine:O+1,endLine:f,fineGrained:!0,content:te=>e.jsx(G,{start:F?i:void 0,className:`${F?"list-decimal":"list-disc"} space-y-0.5 pl-4 text-muted-foreground marker:text-muted-foreground/70 sm:space-y-1 sm:pl-5`,children:il(fe,te)})});continue}const E=[y.trimStart()],$=[f+1],P=f;for(f+=1;f<r.length&&r[f].trim()&&!Gi(r[f])&&!(f+1<r.length&&r[f].includes("|")&&so(r[f+1]));){if(to(r[f])||h.has(f)){f+=1;continue}E.push(r[f].trimStart()),$.push(f+1),f+=1}const U=Yi(E,`p-${P}`,g);b.push({key:`p-${P}`,startLine:P+1,endLine:f,fineGrained:!0,content:F=>e.jsx("p",{className:"text-muted-foreground",children:Xi(U.perLine,U.hardBreaks,$,`p-${P}`,F)})})}const k=hb(g);return k&&b.push({key:"footnotes",startLine:r.length,endLine:r.length,content:k}),{blocks:b,images:m}}function wb(r,n,s){return ll(r,n,s).blocks}function mf(r,n){const s=[];for(const l of r){if(l.startLine>n)break;if(l.heading){for(;s.length>0&&s[s.length-1].level>=l.heading.level;)s.pop();s.push({...l.heading,startLine:l.startLine})}}return s}function pf(r){return r.filter(n=>!!n.heading).map(n=>({...n.heading,startLine:n.startLine}))}function kb({src:r,alt:n,onZoomChange:s,onDoubleTap:l}){const u=Qu(r);return e.jsx(Ef,{src:u,alt:n,onLoad:()=>{},onError:()=>{},onZoomChange:s,onDoubleTap:l})}function gf({images:r,index:n,onChange:s,onClose:l}){const{t:u}=wt(),c=r[n],h=r.length>1,m=a.useRef(null),g=a.useRef(null),b=a.useRef(null),f=a.useRef(0),[k,y]=a.useState(!1),[N,I]=a.useState(0),[B,_]=a.useState(!1),R=a.useCallback(()=>{b.current!==null&&(window.clearTimeout(b.current),b.current=null)},[]),E=a.useCallback(()=>{k||Date.now()<f.current||(R(),b.current=window.setTimeout(()=>{b.current=null,l()},450))},[R,k,l]),$=a.useCallback(p=>{if(r.length===0)return;const i=(p+r.length)%r.length;m.current?.slideTo(i),s(i)},[r.length,s]),P=a.useCallback(()=>$(n-1),[$,n]),U=a.useCallback(()=>$(n+1),[$,n]);if(a.useEffect(()=>{R(),I(0),_(!1),y(!1)},[R,n]),a.useEffect(()=>{const p=m.current;p&&(p.allowTouchMove=h&&!k)},[h,k]),a.useEffect(()=>{const p=m.current;!p||p.activeIndex===n||p.slideTo(n,0)},[n]),a.useEffect(()=>R,[R]),a.useEffect(()=>{const p=i=>{if(i.key==="Escape"){i.preventDefault(),l();return}h&&(i.key==="ArrowLeft"?(i.preventDefault(),P()):i.key==="ArrowRight"&&(i.preventDefault(),U()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[h,U,P,l]),iu({onDrag:({movement:[p,i],pinching:O})=>{O||k||Math.abs(i)<Math.abs(p)*1.15&&N===0||(_(!0),Math.abs(i)>8&&(f.current=Date.now()+300),I(Math.max(0,i)))},onDragEnd:({movement:[p,i],velocity:[,O],pinching:C,canceled:G})=>{if(_(!1),C||G||k||Math.abs(i)<Math.abs(p)*1.15){I(0);return}if(Math.abs(i)>8&&(f.current=Date.now()+300),uf(i,O)){l();return}I(0)}},{target:g,drag:{filterTaps:!0,pointer:{touch:!0}}}),!c)return null;const F=c.title||c.alt||(c.kind==="mermaid"?u("rightSidebar.mermaidDiagram"):u("rightSidebar.image"));return typeof document>"u"?null:Ir.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:l}),e.jsxs("div",{className:"fixed inset-0 z-modal-panel flex flex-col bg-background-subtle/95 pt-[var(--safe-top-inset,env(safe-area-inset-top,0px))] text-foreground","data-markdown-image-lightbox":!0,"data-sidebar-gesture-ignore":!0,children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center justify-between gap-3 border-b border-border/20 bg-surface/80 px-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:F}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[n+1," / ",r.length]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:P,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.previousImage"),title:u("common.previous"),children:e.jsx(Ts,{size:17})}),e.jsx("button",{type:"button",onClick:U,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":u("rightSidebar.nextImage"),title:u("common.next"),children:e.jsx(Yh,{size:17})})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":u("rightSidebar.closeImagePreview"),title:u("common.close"),children:e.jsx(Kt,{size:18})})]})]}),e.jsx("div",{ref:g,className:"relative min-h-0 flex-1 overflow-hidden","data-markdown-image-lightbox-stage":!0,"data-sidebar-gesture-ignore":!0,onClick:E,children:e.jsx("div",{className:"h-full w-full",style:{transform:`translate3d(0, ${N}px, 0) scale(${Math.max(.86,1-N/900)})`,opacity:Math.max(.35,1-N/360),transition:B?"none":"transform 0.2s ease-out, opacity 0.2s ease-out",willChange:"transform, opacity"},children:e.jsx(lu,{onSwiper:p=>{m.current=p,p.allowTouchMove=h&&!k},onSlideChange:p=>{p.activeIndex!==n&&s(p.activeIndex)},onSliderMove:()=>{R(),f.current=Date.now()+450},initialSlide:n,speed:260,slidesPerView:1,resistanceRatio:.82,threshold:6,longSwipesRatio:.2,touchAngle:45,touchStartPreventDefault:!1,simulateTouch:!1,className:"h-full",children:r.map((p,i)=>e.jsx(Li,{className:"h-full",children:e.jsx("div",{className:"h-full w-full px-3 py-4 sm:px-6 sm:py-6",children:p.kind==="image"?e.jsx(kb,{src:p.src,alt:p.alt||p.title||u("rightSidebar.markdownImage"),onZoomChange:y,onDoubleTap:R}):e.jsx(_b,{svg:p.svg,title:p.title||p.alt||u("rightSidebar.mermaidDiagram"),onZoomChange:y,onDoubleTap:R})})},`${p.kind}-${i}-${p.alt}`))})})})]})]}),document.body)}function bf({content:r,filePath:n,rootPath:s,lineRange:l,onLineRangeClick:u,onLineRangeDrag:c,scrollTop:h,outlineOpen:m,outlineCloseSignal:g,onOutlineOpen:b,onOutlineClose:f,lightboxOpen:k,lightboxCloseSignal:y,onLightboxOpen:N,onLightboxClose:I,onLocalLinkOpen:B}){const{t:_}=wt(),[R,E]=a.useState(null),[$,P]=a.useState(null),[U,F]=a.useState(1),[p,i]=a.useState(null),O=a.useRef(null),C=a.useRef(null),{blocks:G,images:fe}=a.useMemo(()=>ll(r.split(`
1652
+ `),n,s,S=>{P(null),E(S),N?.()},{footnotes:_("rightSidebar.footnotes"),backToFootnote:S=>_("rightSidebar.backToFootnote",{index:S})}),[r,n,s,N,_]),te=a.useMemo(()=>$?[...fe,$]:fe,[fe,$]),xe=a.useCallback(S=>{P({kind:"mermaid",svg:S,alt:"Mermaid diagram",title:"Mermaid diagram"}),E(fe.length),N?.()},[fe.length,N]);a.useEffect(()=>{E(null),P(null)},[r,n]),a.useEffect(()=>{E(null),P(null)},[y]),a.useEffect(()=>{k||(E(null),P(null))},[k]),a.useEffect(()=>{F(1)},[r,n]),a.useLayoutEffect(()=>{const S=O.current;if(!S||G.length===0)return;const Q=Array.from(S.querySelectorAll("[data-markdown-preview-block-start]"));let le=1;const q=28;for(const me of Q)if(me.offsetTop-h<=q)le=Number(me.dataset.markdownPreviewBlockStart)||le;else break;F(me=>me===le?me:le)},[G,h]);const W=a.useMemo(()=>mf(G,U),[U,G]),Y=a.useMemo(()=>pf(G),[G]),L=`${n??""}
1653
+ ${r}`,D=a.useRef(L),K=a.useRef(null),re=a.useRef(null),ce=a.useRef(!1);a.useEffect(()=>{D.current!==L&&(D.current=L,f?.())},[f,L]),a.useEffect(()=>{g!==void 0&&i(null)},[g]),a.useLayoutEffect(()=>{if(!m){i(null);return}const S=()=>{const Q=C.current;if(!Q)return;const le=Q.getBoundingClientRect(),q=window.innerWidth;i({top:le.bottom+6,right:Math.max(8,q-le.right)})};return S(),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0),()=>{window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0)}},[m,h,W]);const ve=a.useCallback(S=>{const Q=O.current,le=Q?.closest("[data-markdown-preview-scroller]"),q=Q?.querySelector(`[data-markdown-preview-block-start="${S.startLine}"]`);if(!le||!q)return;const me=le.getBoundingClientRect(),Ae=q.getBoundingClientRect(),Me=Q?.querySelector("[data-markdown-heading-sticky]")?.getBoundingClientRect().height??0,st=Ae.top-me.top+le.scrollTop;le.scrollTo({top:Math.max(0,st-Me-8),behavior:"smooth"}),F(S.startLine),f?.()},[f]),pe=a.useCallback(S=>{S.pointerType==="mouse"&&S.button!==0||ji(S.target)||(K.current={pointerId:S.pointerId,startX:S.clientX,startY:S.clientY})},[]),Ee=a.useCallback((S,Q,le)=>{const q=K.current;if(K.current=null,!q||q.pointerId!==S.pointerId)return;const me=Math.abs(S.clientX-q.startX),Ae=Math.abs(S.clientY-q.startY);if(me>8||Ae>8)return;const oe=S.target;if(ji(oe)||Pi())return;const Me=eu(oe,Q,le);u(S,Me.start,Me.end)},[u]),M=a.useCallback(S=>{K.current?.pointerId===S.pointerId&&(K.current=null)},[]),Z=a.useCallback((S,Q)=>{const le=O.current;if(!le||typeof document.elementFromPoint!="function")return null;const q=document.elementFromPoint(S,Q);if(!(q instanceof HTMLElement)||!le.contains(q))return null;const me=q.closest("[data-md-ref-start]");if(me){const ke=Number(me.dataset.mdRefStart);if(Number.isFinite(ke)&&ke>0)return ke}const Ae=q.closest("[data-markdown-preview-block-start]");if(!Ae)return null;const oe=Number(Ae.dataset.markdownPreviewBlockStart),Me=G.find(ke=>ke.startLine===oe);if(!Me)return Number.isFinite(oe)&&oe>0?oe:null;if(Me.endLine<=Me.startLine)return Me.startLine;const st=Ae.getBoundingClientRect(),Pe=st.height>0?Math.min(1,Math.max(0,(Q-st.top)/st.height)):0;return Math.round(Me.startLine+Pe*(Me.endLine-Me.startLine))},[G]),he=a.useCallback(S=>{if(!c||S.pointerType==="mouse"&&S.button!==0)return;const Q=Z(S.clientX+24,S.clientY);if(Q!=null){re.current={pointerId:S.pointerId,anchorLine:Q,moved:!1};try{S.currentTarget.setPointerCapture(S.pointerId)}catch{}}},[c,Z]),Ne=a.useCallback(S=>{const Q=re.current;if(!Q||Q.pointerId!==S.pointerId||!c)return;const le=Z(S.clientX+16,S.clientY);le!=null&&(!Q.moved&&le===Q.anchorLine||(Q.moved=!0,ce.current=!0,c(S,Math.min(Q.anchorLine,le),Math.max(Q.anchorLine,le),"move")))},[c,Z]),Ve=a.useCallback(S=>{const Q=re.current;if(re.current=null,!Q||Q.pointerId!==S.pointerId||!c||!Q.moved)return;const le=Z(S.clientX+16,S.clientY)??Q.anchorLine;c(S,Math.min(Q.anchorLine,le),Math.max(Q.anchorLine,le),"end")},[c,Z]),Ce=a.useCallback(S=>{re.current?.pointerId===S.pointerId&&(re.current=null)},[]),Ye={onPointerDown:he,onPointerMove:Ne,onPointerUp:Ve,onPointerCancel:Ce},Ie=()=>ce.current?(ce.current=!1,!0):!1;return G.length===0?e.jsx("div",{className:"min-w-0 max-w-full px-4 py-4 text-sm leading-6 text-foreground",children:e.jsx("p",{className:"text-muted-foreground",children:_("rightSidebar.emptyFile")})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:O,className:"relative min-w-0 max-w-full",onClickCapture:S=>{const Q=S.target instanceof Element?S.target.closest("a[href]"):null;if(!Q||!B)return;const le=Q.getAttribute("href");if(!le)return;const q=rl(le,n,s);q&&(S.preventDefault(),B(q))},children:[W.length>0&&e.jsx("div",{className:"sticky top-0 z-10 border-b border-border/15 bg-surface px-2 py-1 shadow-sm sm:px-3","data-markdown-heading-sticky":!0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-hidden",title:W.map(S=>S.text).join(" / "),children:[e.jsx("span",{className:"h-4 w-0.5 shrink-0 rounded-full bg-primary/70","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold leading-5 text-foreground sm:text-[13px]","data-markdown-heading-current":!0,children:W[W.length-1].text}),Y.length>1&&e.jsxs("button",{ref:C,type:"button",onClick:()=>{m?f?.():b?.()},className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 ${m?"bg-surface-2 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":m,"aria-label":_("rightSidebar.markdownOutline"),title:_("rightSidebar.markdownOutline"),children:[e.jsx(cu,{size:12}),e.jsx("span",{children:_("rightSidebar.markdownOutlineShort")})]})]})}),m&&typeof document<"u"&&Ir.createPortal(e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-menu-backdrop bg-[rgb(var(--background-rgb)_/_0.18)] sm:hidden",onClick:f}),e.jsx("div",{className:"hidden fixed z-menu-panel w-80 max-w-[min(20rem,calc(100vw-2rem))] rounded-lg border border-border/20 bg-surface p-2 shadow-xl sm:block",style:p?{top:`${p.top}px`,right:`${p.right}px`}:{top:-9999,right:-9999},"data-markdown-heading-outline-desktop":!0,children:e.jsx("div",{className:"max-h-72 overflow-auto pr-1",children:Y.map(S=>{const Q=W[W.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>ve(S),className:`flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left transition active:scale-[0.995] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`desktop-${S.id}-${S.startLine}`)})})}),e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[min(74vh,34rem)] rounded-t-xl border border-border/20 bg-surface p-2 pb-[calc(0.5rem+env(safe-area-inset-bottom,0px))] shadow-[0_-18px_48px_var(--app-shadow-strong)] sm:hidden","data-markdown-heading-outline-mobile":!0,children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2 px-1.5 py-1 sm:hidden",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:_("rightSidebar.markdownOutlineShort")}),e.jsx("button",{type:"button",onClick:f,className:"inline-flex h-7 w-7 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":_("rightSidebar.closeMarkdownOutline"),title:_("common.close"),children:e.jsx(Kt,{size:14})})]}),e.jsx("div",{className:"max-h-[calc(min(74vh,34rem)-3.25rem-env(safe-area-inset-bottom,0px))] overflow-auto overscroll-contain pr-1 sm:max-h-72",children:Y.map(S=>{const Q=W[W.length-1]?.startLine===S.startLine;return e.jsxs("button",{type:"button",onClick:()=>ve(S),className:`flex min-h-10 w-full min-w-0 items-center gap-2 rounded-md px-2 py-2 text-left transition active:scale-[0.995] ${Q?"bg-primary/10 text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,style:{paddingLeft:`${Math.min(S.level-1,4)*12+8}px`},title:S.text,children:[e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Q?"bg-primary":"bg-border-strong/70"}`,"aria-hidden":"true"}),e.jsxs("span",{className:"w-5 shrink-0 font-mono text-[9px] text-muted-foreground/70",children:["H",S.level]}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px]",children:S.text})]},`${S.id}-${S.startLine}`)})})]})]}),document.body),e.jsx("div",{className:"min-w-0 max-w-full space-y-1.5 overflow-x-hidden break-words px-1.5 py-3 text-[13px] leading-5 text-foreground sm:space-y-2 sm:px-2 sm:py-4 sm:text-sm sm:leading-6",children:e.jsx(Gu.Provider,{value:xe,children:G.map(S=>{const Q=!!(l&&S.startLine<=l.end&&S.endLine>=l.start),le=!!(l&&l.start<=S.startLine&&l.end>=S.endLine),q=S.kind==="table"?!1:S.fineGrained?le:Q,me=S.kind==="table"&&l?.start===S.startLine&&l.end===S.endLine;let Ae=null;if(S.kind!=="table"&&S.fineGrained&&Q&&!le&&l){const Pe=S.endLine-S.startLine+1,ke=Math.max(l.start,S.startLine),at=Math.min(l.end,S.endLine),et=(ke-S.startLine)/Pe,qt=(at-ke+1)/Pe;Ae=e.jsx("span",{"aria-hidden":"true","data-md-rail-segment":!0,className:"absolute left-1/2 w-0.5 -translate-x-1/2 rounded-full bg-primary transition sm:w-1",style:{top:`calc(0.25rem + (100% - 0.5rem) * ${et})`,height:`calc((100% - 0.5rem) * ${qt})`}})}const oe=typeof S.content=="function"?S.content(l):S.content,Me=S.startLine===S.endLine?String(S.startLine):`${S.startLine}-${S.endLine}`,st=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:wi(q),"aria-hidden":"true",...Ye,children:[e.jsx("span",{className:ki(q)}),Ae]}),e.jsx("div",{className:"min-w-0","data-sidebar-selectable":!0,children:oe})]});return S.interactive===!1?e.jsxs("div",{"data-markdown-preview-block-start":S.startLine,className:`group grid w-full grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${q?"bg-primary/10":""}`,title:`Line ${Me}`,"aria-label":`Line ${Me}`,children:[S.kind==="table"?e.jsx("button",{type:"button",className:wi(me,"self"),onClick:Pe=>{Pe.preventDefault(),!Ie()&&u(Pe,S.startLine,S.endLine)},title:`Reference table lines ${Me}`,"aria-label":`Reference table lines ${Me}`,...Ye,children:e.jsx("span",{className:ki(me,"self")})}):e.jsxs("span",{className:wi(q,"none"),"aria-hidden":"true",...Ye,children:[e.jsx("span",{className:ki(q,"none")}),Ae]}),e.jsx("div",{className:"min-w-0 cursor-text select-text","data-sidebar-selectable":!0,role:"button",tabIndex:0,onPointerDown:pe,onPointerUp:Pe=>Ee(Pe,S.startLine,S.endLine),onPointerCancel:M,onKeyDown:Pe=>{Pe.key!=="Enter"&&Pe.key!==" "||(Pe.preventDefault(),u(Pe,S.startLine,S.endLine))},title:`Reference line ${Me}`,"aria-label":`Reference line ${Me}`,children:oe})]},S.key):e.jsx("div",{role:"button",tabIndex:0,"data-markdown-preview-block-start":S.startLine,onClick:Pe=>{const ke=Pe.target;if(ji(ke)||Pi()||Ie())return;const at=eu(ke,S.startLine,S.endLine);u(Pe,at.start,at.end)},onKeyDown:Pe=>{Pe.key!=="Enter"&&Pe.key!==" "||(Pe.preventDefault(),u(Pe,S.startLine,S.endLine))},className:`group grid w-full cursor-pointer grid-cols-[0.625rem_minmax(0,1fr)] gap-1.5 rounded-md py-0.5 pr-1.5 text-left outline-none transition active:scale-[0.998] sm:grid-cols-[0.875rem_minmax(0,1fr)] sm:gap-2 sm:pr-2 ${q?"bg-primary/10":"hover:bg-[var(--surface-2)]"}`,title:`Reference line ${Me}`,"aria-label":`Reference line ${Me}`,children:st},S.key)})})})]}),k&&R!==null&&te[R]&&e.jsx(gf,{images:te,index:R,onChange:E,onClose:()=>{E(null),P(null),I?.()}})]})}function Xn({label:r,value:n,options:s,placeholder:l,searchPlaceholder:u,emptyText:c,disabled:h,onChange:m}){const{t:g}=wt(),[b,f]=a.useState(!1),[k,y]=a.useState(""),[N,I]=a.useState(null),B=a.useRef(null),_=a.useRef(null),R=k.trim().toLowerCase(),E=a.useMemo(()=>R?s.filter(p=>`${p.label} ${p.meta??""}`.toLowerCase().includes(R)):s,[R,s]),$=s.find(p=>p.value===n),P=()=>{const p=k.trim();p&&(m(p),f(!1),y(""))},U=a.useCallback(()=>{const p=B.current?.getBoundingClientRect();if(!p)return!1;const i=12,O=Math.max(220,Math.min(p.width,window.innerWidth-i*2)),C=Math.min(Math.max(i,p.left),window.innerWidth-O-i),G=window.innerHeight-p.bottom-i,fe=p.top-i,te=G>=180||G>=fe,xe=Math.max(96,(te?G:fe)-4),W=Math.min(320,xe);return I({left:C,top:te?p.bottom+4:Math.max(i,p.top-W-4),width:O,maxHeight:W}),!0},[]),F=()=>{U(),f(!0)};return a.useEffect(()=>{if(!b)return;let p=0;const i=()=>{p||(p=window.requestAnimationFrame(()=>{p=0,U()}))},O=C=>{const G=C.target;G instanceof Node&&(B.current?.contains(G)||_.current?.contains(G)||(f(!1),y("")))};return window.addEventListener("resize",i),window.addEventListener("scroll",i,!0),document.addEventListener("pointerdown",O,!0),()=>{p&&window.cancelAnimationFrame(p),window.removeEventListener("resize",i),window.removeEventListener("scroll",i,!0),document.removeEventListener("pointerdown",O,!0)}},[b,U]),e.jsxs("div",{className:"relative min-w-0",children:[e.jsxs("button",{ref:B,type:"button",disabled:h,onClick:()=>{if(!h){if(y(""),b){f(!1);return}F()}},className:"group flex w-full items-center justify-between gap-2 min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-left transition hover:bg-surface-elevated focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:r}),e.jsx("span",{className:`min-w-0 flex-1 truncate text-[13px] ${n?"text-foreground":"text-muted-foreground/70"}`,children:$?.label??(n||l)})]}),e.jsx(Is,{size:13,className:`shrink-0 text-muted-foreground transition group-hover:text-foreground ${b?"rotate-180":""}`})]}),b&&!h&&typeof document<"u"&&Ir.createPortal(e.jsxs("div",{ref:_,className:"fixed z-popover overflow-hidden rounded-lg border border-border/15 bg-surface shadow-lg",onClick:p=>p.stopPropagation(),style:{left:N?.left??12,top:N?.top??12,width:N?.width??260,maxHeight:N?.maxHeight??320},children:[e.jsx("div",{className:"border-b border-border/10 p-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5",children:[e.jsx(Zn,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsx("input",{autoFocus:!0,value:k,onChange:p=>y(p.target.value),onKeyDown:p=>{if(p.key==="Escape"){p.preventDefault(),f(!1),y("");return}p.key==="Enter"&&(p.preventDefault(),P())},onBlur:()=>{k.trim()&&E.length===0&&P()},placeholder:u,className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground outline-none placeholder:text-muted-foreground/70"})]})}),e.jsxs("div",{className:"overflow-y-auto p-1",style:{maxHeight:Math.max(96,(N?.maxHeight??320)-46)},children:[k.trim()&&!s.some(p=>p.value===k.trim())&&e.jsxs("button",{type:"button",onMouseDown:p=>p.preventDefault(),onClick:P,className:"mb-1 flex w-full items-center justify-between gap-2 rounded-md bg-primary/10 px-2 py-1.5 text-left text-[12px] font-medium text-primary transition hover:bg-primary/15",children:[e.jsx("span",{className:"min-w-0 truncate",children:k.trim()}),e.jsx("span",{className:"shrink-0 text-[10px] text-primary/75",children:g("common.use")})]}),E.length>0?E.map(p=>e.jsxs("button",{type:"button",onClick:()=>{m(p.value),f(!1),y("")},className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-[12px] transition hover:bg-surface-2 ${p.value===n?"bg-accent/10 text-accent":"text-foreground"}`,children:[e.jsx("span",{className:"min-w-0 truncate font-medium",children:p.label}),p.meta&&e.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:p.meta})]},p.value)):e.jsx("div",{className:"px-2 py-2 text-[11px] text-muted-foreground",children:c})]})]}),document.body)]})}function Vd({open:r,onOpenChange:n,showScopePicker:s,selectedAll:l,repos:u,selectedRoots:c,onToggleRepo:h,onGenerate:m,onSecondaryAction:g,disabled:b,generateDisabled:f,secondaryDisabled:k,inserted:y,buttonLabel:N,insertedLabel:I,title:B,ariaLabel:_,scopeTitle:R,scopeLabel:E,allLabel:$,generateLabel:P,secondaryLabel:U,secondaryTitle:F,secondaryLoading:p,loading:i,error:O,statusTitle:C,extraContent:G,renderRepoExtra:fe}){return e.jsxs("div",{className:"relative inline-flex shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>{s?n(!r):f||m()},disabled:b,className:`relative inline-flex h-7 shrink-0 items-center justify-center gap-1 rounded-md px-2 text-[11px] font-medium transition active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 ${O?"text-destructive hover:bg-destructive/5":y?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-label":_,title:C??(s?`${R}: ${E}`:B),children:[i?e.jsx(yt,{size:13,className:"animate-spin"}):e.jsx(Fs,{size:13}),e.jsx("span",{children:y?I:N}),s&&e.jsx(Is,{size:11,className:`shrink-0 transition ${r?"rotate-180":""}`}),O&&e.jsx("span",{className:"absolute right-0.5 top-0.5 size-1.5 rounded-full bg-destructive"})]}),s&&r&&typeof document<"u"&&Ir.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] px-3 py-6 backdrop-blur-sm animate-fade-in",onClick:()=>n(!1),children:e.jsxs("div",{className:"fixed left-1/2 top-1/2 z-modal-panel flex max-h-[min(82vh,36rem)] w-[calc(100vw-1.5rem)] max-w-[42rem] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border/20 bg-surface text-[11px] shadow-2xl",onClick:te=>te.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border/15 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-semibold text-foreground",children:R}),e.jsx("div",{className:"mt-0.5 truncate text-[10px] text-muted-foreground",children:E})]}),e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":"Close",children:e.jsx(Kt,{size:14})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[G,e.jsxs("button",{type:"button",onClick:()=>h(null),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${l?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,children:[e.jsx("span",{className:"truncate",children:$}),l&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),u.map(te=>{const xe=c.includes(te.root);return e.jsxs("div",{className:`mt-1 rounded-md transition ${xe?"bg-primary/15 text-primary":""}`,children:[e.jsxs("button",{type:"button",onClick:()=>h(te.root),className:`flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left font-medium transition ${xe?"text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:te.root,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:te.label}),te.branch&&e.jsx("span",{className:"block truncate text-[9px] opacity-70",children:te.branch})]}),xe&&e.jsx("span",{className:"text-[10px]",children:"✓"})]}),fe&&(l||xe)&&e.jsx("div",{className:"px-2 pb-2",children:fe(te)})]},te.root)})]}),e.jsxs("div",{className:`grid grid-cols-1 gap-1.5 border-t border-border/15 p-2 ${g&&U?"sm:grid-cols-2":""}`,children:[g&&U&&e.jsxs("button",{type:"button",onClick:()=>{k||(n(!1),g())},disabled:k,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-surface-2 px-2 text-[11px] font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:F,children:[p?e.jsx(yt,{size:12,className:"animate-spin"}):e.jsx(xu,{size:12}),U]}),e.jsxs("button",{type:"button",onClick:()=>{f||(n(!1),m())},disabled:f,className:"flex h-7 w-full items-center justify-center gap-1 rounded-md bg-primary/15 px-2 text-[11px] font-semibold text-primary transition hover:bg-primary/25 disabled:cursor-not-allowed disabled:opacity-50 active:scale-95",title:B,children:[e.jsx(Fs,{size:12}),P]})]})]})}),document.body)]})}function Sb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function xf(){return ut(Qi,Sb)??{}}function jb(r,n){const s=xf(),l=Object.entries({...s,[r]:{top:n,updatedAt:Date.now()}}).sort(([,u],[,c])=>c.updatedAt-u.updatedAt).slice(0,vg);$s(Qi,Object.fromEntries(l),wg)}function Rb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r;return typeof n.start=="number"&&Number.isFinite(n.start)&&typeof n.end=="number"&&Number.isFinite(n.end)&&n.start>=1&&n.end>=n.start}function Cb(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;for(const n of Object.values(r)){if(!n||typeof n!="object"||Array.isArray(n))return!1;const s=n;if(typeof s.top!="number"||!Number.isFinite(s.top)||s.left!==void 0&&(typeof s.left!="number"||!Number.isFinite(s.left))||s.markdownTop!==void 0&&(typeof s.markdownTop!="number"||!Number.isFinite(s.markdownTop))||s.lineRange!==void 0&&s.lineRange!==null&&!Rb(s.lineRange)||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt))return!1}return!0}function cl(r,n){if(!n)return null;const s=r&&!n.startsWith("/")?`${r}/${n}`:n;return r?`${r}::${s}`:s}function vf(){return ut(el,Cb)??{}}function Yd(r,n){const s=cl(r,n);return s?vf()[s]??null:null}function xi(r,n,s){const l=cl(r,n);if(!l)return;const u=vf(),c=u[l]??{top:0,left:0,markdownTop:0,lineRange:null,updatedAt:Date.now()},h=Object.entries({...u,[l]:{...c,...s,updatedAt:Date.now()}}).sort(([,m],[,g])=>g.updatedAt-m.updatedAt).slice(0,yg);$s(el,Object.fromEntries(h),kg)}function Ka({active:r,mounted:n=!0,fallback:s=null,children:l}){return e.jsx("div",{className:`h-full min-h-0 overflow-hidden bg-surface text-foreground ${r?"block":"hidden"}`,"aria-hidden":!r,children:n?typeof l=="function"?l():l:s})}function vi({slow:r}){return e.jsx(Tm,{slow:r})}function qa({message:r,onRetry:n}){const{t:s}=wt();return e.jsxs("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-destructive/20 bg-destructive/5 px-4 py-5 text-center text-sm text-destructive",children:[e.jsx("div",{className:"font-medium",children:s("rightSidebar.gitChangesLoadFailed")}),e.jsx("div",{className:"mt-1 break-words text-xs opacity-85",children:r}),e.jsx("button",{type:"button",onClick:n,className:"mt-3 rounded-full bg-destructive/10 px-3 py-1.5 text-xs font-semibold text-destructive transition hover:bg-destructive/15 active:scale-95",children:s("rightSidebar.retryGitChanges")})]})}function Za(r,n){const s=n&&r.startsWith(`${n}/`)?r.slice(n.length+1):r,l=s.split("/").filter(Boolean);return{name:l.pop()||s,dir:l.join("/")}}function vt(r){if(!r)return"";const n=r.replace(/\/+$/,"");return n.split("/").pop()||n||"/"}function yi(r){if(!r)return null;const n=r.replace(/\/+$/,"")||"/";if(n==="/")return null;const s=n.slice(0,n.lastIndexOf("/"))||"/";return s===n?null:s}function Nb(r,n,s){return Ti(r,n,s)}function wi(r,n="group"){return`relative flex min-h-5 w-full touch-none select-none items-stretch justify-center rounded transition sm:min-h-6 ${r?"bg-primary/20":`bg-[var(--surface-2)] ${n==="group"?"group-hover:bg-[var(--surface-elevated)]":n==="self"?"hover:bg-[var(--surface-elevated)]":""}`}`}function ki(r,n="group"){return`my-1 w-0.5 rounded-full transition sm:w-1 ${r?"bg-primary":`bg-[var(--border-strong)] ${n==="group"?"group-hover:bg-[var(--muted-foreground)]":n==="self"?"hover:bg-[var(--muted-foreground)]":""}`}`}function yf(r){const n=new Map;for(const s of r)n.set(dl(s),s);return n}function wf(r,n){const s=new Map(r);for(const l of n)s.set(dl(l),l);return s}function Xd(r,n){let s=0;for(const l of r){const u=mt(l,n);u&&n&&u!==n&&(s+=1)}return s}function Eb(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Mb(r,n){return Array.from(wf(yf(r),n).values()).sort((s,l)=>s.path.localeCompare(l.path))}function $b(r,n){const s=r.relativeRoot==="."?vt(n??r.root)||r.name||r.root:r.relativeRoot||r.name||vt(r.root)||r.root;return{root:r.root,label:s,branch:r.context?.branch??null,count:r.files.length,staged:Eb(r.files)}}function kf(r,n){const s=vt(n??"")||n||"";return r.map(l=>$b(l,n)).sort((l,u)=>s&&l.label===s?-1:s&&u.label===s?1:l.label.localeCompare(u.label))}function Sf(r,n,s,l,u){const c=Bu(s),h=c.find(B=>B.root===l)??c[0]??null,m=n.find(B=>B.root===l)??null,g=m?.relativeRoot??h?.relativeRoot??".",b=m?.name??h?.name??(vt(l)||l),f=(h?.files??s.files).map(B=>({...B,repoRoot:l,repoRelativeRoot:g,repoName:b})),k=h?.context??s.context,y={...m??h??{id:l,root:l,relativeRoot:g,name:b,depth:0,nested:!!(u&&l!==u),available:s.available,files:[],context:null},...h??{},id:m?.id??h?.id??l,root:l,displayRoot:m?.displayRoot??h?.displayRoot,relativeRoot:g,name:b,depth:m?.depth??h?.depth??0,nested:m?.nested??h?.nested??!!(u&&l!==u),available:h?.available??s.available,deferred:h?.deferred??!1,files:f,context:k?{...k,root:l,changedFiles:f.map(B=>({path:B.path,absolutePath:B.absolutePath,status:B.status}))}:null,untrackedDeferred:h?.untrackedDeferred??s.untrackedDeferred,error:h?.error??s.error},N=m?n.map(B=>B.root===l?y:B):[...n,y];return{files:Array.from(r).filter(B=>mt(B,u)!==l).concat(f),repositories:N,repoFilters:kf(N,u)}}function mt(r,n){return r.repoRoot??n}function dl(r){return`${r.repoRoot??""}\0${r.path}`}function xt(r){return r.absolutePath||r.path}function Si(r){return dl(r)}function Lb(r){return r.repoRelativeRoot&&r.repoRelativeRoot!=="."?r.repoRelativeRoot:r.repoName??""}function Jd(r){return r.reduce((n,s)=>n+(s.staged?1:0),0)}function Zd(r){const n={added:0,modified:0,deleted:0,renamed:0,copied:0,untracked:0,conflicted:0,staged:0,other:0};for(const s of r)s.status==="added"?n.added+=1:s.status==="modified"?n.modified+=1:s.status==="deleted"?n.deleted+=1:s.status==="renamed"?n.renamed+=1:s.status==="copied"?n.copied+=1:s.status==="untracked"?n.untracked+=1:s.status==="conflicted"?n.conflicted+=1:n.other+=1,s.staged&&(n.staged+=1);return n}function Jn(r){let n=0;const s=r??"root";for(let l=0;l<s.length;l+=1)n=Math.imul(n^s.charCodeAt(l),16777619);return`right-sidebar-git-bundle:${(n>>>0).toString(36)}`}function Cs(r,n){return typeof r!="number"||!Number.isFinite(r)||r<=0?null:new Intl.DateTimeFormat(n==="zh"?"zh-CN":"en",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r))}function Pr(r){return r instanceof DOMException&&r.name==="AbortError"}function Ab(r){const n=r.error??r.context?.error??"";return n.includes("request was cancelled")||n.includes("IO_REQUEST_CANCELLED")}function Qd(r){return r?.available===!1&&r.code==="NOT_GIT_REPOSITORY"}function ji(r){return r instanceof HTMLElement&&!!r.closest('a, button, input, textarea, select, label, [contenteditable="true"]')}function eu(r,n,s){const l=r instanceof HTMLElement?r.closest("[data-md-ref-start]"):null,u=Number(l?.dataset.mdRefStart),c=Number(l?.dataset.mdRefEnd??l?.dataset.mdRefStart);return Number.isFinite(u)&&u>0&&Number.isFinite(c)&&c>0?{start:Math.min(u,c),end:Math.max(u,c)}:{start:n,end:s}}function Pb({actions:r,running:n,completed:s}){const{t:l}=wt(),[u,c]=a.useState(!1),h=a.useRef(null),m=r.find(b=>n?.action===b.key),g=r.find(b=>s?.action===b.key);return r.length===0?null:(a.useEffect(()=>{if(!u)return;const b=k=>{const y=k.target;y instanceof Node&&h.current?.contains(y)||c(!1)},f=k=>{k.key==="Escape"&&c(!1)};return document.addEventListener("pointerdown",b),document.addEventListener("keydown",f),()=>{document.removeEventListener("pointerdown",b),document.removeEventListener("keydown",f)}},[u]),e.jsxs("div",{ref:h,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),c(f=>!f)},disabled:r.every(b=>b.disabled)&&!n&&!s,className:`inline-flex h-6 min-w-6 shrink-0 items-center justify-center rounded-md transition active:scale-95 disabled:opacity-50 ${u?"bg-surface-elevated text-foreground":g?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:m?.label??g?.label??l("rightSidebar.gitQuickActions"),children:m?e.jsx(yt,{size:13,className:"animate-spin"}):g?e.jsx("span",{className:"text-[12px] font-semibold",children:"✓"}):e.jsx(Mi,{size:14})}),u&&e.jsx("div",{className:"absolute right-0 top-[calc(100%+2px)] z-30 w-44 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:r.map(b=>{const f=n?.action===b.key,k=s?.action===b.key;return e.jsxs("button",{type:"button",onClick:y=>{y.stopPropagation(),b.onClick(),c(!1)},disabled:b.disabled||!!n,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition active:scale-[0.99] disabled:opacity-50 ${k?"bg-accent/10 text-accent":b.destructive?"text-destructive hover:bg-destructive/10":"text-foreground hover:bg-surface-2"}`,children:[e.jsx("span",{className:"flex h-4 w-4 shrink-0 items-center justify-center",children:f?e.jsx(yt,{size:13,className:"animate-spin"}):k?"✓":null}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:b.label})]},b.key)})})]}))}function Tb(r){const n=window.getComputedStyle(r).overflowY;return(n==="auto"||n==="scroll")&&r.scrollHeight>r.clientHeight+1}function jf(r){let n=r;for(;n;){if(n.classList.contains("termdock-diff-stream-scroller")&&Tb(n))return n;n=n.parentElement}return r.closest(".termdock-diff-stream-scroller")}function Qn(r){return r.getClientRects().length>0&&window.getComputedStyle(r).visibility!=="hidden"}const Ri=new WeakMap;function oo(r){const n=Ri.get(r);n!==void 0&&window.clearTimeout(n),r.classList.remove("diff-walkthrough-target"),r.offsetWidth,r.classList.add("diff-walkthrough-target");const s=window.setTimeout(()=>{r.classList.remove("diff-walkthrough-target"),Ri.delete(r)},1700);Ri.set(r,s)}function Ib(r){const n=CSS.escape(r),s=[`[data-diff-stream-item="${n}"]`,`[data-diff-selection-path="${n}"]`,`[data-diff-absolute-path="${n}"]`].join(","),l=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let u=null;for(const m of l){if(!Qn(m))continue;const g=m.querySelector(s);if(g&&Qn(g)){u=g;break}}if(u??=Array.from(document.querySelectorAll(s)).find(Qn)??null,!u)return;const c=jf(u);if(!c){u.scrollIntoView({block:"start",behavior:"smooth"}),oo(u);return}const h=u.getBoundingClientRect().top-c.getBoundingClientRect().top+c.scrollTop;c.scrollTo({top:Math.max(0,h),behavior:"instant"}),oo(u)}function kn(r){const n=CSS.escape(r.filePath),s=typeof r.sectionIndex=="number"?String(r.sectionIndex):null,l=typeof r.hunkIndex=="number"?String(r.hunkIndex):null,u=r.sectionFingerprint?CSS.escape(r.sectionFingerprint):null,c=r.hunkFingerprint?CSS.escape(r.hunkFingerprint):null,h=[s!==null&&u?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null&&u?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"][data-diff-section-fingerprint="${u}"]`:null,s!==null?`[data-diff-section-audit="${n}"][data-diff-section-index="${s}"]`:null,s!==null?`[data-diff-section-anchor="${n}"][data-diff-section-index="${s}"]`:null,l!==null&&c?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"][data-diff-hunk-fingerprint="${c}"]`:null,l!==null?`[data-diff-hunk-anchor="${n}"][data-diff-hunk-index="${l}"]`:null,`[data-diff-file-path="${n}"]`].filter(I=>!!I),m=Array.from(document.querySelectorAll(".termdock-diff-stream-scroller"));let g=null;for(const I of m)if(Qn(I)){for(const B of h){const _=I.querySelector(B);if(_&&Qn(_)){g=_;break}}if(g)break}if(g??=h.flatMap(I=>Array.from(document.querySelectorAll(I))).find(Qn)??null,!g){Ib(r.filePath);return}const b=jf(g);if(!b){g.scrollIntoView({block:"center",behavior:"smooth"}),oo(g);return}const f=g.getBoundingClientRect(),k=b.getBoundingClientRect(),N=f.top-k.top+b.scrollTop-Math.max(24,(b.clientHeight-f.height)/2);b.scrollTo({top:Math.max(0,N),behavior:"instant"}),oo(g)}const Rf=1,Cf=8;function Db(r){return Math.min(Cf,Math.max(Rf,r))}function Nf({resetKey:r,onZoomChange:n,onDoubleTap:s,children:l}){const u=a.useRef(null),[c,h]=a.useState({scale:1,x:0,y:0}),[m,g]=a.useState(!1),b=a.useRef(null),f=a.useRef(new Set),k=a.useRef(!1),y=a.useRef(null),N=a.useRef(0),I=a.useRef(c);I.current=c,a.useEffect(()=>{h({scale:1,x:0,y:0})},[r]);const B=a.useCallback(($,P,U)=>{const F=u.current;if(!F)return{x:P,y:U};const p=F.firstElementChild instanceof HTMLElement?F.firstElementChild:null,i=p?.clientWidth||F.clientWidth,O=p?.clientHeight||F.clientHeight,C=Math.max(0,(i*$-F.clientWidth)/2),G=Math.max(0,(O*$-F.clientHeight)/2);return{x:Math.min(C,Math.max(-C,P)),y:Math.min(G,Math.max(-G,U))}},[]),_=a.useCallback(($,P,U)=>{h(F=>{const p=Db($),i=u.current;if(!i||p===1)return{scale:p,x:0,y:0};const O=i.getBoundingClientRect(),C=(P??O.left+O.width/2)-O.left-O.width/2,G=(U??O.top+O.height/2)-O.top-O.height/2,fe=p/F.scale,te=C-(C-F.x)*fe,xe=G-(G-F.y)*fe;return{scale:p,...B(p,te,xe)}})},[B]),R=a.useCallback(($,P)=>{g(!0),I.current.scale>1?h({scale:1,x:0,y:0}):_(2.5,$,P),window.setTimeout(()=>g(!1),220)},[_]);a.useEffect(()=>{const $=u.current;if(!$)return;const P=p=>{if(p.pointerType==="mouse"&&p.button!==0)return;const i=f.current.size===0;if(f.current.add(p.pointerId),i){const O=Date.now(),C=y.current;if(C&&O-C.time<350&&Math.hypot(p.clientX-C.x,p.clientY-C.y)<24){y.current=null,N.current=O,s?.(),R(p.clientX,p.clientY);return}}if(f.current.size>1){k.current=!0,b.current=null;return}if(!(I.current.scale<=1)){p.preventDefault(),b.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,originX:I.current.x,originY:I.current.y,moved:!1};try{$.setPointerCapture?.(p.pointerId)}catch{}g(!1)}},U=p=>{const i=b.current;if(!i||i.pointerId!==p.pointerId)return;const O=p.clientX-i.startX,C=p.clientY-i.startY;if(!i.moved){if(Math.hypot(O,C)<6)return;i.moved=!0}p.stopPropagation(),p.preventDefault(),h(G=>({...G,...B(G.scale,i.originX+O,i.originY+C)}))},F=p=>{const i=b.current,O=i?.pointerId===p.pointerId&&i.moved;if(i?.pointerId===p.pointerId){i.moved&&p.stopPropagation(),b.current=null;try{$.releasePointerCapture?.(p.pointerId)}catch{}}f.current.delete(p.pointerId)&&f.current.size===0&&(!k.current&&!O&&(y.current={time:Date.now(),x:p.clientX,y:p.clientY}),k.current=!1)};return $.addEventListener("pointerdown",P,{capture:!0,passive:!1}),window.addEventListener("pointermove",U,{capture:!0,passive:!1}),window.addEventListener("pointerup",F,{capture:!0}),window.addEventListener("pointercancel",F,{capture:!0}),()=>{$.removeEventListener("pointerdown",P,{capture:!0}),window.removeEventListener("pointermove",U,{capture:!0}),window.removeEventListener("pointerup",F,{capture:!0}),window.removeEventListener("pointercancel",F,{capture:!0})}},[B,s,R]),iu({onPinch:({offset:[$],origin:[P,U]})=>{g(!1),_($,P,U)},onWheel:({event:$,delta:[P,U],ctrlKey:F})=>{if(F){$.preventDefault(),$.stopPropagation(),g(!1),_(I.current.scale*(1-U*.01),$.clientX,$.clientY);return}I.current.scale<=1||($.preventDefault(),$.stopPropagation(),g(!1),h(p=>({...p,...B(p.scale,p.x-P,p.y-U)})))}},{target:u,eventOptions:{passive:!1},pinch:{scaleBounds:{min:Rf,max:Cf},from:()=>[I.current.scale,0],rubberband:!0}});const E=c.scale>1;return a.useEffect(()=>{n?.(E)},[n,E]),e.jsx("div",{ref:u,"data-sidebar-gesture-ignore":E?"":void 0,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden",style:{cursor:E?"grab":"zoom-in"},onDoubleClick:$=>{$.stopPropagation(),!(Date.now()-N.current<500)&&(s?.(),R($.clientX,$.clientY))},children:l({scale:c.scale,zoomed:E,animateTransform:m,transformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0) scale(${c.scale})`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none",willChange:"transform"},vectorTransformStyle:{transform:`translate3d(${c.x}px, ${c.y}px, 0)`,transformOrigin:"center center",transition:m?"transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}})})}function Ef({src:r,alt:n,vector:s,onLoad:l,onError:u,onZoomChange:c,onDoubleTap:h}){const m=io(r,u),[g,b]=a.useState(null),f=s??co(r);return a.useEffect(()=>{b(null)},[r]),e.jsx(Nf,{resetKey:r,onZoomChange:c,onDoubleTap:h,children:({transformStyle:k,vectorTransformStyle:y,scale:N,animateTransform:I})=>{const B=e.jsx("img",{src:m,alt:n,draggable:!1,className:"max-h-full max-w-full touch-none select-none rounded border border-border/15 bg-surface object-contain shadow-sm",style:f&&g?{position:"absolute",left:"50%",top:"50%",width:g.width*N,height:g.height*N,maxWidth:"none",maxHeight:"none",transform:"translate3d(-50%, -50%, 0)",transition:I?"width 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), height 0.22s cubic-bezier(0.2, 0.8, 0.2, 1)":"none"}:g?{...k,width:g.width,height:g.height}:f?y:k,onLoad:_=>{const R=_.currentTarget,E=R.parentElement;if(E&&R.naturalWidth>0&&R.naturalHeight>0){const $=Math.max(1,E.clientWidth-2),P=Math.max(1,E.clientHeight-2),U=Math.min($/R.naturalWidth,P/R.naturalHeight),F=f?U:Math.min(U,1);b({width:Math.max(1,Math.round(R.naturalWidth*F)),height:Math.max(1,Math.round(R.naturalHeight*F))})}l(_)},onError:u});return!f||!g?B:e.jsx("div",{"data-vector-zoom-surface":!0,className:"relative shrink-0 touch-none select-none",style:{...y,width:g.width,height:g.height},children:B})}})}function Fb({svg:r,title:n,scale:s,vectorTransformStyle:l}){const u=a.useRef(null);return a.useLayoutEffect(()=>{const c=u.current,h=c?.querySelector("svg");if(!c||!h)return;const m=()=>{const f=h.getAttribute("viewBox")?.trim().split(/[\s,]+/).map(Number)??[];let k=f[2],y=f[3];if((!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)&&(k=Number(h.getAttribute("width")),y=Number(h.getAttribute("height"))),!Number.isFinite(k)||!Number.isFinite(y)||k<=0||y<=0)return;const N=Math.max(1,c.clientWidth-24),I=Math.max(1,c.clientHeight-24),B=Math.min(N/k,I/y,1);h.style.width=`${Math.max(1,Math.floor(k*B*s))}px`,h.style.height=`${Math.max(1,Math.floor(y*B*s))}px`,h.style.maxWidth="none",h.style.maxHeight="none",h.style.transform=String(l.transform??""),h.style.transformOrigin="center center",h.style.transition=String(l.transition??"none")};m();const g=typeof ResizeObserver>"u"?null:new ResizeObserver(m);return g?.observe(c),()=>g?.disconnect()},[s,r,l]),e.jsx("div",{ref:u,role:"img","aria-label":n,className:"flex h-full w-full touch-none select-none items-center justify-center overflow-hidden rounded border border-border/15 bg-white p-3 text-slate-900 shadow-sm [&_svg]:block",dangerouslySetInnerHTML:{__html:r}})}function _b({svg:r,title:n,onZoomChange:s,onDoubleTap:l}){return e.jsx(Nf,{resetKey:r,onZoomChange:s,onDoubleTap:l,children:({vectorTransformStyle:u,scale:c})=>e.jsx(Fb,{svg:r,title:n,scale:c,vectorTransformStyle:u})})}let Bb=0,Ob=0,Ub=0,Hb=0,zb=0;function Ci(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="still_active"?"warn":"info",message:`FILE_PREVIEW_LOADING ${r}`,data:{ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function nt(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:r==="error"||r==="empty_bundle"?"warn":"info",message:`GIT_BUNDLE ${r}`,data:{seq:++Ob,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Va(r,n={}){if(typeof window>"u")return;const s=JSON.stringify({level:"info",message:`DIFF_INTERACTION ${r}`,data:{seq:++Hb,ts:Date.now(),...n}});fetch("/api/client-log",{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0}).catch(()=>{})}function Wb(){return`diff-ui-${Date.now().toString(36)}-${(++zb).toString(36)}`}function Gb(r){return r instanceof Element?r.closest("[data-diff-selection-path]"):null}function Kb(r){const n=r.target instanceof HTMLElement?r.target:null;return{eventType:r.type,button:r.button,pointerType:r instanceof globalThis.PointerEvent?r.pointerType:void 0,targetTag:n?.tagName,targetClass:n?.className,targetText:n?.textContent?.slice(0,80)}}function Ji({onReviewReference:r,filePath:n,onInsertReference:s,onInsertText:l,onInsertFeature:u,onReferenceCopied:c,onClose:h,onDirectoryLinkOpen:m,isMobile:g,markdownOutlineOpen:b,markdownOutlineCloseSignal:f,onOpenMarkdownOutline:k,onCloseMarkdownOutline:y,markdownImageLightboxOpen:N,markdownImageLightboxCloseSignal:I,onOpenMarkdownImageLightbox:B,onCloseMarkdownImageLightbox:_,lineRange:R,onLineRangeChange:E,insertedReferenceKey:$,copiedReferenceKey:P,scrollToLine:U,onScrollToLineHandled:F}){const{t:p}=wt(),i=J(T=>T.rootPath),O=J(T=>T.selectFile),[C,G]=a.useState({kind:"idle"}),[fe,te]=a.useState("schematic"),[xe,W]=a.useState(null),Y=a.useRef(null),[L,D]=a.useState(null),K=a.useRef(new Map),re=a.useRef(null),[ce,ve]=a.useState(null),[pe,Ee]=a.useState(()=>Fd()),[M,Z]=a.useState(()=>jd(i,n)),he=a.useRef(null),[Ne,Ve]=a.useState(!1),[Ce,Ye]=a.useState(null),[Ie,S]=a.useState(0),[Q,le]=a.useState([]),[q,me]=a.useState(null),Ae=a.useRef(null),oe=a.useRef(n),[Me,st]=a.useState(null),[Pe,ke]=a.useState({status:"idle"}),[at,et]=a.useState(!1),[qt,lt]=a.useState(""),[ct,Dr]=a.useState([]),[Ft,H]=a.useState(0),se=a.useRef(null),be=bu(c),We=cl(i,n);a.useEffect(()=>{if(oe.current===n)return;oe.current=n;const T=n&&i&&!n.startsWith("/")?`${i}/${n}`:n;if(Ae.current===T){Ae.current=null;return}Ae.current=null,le([]),me(null),et(!1),lt("")},[n,i]);const ft=n?i&&!n.startsWith("/")?`${i}/${n}`:n:null,dr=J(T=>ft?(T.fileChangeVersions.get(ft)??0)+T.fileWatchEpoch:T.fileWatchEpoch),ur=a.useRef(null),_t=a.useRef(null),[fr,hr]=a.useState(0),Sn=a.useCallback(()=>hr(T=>T+1),[]);a.useEffect(()=>{const T=Y.current;return Y.current=null,W(null),T&&URL.revokeObjectURL(T.objectUrl),()=>{const z=Y.current;Y.current=null,z&&URL.revokeObjectURL(z.objectUrl)}},[ft,dr,fr]),a.useEffect(()=>{if(!n){ur.current=null,G({kind:"idle"});return}const T=i&&!n.startsWith("/")?`${i}/${n}`:n,z=new AbortController,ae=++Bb,Se=`right-sidebar-file-preview:${ae}`,He=performance.now();let Fe=!1;const Oe=(X,ze={})=>{Fe||(Fe=!0,Ci("end",{loadingId:ae,reason:X,durationMs:Math.round(performance.now()-He),filePath:n,fullPath:T,rootPath:i,...ze}))};let Ge=null;const tt=Fh(T),Ct=tt?T.toLowerCase().endsWith(".kicad_pcb")?fe==="schematic"?"pcb-front":fe:"schematic":fe,rr=!tt&&Zi(T),Xt=!tt&&!rr&&_h(T),En=!tt&&!rr&&!Xt&&ru(T),os=Rs(T),on=Ss(T),zr=tt?"eda":rr?"image":Xt?"model3d":En?"video":"text",Sr=ur.current!==T;if(ur.current=T,Sr){Ci("start",{loadingId:ae,filePath:n,fullPath:T,rootPath:i,mode:zr,externalVersion:dr}),ke({status:"idle"}),G({kind:"loading",mode:zr}),_t.current=null;const X=Yd(i,n);E(X?.lineRange??null),Ee(os?Fd():"source"),Z(on?jd(i,n):"source"),tt&&te(Bh(T))}Sr||G(X=>X.kind==="error"?{kind:"loading",mode:zr}:X);const ho=window.setTimeout(()=>{Fe||z.signal.aborted||Ci("still_active",{loadingId:ae,filePath:n,fullPath:T,rootPath:i,mode:zr,durationMs:Math.round(performance.now()-He),isPathChange:Sr})},3e3),ln=window.setTimeout(()=>{if(Fe||z.signal.aborted)return;const X=tt?p("rightSidebar.edaTimeout"):Xt?p("rightSidebar.model3dTimeout"):"File preview timed out. Try the file again or refresh the directory.";z.abort(new DOMException(X,"TimeoutError")),G({kind:"error",message:X}),Oe("stuck_timeout",{error:X})},tt?Oh+5e3:Xt?Uh+5e3:Hh(T)?35e3:Mg);if(tt){const X=Ct==="pcb-3d"?Y.current:null;X?(G(X),Oe("eda_3d_client_cache_hit",{bytes:X.meta.size,view:X.view,mimeType:X.meta.mimeType})):zh(T,Ct,z.signal,"view_file",Se).then(ze=>{if(z.signal.aborted)return;Ge=URL.createObjectURL(ze.blob);const Pt={kind:"eda",sourcePath:ze.path||T,objectUrl:Ge,view:ze.view,meta:{size:ze.size,mimeType:ze.mimeType,modified:ze.modified}};if(ze.view==="pcb-3d"){const Wr=Y.current;Wr&&Wr.objectUrl!==Ge&&URL.revokeObjectURL(Wr.objectUrl),Y.current=Pt,W(Pt),Ge=null}G(Pt),Oe("eda_loaded",{bytes:ze.size,view:ze.view,mimeType:ze.mimeType})}).catch(ze=>{z.signal.aborted||(G({kind:"error",message:ze instanceof Error&&/timed out/i.test(ze.message)?p("rightSidebar.edaTimeout"):ze instanceof Error?ze.message:p("rightSidebar.edaLoadFailed")}),Oe("error",{error:ze instanceof Error?ze.message:String(ze)}))})}else if(rr)Wh(T,z.signal,"view_file",Se).then(X=>{Ge=URL.createObjectURL(X.blob),G({kind:"image",objectUrl:Ge,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Oe("image_loaded",{bytes:X.size,mimeType:X.mimeType})}).catch(X=>{z.signal.aborted||(G({kind:"error",message:X instanceof Error?X.message:p("rightSidebar.imageLoadFailed")}),Oe("error",{error:X instanceof Error?X.message:String(X)}))});else if(Xt)Gh(T,z.signal,"view_file",Se).then(X=>{z.signal.aborted||(Ge=URL.createObjectURL(X.blob),G({kind:"model3d",sourcePath:X.path||T,objectUrl:Ge,ext:X.ext,meta:{size:X.size,mimeType:X.mimeType,modified:X.modified}}),Oe("model3d_loaded",{bytes:X.size,ext:X.ext}))}).catch(X=>{z.signal.aborted||(G({kind:"error",message:X instanceof Error&&(X.name==="TimeoutError"||/timed out/i.test(X.message))?p("rightSidebar.model3dTimeout"):X instanceof Error?X.message:p("rightSidebar.model3dLoadFailed")}),Oe("error",{error:X instanceof Error?X.message:String(X)}))});else if(En){const X=Kh(T)??"",ze=nu(T);G(Pt=>Pt.kind==="video"&&Pt.url===ze?Pt:{kind:"video",url:ze,meta:{size:null,mimeType:X,modified:null}}),Oe("video_ready",{mimeType:X})}else td(T,z.signal,"view_file",Se).then(X=>{if(!z.signal.aborted){if(X.binary){G({kind:"binary"});return}G({kind:"text",content:X.content,sourcePath:X.path||T,meta:{size:X.size,truncated:X.truncated}}),Oe("text_loaded",{bytes:X.size,truncated:!!X.truncated})}}).catch(X=>{z.signal.aborted||(G({kind:"error",message:X instanceof Error?X.message:"Failed to read file"}),Oe("error",{error:X instanceof Error?X.message:String(X)}))});return()=>{z.abort(),jt(Se),window.clearTimeout(ho),window.clearTimeout(ln),Ge&&URL.revokeObjectURL(Ge),Oe("cleanup")}},[n,i,dr,fr,E,p,fe]),a.useEffect(()=>{if(C.kind!=="model3d"||!n){D(null);return}let T=!1;const z=n.lastIndexOf("/"),ae=z>=0?n.slice(z+1):n,Se=z>=0?n.slice(0,z):"",He=Se.lastIndexOf("/"),Fe=He>=0?Se.slice(0,He):"",Oe=ae.replace(/\.(stl|glb|gltf)$/i,""),Ge=`${Fe?`${Fe}/`:""}features/${Oe}.json`;return td(Ge).then(tt=>{if(!T)try{const Ct=JSON.parse(tt.content);D(Ct.version===1&&Array.isArray(Ct.features)&&Ct.features.length>0?Ct.features:null)}catch{D(null)}}).catch(()=>{T||D(null)}),()=>{T=!0}},[C,n]),a.useEffect(()=>{if(C.kind!=="text"){st(null);return}const T=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=hu(T),ae=C.content,Se=Rs(T??"")&&pe==="preview",He=Ss(T??"")&&M==="preview";if(!z||Se||He||!mu(ae)){st(null);return}let Fe=!1;const Oe=Ge=>{if(Fe||!Ge.registered(z)){Fe||st(null);return}try{st(gu(Ge,ae,z))}catch{st(null)}};return Ce?Oe(Ce):(st(null),pu().then(Ge=>{Fe||(Ye(Ge),Oe(Ge))}).catch(()=>{})),()=>{Fe=!0}},[C,Ce,n,i,pe,M]),a.useLayoutEffect(()=>{if(!We||C.kind!=="text")return;const T=`${We}:${pe}:${M}`;if(_t.current===T)return;const z=Yd(i,n);if(_t.current=T,!z)return;const ae=requestAnimationFrame(()=>{const Se=re.current;if(!Se)return;const He=pe==="preview"?z.markdownTop??z.top:z.top;Se.scrollTo({top:Math.max(0,He??0),left:Math.max(0,z.left??0)}),S(pe==="preview"?Math.max(0,He??0):0)});return()=>cancelAnimationFrame(ae)},[n,pe,M,C.kind,We,i]),a.useEffect(()=>{We&&xi(i,n,{lineRange:R})},[n,R,We,i]),a.useEffect(()=>{if(U==null||C.kind!=="text")return;ve(null),E({start:U,end:U});const T=U,z=requestAnimationFrame(()=>{const ae=K.current.get(T);ae&&ae.scrollIntoView({block:"center"}),F?.()});return()=>cancelAnimationFrame(z)},[U,C,E,F]);const jn=a.useCallback(T=>{const z=re.current;if(!z)return!1;const ae=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(T):T.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Se=z.querySelector(`#${ae}`);return Se?(Se.scrollIntoView({block:"start"}),!0):!1},[]);a.useEffect(()=>{const T=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,z=C.kind==="text"&&Rs(T??"")&&pe==="preview";if(!q||!z)return;const ae=requestAnimationFrame(()=>{jn(q)&&me(null)});return()=>cancelAnimationFrame(ae)},[n,jn,pe,q,C,i]),a.useLayoutEffect(()=>{const T=re.current;if(!T||!R){ve(null);return}if(ce)return;const z=C.kind==="image"||C.kind==="loading"&&C.mode==="image",ae=i&&n&&!n.startsWith("/")?`${i}/${n}`:n,Se=C.kind==="text"&&Rs(ae??"")&&pe==="preview",He=C.kind==="text"&&Ss(ae??"")&&M==="preview";if(C.kind!=="text"||z||Se||He){ve(null);return}const Fe=()=>{const Ge=K.current.get(R.end);if(!Ge||!T){ve(null);return}const tt=Ge.offsetTop+Ge.offsetHeight/2,Ct=T.scrollLeft+Math.max(8,T.clientWidth-120);ve({top:tt,left:Ct})};Fe();const Oe=new ResizeObserver(()=>Fe());return Oe.observe(T),()=>Oe.disconnect()},[R,ce,C,pe,M,n,i,Me]);const Fr=C.kind==="text"&&!(Ss(ft??"")&&M==="preview")&&!ft?.toLowerCase().endsWith(".csv")&&!ft?.toLowerCase().endsWith(".kicad_pro")&&!ft?.toLowerCase().endsWith(".kicad_prl"),mr=a.useCallback(()=>{et(!1),lt(""),Dr([]),H(0),Ua()},[]),Rn=a.useCallback(()=>{Fr&&(et(!0),requestAnimationFrame(()=>{se.current?.focus(),se.current?.select()}))},[Fr]),pt=a.useCallback(T=>{H(z=>ct.length===0?0:(z+T+ct.length)%ct.length)},[ct.length]);if(a.useEffect(()=>{const T=z=>{const ae=ug(z);if(ae==="open"&&Fr){z.preventDefault(),Rn();return}at&&(ae==="close"?(z.preventDefault(),mr()):(ae==="next"||ae==="previous")&&(z.preventDefault(),pt(ae==="previous"?-1:1)))};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[mr,at,pt,Rn,Fr]),a.useLayoutEffect(()=>{if(Ua(),!at||!qt.trim()||!re.current){Dr([]),H(0);return}const T=hg(re.current,qt);return Dr(T),H(0),Ed(T,0),Md(T[0]),Ua},[at,qt,Me,pe,C]),a.useEffect(()=>{at&&(Ed(ct,Ft),Md(ct[Ft]))},[Ft,ct,at]),a.useEffect(()=>Ua,[]),!n)return e.jsx("div",{className:"mx-3 mt-3 overflow-hidden rounded-xl border border-border/15 bg-surface-2 px-4 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.selectFilePrompt")});const Ue=i&&!n.startsWith("/")?`${i}/${n}`:n,Lt=Za(Ue,i),pr=au(Ue,i),gr=C.kind==="text"&&C.content?C.content.split(`
1654
+ `):[],Us=Math.max(2,String(gr.length).length)+1,br=C.kind==="text"||C.kind==="image"||C.kind==="model3d"||C.kind==="video"||C.kind==="eda"?C.meta:null,xr=Rs(Ue),Hs=Ue.toLowerCase().endsWith(".csv"),At=Ue.toLowerCase().endsWith(".kicad_pro"),es=Ue.toLowerCase().endsWith(".kicad_prl"),Bt=C.kind==="text"&&xr&&pe==="preview",zs=Ss(Ue),vr=C.kind==="text"&&zs&&M==="preview",Ws=C.kind==="image"||C.kind==="loading"&&C.mode==="image",fo=C.kind==="model3d"||C.kind==="loading"&&C.mode==="model3d",Rt=C.kind==="video"||C.kind==="loading"&&C.mode==="video",nn=C.kind==="eda"||C.kind==="loading"&&C.mode==="eda",ts=C.kind==="text"?C.sourcePath:Ue,_r=wm(ts,i,R),Br=(()=>{if(!R||C.kind!=="text"||gr.length===0)return _r;const T=[];for(let Se=R.start;Se<=R.end;Se+=1)T.push(`${Se} ${gr[Se-1]??""}`);const z=Hu(Ue).replace(/^\./,""),ae="```";return`${_r}
1655
1655
  ${ae}${z}
1656
- ${P.join(`
1656
+ ${T.join(`
1657
1657
  `)}
1658
1658
  ${ae}
1659
- `})(),yr=`path:${Ue}`,wr=E?`path:${Ue}:${E.start}-${E.end}`:yr,Br=$===yr,Or=$===wr,Cn=T===yr,rs=T===wr,sn=Or||rs,Vt=E?E.start===E.end?`L${E.start}`:`L${E.start}-${E.end}`:null,Ur=P=>{const z=re.current;if(!z)return;const ae=z.getBoundingClientRect(),Se=P.currentTarget.getBoundingClientRect(),He=P.clientX||Se.left+Se.width/2,Oe=(P.clientY||Se.top+Se.height/2)-ae.top+z.scrollTop,Ge=g?116:132,tt=z.scrollLeft+Math.max(8,z.clientWidth-Ge),Ct=Math.min(Math.max(8,He-ae.left+z.scrollLeft+10),tt);ve({top:Oe,left:Ct})},ns=(P,z)=>{Ai()||(Ur(P),N(ae=>{const Se=Pi(ae,z,z);return Se||ve(null),Se}))},ss=(P,z,ae)=>{Ur(P),N(Se=>{const He=Pi(Se,z,ae);return He||ve(null),He})},kr=(P,z,ae,Se)=>{Se==="end"&&Ur(P),N({start:z,end:ae})},tr=P=>{const{scrollTop:z,scrollLeft:ae}=P.currentTarget;S(z),bi(i,n,{top:z,left:ae,markdownTop:z})},De=P=>{if(P.directory){p?.(P.path);return}if(P.path===Ue||R.kind==="text"&&P.path===R.sourcePath){P.fragment&&jn(P.fragment);return}le(z=>[...z,Ue]),Ae.current=P.path,me(P.fragment),N(null),O(P.path)},Yt=()=>{const P=Q[Q.length-1];P&&(le(z=>z.slice(0,-1)),Ae.current=P,me(null),N(null),O(P))},an=P=>{const{scrollTop:z,scrollLeft:ae}=P.currentTarget;bi(i,n,{top:z,left:ae})},Nn=()=>{if(r){r(_r,wr);return}E&&l(_r,wr)},as=async()=>{if(!(!Ue||Pe.status==="pending")&&!(R.kind==="loading"||R.kind==="error")){ke({status:"pending"});try{await am(Ue),ke({status:"idle"})}catch(P){ke({status:"error",message:P instanceof Error?P.message:m("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[be.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${g&&(Bt||vr)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[g&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":m("rightSidebar.backToFileList"),title:m("rightSidebar.backToFileList"),children:e.jsx(ou,{size:16})}),Q.length>0&&e.jsxs("button",{type:"button",onClick:Yt,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${g?"w-9":"px-2.5"}`,"aria-label":m("rightSidebar.backToPreviousPreview"),title:m("rightSidebar.backToPreviousPreview"),children:[e.jsx(Ps,{size:15}),!g&&e.jsx("span",{className:"text-[11px] font-medium",children:m("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Ue,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Lt.name}),Lt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Lt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Dr&&e.jsx("button",{type:"button",onClick:at?mr:Rn,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${at?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":m("rightSidebar.findInFile"),title:`${m("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Zn,{size:14})}),xr&&R.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{b&&y?.(),Me(P=>{const z=P==="preview"?"source":"preview";return $t(Ru,z),z}),N(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${g?"w-9 px-0":"px-3"}`,"aria-label":m(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:m(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:g?pe==="preview"?e.jsx(Ii,{size:14}):e.jsx(Ti,{size:14}):m(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),Hs&&R.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Z(P=>{const z=P==="preview"?"source":"preview";return Cp(i,n,z),z}),N(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${g?"w-9 px-0":"px-3"}`,"aria-label":m(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:m(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:g?M==="preview"?e.jsx(Ii,{size:14}):e.jsx(Ti,{size:14}):m(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),vr&&e.jsx("button",{type:"button",onClick:()=>{he.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":m(Ne?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:m(Ne?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(iu,{size:15})}),!g&&e.jsx("button",{type:"button",onClick:()=>s(Ue,yr),...be(pr,yr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Br||Cn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:m("rightSidebar.insertReference",{reference:pr}),children:m(Cn?"rightSidebar.copied":Br?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(pr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:m("rightSidebar.copyReference",{reference:pr}),"aria-label":m("rightSidebar.copyFileRef"),children:e.jsx(Wh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{as()},disabled:Pe.status==="pending"||R.kind==="loading"||R.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:Pe.status==="error"?Pe.message??m("rightSidebar.downloadFailed"):m("rightSidebar.downloadFile"),"aria-label":m("rightSidebar.downloadFile"),children:Pe.status==="pending"?e.jsx(St,{size:13,className:"animate-spin"}):e.jsx(xm,{size:14})})]})]}),at&&Dr&&e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:se,type:"search",value:qt,onChange:P=>lt(P.target.value),onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),pt(P.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:m("rightSidebar.findInFilePlaceholder"),"aria-label":m("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ct.length>0?`${Ft+1}/${ct.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>pt(-1),disabled:ct.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":m("rightSidebar.previousSearchMatch"),title:`${m("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(nu,{size:13})}),e.jsx("button",{type:"button",onClick:()=>pt(1),disabled:ct.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":m("rightSidebar.nextSearchMatch"),title:`${m("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(vm,{size:13})}),e.jsx("button",{type:"button",onClick:mr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":m("rightSidebar.closeFileSearch"),title:`${m("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Kt,{size:13})})]}),br&&!(g&&(Bt||vr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[br.size!==null&&e.jsx("span",{children:m("rightSidebar.byteCount",{count:br.size.toLocaleString()})}),"truncated"in br&&br.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:m("rightSidebar.previewTruncated")}),"mimeType"in br&&e.jsx("span",{children:br.mimeType}),"dimensions"in R&&R.dimensions&&e.jsxs("span",{children:[R.dimensions.width," × ",R.dimensions.height]})]}),!(g&&(Bt||vr))&&!fo&&R.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:nn?m("rightSidebar.edaPickHint"):Us?m("rightSidebar.csvTablePreview"):At||es?m("rightSidebar.kicadProjectPickHint"):Rt?m("rightSidebar.videoPreviewHint"):zs?m("rightSidebar.imagePreviewHint"):Bt?E?m("rightSidebar.selectedLineHint",{lineLabel:Vt??""}):m("rightSidebar.markdownPreviewHint"):vr?m("rightSidebar.htmlPreviewHint"):E?m("rightSidebar.selectedLineHint",{lineLabel:Vt??""}):m("rightSidebar.multiLineHint")})})]}),R.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:R.mode==="eda"?m("rightSidebar.edaLoading"):R.mode==="image"?m("rightSidebar.loadingImage"):R.mode==="model3d"?m("rightSidebar.model3dLoading"):R.mode==="video"?m("rightSidebar.loadingVideo"):"Loading file…"}):R.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:R.message}),e.jsx("button",{type:"button",onClick:Sn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:m("common.retry")})]}):R.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:m("rightSidebar.binaryPreviewHint")})}):R.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:R.meta.mimeType==="image/svg+xml"?e.jsx(yu,{blobUrl:R.objectUrl,filePath:Ue,viewLabel:"SVG 文件",onInsertAnnotation:u}):e.jsx(Rf,{src:R.objectUrl,alt:Lt.name,vector:!1,onLoad:P=>{const z=P.currentTarget;G(ae=>ae.kind==="image"?{...ae,dimensions:{width:z.naturalWidth,height:z.naturalHeight}}:ae)},onError:()=>G({kind:"error",message:m("rightSidebar.imageLoadFailed")})})}):R.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(_p,{url:R.url,onLoadError:()=>G({kind:"error",message:m("rightSidebar.videoLoadFailed")})})}):R.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Gp,{blobUrl:R.objectUrl,filePath:R.sourcePath,view:R.view,board:Ue.toLowerCase().endsWith(".kicad_pcb"),onViewChange:te,onInsertAnnotation:r??u,onRefresh:Sn,interactive3d:xe?e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:m("rightSidebar.model3dLoading")}),children:e.jsx(Pd,{blobUrl:xe.objectUrl,ext:".glb",fileName:Lt.name,filePath:xe.sourcePath,features:null,onInsertFeature:r??u,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:P=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(P)?P:"PCB板体/铜箔/丝印",active:R.view==="pcb-3d"})}):void 0})}):R.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:m("rightSidebar.model3dLoading")}),children:e.jsx(Pd,{blobUrl:R.objectUrl,ext:R.ext,fileName:Lt.name,filePath:R.sourcePath,features:L,onInsertFeature:r??u,onRefresh:Sn})})}):R.kind==="text"&&Us?e.jsx(Vp,{content:R.content,filePath:Ue,onInsertAnnotation:r??u},Ue):R.kind==="text"&&(At||es)?e.jsx(Jp,{content:R.content,filePath:Ue,localState:es,onInsertAnnotation:r??u},Ue):Bt?e.jsxs("div",{ref:re,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:tr,style:{touchAction:"pan-x pan-y"},children:[e.jsx(mf,{content:R.content,filePath:R.sourcePath,rootPath:i,lineRange:E,onLineRangeClick:ss,onLineRangeDrag:kr,scrollTop:Ie,outlineOpen:b,outlineCloseSignal:f,onOutlineOpen:k,onOutlineClose:y,lightboxOpen:C,lightboxCloseSignal:D,onLightboxOpen:_,onLightboxClose:B,onLocalLinkOpen:De}),E&&ce&&e.jsxs("button",{type:"button",onClick:Nn,...be(_r,wr),style:{top:ce.top,left:ce.left,transform:"translateY(-50%)"},className:bd(g,sn),title:`Insert markdown reference: ${Fr}`,children:[e.jsx(Qa,{size:g?13:11}),rs?m("rightSidebar.copied"):Or?m("rightSidebar.inserted"):m("rightSidebar.insertLineRef",{lineLabel:Vt??""})]})]}):vr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(ag,{ref:he,src:Gh(Ue),title:`${Lt.name} preview`,exitFullscreenLabel:m("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Ve},`${Ue}:${dr}:${fr}`)}):R.kind==="text"?e.jsxs("div",{ref:re,onScroll:an,className:`${el} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[gr.length>0?e.jsx("div",{className:"min-w-full",children:gr.map((P,z)=>{const ae=z+1,Se=!!(E&&ae>=E.start&&ae<=E.end),He=Ee&&Ee.length===gr.length?Ee[z]:null;return e.jsxs("div",{ref:Fe=>{Fe?K.current.set(ae,Fe):K.current.delete(ae)},role:"button","data-file-preview-line":ae,tabIndex:0,onClick:Fe=>ns(Fe,ae),onKeyDown:Fe=>{Fe.key!=="Enter"&&Fe.key!==" "||(Fe.preventDefault(),ns(Fe,ae))},style:{gridTemplateColumns:`${Os}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${Se?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${pr}:${ae}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${Se?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:ae}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:He??(P||" ")})]},z)})}):"Empty file.",E&&ce&&e.jsxs("button",{type:"button",onClick:Nn,...be(_r,wr),style:{top:ce.top,left:ce.left,transform:"translateY(-50%)"},className:bd(g,sn),title:`Insert code reference: ${Fr}`,children:[e.jsx(Qa,{size:g?13:11}),rs?m("rightSidebar.copied"):Or?m("rightSidebar.inserted"):m("rightSidebar.insertLineRef",{lineLabel:Vt??""})]})]}):null]})}function Hb({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h=!1,onTogglePinned:p,rightSidebarFilePreviewOpen:g=!1,rightSidebarFilePreviewCloseSignal:b,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:k,rightSidebarRepoPickerOpen:y=!1,rightSidebarRepoPickerCloseSignal:C,onOpenRightSidebarRepoPicker:D,onCloseRightSidebarRepoPicker:_,markdownOutlineOpen:B=!1,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:m}){const{t:i,locale:O}=jt(),[R,G]=a.useState(""),[fe,te]=a.useState(null),xe=J(t=>t.rightSearchOpen),W=J(t=>t.setRightSearchOpen),Y=J(t=>t.rightSidebarLayoutPreference),L=J(t=>t.setRightSidebarLayoutPreference),[I,K]=a.useState(()=>Ig()),[re,ce]=a.useState("."),[ve,pe]=a.useState(""),[Me,M]=a.useState(!1),[Z,he]=a.useState(!1),[Ne,Ve]=a.useState(!1),[Ce,Ye]=a.useState(!1),Ie=a.useDeferredValue(R),[S,Q]=a.useState(null),[le,q]=a.useState([]),[me,Ae]=a.useState([]),oe=J(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Ee=J(t=>t.setActiveGitRepo),[st,Pe]=a.useState(null),[ke,at]=a.useState(null),[et,qt]=a.useState(null),[lt,ct]=a.useState(()=>ut(Md,Ms)??!1),[Ir,Ft]=a.useState(()=>ut(Ed,Ms)??!1),[H,se]=a.useState(()=>ut($d,Ms)??!1),[be,We]=a.useState(()=>ut(fi,$g)??""),[ft,dr]=a.useState(0),[ur,_t]=a.useState(!1),[fr,hr]=a.useState(!1),Sn=a.useRef(null),jn=a.useRef(null),[Dr,mr]=a.useState(!1),[Rn,pt]=a.useState(null),[Ue,Lt]=a.useState(null),[pr,gr]=a.useState(()=>Id(di)),[Os,br]=a.useState(()=>Id(Nd)),[xr,Us]=a.useState(()=>Eg()),[At,es]=a.useState(()=>Lg()),[Bt,Hs]=a.useState(()=>Pg()),vr="words",[zs,fo]=a.useState(0),[Rt,nn]=a.useState([]),[ts,Fr]=a.useState([]),[_r,yr]=a.useState(!1),[wr,Br]=a.useState(null),[Or,Cn]=a.useState([]),[rs,sn]=a.useState(!1),[Vt,Ur]=a.useState([]),[ns,ss]=a.useState([]),[kr,tr]=a.useState(!1),[De,Yt]=a.useState(null),[an,Nn]=a.useState([]),[as,P]=a.useState({}),[z,ae]=a.useState(!1),[Se,He]=a.useState(null),[Fe,Oe]=a.useState(null),[Ge,tt]=a.useState(null),[Ct,rr]=a.useState(null),[Xt,Mn]=a.useState(!1),[os,on]=a.useState(""),Hr=a.useDeferredValue(os),[Sr,ho]=a.useState({}),[ln,X]=a.useState([]),[ze,Pt]=a.useState(!1),[zr,is]=a.useState(!1),[dl,En]=a.useState(null),[mo,$n]=a.useState(!1),nr=a.useRef(null),Wr=a.useRef(0),ul=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[Cf,Ws]=a.useState(null),[ls,fl]=a.useState(()=>ut(ui,Ms)??!1),[po,go]=a.useState(!1),[Gs,bo]=a.useState([]),[jr,Ks]=a.useState({}),[Nt,qs]=a.useState({}),[Gr,hl]=a.useState(!0),[ml,pl]=a.useState(()=>new Set),[rt,Kr]=a.useState(null),[xo,qr]=a.useState(null),[Nf,Rr]=a.useState(!1),[gl,Cr]=a.useState(0),[,vo]=a.useState(0),[yo,Vs]=a.useState(!1),[sr,wo]=a.useState(!1),[Mf,bl]=a.useState(()=>J.getState().rightTab==="diff"),[ko,So]=a.useState(()=>J.getState().rightTab==="android"),[Vr,xl]=a.useState(!1),Ef=Qc(t=>!!t.docks[ld]),[_e,cs]=a.useState(null),[Ln,ds]=a.useState(null),[gt,Yr]=a.useState(null),[vl,bt]=a.useState(null),[An,yl]=a.useState(null),[jo,$f]=a.useState(()=>Date.now()),[Lf,Af]=a.useState(!1),[cn,Ys]=a.useState(!1),[Xs,wl]=a.useState(""),[Pn,Js]=a.useState(""),[dn,Zs]=a.useState(""),[un,Qs]=a.useState(""),[kl,Tn]=a.useState(null),[ea,ta]=a.useState(!1),[Sl,Ro]=a.useState(!1),[jl,Rl]=a.useState(!1),[ra,Pf]=a.useState({key:null,nonce:0}),Cl=a.useRef(null),Nl=a.useRef(null),ee=om(s,h,Y),Tf=Iu(ee,h,Bt),[Co,No]=a.useState(()=>Hg(s)),Mo=J(t=>t.rightTab),Jt=J(t=>t.setRightTab),v=J(t=>t.rootPath),In=J(t=>t.explorerRoot),Ml=J(t=>t.pinnedExplorerRootsCache),El=J(t=>t.hydratePinnedExplorerRoots),$l=J(t=>t.syncPinnedExplorerRoots),Ot=J(t=>t.setExplorerRoot),Ll=J(t=>t.resetExplorerToProject),Dn=J(t=>t.pinExplorerRoot),fn=J(t=>t.unpinExplorerRoot),Je=J(t=>t.selectedFilePath),Ze=J(t=>t.selectFile),Eo=J(t=>t.showHiddenFiles),If=J(t=>t.toggleShowHiddenFiles),$o=J(t=>!!(v&&t.nestedGitScanRoots[v])),we=J(t=>t.changedFiles),na=J(t=>t.setChangedFiles),sa=J(t=>t.invalidateDirectoryCache),Df=J(t=>t.setDirectorySortMode),Al=J(t=>t.applyFileWatchEvents),Pl=J(t=>t.reconcileDirectoryCache),Tl=J(t=>t.bumpFileWatchEpoch),Xr=J(t=>t.gitBundleLoading),Il=J(t=>t.gitBundleSlow),hn=J(t=>t.gitBundleError),Fn=J(t=>t.gitBundleLastLoadedAt),Dl=J(t=>t.beginGitBundleLoading),Fl=J(t=>t.setGitBundleSlowFor),Lo=J(t=>t.finishGitBundleLoading),aa=J(t=>t.resetGitBundleLoading),Ao=J(t=>t.setGitBundleError),_l=J(t=>t.markGitBundleLoaded),ge=In??v,Bl=a.useMemo(()=>ge?dg(ge,re):"",[ge,re]),us=a.useMemo(()=>cg(ve),[ve]),Ol=a.useMemo(()=>({excludePatterns:us,caseSensitive:Z,wholeWord:Ne,regex:Ce}),[Z,us,Ce,Ne]),oa=J(t=>ge?t.fileSortModes[ge]??"name":"name"),Ul=J(t=>!!(ge&&t.directoryCache.has(ge))),_n=a.useRef(null),yt=a.useRef(0),[Hl]=a.useState(()=>++Db),Nr=a.useRef(null),Jr=a.useRef(null),ia=a.useRef(0),Ut=a.useRef(new Map),Ht=a.useRef(new Map),ar=a.useRef(new Set),mn=a.useRef(new Set),pn=a.useRef(0),Zr=a.useRef(null),Bn=a.useRef(0),On=a.useRef(null),Un=a.useRef(0),Qr=a.useRef(null),Po=a.useRef(new Set),To=a.useRef(null),Io=a.useRef(null),la=a.useRef(null),Do=a.useRef(null),Fo=a.useRef(null),fs=a.useRef(new Set);a.useEffect(()=>{if(An===null)return;const t=Math.max(0,Date.now()-An),o=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,d=Math.max(50,o-t%o),x=window.setTimeout(()=>$f(Date.now()),d);return()=>window.clearTimeout(x)},[jo,An]);const ca=a.useRef(null),Mr=a.useRef(null),da=a.useRef(null),hs=a.useRef(null),je=a.useCallback(t=>J.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=o=>{const d=Ob(o.target);d&&Va("global_change_row_event",{...Ub(o),selectionPath:d.dataset.diffSelectionPath,filePath:d.dataset.diffFilePath,absolutePath:d.dataset.diffAbsolutePath,repoRoot:d.dataset.diffRepoRoot,status:d.dataset.diffStatus,selectedFilePath:J.getState().selectedFilePath,rightTab:J.getState().rightTab,activeGitRepoRoot:oe,changedFiles:J.getState().changedFiles.size})};return window.addEventListener("pointerdown",t,{capture:!0}),window.addEventListener("click",t,{capture:!0}),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),window.removeEventListener("click",t,{capture:!0})}},[oe,r]);const zl=a.useCallback(async(t=v??void 0)=>{if(!t)return null;if(ar.current.has(t)||mn.current.has(t))return nt("untracked_skip_cached",{cwd:t,rootPath:v,completed:ar.current.has(t),running:mn.current.has(t)}),null;const o=v,d=ia.current+1;ia.current=d,Ut.current.set(t,d);const x=`right-sidebar-git-untracked:${t}`,w=new AbortController;Ht.current.set(t,w),mn.current.add(t),nt("untracked_start",{requestId:d,cwd:t,rootPath:v});try{let j=await ed(t,w.signal,x),A=0;for(;j.status==="running"&&A<120;){if(Ut.current.get(t)!==d||w.signal.aborted)return nt("untracked_stale_result",{requestId:d,activeRequestId:Ut.current.get(t),cwd:t,status:j.status}),null;if(!je(o))return nt("untracked_root_changed",{requestId:d,cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath}),null;await new Promise(ne=>window.setTimeout(ne,A<10?1e3:3e3)),A+=1,j=await ed(t,w.signal,x)}if(Ut.current.get(t)!==d||!je(o))return nt("untracked_stale_result",{requestId:d,activeRequestId:Ut.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,files:j.files.length,status:j.status}),null;if(j.status==="done")return na(xf(J.getState().changedFiles,j.files)),j.files.length>0&&q(ne=>{const $e=new Map(ne.map(Le=>[Le.root,Le])).get(t);if(!$e)return ne;const Be=jb($e.files,j.files),Re=ne.map(Le=>Le.root===t?{...Le,files:Be,context:Le.context?{...Le.context,changedFiles:Be.map(Ke=>({path:Ke.path,absolutePath:Ke.absolutePath,status:Ke.status})),truncated:!1}:Le.context,untrackedDeferred:!1}:Le);Ae(vf(Re,v));const ie=Re.find(Le=>Le.root===v);return ie?.context&&Q(Le=>Le?.root===ie.root?{...Le,...ie.context}:Le),Re}),ar.current.add(t),nt("untracked_apply",{requestId:d,cwd:t,files:j.files.length}),j;const ue=j.error||(j.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return ar.current.add(t),nt("untracked_error",{requestId:d,cwd:t,message:ue,code:j.code,status:j.status}),null}catch(j){if(Ut.current.get(t)!==d||!je(o)||Pr(j))return nt("untracked_aborted",{requestId:d,activeRequestId:Ut.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,message:j instanceof Error?j.message:String(j)}),null;const A=j instanceof Error?j.message:"Failed to scan untracked files";return ar.current.add(t),nt("untracked_error",{requestId:d,cwd:t,message:A}),null}finally{Ht.current.get(t)===w&&Ht.current.delete(t),Ut.current.get(t)===d&&Ut.current.delete(t),mn.current.delete(t)}},[S,je,v,na]),Zt=a.useMemo(()=>{const t=new Set(me.map(d=>d.root)),o=Or.filter(d=>t.has(d));return o.length>0?o:oe?[oe]:[]},[oe,Or,me]),Wl=Zt.length===0,gn=a.useMemo(()=>Zt.map(t=>le.find(o=>o.root===t)).filter(t=>!!t),[Zt,le]),Ff=a.useMemo(()=>me.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[me]),or=a.useCallback(async()=>{if(!v){nn([]),Fr([]);return}const t=v,o=Bn.current+1;Bn.current=o,On.current?.abort();const d=new AbortController;On.current=d,yr(Rt.length===0),Br(null);try{const x=Zt.length>0?await Promise.all(Zt.map(w=>td({workspaceRoot:v,repoRoot:w},d.signal))).then(w=>({records:w.flatMap(j=>j.records),walkthroughs:w.flatMap(j=>j.walkthroughs??[])})):await td({workspaceRoot:v},d.signal);if(Bn.current!==o||!je(t))return;nn(x.records),Fr(x.walkthroughs??[])}catch(x){if(Bn.current!==o||!je(t)||Pr(x))return;Br(x instanceof Error?x.message:"Failed to load change audit explanations")}finally{On.current===d&&(On.current=null),Bn.current===o&&je(t)&&yr(!1)}},[Rt.length,Zt,je,v]),ua=a.useCallback(async(t,o,d)=>{if(!t&&!v){Ur([]),ss([]);return}const x=v,w=Un.current+1;Un.current=w,Qr.current?.abort();const j=new AbortController;Qr.current=j;try{const A=t?[t]:Array.from(new Set([v,...le.map(ne=>ne.root)].filter(ne=>!!ne))),ue=await Promise.all(A.map(ne=>qh({repoRoot:ne,baseRef:o,branchName:d},j.signal))).then(ne=>{const V=new Map,$e=new Map;for(const Be of ne){for(const Re of Be.records)V.set(Re.id,Re);for(const Re of Be.walkthroughs??[])$e.set(Re.id,Re)}return{records:Array.from(V.values()),walkthroughs:Array.from($e.values())}});if(Un.current!==w||!je(x))return;Ur(ue.records),ss(ue.walkthroughs??[])}catch(A){if(Un.current!==w||!je(x)||Pr(A))return;console.warn("[RightSidebar] Failed to load branch explanations",A)}finally{Qr.current===j&&(Qr.current=null)}},[le,je,v]),en=a.useCallback((t,o={})=>{if(!je(v)){nt("apply_skipped_root_changed",{expectedRootPath:v,currentRootPath:J.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}nt(t.files.length===0?"empty_bundle":"apply",{rootPath:v,available:t.available,files:t.files.length,repositories:t.repositories?.map(ie=>({root:ie.root,relativeRoot:ie.relativeRoot,files:ie.files.length,available:ie.available,error:ie.error})),repoFilters:t.repoFilters?.map(ie=>({root:ie.root,label:ie.label,count:ie.count})),cached:t.cached,stale:t.stale,cacheAgeMs:t.cacheAgeMs,untrackedDeferred:t.untrackedDeferred,error:t.error});let d=Du(t),x=t.repoFilters??[],w=t.files;const j=J.getState().changedFiles;if(!!(o.cacheOnly&&!t.cached&&t.files.length===0&&d.length===0)&&(j.size>0||le.length>0||S)){nt("cache_only_apply_skipped_empty_backend_cache",{rootPath:v,currentFiles:j.size,currentRepositories:le.length});return}const ue=d.some(ie=>ie.deferred);if(ue&&!o.replaceWorkspace){const ie=new Set(d.filter(Ke=>!Ke.deferred||Ke.root===v).map(Ke=>Ke.root));w=[...Array.from(j.values()).filter(Ke=>!ie.has(mt(Ke,v)??"")),...t.files]}const ne=qd(j.values(),v),V=qd(t.files,v),$e=d.some(ie=>ie.root!==v);if(!!(o.background&&!ue&&!o.replaceWorkspace&&j.size>0&&(t.files.length===0&&!t.error||ne>0&&V===0&&!$e))){nt("background_apply_skipped_degraded_bundle",{rootPath:v,currentFiles:j.size,nextFiles:t.files.length,currentNestedCount:ne,nextNestedCount:V,nextRepositories:d.map(ie=>({root:ie.root,relativeRoot:ie.relativeRoot,files:ie.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(o.replaceRepoRoot){const ie=yf(j.values(),le,t,o.replaceRepoRoot,v);w=ie.files,d=ie.repositories,x=ie.repoFilters}if(na(bf(w)),q(d),Ae(x),Fo.current=v,o.syncActiveRepo!==!1){const{contextKey:ie,activeGitRepos:Le}=J.getState(),Ke=ie?Le[ie]??null:null,Dt=o.activeRepoRoot!==void 0?o.activeRepoRoot:Ke,Te=Dg({...t,repositories:d,repoFilters:x},Dt);Ee(Te)}typeof t.cacheUpdatedAt=="number"&&yl(t.cacheUpdatedAt),Q(ie=>{if(o.replaceRepoRoot&&o.replaceRepoRoot!==v)return ie;if(!t.context)return null;const Le=ie?.root??v;return!ie?.available||Le!==(t.context.root??v)?t.context:{...ie,...t.context}}),o.reloadDiff&&fo(ie=>ie+1);const Re=J.getState().selectedFilePath;if(Re&&!Re.startsWith("/")&&!w.some(ie=>ie.path===Re||ie.absolutePath===Re)&&Ze(null),gr(ie=>{const Le=new Set(w.map(Dt=>mt(Dt,v)).filter(Boolean)),Ke=new Set;for(const Dt of ie)Le.has(Dt)&&Ke.add(Dt);return mi(di,Ke),Ke}),o.loadDeferred!==!1){const ie=d.filter(Le=>Le.untrackedDeferred&&Le.root).map(Le=>Le.root);for(const Le of ie)zl(Le)}o.loadAudit!==!1&&or()},[je,or,zl,v,Ze,Ee,na]);a.useEffect(()=>{aa(),To.current=null,Io.current=v;const t=[],o=[];yt.current+=1,pn.current+=1,ia.current+=1,Nr.current?.abort(),kt(Jn(Jr.current?.cwd??v??void 0)),Jr.current=null,Nr.current=null,Zr.current?.abort(),kt("right-sidebar-git-details"),Zr.current=null;for(const A of Ht.current.values())A.abort();for(const A of Ht.current.keys())kt(`right-sidebar-git-untracked:${A}`);Ht.current.clear(),Ut.current.clear(),Bn.current+=1,On.current?.abort(),On.current=null,Un.current+=1,Qr.current?.abort(),Qr.current=null,Wr.current+=1,nr.current?.abort(),kt("right-sidebar-recent-commits"),nr.current=null,nn([]),Fr([]),yr(!1),Br(null),Cn([]),sn(!1),Ur([]),ss([]),tr(!1),Yt(null),ae(!1),He(null),Oe(null),tt(null),rr(null),Mn(!1),on(""),X([]),Pt(!1),is(!1),En(null),$n(!1),Ws(null),Kr(null),qr(null),fl(!1),$t(ui,!1),go(!1);const d=v?Dd()[v]:null,x=d?.previewEntries??[],w=d?.selectedPreviewKey??null,j=w?x.find(A=>A.key===w)??null:null;bo(d?.selectedRepoRoots??[]),Ks(d?.repoTargetBranches??{}),qs(d?.repoBaseBranches??{}),Nn(x),P(d?.previewScrollTops??{}),j&&d?.previewDetailOpen&&(j.diff.hunks?.length??0)>0&&(Yt(j.diff),Kr(j.key),qr(d.selectedPreviewFileKey??(j.diff.hunks?.[0]?`${j.diff.hunks[0].filePath}\0${j.diff.hunks[0].hunkHeader}\0${j.diff.hunks[0].hunkIndex}`:null)),tr(!0)),hl(d?.includeUncommitted??!0),To.current=v,Ys(!1),ar.current.clear(),mn.current.clear(),cs(null),ds(null),Yr(null),bt(null),yl(null),q(t),Ae(o),Q(null),Do.current=null,Fo.current=null,fs.current.clear()},[aa,v]);const Qt=a.useCallback(async(t=v??void 0,o={})=>{if(!t)return null;const d=v,x=yt.current;if(await Zm(()=>Promise.all([J.getState().hydrateNestedGitScanRoots(),J.getState().hydrateActiveGitRepos()]).then(()=>{})),yt.current!==x||!je(d))return null;const w=t===v&&Yn(v),j=o.includeNested??w,A=o.refresh??o.reloadDiff??!1,ue=o.cacheOnly??!1,ne=o.background??!1,V=j&&(o.discoverOnly??!1);A&&ar.current.clear();const $e=Jr.current;if($e&&$e.cwd===t&&$e.includeNested===j&&$e.refresh===A&&$e.cacheOnly===ue&&$e.discoverOnly===V)return nt("reuse_pending",{cwd:t,includeNested:j,refresh:A,cacheOnly:ue,discoverOnly:V}),$e.promise;const Be=yt.current+1;yt.current=Be;const Re=`right-sidebar:${Hl}:${Be}`;Nr.current?.abort();const ie=Jn(t);kt(ie);const Le=new AbortController;Nr.current=Le;let Ke=null;ne||Dl(Re),Ao(null),nt("start",{requestId:Be,cwd:t,rootPath:v,requestSlotId:ie,includeNested:j,refresh:A,cacheOnly:ue,background:ne,existingChanges:we.size,lastLoadedAt:Fn}),!ne&&typeof window<"u"&&(Ke=window.setTimeout(()=>{yt.current===Be&&Fl(Re,!0)},vg));const Dt=(async()=>{const Te=await Pa(t,Le.signal,{includeNested:j,refresh:A,cacheOnly:ue,discoverOnly:V,action:A?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:ie,requestTimeoutMs:A?null:void 0});if(Nb(Te)){if(nt("cancelled_result_ignored",{requestId:Be,activeRequestId:yt.current,cwd:t,error:Te.error??Te.context?.error}),Le.signal.aborted)return null;throw new Error(Te.error??Te.context?.error??"Failed to load Git changes")}return yt.current!==Be||!je(d)?(nt("stale_result",{requestId:Be,activeRequestId:yt.current,cwd:t,expectedRootPath:d,currentRootPath:J.getState().rootPath,files:Te.files.length,repositories:Te.repositories?.length??0}),null):(en(Te,{reloadDiff:o.reloadDiff,syncActiveRepo:o.replaceWorkspace?!0:j,background:ne,cacheOnly:ue,replaceRepoRoot:o.replaceRepoRoot,replaceWorkspace:o.replaceWorkspace}),Te)})();Jr.current={cwd:t,includeNested:j,refresh:A,cacheOnly:ue,discoverOnly:V,promise:Dt};try{const Te=await Dt;return yt.current===Be&&Te&&je(d)?_l({cached:Te.cached,stale:Te.stale,cacheAgeMs:Te.cacheAgeMs,nestedDeferred:!j||Te.nestedDeferred,untrackedDeferred:Te.untrackedDeferred}):yt.current===Be&&je(d)&&Lo(Re),Te}catch(Te){return yt.current!==Be||!je(d)||Le.signal.aborted?(nt("aborted",{requestId:Be,activeRequestId:yt.current,cwd:t,expectedRootPath:d,currentRootPath:J.getState().rootPath,message:Te instanceof Error?Te.message:String(Te)}),null):(nt("error",{requestId:Be,cwd:t,includeNested:j,refresh:A,background:ne,message:Te instanceof Error?Te.message:String(Te)}),ne||(Q(null),Ao(Te instanceof Error?Te.message:"Failed to load Git changes")),null)}finally{Ke!==null&&window.clearTimeout(Ke),Nr.current===Le&&(Nr.current=null),Jr.current?.promise===Dt&&(Jr.current=null),!ne&&yt.current===Be&&je(d)&&Lo(Re)}},[en,Dl,we.size,Lo,Hl,Fn,je,_l,v,Ao,Fl]),ms=a.useCallback(async()=>{v&&await Qt(v,{reloadDiff:!0,refresh:!0})},[Qt,v]),_o=a.useCallback(async(t=v??void 0)=>{if(!t)return null;const o=v,d=pn.current+1;pn.current=d,Zr.current?.abort(),kt("right-sidebar-git-details");const x=new AbortController;Zr.current=x,Ys(!0);try{const w=await rd(t,x.signal,"load_git_details","right-sidebar-git-details");return pn.current!==d||!je(o)?null:(q(j=>j.map(A=>A.root===w.root?{...A,available:w.available,context:w,error:w.error}:A)),Q(j=>j?.root&&w.root&&j.root!==w.root?j:!j?.available||!w.available?w:{...j,...w}),w)}catch(w){return Pr(w)||!je(o)||pn.current===d&&bt(w instanceof Error?w.message:"Failed to load Git details"),null}finally{Zr.current===x&&(Zr.current=null),pn.current===d&&je(o)&&Ys(!1)}},[je,v]);a.useEffect(()=>{if(!r){yt.current+=1,aa(),Do.current=null,pn.current+=1,ia.current+=1,Nr.current?.abort(),kt(Jn(Jr.current?.cwd??v??void 0)),Jr.current=null,Nr.current=null,Zr.current?.abort(),kt("right-sidebar-git-details"),Zr.current=null;for(const t of Ht.current.values())t.abort();for(const t of Ht.current.keys())kt(`right-sidebar-git-untracked:${t}`);Ht.current.clear(),Ut.current.clear(),Un.current+=1,Qr.current?.abort(),Qr.current=null,Wr.current+=1,nr.current?.abort(),kt("right-sidebar-recent-commits"),nr.current=null,Ys(!1),ae(!1),He(null),Oe(null),tt(null),rr(null),Mn(!1),on(""),X([]),Pt(!1),is(!1),En(null),$n(!1),G(""),W(!1),pt(null),wo(!1),ee&&bl(!1)}},[ee,r,aa,W]),a.useEffect(()=>{if(!xe)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[xe]),a.useEffect(()=>{ee||Rr(!1)},[ee]);const ps=a.useCallback(t=>{vo(t);const o=da.current;o&&(o.update(),o.slideTo(t,0),window.requestAnimationFrame(()=>{o.update(),o.slideTo(t,0)}))},[]);a.useEffect(()=>{if(ee)if(Rr(g),g&&Je){Cr(1);const t=Mr.current;t&&(t.update(),t.activeIndex!==1&&(hs.current=1,t.slideTo(1,0)))}else{Cr(0);const t=Mr.current;t&&t.activeIndex!==0&&(hs.current=0,t.slideTo(0,0)),pt(null)}},[ee,g,v,Je]),a.useEffect(()=>{if(b!==void 0&&!g){Cr(0);const t=Mr.current;t&&t.activeIndex!==0&&(hs.current=0,t.slideTo(0,0)),Rr(!1),pt(null)}},[b,g]),a.useEffect(()=>{C!==void 0&&Pe(null)},[C]),a.useEffect(()=>{!ee&&g&&k?.()},[ee,k,g]),a.useEffect(()=>{No(t=>zi(t,s))},[s]);const _f=a.useCallback(t=>{ee||(t.preventDefault(),ca.current={startX:t.clientX,startWidth:Co,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Co,ee]),Bf=a.useCallback(t=>{const o=ca.current;if(!o||o.pointerId!==t.pointerId)return;const d=zi(o.startWidth+t.clientX-o.startX,s);No(d),Es(Ns,d,xg)},[s]),Gl=a.useCallback(t=>{const o=ca.current;if(!(!o||o.pointerId!==t.pointerId)){ca.current=null,js(Ns);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),Hn=!!(v&&Fn!==null&&Xd(S)),Bo=!!(v&&!hn&&we.size===0&&Fn===null),ir=(()=>{let t=Mo;return t==="android"&&!Vr&&(t="files"),Hn&&(t==="git"||t==="diff")&&(t="files"),t})(),Qe=ir==="git",zn=ir==="files",wt=ir==="diff",Wn=ir==="android",Of=ym(t=>t.overlay==="sidebar")&&Wn;a.useEffect(()=>{if(!ee){Vs(!0);return}if(!r){const o=window.setTimeout(()=>{Vs(!1)},kg);return()=>window.clearTimeout(o)}Vs(!1);const t=window.setTimeout(()=>{Vs(!0)},wg);return()=>window.clearTimeout(t)},[ee,r]),a.useEffect(()=>{if(!ee||!wt)return;const t=da.current;if(!t)return;const o=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(o)},[wt,ee]),a.useEffect(()=>{if(!Hn||!v||Xr)return;const t=window.setTimeout(()=>{Qt(v,{background:!0})},3e3);return()=>window.clearTimeout(t)},[Hn,v,Xr,Qt]);const Uf=a.useCallback(t=>{Qt(t,{discoverOnly:!0})},[Qt]);Qm({active:r&&(Qe||wt),rootPath:v,loading:Xr,delay:Qe&&!ee?0:hi,lastStartedRoot:Do,load:Uf}),a.useEffect(()=>{!r||!Qe||(!ee||yo)&&wo(!0)},[Qe,ee,r,yo]),a.useEffect(()=>{if(!r||Qe)return;const t=window.setTimeout(()=>{wo(!0)},hi);return()=>window.clearTimeout(t)},[Qe,r]),a.useEffect(()=>{wt&&bl(!0)},[wt]),a.useEffect(()=>{!r||!Wn||So(!0)},[Wn,r]),a.useEffect(()=>{if(r&&Wn||!ko)return;const t=window.setTimeout(()=>So(!1),yg);return()=>window.clearTimeout(t)},[r,Wn,ko]),a.useEffect(()=>{So(!1)},[n]),a.useEffect(()=>{let t=!1;return Zd().then(o=>{!t&&o.androidPanel&&xl(o.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const Hf=a.useCallback(t=>{xl(t),t?Jt("android"):J.getState().rightTab==="android"&&Jt("files"),Ni({androidPanel:{enabled:t}}).catch(()=>{})},[Jt]),Kl=a.useCallback(t=>{ge&&vb(ge,t.currentTarget.scrollTop)},[ge]);a.useEffect(()=>()=>{Nr.current?.abort(),js(Zi),js(Qi),js(Ns),js(fi)},[]),a.useEffect(()=>{if(!ge||!Ul)return;const t=pf()[ge]?.top;if(typeof t!="number")return;let o=window.requestAnimationFrame(()=>{_n.current&&(_n.current.scrollTop=t),o=window.requestAnimationFrame(()=>{_n.current&&(_n.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(o)},[ge,Ul]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return Vh(t.signal).then(o=>Rl(!!o.available)).catch(()=>Rl(!1)),()=>t.abort()},[r]);const gs=a.useCallback(t=>{if(te(null),Ze(t),pt(null),ee){Rr(!0),Cr(1),Mr.current?.slideTo(1),f?.();return}},[ee,f,Ze]),ql=a.useCallback((t,o)=>{if(te(null),Ze(t),Lt(o),ee){Rr(!0),Cr(1),Mr.current?.slideTo(1),f?.();return}},[ee,f,Ze]),bs=a.useCallback(async(t,o)=>{const d=o||In||v;if(!(!d||t.length===0)){ta(!0);try{await Ta(d,t),sa(d,!1)}catch(x){bt(x instanceof Error?x.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>bt(null),4e3)}finally{ta(!1)}}},[In,v,sa,i]),Vl=a.useCallback(async t=>{try{await Yh(t)}catch(o){bt(o instanceof Error?o.message:i("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>bt(null),4e3)}},[i]),fa=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Ro(!0)},[]),Yl=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ro(!1)},[]),Xl=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ro(!1);const o=t.dataTransfer.files;o.length>0&&bs(Array.from(o))},[bs]),Oo=a.useCallback(t=>{at(t),window.setTimeout(()=>at(o=>o===t?null:o),1400)},[]),Er=a.useCallback(t=>{qt(t),window.setTimeout(()=>qt(o=>o===t?null:o),1400)},[]);a.useEffect(()=>{$t(Md,lt)},[lt]),a.useEffect(()=>{$t(Ed,Ir)},[Ir]),a.useEffect(()=>{$t($d,H)},[H]),a.useEffect(()=>{Es(fi,be,hg)},[be]),a.useEffect(()=>(El().catch(()=>{}),nd(t=>{t.type==="pinned-explorer-roots"&&$l(t.pinnedExplorerRoots)})),[El,$l]);const Jl=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),ha=a.useRef(null),bn=a.useRef(null),[Zl,Uo]=a.useState(!1);a.useEffect(()=>{if(!r)return;Uo(!1);let t=!1;Xh().then(d=>{t||(ha.current=d.text,We(x=>d.text&&d.text!==x?d.text:x),Uo(!0))}).catch(()=>{t||Uo(!0)});const o=nd(d=>{d.type==="context-draft"&&d.origin!==Jl.current&&(ha.current=d.text,We(d.text))});return()=>{t=!0,o(),bn.current!==null&&(window.clearTimeout(bn.current),bn.current=null)}},[r]),a.useEffect(()=>{if(!Zl||ha.current===be)return;bn.current!==null&&window.clearTimeout(bn.current);const t=be;bn.current=window.setTimeout(()=>{bn.current=null,Jh(t,Jl.current).then(()=>{ha.current=t}).catch(()=>{})},500)},[be,Zl]);const Gn=a.useCallback((t,o,d)=>{if(t){if(Zh(d?t+d:t)){Oo(o);return}lt?(We(x=>Sp(x,t)+(d??"")),window.matchMedia("(pointer: coarse)").matches||(Ft(!1),dr(x=>x+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:d?t+d:t,focus:!0}})),Oo(o)}},[lt,Oo]),ma=a.useCallback(t=>{const o=Da(t,v);return wm(o,v)},[v]),Ho=mu(Er),lr=a.useCallback((t,o)=>{const d=Da(t,v);Gn(km(d,v),o??`path:${d}`)},[v,Gn]),zf=a.useCallback(async t=>{ta(!0);try{await cd(t,Ta,o=>{lr(o,`path:${o}`)}),ee&&!lt&&l()}catch(o){bt(o instanceof Error?o.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>bt(null),4e3)}finally{ta(!1)}},[lt,lr,ee,l,i]),Wf=a.useCallback(async t=>{await cd(t,Ta,o=>{lr(o,`path:${o}`)})},[lr]),$r=a.useCallback((t,o)=>{if(!t)return;const d=t.includes(`
1659
+ `})(),yr=`path:${Ue}`,wr=R?`path:${Ue}:${R.start}-${R.end}`:yr,Or=$===yr,Ur=$===wr,Cn=P===yr,rs=P===wr,sn=Ur||rs,Vt=R?R.start===R.end?`L${R.start}`:`L${R.start}-${R.end}`:null,Hr=T=>{const z=re.current;if(!z)return;const ae=z.getBoundingClientRect(),Se=T.currentTarget.getBoundingClientRect(),He=T.clientX||Se.left+Se.width/2,Oe=(T.clientY||Se.top+Se.height/2)-ae.top+z.scrollTop,Ge=g?116:132,tt=z.scrollLeft+Math.max(8,z.clientWidth-Ge),Ct=Math.min(Math.max(8,He-ae.left+z.scrollLeft+10),tt);ve({top:Oe,left:Ct})},ns=(T,z)=>{Pi()||(Hr(T),E(ae=>{const Se=Ti(ae,z,z);return Se||ve(null),Se}))},ss=(T,z,ae)=>{Hr(T),E(Se=>{const He=Ti(Se,z,ae);return He||ve(null),He})},kr=(T,z,ae,Se)=>{Se==="end"&&Hr(T),E({start:z,end:ae})},tr=T=>{const{scrollTop:z,scrollLeft:ae}=T.currentTarget;S(z),xi(i,n,{top:z,left:ae,markdownTop:z})},De=T=>{if(T.directory){m?.(T.path);return}if(T.path===Ue||C.kind==="text"&&T.path===C.sourcePath){T.fragment&&jn(T.fragment);return}le(z=>[...z,Ue]),Ae.current=T.path,me(T.fragment),E(null),O(T.path)},Yt=()=>{const T=Q[Q.length-1];T&&(le(z=>z.slice(0,-1)),Ae.current=T,me(null),E(null),O(T))},an=T=>{const{scrollTop:z,scrollLeft:ae}=T.currentTarget;xi(i,n,{top:z,left:ae})},Nn=()=>{if(r){r(Br,wr);return}R&&l(Br,wr)},as=async()=>{if(!(!Ue||Pe.status==="pending")&&!(C.kind==="loading"||C.kind==="error")){ke({status:"pending"});try{await lm(Ue),ke({status:"idle"})}catch(T){ke({status:"error",message:T instanceof Error?T.message:p("rightSidebar.downloadFailed")})}}};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-surface text-foreground",children:[be.popoverNode,e.jsxs("div",{className:`shrink-0 border-b border-border/15 px-3 ${g&&(Bt||vr)?"py-1.5":"py-2"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[g&&h&&e.jsx("button",{type:"button",onClick:h,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p("rightSidebar.backToFileList"),title:p("rightSidebar.backToFileList"),children:e.jsx(cu,{size:16})}),Q.length>0&&e.jsxs("button",{type:"button",onClick:Yt,className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-primary/10 text-primary transition hover:bg-primary/15 active:scale-95 ${g?"w-9":"px-2.5"}`,"aria-label":p("rightSidebar.backToPreviousPreview"),title:p("rightSidebar.backToPreviousPreview"),children:[e.jsx(Ts,{size:15}),!g&&e.jsx("span",{className:"text-[11px] font-medium",children:p("rightSidebar.backToPreviousPreview")})]}),e.jsxs("div",{className:"min-w-0",title:Ue,children:[e.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:Lt.name}),Lt.dir&&e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Lt.dir})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Fr&&e.jsx("button",{type:"button",onClick:at?mr:Rn,className:`inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${at?"bg-surface-elevated text-foreground":"bg-surface-2"}`,"aria-label":p("rightSidebar.findInFile"),title:`${p("rightSidebar.findInFile")} (⌘/Ctrl+F)`,children:e.jsx(Zn,{size:14})}),xr&&C.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{b&&y?.(),Ee(T=>{const z=T==="preview"?"source":"preview";return $t(Eu,z),z}),E(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${g?"w-9 px-0":"px-3"}`,"aria-label":p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),title:p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview"),children:g?pe==="preview"?e.jsx(Di,{size:14}):e.jsx(Ii,{size:14}):p(pe==="preview"?"rightSidebar.markdownSource":"rightSidebar.markdownPreview")}),zs&&C.kind==="text"&&e.jsx("button",{type:"button",onClick:()=>{Z(T=>{const z=T==="preview"?"source":"preview";return Lp(i,n,z),z}),E(null)},className:`inline-flex h-9 shrink-0 items-center justify-center gap-1 rounded-full bg-surface-2 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 ${g?"w-9 px-0":"px-3"}`,"aria-label":p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),title:p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview"),children:g?M==="preview"?e.jsx(Di,{size:14}):e.jsx(Ii,{size:14}):p(M==="preview"?"rightSidebar.htmlSource":"rightSidebar.htmlPreview")}),vr&&e.jsx("button",{type:"button",onClick:()=>{he.current?.toggleFullscreen()},className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95","aria-label":p(Ne?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),title:p(Ne?"rightSidebar.htmlFullscreenExit":"rightSidebar.htmlFullscreenEnter"),children:e.jsx(du,{size:15})}),!g&&e.jsx("button",{type:"button",onClick:()=>s(Ue,yr),...be(pr,yr),className:`inline-flex h-9 items-center gap-1 rounded-full px-3 text-xs font-semibold transition active:scale-95 ${Or||Cn?"bg-surface-elevated text-foreground":"bg-primary/15 text-primary hover:bg-primary/25"}`,title:p("rightSidebar.insertReference",{reference:pr}),children:p(Cn?"rightSidebar.copied":Or?"rightSidebar.inserted":"rightSidebar.insertFileRef")}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard?.writeText(pr)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:p("rightSidebar.copyReference",{reference:pr}),"aria-label":p("rightSidebar.copyFileRef"),children:e.jsx(qh,{size:13})}),e.jsx("button",{type:"button",onClick:()=>{as()},disabled:Pe.status==="pending"||C.kind==="loading"||C.kind==="error",className:"inline-flex h-9 w-9 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95 disabled:opacity-50 disabled:active:scale-100",title:Pe.status==="error"?Pe.message??p("rightSidebar.downloadFailed"):p("rightSidebar.downloadFile"),"aria-label":p("rightSidebar.downloadFile"),children:Pe.status==="pending"?e.jsx(yt,{size:13,className:"animate-spin"}):e.jsx(km,{size:14})})]})]}),at&&Fr&&e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-1.5","data-file-preview-search":!0,children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center rounded-lg bg-surface-2 px-2 focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:13,className:"shrink-0 text-muted-foreground","aria-hidden":"true"}),e.jsx("input",{ref:se,type:"search",value:qt,onChange:T=>lt(T.target.value),onKeyDown:T=>{T.key==="Enter"&&(T.preventDefault(),pt(T.shiftKey?-1:1))},className:"h-8 min-w-0 flex-1 bg-transparent px-2 text-xs text-foreground outline-none placeholder:text-muted-foreground/70",placeholder:p("rightSidebar.findInFilePlaceholder"),"aria-label":p("rightSidebar.findInFile")}),e.jsx("span",{className:"shrink-0 text-[10px] tabular-nums text-muted-foreground","aria-live":"polite",children:ct.length>0?`${Ft+1}/${ct.length}`:"0/0"})]}),e.jsx("button",{type:"button",onClick:()=>pt(-1),disabled:ct.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":p("rightSidebar.previousSearchMatch"),title:`${p("rightSidebar.previousSearchMatch")} (Shift+Enter)`,children:e.jsx(ou,{size:13})}),e.jsx("button",{type:"button",onClick:()=>pt(1),disabled:ct.length===0,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground disabled:opacity-35","aria-label":p("rightSidebar.nextSearchMatch"),title:`${p("rightSidebar.nextSearchMatch")} (Enter)`,children:e.jsx(Sm,{size:13})}),e.jsx("button",{type:"button",onClick:mr,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-surface-2 text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":p("rightSidebar.closeFileSearch"),title:`${p("rightSidebar.closeFileSearch")} (Esc)`,children:e.jsx(Kt,{size:13})})]}),br&&!(g&&(Bt||vr))&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[10px] text-muted-foreground",children:[br.size!==null&&e.jsx("span",{children:p("rightSidebar.byteCount",{count:br.size.toLocaleString()})}),"truncated"in br&&br.truncated&&e.jsx("span",{className:"text-[color:var(--warning)]",children:p("rightSidebar.previewTruncated")}),"mimeType"in br&&e.jsx("span",{children:br.mimeType}),"dimensions"in C&&C.dimensions&&e.jsxs("span",{children:[C.dimensions.width," × ",C.dimensions.height]})]}),!(g&&(Bt||vr))&&!fo&&C.kind!=="binary"&&e.jsx("div",{className:"mt-1 flex h-4 items-center gap-2 text-[10px] text-muted-foreground/75",children:e.jsx("span",{className:"truncate",children:nn?p("rightSidebar.edaPickHint"):Hs?p("rightSidebar.csvTablePreview"):At||es?p("rightSidebar.kicadProjectPickHint"):Rt?p("rightSidebar.videoPreviewHint"):Ws?p("rightSidebar.imagePreviewHint"):Bt?R?p("rightSidebar.selectedLineHint",{lineLabel:Vt??""}):p("rightSidebar.markdownPreviewHint"):vr?p("rightSidebar.htmlPreviewHint"):R?p("rightSidebar.selectedLineHint",{lineLabel:Vt??""}):p("rightSidebar.multiLineHint")})})]}),C.kind==="loading"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-3 py-8 text-center text-sm text-muted-foreground",children:C.mode==="eda"?p("rightSidebar.edaLoading"):C.mode==="image"?p("rightSidebar.loadingImage"):C.mode==="model3d"?p("rightSidebar.model3dLoading"):C.mode==="video"?p("rightSidebar.loadingVideo"):"Loading file…"}):C.kind==="error"?e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto",children:[e.jsx("div",{className:"mx-3 mt-3 border border-destructive/20 bg-destructive/5 px-4 py-4 text-sm text-destructive",children:C.message}),e.jsx("button",{type:"button",onClick:Sn,className:"mx-3 mt-3 rounded-lg bg-surface-2 px-4 py-2 text-sm text-foreground hover:bg-surface-3",children:p("common.retry")})]}):C.kind==="binary"?e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx("div",{className:"mx-3 mt-3 rounded-xl border border-border/15 bg-surface-2 px-4 py-6 text-center text-sm text-muted-foreground",children:p("rightSidebar.binaryPreviewHint")})}):C.kind==="image"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:C.meta.mimeType==="image/svg+xml"?e.jsx(Su,{blobUrl:C.objectUrl,filePath:Ue,viewLabel:"SVG 文件",onInsertAnnotation:u}):e.jsx(Ef,{src:C.objectUrl,alt:Lt.name,vector:!1,onLoad:T=>{const z=T.currentTarget;G(ae=>ae.kind==="image"?{...ae,dimensions:{width:z.naturalWidth,height:z.naturalHeight}}:ae)},onError:()=>G({kind:"error",message:p("rightSidebar.imageLoadFailed")})})}):C.kind==="video"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface p-3",children:e.jsx(zp,{url:C.url,onLoadError:()=>G({kind:"error",message:p("rightSidebar.videoLoadFailed")})})}):C.kind==="eda"?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Xp,{blobUrl:C.objectUrl,filePath:C.sourcePath,view:C.view,board:Ue.toLowerCase().endsWith(".kicad_pcb"),onViewChange:te,onInsertAnnotation:r??u,onRefresh:Sn,interactive3d:xe?e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(Dd,{blobUrl:xe.objectUrl,ext:".glb",fileName:Lt.name,filePath:xe.sourcePath,features:null,onInsertFeature:r??u,unitScale:1e3,dimensionUnit:"mm",coordinateSystemLabel:"KiCad 3D 导出坐标 Y-up",annotationPrefix:"PCB三维标注",normalizePickedPartName:T=>/^[A-Za-z]{1,5}\d+[A-Za-z0-9._-]*$/.test(T)?T:"PCB板体/铜箔/丝印",active:C.view==="pcb-3d"})}):void 0})}):C.kind==="model3d"?e.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden bg-surface",children:e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"min-h-0 flex-1 px-3 py-8 text-center text-sm text-muted-foreground",children:p("rightSidebar.model3dLoading")}),children:e.jsx(Dd,{blobUrl:C.objectUrl,ext:C.ext,fileName:Lt.name,filePath:C.sourcePath,features:L,onInsertFeature:r??u,onRefresh:Sn})})}):C.kind==="text"&&Hs?e.jsx(Qp,{content:C.content,filePath:Ue,onInsertAnnotation:r??u},Ue):C.kind==="text"&&(At||es)?e.jsx(rg,{content:C.content,filePath:Ue,localState:es,onInsertAnnotation:r??u},Ue):Bt?e.jsxs("div",{ref:re,className:"termdock-native-select relative min-h-0 flex-1 overflow-auto bg-surface","data-markdown-preview-scroller":!0,onScroll:tr,style:{touchAction:"pan-x pan-y"},children:[e.jsx(bf,{content:C.content,filePath:C.sourcePath,rootPath:i,lineRange:R,onLineRangeClick:ss,onLineRangeDrag:kr,scrollTop:Ie,outlineOpen:b,outlineCloseSignal:f,onOutlineOpen:k,onOutlineClose:y,lightboxOpen:N,lightboxCloseSignal:I,onLightboxOpen:B,onLightboxClose:_,onLocalLinkOpen:De}),R&&ce&&e.jsxs("button",{type:"button",onClick:Nn,...be(Br,wr),style:{top:ce.top,left:ce.left,transform:"translateY(-50%)"},className:yd(g,sn),title:`Insert markdown reference: ${_r}`,children:[e.jsx(Qa,{size:g?13:11}),rs?p("rightSidebar.copied"):Ur?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Vt??""})]})]}):vr?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:e.jsx(dg,{ref:he,src:Vh(Ue),title:`${Lt.name} preview`,exitFullscreenLabel:p("rightSidebar.htmlFullscreenExit"),onFullscreenChange:Ve},`${Ue}:${dr}:${fr}`)}):C.kind==="text"?e.jsxs("div",{ref:re,onScroll:an,className:`${tl} termdock-native-select termdock-code relative min-h-0 flex-1 overflow-auto rounded-none bg-surface p-2 font-mono text-[11px] leading-relaxed text-foreground`,children:[gr.length>0?e.jsx("div",{className:"min-w-full",children:gr.map((T,z)=>{const ae=z+1,Se=!!(R&&ae>=R.start&&ae<=R.end),He=Me&&Me.length===gr.length?Me[z]:null;return e.jsxs("div",{ref:Fe=>{Fe?K.current.set(ae,Fe):K.current.delete(ae)},role:"button","data-file-preview-line":ae,tabIndex:0,onClick:Fe=>ns(Fe,ae),onKeyDown:Fe=>{Fe.key!=="Enter"&&Fe.key!==" "||(Fe.preventDefault(),ns(Fe,ae))},style:{gridTemplateColumns:`${Us}ch 1fr`},className:`group grid w-max min-w-full cursor-text gap-2 rounded-md pr-1 text-left transition ${Se?"bg-[var(--surface-2)] text-foreground":"hover:bg-surface-2"}`,title:`Tap to reference ${pr}:${ae}`,children:[e.jsx("span",{className:`select-none rounded text-right text-[10px] transition ${Se?"bg-[var(--surface-elevated)] text-muted-foreground":"text-muted-foreground/55"}`,children:ae}),e.jsx("span",{className:"whitespace-pre select-text","data-sidebar-selectable":!0,children:He??(T||" ")})]},z)})}):"Empty file.",R&&ce&&e.jsxs("button",{type:"button",onClick:Nn,...be(Br,wr),style:{top:ce.top,left:ce.left,transform:"translateY(-50%)"},className:yd(g,sn),title:`Insert code reference: ${_r}`,children:[e.jsx(Qa,{size:g?13:11}),rs?p("rightSidebar.copied"):Ur?p("rightSidebar.inserted"):p("rightSidebar.insertLineRef",{lineLabel:Vt??""})]})]}):null]})}function qb({isOpen:r,sessionId:n,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h=!1,onTogglePinned:m,rightSidebarFilePreviewOpen:g=!1,rightSidebarFilePreviewCloseSignal:b,onOpenRightSidebarFilePreview:f,onCloseRightSidebarFilePreview:k,rightSidebarRepoPickerOpen:y=!1,rightSidebarRepoPickerCloseSignal:N,onOpenRightSidebarRepoPicker:I,onCloseRightSidebarRepoPicker:B,markdownOutlineOpen:_=!1,markdownOutlineCloseSignal:R,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:P=!1,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:p}){const{t:i,locale:O}=wt(),[C,G]=a.useState(""),[fe,te]=a.useState(null),xe=J(t=>t.rightSearchOpen),W=J(t=>t.setRightSearchOpen),Y=J(t=>t.rightSidebarLayoutPreference),L=J(t=>t.setRightSidebarLayoutPreference),[D,K]=a.useState(()=>Og()),[re,ce]=a.useState("."),[ve,pe]=a.useState(""),[Ee,M]=a.useState(!1),[Z,he]=a.useState(!1),[Ne,Ve]=a.useState(!1),[Ce,Ye]=a.useState(!1),Ie=a.useDeferredValue(C),[S,Q]=a.useState(null),[le,q]=a.useState([]),[me,Ae]=a.useState([]),oe=J(t=>t.contextKey?t.activeGitRepos[t.contextKey]??null:null),Me=J(t=>t.setActiveGitRepo),[st,Pe]=a.useState(null),[ke,at]=a.useState(null),[et,qt]=a.useState(null),[lt,ct]=a.useState(()=>ut(Ld,Ms)??!1),[Dr,Ft]=a.useState(()=>ut(Ad,Ms)??!1),[H,se]=a.useState(()=>ut(Pd,Ms)??!1),[be,We]=a.useState(()=>ut(hi,Ig)??""),[ft,dr]=a.useState(0),[ur,_t]=a.useState(!1),[fr,hr]=a.useState(!1),Sn=a.useRef(null),jn=a.useRef(null),[Fr,mr]=a.useState(!1),[Rn,pt]=a.useState(null),[Ue,Lt]=a.useState(null),[pr,gr]=a.useState(()=>_d(ui)),[Us,br]=a.useState(()=>_d($d)),[xr,Hs]=a.useState(()=>Tg()),[At,es]=a.useState(()=>Dg()),[Bt,zs]=a.useState(()=>_g()),vr="words",[Ws,fo]=a.useState(0),[Rt,nn]=a.useState([]),[ts,_r]=a.useState([]),[Br,yr]=a.useState(!1),[wr,Or]=a.useState(null),[Ur,Cn]=a.useState([]),[rs,sn]=a.useState(!1),[Vt,Hr]=a.useState([]),[ns,ss]=a.useState([]),[kr,tr]=a.useState(!1),[De,Yt]=a.useState(null),[an,Nn]=a.useState([]),[as,T]=a.useState({}),[z,ae]=a.useState(!1),[Se,He]=a.useState(null),[Fe,Oe]=a.useState(null),[Ge,tt]=a.useState(null),[Ct,rr]=a.useState(null),[Xt,En]=a.useState(!1),[os,on]=a.useState(""),zr=a.useDeferredValue(os),[Sr,ho]=a.useState({}),[ln,X]=a.useState([]),[ze,Pt]=a.useState(!1),[Wr,is]=a.useState(!1),[ul,Mn]=a.useState(null),[mo,$n]=a.useState(!1),nr=a.useRef(null),Gr=a.useRef(0),fl=a.useRef({count:0,loading:!1,loadingMore:!1,hasMore:!1}),[Mf,Gs]=a.useState(null),[ls,hl]=a.useState(()=>ut(fi,Ms)??!1),[po,go]=a.useState(!1),[Ks,bo]=a.useState([]),[jr,qs]=a.useState({}),[Nt,Vs]=a.useState({}),[Kr,ml]=a.useState(!0),[pl,gl]=a.useState(()=>new Set),[rt,qr]=a.useState(null),[xo,Vr]=a.useState(null),[$f,Rr]=a.useState(!1),[bl,Cr]=a.useState(0),[,vo]=a.useState(0),[yo,Ys]=a.useState(!1),[sr,wo]=a.useState(!1),[Lf,xl]=a.useState(()=>J.getState().rightTab==="diff"),[ko,So]=a.useState(()=>J.getState().rightTab==="android"),[Yr,vl]=a.useState(!1),Af=rd(t=>!!t.docks[ud]),[_e,cs]=a.useState(null),[Ln,ds]=a.useState(null),[gt,Xr]=a.useState(null),[yl,bt]=a.useState(null),[An,wl]=a.useState(null),[jo,Pf]=a.useState(()=>Date.now()),[Tf,If]=a.useState(!1),[cn,Xs]=a.useState(!1),[Js,kl]=a.useState(""),[Pn,Zs]=a.useState(""),[dn,Qs]=a.useState(""),[un,ea]=a.useState(""),[Sl,Tn]=a.useState(null),[ta,ra]=a.useState(!1),[jl,Ro]=a.useState(!1),[Rl,Cl]=a.useState(!1),[na,Df]=a.useState({key:null,nonce:0}),Nl=a.useRef(null),El=a.useRef(null),ee=cm(s,h,Y),Ff=_u(ee,h,Bt),[Co,No]=a.useState(()=>qg(s)),Eo=J(t=>t.rightTab),Jt=J(t=>t.setRightTab),v=J(t=>t.rootPath),In=J(t=>t.explorerRoot),Ml=J(t=>t.pinnedExplorerRootsCache),$l=J(t=>t.hydratePinnedExplorerRoots),Ll=J(t=>t.syncPinnedExplorerRoots),Ot=J(t=>t.setExplorerRoot),Al=J(t=>t.resetExplorerToProject),Dn=J(t=>t.pinExplorerRoot),fn=J(t=>t.unpinExplorerRoot),Je=J(t=>t.selectedFilePath),Ze=J(t=>t.selectFile),Mo=J(t=>t.showHiddenFiles),_f=J(t=>t.toggleShowHiddenFiles),$o=J(t=>!!(v&&t.nestedGitScanRoots[v])),we=J(t=>t.changedFiles),sa=J(t=>t.setChangedFiles),aa=J(t=>t.invalidateDirectoryCache),Bf=J(t=>t.setDirectorySortMode),Pl=J(t=>t.applyFileWatchEvents),Tl=J(t=>t.reconcileDirectoryCache),Il=J(t=>t.bumpFileWatchEpoch),Jr=J(t=>t.gitBundleLoading),Dl=J(t=>t.gitBundleSlow),hn=J(t=>t.gitBundleError),Fn=J(t=>t.gitBundleLastLoadedAt),Fl=J(t=>t.beginGitBundleLoading),_l=J(t=>t.setGitBundleSlowFor),Lo=J(t=>t.finishGitBundleLoading),oa=J(t=>t.resetGitBundleLoading),Ao=J(t=>t.setGitBundleError),Bl=J(t=>t.markGitBundleLoaded),ge=In??v,Ol=a.useMemo(()=>ge?pg(ge,re):"",[ge,re]),us=a.useMemo(()=>mg(ve),[ve]),Ul=a.useMemo(()=>({excludePatterns:us,caseSensitive:Z,wholeWord:Ne,regex:Ce}),[Z,us,Ce,Ne]),ia=J(t=>ge?t.fileSortModes[ge]??"name":"name"),Hl=J(t=>!!(ge&&t.directoryCache.has(ge))),_n=a.useRef(null),kt=a.useRef(0),[zl]=a.useState(()=>++Ub),Nr=a.useRef(null),Zr=a.useRef(null),la=a.useRef(0),Ut=a.useRef(new Map),Ht=a.useRef(new Map),ar=a.useRef(new Set),mn=a.useRef(new Set),pn=a.useRef(0),Qr=a.useRef(null),Bn=a.useRef(0),On=a.useRef(null),Un=a.useRef(0),en=a.useRef(null),Po=a.useRef(new Set),To=a.useRef(null),Io=a.useRef(null),ca=a.useRef(null),Do=a.useRef(null),Fo=a.useRef(null),fs=a.useRef(new Set);a.useEffect(()=>{if(An===null)return;const t=Math.max(0,Date.now()-An),o=t<6e4?1e3:t<36e5?6e4:t<864e5?36e5:864e5,d=Math.max(50,o-t%o),x=window.setTimeout(()=>Pf(Date.now()),d);return()=>window.clearTimeout(x)},[jo,An]);const da=a.useRef(null),Er=a.useRef(null),ua=a.useRef(null),hs=a.useRef(null),je=a.useCallback(t=>J.getState().rootPath===t,[]);a.useEffect(()=>{if(!r||typeof window>"u")return;const t=o=>{const d=Gb(o.target);d&&Va("global_change_row_event",{...Kb(o),selectionPath:d.dataset.diffSelectionPath,filePath:d.dataset.diffFilePath,absolutePath:d.dataset.diffAbsolutePath,repoRoot:d.dataset.diffRepoRoot,status:d.dataset.diffStatus,selectedFilePath:J.getState().selectedFilePath,rightTab:J.getState().rightTab,activeGitRepoRoot:oe,changedFiles:J.getState().changedFiles.size})};return window.addEventListener("pointerdown",t,{capture:!0}),window.addEventListener("click",t,{capture:!0}),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),window.removeEventListener("click",t,{capture:!0})}},[oe,r]);const Wl=a.useCallback(async(t=v??void 0)=>{if(!t)return null;if(ar.current.has(t)||mn.current.has(t))return nt("untracked_skip_cached",{cwd:t,rootPath:v,completed:ar.current.has(t),running:mn.current.has(t)}),null;const o=v,d=la.current+1;la.current=d,Ut.current.set(t,d);const x=`right-sidebar-git-untracked:${t}`,w=new AbortController;Ht.current.set(t,w),mn.current.add(t),nt("untracked_start",{requestId:d,cwd:t,rootPath:v});try{let j=await nd(t,w.signal,x),A=0;for(;j.status==="running"&&A<120;){if(Ut.current.get(t)!==d||w.signal.aborted)return nt("untracked_stale_result",{requestId:d,activeRequestId:Ut.current.get(t),cwd:t,status:j.status}),null;if(!je(o))return nt("untracked_root_changed",{requestId:d,cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath}),null;await new Promise(ne=>window.setTimeout(ne,A<10?1e3:3e3)),A+=1,j=await nd(t,w.signal,x)}if(Ut.current.get(t)!==d||!je(o))return nt("untracked_stale_result",{requestId:d,activeRequestId:Ut.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,files:j.files.length,status:j.status}),null;if(j.status==="done")return sa(wf(J.getState().changedFiles,j.files)),j.files.length>0&&q(ne=>{const $e=new Map(ne.map(Le=>[Le.root,Le])).get(t);if(!$e)return ne;const Be=Mb($e.files,j.files),Re=ne.map(Le=>Le.root===t?{...Le,files:Be,context:Le.context?{...Le.context,changedFiles:Be.map(Ke=>({path:Ke.path,absolutePath:Ke.absolutePath,status:Ke.status})),truncated:!1}:Le.context,untrackedDeferred:!1}:Le);Ae(kf(Re,v));const ie=Re.find(Le=>Le.root===v);return ie?.context&&Q(Le=>Le?.root===ie.root?{...Le,...ie.context}:Le),Re}),ar.current.add(t),nt("untracked_apply",{requestId:d,cwd:t,files:j.files.length}),j;const ue=j.error||(j.status==="running"?"Untracked file scan is still running.":"Failed to scan untracked files");return ar.current.add(t),nt("untracked_error",{requestId:d,cwd:t,message:ue,code:j.code,status:j.status}),null}catch(j){if(Ut.current.get(t)!==d||!je(o)||Pr(j))return nt("untracked_aborted",{requestId:d,activeRequestId:Ut.current.get(t),cwd:t,expectedRootPath:o,currentRootPath:J.getState().rootPath,message:j instanceof Error?j.message:String(j)}),null;const A=j instanceof Error?j.message:"Failed to scan untracked files";return ar.current.add(t),nt("untracked_error",{requestId:d,cwd:t,message:A}),null}finally{Ht.current.get(t)===w&&Ht.current.delete(t),Ut.current.get(t)===d&&Ut.current.delete(t),mn.current.delete(t)}},[S,je,v,sa]),Zt=a.useMemo(()=>{const t=new Set(me.map(d=>d.root)),o=Ur.filter(d=>t.has(d));return o.length>0?o:oe?[oe]:[]},[oe,Ur,me]),Gl=Zt.length===0,gn=a.useMemo(()=>Zt.map(t=>le.find(o=>o.root===t)).filter(t=>!!t),[Zt,le]),Of=a.useMemo(()=>me.map(t=>({root:t.root,label:t.label,branch:t.branch??null})),[me]),or=a.useCallback(async()=>{if(!v){nn([]),_r([]);return}const t=v,o=Bn.current+1;Bn.current=o,On.current?.abort();const d=new AbortController;On.current=d,yr(Rt.length===0),Or(null);try{const x=Zt.length>0?await Promise.all(Zt.map(w=>sd({workspaceRoot:v,repoRoot:w},d.signal))).then(w=>({records:w.flatMap(j=>j.records),walkthroughs:w.flatMap(j=>j.walkthroughs??[])})):await sd({workspaceRoot:v},d.signal);if(Bn.current!==o||!je(t))return;nn(x.records),_r(x.walkthroughs??[])}catch(x){if(Bn.current!==o||!je(t)||Pr(x))return;Or(x instanceof Error?x.message:"Failed to load change audit explanations")}finally{On.current===d&&(On.current=null),Bn.current===o&&je(t)&&yr(!1)}},[Rt.length,Zt,je,v]),fa=a.useCallback(async(t,o,d)=>{if(!t&&!v){Hr([]),ss([]);return}const x=v,w=Un.current+1;Un.current=w,en.current?.abort();const j=new AbortController;en.current=j;try{const A=t?[t]:Array.from(new Set([v,...le.map(ne=>ne.root)].filter(ne=>!!ne))),ue=await Promise.all(A.map(ne=>Xh({repoRoot:ne,baseRef:o,branchName:d},j.signal))).then(ne=>{const V=new Map,$e=new Map;for(const Be of ne){for(const Re of Be.records)V.set(Re.id,Re);for(const Re of Be.walkthroughs??[])$e.set(Re.id,Re)}return{records:Array.from(V.values()),walkthroughs:Array.from($e.values())}});if(Un.current!==w||!je(x))return;Hr(ue.records),ss(ue.walkthroughs??[])}catch(A){if(Un.current!==w||!je(x)||Pr(A))return;console.warn("[RightSidebar] Failed to load branch explanations",A)}finally{en.current===j&&(en.current=null)}},[le,je,v]),tn=a.useCallback((t,o={})=>{if(!je(v)){nt("apply_skipped_root_changed",{expectedRootPath:v,currentRootPath:J.getState().rootPath,bundleRoot:t.context?.root,files:t.files.length});return}nt(t.files.length===0?"empty_bundle":"apply",{rootPath:v,available:t.available,files:t.files.length,repositories:t.repositories?.map(ie=>({root:ie.root,relativeRoot:ie.relativeRoot,files:ie.files.length,available:ie.available,error:ie.error})),repoFilters:t.repoFilters?.map(ie=>({root:ie.root,label:ie.label,count:ie.count})),cached:t.cached,stale:t.stale,cacheAgeMs:t.cacheAgeMs,untrackedDeferred:t.untrackedDeferred,error:t.error});let d=Bu(t),x=t.repoFilters??[],w=t.files;const j=J.getState().changedFiles;if(!!(o.cacheOnly&&!t.cached&&t.files.length===0&&d.length===0)&&(j.size>0||le.length>0||S)){nt("cache_only_apply_skipped_empty_backend_cache",{rootPath:v,currentFiles:j.size,currentRepositories:le.length});return}const ue=d.some(ie=>ie.deferred);if(ue&&!o.replaceWorkspace){const ie=new Set(d.filter(Ke=>!Ke.deferred||Ke.root===v).map(Ke=>Ke.root));w=[...Array.from(j.values()).filter(Ke=>!ie.has(mt(Ke,v)??"")),...t.files]}const ne=Xd(j.values(),v),V=Xd(t.files,v),$e=d.some(ie=>ie.root!==v);if(!!(o.background&&!ue&&!o.replaceWorkspace&&j.size>0&&(t.files.length===0&&!t.error||ne>0&&V===0&&!$e))){nt("background_apply_skipped_degraded_bundle",{rootPath:v,currentFiles:j.size,nextFiles:t.files.length,currentNestedCount:ne,nextNestedCount:V,nextRepositories:d.map(ie=>({root:ie.root,relativeRoot:ie.relativeRoot,files:ie.files.length})),cached:t.cached,stale:t.stale,error:t.error});return}if(o.replaceRepoRoot){const ie=Sf(j.values(),le,t,o.replaceRepoRoot,v);w=ie.files,d=ie.repositories,x=ie.repoFilters}if(sa(yf(w)),q(d),Ae(x),Fo.current=v,o.syncActiveRepo!==!1){const{contextKey:ie,activeGitRepos:Le}=J.getState(),Ke=ie?Le[ie]??null:null,Dt=o.activeRepoRoot!==void 0?o.activeRepoRoot:Ke,Te=Ug({...t,repositories:d,repoFilters:x},Dt);Me(Te)}typeof t.cacheUpdatedAt=="number"&&wl(t.cacheUpdatedAt),Q(ie=>{if(o.replaceRepoRoot&&o.replaceRepoRoot!==v)return ie;if(!t.context)return null;const Le=ie?.root??v;return!ie?.available||Le!==(t.context.root??v)?t.context:{...ie,...t.context}}),o.reloadDiff&&fo(ie=>ie+1);const Re=J.getState().selectedFilePath;if(Re&&!Re.startsWith("/")&&!w.some(ie=>ie.path===Re||ie.absolutePath===Re)&&Ze(null),gr(ie=>{const Le=new Set(w.map(Dt=>mt(Dt,v)).filter(Boolean)),Ke=new Set;for(const Dt of ie)Le.has(Dt)&&Ke.add(Dt);return pi(ui,Ke),Ke}),o.loadDeferred!==!1){const ie=d.filter(Le=>Le.untrackedDeferred&&Le.root).map(Le=>Le.root);for(const Le of ie)Wl(Le)}o.loadAudit!==!1&&or()},[je,or,Wl,v,Ze,Me,sa]);a.useEffect(()=>{oa(),To.current=null,Io.current=v;const t=[],o=[];kt.current+=1,pn.current+=1,la.current+=1,Nr.current?.abort(),jt(Jn(Zr.current?.cwd??v??void 0)),Zr.current=null,Nr.current=null,Qr.current?.abort(),jt("right-sidebar-git-details"),Qr.current=null;for(const A of Ht.current.values())A.abort();for(const A of Ht.current.keys())jt(`right-sidebar-git-untracked:${A}`);Ht.current.clear(),Ut.current.clear(),Bn.current+=1,On.current?.abort(),On.current=null,Un.current+=1,en.current?.abort(),en.current=null,Gr.current+=1,nr.current?.abort(),jt("right-sidebar-recent-commits"),nr.current=null,nn([]),_r([]),yr(!1),Or(null),Cn([]),sn(!1),Hr([]),ss([]),tr(!1),Yt(null),ae(!1),He(null),Oe(null),tt(null),rr(null),En(!1),on(""),X([]),Pt(!1),is(!1),Mn(null),$n(!1),Gs(null),qr(null),Vr(null),hl(!1),$t(fi,!1),go(!1);const d=v?Bd()[v]:null,x=d?.previewEntries??[],w=d?.selectedPreviewKey??null,j=w?x.find(A=>A.key===w)??null:null;bo(d?.selectedRepoRoots??[]),qs(d?.repoTargetBranches??{}),Vs(d?.repoBaseBranches??{}),Nn(x),T(d?.previewScrollTops??{}),j&&d?.previewDetailOpen&&(j.diff.hunks?.length??0)>0&&(Yt(j.diff),qr(j.key),Vr(d.selectedPreviewFileKey??(j.diff.hunks?.[0]?`${j.diff.hunks[0].filePath}\0${j.diff.hunks[0].hunkHeader}\0${j.diff.hunks[0].hunkIndex}`:null)),tr(!0)),ml(d?.includeUncommitted??!0),To.current=v,Xs(!1),ar.current.clear(),mn.current.clear(),cs(null),ds(null),Xr(null),bt(null),wl(null),q(t),Ae(o),Q(null),Do.current=null,Fo.current=null,fs.current.clear()},[oa,v]);const Qt=a.useCallback(async(t=v??void 0,o={})=>{if(!t)return null;const d=v,x=kt.current;if(await rp(()=>Promise.all([J.getState().hydrateNestedGitScanRoots(),J.getState().hydrateActiveGitRepos()]).then(()=>{})),kt.current!==x||!je(d))return null;const w=t===v&&Yn(v),j=o.includeNested??w,A=o.refresh??o.reloadDiff??!1,ue=o.cacheOnly??!1,ne=o.background??!1,V=j&&(o.discoverOnly??!1);A&&ar.current.clear();const $e=Zr.current;if($e&&$e.cwd===t&&$e.includeNested===j&&$e.refresh===A&&$e.cacheOnly===ue&&$e.discoverOnly===V)return nt("reuse_pending",{cwd:t,includeNested:j,refresh:A,cacheOnly:ue,discoverOnly:V}),$e.promise;const Be=kt.current+1;kt.current=Be;const Re=`right-sidebar:${zl}:${Be}`;Nr.current?.abort();const ie=Jn(t);jt(ie);const Le=new AbortController;Nr.current=Le;let Ke=null;ne||Fl(Re),Ao(null),nt("start",{requestId:Be,cwd:t,rootPath:v,requestSlotId:ie,includeNested:j,refresh:A,cacheOnly:ue,background:ne,existingChanges:we.size,lastLoadedAt:Fn}),!ne&&typeof window<"u"&&(Ke=window.setTimeout(()=>{kt.current===Be&&_l(Re,!0)},jg));const Dt=(async()=>{const Te=await Ta(t,Le.signal,{includeNested:j,refresh:A,cacheOnly:ue,discoverOnly:V,action:A?"manual_git_refresh":"open_sidebar_git_refresh",requestSlotId:ie,requestTimeoutMs:A?null:void 0});if(Ab(Te)){if(nt("cancelled_result_ignored",{requestId:Be,activeRequestId:kt.current,cwd:t,error:Te.error??Te.context?.error}),Le.signal.aborted)return null;throw new Error(Te.error??Te.context?.error??"Failed to load Git changes")}return kt.current!==Be||!je(d)?(nt("stale_result",{requestId:Be,activeRequestId:kt.current,cwd:t,expectedRootPath:d,currentRootPath:J.getState().rootPath,files:Te.files.length,repositories:Te.repositories?.length??0}),null):(tn(Te,{reloadDiff:o.reloadDiff,syncActiveRepo:o.replaceWorkspace?!0:j,background:ne,cacheOnly:ue,replaceRepoRoot:o.replaceRepoRoot,replaceWorkspace:o.replaceWorkspace}),Te)})();Zr.current={cwd:t,includeNested:j,refresh:A,cacheOnly:ue,discoverOnly:V,promise:Dt};try{const Te=await Dt;return kt.current===Be&&Te&&je(d)?Bl({cached:Te.cached,stale:Te.stale,cacheAgeMs:Te.cacheAgeMs,nestedDeferred:!j||Te.nestedDeferred,untrackedDeferred:Te.untrackedDeferred}):kt.current===Be&&je(d)&&Lo(Re),Te}catch(Te){return kt.current!==Be||!je(d)||Le.signal.aborted?(nt("aborted",{requestId:Be,activeRequestId:kt.current,cwd:t,expectedRootPath:d,currentRootPath:J.getState().rootPath,message:Te instanceof Error?Te.message:String(Te)}),null):(nt("error",{requestId:Be,cwd:t,includeNested:j,refresh:A,background:ne,message:Te instanceof Error?Te.message:String(Te)}),ne||(Q(null),Ao(Te instanceof Error?Te.message:"Failed to load Git changes")),null)}finally{Ke!==null&&window.clearTimeout(Ke),Nr.current===Le&&(Nr.current=null),Zr.current?.promise===Dt&&(Zr.current=null),!ne&&kt.current===Be&&je(d)&&Lo(Re)}},[tn,Fl,we.size,Lo,zl,Fn,je,Bl,v,Ao,_l]),ms=a.useCallback(async()=>{v&&await Qt(v,{reloadDiff:!0,refresh:!0})},[Qt,v]),_o=a.useCallback(async(t=v??void 0)=>{if(!t)return null;const o=v,d=pn.current+1;pn.current=d,Qr.current?.abort(),jt("right-sidebar-git-details");const x=new AbortController;Qr.current=x,Xs(!0);try{const w=await ad(t,x.signal,"load_git_details","right-sidebar-git-details");return pn.current!==d||!je(o)?null:(q(j=>j.map(A=>A.root===w.root?{...A,available:w.available,context:w,error:w.error}:A)),Q(j=>j?.root&&w.root&&j.root!==w.root?j:!j?.available||!w.available?w:{...j,...w}),w)}catch(w){return Pr(w)||!je(o)||pn.current===d&&bt(w instanceof Error?w.message:"Failed to load Git details"),null}finally{Qr.current===x&&(Qr.current=null),pn.current===d&&je(o)&&Xs(!1)}},[je,v]);a.useEffect(()=>{if(!r){kt.current+=1,oa(),Do.current=null,pn.current+=1,la.current+=1,Nr.current?.abort(),jt(Jn(Zr.current?.cwd??v??void 0)),Zr.current=null,Nr.current=null,Qr.current?.abort(),jt("right-sidebar-git-details"),Qr.current=null;for(const t of Ht.current.values())t.abort();for(const t of Ht.current.keys())jt(`right-sidebar-git-untracked:${t}`);Ht.current.clear(),Ut.current.clear(),Un.current+=1,en.current?.abort(),en.current=null,Gr.current+=1,nr.current?.abort(),jt("right-sidebar-recent-commits"),nr.current=null,Xs(!1),ae(!1),He(null),Oe(null),tt(null),rr(null),En(!1),on(""),X([]),Pt(!1),is(!1),Mn(null),$n(!1),G(""),W(!1),pt(null),wo(!1),ee&&xl(!1)}},[ee,r,oa,W]),a.useEffect(()=>{if(!xe)return;const t=setTimeout(()=>{document.querySelector("input[data-right-search]")?.focus()},50);return()=>clearTimeout(t)},[xe]),a.useEffect(()=>{ee||Rr(!1)},[ee]);const ps=a.useCallback(t=>{vo(t);const o=ua.current;o&&(o.update(),o.slideTo(t,0),window.requestAnimationFrame(()=>{o.update(),o.slideTo(t,0)}))},[]);a.useEffect(()=>{if(ee)if(Rr(g),g&&Je){Cr(1);const t=Er.current;t&&(t.update(),t.activeIndex!==1&&(hs.current=1,t.slideTo(1,0)))}else{Cr(0);const t=Er.current;t&&t.activeIndex!==0&&(hs.current=0,t.slideTo(0,0)),pt(null)}},[ee,g,v,Je]),a.useEffect(()=>{if(b!==void 0&&!g){Cr(0);const t=Er.current;t&&t.activeIndex!==0&&(hs.current=0,t.slideTo(0,0)),Rr(!1),pt(null)}},[b,g]),a.useEffect(()=>{N!==void 0&&Pe(null)},[N]),a.useEffect(()=>{!ee&&g&&k?.()},[ee,k,g]),a.useEffect(()=>{No(t=>Wi(t,s))},[s]);const Uf=a.useCallback(t=>{ee||(t.preventDefault(),da.current={startX:t.clientX,startWidth:Co,pointerId:t.pointerId},t.currentTarget.setPointerCapture(t.pointerId))},[Co,ee]),Hf=a.useCallback(t=>{const o=da.current;if(!o||o.pointerId!==t.pointerId)return;const d=Wi(o.startWidth+t.clientX-o.startX,s);No(d),$s(Es,d,Sg)},[s]),Kl=a.useCallback(t=>{const o=da.current;if(!(!o||o.pointerId!==t.pointerId)){da.current=null,js(Es);try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}}},[]),Hn=!!(v&&Fn!==null&&Qd(S)),Bo=!!(v&&!hn&&we.size===0&&Fn===null),ir=(()=>{let t=Eo;return t==="android"&&!Yr&&(t="files"),Hn&&(t==="git"||t==="diff")&&(t="files"),t})(),Qe=ir==="git",zn=ir==="files",St=ir==="diff",Wn=ir==="android",zf=jm(t=>t.overlay==="sidebar")&&Wn;a.useEffect(()=>{if(!ee){Ys(!0);return}if(!r){const o=window.setTimeout(()=>{Ys(!1)},Ng);return()=>window.clearTimeout(o)}Ys(!1);const t=window.setTimeout(()=>{Ys(!0)},Cg);return()=>window.clearTimeout(t)},[ee,r]),a.useEffect(()=>{if(!ee||!St)return;const t=ua.current;if(!t)return;const o=window.requestAnimationFrame(()=>{t.update()});return()=>window.cancelAnimationFrame(o)},[St,ee]),a.useEffect(()=>{if(!Hn||!v||Jr)return;const t=window.setTimeout(()=>{Qt(v,{background:!0})},3e3);return()=>window.clearTimeout(t)},[Hn,v,Jr,Qt]);const Wf=a.useCallback(t=>{Qt(t,{discoverOnly:!0})},[Qt]);np({active:r&&(Qe||St),rootPath:v,loading:Jr,delay:Qe&&!ee?0:mi,lastStartedRoot:Do,load:Wf}),a.useEffect(()=>{!r||!Qe||(!ee||yo)&&wo(!0)},[Qe,ee,r,yo]),a.useEffect(()=>{if(!r||Qe)return;const t=window.setTimeout(()=>{wo(!0)},mi);return()=>window.clearTimeout(t)},[Qe,r]),a.useEffect(()=>{St&&xl(!0)},[St]),a.useEffect(()=>{!r||!Wn||So(!0)},[Wn,r]),a.useEffect(()=>{if(r&&Wn||!ko)return;const t=window.setTimeout(()=>So(!1),Rg);return()=>window.clearTimeout(t)},[r,Wn,ko]),a.useEffect(()=>{So(!1)},[n]),a.useEffect(()=>{let t=!1;return tu().then(o=>{!t&&o.androidPanel&&vl(o.androidPanel.enabled===!0)}).catch(()=>{}),()=>{t=!0}},[]);const Gf=a.useCallback(t=>{vl(t),t?Jt("android"):J.getState().rightTab==="android"&&Jt("files"),Ei({androidPanel:{enabled:t}}).catch(()=>{})},[Jt]),ql=a.useCallback(t=>{ge&&jb(ge,t.currentTarget.scrollTop)},[ge]);a.useEffect(()=>()=>{Nr.current?.abort(),js(Qi),js(el),js(Es),js(hi)},[]),a.useEffect(()=>{if(!ge||!Hl)return;const t=xf()[ge]?.top;if(typeof t!="number")return;let o=window.requestAnimationFrame(()=>{_n.current&&(_n.current.scrollTop=t),o=window.requestAnimationFrame(()=>{_n.current&&(_n.current.scrollTop=t)})});return()=>window.cancelAnimationFrame(o)},[ge,Hl]),a.useEffect(()=>{if(!r)return;const t=new AbortController;return Jh(t.signal).then(o=>Cl(!!o.available)).catch(()=>Cl(!1)),()=>t.abort()},[r]);const gs=a.useCallback(t=>{if(te(null),Ze(t),pt(null),ee){Rr(!0),Cr(1),Er.current?.slideTo(1),f?.();return}},[ee,f,Ze]),Vl=a.useCallback((t,o)=>{if(te(null),Ze(t),Lt(o),ee){Rr(!0),Cr(1),Er.current?.slideTo(1),f?.();return}},[ee,f,Ze]),bs=a.useCallback(async(t,o)=>{const d=o||In||v;if(!(!d||t.length===0)){ra(!0);try{await Ns(d,t),aa(d,!1)}catch(x){bt(x instanceof Error?x.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>bt(null),4e3)}finally{ra(!1)}}},[In,v,aa,i]),Yl=a.useCallback(async t=>{try{await Zh(t)}catch(o){bt(o instanceof Error?o.message:i("fileTree.openInFileBrowserFailed")),window.setTimeout(()=>bt(null),4e3)}},[i]),ha=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),t.dataTransfer.types.includes("Files")&&Ro(!0)},[]),Xl=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ro(!1)},[]),Jl=a.useCallback(t=>{t.preventDefault(),t.stopPropagation(),Ro(!1);const o=t.dataTransfer.files;o.length>0&&bs(Array.from(o))},[bs]),Oo=a.useCallback(t=>{at(t),window.setTimeout(()=>at(o=>o===t?null:o),1400)},[]),Mr=a.useCallback(t=>{qt(t),window.setTimeout(()=>qt(o=>o===t?null:o),1400)},[]);a.useEffect(()=>{$t(Ld,lt)},[lt]),a.useEffect(()=>{$t(Ad,Dr)},[Dr]),a.useEffect(()=>{$t(Pd,H)},[H]),a.useEffect(()=>{$s(hi,be,xg)},[be]),a.useEffect(()=>($l().catch(()=>{}),od(t=>{t.type==="pinned-explorer-roots"&&Ll(t.pinnedExplorerRoots)})),[$l,Ll]);const Zl=a.useRef(crypto.randomUUID?.()??`draft-${Math.random().toString(36).slice(2)}`),ma=a.useRef(null),bn=a.useRef(null),[Ql,Uo]=a.useState(!1);a.useEffect(()=>{if(!r)return;Uo(!1);let t=!1;Qh().then(d=>{t||(ma.current=d.text,We(x=>d.text&&d.text!==x?d.text:x),Uo(!0))}).catch(()=>{t||Uo(!0)});const o=od(d=>{d.type==="context-draft"&&d.origin!==Zl.current&&(ma.current=d.text,We(d.text))});return()=>{t=!0,o(),bn.current!==null&&(window.clearTimeout(bn.current),bn.current=null)}},[r]),a.useEffect(()=>{if(!Ql||ma.current===be)return;bn.current!==null&&window.clearTimeout(bn.current);const t=be;bn.current=window.setTimeout(()=>{bn.current=null,em(t,Zl.current).then(()=>{ma.current=t}).catch(()=>{})},500)},[be,Ql]);const Gn=a.useCallback((t,o,d)=>{if(t){if(tm(d?t+d:t)){Oo(o);return}lt?(We(x=>Ep(x,t)+(d??"")),window.matchMedia("(pointer: coarse)").matches||(Ft(!1),dr(x=>x+1))):window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:d?t+d:t,focus:!0}})),Oo(o)}},[lt,Oo]),pa=a.useCallback(t=>{const o=Da(t,v);return Rm(o,v)},[v]),Ho=bu(Mr),lr=a.useCallback((t,o)=>{const d=Da(t,v);Gn(Cm(d,v),o??`path:${d}`)},[v,Gn]),Kf=a.useCallback(async t=>{ra(!0);try{await fd(t,Ns,o=>{lr(o,`path:${o}`)}),ee&&!lt&&l()}catch(o){bt(o instanceof Error?o.message:i("rightSidebar.uploadFailed")),window.setTimeout(()=>bt(null),4e3)}finally{ra(!1)}},[lt,lr,ee,l,i]),[zo,ec]=a.useState([]),qf=a.useCallback(t=>{ec(o=>[...o,t])},[]),tc=a.useCallback(async t=>{await fd(t,Ns,o=>{lr(o,`path:${o}`)})},[lr]),$r=a.useCallback((t,o)=>{if(!t)return;const d=t.includes(`
1660
1660
  `)?`
1661
1661
  `:void 0;Gn(t.endsWith(`
1662
- `)||t.endsWith(" ")?t:`${t} `,o,d)},[Gn]),Ql=a.useRef($r);Ql.current=$r;const zo=a.useRef(!0);a.useEffect(()=>(zo.current=!0,()=>{zo.current=!1}),[]);const Wo=a.useRef(new Set),ec=a.useCallback((t,o,d)=>{if(Wo.current.has(o))return;const x=dd.getState().activeSessionId;Wo.current.add(o),rp(t,o,d,{insert:$r,upload:async(w,j)=>(await Ta("/tmp",[w],j)).files[0]?.path,isCurrent:()=>zo.current&&Ql.current===$r&&x===dd.getState().activeSessionId}).finally(()=>Wo.current.delete(o))},[$r]),Lr=a.useCallback((t,o,d)=>{o&&Gn(o.endsWith(" ")?o:`${o} `,d??`context:${t}`,`
1663
- `)},[Gn]),tc=a.useCallback(t=>{const o=jp(be,t);if(!o)return;const d=t&&be.trim().includes(`
1664
- `),x=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let w=!1;const j=ne=>{w||(w=!0,window.removeEventListener("termdock-insert-reference-ack",A),window.clearTimeout(ue),ne?(mr(!1),We(""),H&&Ft(!0)):(mr(!0),Ft(!1)))},A=ne=>{const V=ne.detail;V?.nonce===x&&j(V.ok===!0)},ue=window.setTimeout(()=>j(!1),1500);window.addEventListener("termdock-insert-reference-ack",A),mr(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:o,focus:!0,paste:d,nonce:x}}))},[H,be]),Xe=a.useMemo(()=>v?vt(v):i("rightSidebar.workspace"),[v,i]),Gf=a.useMemo(()=>vt(ge)||Xe,[ge,Xe]),pa=a.useMemo(()=>vi(ge),[ge]),ga=a.useMemo(()=>v?Ml[v]??[]:[],[Ml,v]),xn=a.useMemo(()=>new Set(ga.map(t=>t.path)),[ga]),xs=!!(ge&&xn.has(ge)),Go=!!(v&&ge&&ge!==v),Kf=!!(v&&In&&In!==v),Tt=ge?`path:${ge}`:null,rc="context:change-audit",qf=a.useCallback(()=>{pa&&Ot(pa)},[pa,Ot]),nc=a.useCallback(()=>{Ll()},[Ll]),Vf=a.useCallback(()=>{ge&&(sa(ge,!0),Tl())},[Tl,ge,sa]),Yf=a.useCallback(()=>{!ge||!Go||(xs?fn(ge):Dn(ge,"directory"))},[Go,ge,xs,Dn,fn]),sc=a.useCallback(t=>{Ot(t),G("")},[Ot]),ac=a.useCallback(t=>{ge&&(ce(ug(ge,t)),W(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ge,W]),oc=a.useCallback(t=>{!v||t===v||(xn.has(t)?fn(t):Dn(t,"directory"))},[Dn,xn,v,fn]),ic=a.useCallback(t=>{!v||!t||(xn.has(t)?fn(t):Dn(t,"file"))},[Dn,xn,v,fn]),lc=J(t=>t.expandedPaths),Ko=a.useMemo(()=>{const t=new Set;if(zn&&ge){t.add(ge);const o=`${ge.replace(/\/+$/,"")}/`;for(const d of lc)d.startsWith(o)&&t.add(d)}if(zn&&v&&Je){const o=Je.startsWith("/")?Je:`${v}/${Je}`,d=vi(o);d&&t.add(d)}return pp(t).join(`
1665
- `)},[lc,zn,ge,v,Je]),vn=a.useRef(new Map);a.useEffect(()=>{const t=Ko?Ko.split(`
1666
- `):[];if(!r||t.length===0){Tn(null);return}const o=new AbortController;let d=!1,x=0,w=0;Tn(null);const j=async()=>{let A=0;for(;!d&&!o.signal.aborted;){let ue=null;try{Tn(null),await im(t,V=>{const{applicableEvents:$e,unavailableReason:Be}=bp(V);$e.length>0&&Al($e);for(const Re of $e){if(Re.type!=="rescan-required")continue;const ie=J.getState();if(!ie.directoryCache.has(Re.path))continue;vn.current.get(Re.path)?.abort();const Ke=new AbortController;vn.current.set(Re.path,Ke);const Dt=`file-watch-rescan:${Re.path}`;kt(Dt),lm(Re.path,Ke.signal,ie.showHiddenFiles,"watch_rescan",Dt,ie.fileSortModes[Re.path]??"name").then(Te=>{vn.current.get(Re.path)===Ke&&Pl(Re.path,Te.entries)}).catch(Te=>{Pr(Te)||Tn(Te instanceof Error?Te.message:"File refresh unavailable")}).finally(()=>{vn.current.get(Re.path)===Ke&&vn.current.delete(Re.path)})}Be&&Tn(Be)},o.signal),ue=new Error("File watch stream ended")}catch(V){ue=V}if(d||o.signal.aborted||Pr(ue))return;Tn(ue instanceof Error?ue.message:"File watching unavailable");const ne=Ld[Math.min(A,Ld.length-1)];A+=1,await new Promise(V=>{w=window.setTimeout(V,ne)})}};return x=window.setTimeout(()=>{d||j()},hi),()=>{d=!0,window.clearTimeout(x),window.clearTimeout(w),o.abort();for(const A of vn.current.values())A.abort();vn.current.clear()}},[Al,r,Pl,Ko]),a.useEffect(()=>{if(!v||To.current!==v)return;if(Io.current===v){Io.current=null;return}const t=Dd();Es($u,{...t,[v]:{selectedRepoRoots:Gs,repoTargetBranches:jr,repoBaseBranches:Nt,previewEntries:an,selectedPreviewKey:De&&kr?rt:null,selectedPreviewFileKey:De&&kr?xo:null,previewDetailOpen:!!(De&&kr),previewScrollTops:as,previewMobileSlideIndex:1,includeUncommitted:Gr,updatedAt:Date.now()}},fg)},[kr,Gr,De,an,as,Nt,jr,Gs,v,xo,rt]);const dt=a.useMemo(()=>Yd(we.values()),[we]),ot=a.useMemo(()=>{const t=new Map;for(const o of le)t.set(o.root,o);return t},[le]),vs=a.useMemo(()=>{const t=new Map;for(const o of le)o.deferred||t.set(o.root,o.files.length);return t},[le]),ba=a.useCallback(t=>{if(t){if(!t.deferred){fs.current.delete(t.root);return}vs.has(t.root)||fs.current.has(t.root)||(fs.current.add(t.root),Qt(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(o=>{o||fs.current.delete(t.root)}))}},[Qt,vs]),Mt=a.useMemo(()=>oe?me.find(t=>t.root===oe)??null:null,[oe,me]),zt=a.useMemo(()=>Je?Array.from(we.values()).find(t=>t.path===Je||t.absolutePath===Je)??null:null,[we,Je]),It=a.useMemo(()=>{const t=new Map;for(const o of le)o.available&&o.context?.available&&t.set(o.root,o);return t.size===0&&S?.available&&S.root&&t.set(S.root,{id:S.root,root:S.root,relativeRoot:".",name:Xe,depth:0,nested:!1,available:!0,files:Array.from(we.values()).filter(o=>mt(o,v)===S.root),context:S}),Array.from(t.values()).sort((o,d)=>o.root===v?-1:d.root===v?1:(o.relativeRoot||o.name).localeCompare(d.relativeRoot||d.name)).map(o=>{const d=o.relativeRoot==="."?Xe:o.relativeRoot||o.name||vt(o.root),x=Vd(o.files),w=o.files.length;return{value:o.root,label:d,meta:[o.context?.branch,w>0?i("rightSidebar.repoChangedCount",{count:w}):null,x>0?i("rightSidebar.repoStagedCount",{count:x}):null].filter(Boolean).join(" · ")}})},[we,S,le,Xe,v,i]),ye=a.useMemo(()=>oe&&It.some(t=>t.value===oe)?oe:zt?.repoRoot&&It.some(t=>t.value===zt.repoRoot)?zt.repoRoot:It.length===1||It.length>1?It[0].value:null,[oe,It,zt?.repoRoot]),cc=ye?ot.get(ye)??null:null,de=cc?.context?.available?cc.context:ye===S?.root?S:null,qe=It.length>0&&!ye,dc=a.useMemo(()=>qe?[]:ye?Array.from(we.values()).filter(t=>mt(t,v)===ye):Array.from(we.values()),[ye,we,qe,v]),yn=a.useMemo(()=>Yd(dc),[dc]),qo=!!(de?.available&&de.root&&ye&&de.root===ye),Xf=ye?It.find(t=>t.value===ye)?.label??vt(ye):i("rightSidebar.gitRepositoryPlaceholder"),uc=qo?de?.branch??"HEAD":qe?i("rightSidebar.selectRepositoryForGitActions"):cn?i("rightSidebar.gitActionRunning"):"HEAD",Kn=!!(de?.available&&de.root===ye&&de.status);a.useEffect(()=>{ul.current={count:ln.length,loading:ze,loadingMore:zr,hasMore:mo}},[ln.length,mo,ze,zr]),a.useEffect(()=>{Wr.current+=1,nr.current?.abort(),kt("right-sidebar-recent-commits"),nr.current=null,on(""),X([]),Pt(!1),is(!1),En(null),$n(!1)},[ye]);const ys=a.useCallback(async(t={})=>{if(!v||!ye||qe)return;const o=t.reset??!1,d=ul.current,x=o?0:d.count;if(!o&&(d.loading||d.loadingMore||!d.hasMore))return;const w=Wr.current+1;Wr.current=w,nr.current?.abort(),kt("right-sidebar-recent-commits");const j=new AbortController;nr.current=j,o?Pt(!0):is(!0),En(null);try{const A=await Qh({cwd:v,repoRoot:ye,limit:Sg,skip:x,query:Hr.trim(),requestSlotId:"right-sidebar-recent-commits"},j.signal);if(Wr.current!==w)return;if(!A.available){En(A.error??"Recent commits are unavailable"),o&&X([]),$n(!1);return}ho(ue=>o?A.commitSyncStatus??{}:{...ue,...A.commitSyncStatus}),X(ue=>o?A.commits:[...ue,...A.commits]),$n(A.hasMore)}catch(A){if(Wr.current!==w||Pr(A))return;En(A instanceof Error?A.message:"Failed to load recent commits"),o&&X([]),$n(!1)}finally{nr.current===j&&(nr.current=null),Wr.current===w&&(Pt(!1),is(!1))}},[ye,Hr,qe,v]);a.useEffect(()=>{Xt&&ys({reset:!0})},[Hr,ys,Xt,de?.ahead,de?.behind,de?.upstream]);const Jf=a.useCallback(t=>{const o=t.currentTarget;o.scrollTop+o.clientHeight<o.scrollHeight-48||ys({reset:!1})},[ys]);a.useEffect(()=>{!ye||!S?.available||!Qe||!sr||Kn||cn||qe||_o(ye)},[ye,S?.available,Kn,cn,Qe,sr,_o,qe]),a.useEffect(()=>{!r||!wt&&!Qe||!v||or()},[wt,Qe,r,or,v]),a.useEffect(()=>{!r||!Qe||!sr||!ls||!v||ua(null)},[ls,Qe,sr,r,ua,v]);const Zf=a.useMemo(()=>{if(!oe)return 0;const t=me.findIndex(o=>o.root===oe);return t>=0?t+1:0},[oe,me]),fc=a.useCallback(t=>{if(!t)return null;const o=Array.from(we.values()).filter(d=>mt(d,v)===t).sort((d,x)=>d.path.localeCompare(x.path))[0];return o?xt(o):null},[we,v]),wn=me.length>1,xa=a.useMemo(()=>[{root:null,label:i("rightSidebar.allRepositories"),count:we.size,branch:null,deferred:!1},...me.map(t=>({root:t.root,label:t.label,count:t.deferred?vs.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!vs.has(t.root)}))],[we.size,me,vs,i]),hc=xa[Zf]??xa[0],va=!!oe,mc=a.useMemo(()=>Fu(me,le),[me,le]);a.useEffect(()=>{Fo.current===v&&oe&&!mc.has(oe)&&Ee(null),Cn(t=>t.filter(o=>me.some(d=>d.root===o)))},[oe,me,mc,v,Ee]),a.useEffect(()=>{oe&&ba(ot.get(oe))},[oe,ba,ot]);const Qf=a.useMemo(()=>{const t=new Set;de?.branch&&t.add(de.branch);for(const o of de?.branches??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===de?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0}))},[de?.branch,de?.branches,i]),pc=a.useMemo(()=>{const t=new Set;de?.upstreamRemote&&t.add(de.upstreamRemote);for(const o of de?.remotes??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===de?.upstreamRemote?i("rightSidebar.pushUpstreamBadge"):void 0}))},[de?.remotes,de?.upstreamRemote,i]),gc=pc.length>1,eh=a.useMemo(()=>{const t=[],o=new Set,d=(w,j)=>{!w||o.has(w)||(o.add(w),t.push({value:w,label:w,meta:j}))};d(de?.upstreamBranch,de?.upstreamBranch?i("rightSidebar.pushUpstreamBadge"):void 0),d(de?.branch,de?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0);for(const w of de?.branches??[])d(w,w===de?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");const x=de?.upstreamRemote;for(const w of de?.remoteBranches??[]){const j=w.indexOf("/"),A=j>=0?w.slice(0,j):null,ue=j>=0?w.slice(j+1):w;(!x||A===x)&&d(ue,"remote")}return t},[de?.branch,de?.branches,de?.remoteBranches,de?.upstreamBranch,de?.upstreamRemote,i]),Wt=a.useMemo(()=>It.map(t=>{const o=ot.get(t.value);return{root:t.value,label:t.label,branch:o?.context?.branch??null}}),[It,ot]);a.useEffect(()=>{Wt.length!==0&&(Ks(t=>{let o=!1;const d={...t},x=new Set(Wt.map(w=>w.root));for(const w of Object.keys(d))x.has(w)||(delete d[w],o=!0);for(const w of Wt)!d[w.root]&&w.branch&&(d[w.root]=w.branch,o=!0);return o?d:t}),qs(t=>{let o=!1;const d={...t},x=new Set(Wt.map(w=>w.root));for(const w of Object.keys(d))x.has(w)||(delete d[w],o=!0);for(const w of Wt){const j=ot.get(w.root)?.context;if(d[w.root]&&_u(d[w.root],j?.branch)&&(delete d[w.root],o=!0),d[w.root])continue;const A=Bd(j);A&&(d[w.root]=A,o=!0)}return o?d:t}))},[Wt,ot]);const ya=a.useMemo(()=>{const t=new Set(Wt.map(o=>o.root));return Gs.filter(o=>t.has(o))},[Gs,Wt]),wa=ya.length===0,cr=a.useMemo(()=>wa?Wt:Wt.filter(t=>ya.includes(t.root)),[Wt,ya,wa]),er=a.useMemo(()=>cr.filter(t=>!!Nt[t.root]?.trim()),[Nt,cr]),bc=a.useMemo(()=>cr.filter(t=>!Nt[t.root]?.trim()),[Nt,cr]),xc=a.useCallback(async t=>{if(!t||Po.current.has(t))return;const o=ot.get(t)?.context;if((o?.branches?.length??0)>0||(o?.remoteBranches?.length??0)>0||o?.upstream)return;const d=v;Po.current.add(t),pl(x=>new Set(x).add(t));try{const x=await rd(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!x.available||!je(d))return;q(w=>w.map(j=>j.root===t?{...j,available:!0,context:{...j.context,...x},error:void 0}:j)),Ks(w=>w[t]||!x.branch?w:{...w,[t]:x.branch}),qs(w=>{if(w[t])return w;const j=Bd(x);return j?{...w,[t]:j}:w})}catch(x){Pr(x)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,x)}finally{Po.current.delete(t),pl(x=>{const w=new Set(x);return w.delete(t),w})}},[ot,je,v]);a.useEffect(()=>{if(po)for(const t of cr)xc(t.root)},[po,cr,xc]),a.useEffect(()=>{!qo||!de||(Js(de.branch||(de.branches?.[0]??"")),Zs(de.upstreamRemote||(de.remotes?.includes("origin")?"origin":de.remotes?.[0]??"")),Qs(de.upstreamBranch||de.branch||(de.branches?.[0]??"")))},[de,qo]);const vc=a.useMemo(()=>{if(qe)return{text:i("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Kn||cn)return{text:i("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!de?.upstream)return{text:i("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=de.ahead??0,o=de.behind??0;return t>0&&o>0?{text:i("rightSidebar.pushDivergedCount",{ahead:t,behind:o}),className:"bg-destructive/10 text-destructive"}:t>0?{text:i("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:o>0?{text:i("rightSidebar.pushBehindCount",{count:o}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:i("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[de?.ahead,de?.behind,de?.upstream,Kn,cn,qe,i]),th=a.useCallback(t=>{if(t&&!ee){const o=t.currentTarget.getBoundingClientRect();Pe({x:Math.min(o.left,window.innerWidth-352),y:Math.min(o.bottom+6,window.innerHeight-64)})}else Pe(null);D?.()},[ee,D]),Vo=a.useCallback(()=>{Pe(null),_?.()},[_]);function yc(){if(!wn)return null;const t=hc?.label??i("rightSidebar.allRepositories"),o=hc?.count??we.size,d=vt(t)||t;return e.jsxs("button",{type:"button",onClick:th,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${y?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":y,title:t,children:[e.jsx(Ar,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:d}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${o>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:o}),e.jsx(Ts,{size:12,className:"shrink-0"})]})}function rh(){if(!y||!wn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,o=typeof window>"u"?768:window.innerHeight,d=Math.max(12,Math.min(st?.x??t-368,t-352)),x=Math.max(12,Math.min(st?.y??80,o-420)),w=ee?void 0:{left:d,top:x},j=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Vo,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:w,onClick:A=>A.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:i("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:xa.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${we.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:we.size})]})]}),e.jsx("button",{type:"button",onClick:Vo,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.close"),children:e.jsx(Kt,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:xa.map(A=>{const ue=(A.root??null)===oe,ne=vt(A.label)||A.label;return e.jsxs("button",{type:"button",onClick:()=>{Uc(A.root),Vo()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${ue?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:A.label,role:"option","aria-selected":ue,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${ue?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),e.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${ue?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Ar,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:ne}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:A.root===null?i("rightSidebar.allRepositories"):A.label})]}),A.branch&&e.jsx("span",{className:"hidden max-w-[5.5rem] shrink min-w-0 truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline",children:A.branch}),A.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:i("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${A.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:A.count})]},A.root??"all")})})]})});return ju(j,ee,document.body)}function nh(){return rh()}function wc(t){const o=mt(t,v),d=t.absolutePath||(o?`${o}/${t.path}`:t.path),x=Za(d,o??v);return{key:xt(t),path:t.path,absolutePath:d,displayName:x.name,displayDir:x.dir,oldPath:t.oldPath,status:t.status,title:d}}function kc(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:i("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function Sc(t,o){const d=Da(t,v),x=`path:${d}`,w=ke===x,j=et===x,A=w||j;return e.jsx("button",{type:"button",onClick:ue=>{ue.stopPropagation(),lr(d,x)},...Ho(ma(d),x),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${A?"max-w-20 px-2":"max-w-20 px-2 md:max-w-0 md:px-0 md:opacity-0 md:group-hover:max-w-20 md:group-hover:px-2 md:group-hover:opacity-100"} ${A?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:o,children:e.jsx("span",{className:"whitespace-nowrap",children:i(j?"rightSidebar.copied":w?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function jc(t){const o=mt(t,v),d=t.absolutePath||(o?`${o}/${t.path}`:t.path),x=Eh(t),w=ki(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Mb,{actions:x,running:_e,completed:Ln?.path===w?Ln:null}),Sc(d,i("rightSidebar.insertThisFile"))]})}function Rc(t,o){const d=o.root??v;if(!d)return null;const x=Da(t,d);return Sc(x,i("fileTree.insertRefTitle"))}function Yo(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":i("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>Ic("unified"),"aria-pressed":Bt==="unified",title:i("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Bt==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>Ic("split"),"aria-pressed":Bt==="split",title:i("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Bt==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.split")})]})}function Cc(){return ws.map(t=>{const o=Vd(t.files.map(([,j])=>j)),d=Ui({activeGitRepoRoot:oe,groupCount:ws.length,label:t.label,rootName:Xe}),x=!!(d&&t.root&&pr.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:x,files:t.files.map(([,j])=>wc(j)),header:d?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${x?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>wh(t.root),"aria-expanded":!x,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:x?e.jsx(Ia,{size:13}):e.jsx(Ts,{size:13})}),e.jsx(Ar,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:t.label}),t.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:t.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:t.files.length}),o>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:o})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),$a("stage-all",t.root,t.label)},disabled:!!_e,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),$a("stash-all",t.root,t.label)},disabled:!!_e,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]})]}):null}})}function Nc(){return we.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:i("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:Sa.map(([,t])=>{const o=mt(t,v),d=t.absolutePath||(o?`${o}/${t.path}`:t.path);return{key:xt(t),path:t.path,absolutePath:d,status:t.status,repoRoot:o,displayName:Za(d,o).name,displayDir:Za(d,o).dir,auditRecords:Rt}})}function Mc(t){const o=Array.from(we.values()).find(w=>xt(w)===t.key),d=o?mt(o,v):null,x=sp(Rt,d,o?.path??t.path);return e.jsx(Di,{changeStatus:t.status,auditStatus:x,renderChangeBadge:w=>e.jsx($s,{status:w})})}const ka=a.useCallback(t=>{if(ee)return null;const o=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(o.length===0)return null;const x=t.getBoundingClientRect().top+48;let w=null,j=Number.POSITIVE_INFINITY;for(const ue of o){const ne=ue.getBoundingClientRect();if(ne.bottom<x)continue;const V=Math.abs(ne.top-x);V<j&&(w=ue,j=V)}const A=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;return A?(la.current===A&&J.getState().selectedFilePath===A||(la.current=A,Ze(A)),A):null},[ee,Ze]),sh=!!(!_e&&ye&&!qe&&(de?.upstream||dn.trim()&&un.trim())),ah=!!(!_e&&ye&&!qe&&(de?.upstream||dn.trim()&&un.trim())),oh=!!(!_e&&ye&&!qe&&Pn.trim()&&Pn.trim()!==de?.branch),Gt=a.useMemo(()=>{const t=Ie.trim().toLowerCase(),o=Array.from(we.entries()).filter(([,d])=>!oe||mt(d,v)===oe).sort(([d],[x])=>d.localeCompare(x));return t?o.filter(([d,x])=>`${d} ${x.path} ${x.status} ${x.repoRelativeRoot??""} ${x.repoName??""}`.toLowerCase().includes(t)):o},[oe,we,Ie,v]);a.useEffect(()=>{Va("selected_file_state",{selectedFilePath:Je,selectedChangedFilePath:zt?.path??null,selectedChangedFileAbsolutePath:zt?.absolutePath??null,selectedChangedFileRepoRoot:zt?.repoRoot??null,rootPath:v,activeGitRepoRoot:oe,rightTab:Mo,effectiveRightTab:ir,diffPaneActive:wt,changedFiles:we.size,filteredChangedFiles:Gt.length,gitBundleLoading:Xr,gitBundleLastLoadedAt:Fn})},[oe,we.size,wt,ir,Gt.length,Fn,Xr,Mo,v,zt?.absolutePath,zt?.path,zt?.repoRoot,Je]);const ws=a.useMemo(()=>{const t=new Map;for(const o of Gt){const[,d]=o,x=mt(d,v),w=Cb(d)||Xe,j=x??w,A=x?ot.get(x):void 0,ue=t.get(j)??{root:x,label:w,branch:A?.context?.branch,files:[]};ue.files.push(o),t.set(j,ue)}return Array.from(t.values()).sort((o,d)=>o.label===Xe?-1:d.label===Xe?1:o.label.localeCompare(d.label))},[Gt,ot,Xe,v]),Sa=a.useMemo(()=>{const t=[],o=new Map;for(const d of Gt)o.set(xt(d[1]),d);for(const d of ws){if(!!(d.root&&Ui({activeGitRepoRoot:oe,groupCount:ws.length,label:d.label,rootName:Xe})&&pr.has(d.root)))continue;if(xr!=="tree"){t.push(...d.files);continue}const w=d.files.map(([,j])=>wc(j));for(const j of Am(w)){const A=o.get(j.key);A&&t.push(A)}}return t},[oe,pr,xr,ws,Gt,Xe]);a.useEffect(()=>{if(!wt||Sa.length===0||ee)return;const t=[],o=()=>{const d=document.querySelector(".termdock-diff-stream-scroller");if(d&&ka(d))return;const x=document.querySelector("[data-diff-stream-item]"),w=x?.dataset.diffSelectionPath??x?.dataset.diffStreamItem??null;if(w){la.current=w,Ze(w);return}const j=Sa[0]?.[1];if(!j)return;const A=xt(j);la.current=A,Ze(A)};for(const d of[80,240,600,1200])t.push(window.setTimeout(o,d));return()=>t.forEach(d=>window.clearTimeout(d))},[wt,ee,Sa,Ze,ka]);const Xo=a.useMemo(()=>{const t=A=>`'${A.replace(/'/g,"'\\''")}'`,o=Zt.length>0?gn:le.filter(A=>A.files.length>0),d=o.length>0?o:v?[{root:v,relativeRoot:".",name:Xe}]:[],x=d.length>0?d.map(A=>`- ${A.relativeRoot==="."?".":A.relativeRoot} (${A.root})`).join(`
1662
+ `)||t.endsWith(" ")?t:`${t} `,o,d)},[Gn]),rc=a.useRef($r);rc.current=$r;const Wo=a.useRef(!0);a.useEffect(()=>(Wo.current=!0,()=>{Wo.current=!1}),[]);const Go=a.useRef(new Set),nc=a.useCallback((t,o,d)=>{if(Go.current.has(o))return;const x=hd.getState().activeSessionId;Go.current.add(o),op(t,o,d,{insert:$r,upload:async(w,j)=>(await Ns("/tmp",[w],j)).files[0]?.path,isCurrent:()=>Wo.current&&rc.current===$r&&x===hd.getState().activeSessionId}).finally(()=>Go.current.delete(o))},[$r]),Lr=a.useCallback((t,o,d)=>{o&&Gn(o.endsWith(" ")?o:`${o} `,d??`context:${t}`,`
1663
+ `)},[Gn]),sc=a.useCallback(t=>{const o=Mp(be,t);if(!o)return;const d=t&&be.trim().includes(`
1664
+ `),x=`draft-${Date.now()}-${Math.random().toString(36).slice(2)}`;let w=!1;const j=ne=>{w||(w=!0,window.removeEventListener("termdock-insert-reference-ack",A),window.clearTimeout(ue),ne?(mr(!1),We(""),H&&Ft(!0)):(mr(!0),Ft(!1)))},A=ne=>{const V=ne.detail;V?.nonce===x&&j(V.ok===!0)},ue=window.setTimeout(()=>j(!1),1500);window.addEventListener("termdock-insert-reference-ack",A),mr(!1),window.dispatchEvent(new CustomEvent("termdock-insert-reference",{detail:{text:o,focus:!0,paste:d,nonce:x}}))},[H,be]),Xe=a.useMemo(()=>v?vt(v):i("rightSidebar.workspace"),[v,i]),Vf=a.useMemo(()=>vt(ge)||Xe,[ge,Xe]),ga=a.useMemo(()=>yi(ge),[ge]),ba=a.useMemo(()=>v?Ml[v]??[]:[],[Ml,v]),xn=a.useMemo(()=>new Set(ba.map(t=>t.path)),[ba]),xs=!!(ge&&xn.has(ge)),Ko=!!(v&&ge&&ge!==v),Yf=!!(v&&In&&In!==v),Tt=ge?`path:${ge}`:null,ac="context:change-audit",Xf=a.useCallback(()=>{ga&&Ot(ga)},[ga,Ot]),oc=a.useCallback(()=>{Al()},[Al]),Jf=a.useCallback(()=>{ge&&(aa(ge,!0),Il())},[Il,ge,aa]),Zf=a.useCallback(()=>{!ge||!Ko||(xs?fn(ge):Dn(ge,"directory"))},[Ko,ge,xs,Dn,fn]),ic=a.useCallback(t=>{Ot(t),G("")},[Ot]),lc=a.useCallback(t=>{ge&&(ce(gg(ge,t)),W(!0),window.requestAnimationFrame(()=>{document.querySelector("[data-right-search]")?.focus()}))},[ge,W]),cc=a.useCallback(t=>{!v||t===v||(xn.has(t)?fn(t):Dn(t,"directory"))},[Dn,xn,v,fn]),dc=a.useCallback(t=>{!v||!t||(xn.has(t)?fn(t):Dn(t,"file"))},[Dn,xn,v,fn]),uc=J(t=>t.expandedPaths),qo=a.useMemo(()=>{const t=new Set;if(zn&&ge){t.add(ge);const o=`${ge.replace(/\/+$/,"")}/`;for(const d of uc)d.startsWith(o)&&t.add(d)}if(zn&&v&&Je){const o=Je.startsWith("/")?Je:`${v}/${Je}`,d=yi(o);d&&t.add(d)}return vp(t).join(`
1665
+ `)},[uc,zn,ge,v,Je]),vn=a.useRef(new Map);a.useEffect(()=>{const t=qo?qo.split(`
1666
+ `):[];if(!r||t.length===0){Tn(null);return}const o=new AbortController;let d=!1,x=0,w=0;Tn(null);const j=async()=>{let A=0;for(;!d&&!o.signal.aborted;){let ue=null;try{Tn(null),await dm(t,V=>{const{applicableEvents:$e,unavailableReason:Be}=wp(V);$e.length>0&&Pl($e);for(const Re of $e){if(Re.type!=="rescan-required")continue;const ie=J.getState();if(!ie.directoryCache.has(Re.path))continue;vn.current.get(Re.path)?.abort();const Ke=new AbortController;vn.current.set(Re.path,Ke);const Dt=`file-watch-rescan:${Re.path}`;jt(Dt),um(Re.path,Ke.signal,ie.showHiddenFiles,"watch_rescan",Dt,ie.fileSortModes[Re.path]??"name").then(Te=>{vn.current.get(Re.path)===Ke&&Tl(Re.path,Te.entries)}).catch(Te=>{Pr(Te)||Tn(Te instanceof Error?Te.message:"File refresh unavailable")}).finally(()=>{vn.current.get(Re.path)===Ke&&vn.current.delete(Re.path)})}Be&&Tn(Be)},o.signal),ue=new Error("File watch stream ended")}catch(V){ue=V}if(d||o.signal.aborted||Pr(ue))return;Tn(ue instanceof Error?ue.message:"File watching unavailable");const ne=Td[Math.min(A,Td.length-1)];A+=1,await new Promise(V=>{w=window.setTimeout(V,ne)})}};return x=window.setTimeout(()=>{d||j()},mi),()=>{d=!0,window.clearTimeout(x),window.clearTimeout(w),o.abort();for(const A of vn.current.values())A.abort();vn.current.clear()}},[Pl,r,Tl,qo]),a.useEffect(()=>{if(!v||To.current!==v)return;if(Io.current===v){Io.current=null;return}const t=Bd();$s(Pu,{...t,[v]:{selectedRepoRoots:Ks,repoTargetBranches:jr,repoBaseBranches:Nt,previewEntries:an,selectedPreviewKey:De&&kr?rt:null,selectedPreviewFileKey:De&&kr?xo:null,previewDetailOpen:!!(De&&kr),previewScrollTops:as,previewMobileSlideIndex:1,includeUncommitted:Kr,updatedAt:Date.now()}},bg)},[kr,Kr,De,an,as,Nt,jr,Ks,v,xo,rt]);const dt=a.useMemo(()=>Zd(we.values()),[we]),ot=a.useMemo(()=>{const t=new Map;for(const o of le)t.set(o.root,o);return t},[le]),vs=a.useMemo(()=>{const t=new Map;for(const o of le)o.deferred||t.set(o.root,o.files.length);return t},[le]),xa=a.useCallback(t=>{if(t){if(!t.deferred){fs.current.delete(t.root);return}vs.has(t.root)||fs.current.has(t.root)||(fs.current.add(t.root),Qt(t.root,{includeNested:!1,background:!0,replaceRepoRoot:t.root}).then(o=>{o||fs.current.delete(t.root)}))}},[Qt,vs]),Et=a.useMemo(()=>oe?me.find(t=>t.root===oe)??null:null,[oe,me]),zt=a.useMemo(()=>Je?Array.from(we.values()).find(t=>t.path===Je||t.absolutePath===Je)??null:null,[we,Je]),It=a.useMemo(()=>{const t=new Map;for(const o of le)o.available&&o.context?.available&&t.set(o.root,o);return t.size===0&&S?.available&&S.root&&t.set(S.root,{id:S.root,root:S.root,relativeRoot:".",name:Xe,depth:0,nested:!1,available:!0,files:Array.from(we.values()).filter(o=>mt(o,v)===S.root),context:S}),Array.from(t.values()).sort((o,d)=>o.root===v?-1:d.root===v?1:(o.relativeRoot||o.name).localeCompare(d.relativeRoot||d.name)).map(o=>{const d=o.relativeRoot==="."?Xe:o.relativeRoot||o.name||vt(o.root),x=Jd(o.files),w=o.files.length;return{value:o.root,label:d,meta:[o.context?.branch,w>0?i("rightSidebar.repoChangedCount",{count:w}):null,x>0?i("rightSidebar.repoStagedCount",{count:x}):null].filter(Boolean).join(" · ")}})},[we,S,le,Xe,v,i]),ye=a.useMemo(()=>oe&&It.some(t=>t.value===oe)?oe:zt?.repoRoot&&It.some(t=>t.value===zt.repoRoot)?zt.repoRoot:It.length===1||It.length>1?It[0].value:null,[oe,It,zt?.repoRoot]),fc=ye?ot.get(ye)??null:null,de=fc?.context?.available?fc.context:ye===S?.root?S:null,qe=It.length>0&&!ye,hc=a.useMemo(()=>qe?[]:ye?Array.from(we.values()).filter(t=>mt(t,v)===ye):Array.from(we.values()),[ye,we,qe,v]),yn=a.useMemo(()=>Zd(hc),[hc]),Vo=!!(de?.available&&de.root&&ye&&de.root===ye),Qf=ye?It.find(t=>t.value===ye)?.label??vt(ye):i("rightSidebar.gitRepositoryPlaceholder"),mc=Vo?de?.branch??"HEAD":qe?i("rightSidebar.selectRepositoryForGitActions"):cn?i("rightSidebar.gitActionRunning"):"HEAD",Kn=!!(de?.available&&de.root===ye&&de.status);a.useEffect(()=>{fl.current={count:ln.length,loading:ze,loadingMore:Wr,hasMore:mo}},[ln.length,mo,ze,Wr]),a.useEffect(()=>{Gr.current+=1,nr.current?.abort(),jt("right-sidebar-recent-commits"),nr.current=null,on(""),X([]),Pt(!1),is(!1),Mn(null),$n(!1)},[ye]);const ys=a.useCallback(async(t={})=>{if(!v||!ye||qe)return;const o=t.reset??!1,d=fl.current,x=o?0:d.count;if(!o&&(d.loading||d.loadingMore||!d.hasMore))return;const w=Gr.current+1;Gr.current=w,nr.current?.abort(),jt("right-sidebar-recent-commits");const j=new AbortController;nr.current=j,o?Pt(!0):is(!0),Mn(null);try{const A=await rm({cwd:v,repoRoot:ye,limit:Eg,skip:x,query:zr.trim(),requestSlotId:"right-sidebar-recent-commits"},j.signal);if(Gr.current!==w)return;if(!A.available){Mn(A.error??"Recent commits are unavailable"),o&&X([]),$n(!1);return}ho(ue=>o?A.commitSyncStatus??{}:{...ue,...A.commitSyncStatus}),X(ue=>o?A.commits:[...ue,...A.commits]),$n(A.hasMore)}catch(A){if(Gr.current!==w||Pr(A))return;Mn(A instanceof Error?A.message:"Failed to load recent commits"),o&&X([]),$n(!1)}finally{nr.current===j&&(nr.current=null),Gr.current===w&&(Pt(!1),is(!1))}},[ye,zr,qe,v]);a.useEffect(()=>{Xt&&ys({reset:!0})},[zr,ys,Xt,de?.ahead,de?.behind,de?.upstream]);const eh=a.useCallback(t=>{const o=t.currentTarget;o.scrollTop+o.clientHeight<o.scrollHeight-48||ys({reset:!1})},[ys]);a.useEffect(()=>{!ye||!S?.available||!Qe||!sr||Kn||cn||qe||_o(ye)},[ye,S?.available,Kn,cn,Qe,sr,_o,qe]),a.useEffect(()=>{!r||!St&&!Qe||!v||or()},[St,Qe,r,or,v]),a.useEffect(()=>{!r||!Qe||!sr||!ls||!v||fa(null)},[ls,Qe,sr,r,fa,v]);const th=a.useMemo(()=>{if(!oe)return 0;const t=me.findIndex(o=>o.root===oe);return t>=0?t+1:0},[oe,me]),pc=a.useCallback(t=>{if(!t)return null;const o=Array.from(we.values()).filter(d=>mt(d,v)===t).sort((d,x)=>d.path.localeCompare(x.path))[0];return o?xt(o):null},[we,v]),wn=me.length>1,va=a.useMemo(()=>[{root:null,label:i("rightSidebar.allRepositories"),count:we.size,branch:null,deferred:!1},...me.map(t=>({root:t.root,label:t.label,count:t.deferred?vs.get(t.root)??0:t.count,branch:t.branch??null,deferred:!!t.deferred&&!vs.has(t.root)}))],[we.size,me,vs,i]),gc=va[th]??va[0],ya=!!oe,bc=a.useMemo(()=>Ou(me,le),[me,le]);a.useEffect(()=>{Fo.current===v&&oe&&!bc.has(oe)&&Me(null),Cn(t=>t.filter(o=>me.some(d=>d.root===o)))},[oe,me,bc,v,Me]),a.useEffect(()=>{oe&&xa(ot.get(oe))},[oe,xa,ot]);const rh=a.useMemo(()=>{const t=new Set;de?.branch&&t.add(de.branch);for(const o of de?.branches??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===de?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0}))},[de?.branch,de?.branches,i]),xc=a.useMemo(()=>{const t=new Set;de?.upstreamRemote&&t.add(de.upstreamRemote);for(const o of de?.remotes??[])t.add(o);return Array.from(t).map(o=>({value:o,label:o,meta:o===de?.upstreamRemote?i("rightSidebar.pushUpstreamBadge"):void 0}))},[de?.remotes,de?.upstreamRemote,i]),vc=xc.length>1,nh=a.useMemo(()=>{const t=[],o=new Set,d=(w,j)=>{!w||o.has(w)||(o.add(w),t.push({value:w,label:w,meta:j}))};d(de?.upstreamBranch,de?.upstreamBranch?i("rightSidebar.pushUpstreamBadge"):void 0),d(de?.branch,de?.branch?i("rightSidebar.pushCurrentBranchBadge"):void 0);for(const w of de?.branches??[])d(w,w===de?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");const x=de?.upstreamRemote;for(const w of de?.remoteBranches??[]){const j=w.indexOf("/"),A=j>=0?w.slice(0,j):null,ue=j>=0?w.slice(j+1):w;(!x||A===x)&&d(ue,"remote")}return t},[de?.branch,de?.branches,de?.remoteBranches,de?.upstreamBranch,de?.upstreamRemote,i]),Wt=a.useMemo(()=>It.map(t=>{const o=ot.get(t.value);return{root:t.value,label:t.label,branch:o?.context?.branch??null}}),[It,ot]);a.useEffect(()=>{Wt.length!==0&&(qs(t=>{let o=!1;const d={...t},x=new Set(Wt.map(w=>w.root));for(const w of Object.keys(d))x.has(w)||(delete d[w],o=!0);for(const w of Wt)!d[w.root]&&w.branch&&(d[w.root]=w.branch,o=!0);return o?d:t}),Vs(t=>{let o=!1;const d={...t},x=new Set(Wt.map(w=>w.root));for(const w of Object.keys(d))x.has(w)||(delete d[w],o=!0);for(const w of Wt){const j=ot.get(w.root)?.context;if(d[w.root]&&Uu(d[w.root],j?.branch)&&(delete d[w.root],o=!0),d[w.root])continue;const A=Hd(j);A&&(d[w.root]=A,o=!0)}return o?d:t}))},[Wt,ot]);const wa=a.useMemo(()=>{const t=new Set(Wt.map(o=>o.root));return Ks.filter(o=>t.has(o))},[Ks,Wt]),ka=wa.length===0,cr=a.useMemo(()=>ka?Wt:Wt.filter(t=>wa.includes(t.root)),[Wt,wa,ka]),er=a.useMemo(()=>cr.filter(t=>!!Nt[t.root]?.trim()),[Nt,cr]),yc=a.useMemo(()=>cr.filter(t=>!Nt[t.root]?.trim()),[Nt,cr]),wc=a.useCallback(async t=>{if(!t||Po.current.has(t))return;const o=ot.get(t)?.context;if((o?.branches?.length??0)>0||(o?.remoteBranches?.length??0)>0||o?.upstream)return;const d=v;Po.current.add(t),gl(x=>new Set(x).add(t));try{const x=await ad(t,void 0,"load_branch_audit_repo_details",`right-sidebar-branch-audit-details:${t}`);if(!x.available||!je(d))return;q(w=>w.map(j=>j.root===t?{...j,available:!0,context:{...j.context,...x},error:void 0}:j)),qs(w=>w[t]||!x.branch?w:{...w,[t]:x.branch}),Vs(w=>{if(w[t])return w;const j=Hd(x);return j?{...w,[t]:j}:w})}catch(x){Pr(x)||console.warn("[RightSidebar] Failed to load branch audit repo details",t,x)}finally{Po.current.delete(t),gl(x=>{const w=new Set(x);return w.delete(t),w})}},[ot,je,v]);a.useEffect(()=>{if(po)for(const t of cr)wc(t.root)},[po,cr,wc]),a.useEffect(()=>{!Vo||!de||(Zs(de.branch||(de.branches?.[0]??"")),Qs(de.upstreamRemote||(de.remotes?.includes("origin")?"origin":de.remotes?.[0]??"")),ea(de.upstreamBranch||de.branch||(de.branches?.[0]??"")))},[de,Vo]);const kc=a.useMemo(()=>{if(qe)return{text:i("rightSidebar.selectRepositoryForGitActions"),className:"bg-[rgb(var(--warning-rgb)_/_0.12)] text-[color:var(--warning)]"};if(!Kn||cn)return{text:i("common.loading"),className:"bg-surface-2 text-muted-foreground"};if(!de?.upstream)return{text:i("rightSidebar.pushNoUpstream"),className:"bg-surface-2 text-muted-foreground"};const t=de.ahead??0,o=de.behind??0;return t>0&&o>0?{text:i("rightSidebar.pushDivergedCount",{ahead:t,behind:o}),className:"bg-destructive/10 text-destructive"}:t>0?{text:i("rightSidebar.pushAheadCount",{count:t}),className:"bg-accent/10 text-accent"}:o>0?{text:i("rightSidebar.pushBehindCount",{count:o}),className:"bg-surface-2 text-[color:var(--diff-hunk-accent)]"}:{text:i("rightSidebar.pushUpToDate"),className:"bg-surface-2 text-muted-foreground"}},[de?.ahead,de?.behind,de?.upstream,Kn,cn,qe,i]),sh=a.useCallback(t=>{if(t&&!ee){const o=t.currentTarget.getBoundingClientRect();Pe({x:Math.min(o.left,window.innerWidth-352),y:Math.min(o.bottom+6,window.innerHeight-64)})}else Pe(null);I?.()},[ee,I]),Yo=a.useCallback(()=>{Pe(null),B?.()},[B]);function Sc(){if(!wn)return null;const t=gc?.label??i("rightSidebar.allRepositories"),o=gc?.count??we.size,d=vt(t)||t;return e.jsxs("button",{type:"button",onClick:sh,className:`inline-flex h-7 min-w-0 max-w-[13rem] shrink-0 items-center gap-1.5 rounded-md border px-2 text-[11px] font-medium transition active:scale-95 ${y?"border-primary/25 bg-primary/10 text-primary":"border-border/10 bg-surface-2 text-muted-foreground hover:border-border/25 hover:bg-surface-elevated hover:text-foreground"}`,"aria-haspopup":"listbox","aria-expanded":y,title:t,children:[e.jsx(Ar,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:d}),e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${o>0?"bg-accent/10 text-accent":"bg-surface text-muted-foreground"}`,children:o}),e.jsx(Is,{size:12,className:"shrink-0"})]})}function ah(){if(!y||!wn||typeof document>"u")return null;const t=typeof window>"u"?1024:window.innerWidth,o=typeof window>"u"?768:window.innerHeight,d=Math.max(12,Math.min(st?.x??t-368,t-352)),x=Math.max(12,Math.min(st?.y??80,o-420)),w=ee?void 0:{left:d,top:x},j=e.jsx("div",{className:`fixed inset-0 z-drawer-backdrop ${ee?"bg-[var(--app-backdrop)]":"bg-transparent"}`,onClick:Yo,children:e.jsxs("div",{className:ee?"fixed inset-x-0 bottom-0 z-drawer-panel max-h-[72vh] overflow-hidden rounded-t-2xl border-t border-border/20 bg-surface-elevated shadow-2xl":"fixed z-drawer-panel w-[21rem] max-w-[calc(100vw-1.5rem)] max-h-[min(26rem,calc(100vh-1.5rem))] overflow-hidden rounded-lg border border-border/20 bg-surface-elevated shadow-xl ring-1 ring-black/5",style:w,onClick:A=>A.stopPropagation(),children:[e.jsxs("div",{className:ee?"flex items-center justify-between border-b border-border/15 px-4 py-3":"flex items-center justify-between border-b border-border/12 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:ee?"text-sm font-semibold text-foreground":"text-xs font-semibold text-foreground",children:i("rightSidebar.repositories")}),!ee&&e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:va.length}),e.jsx("span",{className:`rounded px-1.5 py-0.5 text-[10px] ${we.size>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:we.size})]})]}),e.jsx("button",{type:"button",onClick:Yo,className:ee?"rounded-full bg-surface-2 p-1.5 text-muted-foreground hover:bg-surface hover:text-foreground":"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.close"),children:e.jsx(Kt,{size:ee?16:14})})]}),e.jsx("div",{className:ee?"max-h-[calc(72vh-3.25rem)] overflow-y-auto overscroll-contain px-3 py-2 pb-[calc(env(safe-area-inset-bottom)+5.5rem)]":"max-h-[calc(min(26rem,100vh-1.5rem)-3.5rem)] overflow-y-auto overscroll-contain p-1.5",children:va.map(A=>{const ue=(A.root??null)===oe,ne=vt(A.label)||A.label;return e.jsxs("button",{type:"button",onClick:()=>{Wc(A.root),Yo()},className:`group mb-0.5 flex w-full items-center gap-2 rounded-md text-left transition active:scale-[0.99] ${ee?"px-3 py-2":"px-2 py-1.5"} ${ue?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,title:A.label,role:"option","aria-selected":ue,children:[e.jsx("span",{className:`h-7 w-1 shrink-0 rounded-full ${ue?"bg-primary":"bg-transparent group-hover:bg-border/40"}`}),e.jsx("span",{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md ${ue?"bg-primary/10 text-primary":"bg-surface-2 text-muted-foreground group-hover:text-foreground"}`,children:e.jsx(Ar,{size:13})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`${ee?"text-[13px]":"text-[12px]"} block truncate font-semibold leading-snug`,children:ne}),e.jsx("span",{className:"block truncate text-[10px] leading-snug text-muted-foreground/70",children:A.root===null?i("rightSidebar.allRepositories"):A.label})]}),A.branch&&e.jsx("span",{className:"hidden max-w-[5.5rem] shrink min-w-0 truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline",children:A.branch}),A.deferred?e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground/70",children:i("rightSidebar.repoNotLoaded")}):e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] ${A.count>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:A.count})]},A.root??"all")})})]})});return Nu(j,ee,document.body)}function oh(){return ah()}function jc(t){const o=mt(t,v),d=t.absolutePath||(o?`${o}/${t.path}`:t.path),x=Za(d,o??v);return{key:xt(t),path:t.path,absolutePath:d,displayName:x.name,displayDir:x.dir,oldPath:t.oldPath,status:t.status,title:d}}function Rc(t){return t.oldPath?e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground/60",children:i("rightSidebar.changedFromPath",{path:t.oldPath})}):null}function Cc(t,o){const d=Da(t,v),x=`path:${d}`,w=ke===x,j=et===x,A=w||j;return e.jsx("button",{type:"button",onClick:ue=>{ue.stopPropagation(),lr(d,x)},...Ho(pa(d),x),className:`inline-flex h-6 shrink-0 items-center justify-center overflow-hidden rounded-md text-[11px] font-semibold opacity-100 transition-[max-width,padding,opacity,transform,background-color,color] active:scale-95 ${A?"max-w-20 px-2":"max-w-20 px-2 md:max-w-0 md:px-0 md:opacity-0 md:group-hover:max-w-20 md:group-hover:px-2 md:group-hover:opacity-100"} ${A?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary"}`,title:o,children:e.jsx("span",{className:"whitespace-nowrap",children:i(j?"rightSidebar.copied":w?"rightSidebar.inserted":"rightSidebar.insertFileRef")})})}function Nc(t){const o=mt(t,v),d=t.absolutePath||(o?`${o}/${t.path}`:t.path),x=Ah(t),w=Si(t);return e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Pb,{actions:x,running:_e,completed:Ln?.path===w?Ln:null}),Cc(d,i("rightSidebar.insertThisFile"))]})}function Ec(t,o){const d=o.root??v;if(!d)return null;const x=Da(t,d);return Cc(x,i("fileTree.insertRefTitle"))}function Xo(){return e.jsxs("div",{className:"inline-flex h-7 shrink-0 overflow-hidden rounded-full bg-surface-2 p-0.5","aria-label":i("diffViewer.view"),children:[e.jsx("button",{type:"button",onClick:()=>_c("unified"),"aria-pressed":Bt==="unified",title:i("diffViewer.unifiedMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Bt==="unified"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.unified")}),e.jsx("button",{type:"button",onClick:()=>_c("split"),"aria-pressed":Bt==="split",title:i("diffViewer.splitMode"),className:`inline-flex h-6 items-center rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${Bt==="split"?"bg-surface-elevated text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:i("diffViewer.split")})]})}function Mc(){return ws.map(t=>{const o=Jd(t.files.map(([,j])=>j)),d=Hi({activeGitRepoRoot:oe,groupCount:ws.length,label:t.label,rootName:Xe}),x=!!(d&&t.root&&pr.has(t.root));return{key:t.root??t.label,root:t.root,label:t.label,branch:t.branch,collapsed:x,files:t.files.map(([,j])=>jc(j)),header:d?e.jsxs("div",{className:`flex w-full items-center gap-1.5 px-2 py-1.5 transition hover:bg-surface-2 ${x?"rounded-lg":"rounded-t-lg border-b border-border/10"}`,children:[e.jsxs("button",{type:"button",onClick:()=>jh(t.root),"aria-expanded":!x,className:"flex min-w-0 flex-1 items-center gap-2 text-left active:scale-[0.99]",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:x?e.jsx(Ia,{size:13}):e.jsx(Is,{size:13})}),e.jsx(Ar,{size:12,className:"shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[11px] font-semibold text-foreground",children:t.label}),t.branch&&e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:t.branch})]}),e.jsx("span",{className:"shrink-0 rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:t.files.length}),o>0&&e.jsx("span",{className:"shrink-0 rounded bg-accent/10 px-1.5 py-0.5 text-[10px] text-accent",children:o})]}),t.root&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),La("stage-all",t.root,t.label)},disabled:!!_e,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),La("stash-all",t.root,t.label)},disabled:!!_e,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]})]}):null}})}function $c(){return we.size===0?[{key:"empty",path:"",status:"unknown",repoRoot:null,displayName:i("rightSidebar.noChanges"),diffOverride:"",auditRecords:[]}]:ja.map(([,t])=>{const o=mt(t,v),d=t.absolutePath||(o?`${o}/${t.path}`:t.path);return{key:xt(t),path:t.path,absolutePath:d,status:t.status,repoRoot:o,displayName:Za(d,o).name,displayDir:Za(d,o).dir,auditRecords:Rt}})}function Lc(t){const o=Array.from(we.values()).find(w=>xt(w)===t.key),d=o?mt(o,v):null,x=lp(Rt,d,o?.path??t.path);return e.jsx(Fi,{changeStatus:t.status,auditStatus:x,renderChangeBadge:w=>e.jsx(Ls,{status:w})})}const Sa=a.useCallback(t=>{if(ee)return null;const o=Array.from(t.querySelectorAll("[data-diff-stream-item]"));if(o.length===0)return null;const x=t.getBoundingClientRect().top+48;let w=null,j=Number.POSITIVE_INFINITY;for(const ue of o){const ne=ue.getBoundingClientRect();if(ne.bottom<x)continue;const V=Math.abs(ne.top-x);V<j&&(w=ue,j=V)}const A=w?.dataset.diffSelectionPath??w?.dataset.diffStreamItem??null;return A?(ca.current===A&&J.getState().selectedFilePath===A||(ca.current=A,Ze(A)),A):null},[ee,Ze]),ih=!!(!_e&&ye&&!qe&&(de?.upstream||dn.trim()&&un.trim())),lh=!!(!_e&&ye&&!qe&&(de?.upstream||dn.trim()&&un.trim())),ch=!!(!_e&&ye&&!qe&&Pn.trim()&&Pn.trim()!==de?.branch),Gt=a.useMemo(()=>{const t=Ie.trim().toLowerCase(),o=Array.from(we.entries()).filter(([,d])=>!oe||mt(d,v)===oe).sort(([d],[x])=>d.localeCompare(x));return t?o.filter(([d,x])=>`${d} ${x.path} ${x.status} ${x.repoRelativeRoot??""} ${x.repoName??""}`.toLowerCase().includes(t)):o},[oe,we,Ie,v]);a.useEffect(()=>{Va("selected_file_state",{selectedFilePath:Je,selectedChangedFilePath:zt?.path??null,selectedChangedFileAbsolutePath:zt?.absolutePath??null,selectedChangedFileRepoRoot:zt?.repoRoot??null,rootPath:v,activeGitRepoRoot:oe,rightTab:Eo,effectiveRightTab:ir,diffPaneActive:St,changedFiles:we.size,filteredChangedFiles:Gt.length,gitBundleLoading:Jr,gitBundleLastLoadedAt:Fn})},[oe,we.size,St,ir,Gt.length,Fn,Jr,Eo,v,zt?.absolutePath,zt?.path,zt?.repoRoot,Je]);const ws=a.useMemo(()=>{const t=new Map;for(const o of Gt){const[,d]=o,x=mt(d,v),w=Lb(d)||Xe,j=x??w,A=x?ot.get(x):void 0,ue=t.get(j)??{root:x,label:w,branch:A?.context?.branch,files:[]};ue.files.push(o),t.set(j,ue)}return Array.from(t.values()).sort((o,d)=>o.label===Xe?-1:d.label===Xe?1:o.label.localeCompare(d.label))},[Gt,ot,Xe,v]),ja=a.useMemo(()=>{const t=[],o=new Map;for(const d of Gt)o.set(xt(d[1]),d);for(const d of ws){if(!!(d.root&&Hi({activeGitRepoRoot:oe,groupCount:ws.length,label:d.label,rootName:Xe})&&pr.has(d.root)))continue;if(xr!=="tree"){t.push(...d.files);continue}const w=d.files.map(([,j])=>jc(j));for(const j of Dm(w)){const A=o.get(j.key);A&&t.push(A)}}return t},[oe,pr,xr,ws,Gt,Xe]);a.useEffect(()=>{if(!St||ja.length===0||ee)return;const t=[],o=()=>{const d=document.querySelector(".termdock-diff-stream-scroller");if(d&&Sa(d))return;const x=document.querySelector("[data-diff-stream-item]"),w=x?.dataset.diffSelectionPath??x?.dataset.diffStreamItem??null;if(w){ca.current=w,Ze(w);return}const j=ja[0]?.[1];if(!j)return;const A=xt(j);ca.current=A,Ze(A)};for(const d of[80,240,600,1200])t.push(window.setTimeout(o,d));return()=>t.forEach(d=>window.clearTimeout(d))},[St,ee,ja,Ze,Sa]);const Jo=a.useMemo(()=>{const t=A=>`'${A.replace(/'/g,"'\\''")}'`,o=Zt.length>0?gn:le.filter(A=>A.files.length>0),d=o.length>0?o:v?[{root:v,relativeRoot:".",name:Xe}]:[],x=d.length>0?d.map(A=>`- ${A.relativeRoot==="."?".":A.relativeRoot} (${A.root})`).join(`
1667
1667
  `):`- ${v?".":""}`,w=d.length>0?d.map(A=>` td audit-export ${t(A.root)}`).join(`
1668
1668
  `):" td audit-export",j=d.length>0?" td audit ~/.termdock/change-audit/payload-<repo>.json":" td audit ~/.termdock/change-audit/payload.json";return["任务:为目标仓库的 Git diff hunk 生成自包含审计解释,并通过 Termdock CLI 注入。","",`当前工作区:${v??""}`,"目标仓库:",x,"","执行步骤:","1. 仅对“目标仓库”逐个执行 audit-export。嵌套子仓使用括号内 repo 绝对路径作为命令参数。",w,"2. 先检查 audit-export 输出的 coverage[]:确认 untrackedFiles 是否为空、未跟踪文件是否已经出现在 hunks[].filePath 中;如果 coverage 显示存在未跟踪文件但 hunks[] 未包含对应文件,必须汇报导出异常,不要假装已解释。","3. 读取 audit-export 输出的全部 hunks[].diff,包含 tracked 与 untracked hunks;先理解整批改动的业务目标、行为变化、文件分工和跨 hunk 依赖。","4. 以 audit-export 内置 diff 为分析依据。仅在单个 hunk 信息不足时执行:td audit-show <hunkId> <对应仓库绝对路径>","5. 在 ~/.termdock/change-audit/ 生成批量 payload JSON。"," mkdir -p ~/.termdock/change-audit","6. payload 顶层字段:workspaceRoot、repoRoot、generatedBy、walkthrough、records[]。","7. walkthrough 必须先生成,用三层结构说明整批改动:highlights[] 面向不了解代码的人讲“改了什么/带来什么效果”;nodes[]/edges[] 表达关键链路;risks[]/checks[] 写真实风险和验证。节点可带 anchor,点击后会跳到对应 diff。","8. records[] 必须覆盖每个 hunk 内的多个 section,而不是只写 hunk 总结;从 audit-export hunk 原样复制 filePath、oldPath、newPath、hunkHeader、hunkIndex、fingerprint;如果解释的是 section,额外填写 sectionIndex 和 sectionFingerprint;补充 summary、explanation。","9. 写入 payload 后批量注入:",j,'10. 少量 hunk 或临时补单条时使用:printf "%s\\n" "这里写该 hunk 的改动意义" | td audit-explain <hunkId> <对应仓库绝对路径>',"11. 注入成功后清理本次 payload:rm -f ~/.termdock/change-audit/payload*.json","","payload.walkthrough 示例字段:","{",' "title": "一句话标题",',' "summary": "整批改动的目的和结果",',' "highlights": [{ "what": "改了什么", "effect": "用户或系统得到什么", "tag": "体验" }],',' "nodes": [{ "id": "n1", "title": "节点标题", "kind": "ui", "business": "零上下文业务解释", "anchor": { "repoRoot": "<repoRoot>", "filePath": "<filePath>", "hunkIndex": 0, "hunkFingerprint": "<fingerprint>", "sectionIndex": 0, "sectionFingerprint": "<sectionFingerprint>" } }],',' "edges": [{ "from": "n1", "to": "n2", "label": "调用/传递/消费", "desc": "这条关系的业务含义" }],',' "risks": [{ "title": "真实风险或口径疑问", "anchor": { "filePath": "<filePath>" } }],',' "checks": ["可执行验证动作"]',"}","","写作标准:","- summary:一句话概括该 hunk 在整批改动中的职责。","- explanation:自包含说明业务链路、该 hunk 的作用、解决的问题、与其它 hunk 的关系。","- walkthrough.highlights 必须大白话,不要堆文件名/函数名;只看 highlights 应该知道这次改动干嘛。","- walkthrough.nodes 优先对应方法、关键业务步骤或关键 section;每个有 anchor 的节点必须能跳回真实 diff。","- 面向不了解本轮对话的 AI 编写,补足必要上下文。","- 输出高信息量结论;避免铺垫、套话、流程复述、泛泛风险、逐行翻译 diff。","","完成条件:汇报每个目标仓库已注入的 hunk 数和总数。"].join(`
1669
- `)},[Zt.length,gn,le,Xe,v]),ih=a.useCallback((t="generate")=>{if(wn&&Or.length===0&&!oe){sn(!0);return}const o=t==="generate"?Xo:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Xo].join(`
1670
- `);nt("insert_change_audit_prompt",{rootPath:v,activeGitRepoRoots:Zt,mode:t,hasAuditListCommand:o.includes("td audit-list"),promptLength:o.length}),Lr(i("rightSidebar.insertChangeAuditPrompt"),o,`${rc}:${t}`),or(),c||l()},[oe,Xo,Or.length,Zt,Lr,or,l,c,v,wn,i]),ja=a.useCallback(async t=>{try{await sd({ids:[t]}),nn(o=>o.filter(d=>d.id!==t))}catch{or()}},[or]),lh=a.useCallback(async()=>{if(Rt.length===0)return;const t=Rt.map(o=>o.id);try{await sd({ids:t}),nn(o=>o.filter(d=>!t.includes(d.id))),Br(null)}catch(o){const d=o instanceof Error?o.message:"Failed to clear change audit explanations";Br(i("rightSidebar.changeAuditClearFailed",{message:d})),or()}},[Rt,or,i]),ch=a.useCallback(async t=>{if(t.records.length===0)return;const o=t.records.map(d=>d.id);try{await em({ids:o}),Ur(d=>d.filter(x=>!o.includes(x.id))),rt===t.key&&(Kr(null),tr(!1))}catch(d){bt(i("rightSidebar.branchAuditClearFailed",{message:d instanceof Error?d.message:"Failed to clear branch explanation"})),ua(null)}},[ua,rt,i]),dh=a.useCallback(t=>{Cn(o=>t===null?(sn(!1),[]):o.includes(t)?o.filter(d=>d!==t):[...o,t])},[]),uh=a.useCallback(t=>{bo(o=>t===null?(go(!1),[]):o.includes(t)?o.filter(d=>d!==t):[...o,t])},[]),Jo=a.useMemo(()=>{if(!sr)return[];const t=o=>{const d=o.diff??"";let x=0,w=0;for(const j of d.split(`
1671
- `))j.startsWith("+++")||j.startsWith("---")||(j.startsWith("+")&&(x+=1),j.startsWith("-")&&(w+=1));return{filePath:o.filePath,oldPath:o.oldPath,newPath:o.newPath,hunkHeader:o.hunkHeader,hunkIndex:o.hunkIndex??0,fingerprint:o.fingerprint,additions:x,deletions:w,diff:d}};return De?(De.hunks??[]).map(o=>{const d=Vt.find(x=>x.repoRoot===De.repoRoot&&x.baseRef===De.baseRef&&(x.branchName??null)===(De.currentBranch??null)&&x.filePath===o.filePath&&x.hunkHeader===o.hunkHeader&&(x.hunkIndex??0)===o.hunkIndex&&x.fingerprint===o.fingerprint)??null;return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex}`,hunk:o,current:d,stale:null}}):rt?Vt.filter(o=>Fd(o)===rt).map(o=>{const d=t(o);return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex??0}`,hunk:d,current:o,stale:null}}):[]},[De,Vt,sr,rt]),Zo=Vt.length>0,qn=a.useMemo(()=>{if(!sr)return[];const t=new Map;for(const o of Vt){const d=o.repoRoot,x=ot.get(d),w=x?.relativeRoot==="."?Xe:x?.relativeRoot||x?.name||vt(d),j=Fd(o),A=t.get(j)??{key:j,repoRoot:d,repoLabel:w,baseRef:o.baseRef,branchName:o.branchName??null,headRef:o.headRef??null,diffFingerprint:o.diffFingerprint??null,records:[],latestInjectedAt:0};A.records.push(o),A.latestInjectedAt=Math.max(A.latestInjectedAt,o.injectedAt??0),t.set(j,A)}return Array.from(t.values()).sort((o,d)=>d.latestInjectedAt-o.latestInjectedAt)},[Vt,ot,sr,Xe]),Qo=a.useMemo(()=>rt?qn.find(t=>t.key===rt)??null:null,[qn,rt]),Ra=De?{repoRoot:De.repoRoot??"",repoLabel:De.repoRoot?ot.get(De.repoRoot)?.relativeRoot==="."?Xe:ot.get(De.repoRoot)?.relativeRoot||ot.get(De.repoRoot)?.name||vt(De.repoRoot):Xe,baseRef:De.baseRef??De.baseBranch??"",branchName:De.currentBranch??null,headRef:De.headRef??null,diffFingerprint:De.diffFingerprint??null}:Qo,fh=a.useMemo(()=>(Fe?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,hunk:t,current:null,stale:null})),[Fe?.hunks]),hh=a.useMemo(()=>{if(De)return[];const t=Qo;return t?ns.filter(o=>o.repoRoot===t.repoRoot&&o.baseRef===t.baseRef&&(o.branchName??null)===t.branchName&&(!t.diffFingerprint||o.diffFingerprint===t.diffFingerprint)):[]},[De,ns,Qo]),mh=a.useCallback(t=>{const o=Jo.find(d=>d.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${d.hunk.filePath}`===t.filePath:!1));o&&(qr(o.key),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760))},[Jo]),ei=a.useMemo(()=>{const t=w=>`'${w.replace(/'/g,"'\\''")}'`,o=er,d=o.length>0?o.map(w=>`- ${w.label} (${w.root}),目标分支:${jr[w.root]||w.branch||"(current branch)"},基线分支:${Nt[w.root]||"(not set)"}`).join(`
1669
+ `)},[Zt.length,gn,le,Xe,v]),dh=a.useCallback((t="generate")=>{if(wn&&Ur.length===0&&!oe){sn(!0);return}const o=t==="generate"?Jo:[t==="regenerate"?"模式:重新生成。基于当前 audit-export 为全部 hunk 重新生成解释并覆盖写回。":"模式:补充失效。基于当前 audit-export 补充新增、变更或已失效的 hunk 解释;保留仍有效的解释。","",Jo].join(`
1670
+ `);nt("insert_change_audit_prompt",{rootPath:v,activeGitRepoRoots:Zt,mode:t,hasAuditListCommand:o.includes("td audit-list"),promptLength:o.length}),Lr(i("rightSidebar.insertChangeAuditPrompt"),o,`${ac}:${t}`),or(),c||l()},[oe,Jo,Ur.length,Zt,Lr,or,l,c,v,wn,i]),Ra=a.useCallback(async t=>{try{await id({ids:[t]}),nn(o=>o.filter(d=>d.id!==t))}catch{or()}},[or]),uh=a.useCallback(async()=>{if(Rt.length===0)return;const t=Rt.map(o=>o.id);try{await id({ids:t}),nn(o=>o.filter(d=>!t.includes(d.id))),Or(null)}catch(o){const d=o instanceof Error?o.message:"Failed to clear change audit explanations";Or(i("rightSidebar.changeAuditClearFailed",{message:d})),or()}},[Rt,or,i]),fh=a.useCallback(async t=>{if(t.records.length===0)return;const o=t.records.map(d=>d.id);try{await nm({ids:o}),Hr(d=>d.filter(x=>!o.includes(x.id))),rt===t.key&&(qr(null),tr(!1))}catch(d){bt(i("rightSidebar.branchAuditClearFailed",{message:d instanceof Error?d.message:"Failed to clear branch explanation"})),fa(null)}},[fa,rt,i]),hh=a.useCallback(t=>{Cn(o=>t===null?(sn(!1),[]):o.includes(t)?o.filter(d=>d!==t):[...o,t])},[]),mh=a.useCallback(t=>{bo(o=>t===null?(go(!1),[]):o.includes(t)?o.filter(d=>d!==t):[...o,t])},[]),Zo=a.useMemo(()=>{if(!sr)return[];const t=o=>{const d=o.diff??"";let x=0,w=0;for(const j of d.split(`
1671
+ `))j.startsWith("+++")||j.startsWith("---")||(j.startsWith("+")&&(x+=1),j.startsWith("-")&&(w+=1));return{filePath:o.filePath,oldPath:o.oldPath,newPath:o.newPath,hunkHeader:o.hunkHeader,hunkIndex:o.hunkIndex??0,fingerprint:o.fingerprint,additions:x,deletions:w,diff:d}};return De?(De.hunks??[]).map(o=>{const d=Vt.find(x=>x.repoRoot===De.repoRoot&&x.baseRef===De.baseRef&&(x.branchName??null)===(De.currentBranch??null)&&x.filePath===o.filePath&&x.hunkHeader===o.hunkHeader&&(x.hunkIndex??0)===o.hunkIndex&&x.fingerprint===o.fingerprint)??null;return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex}`,hunk:o,current:d,stale:null}}):rt?Vt.filter(o=>Od(o)===rt).map(o=>{const d=t(o);return{key:`${o.filePath}\0${o.hunkHeader}\0${o.hunkIndex??0}`,hunk:d,current:o,stale:null}}):[]},[De,Vt,sr,rt]),Qo=Vt.length>0,qn=a.useMemo(()=>{if(!sr)return[];const t=new Map;for(const o of Vt){const d=o.repoRoot,x=ot.get(d),w=x?.relativeRoot==="."?Xe:x?.relativeRoot||x?.name||vt(d),j=Od(o),A=t.get(j)??{key:j,repoRoot:d,repoLabel:w,baseRef:o.baseRef,branchName:o.branchName??null,headRef:o.headRef??null,diffFingerprint:o.diffFingerprint??null,records:[],latestInjectedAt:0};A.records.push(o),A.latestInjectedAt=Math.max(A.latestInjectedAt,o.injectedAt??0),t.set(j,A)}return Array.from(t.values()).sort((o,d)=>d.latestInjectedAt-o.latestInjectedAt)},[Vt,ot,sr,Xe]),ei=a.useMemo(()=>rt?qn.find(t=>t.key===rt)??null:null,[qn,rt]),Ca=De?{repoRoot:De.repoRoot??"",repoLabel:De.repoRoot?ot.get(De.repoRoot)?.relativeRoot==="."?Xe:ot.get(De.repoRoot)?.relativeRoot||ot.get(De.repoRoot)?.name||vt(De.repoRoot):Xe,baseRef:De.baseRef??De.baseBranch??"",branchName:De.currentBranch??null,headRef:De.headRef??null,diffFingerprint:De.diffFingerprint??null}:ei,ph=a.useMemo(()=>(Fe?.hunks??[]).map(t=>({key:`${t.filePath}\0${t.hunkHeader}\0${t.hunkIndex}`,hunk:t,current:null,stale:null})),[Fe?.hunks]),gh=a.useMemo(()=>{if(De)return[];const t=ei;return t?ns.filter(o=>o.repoRoot===t.repoRoot&&o.baseRef===t.baseRef&&(o.branchName??null)===t.branchName&&(!t.diffFingerprint||o.diffFingerprint===t.diffFingerprint)):[]},[De,ns,ei]),bh=a.useCallback(t=>{const o=Zo.find(d=>d.hunk.filePath===t.filePath||(t.repoRoot?`${t.repoRoot}/${d.hunk.filePath}`===t.filePath:!1));o&&(Vr(o.key),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760))},[Zo]),ti=a.useMemo(()=>{const t=w=>`'${w.replace(/'/g,"'\\''")}'`,o=er,d=o.length>0?o.map(w=>`- ${w.label} (${w.root}),目标分支:${jr[w.root]||w.branch||"(current branch)"},基线分支:${Nt[w.root]||"(not set)"}`).join(`
1672
1672
  `):`- ${v?".":""}`,x=o.length>0?o.map(w=>{const j=jr[w.root]||w.branch||"",A=Nt[w.root]||"",ue=w.label.replace(/[^A-Za-z0-9_-]+/g,"_")||"repo";return[j?` git -C ${t(w.root)} switch ${t(j)}`:` # ${w.label}: keep current branch`," mkdir -p ~/.termdock/branch-audit",` td branch-audit-export ${t(A)} ${t(w.root)} > ~/.termdock/branch-audit/branch-audit-export-${ue}.json`].join(`
1673
1673
  `)}).join(`
1674
- `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${v??""}`,`包含本地未提交更改:${Gr?"是":"否"}`,"目标仓库:",d,"","操作指令:",Gr?"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。导出内容需要包含目标分支相对基线分支的提交改动,以及当前工作区 staged/unstaged/untracked 改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:":"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。不要包含本地 staged/unstaged/untracked 改动;如果导出结果里混入了本地工作区改动,生成解释时必须忽略这些本地改动,只解释目标分支相对基线分支的提交改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:",x,"2. 读取导出的 ~/.termdock/branch-audit/branch-audit-export*.json 中的 hunks[],不要把临时 JSON 放到业务仓目录,也不要把整份 JSON 粘贴回输入框。导出工具使用 base...HEAD(三点)生成 diff,只表示当前分支独有改动;提交列表使用 base..HEAD(两点)。","3. 先生成 walkthrough,用 highlights[] 说明整批分支改动目的和影响,用 nodes[]/edges[] 画出主链路、分支链路和验证链路;节点可带 anchor,点击后会跳到对应 diff。","4. 逐个 hunk 写解释。解释要说明该 hunk 的意图、解决的问题、影响、风险,以及它和其它 hunk 的关系;不要逐行复述 diff。","5. 每个仓库分别生成 ~/.termdock/branch-audit/payload-<repo>.json,payload 必须包含 workspaceRoot、repoRoot、baseRef、branchName、headRef、diffFingerprint、walkthrough 和 records[];records[] 每条 record 对应一个 hunk,diff 字段必须从 hunk.diff 原样复制。","6. 把解释写入 payload 后执行:td branch-audit ~/.termdock/branch-audit/payload-<repo>.json","7. 注入成功后删除本次生成的临时 JSON:rm -f ~/.termdock/branch-audit/branch-audit-export-*.json ~/.termdock/branch-audit/payload-*.json","","payload 示例:","```json",JSON.stringify({workspaceRoot:v??null,repoRoot:"<target repo root>",baseRef:"<target repo base branch>",branchName:"<from export currentBranch>",headRef:"<from export headRef>",diffFingerprint:"<from export diffFingerprint>",generatedBy:"termdock-branch-audit",walkthrough:{title:"<one-line branch change title>",summary:"<branch change goal and effect>",highlights:[{what:"<what changed>",effect:"<user/system effect>",tag:"<category>"}],nodes:[{id:"n1",title:"<node title>",kind:"process",business:"<zero-context business explanation>",anchor:{repoRoot:"<target repo root>",filePath:"<from hunk.filePath>",hunkIndex:0,hunkFingerprint:"<from hunk.fingerprint>"}}],edges:[{from:"n1",to:"n2",label:"<relationship>",desc:"<business meaning>"}],risks:[{title:"<real risk or validation gap>"}],checks:["<executable validation step>"]},records:[{filePath:"<from hunk.filePath>",oldPath:"<from hunk.oldPath or null>",newPath:"<from hunk.newPath or null>",hunkHeader:"<from hunk.hunkHeader>",hunkIndex:0,fingerprint:"<from hunk.fingerprint>",diff:"<copy from hunk.diff exactly>",explanation:"<replace with hunk explanation>",summary:""}]},null,2),"```"].join(`
1675
- `)},[Gr,er,Nt,jr,v]),ph=a.useCallback((t="generate")=>{const o=t==="generate"?ei:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",ei].join(`
1676
- `);Lr(i("rightSidebar.branchAuditShort"),o,`context:branch-audit-scope:${t}`),c||l()},[ei,Lr,l,c,i]),Ec=a.useCallback(async(t={})=>{const o=t.refresh===!0;if(!v||er.length===0)return;const d=v;ae(!0),He(null),o||(Yt(null),Oe(null));try{const x=await Promise.all(er.map(async V=>{const $e=Nt[V.root]?.trim();if(!$e)throw new Error(i("rightSidebar.branchAuditMissingBase",{repo:V.label}));const Be=(jr[V.root]||V.branch||"").trim();return tm({cwd:v,repoRoot:V.root,base:$e,head:Be&&Be!==V.branch?Be:null,includeUncommitted:Gr,requestSlotId:`right-sidebar-branch-preview:${V.root}`})}));if(!je(d))return;const w=x.find(V=>!V.available);if(w){He(w.error??"Branch diff is unavailable");return}const j=x.length===1?x[0]:{available:!0,workspaceRoot:v,repoRoot:v,baseRef:x.map(V=>V.baseRef??V.baseBranch).filter(Boolean).join(", "),currentBranch:x.map(V=>V.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:x.map(V=>V.headRef).filter(Boolean).join(", "),diffFingerprint:x.map(V=>V.diffFingerprint).filter(Boolean).join("+"),stat:x.map(V=>V.stat).filter(Boolean).join(`
1674
+ `):" td branch-audit-export <base-branch>";return["解释目标仓库当前分支相对于基线分支的改动,并把解释写回 Termdock。","",`当前工作区:${v??""}`,`包含本地未提交更改:${Kr?"是":"否"}`,"目标仓库:",d,"","操作指令:",Kr?"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。导出内容需要包含目标分支相对基线分支的提交改动,以及当前工作区 staged/unstaged/untracked 改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:":"1. 只针对上面列出的目标仓库导出分支 hunk;如果指定了目标分支,先在对应仓库切到目标分支。不要包含本地 staged/unstaged/untracked 改动;如果导出结果里混入了本地工作区改动,生成解释时必须忽略这些本地改动,只解释目标分支相对基线分支的提交改动。嵌套子仓或软链接子仓必须使用括号里的仓库绝对路径,不要改用当前工作区根目录。示例:",x,"2. 读取导出的 ~/.termdock/branch-audit/branch-audit-export*.json 中的 hunks[],不要把临时 JSON 放到业务仓目录,也不要把整份 JSON 粘贴回输入框。导出工具使用 base...HEAD(三点)生成 diff,只表示当前分支独有改动;提交列表使用 base..HEAD(两点)。","3. 先生成 walkthrough,用 highlights[] 说明整批分支改动目的和影响,用 nodes[]/edges[] 画出主链路、分支链路和验证链路;节点可带 anchor,点击后会跳到对应 diff。","4. 逐个 hunk 写解释。解释要说明该 hunk 的意图、解决的问题、影响、风险,以及它和其它 hunk 的关系;不要逐行复述 diff。","5. 每个仓库分别生成 ~/.termdock/branch-audit/payload-<repo>.json,payload 必须包含 workspaceRoot、repoRoot、baseRef、branchName、headRef、diffFingerprint、walkthrough 和 records[];records[] 每条 record 对应一个 hunk,diff 字段必须从 hunk.diff 原样复制。","6. 把解释写入 payload 后执行:td branch-audit ~/.termdock/branch-audit/payload-<repo>.json","7. 注入成功后删除本次生成的临时 JSON:rm -f ~/.termdock/branch-audit/branch-audit-export-*.json ~/.termdock/branch-audit/payload-*.json","","payload 示例:","```json",JSON.stringify({workspaceRoot:v??null,repoRoot:"<target repo root>",baseRef:"<target repo base branch>",branchName:"<from export currentBranch>",headRef:"<from export headRef>",diffFingerprint:"<from export diffFingerprint>",generatedBy:"termdock-branch-audit",walkthrough:{title:"<one-line branch change title>",summary:"<branch change goal and effect>",highlights:[{what:"<what changed>",effect:"<user/system effect>",tag:"<category>"}],nodes:[{id:"n1",title:"<node title>",kind:"process",business:"<zero-context business explanation>",anchor:{repoRoot:"<target repo root>",filePath:"<from hunk.filePath>",hunkIndex:0,hunkFingerprint:"<from hunk.fingerprint>"}}],edges:[{from:"n1",to:"n2",label:"<relationship>",desc:"<business meaning>"}],risks:[{title:"<real risk or validation gap>"}],checks:["<executable validation step>"]},records:[{filePath:"<from hunk.filePath>",oldPath:"<from hunk.oldPath or null>",newPath:"<from hunk.newPath or null>",hunkHeader:"<from hunk.hunkHeader>",hunkIndex:0,fingerprint:"<from hunk.fingerprint>",diff:"<copy from hunk.diff exactly>",explanation:"<replace with hunk explanation>",summary:""}]},null,2),"```"].join(`
1675
+ `)},[Kr,er,Nt,jr,v]),xh=a.useCallback((t="generate")=>{const o=t==="generate"?ti:[t==="regenerate"?"模式:重新生成。请基于当前分支导出结果重新生成全部 hunk 解释并覆盖写回。":"模式:补充失效。请基于当前分支导出结果只补充新增、变更或已失效的 hunk 解释,仍有效的解释不要重复写回。","",ti].join(`
1676
+ `);Lr(i("rightSidebar.branchAuditShort"),o,`context:branch-audit-scope:${t}`),c||l()},[ti,Lr,l,c,i]),Ac=a.useCallback(async(t={})=>{const o=t.refresh===!0;if(!v||er.length===0)return;const d=v;ae(!0),He(null),o||(Yt(null),Oe(null));try{const x=await Promise.all(er.map(async V=>{const $e=Nt[V.root]?.trim();if(!$e)throw new Error(i("rightSidebar.branchAuditMissingBase",{repo:V.label}));const Be=(jr[V.root]||V.branch||"").trim();return sm({cwd:v,repoRoot:V.root,base:$e,head:Be&&Be!==V.branch?Be:null,includeUncommitted:Kr,requestSlotId:`right-sidebar-branch-preview:${V.root}`})}));if(!je(d))return;const w=x.find(V=>!V.available);if(w){He(w.error??"Branch diff is unavailable");return}const j=x.length===1?x[0]:{available:!0,workspaceRoot:v,repoRoot:v,baseRef:x.map(V=>V.baseRef??V.baseBranch).filter(Boolean).join(", "),currentBranch:x.map(V=>V.currentBranch??"HEAD").filter(Boolean).join(", "),headRef:x.map(V=>V.headRef).filter(Boolean).join(", "),diffFingerprint:x.map(V=>V.diffFingerprint).filter(Boolean).join("+"),stat:x.map(V=>V.stat).filter(Boolean).join(`
1677
1677
  `),files:x.flatMap((V,$e)=>{const Be=er[$e];return(V.files??[]).map(Re=>`${Be?.label??V.repoRoot??"repo"}/${Re}`)}),hunks:x.flatMap((V,$e)=>{const Re=er[$e]?.label??V.repoRoot??"repo";return(V.hunks??[]).map(ie=>({...ie,filePath:`${Re}/${ie.filePath}`,oldPath:ie.oldPath?`${Re}/${ie.oldPath}`:ie.oldPath,newPath:ie.newPath?`${Re}/${ie.newPath}`:ie.newPath}))}),commits:x.flatMap(V=>V.commits??[]),commitCount:x.reduce((V,$e)=>V+($e.commitCount??$e.commits?.length??0),0),diff:x.map(V=>V.diff).filter(Boolean).join(`
1678
- `),truncated:x.some(V=>V.truncated)};if((j.hunks??[]).length===0){o?(Yt(j),Kr(null),qr(null)):He(i("rightSidebar.branchAuditDiffEmpty"));return}const A=Date.now(),ue=["preview",j.repoRoot??v,j.baseRef??j.baseBranch??"",j.currentBranch??"",j.headRef??"",j.diffFingerprint??A].join("\0"),ne=er.length===1?er[0].label:`${er.length} repos`;Yt(j),Nn(V=>[{key:ue,diff:j,repoLabel:ne,createdAt:A},...V.filter($e=>$e.key!==ue)].slice(0,8)),o||P(V=>V[ue]===void 0?V:{...V,[ue]:0}),Kr(ue),qr(V=>{const $e=j.hunks?.[0],Be=$e?`${$e.filePath}\0${$e.hunkHeader}\0${$e.hunkIndex}`:null;return o&&V&&(j.hunks??[]).some(Re=>`${Re.filePath}\0${Re.hunkHeader}\0${Re.hunkIndex}`===V)?V:Be}),tr(!0)}catch(x){if(!je(d)||Pr(x))return;He(x instanceof Error?x.message:"Failed to load branch diff")}finally{je(d)&&ae(!1)}},[Gr,er,Nt,jr,je,v,i]),gh=a.useCallback(t=>{Yt(t.diff),He(null),Kr(t.key),qr(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),tr(!0)},[]),bh=a.useCallback(t=>{Nn(o=>o.filter(d=>d.key!==t)),P(o=>{if(!(t in o))return o;const d={...o};return delete d[t],d}),rt===t&&(Kr(null),Yt(null),tr(!1))},[rt]),xh=a.useCallback(t=>{const o=qn.find(d=>d.key===t);o&&(Yt(null),He(null),Kr(t),qr(o.records[0]?.filePath??null),tr(!0))},[qn]),vh=a.useCallback(async t=>{if(!v||!ye)return;const[o]=t.split(/\s+/);if(o){tt(o),rr(null),Oe(null);try{const d=await rm({cwd:v,repoRoot:ye,commit:o,requestSlotId:"right-sidebar-commit-diff"});if(!d.available){rr(d.error??"Commit diff is unavailable");return}Oe(d);const x=d.hunks?.[0];Ws(x?`${x.filePath}\0${x.hunkHeader}\0${x.hunkIndex}`:null)}catch(d){rr(d instanceof Error?d.message:"Failed to load commit diff")}finally{tt(null)}}},[ye,v]),yh=a.useCallback(t=>{if(!De||!rt)return;const o=Math.max(0,Math.round(t));P(d=>Math.abs((d[rt]??0)-o)<24?d:{...d,[rt]:o})},[De,rt]);a.useEffect(()=>{!ee||!kr||!De||ps(1)},[kr,De,ee,ps]);const $c=a.useCallback(t=>{t&&Pf(o=>Pm(o,t))},[]),Lc=ra.key===Je?ra.key:null,Ca=a.useCallback(t=>{const o=J.getState(),d=Bb();Va("select_diff_file",{interactionId:d,path:t,previousSelectedFilePath:o.selectedFilePath,rootPath:o.rootPath,activeGitRepoRoot:oe,changedFiles:o.changedFiles.size,gitBundleLoading:o.gitBundleLoading,gitBundleLastLoadedAt:o.gitBundleLastLoadedAt,rightTab:o.rightTab}),Ze(t),Jt("diff"),ee&&t&&ps(1),$c(t),queueMicrotask(()=>{const x=J.getState();Va("select_diff_file_after",{interactionId:d,requestedPath:t,selectedFilePath:x.selectedFilePath,rootPath:x.rootPath,rightTab:x.rightTab,changedFiles:x.changedFiles.size,activeGitRepoRoot:oe})})},[oe,ee,$c,Ze,Jt,ps]),Ac=a.useCallback(t=>{const o=Array.from(we.values()).find(d=>{const x=mt(d,v),w=xt(d);return d.path===t.filePath||w===t.filePath||d.absolutePath===t.filePath||(x?`${x}/${d.path}`===t.filePath:!1)||t.repoRoot&&x===t.repoRoot&&d.path===t.filePath});if(o){Ca(xt(o)),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760);return}kn(t)},[we,v,Ca]),Pc=a.useCallback(({slideToDetail:t,fullscreen:o,toggleFullscreen:d}={})=>ts.length>0?e.jsx(lu,{walkthroughs:ts,repoRoot:oe,fullscreen:o,onToggleFullscreen:d,onNavigate:x=>{ee&&window.requestAnimationFrame(()=>t?.()),Ac(x)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(Ds,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),i("rightSidebar.changeWalkthroughEmpty")]}),[oe,ts,Ac,ee,i]),wh=a.useCallback(t=>{t&&gr(o=>{const d=new Set(o);return d.has(t)?d.delete(t):d.add(t),mi(di,d),d})},[]),Tc=a.useCallback(t=>{br(o=>{const d=new Set(o);return d.has(t)?d.delete(t):d.add(t),mi(Nd,d),d})},[]),Na=a.useCallback(t=>{Us(t),$t(Cu,t)},[]);a.useEffect(()=>{va||xr!=="ai"||Na("tree")},[xr,Na,va]);const Ma=a.useCallback(()=>{es(t=>{const o=!t;return $t(Nu,o),o})},[]),Ic=a.useCallback(t=>{Hs(t),$t(Mu,t)},[]),{whitespace:Dc,context:Fc}=Im(),_c=a.useMemo(()=>({algorithm:"histogram",whitespace:Dc,context:Fc}),[Dc,Fc]),Bc=a.useCallback(t=>{K(t),$t(Eu,t)},[]),Ea=a.useCallback(async(t,o,d,x)=>{let w=t;for(;w.ok&&w.status==="running";)await new Promise(A=>window.setTimeout(A,1500)),w=await ad({jobId:w.jobId,cwd:o.cwd,action:o.action});if(!w.ok)throw new Error("Git action status is unavailable");if(w.status==="error")throw new Error(w.error||w.message||"Git action failed");const j={action:o.action,path:x,label:d};return ds(j),window.setTimeout(()=>ds(A=>A?.action===j.action&&A.path===j.path?null:A),1400),w},[]),ht=a.useCallback(async(t,o,d)=>{const x=v;v&&ar.current.delete(v),bt(null),ds(null),cs({action:t.action,path:d});try{const w=await nm({...t,includeNested:Yn(v)}),j=await Ea(w,t,o,d);if(!je(x))return!1;const A=v?await Pa(v,void 0,{includeNested:Yn(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Jn(v)}).catch(()=>j.bundle):j.bundle;return je(x)?(A&&en(A,{reloadDiff:!0,cacheOnly:!0}),Yr(null),!0):!1}catch(w){return ds(null),bt(i("rightSidebar.gitActionFailed",{message:w instanceof Error?w.message:"Unknown error"})),!1}finally{je(x)&&cs(null)}},[en,je,v,i,Ea]),Oc=a.useCallback(async t=>{const o=v,d=await sm({...t,includeNested:Yn(v)});if(!je(o))return;const x=v?await Pa(v,void 0,{includeNested:Yn(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Jn(v)}).catch(()=>d.bundle):d.bundle;je(o)&&x&&en(x,{reloadDiff:!0,cacheOnly:!0})},[en,je,v]),$a=a.useCallback((t,o,d)=>{if(o){if(t==="stage-all"){ht({action:"stage-all",cwd:o},i("rightSidebar.stageAll"),`repo:${o}`);return}Yr({kind:"stash-all",repoRoot:o,repoLabel:d})}},[ht,i]),Uc=a.useCallback(t=>{Ee(t),Js(""),Zs(""),Qs(""),Ze(fc(t)),Qe||Jt("diff"),t&&ba(ot.get(t))},[ba,fc,Qe,ot,Ze,Ee,Jt]),Hc=a.useCallback(t=>{const o=new Set([...Ht.current.keys(),...mn.current,...ar.current]);for(const d of o)d!==t&&(Ut.current.delete(d),Ht.current.get(d)?.abort(),Ht.current.delete(d),kt(`right-sidebar-git-untracked:${d}`),mn.current.delete(d),ar.current.delete(d))},[]),kh=a.useCallback(async t=>{const o=v;if(!o||(await J.getState().setNestedGitScanRoot(o,t),!je(o)))return;if(t){await Qt(o,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Hc(o),Js(""),Zs(""),Qs(""),bo(x=>x.filter(w=>w===o));const d=zt;d&&mt(d,o)!==o&&Ze(null),await Qt(o,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Hc,je,Qt,v,Ze,zt]),Sh=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=Pn.trim();!t||t===de?.branch||await ht({action:"switch-branch",cwd:ye,branch:t},i("rightSidebar.switchBranch"))},[de?.branch,ye,qe,ht,Pn,i]),zc=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=Xs.trim();if(!t)return;await ht({action:"commit",cwd:ye,message:t},i("rightSidebar.commitChanges"))&&wl("")},[ye,Xs,qe,ht,i]),jh=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=dn.trim(),o=un.trim();await ht({action:"push",cwd:ye,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pushChanges"))},[ye,un,dn,qe,ht,i]),Rh=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=dn.trim(),o=un.trim();await ht({action:"pull",cwd:ye,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pullChanges"))},[ye,un,dn,qe,ht,i]);a.useEffect(()=>{if(!Qe||!ye||_e)return;let t=!1;const o={push:i("rightSidebar.pushChanges"),pull:i("rightSidebar.pullChanges"),commit:i("rightSidebar.commitChanges"),"switch-branch":i("rightSidebar.switchBranch"),"stage-all":i("rightSidebar.stageAll"),"stash-all":i("rightSidebar.stashAll")};return(async()=>{for(const d of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const x=await ad({cwd:ye,action:d}).catch(()=>null);if(!x?.ok||x.status!=="running")continue;const w={action:d,cwd:ye},j=o[d]??d;cs({action:d});try{const A=await Ea(x,w,j);if(t||!je(v))return;const ue=v?await Pa(v,void 0,{includeNested:Yn(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Jn(v)}).catch(()=>A.bundle):A.bundle;ue&&en(ue,{reloadDiff:!0,cacheOnly:!0})}catch(A){t||bt(i("rightSidebar.gitActionFailed",{message:A instanceof Error?A.message:"Unknown error"}))}finally{t||cs(null)}return}})(),()=>{t=!0}},[ye,en,Qe,je,v,_e,i,Ea]);const ti=Ln?.action==="commit",ri=Ln?.action==="switch-branch",ni=Ln?.action==="pull",si=Ln?.action==="push",La=Qe||Lf,ai=wa?i("rightSidebar.changeAuditScopeAll"):cr.length===1?cr[0].label:`${cr.length} repos`,Ch=cr.length>0,Wc=er.length>0,Nh=v?e.jsx(Gd,{open:po,onOpenChange:go,showScopePicker:!0,selectedAll:wa,repos:Wt,selectedRoots:ya,onToggleRepo:uh,onGenerate:()=>ph(Zo?"regenerate":"generate"),disabled:!Ch,generateDisabled:!Wc,inserted:ke?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:i(Zo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.branchAuditGenerateTitle"),ariaLabel:i("rightSidebar.branchAuditShort"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:ai,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i(Zo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ec()},secondaryDisabled:!Wc||z,secondaryLabel:i("rightSidebar.branchAuditViewDiff"),secondaryTitle:i("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:z,loading:ml.size>0,statusTitle:ml.size>0?i("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:i("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:i("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:Gr,onChange:t=>hl(t.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),bc.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:i("rightSidebar.missingBaseReposSkipped",{repositories:bc.map(t=>t.label).join(O==="zh"?"、":", ")})})]}),renderRepoExtra:t=>{const o=ot.get(t.root),d=[],x=new Set,w=(ne,V)=>{!ne||x.has(ne)||(x.add(ne),d.push({value:ne,label:ne,meta:V}))};w(jr[t.root]||o?.context?.branch,i("rightSidebar.pushCurrentBranchBadge"));for(const ne of o?.context?.branches??[])w(ne,ne===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):i("rightSidebar.localBranch"));for(const ne of o?.context?.remoteBranches??[])w(ne,i("rightSidebar.remoteBranch"));const j=[],A=new Set,ue=(ne,V)=>{!ne||A.has(ne)||(A.add(ne),j.push({value:ne,label:ne,meta:V}))};ue(Nt[t.root],Nt[t.root]?i("rightSidebar.pushUpstreamBadge"):void 0),ue(o?.context?.upstream,o?.context?.upstream?i("rightSidebar.pushUpstreamBadge"):void 0);for(const ne of o?.context?.remoteBranches??[])ue(ne,"remote");for(const ne of o?.context?.branches??[])ue(ne,ne===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Xn,{label:i("rightSidebar.currentBranchLabel"),value:jr[t.root]||o?.context?.branch||"",options:d,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),onChange:ne=>{Ks(V=>({...V,[t.root]:ne}))}}),e.jsx(Xn,{label:i("rightSidebar.branchAuditBaseLabel"),value:Nt[t.root]||"",options:j,placeholder:i("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:i("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:i("rightSidebar.branchAuditBaseEmpty"),onChange:ne=>{qs(V=>({...V,[t.root]:ne}))}})]})}}):null,Gc=Cs(Rt.reduce((t,o)=>Math.max(t,o.injectedAt??0),0),O),Mh=v?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>fl(t=>{const o=!t;return $t(ui,o),o}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":ls,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Ds,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:ai})]}),e.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${ls?"rotate-90":""}`,children:e.jsx(Ia,{size:13})})]}),ls&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[i("rightSidebar.changeAuditScopeLabel"),": ",ai]}),Nh]}),Se&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Se}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[an.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>gh(t),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.baseRef??t.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:i("rightSidebar.branchAuditViewDiff")})]}),Cs(t.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Cs(t.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>bh(t.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("common.delete"),"aria-label":i("common.delete"),children:e.jsx(Ya,{size:12})})]},t.key)),qn.length>0?qn.slice(0,Math.max(0,8-an.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>xh(t.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.baseRef}),t.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diffFingerprint})]}),Cs(t.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:i("rightSidebar.branchAuditGeneratedAt",{time:Cs(t.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{ch(t)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("rightSidebar.branchAuditClearTitle"),"aria-label":i("rightSidebar.branchAuditClearTitle"),children:e.jsx(Ya,{size:12})})]},t.key)):an.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Kc=sr&&v&&Kn?e.jsxs("div",{className:La?"overflow-visible":"overflow-hidden",children:[Mh,e.jsxs("button",{type:"button",onClick:()=>{Qe||Af(t=>{const o=!t;return o&&ye&&!Kn&&!cn&&_o(ye),o})},"aria-expanded":La,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${Qe?"cursor-default":"rounded-lg hover:bg-surface-2 active:scale-[0.99]"}`,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Ar,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${yn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[cn&&e.jsx(St,{size:10,className:"animate-spin"}),yn.staged>0?i("rightSidebar.stagedCount",{count:yn.staged}):i("rightSidebar.noStagedChangesShort")]}),!Qe&&e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${La?"rotate-90":""}`,children:e.jsx(Ia,{size:13})})]})]}),La&&e.jsxs("div",{className:"space-y-0",children:[It.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Xf})]})}),e.jsx(Xn,{label:i("rightSidebar.gitRepositoryLabel"),value:ye??"",options:It,placeholder:i("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:i("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:i("rightSidebar.gitRepositoryEmpty"),disabled:!!_e,onChange:t=>{Uc(t||null)}}),qe&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:i("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Pn!==uc?uc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{Sh()},disabled:!oh,className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${ri?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.switchBranch"),children:[e.jsx("span",{className:_e?.action==="switch-branch"||ri?"opacity-0":"",children:i("rightSidebar.switchBranch")}),_e?.action==="switch-branch"&&e.jsx(St,{size:12,className:"absolute animate-spin"}),ri&&_e?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Xn,{label:i("rightSidebar.currentBranchLabel"),value:Pn,options:Qf,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),disabled:!!_e,onChange:Js})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:qe?i("rightSidebar.selectRepositoryForGitActions"):yn.staged>0?i("rightSidebar.commitReadyHint",{count:yn.staged}):i("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{zc()},disabled:!!_e||qe||yn.staged===0||!Xs.trim(),className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition active:scale-95 ${ti?"bg-accent/10 text-accent disabled:bg-accent/10 disabled:text-accent":"bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-surface-2 disabled:text-muted-foreground"} disabled:cursor-not-allowed`,title:qe?i("rightSidebar.selectRepositoryForGitActions"):yn.staged===0?i("rightSidebar.commitNeedsStaged"):i("rightSidebar.commitChanges"),children:[e.jsx("span",{className:_e?.action==="commit"||ti?"opacity-0":"",children:i("rightSidebar.commitChanges")}),_e?.action==="commit"&&e.jsx(St,{size:12,className:"absolute animate-spin"}),ti&&_e?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Xs,onChange:t=>wl(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),zc())},placeholder:i("rightSidebar.commitMessagePlaceholder"),disabled:!!_e,className:"w-full min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-[13px] placeholder:text-[13px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>Mn(t=>!t),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Xt,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:i("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[ze&&e.jsx(St,{size:12,className:"animate-spin text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Xt?"rotate-90":""}`,children:e.jsx(Ia,{size:13})})]})]}),Xt&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:12,className:"shrink-0"}),e.jsx("input",{value:os,onChange:t=>on(t.target.value),placeholder:i("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),os&&e.jsx("button",{type:"button",onClick:()=>on(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Kt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:Jf,children:[ln.length>0?ln.map(t=>{const[o,...d]=t.split(/\s+/),x=d.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{vh(t)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:x,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:o}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:x,children:x}),Sr[o]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${Sr[o]==="ahead"?"bg-accent/10 text-accent":Sr[o]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:i(Sr[o]==="ahead"?"rightSidebar.commitAhead":Sr[o]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),Ge===o&&e.jsx(St,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):ze?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:i("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.recentCommitsEmpty")}),zr&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(St,{size:12,className:"animate-spin"})}),mo&&!zr&&ln.length>0&&e.jsx("button",{type:"button",onClick:()=>{ys({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:i("rightSidebar.recentCommitsLoadMore")})]})]}),Ct&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Ct}),dl&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:dl})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{Rh()},disabled:!sh,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${ni?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pullChanges"),children:[e.jsx("span",{className:_e?.action==="pull"||ni?"opacity-0":"",children:i("rightSidebar.pullChanges")}),_e?.action==="pull"&&e.jsx(St,{size:12,className:"absolute animate-spin"}),ni&&_e?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{jh()},disabled:!ah,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${si?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pushChanges"),children:[e.jsx("span",{className:_e?.action==="push"||si?"opacity-0":"",children:i("rightSidebar.pushChanges")}),_e?.action==="push"&&e.jsx(St,{size:12,className:"absolute animate-spin"}),si&&_e?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${vc.className}`,title:de?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:vc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:de?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${gc?"grid-cols-2":"grid-cols-1"}`,children:[gc&&e.jsx(Xn,{label:i("rightSidebar.pushRemoteLabel"),value:dn,options:pc,placeholder:i("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:i("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:i("rightSidebar.pushNoRemotes"),disabled:!!_e,onChange:Zs}),e.jsx(Xn,{label:i("rightSidebar.pushBranchLabel"),value:un,options:eh,placeholder:i("rightSidebar.pushBranchPlaceholder",{branch:de?.branch??"HEAD"}),searchPlaceholder:i("rightSidebar.pushBranchSearchPlaceholder"),emptyText:i("rightSidebar.pushNoBranches"),disabled:!!_e,onChange:Qs})]})]})]})]}):null,Eh=a.useCallback(t=>{const o=mt(t,v);if(!o)return[];const d=ki(t),x=[];return t.canStage&&x.push({key:"stage-file",label:i("rightSidebar.stageFile"),onClick:()=>{ht({action:"stage-file",cwd:o,paths:[t.path]},i("rightSidebar.stageFile"),d)}}),t.canUnstage&&x.push({key:"unstage-file",label:i("rightSidebar.unstageFile"),onClick:()=>{ht({action:"unstage-file",cwd:o,paths:[t.path]},i("rightSidebar.unstageFile"),d)}}),t.canStash&&x.push({key:"stash-file",label:i("rightSidebar.stashFile"),onClick:()=>{ht({action:"stash-file",cwd:o,paths:[t.path]},i("rightSidebar.stashFile"),d)}}),t.canRestoreWorktree&&x.push({key:"restore-worktree-file",label:i("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Yr({kind:"restore",file:t,phrase:""})}),x},[v,ht,i]),$h=a.useCallback(()=>{if(g){k?.();return}Cr(0),Mr.current?.slideTo(0),Rr(!1),pt(null)},[k,g]),qc=a.useCallback(t=>{if(G(""),Ot(t),Ze(null),pt(null),te(null),ee){g&&k?.(),Cr(0),Mr.current?.slideTo(0),Rr(!1);return}},[ee,k,g,Ze,Ot]);a.useEffect(()=>{const t=o=>{const d=o.detail,x=d?.path;if(typeof x!="string"||!x.startsWith("/"))return;G(""),pt(null),Lt(null);const w=!!(v&&(x===v||x.startsWith(`${v}/`)));if(d.kind==="file"){const j=vi(x);gs(x),typeof d.line=="number"&&Number.isSafeInteger(d.line)&&d.line>0&&Lt(d.line),Ot(w?null:j),te(A=>({path:x,nonce:(A?.nonce??0)+1}));return}Ze(null),w?(Ot(null),te(j=>({path:x,nonce:(j?.nonce??0)+1}))):(te(null),Ot(x)),ee&&(g&&k?.(),Cr(0),Mr.current?.slideTo(0),Rr(!1))};return window.addEventListener(ud,t),()=>window.removeEventListener(ud,t)},[gs,ee,k,g,v,Ze,Ot]),a.useEffect(()=>{r||(_t(!1),hr(!1))},[r]),a.useEffect(()=>{if(!ur&&!fr)return;const t=o=>{o instanceof globalThis.KeyboardEvent&&o.key!=="Escape"||o instanceof globalThis.MouseEvent&&o.target instanceof Node&&(Sn.current?.contains(o.target)||jn.current?.contains(o.target))||(_t(!1),hr(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[fr,ur]);const Vc=e.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[e.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:qf,disabled:!pa,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.parentFolder"),title:i("rightSidebar.parentFolder"),children:e.jsx(nu,{size:14})}),e.jsx("button",{type:"button",onClick:nc,disabled:!v||In===v,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.backToProjectRoot"),title:i("rightSidebar.backToProjectRoot"),children:e.jsx(fd,{size:14})}),e.jsx("button",{type:"button",onClick:Vf,disabled:!ge,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.refreshFiles"),title:kl?i("rightSidebar.fileWatchUnavailable",{message:kl}):i("rightSidebar.refreshFiles"),children:e.jsx(Ei,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ge??void 0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:Gf}),oa==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:i("fileTree.sortedByModified"),"aria-label":i("fileTree.sortedByModified"),children:e.jsx(hd,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ge&&lr(ge,Tt??void 0),disabled:!ge,...ge&&Tt?Ho(ma(ge),Tt):{},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${Tt&&(ke===Tt||et===Tt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":i(Tt&&et===Tt?"rightSidebar.copied":Tt&&ke===Tt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:i("rightSidebar.insertCurrentFolder"),children:Tt&&(ke===Tt||et===Tt)?e.jsx(Ci,{size:13}):e.jsx(Qa,{size:13})}),e.jsxs("div",{ref:jn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{_t(!1),hr(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${fr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":fr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(Mi,{size:14})}),fr&&e.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{hr(!1),Yf()},disabled:!Go,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${xs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[xs?e.jsx(ii,{size:14}):e.jsx(Fa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(xs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{hr(!1),If()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${Eo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Eo?e.jsx(Bm,{size:14}):e.jsx(Ti,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(Eo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ge,onClick:()=>{ge&&(hr(!1),Df(ge,oa==="modified"?"name":"modified"))},className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-40",children:[oa==="modified"?e.jsx(Sm,{size:14}):e.jsx(hd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(oa==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),v&&(ga.length>0||Kf)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:nc,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-md px-2 py-0.5 font-medium transition active:scale-95 ${ge===v?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:v,children:[e.jsx(fd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Xe})]}),ga.map(t=>{const o=t.path,d=t.kind==="file",x=d?Je===o:ge===o;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${x?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o,children:[e.jsxs("button",{type:"button",onClick:()=>d?gs(o):Ot(o),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[d?e.jsx(Ii,{size:10,className:"shrink-0"}):e.jsx(Fa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:vt(o)})]}),e.jsx("button",{type:"button",onClick:()=>fn(o),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":i("rightSidebar.unpinFolder",{name:vt(o)}),title:i("rightSidebar.unpinFolder",{name:vt(o)}),children:e.jsx(Kt,{size:9})})]},o)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),oi=a.useMemo(()=>{if(An===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,o=Math.max(0,Math.floor((jo-An)/1e3)),d=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[x,w]=o<60?[-o,"second"]:o<3600?[-Math.floor(o/60),"minute"]:o<86400?[-Math.floor(o/3600),"hour"]:[-Math.floor(o/86400),"day"];return d.format(x,w)},[jo,An]),Yc=v&&!Hn?e.jsx("button",{type:"button",onClick:()=>{kh(!$o)},"aria-pressed":$o,title:i("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${$o?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:i("rightSidebar.multiRepoScan")}):null,Xc=v?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[oi?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:i("rightSidebar.gitLastUpdated",{time:oi}),children:oi}):null,e.jsx("button",{type:"button",onClick:()=>{ms()},disabled:Xr,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":i("rightSidebar.refreshGit"),title:i("rightSidebar.refreshGit"),children:e.jsx(Ei,{size:13,className:Xr?"animate-spin":""})})]}):null,Lh=Wl?i("rightSidebar.changeAuditScopeAll"):gn.length===1?gn[0].relativeRoot==="."?Xe:gn[0].relativeRoot||gn[0].name:`${gn.length} repos`,Jc=v?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(Gd,{open:rs,onOpenChange:sn,showScopePicker:wn,selectedAll:Wl,repos:Ff,selectedRoots:Zt,onToggleRepo:dh,onGenerate:()=>ih(),disabled:!v,inserted:ke===rc,buttonLabel:i("rightSidebar.changeAuditShort"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:i("rightSidebar.insertChangeAuditPrompt"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Lh,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i("rightSidebar.changeAuditShort"),loading:_r,error:!!wr,statusTitle:wr??(_r?i("rightSidebar.changeAuditLoading"):Rt.length>0?`${i("rightSidebar.changeAuditLoaded",{count:Rt.length})}${Gc?` · ${i("rightSidebar.changeAuditLoadedAt",{time:Gc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{lh()},disabled:_r||Rt.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Rt.length>0?"":"invisible"}`,title:i("rightSidebar.clearChangeAuditTitle"),"aria-label":i("rightSidebar.clearChangeAudit"),children:e.jsx(Ya,{size:12})})]}):null,Aa=e.jsxs("div",{className:"flex h-5 flex-nowrap items-center gap-1 overflow-x-auto whitespace-nowrap text-[10px] font-medium [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0",children:[S?.available&&S.branch&&e.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:S.branch,children:[e.jsx(Ar,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:S.branch})]}),dt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[dt.modified,"M"]}),dt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",dt.added]}),dt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",dt.deleted]}),dt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.renamed,"R"]}),dt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.copied,"C"]}),dt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.untracked,"U"]}),dt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[dt.conflicted,"!"]}),dt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.other,"?"]}),dt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:i("rightSidebar.stagedCountShort",{count:dt.staged})}),S?.available&&v&&we.size>0&&le.length<=1&&e.jsx("button",{type:"button",onClick:()=>{ht({action:"stage-all",cwd:v},i("rightSidebar.stageAll"))},disabled:!!_e,className:"rounded-md bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),S?.available&&v&&we.size>0&&le.length<=1&&e.jsx("button",{type:"button",onClick:()=>Yr({kind:"stash-all",repoRoot:v,repoLabel:Xe}),disabled:!!_e,className:"rounded-md bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]});return e.jsxs(jm,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h,children:[Ho.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${Of?"hidden":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:v??void 0,children:Xe}),(!ee||yo)&&S?.available&&S.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:S.branch,children:[e.jsx(Ar,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:S.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!xe;W(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):G("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${xe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleSearch"),title:i("common.search"),children:e.jsx(Zn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":lt,onClick:()=>{ct(t=>!t),Ft(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${lt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleContextDraft"),title:i("rightSidebar.contextDraftTitle"),children:[e.jsx(Rm,{size:14}),!lt&&be.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:Cl,type:"file",multiple:!0,className:"hidden",onChange:t=>{const o=t.target.files;!o||o.length===0||(bs(Array.from(o)),t.target.value="")}}),e.jsx("input",{ref:Nl,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const o=t.target.files?.[0];t.target.value="",o&&zf(o)}}),p&&e.jsx("button",{type:"button",onClick:p,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${h?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(ii,{size:14}):e.jsx(Fa,{size:14})}),e.jsxs("div",{ref:Sn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{hr(!1),_t(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${ur?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":ur,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(Mi,{size:15})}),ur&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Vr,onClick:()=>Hf(!Vr),className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2",children:[e.jsx(od,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:i("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Vr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Vr?"left-3.5":"left-0.5"}`})})]}),e.jsx("div",{className:"my-1 h-px bg-border/15",role:"separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),Cl.current?.click()},disabled:ea,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ea?e.jsx(St,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Ym,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),Nl.current?.click()},disabled:ea,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ea?e.jsx(St,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(zm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.insertLocalImage")})]}),p&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),p()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${h?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[h?e.jsx(ii,{size:14}):e.jsx(Fa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),h&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":i("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:i("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",i("rightSidebar.layoutModeAuto")],["narrow",i("rightSidebar.layoutModeNarrow")],["wide",i("rightSidebar.layoutModeWide")]].map(([t,o])=>{const d=Y===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":d,onClick:()=>{L(t),_t(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${d?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:o},t)})})]})]})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":i("rightSidebar.close"),children:e.jsx(Kt,{size:14})})]}),xe&&e.jsxs("div",{className:"mt-2 space-y-1.5 pb-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-3 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:R,onChange:t=>G(t.target.value),placeholder:i(I==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Bc("name"),"aria-pressed":I==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${I==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Bc("content"),"aria-pressed":I==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${I==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeContent")})]}),R&&e.jsx("button",{type:"button",onClick:()=>G(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Kt,{size:12})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg bg-surface-2 px-2.5 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Cm,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:re,onChange:t=>ce(t.target.value),onKeyDown:t=>{t.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchScopePlaceholder"),"aria-label":i("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),re!=="."&&e.jsx("button",{type:"button",onClick:()=>ce("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.resetSearchScope"),children:e.jsx(Kt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>M(t=>!t),"aria-expanded":Me,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${Me||us.length>0||Z||Ne||Ce?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:i("rightSidebar.searchOptions"),"aria-label":i("rightSidebar.searchOptions"),children:[e.jsx(Nm,{size:13}),us.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 min-w-4 rounded-full bg-primary px-1 text-[8px] font-bold leading-4 text-primary-foreground",children:us.length})]})]}),Me&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ve,onChange:t=>pe(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchExcludePlaceholder"),"aria-label":i("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ve&&e.jsx("button",{type:"button",onClick:()=>pe(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.clearSearchExclude"),children:e.jsx(Kt,{size:11})})]}),I==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":i("rightSidebar.contentSearchOptions"),children:[[Z,()=>he(t=>!t),Fm,i("rightSidebar.matchCase")],[Ne,()=>Ve(t=>!t),Jm,i("rightSidebar.matchWholeWord")],[Ce,()=>Ye(t=>!t),Gm,i("rightSidebar.useRegex")]].map(([t,o,d,x])=>e.jsxs("button",{type:"button",onClick:o,"aria-pressed":t,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${t?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(d,{size:12}),x]},x))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(Hn?2:3)+(Vr?1:0)}, minmax(0, 1fr))`},children:[!Hn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>Jt("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Ar,{size:12}),i("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>Jt("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(pu,{size:12}),i("rightSidebar.tabChanges"),we.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:we.size}):null]})]}),e.jsxs("button",{type:"button",onClick:()=>Jt("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Lm,{size:12}),i("rightSidebar.tabFiles")]}),Vr&&e.jsxs("button",{type:"button",onClick:()=>Jt("android"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(od,{size:12}),i("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),vl&&e.jsx("div",{className:"pointer-events-none absolute right-3 top-10 z-20 max-w-[72%] rounded-lg bg-destructive/95 px-3 py-2 text-[11px] font-medium text-destructive-foreground shadow-md animate-fade-in",children:vl})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Ka,{active:Qe,mounted:sr,fallback:e.jsx(xi,{slow:!1}),children:Fe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(vd,{items:fh,selectedKey:Cf,onSelect:Ws,emptyText:i("rightSidebar.noChanges"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i("rightSidebar.recentCommitsTitle"),headerMeta:`${Fe.headRef??""}${Fe.commits?.[0]?` · ${Fe.commits[0]}`:""}`,onClose:()=>{Oe(null),Ws(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?Ma:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:Er,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:ja})}):kr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(vd,{items:Jo,selectedKey:xo,onSelect:qr,emptyText:i(De?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i(De?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:Ra?`${Ra.repoLabel} · ${Ra.branchName??"HEAD"} → ${Ra.baseRef}`:void 0,onClose:()=>{tr(!1),Yt(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?Ma:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:Er,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:ja,onRefresh:()=>{Ec({refresh:!0})},refreshing:z,refreshLabel:i("rightSidebar.branchAuditRefreshDiff"),refreshTitle:i("rightSidebar.branchAuditRefreshDiff"),walkthroughs:hh,onWalkthroughNavigate:mh,initialDetailScrollTop:De&&rt?as[rt]:void 0,onDetailScrollPositionChange:yh,externalSwiperRef:ee?da:void 0,onMobileSlideChange:ee?vo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:Kc?e.jsx("div",{className:"px-3",children:Kc}):Xr?e.jsx(xi,{slow:Il}):hn?e.jsx(qa,{message:hn,onRetry:()=>{ms()}}):Xd(S)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):S?.available===!1?e.jsx(qa,{message:S.error??i("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{ms()}}):v?e.jsx(xi,{slow:Il}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Ka,{active:zn,children:ee?e.jsxs(au,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:t=>{Mr.current=t,t.slideTo(gl,0)},onSlideChange:t=>{if(Cr(t.activeIndex),hs.current===t.activeIndex){hs.current=null;return}t.activeIndex===0&&(Rr(!1),pt(null),k?.())},children:[e.jsx($i,{className:"h-full min-h-0",children:e.jsxs("div",{ref:_n,onScroll:Kl,onDragOver:fa,onDragEnter:fa,onDragLeave:Yl,onDrop:Xl,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[Sl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!R.trim()&&Vc,e.jsx(md,{rootPath:ge??"",onFileSelect:gs,onPathReference:lr,getReferenceText:ma,onReferenceCopied:Er,insertedReferenceKey:ke,copiedReferenceKey:et,onDirectoryRoot:sc,onSearchFromDirectory:ac,onDirectoryPinToggle:oc,onFilePinToggle:ic,pinnedPaths:xn,selectedFilePath:Je,query:Ie,searchRootPath:Bl,searchOptions:Ol,searchMode:I,onContentMatchSelect:ql,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:fe,canOpenInFileBrowser:jl,onOpenInFileBrowser:Vl})]})}),e.jsx($i,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Xi,{filePath:zn&&(Nf||gl===1)?Je:null,onInsertReference:lr,onInsertText:$r,onInsertFeature:$r,onReviewReference:ec,onReferenceCopied:Er,onClose:$h,onDirectoryLinkOpen:qc,isMobile:!0,lineRange:Rn,onLineRangeChange:pt,insertedReferenceKey:ke,copiedReferenceKey:et,scrollToLine:Ue,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:m})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:_n,onScroll:Kl,onDragOver:fa,onDragEnter:fa,onDragLeave:Yl,onDrop:Xl,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Co},children:[Sl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!R.trim()&&Vc,e.jsx(md,{rootPath:ge??"",onFileSelect:gs,onPathReference:lr,getReferenceText:ma,onReferenceCopied:Er,insertedReferenceKey:ke,copiedReferenceKey:et,onDirectoryRoot:sc,onSearchFromDirectory:ac,onDirectoryPinToggle:oc,onFilePinToggle:ic,pinnedPaths:xn,selectedFilePath:Je,query:Ie,searchRootPath:Bl,searchOptions:Ol,searchMode:I,onContentMatchSelect:ql,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:fe,canOpenInFileBrowser:jl,onOpenInFileBrowser:Vl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":i("rightSidebar.resizeFileTree"),title:i("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:_f,onPointerMove:Bf,onPointerUp:Gl,onPointerCancel:Gl,onDoubleClick:()=>{No(Oi),$t(Ns,Oi)},children:e.jsx("span",{className:"absolute left-1/2 top-0 h-full w-px -translate-x-1/2 bg-border/20 transition group-hover:bg-primary/45"})}),e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Xi,{filePath:zn?Je:null,onInsertReference:lr,onInsertText:$r,onInsertFeature:$r,onReviewReference:ec,onReferenceCopied:Er,onDirectoryLinkOpen:qc,isMobile:!1,lineRange:Rn,onLineRangeChange:pt,insertedReferenceKey:ke,copiedReferenceKey:et,scrollToLine:Ue,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:B,markdownOutlineCloseSignal:E,onOpenMarkdownOutline:N,onCloseMarkdownOutline:$,markdownImageLightboxOpen:T,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:m})})]})}),e.jsx(Ka,{active:wt,mounted:Mf||wt,children:()=>Bo?e.jsx(Mm,{}):ee?e.jsx(Li,{mobile:!0,backLabel:i("rightSidebar.backToChangeList"),externalSwiperRef:da,onMobileSlideChange:vo,groups:Gt.length>0?Cc():[],mode:xr,onModeChange:Na,selectedKey:Je,scrollToKey:Lc,scrollToKeyNonce:ra.nonce,compact:!1,collapsedDirectoryKeys:Os,onToggleDirectory:Tc,onSelectFile:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);o&&Ca(xt(o))},renderLeading:Mc,renderTrailing:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?jc(o):null},renderDirectoryTrailing:Rc,renderSubtitle:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?kc(o):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[Aa&&e.jsx("div",{className:"mb-2",children:Aa}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Gt.length,"/",we.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[yc(),Yc,t,h&&Yo(),Jc,Xc]}),Mt&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:Mt.label}),Mt.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Mt.branch})]}),!Mt&&wn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Ar,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:va?(t=>Pc(t)):void 0,emptyContent:Bo?null:hn&&we.size===0?e.jsx(qa,{message:hn,onRetry:()=>{ms()}}):we.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Gt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>ps(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:i("rightSidebar.backToChangeList"),children:[e.jsx(Ps,{size:14}),i("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[h&&Yo(),e.jsxs("button",{type:"button",onClick:Ma,"aria-pressed":At,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:Nc(),activePane:wt,wrap:At,diffViewType:Tf,inlineMode:vr,diffOptions:_c,reloadKey:zs,renderStreamBadge:t=>e.jsx($s,{status:t}),onHunkGitAction:Oc,onInsertDiffReference:Lr,onReferenceCopied:Er,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:ja,onDetailScroll:ka}):e.jsx(Li,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:i("rightSidebar.backToChangeList"),groups:Gt.length>0?Cc():[],mode:xr,onModeChange:Na,selectedKey:Je,scrollToKey:Lc,scrollToKeyNonce:ra.nonce,compact:!0,collapsedDirectoryKeys:Os,onToggleDirectory:Tc,onSelectFile:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);o&&Ca(xt(o))},renderLeading:Mc,renderTrailing:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?jc(o):null},renderDirectoryTrailing:Rc,renderSubtitle:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?kc(o):null},aiContent:va?(t=>Pc(t)):void 0,emptyContent:Bo?null:hn&&we.size===0?e.jsx(qa,{message:hn,onRetry:()=>{ms()}}):we.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Gt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[Aa&&e.jsx("div",{className:"mb-2",children:Aa}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Gt.length,"/",we.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[yc(),Yc,t,Yo(),e.jsxs("button",{type:"button",onClick:Ma,"aria-pressed":At,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),Jc,Xc]}),Mt&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:Mt.label}),Mt.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Mt.branch}),e.jsx("button",{type:"button",onClick:()=>$a("stage-all",Mt.root,Mt.label),disabled:!!_e,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>$a("stash-all",Mt.root,Mt.label),disabled:!!_e,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]}),!Mt&&wn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Ar,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),files:Nc(),activePane:wt,wrap:At,diffViewType:Bt,inlineMode:vr,diffOptions:_c,reloadKey:zs,renderStreamBadge:t=>e.jsx($s,{status:t}),onHunkGitAction:Oc,onInsertDiffReference:Lr,onReferenceCopied:Er,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:ja,onDetailScroll:ka})}),e.jsx(Ka,{active:Wn,mounted:ko&&Vr,children:Ef?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:i("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{Qc.getState().setDock(ld,null),Ni({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:i("android.splitClose")})]}):e.jsx(Em,{sessionId:n??null,onInsertPrompt:t=>Lr("android-deps",t),onInsertFile:Wf})})]}),r&&lt&&e.jsx(kp,{value:be,collapsed:Ir,autoCollapseAfterSend:H,focusRequest:ft,insertError:Dr?i("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{mr(!1),We(t)},onCollapsedChange:Ft,onAutoCollapseAfterSendChange:se,onDisable:()=>ct(!1),onClear:()=>We(""),onInsert:()=>tc(!1),onInsertAndSend:()=>tc(!0),labels:{title:i("rightSidebar.contextDraftTitle"),hint:i("rightSidebar.contextDraftHint"),placeholder:i("rightSidebar.contextDraftPlaceholder"),collapse:i("rightSidebar.contextDraftCollapse"),expand:i("rightSidebar.contextDraftExpand"),disable:i("rightSidebar.contextDraftDisable"),clear:i("rightSidebar.contextDraftClear"),insert:i("rightSidebar.contextDraftInsert"),insertAndSend:i("rightSidebar.contextDraftInsertAndSend"),inserted:i("rightSidebar.contextDraftInserted"),sent:i("rightSidebar.contextDraftSent"),send:i("rightSidebar.contextDraftSend"),appended:i("rightSidebar.contextDraftAppended"),resize:i("rightSidebar.contextDraftResize"),autoCollapseAfterSend:i("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>i("rightSidebar.contextDraftCharacterCount",{count:t})}}),nh(),gt&&typeof document<"u"&&rn.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Yr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:gt.kind==="restore"?i("rightSidebar.confirmRestoreTitle"):i("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:gt.kind==="restore"?i("rightSidebar.confirmRestoreDescription",{path:ru(gt.file.absolutePath,v)}):i("rightSidebar.confirmStashAllDescription")}),gt.kind==="restore"&&e.jsx("input",{value:gt.phrase,onChange:t=>Yr({...gt,phrase:t.target.value}),placeholder:i("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Yr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:i("common.cancel")}),e.jsx("button",{type:"button",disabled:!!_e||gt.kind==="restore"&&gt.phrase.trim()!==i("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(gt.kind==="restore"){const t=mt(gt.file,v);if(!t)return;ht({action:"restore-worktree-file",cwd:t,paths:[gt.file.path],confirm:{acknowledged:!0,phrase:gt.phrase}},i("rightSidebar.restoreFile"),ki(gt.file))}else{const t=gt.repoRoot??v;if(!t)return;ht({action:"stash-all",cwd:t},i("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${gt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:i(_e?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const ex=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Xi,MarkdownImageLightbox:hf,MarkdownPreview:mf,RightSidebar:Hb,__testParseMarkdownListBlock:ab,buildMarkdownPreviewBlocks:gb,buildMarkdownPreviewRenderResult:il,collectKnownGitRepoRoots:Fu,computeMarkdownImageDisplayBox:Yu,getMarkdownHeadingOutline:ff,getMarkdownHeadingPathAtLine:uf,getNextMarkdownPreviewLineRange:kb,isSvgImageSrc:co,mountRightSidebarRepoPickerOverlay:ju,replaceGitRepositorySnapshot:yf,resolveMarkdownLocalLinkTarget:tl,resolveRightSidebarDiffViewType:Iu,shouldCloseMarkdownImageLightboxDrag:lf,showsGitRepoGroupHeader:Ui},Symbol.toStringTag,{value:"Module"}));export{Ti as E,ex as R,Bm as a,ep as c,Qb as m};
1678
+ `),truncated:x.some(V=>V.truncated)};if((j.hunks??[]).length===0){o?(Yt(j),qr(null),Vr(null)):He(i("rightSidebar.branchAuditDiffEmpty"));return}const A=Date.now(),ue=["preview",j.repoRoot??v,j.baseRef??j.baseBranch??"",j.currentBranch??"",j.headRef??"",j.diffFingerprint??A].join("\0"),ne=er.length===1?er[0].label:`${er.length} repos`;Yt(j),Nn(V=>[{key:ue,diff:j,repoLabel:ne,createdAt:A},...V.filter($e=>$e.key!==ue)].slice(0,8)),o||T(V=>V[ue]===void 0?V:{...V,[ue]:0}),qr(ue),Vr(V=>{const $e=j.hunks?.[0],Be=$e?`${$e.filePath}\0${$e.hunkHeader}\0${$e.hunkIndex}`:null;return o&&V&&(j.hunks??[]).some(Re=>`${Re.filePath}\0${Re.hunkHeader}\0${Re.hunkIndex}`===V)?V:Be}),tr(!0)}catch(x){if(!je(d)||Pr(x))return;He(x instanceof Error?x.message:"Failed to load branch diff")}finally{je(d)&&ae(!1)}},[Kr,er,Nt,jr,je,v,i]),vh=a.useCallback(t=>{Yt(t.diff),He(null),qr(t.key),Vr(t.diff.hunks?.[0]?`${t.diff.hunks[0].filePath}\0${t.diff.hunks[0].hunkHeader}\0${t.diff.hunks[0].hunkIndex}`:null),tr(!0)},[]),yh=a.useCallback(t=>{Nn(o=>o.filter(d=>d.key!==t)),T(o=>{if(!(t in o))return o;const d={...o};return delete d[t],d}),rt===t&&(qr(null),Yt(null),tr(!1))},[rt]),wh=a.useCallback(t=>{const o=qn.find(d=>d.key===t);o&&(Yt(null),He(null),qr(t),Vr(o.records[0]?.filePath??null),tr(!0))},[qn]),kh=a.useCallback(async t=>{if(!v||!ye)return;const[o]=t.split(/\s+/);if(o){tt(o),rr(null),Oe(null);try{const d=await am({cwd:v,repoRoot:ye,commit:o,requestSlotId:"right-sidebar-commit-diff"});if(!d.available){rr(d.error??"Commit diff is unavailable");return}Oe(d);const x=d.hunks?.[0];Gs(x?`${x.filePath}\0${x.hunkHeader}\0${x.hunkIndex}`:null)}catch(d){rr(d instanceof Error?d.message:"Failed to load commit diff")}finally{tt(null)}}},[ye,v]),Sh=a.useCallback(t=>{if(!De||!rt)return;const o=Math.max(0,Math.round(t));T(d=>Math.abs((d[rt]??0)-o)<24?d:{...d,[rt]:o})},[De,rt]);a.useEffect(()=>{!ee||!kr||!De||ps(1)},[kr,De,ee,ps]);const Pc=a.useCallback(t=>{t&&Df(o=>Fm(o,t))},[]),Tc=na.key===Je?na.key:null,Na=a.useCallback(t=>{const o=J.getState(),d=Wb();Va("select_diff_file",{interactionId:d,path:t,previousSelectedFilePath:o.selectedFilePath,rootPath:o.rootPath,activeGitRepoRoot:oe,changedFiles:o.changedFiles.size,gitBundleLoading:o.gitBundleLoading,gitBundleLastLoadedAt:o.gitBundleLastLoadedAt,rightTab:o.rightTab}),Ze(t),Jt("diff"),ee&&t&&ps(1),Pc(t),queueMicrotask(()=>{const x=J.getState();Va("select_diff_file_after",{interactionId:d,requestedPath:t,selectedFilePath:x.selectedFilePath,rootPath:x.rootPath,rightTab:x.rightTab,changedFiles:x.changedFiles.size,activeGitRepoRoot:oe})})},[oe,ee,Pc,Ze,Jt,ps]),Ic=a.useCallback(t=>{const o=Array.from(we.values()).find(d=>{const x=mt(d,v),w=xt(d);return d.path===t.filePath||w===t.filePath||d.absolutePath===t.filePath||(x?`${x}/${d.path}`===t.filePath:!1)||t.repoRoot&&x===t.repoRoot&&d.path===t.filePath});if(o){Na(xt(o)),window.setTimeout(()=>kn(t),90),window.setTimeout(()=>kn(t),320),window.setTimeout(()=>kn(t),760);return}kn(t)},[we,v,Na]),Dc=a.useCallback(({slideToDetail:t,fullscreen:o,toggleFullscreen:d}={})=>ts.length>0?e.jsx(uu,{walkthroughs:ts,repoRoot:oe,fullscreen:o,onToggleFullscreen:d,onNavigate:x=>{ee&&window.requestAnimationFrame(()=>t?.()),Ic(x)}}):e.jsxs("div",{className:"rounded-lg border border-border/15 bg-surface px-3 py-6 text-center text-xs text-muted-foreground",children:[e.jsx(Fs,{size:18,className:"mx-auto mb-2 text-muted-foreground/80"}),i("rightSidebar.changeWalkthroughEmpty")]}),[oe,ts,Ic,ee,i]),jh=a.useCallback(t=>{t&&gr(o=>{const d=new Set(o);return d.has(t)?d.delete(t):d.add(t),pi(ui,d),d})},[]),Fc=a.useCallback(t=>{br(o=>{const d=new Set(o);return d.has(t)?d.delete(t):d.add(t),pi($d,d),d})},[]),Ea=a.useCallback(t=>{Hs(t),$t(Mu,t)},[]);a.useEffect(()=>{ya||xr!=="ai"||Ea("tree")},[xr,Ea,ya]);const Ma=a.useCallback(()=>{es(t=>{const o=!t;return $t($u,o),o})},[]),_c=a.useCallback(t=>{zs(t),$t(Lu,t)},[]),{whitespace:Bc,context:Oc}=Bm(),Uc=a.useMemo(()=>({algorithm:"histogram",whitespace:Bc,context:Oc}),[Bc,Oc]),Hc=a.useCallback(t=>{K(t),$t(Au,t)},[]),$a=a.useCallback(async(t,o,d,x)=>{let w=t;for(;w.ok&&w.status==="running";)await new Promise(A=>window.setTimeout(A,1500)),w=await ld({jobId:w.jobId,cwd:o.cwd,action:o.action});if(!w.ok)throw new Error("Git action status is unavailable");if(w.status==="error")throw new Error(w.error||w.message||"Git action failed");const j={action:o.action,path:x,label:d};return ds(j),window.setTimeout(()=>ds(A=>A?.action===j.action&&A.path===j.path?null:A),1400),w},[]),ht=a.useCallback(async(t,o,d)=>{const x=v;v&&ar.current.delete(v),bt(null),ds(null),cs({action:t.action,path:d});try{const w=await om({...t,includeNested:Yn(v)}),j=await $a(w,t,o,d);if(!je(x))return!1;const A=v?await Ta(v,void 0,{includeNested:Yn(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Jn(v)}).catch(()=>j.bundle):j.bundle;return je(x)?(A&&tn(A,{reloadDiff:!0,cacheOnly:!0}),Xr(null),!0):!1}catch(w){return ds(null),bt(i("rightSidebar.gitActionFailed",{message:w instanceof Error?w.message:"Unknown error"})),!1}finally{je(x)&&cs(null)}},[tn,je,v,i,$a]),zc=a.useCallback(async t=>{const o=v,d=await im({...t,includeNested:Yn(v)});if(!je(o))return;const x=v?await Ta(v,void 0,{includeNested:Yn(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Jn(v)}).catch(()=>d.bundle):d.bundle;je(o)&&x&&tn(x,{reloadDiff:!0,cacheOnly:!0})},[tn,je,v]),La=a.useCallback((t,o,d)=>{if(o){if(t==="stage-all"){ht({action:"stage-all",cwd:o},i("rightSidebar.stageAll"),`repo:${o}`);return}Xr({kind:"stash-all",repoRoot:o,repoLabel:d})}},[ht,i]),Wc=a.useCallback(t=>{Me(t),Zs(""),Qs(""),ea(""),Ze(pc(t)),Qe||Jt("diff"),t&&xa(ot.get(t))},[xa,pc,Qe,ot,Ze,Me,Jt]),Gc=a.useCallback(t=>{const o=new Set([...Ht.current.keys(),...mn.current,...ar.current]);for(const d of o)d!==t&&(Ut.current.delete(d),Ht.current.get(d)?.abort(),Ht.current.delete(d),jt(`right-sidebar-git-untracked:${d}`),mn.current.delete(d),ar.current.delete(d))},[]),Rh=a.useCallback(async t=>{const o=v;if(!o||(await J.getState().setNestedGitScanRoot(o,t),!je(o)))return;if(t){await Qt(o,{includeNested:!0,discoverOnly:!0,replaceWorkspace:!0,background:!0,reloadDiff:!0});return}Gc(o),Zs(""),Qs(""),ea(""),bo(x=>x.filter(w=>w===o));const d=zt;d&&mt(d,o)!==o&&Ze(null),await Qt(o,{includeNested:!1,replaceWorkspace:!0,background:!0,reloadDiff:!0})},[Gc,je,Qt,v,Ze,zt]),Ch=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=Pn.trim();!t||t===de?.branch||await ht({action:"switch-branch",cwd:ye,branch:t},i("rightSidebar.switchBranch"))},[de?.branch,ye,qe,ht,Pn,i]),Kc=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=Js.trim();if(!t)return;await ht({action:"commit",cwd:ye,message:t},i("rightSidebar.commitChanges"))&&kl("")},[ye,Js,qe,ht,i]),Nh=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=dn.trim(),o=un.trim();await ht({action:"push",cwd:ye,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pushChanges"))},[ye,un,dn,qe,ht,i]),Eh=a.useCallback(async()=>{if(!ye||qe){bt(i("rightSidebar.selectRepositoryForGitActions"));return}const t=dn.trim(),o=un.trim();await ht({action:"pull",cwd:ye,...t?{remote:t}:{},...o?{branch:o}:{}},i("rightSidebar.pullChanges"))},[ye,un,dn,qe,ht,i]);a.useEffect(()=>{if(!Qe||!ye||_e)return;let t=!1;const o={push:i("rightSidebar.pushChanges"),pull:i("rightSidebar.pullChanges"),commit:i("rightSidebar.commitChanges"),"switch-branch":i("rightSidebar.switchBranch"),"stage-all":i("rightSidebar.stageAll"),"stash-all":i("rightSidebar.stashAll")};return(async()=>{for(const d of["push","pull","commit","switch-branch","stage-all","stash-all"]){if(t)return;const x=await ld({cwd:ye,action:d}).catch(()=>null);if(!x?.ok||x.status!=="running")continue;const w={action:d,cwd:ye},j=o[d]??d;cs({action:d});try{const A=await $a(x,w,j);if(t||!je(v))return;const ue=v?await Ta(v,void 0,{includeNested:Yn(v),cacheOnly:!0,action:"git_action_cache_sync",requestSlotId:Jn(v)}).catch(()=>A.bundle):A.bundle;ue&&tn(ue,{reloadDiff:!0,cacheOnly:!0})}catch(A){t||bt(i("rightSidebar.gitActionFailed",{message:A instanceof Error?A.message:"Unknown error"}))}finally{t||cs(null)}return}})(),()=>{t=!0}},[ye,tn,Qe,je,v,_e,i,$a]);const ri=Ln?.action==="commit",ni=Ln?.action==="switch-branch",si=Ln?.action==="pull",ai=Ln?.action==="push",Aa=Qe||Tf,oi=ka?i("rightSidebar.changeAuditScopeAll"):cr.length===1?cr[0].label:`${cr.length} repos`,Mh=cr.length>0,qc=er.length>0,$h=v?e.jsx(Vd,{open:po,onOpenChange:go,showScopePicker:!0,selectedAll:ka,repos:Wt,selectedRoots:wa,onToggleRepo:mh,onGenerate:()=>xh(Qo?"regenerate":"generate"),disabled:!Mh,generateDisabled:!qc,inserted:ke?.startsWith("context:branch-audit-scope:")??!1,buttonLabel:i(Qo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.branchAuditGenerateTitle"),ariaLabel:i("rightSidebar.branchAuditShort"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:oi,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i(Qo?"rightSidebar.branchAuditRegenerate":"rightSidebar.branchAuditGenerate"),onSecondaryAction:()=>{Ac()},secondaryDisabled:!qc||z,secondaryLabel:i("rightSidebar.branchAuditViewDiff"),secondaryTitle:i("rightSidebar.branchAuditViewDiffTitle"),secondaryLoading:z,loading:pl.size>0,statusTitle:pl.size>0?i("rightSidebar.branchCandidatesLoading"):void 0,extraContent:e.jsxs("div",{className:"mb-2 space-y-1.5",children:[e.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-foreground",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium",children:i("rightSidebar.includeUncommitted")}),e.jsx("span",{className:"block truncate text-[10px] text-muted-foreground",children:i("rightSidebar.includeUncommittedHint")})]}),e.jsx("input",{type:"checkbox",checked:Kr,onChange:t=>ml(t.target.checked),className:"h-4 w-4 shrink-0 accent-[rgb(var(--primary-rgb))]"})]}),yc.length>0&&e.jsx("div",{className:"rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[10px] text-[color:var(--warning)]",children:i("rightSidebar.missingBaseReposSkipped",{repositories:yc.map(t=>t.label).join(O==="zh"?"、":", ")})})]}),renderRepoExtra:t=>{const o=ot.get(t.root),d=[],x=new Set,w=(ne,V)=>{!ne||x.has(ne)||(x.add(ne),d.push({value:ne,label:ne,meta:V}))};w(jr[t.root]||o?.context?.branch,i("rightSidebar.pushCurrentBranchBadge"));for(const ne of o?.context?.branches??[])w(ne,ne===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):i("rightSidebar.localBranch"));for(const ne of o?.context?.remoteBranches??[])w(ne,i("rightSidebar.remoteBranch"));const j=[],A=new Set,ue=(ne,V)=>{!ne||A.has(ne)||(A.add(ne),j.push({value:ne,label:ne,meta:V}))};ue(Nt[t.root],Nt[t.root]?i("rightSidebar.pushUpstreamBadge"):void 0),ue(o?.context?.upstream,o?.context?.upstream?i("rightSidebar.pushUpstreamBadge"):void 0);for(const ne of o?.context?.remoteBranches??[])ue(ne,"remote");for(const ne of o?.context?.branches??[])ue(ne,ne===o?.context?.branch?i("rightSidebar.pushCurrentBranchBadge"):"local");return e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:[e.jsx(Xn,{label:i("rightSidebar.currentBranchLabel"),value:jr[t.root]||o?.context?.branch||"",options:d,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),onChange:ne=>{qs(V=>({...V,[t.root]:ne}))}}),e.jsx(Xn,{label:i("rightSidebar.branchAuditBaseLabel"),value:Nt[t.root]||"",options:j,placeholder:i("rightSidebar.branchAuditBasePlaceholder"),searchPlaceholder:i("rightSidebar.branchAuditBaseSearchPlaceholder"),emptyText:i("rightSidebar.branchAuditBaseEmpty"),onChange:ne=>{Vs(V=>({...V,[t.root]:ne}))}})]})}}):null,Vc=Cs(Rt.reduce((t,o)=>Math.max(t,o.injectedAt??0),0),O),Lh=v?e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>hl(t=>{const o=!t;return $t(fi,o),o}),className:"group flex w-full items-center gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":ls,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Fs,{size:14})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.branchAuditTitle")}),e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:oi})]}),e.jsx("span",{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${ls?"rotate-90":""}`,children:e.jsx(Ia,{size:13})})]}),ls&&e.jsxs("div",{className:"mt-2 rounded-lg border border-border/10 bg-surface/60 p-2",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 text-[11px] text-muted-foreground",children:[i("rightSidebar.changeAuditScopeLabel"),": ",oi]}),$h]}),Se&&e.jsx("div",{className:"mb-2 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-destructive",children:Se}),e.jsxs("div",{className:"mt-2 space-y-1.5",children:[an.map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>vh(t),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.diff.hunks?.length??0," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.currentBranch??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diff.baseRef??t.diff.baseBranch}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:i("rightSidebar.branchAuditViewDiff")})]}),Cs(t.createdAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:Cs(t.createdAt,O)})]}),e.jsx("button",{type:"button",onClick:()=>yh(t.key),className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("common.delete"),"aria-label":i("common.delete"),children:e.jsx(Ya,{size:12})})]},t.key)),qn.length>0?qn.slice(0,Math.max(0,8-an.length)).map(t=>e.jsxs("div",{className:`flex min-w-0 items-start gap-1 rounded-md transition ${rt===t.key?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsxs("button",{type:"button",onClick:()=>wh(t.key),className:"min-w-0 flex-1 px-2 py-1.5 text-left active:scale-[0.99]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:t.repoLabel}),e.jsxs("span",{className:"shrink-0 rounded bg-surface px-1.5 py-0.5 text-[11px] text-muted-foreground",children:[t.records.length," hunk"]})]}),e.jsxs("div",{className:"mt-1 flex min-w-0 flex-wrap items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.branchName??"HEAD"}),e.jsx("span",{className:"text-muted-foreground/60",children:"→"}),e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.baseRef}),t.diffFingerprint&&e.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5",children:t.diffFingerprint})]}),Cs(t.latestInjectedAt,O)&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-muted-foreground/70",children:i("rightSidebar.branchAuditGeneratedAt",{time:Cs(t.latestInjectedAt,O)??""})})]}),e.jsx("button",{type:"button",onClick:()=>{fh(t)},className:"mr-1 mt-1 inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface hover:text-foreground active:scale-95",title:i("rightSidebar.branchAuditClearTitle"),"aria-label":i("rightSidebar.branchAuditClearTitle"),children:e.jsx(Ya,{size:12})})]},t.key)):an.length===0?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.branchAuditEmpty")}):null]})]})]}):null,Yc=sr&&v&&Kn?e.jsxs("div",{className:Aa?"overflow-visible":"overflow-hidden",children:[Lh,e.jsxs("button",{type:"button",onClick:()=>{Qe||If(t=>{const o=!t;return o&&ye&&!Kn&&!cn&&_o(ye),o})},"aria-expanded":Aa,className:`group flex w-full items-center gap-2 px-1 pb-1 pt-4 text-left transition ${Qe?"cursor-default":"rounded-lg hover:bg-surface-2 active:scale-[0.99]"}`,children:[e.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-surface-2 text-muted-foreground group-hover:text-foreground",children:e.jsx(Ar,{size:14})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-semibold text-foreground",children:i("rightSidebar.gitQuickActions")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("span",{className:`inline-flex items-center justify-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${yn.staged>0?"bg-accent/10 text-accent":"bg-surface-2 text-muted-foreground"}`,children:[cn&&e.jsx(yt,{size:10,className:"animate-spin"}),yn.staged>0?i("rightSidebar.stagedCount",{count:yn.staged}):i("rightSidebar.noStagedChangesShort")]}),!Qe&&e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Aa?"rotate-90":""}`,children:e.jsx(Ia,{size:13})})]})]}),Aa&&e.jsxs("div",{className:"space-y-0",children:[It.length>1&&e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between gap-2",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.gitRepositorySectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:Qf})]})}),e.jsx(Xn,{label:i("rightSidebar.gitRepositoryLabel"),value:ye??"",options:It,placeholder:i("rightSidebar.gitRepositoryPlaceholder"),searchPlaceholder:i("rightSidebar.gitRepositorySearchPlaceholder"),emptyText:i("rightSidebar.gitRepositoryEmpty"),disabled:!!_e,onChange:t=>{Wc(t||null)}}),qe&&e.jsx("div",{className:"mt-2 rounded-md bg-[rgb(var(--warning-rgb)_/_0.12)] px-2 py-1.5 text-[11px] text-[color:var(--warning)]",children:i("rightSidebar.selectRepositoryForGitActions")})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.branchSectionTitle")}),e.jsx("div",{className:"mt-0.5 h-4 truncate text-[11px] leading-4 text-muted-foreground",children:Pn!==mc?mc:null})]}),e.jsxs("button",{type:"button",onClick:()=>{Ch()},disabled:!ch,className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${ni?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.switchBranch"),children:[e.jsx("span",{className:_e?.action==="switch-branch"||ni?"opacity-0":"",children:i("rightSidebar.switchBranch")}),_e?.action==="switch-branch"&&e.jsx(yt,{size:12,className:"absolute animate-spin"}),ni&&_e?.action!=="switch-branch"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx(Xn,{label:i("rightSidebar.currentBranchLabel"),value:Pn,options:rh,placeholder:i("rightSidebar.switchBranchPlaceholder"),searchPlaceholder:i("rightSidebar.switchBranchSearchPlaceholder"),emptyText:i("rightSidebar.switchNoBranches"),disabled:!!_e,onChange:Zs})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.commitSectionTitle")}),e.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:qe?i("rightSidebar.selectRepositoryForGitActions"):yn.staged>0?i("rightSidebar.commitReadyHint",{count:yn.staged}):i("rightSidebar.commitNeedsStaged")})]}),e.jsxs("button",{type:"button",onClick:()=>{Kc()},disabled:!!_e||qe||yn.staged===0||!Js.trim(),className:`relative inline-flex h-8 shrink-0 items-center justify-center rounded-md px-3 text-[12px] font-medium transition active:scale-95 ${ri?"bg-accent/10 text-accent disabled:bg-accent/10 disabled:text-accent":"bg-primary text-primary-foreground hover:bg-primary/90 disabled:bg-surface-2 disabled:text-muted-foreground"} disabled:cursor-not-allowed`,title:qe?i("rightSidebar.selectRepositoryForGitActions"):yn.staged===0?i("rightSidebar.commitNeedsStaged"):i("rightSidebar.commitChanges"),children:[e.jsx("span",{className:_e?.action==="commit"||ri?"opacity-0":"",children:i("rightSidebar.commitChanges")}),_e?.action==="commit"&&e.jsx(yt,{size:12,className:"absolute animate-spin"}),ri&&_e?.action!=="commit"&&e.jsx("span",{className:"absolute",children:"✓"})]})]}),e.jsx("input",{value:Js,onChange:t=>kl(t.target.value),onKeyDown:t=>{(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),Kc())},placeholder:i("rightSidebar.commitMessagePlaceholder"),disabled:!!_e,className:"w-full min-h-10 rounded-md border border-transparent bg-surface-2 px-3 py-2 text-[13px] placeholder:text-[13px] text-foreground outline-none transition placeholder:text-muted-foreground/70 focus:border-primary focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-60",maxLength:300})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("button",{type:"button",onClick:()=>En(t=>!t),className:"group flex w-full items-center justify-between gap-2 rounded-lg px-1 py-1.5 text-left transition hover:bg-surface-2 active:scale-[0.99]","aria-expanded":Xt,children:[e.jsx("span",{className:"min-w-0 text-[12px] font-medium text-foreground",children:i("rightSidebar.recentCommitsTitle")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1.5",children:[ze&&e.jsx(yt,{size:12,className:"animate-spin text-muted-foreground"}),e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition group-hover:bg-surface-elevated group-hover:text-foreground ${Xt?"rotate-90":""}`,children:e.jsx(Ia,{size:13})})]})]}),Xt&&e.jsxs("div",{className:"mt-2 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:12,className:"shrink-0"}),e.jsx("input",{value:os,onChange:t=>on(t.target.value),placeholder:i("rightSidebar.recentCommitsSearchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",spellCheck:!1}),os&&e.jsx("button",{type:"button",onClick:()=>on(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Kt,{size:12})})]}),e.jsxs("div",{className:"max-h-56 space-y-1 overflow-y-auto overscroll-contain pr-1",onScroll:eh,children:[ln.length>0?ln.map(t=>{const[o,...d]=t.split(/\s+/),x=d.join(" ")||t;return e.jsxs("button",{type:"button",onClick:()=>{kh(t)},className:"flex w-full min-w-0 items-start gap-2 rounded-md bg-surface-2 px-2 py-1.5 text-left font-mono text-[10px] transition hover:bg-surface-elevated active:scale-[0.99]",title:x,children:[e.jsx("span",{className:"shrink-0 text-[color:var(--diff-hunk-accent)]",children:o}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-muted-foreground",title:x,children:x}),Sr[o]&&e.jsx("span",{className:`shrink-0 rounded px-1 font-sans text-[10px] ${Sr[o]==="ahead"?"bg-accent/10 text-accent":Sr[o]==="behind"?"bg-surface-2 text-[color:var(--warning)]":"text-muted-foreground"}`,children:i(Sr[o]==="ahead"?"rightSidebar.commitAhead":Sr[o]==="behind"?"rightSidebar.commitBehind":"rightSidebar.commitSynced")}),Ge===o&&e.jsx(yt,{size:11,className:"shrink-0 animate-spin text-muted-foreground"})]},t)}):ze?e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-2 text-center text-[11px] text-muted-foreground",children:i("common.loading")}):e.jsx("div",{className:"rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:i("rightSidebar.recentCommitsEmpty")}),Wr&&e.jsx("div",{className:"flex justify-center rounded-md bg-surface-2 px-2 py-2 text-muted-foreground",children:e.jsx(yt,{size:12,className:"animate-spin"})}),mo&&!Wr&&ln.length>0&&e.jsx("button",{type:"button",onClick:()=>{ys({reset:!1})},className:"w-full rounded-md bg-surface-2 px-2 py-1.5 text-[11px] font-medium text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground",children:i("rightSidebar.recentCommitsLoadMore")})]})]}),Ct&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:Ct}),ul&&e.jsx("div",{className:"mt-2 rounded-md bg-destructive/10 px-2 py-1.5 text-[11px] text-destructive",children:ul})]}),e.jsxs("div",{className:"border-b border-border/40 px-1 py-4 last:border-b-0",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-foreground",children:i("rightSidebar.pushSectionTitle")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>{Eh()},disabled:!ih,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${si?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pullChanges"),children:[e.jsx("span",{className:_e?.action==="pull"||si?"opacity-0":"",children:i("rightSidebar.pullChanges")}),_e?.action==="pull"&&e.jsx(yt,{size:12,className:"absolute animate-spin"}),si&&_e?.action!=="pull"&&e.jsx("span",{className:"absolute",children:"✓"})]}),e.jsxs("button",{type:"button",onClick:()=>{Nh()},disabled:!lh,className:`relative inline-flex h-8 min-w-[3.25rem] items-center justify-center rounded-md px-3 text-[12px] font-medium transition disabled:cursor-not-allowed disabled:opacity-50 active:scale-95 ${ai?"bg-accent/10 text-accent hover:bg-accent/15":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:i("rightSidebar.pushChanges"),children:[e.jsx("span",{className:_e?.action==="push"||ai?"opacity-0":"",children:i("rightSidebar.pushChanges")}),_e?.action==="push"&&e.jsx(yt,{size:12,className:"absolute animate-spin"}),ai&&_e?.action!=="push"&&e.jsx("span",{className:"absolute",children:"✓"})]})]})]}),e.jsxs("div",{className:`mb-2 flex min-w-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-[11px] ${kc.className}`,title:de?.upstream??void 0,children:[e.jsx("span",{className:"truncate font-medium",children:kc.text}),e.jsx("span",{className:"w-[6.5rem] shrink-0 truncate text-right text-[10px] opacity-75",children:de?.upstream??""})]}),e.jsxs("div",{className:`grid gap-1.5 ${vc?"grid-cols-2":"grid-cols-1"}`,children:[vc&&e.jsx(Xn,{label:i("rightSidebar.pushRemoteLabel"),value:dn,options:xc,placeholder:i("rightSidebar.pushRemotePlaceholder"),searchPlaceholder:i("rightSidebar.pushRemoteSearchPlaceholder"),emptyText:i("rightSidebar.pushNoRemotes"),disabled:!!_e,onChange:Qs}),e.jsx(Xn,{label:i("rightSidebar.pushBranchLabel"),value:un,options:nh,placeholder:i("rightSidebar.pushBranchPlaceholder",{branch:de?.branch??"HEAD"}),searchPlaceholder:i("rightSidebar.pushBranchSearchPlaceholder"),emptyText:i("rightSidebar.pushNoBranches"),disabled:!!_e,onChange:ea})]})]})]})]}):null,Ah=a.useCallback(t=>{const o=mt(t,v);if(!o)return[];const d=Si(t),x=[];return t.canStage&&x.push({key:"stage-file",label:i("rightSidebar.stageFile"),onClick:()=>{ht({action:"stage-file",cwd:o,paths:[t.path]},i("rightSidebar.stageFile"),d)}}),t.canUnstage&&x.push({key:"unstage-file",label:i("rightSidebar.unstageFile"),onClick:()=>{ht({action:"unstage-file",cwd:o,paths:[t.path]},i("rightSidebar.unstageFile"),d)}}),t.canStash&&x.push({key:"stash-file",label:i("rightSidebar.stashFile"),onClick:()=>{ht({action:"stash-file",cwd:o,paths:[t.path]},i("rightSidebar.stashFile"),d)}}),t.canRestoreWorktree&&x.push({key:"restore-worktree-file",label:i("rightSidebar.restoreFile"),destructive:!0,onClick:()=>Xr({kind:"restore",file:t,phrase:""})}),x},[v,ht,i]),Ph=a.useCallback(()=>{if(g){k?.();return}Cr(0),Er.current?.slideTo(0),Rr(!1),pt(null)},[k,g]),Xc=a.useCallback(t=>{if(G(""),Ot(t),Ze(null),pt(null),te(null),ee){g&&k?.(),Cr(0),Er.current?.slideTo(0),Rr(!1);return}},[ee,k,g,Ze,Ot]);a.useEffect(()=>{const t=o=>{const d=o.detail,x=d?.path;if(typeof x!="string"||!x.startsWith("/"))return;G(""),pt(null),Lt(null);const w=!!(v&&(x===v||x.startsWith(`${v}/`)));if(d.kind==="file"){const j=yi(x);gs(x),typeof d.line=="number"&&Number.isSafeInteger(d.line)&&d.line>0&&Lt(d.line),Ot(w?null:j),te(A=>({path:x,nonce:(A?.nonce??0)+1}));return}Ze(null),w?(Ot(null),te(j=>({path:x,nonce:(j?.nonce??0)+1}))):(te(null),Ot(x)),ee&&(g&&k?.(),Cr(0),Er.current?.slideTo(0),Rr(!1))};return window.addEventListener(md,t),()=>window.removeEventListener(md,t)},[gs,ee,k,g,v,Ze,Ot]),a.useEffect(()=>{r||(_t(!1),hr(!1))},[r]),a.useEffect(()=>{if(!ur&&!fr)return;const t=o=>{o instanceof globalThis.KeyboardEvent&&o.key!=="Escape"||o instanceof globalThis.MouseEvent&&o.target instanceof Node&&(Sn.current?.contains(o.target)||jn.current?.contains(o.target))||(_t(!1),hr(!1))};return window.addEventListener("mousedown",t),window.addEventListener("keydown",t),()=>{window.removeEventListener("mousedown",t),window.removeEventListener("keydown",t)}},[fr,ur]);const Jc=e.jsxs("div",{"data-local-layer":"file-explorer-menu-host",className:"sticky top-0 z-20 bg-surface/95 px-2.5 py-1.5 backdrop-blur",children:[e.jsxs("div",{className:"flex min-h-9 min-w-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:Xf,disabled:!ga,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.parentFolder"),title:i("rightSidebar.parentFolder"),children:e.jsx(ou,{size:14})}),e.jsx("button",{type:"button",onClick:oc,disabled:!v||In===v,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.backToProjectRoot"),title:i("rightSidebar.backToProjectRoot"),children:e.jsx(pd,{size:14})}),e.jsx("button",{type:"button",onClick:Jf,disabled:!ge,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-35 active:scale-95","aria-label":i("rightSidebar.refreshFiles"),title:Sl?i("rightSidebar.fileWatchUnavailable",{message:Sl}):i("rightSidebar.refreshFiles"),children:e.jsx($i,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1 px-1",title:ge??void 0,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-1 text-[12px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:Vf}),ia==="modified"&&e.jsx("span",{className:"inline-flex shrink-0 text-primary",title:i("fileTree.sortedByModified"),"aria-label":i("fileTree.sortedByModified"),children:e.jsx(gd,{size:11})})]})}),e.jsx("button",{type:"button",onClick:()=>ge&&lr(ge,Tt??void 0),disabled:!ge,...ge&&Tt?Ho(pa(ge),Tt):{},className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition disabled:cursor-not-allowed disabled:opacity-35 active:scale-95 ${Tt&&(ke===Tt||et===Tt)?"bg-surface-elevated text-foreground":"bg-primary/10 text-primary hover:bg-primary/20"}`,"aria-label":i(Tt&&et===Tt?"rightSidebar.copied":Tt&&ke===Tt?"rightSidebar.inserted":"rightSidebar.insertCurrentFolder"),title:i("rightSidebar.insertCurrentFolder"),children:Tt&&(ke===Tt||et===Tt)?e.jsx(Ni,{size:13}):e.jsx(Qa,{size:13})}),e.jsxs("div",{ref:jn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{_t(!1),hr(t=>!t)},className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition active:scale-95 ${fr?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2 hover:text-foreground"}`,"aria-expanded":fr,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(Mi,{size:14})}),fr&&e.jsxs("div",{role:"menu","data-local-layer":"file-explorer-menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-48 overflow-hidden rounded-xl border border-border/15 bg-surface p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{hr(!1),Zf()},disabled:!Ko,className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition disabled:opacity-40 ${xs?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[xs?e.jsx(li,{size:14}):e.jsx(Fa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(xs?"rightSidebar.unpinCurrentFolder":"rightSidebar.pinCurrentFolder")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{hr(!1),_f()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${Mo?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[Mo?e.jsx(zm,{size:14}):e.jsx(Ii,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(Mo?"rightSidebar.hideHiddenFiles":"rightSidebar.showHiddenFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",disabled:!ge,onClick:()=>{ge&&(hr(!1),Bf(ge,ia==="modified"?"name":"modified"))},className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-40",children:[ia==="modified"?e.jsx(Nm,{size:14}):e.jsx(gd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(ia==="modified"?"fileTree.sortByName":"fileTree.sortByModified")})]})]})]})]}),v&&(ba.length>0||Yf)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1 pb-0.5 text-[11px]",children:[e.jsx("span",{className:"shrink-0 px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.pinnedFolders")}),e.jsxs("button",{type:"button",onClick:oc,className:`inline-flex max-w-[9rem] shrink-0 items-center gap-1 rounded-md px-2 py-0.5 font-medium transition active:scale-95 ${ge===v?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:v,children:[e.jsx(pd,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:Xe})]}),ba.map(t=>{const o=t.path,d=t.kind==="file",x=d?Je===o:ge===o;return e.jsxs("span",{className:`group inline-flex max-w-[12rem] shrink-0 items-center rounded-md transition ${x?"bg-primary/15 text-primary":"bg-surface-2 text-foreground hover:bg-surface-elevated"}`,title:o,children:[e.jsxs("button",{type:"button",onClick:()=>d?gs(o):Ot(o),className:"inline-flex min-w-0 items-center gap-1 px-2 py-0.5 font-medium active:scale-95",children:[d?e.jsx(Di,{size:10,className:"shrink-0"}):e.jsx(Fa,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:vt(o)})]}),e.jsx("button",{type:"button",onClick:()=>fn(o),className:"mr-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground","aria-label":i("rightSidebar.unpinFolder",{name:vt(o)}),title:i("rightSidebar.unpinFolder",{name:vt(o)}),children:e.jsx(Kt,{size:9})})]},o)})]}),e.jsx("span",{"data-local-layer":"file-explorer-divider",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-px bg-border/15","aria-hidden":"true"})]}),ii=a.useMemo(()=>{if(An===null)return null;const t=typeof navigator>"u"?void 0:navigator.language,o=Math.max(0,Math.floor((jo-An)/1e3)),d=new Intl.RelativeTimeFormat(t,{numeric:"auto"}),[x,w]=o<60?[-o,"second"]:o<3600?[-Math.floor(o/60),"minute"]:o<86400?[-Math.floor(o/3600),"hour"]:[-Math.floor(o/86400),"day"];return d.format(x,w)},[jo,An]),Zc=v&&!Hn?e.jsx("button",{type:"button",onClick:()=>{Rh(!$o)},"aria-pressed":$o,title:i("rightSidebar.multiRepoScanTitle"),className:`inline-flex h-7 shrink-0 items-center rounded-md px-2.5 text-[11px] font-medium transition active:scale-95 ${$o?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:i("rightSidebar.multiRepoScan")}):null,Qc=v?e.jsxs("div",{className:"inline-flex shrink-0 items-center gap-1.5",children:[ii?e.jsx("span",{className:"whitespace-nowrap text-[10px] text-muted-foreground",title:i("rightSidebar.gitLastUpdated",{time:ii}),children:ii}):null,e.jsx("button",{type:"button",onClick:()=>{ms()},disabled:Jr,className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50 active:scale-95","aria-label":i("rightSidebar.refreshGit"),title:i("rightSidebar.refreshGit"),children:e.jsx($i,{size:13,className:Jr?"animate-spin":""})})]}):null,Th=Gl?i("rightSidebar.changeAuditScopeAll"):gn.length===1?gn[0].relativeRoot==="."?Xe:gn[0].relativeRoot||gn[0].name:`${gn.length} repos`,ed=v?e.jsxs("div",{className:"inline-flex h-7 shrink-0 items-center",children:[e.jsx(Vd,{open:rs,onOpenChange:sn,showScopePicker:wn,selectedAll:Gl,repos:Of,selectedRoots:Zt,onToggleRepo:hh,onGenerate:()=>dh(),disabled:!v,inserted:ke===ac,buttonLabel:i("rightSidebar.changeAuditShort"),insertedLabel:i("rightSidebar.inserted"),title:i("rightSidebar.insertChangeAuditPromptTitle"),ariaLabel:i("rightSidebar.insertChangeAuditPrompt"),scopeTitle:i("rightSidebar.changeAuditScopeLabel"),scopeLabel:Th,allLabel:i("rightSidebar.changeAuditScopeAll"),generateLabel:i("rightSidebar.changeAuditShort"),loading:Br,error:!!wr,statusTitle:wr??(Br?i("rightSidebar.changeAuditLoading"):Rt.length>0?`${i("rightSidebar.changeAuditLoaded",{count:Rt.length})}${Vc?` · ${i("rightSidebar.changeAuditLoadedAt",{time:Vc})}`:""}`:void 0)}),e.jsx("button",{type:"button",onClick:()=>{uh()},disabled:Br||Rt.length===0,className:`inline-flex h-7 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition hover:bg-surface-2 hover:text-foreground disabled:pointer-events-none active:scale-95 ${Rt.length>0?"":"invisible"}`,title:i("rightSidebar.clearChangeAuditTitle"),"aria-label":i("rightSidebar.clearChangeAudit"),children:e.jsx(Ya,{size:12})})]}):null,Pa=e.jsxs("div",{className:"flex h-5 flex-nowrap items-center gap-1 overflow-x-auto whitespace-nowrap text-[10px] font-medium [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0",children:[S?.available&&S.branch&&e.jsxs("span",{className:"inline-flex min-w-0 max-w-[8rem] items-center gap-0.5 truncate rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",title:S.branch,children:[e.jsx(Ar,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:S.branch})]}),dt.modified>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-hunk-accent)]",children:[dt.modified,"M"]}),dt.added>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:["+",dt.added]}),dt.deleted>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-delete-strong)]",children:["-",dt.deleted]}),dt.renamed>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.renamed,"R"]}),dt.copied>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.copied,"C"]}),dt.untracked>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-[color:var(--diff-insert-strong)]",children:[dt.untracked,"U"]}),dt.conflicted>0&&e.jsxs("span",{className:"rounded bg-destructive/10 px-1.5 py-0.5 text-destructive",children:[dt.conflicted,"!"]}),dt.other>0&&e.jsxs("span",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-muted-foreground",children:[dt.other,"?"]}),dt.staged>0&&e.jsx("span",{className:"rounded bg-accent/10 px-1.5 py-0.5 text-accent",children:i("rightSidebar.stagedCountShort",{count:dt.staged})}),S?.available&&v&&we.size>0&&le.length<=1&&e.jsx("button",{type:"button",onClick:()=>{ht({action:"stage-all",cwd:v},i("rightSidebar.stageAll"))},disabled:!!_e,className:"rounded-md bg-accent/10 px-2 py-0.5 font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),S?.available&&v&&we.size>0&&le.length<=1&&e.jsx("button",{type:"button",onClick:()=>Xr({kind:"stash-all",repoRoot:v,repoLabel:Xe}),disabled:!!_e,className:"rounded-md bg-surface-2 px-2 py-0.5 font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]});return e.jsxs(Em,{side:"right",isOpen:r,drawerWidthPx:s,onClose:l,onOpen:u,push:c,pinned:h,children:[Ho.popoverNode,e.jsxs("div",{className:`relative shrink-0 border-b border-border/15 bg-surface px-2 pt-2 ${zf?"hidden":""}`,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"min-w-0 flex-1 px-1",children:e.jsxs("div",{className:"flex min-h-[1.25rem] items-baseline gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-semibold text-foreground",title:v??void 0,children:Xe}),(!ee||yo)&&S?.available&&S.branch&&e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5 truncate text-[11px] text-muted-foreground",title:S.branch,children:[e.jsx(Ar,{size:10,className:"shrink-0"}),e.jsx("span",{className:"max-w-[7rem] truncate",children:S.branch})]})]})}),e.jsx("button",{type:"button",onClick:()=>{const t=!xe;W(t),t?window.requestAnimationFrame(()=>document.querySelector("[data-right-search]")?.focus()):G("")},className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${xe?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleSearch"),title:i("common.search"),children:e.jsx(Zn,{size:14})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":lt,onClick:()=>{ct(t=>!t),Ft(!1)},className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${lt?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i("rightSidebar.toggleContextDraft"),title:i("rightSidebar.contextDraftTitle"),children:[e.jsx(Mm,{size:14}),!lt&&be.trim()&&e.jsx("span",{className:"absolute right-0.5 top-0.5 h-1.5 w-1.5 rounded-full bg-primary","aria-hidden":"true"})]}),e.jsx("input",{ref:Nl,type:"file",multiple:!0,className:"hidden",onChange:t=>{const o=t.target.files;!o||o.length===0||(bs(Array.from(o)),t.target.value="")}}),e.jsx("input",{ref:El,type:"file",accept:"image/*",className:"hidden",onChange:t=>{const o=t.target.files?.[0];t.target.value="",o&&Kf(o)}}),m&&e.jsx("button",{type:"button",onClick:m,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full transition active:scale-95 ${h?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-label":i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),title:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar"),children:h?e.jsx(li,{size:14}):e.jsx(Fa,{size:14})}),e.jsxs("div",{ref:Sn,className:"relative shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{hr(!1),_t(t=>!t)},className:`relative inline-flex h-8 w-8 items-center justify-center rounded-full transition active:scale-95 ${ur?"bg-surface-elevated text-foreground":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,"aria-expanded":ur,"aria-haspopup":"menu","aria-label":i("sidebar.moreActions"),title:i("sidebar.moreActions"),children:e.jsx(Mi,{size:15})}),ur&&e.jsxs("div",{role:"menu",className:"absolute right-0 top-[calc(100%+4px)] z-30 w-56 overflow-hidden rounded-xl border border-border/15 bg-surface/98 p-1 text-[12px] shadow-xl shadow-[0_18px_48px_var(--app-shadow-soft)] backdrop-blur animate-fade-in",children:[e.jsxs("button",{type:"button",role:"menuitemcheckbox","aria-checked":Yr,onClick:()=>Gf(!Yr),className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2",children:[e.jsx(cd,{size:14,className:"text-muted-foreground"}),e.jsx("span",{className:"flex-1",children:i("rightSidebar.showAndroidTab")}),e.jsx("span",{"aria-hidden":"true",className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition ${Yr?"bg-primary":"bg-surface-elevated"}`,children:e.jsx("span",{className:`absolute h-3 w-3 rounded-full bg-background transition-all ${Yr?"left-3.5":"left-0.5"}`})})]}),e.jsx("div",{className:"my-1 h-px bg-border/15",role:"separator"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),Nl.current?.click()},disabled:ta,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ta?e.jsx(yt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(Qm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.uploadFiles")})]}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),El.current?.click()},disabled:ta,className:"flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left text-foreground transition hover:bg-surface-2 disabled:opacity-50",children:[ta?e.jsx(yt,{size:14,className:"animate-spin text-muted-foreground"}):e.jsx(qm,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i("rightSidebar.insertLocalImage")})]}),m&&e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{_t(!1),m()},className:`flex w-full items-center gap-2 rounded-lg px-2.5 py-2 text-left transition ${h?"text-primary hover:bg-primary/10":"text-foreground hover:bg-surface-2"}`,children:[h?e.jsx(li,{size:14}):e.jsx(Fa,{size:14,className:"text-muted-foreground"}),e.jsx("span",{children:i(h?"sidebar.unpinSidebar":"sidebar.pinSidebar")})]}),h&&e.jsxs("div",{className:"mt-1 flex items-center gap-2 border-t border-border/15 px-1.5 pt-1.5",role:"group","aria-label":i("rightSidebar.layoutMode"),children:[e.jsx("div",{className:"shrink-0 pl-1 text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:i("rightSidebar.layoutMode")}),e.jsx("div",{className:"grid min-w-0 flex-1 grid-cols-3 gap-0.5 rounded-lg bg-surface-2 p-0.5",children:[["auto",i("rightSidebar.layoutModeAuto")],["narrow",i("rightSidebar.layoutModeNarrow")],["wide",i("rightSidebar.layoutModeWide")]].map(([t,o])=>{const d=Y===t;return e.jsx("button",{type:"button",role:"menuitemradio","aria-checked":d,onClick:()=>{L(t),_t(!1)},className:`rounded-md px-1 py-1.5 text-center text-[11px] font-medium transition active:scale-95 ${d?"bg-primary/15 text-primary":"text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:o},t)})})]})]})]}),e.jsx("button",{type:"button",onClick:l,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-surface-2 text-muted-foreground transition hover:bg-destructive/20 hover:text-destructive active:scale-95","aria-label":i("rightSidebar.close"),children:e.jsx(Kt,{size:14})})]}),xe&&e.jsxs("div",{className:"mt-2 space-y-1.5 pb-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-surface-2 px-3 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx(Zn,{size:12,className:"shrink-0"}),e.jsx("input",{"data-right-search":!0,type:"search",value:C,onChange:t=>G(t.target.value),placeholder:i(D==="content"?"rightSidebar.searchPlaceholderContent":"rightSidebar.filterChanges"),className:"min-w-0 flex-1 bg-transparent text-[13px] text-foreground placeholder:text-muted-foreground",autoCapitalize:"off",autoCorrect:"off",autoComplete:"off",enterKeyHint:"search",spellCheck:!1}),e.jsxs("div",{className:`flex shrink-0 items-center gap-0.5 rounded-full bg-surface/70 p-0.5 font-medium ${ee?"text-[11px]":"text-[10px]"}`,children:[e.jsx("button",{type:"button",onClick:()=>Hc("name"),"aria-pressed":D==="name",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${D==="name"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeName")}),e.jsx("button",{type:"button",onClick:()=>Hc("content"),"aria-pressed":D==="content",className:`rounded-full px-2 transition active:scale-95 ${ee?"py-1":"py-0.5"} ${D==="content"?"bg-primary/15 text-primary":"text-muted-foreground/80 hover:text-foreground"}`,children:i("rightSidebar.searchModeContent")})]}),C&&e.jsx("button",{type:"button",onClick:()=>G(""),className:"rounded-full p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.clearSearch"),children:e.jsx(Kt,{size:12})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 items-center gap-2 rounded-lg bg-surface-2 px-2.5 py-1.5 text-muted-foreground transition focus-within:bg-surface-elevated",children:[e.jsx($m,{size:12,className:"shrink-0 text-primary"}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchScope")}),e.jsx("input",{"data-search-scope":!0,value:re,onChange:t=>ce(t.target.value),onKeyDown:t=>{t.key==="Enter"&&document.querySelector("[data-right-search]")?.focus()},className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchScopePlaceholder"),"aria-label":i("rightSidebar.searchScope"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),re!=="."&&e.jsx("button",{type:"button",onClick:()=>ce("."),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-surface hover:text-foreground","aria-label":i("rightSidebar.resetSearchScope"),children:e.jsx(Kt,{size:11})})]}),e.jsxs("button",{type:"button",onClick:()=>M(t=>!t),"aria-expanded":Ee,className:`relative inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition active:scale-95 ${Ee||us.length>0||Z||Ne||Ce?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,title:i("rightSidebar.searchOptions"),"aria-label":i("rightSidebar.searchOptions"),children:[e.jsx(Lm,{size:13}),us.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 min-w-4 rounded-full bg-primary px-1 text-[8px] font-bold leading-4 text-primary-foreground",children:us.length})]})]}),Ee&&e.jsxs("div",{className:"animate-fade-in rounded-xl bg-surface-2 p-2",children:[e.jsxs("label",{className:"flex items-center gap-2 rounded-lg bg-surface px-2.5 py-1.5 text-muted-foreground focus-within:bg-surface-elevated",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium",children:i("rightSidebar.searchExclude")}),e.jsx("input",{"data-search-exclude":!0,value:ve,onChange:t=>pe(t.target.value),className:"min-w-0 flex-1 bg-transparent font-mono text-[11px] text-foreground placeholder:text-muted-foreground",placeholder:i("rightSidebar.searchExcludePlaceholder"),"aria-label":i("rightSidebar.searchExclude"),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1}),ve&&e.jsx("button",{type:"button",onClick:()=>pe(""),className:"rounded p-0.5 hover:bg-surface-2 hover:text-foreground","aria-label":i("rightSidebar.clearSearchExclude"),children:e.jsx(Kt,{size:11})})]}),D==="content"&&e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1",role:"group","aria-label":i("rightSidebar.contentSearchOptions"),children:[[Z,()=>he(t=>!t),Um,i("rightSidebar.matchCase")],[Ne,()=>Ve(t=>!t),tp,i("rightSidebar.matchWholeWord")],[Ce,()=>Ye(t=>!t),Ym,i("rightSidebar.useRegex")]].map(([t,o,d,x])=>e.jsxs("button",{type:"button",onClick:o,"aria-pressed":t,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-[10px] transition ${t?"bg-primary/15 text-primary":"bg-surface text-muted-foreground hover:bg-surface-elevated hover:text-foreground"}`,children:[e.jsx(d,{size:12}),x]},x))})]})]}),e.jsxs("div",{className:"mt-2 grid gap-0.5 rounded-md bg-surface-2 p-0.5",style:{gridTemplateColumns:`repeat(${(Hn?2:3)+(Yr?1:0)}, minmax(0, 1fr))`},children:[!Hn&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>Jt("git"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="git"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Ar,{size:12}),i("rightSidebar.tabGit")]}),e.jsxs("button",{type:"button",onClick:()=>Jt("diff"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="diff"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(xu,{size:12}),i("rightSidebar.tabChanges"),we.size>0?e.jsx("span",{className:"text-[10px] text-accent",children:we.size}):null]})]}),e.jsxs("button",{type:"button",onClick:()=>Jt("files"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="files"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(Im,{size:12}),i("rightSidebar.tabFiles")]}),Yr&&e.jsxs("button",{type:"button",onClick:()=>Jt("android"),className:`flex items-center justify-center gap-1 rounded px-2 py-1.5 text-[11px] font-medium transition active:scale-[0.98] ${ir==="android"?"bg-surface-elevated text-foreground":"text-muted-foreground hover:bg-surface-2"}`,children:[e.jsx(cd,{size:12}),i("rightSidebar.tabAndroid")]})]}),e.jsx("div",{className:"h-2"}),yl&&e.jsx("div",{className:"pointer-events-none absolute right-3 top-10 z-20 max-w-[72%] rounded-lg bg-destructive/95 px-3 py-2 text-[11px] font-medium text-destructive-foreground shadow-md animate-fade-in",children:yl})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-hidden bg-surface",children:[e.jsx(Ka,{active:Qe,mounted:sr,fallback:e.jsx(vi,{slow:!1}),children:Fe?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(kd,{items:ph,selectedKey:Mf,onSelect:Gs,emptyText:i("rightSidebar.noChanges"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i("rightSidebar.recentCommitsTitle"),headerMeta:`${Fe.headRef??""}${Fe.commits?.[0]?` · ${Fe.commits[0]}`:""}`,onClose:()=>{Oe(null),Gs(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?Ma:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:Mr,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:Ra})}):kr?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:e.jsx(kd,{items:Zo,selectedKey:xo,onSelect:Vr,emptyText:i(De?"rightSidebar.branchAuditDiffEmpty":"rightSidebar.branchAuditEmpty"),mobile:ee,backLabel:i("rightSidebar.backToChangeList"),headerTitle:i(De?"rightSidebar.branchAuditViewDiff":"rightSidebar.branchAuditTitle"),headerMeta:Ca?`${Ca.repoLabel} · ${Ca.branchName??"HEAD"} → ${Ca.baseRef}`:void 0,onClose:()=>{tr(!1),Yt(null)},closeLabel:i("common.back"),wrap:At,onToggleWrap:ee?Ma:void 0,wrapTitle:i("rightSidebar.wrapLongLines"),wrapOnLabel:i("rightSidebar.wrapOn"),wrapOffLabel:i("rightSidebar.wrapOff"),desktopLayout:ee?"stacked":"split",onInsertDiffReference:Lr,onReferenceCopied:Mr,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:Ra,onRefresh:()=>{Ac({refresh:!0})},refreshing:z,refreshLabel:i("rightSidebar.branchAuditRefreshDiff"),refreshTitle:i("rightSidebar.branchAuditRefreshDiff"),walkthroughs:gh,onWalkthroughNavigate:bh,initialDetailScrollTop:De&&rt?as[rt]:void 0,onDetailScrollPositionChange:Sh,externalSwiperRef:ee?ua:void 0,onMobileSlideChange:ee?vo:void 0})}):e.jsx("div",{className:"h-full overflow-y-auto overscroll-contain bg-surface pb-6",children:Yc?e.jsx("div",{className:"px-3",children:Yc}):Jr?e.jsx(vi,{slow:Dl}):hn?e.jsx(qa,{message:hn,onRetry:()=>{ms()}}):Qd(S)?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")}):S?.available===!1?e.jsx(qa,{message:S.error??i("rightSidebar.gitChangesLoadFailed"),onRetry:()=>{ms()}}):v?e.jsx(vi,{slow:Dl}):e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i(v?"rightSidebar.gitUnavailable":"fileTree.noWorkingDir")})})}),e.jsx(Ka,{active:zn,children:ee?e.jsxs(lu,{className:"h-full min-h-0 w-full",slidesPerView:1,resistanceRatio:.45,noSwiping:!0,noSwipingClass:"swiper-no-swiping",noSwipingSelector:".swiper-no-swiping",allowTouchMove:!1,touchAngle:75,touchStartPreventDefault:!1,onSwiper:t=>{Er.current=t,t.slideTo(bl,0)},onSlideChange:t=>{if(Cr(t.activeIndex),hs.current===t.activeIndex){hs.current=null;return}t.activeIndex===0&&(Rr(!1),pt(null),k?.())},children:[e.jsx(Li,{className:"h-full min-h-0",children:e.jsxs("div",{ref:_n,onScroll:ql,onDragOver:ha,onDragEnter:ha,onDragLeave:Xl,onDrop:Jl,className:"h-full overflow-auto overscroll-contain bg-surface relative",children:[jl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!C.trim()&&Jc,e.jsx(bd,{rootPath:ge??"",onFileSelect:gs,onPathReference:lr,getReferenceText:pa,onReferenceCopied:Mr,insertedReferenceKey:ke,copiedReferenceKey:et,onDirectoryRoot:ic,onSearchFromDirectory:lc,onDirectoryPinToggle:cc,onFilePinToggle:dc,pinnedPaths:xn,selectedFilePath:Je,query:Ie,searchRootPath:Ol,searchOptions:Ul,searchMode:D,onContentMatchSelect:Vl,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:fe,canOpenInFileBrowser:Rl,onOpenInFileBrowser:Yl})]})}),e.jsx(Li,{className:"h-full min-h-0",children:e.jsx("div",{className:"h-full overflow-hidden bg-surface",children:e.jsx(Ji,{filePath:zn&&($f||bl===1)?Je:null,onInsertReference:lr,onInsertText:$r,onInsertFeature:$r,onReviewReference:nc,onReferenceCopied:Mr,onClose:Ph,onDirectoryLinkOpen:Xc,isMobile:!0,lineRange:Rn,onLineRangeChange:pt,insertedReferenceKey:ke,copiedReferenceKey:et,scrollToLine:Ue,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:R,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:P,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:p})})})]}):e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{ref:_n,onScroll:ql,onDragOver:ha,onDragEnter:ha,onDragLeave:Xl,onDrop:Jl,className:"shrink-0 overflow-auto overscroll-contain bg-surface relative",style:{width:Co},children:[jl&&e.jsx("div",{className:"pointer-events-none absolute left-3 right-3 top-3 z-10 flex justify-center",children:e.jsx("div",{className:"rounded-xl bg-surface-elevated px-4 py-2 text-sm font-semibold text-foreground shadow-lg",children:i("rightSidebar.dropToUpload")})}),!C.trim()&&Jc,e.jsx(bd,{rootPath:ge??"",onFileSelect:gs,onPathReference:lr,getReferenceText:pa,onReferenceCopied:Mr,insertedReferenceKey:ke,copiedReferenceKey:et,onDirectoryRoot:ic,onSearchFromDirectory:lc,onDirectoryPinToggle:cc,onFilePinToggle:dc,pinnedPaths:xn,selectedFilePath:Je,query:Ie,searchRootPath:Ol,searchOptions:Ul,searchMode:D,onContentMatchSelect:Vl,onDirectoryDropFiles:(t,o)=>bs(o,t),revealDirectory:fe,canOpenInFileBrowser:Rl,onOpenInFileBrowser:Yl})]}),e.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":i("rightSidebar.resizeFileTree"),title:i("rightSidebar.resizeFileTree"),"data-local-layer":"file-preview-separator",className:"group relative z-10 w-2 shrink-0 cursor-col-resize touch-none border-l border-border/15 bg-surface",onPointerDown:Uf,onPointerMove:Hf,onPointerUp:Kl,onPointerCancel:Kl,onDoubleClick:()=>{No(Ui),$t(Es,Ui)},children:e.jsx("span",{className:"absolute left-1/2 top-0 h-full w-px -translate-x-1/2 bg-border/20 transition group-hover:bg-primary/45"})}),e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden bg-surface",children:e.jsx(Ji,{filePath:zn?Je:null,onInsertReference:lr,onInsertText:$r,onInsertFeature:$r,onReviewReference:nc,onReferenceCopied:Mr,onDirectoryLinkOpen:Xc,isMobile:!1,lineRange:Rn,onLineRangeChange:pt,insertedReferenceKey:ke,copiedReferenceKey:et,scrollToLine:Ue,onScrollToLineHandled:()=>Lt(null),markdownOutlineOpen:_,markdownOutlineCloseSignal:R,onOpenMarkdownOutline:E,onCloseMarkdownOutline:$,markdownImageLightboxOpen:P,markdownImageLightboxCloseSignal:U,onOpenMarkdownImageLightbox:F,onCloseMarkdownImageLightbox:p})})]})}),e.jsx(Ka,{active:St,mounted:Lf||St,children:()=>Bo?e.jsx(Am,{}):ee?e.jsx(Ai,{mobile:!0,backLabel:i("rightSidebar.backToChangeList"),externalSwiperRef:ua,onMobileSlideChange:vo,groups:Gt.length>0?Mc():[],mode:xr,onModeChange:Ea,selectedKey:Je,scrollToKey:Tc,scrollToKeyNonce:na.nonce,compact:!1,collapsedDirectoryKeys:Us,onToggleDirectory:Fc,onSelectFile:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);o&&Na(xt(o))},renderLeading:Lc,renderTrailing:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?Nc(o):null},renderDirectoryTrailing:Ec,renderSubtitle:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?Rc(o):null},listContainerClassName:"termdock-native-select min-h-0 px-2 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[Pa&&e.jsx("div",{className:"mb-2",children:Pa}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")})}),e.jsxs("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:[Gt.length,"/",we.size]})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Sc(),Zc,t,h&&Xo(),ed,Qc]}),Et&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:Et.label}),Et.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Et.branch})]}),!Et&&wn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Ar,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),aiContent:ya?(t=>Dc(t)):void 0,emptyContent:Bo?null:hn&&we.size===0?e.jsx(qa,{message:hn,onRetry:()=>{ms()}}):we.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Gt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderMobileDetailHeader:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>ps(0),className:"inline-flex h-9 shrink-0 items-center gap-1.5 rounded-full bg-surface-2 px-3 text-xs font-semibold text-muted-foreground transition hover:bg-surface-elevated hover:text-foreground active:scale-95",title:i("rightSidebar.backToChangeList"),children:[e.jsx(Ts,{size:14}),i("rightSidebar.backToChangeList")]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-1.5",children:[h&&Xo(),e.jsxs("button",{type:"button",onClick:Ma,"aria-pressed":At,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-9 shrink-0 items-center gap-1 rounded-full px-3 text-[11px] font-medium transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]})]})]}),detailContainerClassName:"termdock-native-select termdock-diff-stream-scroller min-h-0",files:$c(),activePane:St,wrap:At,diffViewType:Ff,inlineMode:vr,diffOptions:Uc,reloadKey:Ws,renderStreamBadge:t=>e.jsx(Ls,{status:t}),onHunkGitAction:zc,onInsertDiffReference:Lr,onReferenceCopied:Mr,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:Ra,onDetailScroll:Sa}):e.jsx(Ai,{mobile:!1,desktopLayout:"split",desktopSidePanel:null,desktopListClassName:"w-[320px] min-w-[260px] shrink-0 overflow-y-auto overscroll-contain border-r border-border/15 bg-surface",backLabel:i("rightSidebar.backToChangeList"),groups:Gt.length>0?Mc():[],mode:xr,onModeChange:Ea,selectedKey:Je,scrollToKey:Tc,scrollToKeyNonce:na.nonce,compact:!0,collapsedDirectoryKeys:Us,onToggleDirectory:Fc,onSelectFile:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);o&&Na(xt(o))},renderLeading:Lc,renderTrailing:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?Nc(o):null},renderDirectoryTrailing:Ec,renderSubtitle:t=>{const o=Array.from(we.values()).find(d=>xt(d)===t.key);return o?Rc(o):null},aiContent:ya?(t=>Dc(t)):void 0,emptyContent:Bo?null:hn&&we.size===0?e.jsx(qa,{message:hn,onRetry:()=>{ms()}}):we.size===0?e.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:i("rightSidebar.noChanges")}):Gt.length===0?e.jsx("div",{className:"bg-surface-2 px-3 py-4 text-center text-xs text-muted-foreground",children:i("rightSidebar.noMatchingChanges")}):null,renderListHeader:t=>v&&e.jsxs("div",{className:"px-0 py-0",children:[Pa&&e.jsx("div",{className:"mb-2",children:Pa}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"px-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:i("rightSidebar.allChanges")}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[Gt.length,"/",we.size]})})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-1.5",children:[Sc(),Zc,t,Xo(),e.jsxs("button",{type:"button",onClick:Ma,"aria-pressed":At,title:i("rightSidebar.wrapLongLines"),className:`inline-flex h-7 shrink-0 items-center gap-1 rounded-full px-2 text-[10px] font-semibold transition active:scale-95 ${At?"bg-primary/15 text-primary":"bg-surface-2 text-muted-foreground hover:text-foreground"}`,children:[e.jsx("span",{className:"font-mono text-[12px] leading-none",children:"Aa"}),e.jsx("span",{children:i(At?"rightSidebar.wrapOn":"rightSidebar.wrapOff")})]}),ed,Qc]}),Et&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-foreground",children:Et.label}),Et.branch&&e.jsx("span",{className:"max-w-[7rem] truncate rounded bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Et.branch}),e.jsx("button",{type:"button",onClick:()=>La("stage-all",Et.root,Et.label),disabled:!!_e,className:"rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent hover:bg-accent/20 disabled:opacity-50",title:i("rightSidebar.stageAll"),children:i("rightSidebar.stageAll")}),e.jsx("button",{type:"button",onClick:()=>La("stash-all",Et.root,Et.label),disabled:!!_e,className:"rounded-full bg-surface-2 px-2 py-0.5 text-[10px] font-medium text-foreground hover:bg-surface-elevated disabled:opacity-50",title:i("rightSidebar.stashAll"),children:i("rightSidebar.stashAll")})]}),!Et&&wn&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 rounded-md bg-surface-2 px-2 py-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Ar,{size:12,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:i("rightSidebar.selectRepositoryForDiff")})]})]}),files:$c(),activePane:St,wrap:At,diffViewType:Bt,inlineMode:vr,diffOptions:Uc,reloadKey:Ws,renderStreamBadge:t=>e.jsx(Ls,{status:t}),onHunkGitAction:zc,onInsertDiffReference:Lr,onReferenceCopied:Mr,insertedReferenceKey:ke,copiedReferenceKey:et,onClearAuditRecord:Ra,onDetailScroll:Sa})}),e.jsx(Ka,{active:Wn,mounted:ko&&Yr,children:Af?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 p-4 text-center text-[11px] text-muted-foreground",children:[e.jsx("span",{children:i("android.splitDockedHint")}),e.jsx("button",{type:"button",onClick:()=>{rd.getState().setDock(ud,null),Ei({androidPanel:{docked:null}}).catch(()=>{})},className:"rounded bg-surface-2 px-2 py-1 text-foreground",children:i("android.splitClose")})]}):e.jsx(Pm,{sessionId:n??null,onInsertPrompt:t=>Lr("android-deps",t),onInsertFile:tc,onRecordingComplete:qf})})]}),zo[0]&&e.jsx(Np,{file:zo[0],initialPath:v||"/",onInsert:tc,onDone:()=>ec(t=>t.slice(1))},zo[0].name),r&&lt&&e.jsx(Cp,{value:be,collapsed:Dr,autoCollapseAfterSend:H,focusRequest:ft,insertError:Fr?i("rightSidebar.contextDraftInsertFailed"):null,onChange:t=>{mr(!1),We(t)},onCollapsedChange:Ft,onAutoCollapseAfterSendChange:se,onDisable:()=>ct(!1),onClear:()=>We(""),onInsert:()=>sc(!1),onInsertAndSend:()=>sc(!0),labels:{title:i("rightSidebar.contextDraftTitle"),hint:i("rightSidebar.contextDraftHint"),placeholder:i("rightSidebar.contextDraftPlaceholder"),collapse:i("rightSidebar.contextDraftCollapse"),expand:i("rightSidebar.contextDraftExpand"),disable:i("rightSidebar.contextDraftDisable"),clear:i("rightSidebar.contextDraftClear"),insert:i("rightSidebar.contextDraftInsert"),insertAndSend:i("rightSidebar.contextDraftInsertAndSend"),inserted:i("rightSidebar.contextDraftInserted"),sent:i("rightSidebar.contextDraftSent"),send:i("rightSidebar.contextDraftSend"),appended:i("rightSidebar.contextDraftAppended"),resize:i("rightSidebar.contextDraftResize"),autoCollapseAfterSend:i("rightSidebar.contextDraftAutoCollapseAfterSend"),characterCount:t=>i("rightSidebar.contextDraftCharacterCount",{count:t})}}),oh(),gt&&typeof document<"u"&&Ir.createPortal(e.jsx("div",{className:"fixed inset-0 z-modal-backdrop bg-[var(--app-backdrop)] backdrop-blur-sm",onClick:()=>Xr(null),children:e.jsxs("div",{className:"fixed inset-x-3 bottom-[max(1.5rem,env(safe-area-inset-bottom,0px))] z-modal-panel mx-auto max-w-md rounded-2xl border border-border/20 bg-surface-elevated p-4 shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:gt.kind==="restore"?i("rightSidebar.confirmRestoreTitle"):i("rightSidebar.confirmStashAllTitle")}),e.jsx("div",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:gt.kind==="restore"?i("rightSidebar.confirmRestoreDescription",{path:au(gt.file.absolutePath,v)}):i("rightSidebar.confirmStashAllDescription")}),gt.kind==="restore"&&e.jsx("input",{value:gt.phrase,onChange:t=>Xr({...gt,phrase:t.target.value}),placeholder:i("rightSidebar.confirmRestorePlaceholder"),className:"mt-3 w-full rounded-xl border border-border/20 bg-surface-2 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground",autoFocus:!0}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Xr(null),className:"rounded-full bg-surface-2 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:bg-surface-elevated hover:text-foreground",children:i("common.cancel")}),e.jsx("button",{type:"button",disabled:!!_e||gt.kind==="restore"&&gt.phrase.trim()!==i("rightSidebar.confirmRestorePhrase"),onClick:()=>{if(gt.kind==="restore"){const t=mt(gt.file,v);if(!t)return;ht({action:"restore-worktree-file",cwd:t,paths:[gt.file.path],confirm:{acknowledged:!0,phrase:gt.phrase}},i("rightSidebar.restoreFile"),Si(gt.file))}else{const t=gt.repoRoot??v;if(!t)return;ht({action:"stash-all",cwd:t},i("rightSidebar.stashAll"),`repo:${t}`)}},className:`rounded-full px-3 py-1.5 text-xs font-semibold disabled:opacity-50 ${gt.kind==="restore"?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-primary text-primary-foreground hover:bg-primary/90"}`,children:i(_e?"rightSidebar.gitActionRunning":"rightSidebar.confirmAction")})]})]})}),document.body)]})}const ax=Object.freeze(Object.defineProperty({__proto__:null,FilePreview:Ji,MarkdownImageLightbox:gf,MarkdownPreview:bf,RightSidebar:qb,__testParseMarkdownListBlock:db,buildMarkdownPreviewBlocks:wb,buildMarkdownPreviewRenderResult:ll,collectKnownGitRepoRoots:Ou,computeMarkdownImageDisplayBox:Zu,getMarkdownHeadingOutline:pf,getMarkdownHeadingPathAtLine:mf,getNextMarkdownPreviewLineRange:Nb,isSvgImageSrc:co,mountRightSidebarRepoPickerOverlay:Nu,replaceGitRepositorySnapshot:Sf,resolveMarkdownLocalLinkTarget:rl,resolveRightSidebarDiffViewType:_u,shouldCloseMarkdownImageLightboxDrag:uf,showsGitRepoGroupHeader:Hi},Symbol.toStringTag,{value:"Module"}));export{Ii as E,ax as R,zm as a,sp as c,sx as m};