tide-commander 1.182.0 → 1.183.0
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.
- package/CHANGELOG.md +19 -0
- package/dist/assets/{AudioPlayer-BwhOjJ2c.js → AudioPlayer-DntjtmFY.js} +1 -1
- package/dist/assets/{BossLogsModal-DAHZQ1pi.js → BossLogsModal-DG0qGyyQ.js} +1 -1
- package/dist/assets/{BossSpawnModal-E7SGuXA2.js → BossSpawnModal-BE3fqrEQ.js} +1 -1
- package/dist/assets/{ControlsModal-bAaYejMT.js → ControlsModal-BxUj2hcx.js} +1 -1
- package/dist/assets/{DockerLogsModal-BJx8N4kK.js → DockerLogsModal-DXXdFMWk.js} +1 -1
- package/dist/assets/{EmbeddedEditor-Be-cO4-9.js → EmbeddedEditor-DIfzYNe4.js} +1 -1
- package/dist/assets/FcStdViewer-CpbcvCQH.js +1 -0
- package/dist/assets/{GcodeViewer-ncf61wWb.js → GcodeViewer-GZKkHWus.js} +1 -1
- package/dist/assets/{GlbViewer-D12gmnGd.js → GlbViewer-CypOmYH4.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-C-GvDGQm.js → GmailOAuthSetup-CWO65KoU.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-BDjIAgur.js → GoogleOAuthSetup-ouG98zZm.js} +1 -1
- package/dist/assets/{IframeModal-CCocGfa7.js → IframeModal-jC4LWAqj.js} +1 -1
- package/dist/assets/{IntegrationsPanel-CBpaeiJG.js → IntegrationsPanel-CFrTJ4yI.js} +2 -2
- package/dist/assets/{LogViewerModal-CaN7XU8z.js → LogViewerModal-BYGOn-UY.js} +1 -1
- package/dist/assets/{MonitoringModal-I3nCNlbU.js → MonitoringModal-ChTpAg5E.js} +1 -1
- package/dist/assets/{PM2LogsModal-Bki_LCvj.js → PM2LogsModal-C6ilFV5X.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-Ciy6t7et.js → RestoreArchivedAreaModal-20aGB6m1.js} +1 -1
- package/dist/assets/{Scene2DCanvas-DR56E5p7.js → Scene2DCanvas-B0JqO0Zp.js} +1 -1
- package/dist/assets/{SceneManager-DKg8ugY_.js → SceneManager-DXwGU3ni.js} +1 -1
- package/dist/assets/{SkillsPanel-C_dxzS6F.js → SkillsPanel-zL-QL8-4.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-BwiTMMvL.js → SlackMultiInstanceSetup-Cj4LKpWi.js} +1 -1
- package/dist/assets/{SpawnModal-DUMcIHoz.js → SpawnModal-Dccw_k2y.js} +1 -1
- package/dist/assets/{StatisticsModal-BKXcBthy.js → StatisticsModal-BbGUKCIz.js} +1 -1
- package/dist/assets/{StlViewer-DjdLvysP.js → StlViewer-BuS5d6ze.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-Rl4cdHpe.js → SubordinateAssignmentModal-DpVxp2ta.js} +1 -1
- package/dist/assets/{ThreeAreaSelector-C-9JJ1Hh.js → ThreeAreaSelector-C7TNtwtl.js} +1 -1
- package/dist/assets/{ThreeViewShortcuts-DL0Hmuj0.js → ThreeViewShortcuts-D5ZfDVjp.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-BtCOoX1g.js → TriggerManagerPanel-BrN4V9vK.js} +1 -1
- package/dist/assets/{VideoPlayer-BoTr9gkT.js → VideoPlayer-9wDovE5Z.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-DlcSaDPD.js → WorkflowEditorPanel-DvkV8Z4_.js} +1 -1
- package/dist/assets/{abnfDiagram-VRR7QNED-CEBRXYsw.js → abnfDiagram-VRR7QNED-Con3z51e.js} +1 -1
- package/dist/assets/{arc-COf9R405.js → arc-CWWQYHaK.js} +1 -1
- package/dist/assets/{architectureDiagram-ZJ3FMSHR-DGBRfu4B.js → architectureDiagram-ZJ3FMSHR-CrrniEMZ.js} +1 -1
- package/dist/assets/{area-logos-BRuKyQ5J.js → area-logos-F5U_sfIW.js} +1 -1
- package/dist/assets/{blockDiagram-677ZJIJ3-CN0t4U2k.js → blockDiagram-677ZJIJ3-MlV0Bx2X.js} +1 -1
- package/dist/assets/{c4Diagram-LMCZKHZV-Cq0IftW5.js → c4Diagram-LMCZKHZV-Bczl4ceN.js} +1 -1
- package/dist/assets/channel-DhJKhZOl.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-adR2VoGA.js → chunk-2Q5K7J3B-uMf2zApa.js} +1 -1
- package/dist/assets/{chunk-32BRIVSS-B6LCChZq.js → chunk-32BRIVSS-YQLvcU-w.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CcH2c7y_.js → chunk-5VM5RSS4-Bv44lK_C.js} +1 -1
- package/dist/assets/{chunk-EX3LRPZG-zBWa-mu2.js → chunk-EX3LRPZG-BoWkmPlS.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-DBQlYiWn.js → chunk-JWPE2WC7-B71OUFoy.js} +1 -1
- package/dist/assets/{chunk-MOJQB5TN-BjbsCplS.js → chunk-MOJQB5TN-DGpbFjEE.js} +1 -1
- package/dist/assets/{chunk-RYQCIY6F-B946ZxlN.js → chunk-RYQCIY6F-CUaqIbqz.js} +1 -1
- package/dist/assets/{chunk-V7JOEXUC-DEeYHnRT.js → chunk-V7JOEXUC-DoRxLReN.js} +1 -1
- package/dist/assets/{chunk-VR4S4FIN-B_QmrVGt.js → chunk-VR4S4FIN-B4AQrVEa.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-cgYh6YrW.js → chunk-XXDRQBXY-DZVLCDKR.js} +1 -1
- package/dist/assets/classDiagram-OUVF2IWQ-F4DdT1bz.js +1 -0
- package/dist/assets/classDiagram-v2-EOCWNBFH-F4DdT1bz.js +1 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-DJUmw0Ip.js → cose-bilkent-JH36ORCC-CcOIOt1P.js} +1 -1
- package/dist/assets/{cynefin-VYW2F7L2-BUxR220i.js → cynefin-VYW2F7L2-BwwhPetI.js} +1 -1
- package/dist/assets/{cynefinDiagram-TSTJHNR4-nYR1MwE2.js → cynefinDiagram-TSTJHNR4--V66_WT7.js} +1 -1
- package/dist/assets/{dagre-VKFMJZFB-A5VPim2l.js → dagre-VKFMJZFB-CQidxhQe.js} +1 -1
- package/dist/assets/{diagram-FQU43EPY-wdgwDoVg.js → diagram-FQU43EPY-gVCH6npm.js} +1 -1
- package/dist/assets/{diagram-G47NLZAW-CylyJQBQ.js → diagram-G47NLZAW-Crm2bCwK.js} +1 -1
- package/dist/assets/{diagram-NH7WQ7WH-BOF1uKhH.js → diagram-NH7WQ7WH-B5-91Me5.js} +1 -1
- package/dist/assets/{diagram-OA4YK3LP-B0B5zmh5.js → diagram-OA4YK3LP-BL92CL4n.js} +1 -1
- package/dist/assets/{diagram-WEI45ONY-vKP2IU9q.js → diagram-WEI45ONY-Ct4Y-e1G.js} +1 -1
- package/dist/assets/{ebnfDiagram-CCIWWBDH-DM8hIEJM.js → ebnfDiagram-CCIWWBDH-CgFnpcpk.js} +1 -1
- package/dist/assets/{erDiagram-Q63AITRT-iuRH3hWX.js → erDiagram-Q63AITRT-F93obfaw.js} +1 -1
- package/dist/assets/{fcstd.worker-BSFnALBZ.js → fcstd.worker-bs9ZyQJN.js} +17 -17
- package/dist/assets/{flowDiagram-23GEKE2U-CddCUoGB.js → flowDiagram-23GEKE2U-BjK3Ns-v.js} +1 -1
- package/dist/assets/{ganttDiagram-NO4QXBWP-CIfvQLcu.js → ganttDiagram-NO4QXBWP-Dhg1PlEG.js} +1 -1
- package/dist/assets/{gitGraphDiagram-IHSO6WYX-CbW0FQci.js → gitGraphDiagram-IHSO6WYX-BIvk5Sbm.js} +1 -1
- package/dist/assets/{index-DHuT10Pa.js → index-9tgJKfUx.js} +1 -1
- package/dist/assets/{index-BmD7ycmn.js → index-B4lIIYnl.js} +1 -1
- package/dist/assets/{index-CIcFjlRX.js → index-B8QkgKiD.js} +2 -2
- package/dist/assets/{index-CRhUiTuD.js → index-B9On-Gc2.js} +1 -1
- package/dist/assets/{index-B4YklnOy.js → index-BpuIdv2X.js} +1 -1
- package/dist/assets/{index-HhAZ3SIm.js → index-C-LSKhvC.js} +1 -1
- package/dist/assets/{index-Du8eK_OX.js → index-CGbeEcuO.js} +1 -1
- package/dist/assets/index-DT_iBBpR.js +19 -0
- package/dist/assets/{index-DoJdznbY.js → index-DyAtzN3k.js} +1 -1
- package/dist/assets/{infoDiagram-FWYZ7A6U-C0it9hLc.js → infoDiagram-FWYZ7A6U-D8y97kfq.js} +1 -1
- package/dist/assets/{ishikawaDiagram-FXEZZL3T-pKZnNgqp.js → ishikawaDiagram-FXEZZL3T-RsNvLRNJ.js} +1 -1
- package/dist/assets/{journeyDiagram-5HDEW3XC-Ib9FpXdB.js → journeyDiagram-5HDEW3XC-DDu6O4Xa.js} +1 -1
- package/dist/assets/{kanban-definition-HUTT4EX6-aOTfe6f6.js → kanban-definition-HUTT4EX6-BdyQRxVX.js} +1 -1
- package/dist/assets/{linear-B_ipWlyx.js → linear-CmFTyYvd.js} +1 -1
- package/dist/assets/main-CA-vQSSx.css +1 -0
- package/dist/assets/{main-m3NNcAo4.js → main-DXG9arLM.js} +143 -142
- package/dist/assets/{mermaid.core-EY9hyXLz.js → mermaid.core-Bt-11G2g.js} +4 -4
- package/dist/assets/{mindmap-definition-LN4V7U3C-B_p1LOAa.js → mindmap-definition-LN4V7U3C-SmMMV-FP.js} +1 -1
- package/dist/assets/{pegDiagram-2B236MQR-BgCd9rWg.js → pegDiagram-2B236MQR-CWwvj4kG.js} +1 -1
- package/dist/assets/{pieDiagram-ENE6RG2P-d8ofNooq.js → pieDiagram-ENE6RG2P-gBVnKXU2.js} +1 -1
- package/dist/assets/{quadrantDiagram-ABIIQ3AL-27DPJdZF.js → quadrantDiagram-ABIIQ3AL-DsI4SV_G.js} +1 -1
- package/dist/assets/{railroadDiagram-RFXS5EU6-C7S8pppU.js → railroadDiagram-RFXS5EU6-Xgn2AqX_.js} +1 -1
- package/dist/assets/{requirementDiagram-TGXJPOKE-BbTkDbLO.js → requirementDiagram-TGXJPOKE-CNJSWaII.js} +1 -1
- package/dist/assets/{sankeyDiagram-HTMAVEWB-lU57KWVw.js → sankeyDiagram-HTMAVEWB-7R-oTObT.js} +1 -1
- package/dist/assets/{sequenceDiagram-DBY2YBRQ-Bg18P0LT.js → sequenceDiagram-DBY2YBRQ-DAJ_SkXi.js} +1 -1
- package/dist/assets/{sizeCapture-X5ZJPWSS-FDhyxAiu.js → sizeCapture-X5ZJPWSS-dXg2Btjz.js} +1 -1
- package/dist/assets/{stateDiagram-2N3HPSRC-pp9KUH2d.js → stateDiagram-2N3HPSRC-QOa2unB0.js} +1 -1
- package/dist/assets/stateDiagram-v2-6OUMAXLB-BoRtqceU.js +1 -0
- package/dist/assets/{swimlanes-5IMT3BWC-BCUZKORl.js → swimlanes-5IMT3BWC-DpGkTD0b.js} +2 -2
- package/dist/assets/swimlanesDiagram-G3AALYLV-UzuviI8q.js +8 -0
- package/dist/assets/{timeline-definition-FHXFAJF6-BaeOwVlH.js → timeline-definition-FHXFAJF6-B3wYo6Z0.js} +1 -1
- package/dist/assets/{vennDiagram-L72KCM5P-BkhqU_hz.js → vennDiagram-L72KCM5P-DxRpcVln.js} +1 -1
- package/dist/assets/{wardleyDiagram-EHGQE667-DvPxIC6q.js → wardleyDiagram-EHGQE667-B-nj2Zec.js} +1 -1
- package/dist/assets/{web-DOiXCdVs.js → web-Bq407zt-.js} +1 -1
- package/dist/assets/{web-BhVPxATx.js → web-CZDCjMgt.js} +1 -1
- package/dist/assets/{web-CR-app3U.js → web-CaPWqQkM.js} +1 -1
- package/dist/assets/{xychartDiagram-FW5EYKEG-B9MrBAD_.js → xychartDiagram-FW5EYKEG-D2S19oqW.js} +1 -1
- package/dist/build-info.json +1 -1
- package/dist/index.html +2 -2
- package/dist/src/packages/server/app.js +9 -1
- package/dist/src/packages/server/index.js +9 -0
- package/dist/src/packages/server/routes/files.js +95 -2
- package/dist/src/packages/server/services/agent-service.js +9 -0
- package/dist/src/packages/server/services/instruction-refresh.js +40 -0
- package/dist/src/packages/server/websocket/handlers/sync-handler.js +21 -1
- package/package.json +1 -1
- package/dist/assets/FcStdViewer-DEwQ08Bb.js +0 -1
- package/dist/assets/channel-DF_pUJhw.js +0 -1
- package/dist/assets/classDiagram-OUVF2IWQ-CeYNs9YM.js +0 -1
- package/dist/assets/classDiagram-v2-EOCWNBFH-CeYNs9YM.js +0 -1
- package/dist/assets/index-HYcYan1q.js +0 -19
- package/dist/assets/main-Bvn8CMZc.css +0 -1
- package/dist/assets/stateDiagram-v2-6OUMAXLB-BmoS7QDQ.js +0 -1
- package/dist/assets/swimlanesDiagram-G3AALYLV-Da6QbdiL.js +0 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { saveAreas, saveBuildings, loadAreas, deleteAreaLogo } from '../../data/index.js';
|
|
2
2
|
import { buildingService } from '../../services/index.js';
|
|
3
|
+
import { markInstructionsDirtyForAreaChanges } from '../../services/instruction-refresh.js';
|
|
3
4
|
import { logger } from '../../utils/index.js';
|
|
4
5
|
const log = logger.ws;
|
|
5
6
|
function handleSyncMessage(ctx, payload, entityName, saveFn, updateType) {
|
|
@@ -11,9 +12,28 @@ function handleSyncMessage(ctx, payload, entityName, saveFn, updateType) {
|
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
export function handleSyncAreas(ctx, payload) {
|
|
15
|
+
let previousAreas = [];
|
|
16
|
+
try {
|
|
17
|
+
previousAreas = loadAreas();
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
log.error(' Failed to load previous areas:', err);
|
|
21
|
+
}
|
|
22
|
+
// An area prompt is baked into the instruction block when a session starts, so
|
|
23
|
+
// a running agent on a stdin backend would keep the old text until it restarts —
|
|
24
|
+
// editing an area prompt would look like it did nothing. Flag the agents whose
|
|
25
|
+
// resolved area prompt actually changed so their next turn re-injects it.
|
|
26
|
+
try {
|
|
27
|
+
const affected = markInstructionsDirtyForAreaChanges(previousAreas, payload);
|
|
28
|
+
if (affected.length > 0) {
|
|
29
|
+
log.log(` Area prompt changed for ${affected.length} agent(s) — instructions will refresh`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
log.error(' Failed to flag area prompt changes:', err);
|
|
34
|
+
}
|
|
14
35
|
// Clean up orphaned logo files before saving
|
|
15
36
|
try {
|
|
16
|
-
const previousAreas = loadAreas();
|
|
17
37
|
const newAreaIds = new Set(payload.map(a => a.id));
|
|
18
38
|
for (const prev of previousAreas) {
|
|
19
39
|
// Area was deleted and had a logo
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{u as _e,r as e,j as g,c as Xe}from"./main-m3NNcAo4.js";import{V as R,c as Ze,d as ne,e as qe,W as Je,f as Qe,H as et,D as Pe,G as tt,B as rt,g as he,h as nt,i as st,j as ot,L as at,E as it,k as ct,l as lt,A as ut,b as dt,a as ft,m as mt}from"./vendor-three-CBPuP1jE.js";import{O as pt}from"./OrbitControls-DS7gPhsZ.js";import{g as ht,v as gt,u as wt,a as yt,d as Oe,s as Mt,c as xt,T as bt,b as St}from"./ThreeAreaSelector-C-9JJ1Hh.js";import{T as Ct,a as Et}from"./ThreeViewShortcuts-DL0Hmuj0.js";import"./vendor-react--Eh9ivFN.js";function Rt(y){return Number.isFinite(y)?y>=100?y.toFixed(0):y>=10?y.toFixed(1):y.toFixed(2):"0"}function kt({url:y,filename:Y,filePath:Ae,onFileSelect:ke}){const{t:m}=_e("terminal"),ge=e.useRef(null),A=e.useRef(null),k=e.useRef(null),w=e.useRef(null),F=e.useRef(null),se=e.useRef([]),oe=e.useRef([]),ae=e.useRef(null),_=e.useRef(null),X=e.useRef(null),T=e.useRef(null),Z=e.useRef([]),q=e.useRef(new R),we=e.useRef(1),v=e.useRef(null),[j,L]=e.useState(!0),[ye,ie]=e.useState(null),[S,D]=e.useState(null),[M,Me]=e.useState(null),[ce,Fe]=e.useState(!1),[V]=e.useState(ht),[z,Te]=e.useState(V.modelColor),[B,De]=e.useState(V.backgroundColor),[I,ze]=e.useState(V.lightIntensity),[N,Be]=e.useState(V.modelOpacity),[G,Ie]=e.useState(V.showEdges),[W,xe]=e.useState(V.preserveModelColors),[le,ue]=e.useState(!1),[C,J]=e.useState(null),[P,Q]=e.useState([]),[de,ee]=e.useState(null),fe=Ae||gt(y),Ne=wt(fe,Y,"fcstd");yt({enabled:!!M&&C===null,rendererRef:X,cameraRef:_,controlsRef:T,modelObjectsRef:Z,modelCenterRef:q,markerGroupRef:v,renderRef:w,setAreas:Q,setSelectedId:ee}),e.useEffect(()=>{const r=ge.current;if(!r)return;const d=new AbortController,t=new Worker(new URL("/assets/fcstd.worker-BSFnALBZ.js",import.meta.url),{type:"module"});let l=!1;const b=[],O=[];let a=null;L(!0),ie(null),D(null),Me(null);const u=new Ze;u.background=new ne(1119258),F.current=u;const i=new qe(40,1,.01,1e5);_.current=i,i.up.set(0,0,1);let s;try{s=new Je({antialias:!0})}catch{t.terminate(),L(!1),D(m("fileViewerModal.webglUnavailable"));return}s.setPixelRatio(Math.min(window.devicePixelRatio||1,2)),X.current=s,s.outputColorSpace=Qe,s.domElement.className="stl-viewer-canvas",s.domElement.setAttribute("aria-label",m("fileViewerModal.fcstdPreviewLabel",{filename:Y})),r.appendChild(s.domElement);const f=new pt(i,s.domElement);T.current=f,f.enableDamping=!1,f.screenSpacePanning=!0,f.addEventListener("change",()=>s.render(u,i));const te=new et(16777215,2502724,2.2);u.add(te);const U=new Pe(16777215,2.5);U.position.set(3,-4,6),u.add(U);const E=new Pe(8040191,1.1);E.position.set(-4,3,1),u.add(E),ae.current={hemisphere:te,key:U,fill:E},w.current=()=>s.render(u,i);const H=()=>{const p=Math.max(r.clientWidth,1),c=Math.max(r.clientHeight,1);i.aspect=p/c,i.updateProjectionMatrix(),s.setSize(p,c,!1),s.render(u,i)},$=new ResizeObserver(H);return $.observe(r),H(),t.onmessage=p=>{if(l)return;const c=p.data;if(c.type==="progress"){ie({current:c.current,total:c.total});return}if(c.type==="error"){const n=c.message==="NO_BREP_GEOMETRY"?"fileViewerModal.noBrepGeometry":c.message==="BREP_IMPORT_FAILED"?"fileViewerModal.brepImportFailed":"fileViewerModal.fcstdRenderError";D(m(n)),L(!1);return}const K=new tt,He=c.meshes.reduce((n,o)=>n+o.indices.length/3,0)<=25e4;let Se=0;for(const n of c.meshes){const o=new rt;o.setAttribute("position",new he(n.positions,3)),n.normals?o.setAttribute("normal",new he(n.normals,3)):o.computeVertexNormals(),o.setIndex(new he(n.indices,1)),b.push(o);const x=new nt({color:new ne(...n.color),metalness:.05,roughness:.68,side:st,transparent:n.opacity<1,opacity:n.opacity,depthWrite:n.opacity>=1});x.userData.originalColor=x.color.clone(),x.userData.originalOpacity=n.opacity,O.push(x),se.current.push(x);const pe=new ot(o,x);if(pe.name=n.name,Z.current.push(pe),K.add(pe),He){const je=new at({color:1582123,transparent:!0,opacity:.48}),Le=new it(o,28);b.push(Le),O.push(je);const Ve=new ct(Le,je);oe.current.push(Ve),K.add(Ve)}Se+=n.indices.length/3}u.add(K);const Ce=new lt().setFromObject(K),h=Ce.getSize(new R),Ee=Ce.getCenter(new R);q.current.copy(Ee),we.current=Math.max(h.x,h.y,h.z,.001)*.12,K.position.sub(Ee);const $e=Math.max(h.x,h.y,h.z,.001)*.3;a=new ut($e),a.position.set(-h.x/2,-h.y/2,-h.z/2),a.renderOrder=5,u.add(a);const Re=Math.max(h.length()/2,.001),Ke=dt.degToRad(i.fov/2),re=Math.max(Re/Math.sin(Ke)*1.18,.01),me=n=>{i.near=Math.max(re/1e3,1e-4),i.far=Math.max(re*100,10);const o=n==="x"?new R(1,0,0):n==="y"?new R(0,1,0):n==="z"?new R(0,0,1):new R(1,-1,.78).normalize();i.up.set(0,n==="z"?1:0,n==="z"?0:1),i.position.copy(o.multiplyScalar(re)),i.updateProjectionMatrix(),f.target.set(0,0,0),f.minDistance=Re*.05,f.maxDistance=re*20,f.update(),s.render(u,i)},ve=()=>me("iso");k.current=me,A.current=ve,ve();const Ye=n=>{if(n.ctrlKey||n.metaKey||n.altKey)return;const o=n.key.toLowerCase(),x=o==="x"||o==="1"?"x":o==="y"||o==="2"?"y":o==="z"||o==="3"?"z":o==="i"||o==="4"?"iso":null;x&&(n.preventDefault(),me(x))};s.domElement.tabIndex=0,s.domElement.addEventListener("pointerdown",()=>s.domElement.focus()),s.domElement.addEventListener("keydown",Ye),Me({objects:c.objectCount,triangles:Math.floor(Se),dimensions:[h.x,h.y,h.z]}),L(!1),ie(null)},t.onerror=()=>{l||(D(m("fileViewerModal.fcstdRenderError")),L(!1))},(async()=>{try{const p=await Xe(y,{signal:d.signal});if(!p.ok)throw new Error(`HTTP ${p.status}`);const c=await p.arrayBuffer();l||t.postMessage(c,[c])}catch{if(l||d.signal.aborted)return;D(m("fileViewerModal.fcstdLoadError")),L(!1)}})(),()=>{l=!0,d.abort(),t.terminate(),A.current=null,k.current=null,w.current=null,F.current=null,se.current=[],oe.current=[],ae.current=null,_.current=null,X.current=null,T.current=null,Z.current=[],Oe(v.current),v.current=null,$.disconnect(),f.dispose(),b.forEach(p=>p.dispose()),O.forEach(p=>p.dispose()),a==null||a.geometry.dispose(),a&&(Array.isArray(a.material)?a.material:[a.material]).forEach(c=>c.dispose()),s.dispose(),s.domElement.remove()}},[y,Y,m]),e.useEffect(()=>{var d;F.current&&(F.current.background=new ne(B));for(const t of se.current){const l=t.userData.originalColor;W&&l instanceof ne?t.color.copy(l):t.color.set(z);const b=typeof t.userData.originalOpacity=="number"?t.userData.originalOpacity:1;t.opacity=b*(N/100),t.transparent=t.opacity<1,t.depthWrite=t.opacity>=1,t.needsUpdate=!0}const r=ae.current;if(r){const t=I/100;r.hemisphere.intensity=2.2*t,r.key.intensity=2.5*t,r.fill.intensity=1.1*t}oe.current.forEach(t=>{t.visible=G}),(d=w.current)==null||d.call(w)},[z,B,I,N,G,W,M]),e.useEffect(()=>{Mt({modelColor:z,backgroundColor:B,lightIntensity:I,modelOpacity:N,showEdges:G,preserveModelColors:W})},[z,B,I,N,G,W]),e.useEffect(()=>{Q([]),ee(null),J(null),ue(!1)},[y]),e.useEffect(()=>{T.current&&(T.current.enabled=C===null);const r=X.current,d=_.current;if(!r||!d||!M||!C)return;const t=r.domElement;let l=null;const b=a=>{l=[a.clientX,a.clientY]},O=a=>{var $;if(!l||Math.hypot(a.clientX-l[0],a.clientY-l[1])>5)return;const u=t.getBoundingClientRect(),i=new ft((a.clientX-u.left)/u.width*2-1,-((a.clientY-u.top)/u.height)*2+1),s=new mt;s.setFromCamera(i,d);const f=s.intersectObjects(Z.current,!1)[0];if(!f)return;const te=f.point.clone().add(q.current),U=($=f.face)==null?void 0:$.normal.clone().transformDirection(f.object.matrixWorld).toArray(),E=we.current,H=`area-${Date.now()}-${Math.random().toString(36).slice(2,7)}`;Q(be=>[...be,{id:H,shape:C,center:te.toArray(),size:[E,E,E],objectName:f.object.name||void 0,surfaceNormal:U}]),ee(H)};return t.addEventListener("pointerdown",b),t.addEventListener("pointerup",O),()=>{t.removeEventListener("pointerdown",b),t.removeEventListener("pointerup",O)}},[C,M]),e.useEffect(()=>{var t,l;Oe(v.current),v.current=null;const r=F.current;if(!r||P.length===0){(t=w.current)==null||t.call(w);return}const d=xt(P,q.current,de);v.current=d,r.add(d),(l=w.current)==null||l.call(w)},[P,de,M]);const Ge=e.useCallback(()=>{var r;return(r=A.current)==null?void 0:r.call(A)},[]),We=e.useCallback(r=>{var d;return(d=k.current)==null?void 0:d.call(k,r)},[]),Ue=ye?m("fileViewerModal.processingFcstd",ye):m("fileViewerModal.loadingFcstd");return g.jsxs("div",{className:`stl-viewer fcstd-viewer${C?" area-placement-active":""}`,ref:ge,children:[j&&g.jsx("div",{className:"stl-viewer-status",children:Ue}),S&&g.jsx("div",{className:"stl-viewer-status stl-viewer-error",children:S}),!j&&!S&&g.jsxs("div",{className:"stl-viewer-toolbar",children:[M&&g.jsxs("span",{className:"stl-viewer-info",children:[m("fileViewerModal.fcstdStats",{objects:M.objects.toLocaleString(),triangles:M.triangles.toLocaleString()})," · ",M.dimensions.map(Rt).join(" × ")]}),g.jsx(Ct,{onView:We}),g.jsx("button",{type:"button",onClick:Ge,title:m("fileViewerModal.resetCamera"),children:m("fileViewerModal.resetView")}),g.jsxs("button",{type:"button",className:le?"active":void 0,onClick:()=>{ue(r=>!r),J(null)},"aria-expanded":le,children:[m("fileViewerModal.areas"),P.length>0?` (${P.length})`:""]}),g.jsx("button",{type:"button",className:ce?"active":void 0,onClick:()=>Fe(r=>!r),"aria-expanded":ce,children:m("fileViewerModal.viewerSettings")})]}),!j&&!S&&ce&&g.jsx(bt,{modelColor:z,onModelColorChange:r=>{Te(r),xe(!1)},backgroundColor:B,onBackgroundColorChange:De,lightIntensity:I,onLightIntensityChange:ze,modelOpacity:N,onModelOpacityChange:Be,showEdges:G,onShowEdgesChange:Ie,preserveModelColors:W,onPreserveModelColorsChange:xe,recentFiles:Ne,currentFilePath:fe,onRecentFileSelect:ke}),!j&&!S&&le&&g.jsx(St,{areas:P,selectedId:de,placementShape:C,filename:Y,filePath:fe,modelExtent:Math.max(...M.dimensions),onPlacementShapeChange:J,onSelectedIdChange:ee,onAreasChange:Q,onClose:()=>{ue(!1),J(null)}}),!j&&!S&&g.jsx("div",{className:"stl-viewer-hint",children:m("fileViewerModal.controlsHint")}),!j&&!S&&g.jsx(Et,{})]})}export{kt as FcStdViewer};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{U as a,C as n}from"./mermaid.core-EY9hyXLz.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-DEeYHnRT.js";import{_ as i}from"./mermaid.core-EY9hyXLz.js";import"./chunk-5VM5RSS4-CcH2c7y_.js";import"./chunk-XXDRQBXY-cgYh6YrW.js";import"./chunk-VR4S4FIN-B_QmrVGt.js";import"./chunk-32BRIVSS-B6LCChZq.js";import"./main-m3NNcAo4.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";var b={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{b as diagram};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-DEeYHnRT.js";import{_ as i}from"./mermaid.core-EY9hyXLz.js";import"./chunk-5VM5RSS4-CcH2c7y_.js";import"./chunk-XXDRQBXY-cgYh6YrW.js";import"./chunk-VR4S4FIN-B_QmrVGt.js";import"./chunk-32BRIVSS-B6LCChZq.js";import"./main-m3NNcAo4.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";var b={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{b as diagram};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-Be-cO4-9.js","assets/main-m3NNcAo4.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-CBPuP1jE.js","assets/main-Bvn8CMZc.css","assets/EmbeddedEditor-BipHj7Fz.css","assets/AudioPlayer-BwhOjJ2c.js","assets/VideoPlayer-BoTr9gkT.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as s,c as V,d as A,N as It,ch as Wn,ci as Jn,b4 as Qs,S as Ot,b5 as Zs,s as Ve,u as ie,j as e,I as M,cj as Ut,bp as en,ck as tn,a1 as rs,cl as sn,cm as nn,cn as qn,co as Yn,as as zt,cp as Xn,cq as Qn,cr as Zn,a8 as ct,cs as ea,ct as is,cu as ta,cv as an,cw as Ht,cx as At,bo as lt,cy as bt,cz as jt,cA as Us,cB as sa,a4 as na,cC as as,a0 as aa,cD as ra,cE as ia,cF as Lt,cG as la,cH as oa,cI as ca,cJ as da,bP as ua,cK as ha,cL as Gs,Z as ma,ap as pa}from"./main-m3NNcAo4.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";function fa(t){const[n,l]=s.useState(null),[c,r]=s.useState(!1),i=s.useCallback(async()=>{if(t){r(!0);try{const h=await V(A(`/api/files/git-status?path=${encodeURIComponent(t)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[t]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function ga(t){try{const n=await V(A(`/api/files/git-original?path=${encodeURIComponent(t)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const xa=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),ya=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),ba=new Set([".pdf"]),ja=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function va(t){const n=t.toLowerCase();return ya.has(n)?"image":ba.has(n)?"pdf":Wn(n)?"audio":Jn(n)?"video":ja.has(n)?"binary":(xa.has(n),"text")}function wa(){const[t,n]=s.useState(null),[l,c]=s.useState(!1),[r,i]=s.useState(null),h=s.useCallback(async d=>{var g,b;c(!0),i(null);try{const p=d.substring(d.lastIndexOf(".")).toLowerCase(),v=va(p),N=d.substring(d.lastIndexOf("/")+1);if(v==="image"){const k=await V(A(`/api/files/binary?path=${encodeURIComponent(d)}`));if(!k.ok){const C=await k.json().catch(()=>({error:"Failed to load image"}));i(C.error||"Failed to load image"),n(null);return}const f=await k.blob(),j=URL.createObjectURL(f);n({path:d,filename:N,extension:p,content:"",size:f.size,modified:new Date().toISOString(),fileType:"image",dataUrl:j});return}if(v==="pdf"){const k=await V(A(`/api/files/info?path=${encodeURIComponent(d)}`)),f=await k.json();if(!k.ok){i(f.error||"Failed to load PDF info"),n(null);return}n({path:d,filename:N,extension:p,content:"",size:f.size,modified:f.modified,fileType:"pdf",dataUrl:A(`/api/files/binary?path=${encodeURIComponent(d)}&token=${encodeURIComponent(It())}`)});return}if(v==="audio"||v==="video"){const k=await V(A(`/api/files/info?path=${encodeURIComponent(d)}`)),f=await k.json();if(!k.ok){i(f.error||"Failed to load media info"),n(null);return}const j=v==="video"?`&token=${encodeURIComponent(It())}`:"";n({path:d,filename:N,extension:p,content:"",size:f.size,modified:f.modified,fileType:v,dataUrl:A(`/api/files/binary?path=${encodeURIComponent(d)}${j}`)});return}if(v==="binary"){const k=await V(A(`/api/files/info?path=${encodeURIComponent(d)}`)),f=await k.json();if(!k.ok){i(f.error||"Failed to load file info"),n(null);return}n({path:d,filename:N,extension:p,content:"",size:f.size,modified:f.modified,fileType:"binary",dataUrl:A(`/api/files/binary?path=${encodeURIComponent(d)}&download=true&token=${encodeURIComponent(It())}`)});return}const F=await V(A(`/api/files/read?path=${encodeURIComponent(d)}`)),y=await F.json();if(!F.ok){if((g=y.error)!=null&&g.includes("too large")||(b=y.error)!=null&&b.includes("binary")){const k=await V(A(`/api/files/info?path=${encodeURIComponent(d)}`)),f=await k.json();if(k.ok){n({path:d,filename:N,extension:p,content:"",size:f.size,modified:f.modified,fileType:"binary",dataUrl:A(`/api/files/binary?path=${encodeURIComponent(d)}&download=true&token=${encodeURIComponent(It())}`)});return}}i(y.error||"Failed to load file"),n(null);return}n({...y,fileType:"text"})}catch(p){const v=p instanceof Error?p.message:"Failed to load file";i(v),n(null)}finally{c(!1)}},[]),o=s.useCallback(()=>{n(d=>(d!=null&&d.dataUrl&&d.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(d.dataUrl),null)),i(null)},[]);return{file:t,loading:l,error:r,loadFile:h,clearFile:o,setFile:n}}const Ca="file-explorer-state",_s="file-explorer-recent-projects",Na=10080*60*1e3,ka=12;function ts(t){return`${Ca}-folder-${t}`}async function Ea(t){try{const n=await V(A(`/api/files/exists?path=${encodeURIComponent(t)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function Sa(){const t=s.useCallback(async r=>{if(!r)return null;try{const i=localStorage.getItem(ts(r));if(!i)return null;const h=JSON.parse(i);if(Date.now()-h.timestamp>Na)return localStorage.removeItem(ts(r)),null;const d=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await Ea(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let g=h.activeTabPath;return g&&!d.some(b=>b.path===g)&&(g=d.length>0?d[0].path:null),{tabs:d,activeTabPath:g,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(i){return console.error("[FileExplorerStorage] Failed to load project state:",i),null}},[]),n=s.useCallback((r,i)=>{if(r)try{const h={tabs:i.tabs,activeTabPath:i.activeTabPath,viewMode:i.viewMode,expandedPaths:Array.from(i.expandedPaths),timestamp:Date.now()};localStorage.setItem(ts(r),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=s.useCallback(()=>{try{const r=localStorage.getItem(_s);if(!r)return[];const i=JSON.parse(r);return Array.isArray(i)?i.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=s.useCallback(r=>{if(!r)return l();const i=[r,...l().filter(h=>h!==r)].slice(0,ka);try{localStorage.setItem(_s,JSON.stringify(i))}catch{}return i},[l]);return{loadProjectState:t,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Bs=280,Vs=150,Ks=1200;function Ta(){const[t,n]=s.useState(()=>{const g=Qs(Ot.TREE_PANEL_WIDTH,Bs);return g>=Vs&&g<=Ks?g:Bs}),l=s.useRef(!1),[c,r]=s.useState(!1),i=s.useRef(0),h=s.useRef(0),o=s.useRef(t);o.current=t;const d=s.useCallback(g=>{g.preventDefault(),l.current=!0,r(!0),i.current=g.clientX,h.current=t,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[t]);return s.useEffect(()=>{const g=p=>{if(!l.current)return;const v=p.clientX-i.current,N=Math.min(Ks,Math.max(Vs,h.current+v));n(N)},b=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Zs(Ot.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",g),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:t,handleResizeStart:d,isResizing:c}}const Da=100,Ma=.65,Ra=36;function Fa(){const[t,n]=s.useState(()=>Qs(Ot.MOBILE_TREE_PANEL_HEIGHT,0)),l=s.useRef(t);l.current=t;const c=s.useRef(0),r=s.useRef(0),i=()=>Math.floor((window.innerHeight-Ra)*Ma),h=p=>Math.min(i(),Math.max(Da,p)),o=s.useCallback(p=>{n(p);const v=document.querySelector(".file-explorer-main");v&&v.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),d=s.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Zs(Ot.MOBILE_TREE_PANEL_HEIGHT,l.current),Ve.setTerminalResizing(!1)},[]),g=s.useCallback(p=>{p.preventDefault();const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=p.clientY,r.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Ve.setTerminalResizing(!0);const F=k=>{const f=k.clientY-c.current;o(h(r.current+f))},y=()=>{document.removeEventListener("mousemove",F),document.removeEventListener("mouseup",y),d()};document.addEventListener("mousemove",F),document.addEventListener("mouseup",y)},[o,d]),b=s.useCallback(p=>{if(p.touches.length!==1)return;const v=document.querySelector(".file-explorer-tree-panel"),N=l.current>0?l.current:(v==null?void 0:v.getBoundingClientRect().height)??240;c.current=p.touches[0].clientY,r.current=N,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Ve.setTerminalResizing(!0);const F=k=>{if(k.touches.length!==1)return;k.preventDefault();const f=k.touches[0].clientY-c.current;o(h(r.current+f))},y=()=>{document.removeEventListener("touchmove",F),document.removeEventListener("touchend",y),document.removeEventListener("touchcancel",y),d()};document.addEventListener("touchmove",F,{passive:!1}),document.addEventListener("touchend",y),document.addEventListener("touchcancel",y)},[o,d]);return{mobileTreeHeight:t,handleResizeMouseDown:g,handleResizeTouchStart:b}}function ls(){const[t,n]=s.useState([]),[l,c]=s.useState(!1),[r,i]=s.useState(null),[h,o]=s.useState(null),d=s.useCallback(async k=>{c(!0),i(null);try{const f=await V(A(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),j=await f.json();f.ok?n(j.branches||[]):(i(j.error||"Failed to load branches"),n([]))}catch(f){console.error("[GitBranches] Failed to load branches:",f),i("Failed to load branches"),n([])}finally{c(!1)}},[]),g=s.useCallback(async(k,f)=>{o("checkout"),i(null);try{const j=await V(A("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:f})}),C=await j.json();return j.ok||i(C.error||"Checkout failed"),C}catch(j){console.error("[GitBranches] Checkout failed:",j);const C={success:!1,error:"Checkout failed"};return i(C.error),C}finally{o(null)}},[]),b=s.useCallback(async(k,f,j)=>{o("create"),i(null);try{const C=await V(A("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:f,startPoint:j})}),D=await C.json();return C.ok||i(D.error||"Failed to create branch"),D}catch(C){console.error("[GitBranches] Create branch failed:",C);const D={success:!1,error:"Failed to create branch"};return i(D.error),D}finally{o(null)}},[]),p=s.useCallback(async k=>{o("pull"),i(null);try{const f=await V(A("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await f.json();return!f.ok&&!j.conflicts&&i(j.error||"Pull failed"),j}catch(f){console.error("[GitBranches] Pull failed:",f);const j={success:!1,error:"Pull failed"};return i(j.error),j}finally{o(null)}},[]),v=s.useCallback(async k=>{o("push"),i(null);try{const f=await V(A("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await f.json();return f.ok||i(j.error||"Push failed"),j}catch(f){console.error("[GitBranches] Push failed:",f);const j={success:!1,error:"Push failed"};return i(j.error),j}finally{o(null)}},[]),N=s.useCallback(async(k,f)=>{o("merge"),i(null);try{const j=await V(A("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:f})}),C=await j.json();return!j.ok&&!C.conflicts&&i(C.error||"Merge failed"),C}catch(j){console.error("[GitBranches] Merge failed:",j);const C={success:!1,error:"Merge failed"};return i(C.error),C}finally{o(null)}},[]),F=s.useCallback(async k=>{o("merge-abort"),i(null);try{const f=await V(A("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await f.json();return f.ok||i(j.error||"Merge abort failed"),j}catch(f){console.error("[GitBranches] Merge abort failed:",f);const j={success:!1,error:"Merge abort failed"};return i(j.error),j}finally{o(null)}},[]),y=s.useCallback(async k=>{o("merge-continue"),i(null);try{const f=await V(A("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),j=await f.json();return f.ok||i(j.error||"Merge continue failed"),j}catch(f){console.error("[GitBranches] Merge continue failed:",f);const j={success:!1,error:"Merge continue failed"};return i(j.error),j}finally{o(null)}},[]);return{branches:t,loading:l,error:r,operationInProgress:h,loadBranches:d,checkoutBranch:g,createBranch:b,pullFromRemote:p,pushToRemote:v,mergeBranch:N,mergeAbort:F,mergeContinue:y}}const Pa=50,Ia=400,Ws={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function La(){const[t,n]=s.useState([]),[l,c]=s.useState(!1),[r,i]=s.useState(!1),[h,o]=s.useState(null),[d,g]=s.useState(!1),[b,p]=s.useState(0),[v,N]=s.useState({...Ws}),[F,y]=s.useState(null),[k,f]=s.useState([]),[j,C]=s.useState(!1),[D,H]=s.useState([]),[G,K]=s.useState(!1),w=s.useRef(null),re=s.useRef(""),_=s.useCallback((U,se,I)=>{const B=I||v,Z=new URLSearchParams;return Z.set("path",U),Z.set("limit",String(Pa)),Z.set("offset",String(se)),B.branch&&Z.set("branch",B.branch),B.author&&Z.set("author",B.author),B.since&&Z.set("since",B.since),B.until&&Z.set("until",B.until),B.searchPath&&Z.set("searchPath",B.searchPath),B.search&&Z.set("search",B.search),Z.toString()},[v]),R=s.useCallback(async U=>{re.current=U,c(!0),o(null),y(null),f([]);try{const se=_(U,0),I=await V(A(`/api/files/git-log?${se}`)),B=await I.json();I.ok?(n(B.commits||[]),p(B.total||0),g(B.hasMore||!1)):(o(B.error||"Failed to load git history"),n([]))}catch(se){console.error("[useGitHistory] loadHistory error:",se),o("Failed to load git history"),n([])}finally{c(!1)}},[_]),P=s.useCallback(async U=>{if(!(r||!d)){i(!0);try{const se=_(U,t.length),I=await V(A(`/api/files/git-log?${se}`)),B=await I.json();I.ok&&(n(Z=>[...Z,...B.commits||[]]),p(B.total||0),g(B.hasMore||!1))}catch(se){console.error("[useGitHistory] loadMore error:",se)}finally{i(!1)}}},[_,t.length,d,r]),X=s.useCallback(async U=>{if(y(U),!U){f([]);return}C(!0);try{const se=re.current,I=new URLSearchParams({path:se,hash:U.hash}),B=await V(A(`/api/files/git-commit-files?${I}`)),Z=await B.json();B.ok?f(Z.files||[]):f([])}catch(se){console.error("[useGitHistory] selectCommit files error:",se),f([])}finally{C(!1)}},[]),Q=s.useCallback((U,se)=>{N(I=>({...I,[U]:se}))},[]),ne=s.useCallback(()=>{N({...Ws})},[]);s.useEffect(()=>{const U=re.current;if(U)return w.current&&clearTimeout(w.current),w.current=setTimeout(()=>{R(U)},Ia),()=>{w.current&&clearTimeout(w.current)}},[v]);const ue=s.useCallback(async U=>{K(!0);try{const se=new URLSearchParams({path:U}),I=await V(A(`/api/files/git-authors?${se}`)),B=await I.json();I.ok&&H(B.authors||[])}catch(se){console.error("[useGitHistory] loadAuthors error:",se)}finally{K(!1)}},[]);return{commits:t,loading:l,loadingMore:r,error:h,hasMore:d,total:b,filters:v,setFilter:Q,resetFilters:ne,selectedCommit:F,selectCommit:X,commitFiles:k,commitFilesLoading:j,loadHistory:R,loadMore:P,authors:D,authorsLoading:G,loadAuthors:ue}}function $a(t){if(!t.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=t.current.querySelector(l);if(c&&Js(c))return c}return Js(t.current)?t.current:null}function Js(t){const n=["auto","scroll"].includes(getComputedStyle(t).overflowY),l=t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;return n&&l}function rn(t){if(!t)return 19.5;const n=parseFloat(getComputedStyle(t).lineHeight);return isNaN(n)?19.5:n}function ss(t,n=!0){const l=n?t.scrollHeight:0;t.scrollTo({top:l,behavior:"smooth"})}function za(t){const{scrollTop:n,scrollHeight:l,clientHeight:c}=t;return l<=c?100:Math.round(n/(l-c)*100)}function Ha(t,n){const l=rn(t),c=t.scrollTop,r=Math.floor(c/l)+1,i=n.split(`
|
|
3
|
-
`).length;return Math.min(r,i)}function Aa(t,n,l=!1){if(!n)return[];l||t.toLowerCase();const c=l?n:n.toLowerCase(),r=[];let i=0;const h=t.split(`
|
|
4
|
-
`);let o=0;for(let d=0;d<h.length;d++){const g=h[d],b=l?g:g.toLowerCase();let p=0,v=b.indexOf(c);for(;v!==-1;){const N=o+v;r.push({index:i++,line:d+1,column:v,length:c.length,charIndex:N}),p=v+c.length,v=b.indexOf(c,p)}o+=g.length+1}return r}function ot(t){return/[\w]/.test(t)}function Ke(t){return/\s/.test(t)}function Oa(t,n,l){let c=n-1,r=l;const i=t.length,h=t[c]||"";if(r<h.length){const g=ot(h[r]);if(!Ke(h[r]))for(;r<h.length&&!Ke(h[r])&&ot(h[r])===g;)r++}for(;c<i;){const g=t[c]||"";for(;r<g.length&&Ke(g[r]);)r++;if(r<g.length)return{line:c+1,col:r};c++,r=0}const o=i,d=Math.max(0,(t[i-1]||"").length-1);return{line:o,col:d}}function Ua(t,n,l){let c=n-1,r=l+1;const i=t.length;for(;c<i;){const d=t[c]||"";for(;r<d.length&&Ke(d[r]);)r++;if(r<d.length)break;c++,r=0}if(c>=i)return{line:i,col:Math.max(0,(t[i-1]||"").length-1)};const h=t[c]||"",o=ot(h[r]);for(;r+1<h.length&&!Ke(h[r+1])&&ot(h[r+1])===o;)r++;return{line:c+1,col:r}}function Ga(t,n,l){let c=n-1,r=l-1;for(;c>=0;){const o=t[c]||"";for(;r>=0&&Ke(o[r]);)r--;if(r>=0)break;c--,c>=0&&(r=(t[c]||"").length-1)}if(c<0)return{line:1,col:0};const i=t[c]||"",h=ot(i[r]);for(;r>0&&!Ke(i[r-1])&&ot(i[r-1])===h;)r--;return{line:c+1,col:r}}function _a(t,n,l,c){if(c==="none")return"";const{anchorLine:r,anchorCol:i,headLine:h,headCol:o}=l;if(c==="line"){const N=Math.min(r,h),F=Math.max(r,h);return n.slice(N-1,F).join(`
|
|
5
|
-
`)}let d,g,b,p;if(r<h||r===h&&i<=o?(d=r,g=i,b=h,p=o):(d=h,g=o,b=r,p=i),d===b)return(n[d-1]||"").substring(g,p+1);const v=[];v.push((n[d-1]||"").substring(g));for(let N=d;N<b-1;N++)v.push(n[N]||"");return v.push((n[b-1]||"").substring(0,p+1)),v.join(`
|
|
6
|
-
`)}function ln(t){const{containerRef:n,isEnabled:l=!0,content:c="",onClose:r,onSearchOpen:i}=t,h=s.useRef({percentage:0,line:1,column:1}),o=s.useRef(null),d=s.useRef(19.5),g=s.useMemo(()=>c.split(`
|
|
7
|
-
`),[c]),b=g.length,[p,v]=s.useState(1),[N,F]=s.useState(0),[y,k]=s.useState(!1),[f,j]=s.useState("none"),[C,D]=s.useState(null),[H,G]=s.useState(!1),[K,w]=s.useState(""),[re,_]=s.useState(0),[R,P]=s.useState(!1),X=s.useMemo(()=>Aa(c,K,!1),[c,K]),Q=s.useCallback(()=>{const m=o.current;if(!m)return;const Y=za(m),le=Ha(m,c),T=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:Y,line:le,column:T}},[c]),ne=s.useCallback(()=>{G(!0),w(""),_(0),i==null||i()},[i]),ue=s.useCallback(()=>{G(!1),w(""),_(0)},[]),U=s.useCallback(()=>{P(m=>!m)},[]),se=s.useCallback(m=>{const Y=o.current;if(!Y)return;const le=Y.querySelector(".file-viewer-pre"),me=le&&parseFloat(getComputedStyle(le).lineHeight)||d.current,T=le&&parseFloat(getComputedStyle(le).paddingTop)||0,te=(le?le.offsetTop:0)+T+(m-1)*me,ae=me*3;Y.scrollTo({top:Math.max(0,te-ae),behavior:"smooth"})},[]);s.useEffect(()=>{!H||X.length===0||_(0)},[X,H]),s.useEffect(()=>{if(!H||X.length===0)return;const m=X[re];m&&(v(m.line),F(m.column),se(m.line))},[H,X,re,se]);const I=s.useCallback(()=>{X.length!==0&&_(m=>(m+1)%X.length)},[X]),B=s.useCallback(()=>{X.length!==0&&_(m=>(m-1+X.length)%X.length)},[X]),Z=s.useCallback(m=>{const Y=o.current;if(!Y)return;const le=Y.querySelector(".file-viewer-pre");if(!le)return;const me=parseFloat(getComputedStyle(le).lineHeight),T=isNaN(me)?d.current:me,S=parseFloat(getComputedStyle(le).paddingTop)||0,ae=le.offsetTop+S+(m-1)*T,pe=ae+T,oe=Y.scrollTop,W=oe+Y.clientHeight;ae<oe?Y.scrollTo({top:Math.max(0,ae),behavior:"auto"}):pe>W&&Y.scrollTo({top:pe-Y.clientHeight,behavior:"auto"})},[]),L=s.useCallback((m,Y)=>{v(m),F(Y),Z(m),f!=="none"&&D(le=>le?{...le,headLine:m,headCol:Y}:null)},[f,Z]),we=s.useCallback(()=>{if(f==="none"||!C)return;const m=_a(c,g,C,f);m&&navigator.clipboard.writeText(m).catch(()=>{const Y=document.createElement("textarea");Y.value=m,Y.style.position="fixed",Y.style.left="-9999px",document.body.appendChild(Y),Y.select(),document.execCommand("copy"),document.body.removeChild(Y)}),j("none"),D(null)},[f,C,c,g]),ee=s.useCallback(m=>{const Y=m.target;if((Y.tagName==="INPUT"||Y.tagName==="TEXTAREA")&&m.key!=="Escape")return;const me=o.current;if(!me)return;let T=!1;const S=d.current,te=Math.max(1,Math.floor(me.clientHeight/S)),ae=Math.max(1,Math.floor(te/2)),pe=(W,ye)=>{const Ge=Math.max(0,(g[W-1]||"").length-1);return Math.min(ye,Math.max(0,Ge))},oe=(W,ye)=>{const Ge=pe(W,ye);L(W,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!H)m.preventDefault(),m.stopPropagation(),f==="char"?(j("none"),D(null)):(j("char"),D({anchorLine:p,anchorCol:N,headLine:p,headCol:N})),T=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!H)m.preventDefault(),m.stopPropagation(),f==="line"?(j("none"),D(null)):(j("line"),D({anchorLine:p,anchorCol:0,headLine:p,headCol:0})),T=!0;else if(m.key==="y"&&!m.ctrlKey&&f!=="none")m.preventDefault(),m.stopPropagation(),we(),T=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const W=Math.min(p+1,b);oe(W,N),T=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const W=Math.max(p-1,1);oe(W,N),T=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&f==="none"&&!H){m.preventDefault(),m.stopPropagation();const W=Math.min(p+ae,b);oe(W,N),T=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&f==="none"&&!H){m.preventDefault(),m.stopPropagation();const W=Math.max(p-ae,1);oe(W,N),T=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),ne(),T=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&f==="none"&&!H){m.preventDefault(),m.stopPropagation();const W=Math.min(p+te,b);oe(W,N),T=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const W=Math.min(p+te,b);oe(W,N),T=!0}else if(m.key==="b"&&!y&&f==="none"&&!H||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const W=Math.max(p-te,1);oe(W,N),T=!0}else if(m.key==="g"&&!m.shiftKey&&f==="none"&&!H)m.preventDefault(),m.stopPropagation(),L(1,0),ss(me,!1),T=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),L(1,0),ss(me,!1),T=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),L(b,0),ss(me,!0),T=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),L(p,Math.max(0,N-1)),T=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const W=(g[p-1]||"").length;L(p,Math.min(N+1,Math.max(0,W-1))),T=!0}else if(m.key==="w"&&!m.ctrlKey&&!H){m.preventDefault(),m.stopPropagation();const W=Oa(g,p,N);L(W.line,W.col),T=!0}else if(m.key==="e"&&!m.ctrlKey&&!H){m.preventDefault(),m.stopPropagation();const W=Ua(g,p,N);L(W.line,W.col),T=!0}else if(m.key==="b"&&!H){m.preventDefault(),m.stopPropagation();const W=Ga(g,p,N);L(W.line,W.col),T=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),L(p,0),T=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),L(p,Math.max(0,(g[p-1]||"").length-1)),T=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const ye=(g[p-1]||"").search(/\S/);L(p,ye>=0?ye:0),T=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),ne(),T=!0):m.key==="n"&&!H?(m.preventDefault(),m.stopPropagation(),I(),T=!0):m.key==="N"&&m.shiftKey&&!H?(m.preventDefault(),m.stopPropagation(),B(),T=!0):m.key==="?"&&f==="none"?(m.preventDefault(),m.stopPropagation(),U(),T=!0):m.key==="q"&&f==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),T=!0):m.key==="Escape"&&(f!=="none"?(m.preventDefault(),m.stopPropagation(),j("none"),D(null),T=!0):H?(m.preventDefault(),m.stopPropagation(),ue(),T=!0):y&&(m.preventDefault(),m.stopPropagation(),k(!1),T=!0));T&&(m.key!=="Escape"&&!y&&k(!0),requestAnimationFrame(Q))},[r,Q,b,g,p,N,Z,H,ue,f,y,L,we,ne,I,B,U]);return s.useEffect(()=>{if(!l)return;const m=$a(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}d.current=rn(m);const Y=()=>{Q()};return window.addEventListener("keydown",ee,{capture:!0}),m.addEventListener("scroll",Y,{passive:!0}),Q(),()=>{window.removeEventListener("keydown",ee,{capture:!0}),m.removeEventListener("scroll",Y)}},[l,ee,Q]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:p,cursorCol:N,cursorModeActive:y,visualMode:f,selection:C,searchActive:H,searchQuery:K,searchMatches:X,currentMatchIndex:re,startSearch:ne,setSearchQuery:w,nextMatch:I,prevMatch:B,clearSearch:ue,helpActive:R,toggleHelp:U}}const os=({query:t,onQueryChange:n,matchCount:l,currentIndex:c,onNext:r,onPrev:i,onClose:h})=>{const{t:o}=ie(["terminal"]),d=s.useRef(null);s.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]);const g=s.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),b=l===0&&t?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:d,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:t,onChange:p=>n(p.target.value),onKeyDown:g,autoComplete:"off",spellCheck:"false"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};os.displayName="SearchBar";const Ba=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],cs=({onClose:t})=>{const{t:n}=ie(["terminal"]),l=s.useCallback(i=>{i.target===i.currentTarget&&t()},[t]),c=s.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),t())},[t]),r=Ba.reduce((i,h)=>(i[h.category]||(i[h.category]=[]),i[h.category].push(h),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:t,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,h])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:i}),e.jsx("div",{className:"keybindings-help-list",children:h.map((o,d)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((g,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:g},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},d))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};cs.displayName="KeybindingsHelp";const qs=s.lazy(()=>rs(()=>import("./EmbeddedEditor-Be-cO4-9.js"),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.EmbeddedEditor}))),Va=s.lazy(()=>rs(()=>import("./AudioPlayer-BwhOjJ2c.js"),__vite__mapDeps([6,1,2,3,4])).then(t=>({default:t.AudioPlayer}))),Ka=s.lazy(()=>rs(()=>import("./VideoPlayer-BoTr9gkT.js"),__vite__mapDeps([7,1,2,3,4])).then(t=>({default:t.VideoPlayer}))),Wa=[".md",".mdx",".markdown"],Ys="file-viewer-markdown-render",Ja=[".puml",".plantuml",".iuml",".pu"],Xs="file-viewer-plantuml-render",qa="https://kroki.io/plantuml/svg";function Ya(t){return Wa.includes(t.toLowerCase())}function Xa(t){return Ja.includes(t.toLowerCase())}function Qa(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ys);return c===null?!0:c==="true"}catch{return!0}}),l=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ys,String(r))}catch{}return r})},[]);return[t,l]}function Za(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Xs);return c===null?!0:c==="true"}catch{return!0}}),l=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Xs,String(r))}catch{}return r})},[]);return[t,l]}function er(t){const n=new TextEncoder().encode(t);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function ze({file:t,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:r}){const{t:i}=ie(["terminal","common"]),[h,o]=s.useState("idle"),[d,g]=s.useState("idle"),[b,p]=s.useState("idle"),v=t.fileType==="text"?Ut(t.extension):t.extension.slice(1).toUpperCase(),N=t.fileType==="text"&&t.content!=null,F=en(),y=async()=>{try{await zt(t.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},k=async()=>{const D=A(`/api/files/binary?path=${encodeURIComponent(t.path)}&download=true`);await ct(D,t.filename,"text/plain;charset=utf-8")},f=async()=>{o("loading");try{const D=await V(A("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,...F.externalEditorCommand&&{editorCommand:F.externalEditorCommand}})});if(!D.ok){const H=await D.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",H),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(D){console.error("Error opening file in editor:",D),o("error"),setTimeout(()=>o("idle"),2e3)}},j=async()=>{if(t.path)try{await ea(t.path),g("success"),setTimeout(()=>g("idle"),2e3)}catch(D){console.error("Error opening file explorer:",D),g("error"),setTimeout(()=>g("idle"),2e3)}},C=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:t.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[tn(t.size)," • ",v,t.content&&` • ${t.content.split(`
|
|
8
|
-
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[r&&t.fileType==="text"&&e.jsx("button",{className:`file-viewer-edit-btn${c?" active":""}`,onClick:r,title:i(c?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),N&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:y,title:i("terminal:fileExplorer.copyAllTitle"),children:i(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:k,title:i("terminal:fileExplorer.downloadFileTitle"),children:i("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${d}`,onClick:j,disabled:!t.path,title:C,"aria-label":C,children:d==="success"?e.jsx(M,{name:"check",size:14}):d==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${h}`,onClick:f,disabled:h==="loading",title:i(h==="error"?"terminal:fileExplorer.failedToOpenEditor":h==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:h==="success"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 11-1.06-1.06l7.25-7.25a.75.75 0 011.06 0z"})}):h==="error"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1h6v1.5h-5v11h11v-5H15v6.5H0V1h1.5zm8 0H15v5.5h-1.5V3.56L7.28 9.78l-1.06-1.06L12.44 2.5H9.5V1z"})})}),l&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>l(t.path),title:i("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function tr({file:t,onRevealInTree:n,renderMarkdown:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const h=s.useRef(null),o=s.useRef(null),d=s.useRef(null),{t:g}=ie(["terminal","common"]),[b,p]=s.useState("idle"),[v,N]=s.useState("idle"),[F,y]=s.useState("idle"),[k,f]=s.useState("idle"),j=ln({containerRef:d,isEnabled:!0,content:t.content});s.useEffect(()=>{if(!l&&h.current){const w=Ut(t.extension);sn(w).then(()=>{h.current&&nn(h.current)})}},[t,l]);const C=s.useCallback(async()=>{if(!o.current){p("error"),setTimeout(()=>p("idle"),2e3);return}try{const w=o.current.innerHTML,re=qn(w),_=o.current.innerText;await Yn(re,_),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},[]),D=s.useCallback(async()=>{if(!o.current){N("error"),setTimeout(()=>N("idle"),2e3);return}try{const w=o.current.innerHTML;await zt(w),N("copied"),setTimeout(()=>N("idle"),2e3)}catch{N("error"),setTimeout(()=>N("idle"),2e3)}},[]),H=s.useCallback(async()=>{try{await zt(t.content),y("copied"),setTimeout(()=>y("idle"),2e3)}catch{y("error"),setTimeout(()=>y("idle"),2e3)}},[t.content]),G=s.useCallback(async()=>{try{await zt(t.content),f("copied"),setTimeout(()=>f("idle"),2e3)}catch{f("error"),setTimeout(()=>f("idle"),2e3)}},[t.content]),K=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:C,title:g("terminal:fileExplorer.copyRichTextTitle"),children:g(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${v}`,onClick:D,title:g("terminal:fileExplorer.copyHtmlTitle"),children:g(v==="copied"?"terminal:fileExplorer.copied":v==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${F}`,onClick:H,title:g("terminal:fileExplorer.copyMarkdownTitle"),children:g(F==="copied"?"terminal:fileExplorer.copied":F==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:G,title:g("terminal:fileExplorer.copyOriginalTitle"),children:g(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:g(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n,rightContent:K,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:d,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(Xn,{remarkPlugins:[Qn],children:t.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:h,className:"language-markdown",children:t.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${j.currentLine}/${j.totalLines}`,children:j.scrollPercentage===100?"END":j.scrollPercentage===0?"TOP":`${j.scrollPercentage}%`}),j.searchActive&&e.jsx(os,{query:j.searchQuery,onQueryChange:j.setSearchQuery,matchCount:j.searchMatches.length,currentIndex:j.currentMatchIndex,onNext:j.nextMatch,onPrev:j.prevMatch,onClose:j.clearSearch})]}),j.helpActive&&e.jsx(cs,{onClose:j.toggleHelp})]})}function sr({file:t,onRevealInTree:n,renderPlantUml:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const{t:h}=ie(["terminal"]),o=s.useRef(null),d=s.useRef(null),[g,b]=s.useState(null),[p,v]=s.useState(!1),[N,F]=s.useState(null),y=ln({containerRef:d,isEnabled:!0,content:t.content});s.useEffect(()=>{if(!l&&o.current){const f=Ut(t.extension);sn(f).then(()=>{o.current&&nn(o.current)})}},[t,l]),s.useEffect(()=>{if(!l)return;if(!t.content.trim()){b(null),F("Diagram is empty");return}const f=new AbortController;return v(!0),F(null),(async()=>{try{const C=await fetch(qa,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:t.content,signal:f.signal});if(!C.ok)throw new Error(`Render failed (${C.status})`);const D=await C.text();if(!D.includes("<svg"))throw new Error("Invalid SVG output");b(er(D))}catch(C){if(f.signal.aborted)return;const D=C instanceof Error?C.message:"Failed to render diagram";F(D),b(null)}finally{f.signal.aborted||v(!1)}})(),()=>f.abort()},[t.path,t.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:h(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":h("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n,rightContent:k,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:d,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[p&&e.jsx("div",{className:"file-viewer-placeholder",children:h("terminal:fileExplorer.renderingDiagram")}),!p&&g&&e.jsx("img",{src:g,alt:t.filename,className:"file-viewer-diagram-image"}),!p&&N&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[h("terminal:fileExplorer.couldNotRender"),": ",N]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:h("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:o,className:"language-plaintext",children:t.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${y.currentLine}/${y.totalLines}`,children:y.scrollPercentage===100?"END":y.scrollPercentage===0?"TOP":`${y.scrollPercentage}%`}),y.searchActive&&e.jsx(os,{query:y.searchQuery,onQueryChange:y.setSearchQuery,matchCount:y.searchMatches.length,currentIndex:y.currentMatchIndex,onNext:y.nextMatch,onPrev:y.prevMatch,onClose:y.clearSearch})]}),y.helpActive&&e.jsx(cs,{onClose:y.toggleHelp})]})}function nr({file:t,onRevealInTree:n}){const{t:l}=ie(["common","terminal"]),c=async()=>{const r=A(`/api/files/binary?path=${encodeURIComponent(t.path)}&download=true`);await ct(r,t.filename)};return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper zoomable",children:t.dataUrl?e.jsx(Zn,{src:t.dataUrl,alt:t.filename}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadImage")})})]})}function ar({file:t,onRevealInTree:n}){const{t:l}=ie(["common","terminal"]),c=async()=>{const r=A(`/api/files/binary?path=${encodeURIComponent(t.path)}&download=true`);await ct(r,t.filename,"application/pdf")};return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:t.dataUrl?e.jsx("iframe",{src:t.dataUrl,title:t.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function rr({file:t,onRevealInTree:n}){const{t:l}=ie(["common","terminal"]),c=async()=>{const r=A(`/api/files/binary?path=${encodeURIComponent(t.path)}&download=true`);await ct(r,t.filename)};return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-audio-wrapper",children:t.dataUrl?e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:l("common:status.loading")}),children:e.jsx(Va,{url:t.dataUrl,filename:t.filename})}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:audioPlayer.loadError",{defaultValue:"Could not load audio"})})})]})}function ir({file:t,onRevealInTree:n}){const{t:l}=ie(["common","terminal"]),c=A(`/api/files/binary?path=${encodeURIComponent(t.path)}&download=true`),r=async()=>{await ct(c,t.filename)};return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:r,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-video-wrapper",children:t.dataUrl?e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:l("common:status.loading")}),children:e.jsx(Ka,{url:t.dataUrl,downloadUrl:c,filename:t.filename})}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:videoPlayer.loadError",{defaultValue:"Could not load video"})})})]})}function lr({file:t,onRevealInTree:n}){const{t:l}=ie(["terminal","common"]),c=async()=>{const i=A(`/api/files/binary?path=${encodeURIComponent(t.path)}&download=true`);await ct(i,t.filename)},r=()=>{const i=t.extension.toLowerCase();return[".xlsx",".xls"].includes(i)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(i)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(i)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(i)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(i)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(i)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(i)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(i)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(i)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(i)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(i)?e.jsx(M,{name:"wrench",size:48}):e.jsx(M,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(ze,{file:t,onRevealInTree:n}),e.jsxs("div",{className:"file-viewer-binary",children:[e.jsx("div",{className:"file-viewer-binary-icon",children:r()}),e.jsx("div",{className:"file-viewer-binary-name",children:t.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:tn(t.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:l("terminal:fileExplorer.downloadFile")})]})]})}function or({file:t,loading:n,error:l,onRevealInTree:c,onFileEdited:r}){const{t:i}=ie(["terminal","common"]),[h,o]=Qa(),[d,g]=Za(),[b,p]=s.useState(!1);s.useEffect(()=>{p(!1)},[t==null?void 0:t.path]);const v=s.useCallback(async C=>{if(!t)return;const D=await V(A("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,content:C})});if(!D.ok){const H=await D.json().catch(()=>({error:"Save failed"}));throw new Error(H.error||"Save failed")}},[t]),N=s.useCallback(()=>{p(C=>(C&&t&&(r==null||r(t.path)),!C))},[t,r]),F=s.useCallback(()=>{t&&(r==null||r(t.path))},[t,r]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")});if(l)return e.jsx("div",{className:"file-viewer-placeholder error",children:l});if(!t)return e.jsxs("div",{className:"file-viewer-placeholder",children:[e.jsx("div",{className:"placeholder-icon",children:e.jsx(M,{name:"folder-open",size:32})}),e.jsx("div",{className:"placeholder-text",children:i("terminal:fileExplorer.selectFileToView")})]});const y=t.fileType||"text",k=y==="text"&&Ya(t.extension),f=y==="text"&&Xa(t.extension),j=k||f;return j&&b&&t.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(ze,{file:t,onRevealInTree:c,editMode:!0,onToggleEdit:N}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(qs,{content:t.content,extension:t.extension,onSave:v,onCancel:N},t.path)})]}):y==="text"&&!j&&t.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(ze,{file:t,onRevealInTree:c}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(qs,{content:t.content,extension:t.extension,onSave:v,onCancel:F},t.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(tr,{file:t,onRevealInTree:c,renderMarkdown:h,onToggleRender:o,editMode:b,onToggleEdit:N}),f&&!k&&e.jsx(sr,{file:t,onRevealInTree:c,renderPlantUml:d,onToggleRender:g,editMode:b,onToggleEdit:N}),y==="image"&&e.jsx(nr,{file:t,onRevealInTree:c}),y==="pdf"&&e.jsx(ar,{file:t,onRevealInTree:c}),y==="audio"&&e.jsx(rr,{file:t,onRevealInTree:c}),y==="video"&&e.jsx(ir,{file:t,onRevealInTree:c}),y==="binary"&&e.jsx(lr,{file:t,onRevealInTree:c})]})}const on=s.memo(or,(t,n)=>t.loading!==n.loading||t.error!==n.error?!1:t.file===null&&n.file===null?!0:t.file===null||n.file===null?!1:t.file.path===n.file.path&&t.file.content===n.file.content&&t.file.modified===n.file.modified);on.displayName="FileViewer";function cn({text:t,query:n}){if(!n)return e.jsx(e.Fragment,{children:t});const l=ta(t,n);if(l)return e.jsxs(e.Fragment,{children:[t.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:t.slice(l.start,l.end)}),t.slice(l.end)]});const c=n.toLowerCase(),i=t.toLowerCase().indexOf(c);return i===-1?e.jsx(e.Fragment,{children:t}):e.jsxs(e.Fragment,{children:[t.slice(0,i),e.jsx("mark",{className:"search-highlight",children:t.slice(i,i+n.length)}),t.slice(i+n.length)]})}const cr=s.memo(function({node:n,query:l,isSelected:c,onSelect:r,lineNumber:i}){const h=n.isDirectory?null:is(n),o=n.path.split("/");o[o.length-1];const d=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${c?"selected":""}`,onClick:()=>r(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"folder",size:14})}):h?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${h}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(cn,{text:n.name,query:l}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:d})]})]})}),dr=s.memo(function({match:n,query:l,isSelected:c,onSelect:r}){const{t:i}=ie(["terminal"]),h={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=is(h),d=n.path.split("/"),g=d[d.length-1],b=d.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${c?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${c?"selected":""}`,onClick:()=>r(n.path),children:[o?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${o}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"content-search-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{className:"content-search-name",children:g}),e.jsx("span",{className:"search-result-path",style:{fontSize:"10px"},children:b})]}),e.jsx("span",{className:"content-search-count",children:n.matches.length})]}),e.jsxs("div",{className:"content-search-matches",children:[n.matches.slice(0,5).map((p,v)=>e.jsxs("div",{className:"content-search-match",onClick:()=>r(n.path,p.line),children:[e.jsx("span",{className:"content-search-line-num",children:p.line}),e.jsx("span",{className:"content-search-line-content",children:e.jsx(cn,{text:p.content.trim(),query:l})})]},`${n.path}-${p.line}-${v}`)),n.matches.length>5&&e.jsxs("div",{className:"content-search-match",style:{opacity:.6,cursor:"default"},children:[e.jsx("span",{className:"content-search-line-num",children:"..."}),e.jsx("span",{className:"content-search-line-content",children:i("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function ur({filenameResults:t,contentResults:n,onSelectFile:l,onSelectContent:c,selectedPath:r,query:i,lineNumber:h}){const{t:o}=ie(["terminal"]),d=t.length>0,g=n.length>0;return!d&&!g?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[d&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:t.length})]}),e.jsx("div",{className:"unified-search-section-content",children:t.map(b=>e.jsx(cr,{node:b,query:i,isSelected:r===b.path,onSelect:l,lineNumber:h},b.path))})]}),g&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(M,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:o("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((b,p)=>b+p.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(b=>e.jsx(dr,{match:b,query:i,isSelected:r===b.path,onSelect:c},b.path))})]})]})}const dn=s.memo(ur,(t,n)=>!(t.query!==n.query||t.selectedPath!==n.selectedPath||t.filenameResults.length!==n.filenameResults.length||t.contentResults.length!==n.contentResults.length));dn.displayName="UnifiedSearchResults";const hr=s.memo(function({file:n,isSelected:l,onSelect:c,onStage:r,isStaging:i,showDirPath:h,isChecked:o,onToggleCheck:d,onContextMenu:g,onDiscard:b}){const{t:p}=ie(["terminal"]),v=n.status,N=jt[v],F=v==="deleted",y=v==="untracked"&&r,k=n.name.includes(".")?"."+n.name.split(".").pop():"",f=h&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!F&&c(n.path,v),onContextMenu:j=>{j.preventDefault(),g==null||g(j,n,v)},style:{cursor:F?"not-allowed":"pointer"},title:n.path,children:[d&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:j=>{j.stopPropagation(),d(n.path)},onClick:j=>j.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:bt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,f&&e.jsx("span",{className:"git-file-dir",children:f})]}),e.jsx("span",{className:"git-file-status",style:{color:N.color},children:N.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.oldPath.split("/").pop()]}),y&&e.jsx("button",{className:`git-stage-btn ${i?"staging":""}`,onClick:j=>{j.stopPropagation(),i||r(n.path)},title:p("terminal:fileExplorer.stageFile"),disabled:i,children:i?"...":"+"}),b&&e.jsx("button",{className:"git-discard-btn",onClick:j=>{j.stopPropagation(),b(n,v)},title:v==="untracked"||v==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),mr=16,pr=22,fr=s.memo(function t({node:n,depth:l,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h,onStage:o,stagingPaths:d,checkedFiles:g,onToggleCheck:b,onContextMenu:p,onDirContextMenu:v,onDiscard:N}){const{t:F}=ie(["terminal"]),y=l*mr;if(!n.isDirectory){const f=n.file.status,j=jt[f];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>f!=="deleted"&&h(n.file.path,f),onContextMenu:C=>{C.preventDefault(),p==null||p(C,n.file,f)},style:{paddingLeft:`${y+pr}px`,cursor:f==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[b&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(g==null?void 0:g.has(n.file.path))||!1,onChange:C=>{C.stopPropagation(),b(n.file.path)},onClick:C=>C.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:bt(n.file.name.includes(".")?"."+n.file.name.split(".").pop():""),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:j.color},children:j.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),f==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${d!=null&&d.has(n.path)?"staging":""}`,onClick:C=>{C.stopPropagation(),d!=null&&d.has(n.path)||o(n.file.path)},title:F("terminal:fileExplorer.stageFile"),disabled:d==null?void 0:d.has(n.path),children:d!=null&&d.has(n.path)?"...":"+"}),N&&e.jsx("button",{className:"git-discard-btn",onClick:C=>{C.stopPropagation(),N(n.file,f)},title:f==="untracked"||f==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const k=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${y}px`},onClick:()=>r(n.path),onContextMenu:f=>{f.preventDefault(),f.stopPropagation(),v==null||v(f,n)},children:[e.jsx("span",{className:`tree-arrow ${k?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:k?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:F("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(f=>e.jsx(t,{node:f,depth:l+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h,onStage:o,stagingPaths:d,checkedFiles:g,onToggleCheck:b,onContextMenu:p,onDirContextMenu:v,onDiscard:N},f.path))})]})}),ns=s.memo(function({groupLabel:n,groupIcon:l,groupColor:c,files:r,treeNodes:i,viewMode:h,selectedPath:o,expandedDirs:d,onToggleDir:g,onFileSelect:b,onStageFile:p,onStageAll:v,stagingPaths:N,checkedFiles:F,onToggleCheck:y,onContextMenu:k,onDirContextMenu:f,onDiscardFile:j,onDiscardAll:C}){const{t:D}=ie(["terminal"]);if(r.length===0)return null;const H=r.some(w=>w.status==="untracked"),G=H&&v&&r.length>0,K=N?r.every(w=>N.has(w.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:c},children:[e.jsx("span",{className:"git-status-badge",style:{background:c},children:l}),n," (",r.length,")",G&&e.jsx("button",{className:`git-stage-all-btn ${K?"staging":""}`,onClick:w=>{w.stopPropagation(),K||v()},title:D("terminal:fileExplorer.stageAllUntracked"),disabled:K,children:K?"...":D("terminal:fileExplorer.stageAll")}),C&&e.jsxs("button",{className:"git-discard-all-btn",onClick:w=>{w.stopPropagation(),C()},title:H?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),h==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(w=>e.jsx(fr,{node:w,depth:0,expandedDirs:d,onToggleDir:g,selectedPath:o,onSelect:b,onStage:p,stagingPaths:N,checkedFiles:F,onToggleCheck:y,onContextMenu:k,onDirContextMenu:f,onDiscard:j},w.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(w=>e.jsx(hr,{file:w,isSelected:o===w.path,onSelect:b,onStage:w.status==="untracked"?p:void 0,isStaging:N==null?void 0:N.has(w.path),showDirPath:!0,isChecked:F==null?void 0:F.has(w.path),onToggleCheck:y,onContextMenu:k,onDiscard:j},w.path))})]})});function gr({gitStatus:t,loading:n,onFileSelect:l,selectedPath:c,onRefresh:r,onStageFiles:i,stagingPaths:h,currentFolder:o,onCommitComplete:d,mergeInProgress:g,mergingBranch:b,onMergeContinue:p,onMergeAbort:v,onConflictOpen:N,onRevealInTree:F}){const{t:y}=ie(["terminal","common"]),[k,f]=s.useState("tree"),[j,C]=s.useState(new Set),[D,H]=s.useState(""),[G,K]=s.useState(""),[w,re]=s.useState(!1),[_,R]=s.useState(new Set),[P,X]=s.useState(!1),[Q,ne]=s.useState(null),ue=s.useRef(null),{showToast:U}=an(),[se,I]=s.useState(null),[B,Z]=s.useState(null),[L,we]=s.useState(null),ee=s.useCallback((E,$)=>{we({files:[E],label:E.name})},[]),m=s.useCallback(async()=>{if(!(!L||!o))try{const E=await V(A("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.files.map(O=>({path:O.path,status:O.status})),directory:o})}),$=await E.json();E.ok&&$.success?(U("success","Discarded",`Reverted ${L.files.length} file(s)`),r()):U("error","Discard Failed",$.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}finally{we(null)}},[L,o,r,U]),Y=s.useCallback((E,$,O)=>{E.preventDefault(),E.stopPropagation(),I({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:$,status:O})},[]),le=s.useCallback(async(E,$)=>{if(o)try{const O=await V(A("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:$}],directory:o})}),Ee=await O.json();O.ok&&Ee.success?(U("success","Discarded",`Restored ${E.name}`),r()):U("error","Discard Failed",Ee.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}},[o,r,U]),me=s.useCallback(async E=>{try{await navigator.clipboard.writeText(E),U("success","Copied","Full path copied")}catch{U("error","Copy Failed","Could not copy path")}},[U]),T=s.useCallback(async E=>{const $=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText($),U("success","Copied","Relative path copied")}catch{U("error","Copy Failed","Could not copy path")}},[o,U]),S=s.useMemo(()=>{if(!se)return[];const{file:E,status:$}=se,O=[];return $==="conflict"&&N?O.push({id:"open-conflict",label:y("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>N(E.path)}):$!=="deleted"&&O.push({id:"open-file",label:y("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>l(E.path,$)}),$!=="conflict"&&O.push({id:"stage-file",label:y("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([E.path])}}),O.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),($==="modified"||$==="deleted"||$==="renamed"||$==="conflict")&&O.push({id:"discard-changes",label:y("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{le(E,$)}}),($==="untracked"||$==="added")&&O.push({id:"delete-file",label:y("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{le(E,$)}}),O.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),O.push({id:"copy-full-path",label:y("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{me(E.path)}}),O.push({id:"copy-relative-path",label:y("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{T(E.path)}}),F&&$!=="deleted"&&O.push({id:"reveal-in-tree",label:y("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>F(E.path)}),O},[se,l,i,N,F,le,me,T,y]),te=s.useCallback((E,$)=>{E.preventDefault(),E.stopPropagation(),Z({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:$})},[]),ae=s.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap($=>ae($)),[]),pe=s.useCallback(async E=>{if(!o)return;const $=ae(E);if($.length!==0)try{const O=await V(A("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:$.map(Se=>({path:Se.path,status:Se.status})),directory:o})}),Ee=await O.json();O.ok&&Ee.success?(U("success","Discarded",`Reverted ${$.length} file(s) in ${E.name}`),r()):U("error","Discard Failed",Ee.error||"Could not discard changes")}catch{U("error","Discard Failed","Network error")}},[o,ae,r,U]),oe=s.useMemo(()=>{if(!B)return[];const{node:E}=B,$=ae(E);return[{id:"discard-dir",label:`Discard Changes (${$.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{pe(E)}},{id:"stage-dir",label:`Stage All (${$.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i($.map(O=>O.path))}}]},[B,ae,pe,i]),W=s.useCallback(E=>{C($=>{const O=new Set($);return O.has(E)?O.delete(E):O.add(E),O})},[]),{conflictFiles:ye,conflictTree:Ge,changesFiles:_e,changesTree:vt,untrackedFiles:He,untrackedTree:Gt,allDirPaths:dt}=s.useMemo(()=>{if(!t||!t.isGitRepo||t.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const E=new Set,$=t.files.filter(De=>De.status==="conflict"),O=Ht($);At(O,E);const Ee=t.files.filter(De=>De.status==="modified"||De.status==="added"||De.status==="deleted"||De.status==="renamed"),Se=Ht(Ee);At(Se,E);const Ct=t.files.filter(De=>De.status==="untracked"),qe=Ht(Ct);return At(qe,E),{conflictFiles:$,conflictTree:O,changesFiles:Ee,changesTree:Se,untrackedFiles:Ct,untrackedTree:qe,allDirPaths:E}},[t]);s.useEffect(()=>{C(dt)},[dt]),s.useEffect(()=>{t!=null&&t.files&&R(new Set(t.files.map(E=>E.path)))},[t==null?void 0:t.files]);const We=s.useCallback(()=>{_e.length!==0&&we({files:_e,label:`${_e.length} changed files`})},[_e]),ut=s.useCallback(()=>{He.length!==0&&we({files:He,label:`${He.length} unversioned files`})},[He]),wt=s.useCallback(()=>{ye.length!==0&&we({files:ye,label:`${ye.length} conflicted files`})},[ye]),ht=ye.length>0;s.useEffect(()=>{if(Q){const E=Q.type==="error"?8e3:4e3,$=setTimeout(()=>ne(null),E);return()=>clearTimeout($)}},[Q]);const _t=s.useCallback(async()=>{const E=!w;if(re(E),E&&o){K(D);try{const O=await(await V(A(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();O.message&&H(O.message)}catch{}}else H(G)},[w,o,D,G]),Je=s.useCallback(E=>{R($=>{const O=new Set($);return O.has(E)?O.delete(E):O.add(E),O})},[]),Ce=s.useCallback(()=>{if(!(t!=null&&t.files))return;const E=t.files.map(O=>O.path),$=E.every(O=>_.has(O));R($?new Set:new Set(E))},[t==null?void 0:t.files,_]),ce=s.useCallback(async E=>{if(!(!o||!D.trim()||_.size===0||P)){X(!0),ne(null);try{const $=await V(A("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:D.trim(),amend:w,paths:Array.from(_)})}),O=await $.json();if(!$.ok||!O.success){ne({type:"error",text:O.error||"Commit failed"}),X(!1);return}if(E)try{const Ee=await V(A("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),Se=await Ee.json();Ee.ok&&Se.success?ne({type:"success",text:y("terminal:fileExplorer.committedAndPushed")}):ne({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:Se.error||"Unknown error"})})}catch{ne({type:"error",text:y("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else ne({type:"success",text:y("terminal:fileExplorer.committedSuccessfully")});H(""),K(""),re(!1),r(),d==null||d()}catch($){ne({type:"error",text:$.message||"Commit failed"})}finally{X(!1)}}},[o,D,w,_,P,r,d]);if(n)return e.jsx("div",{className:"git-changes-loading",children:y("terminal:fileExplorer.loadingGitStatus")});if(!t||!t.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.notGitRepo")})]});if(t.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"sparkle",size:32})}),e.jsx("div",{className:"git-empty-text",children:y("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:y("terminal:fileExplorer.onBranch",{branch:t.branch})})]});const Ne=E=>{i([E])},ke=()=>{const E=He.map($=>$.path);E.length>0&&i(E)},Ae=(E,$)=>{$==="conflict"&&N?N(E):l(E,$)};return e.jsxs("div",{className:"git-changes",children:[e.jsxs("div",{className:"git-changes-header",children:[e.jsxs("span",{className:"git-branch",children:[e.jsx("span",{className:"git-branch-icon",children:e.jsx(M,{name:"git-branch",size:12})}),t.branch]}),t.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(t.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[t.counts.conflict,"C"]}),t.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[t.counts.modified,"M"]}),t.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[t.counts.added,"A"]}),t.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[t.counts.deleted,"D"]}),t.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[t.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${k==="flat"?"active":""}`,onClick:()=>f("flat"),title:y("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${k==="tree"?"active":""}`,onClick:()=>f("tree"),title:y("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"git-refresh-btn",onClick:r,title:y("common:buttons.refresh"),children:e.jsx(M,{name:"refresh",size:12})})]}),g&&e.jsxs("div",{className:"git-merge-banner",children:[e.jsx("span",{className:"git-merge-banner-icon",children:"⚠"}),e.jsx("span",{className:"git-merge-banner-text",children:y("terminal:fileExplorer.mergeInProgress",{branch:b?` (${b})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:p,disabled:ht,title:y(ht?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:y("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:v,title:y("terminal:fileExplorer.abortMerge"),children:y("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(ns,{groupLabel:y("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:ye,treeNodes:Ge,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:W,onFileSelect:Ae,checkedFiles:_,onToggleCheck:Je,onContextMenu:Y,onDirContextMenu:te,onDiscardFile:ee,onDiscardAll:wt}),e.jsx(ns,{groupLabel:y("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:_e,treeNodes:vt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:W,onFileSelect:Ae,checkedFiles:_,onToggleCheck:Je,onContextMenu:Y,onDirContextMenu:te,onDiscardFile:ee,onDiscardAll:We}),e.jsx(ns,{groupLabel:y("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:He,treeNodes:Gt,viewMode:k,selectedPath:c,expandedDirs:j,onToggleDir:W,onFileSelect:Ae,onStageFile:Ne,onStageAll:ke,stagingPaths:h,checkedFiles:_,onToggleCheck:Je,onContextMenu:Y,onDirContextMenu:te,onDiscardFile:ee,onDiscardAll:ut})]}),e.jsxs("div",{className:"git-commit-panel",children:[e.jsxs("div",{className:"git-commit-options",children:[e.jsxs("label",{className:"git-commit-amend-label",children:[e.jsx("input",{type:"checkbox",className:"git-commit-amend-checkbox",checked:w,onChange:_t}),y("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:y("terminal:fileExplorer.fileCount",{count:_.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:Ce,title:_.size===t.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll"),children:_.size===t.files.length?y("terminal:fileExplorer.deselectAll"):y("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:ue,className:"git-commit-message",placeholder:y("terminal:fileExplorer.commitMessagePlaceholder"),value:D,onChange:E=>H(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),ce(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),ce(!0)),E.stopPropagation()},rows:3,disabled:P}),Q&&e.jsx("div",{className:`git-commit-status ${Q.type}`,children:Q.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>ce(!1),disabled:!D.trim()||_.size===0||P,title:y("terminal:fileExplorer.commitCtrlEnter"),children:y(P?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>ce(!0),disabled:!D.trim()||_.size===0||P,title:y("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:P?"...":y("terminal:fileExplorer.commitAndPush")})]})]}),se&&e.jsx(lt,{isOpen:se.isOpen,position:se.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>I(null)}),B&&e.jsx(lt,{isOpen:B.isOpen,position:B.position,worldPosition:{x:0,z:0},actions:oe,onClose:()=>Z(null)}),L&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>we(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:L.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:L.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:L.label}),"?"]})}),e.jsx("p",{className:"git-discard-confirm-hint",children:"This cannot be undone."}),e.jsxs("div",{className:"git-discard-confirm-actions",children:[e.jsx("button",{className:"git-discard-confirm-cancel",onClick:()=>we(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:L.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const un=s.memo(gr,(t,n)=>t.loading!==n.loading||t.selectedPath!==n.selectedPath||t.stagingPaths!==n.stagingPaths||t.currentFolder!==n.currentFolder||t.mergeInProgress!==n.mergeInProgress||t.mergingBranch!==n.mergingBranch?!1:t.gitStatus===null&&n.gitStatus===null?!0:!(t.gitStatus===null||n.gitStatus===null||t.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||t.gitStatus.branch!==n.gitStatus.branch||t.gitStatus.files.length!==n.gitStatus.files.length||t.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));un.displayName="GitChanges";const xr=s.memo(function({tab:n,isActive:l,onSelect:c,onClose:r,onContextMenu:i}){const{t:h}=ie(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},d=s.useCallback(()=>{c(n.path)},[c,n.path]),g=s.useCallback(v=>{v.button===1&&(v.preventDefault(),v.stopPropagation(),r(n.path))},[r,n.path]),b=s.useCallback(v=>{v.preventDefault(),v.stopPropagation(),r(n.path)},[r,n.path]),p=s.useCallback(v=>{v.preventDefault(),v.stopPropagation(),i(v,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:d,onMouseDown:g,onContextMenu:p,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:is(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:b,title:h("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function yr(t){return typeof t.path=="string"&&t.path.startsWith("/")}function br({tabs:t,activeTabPath:n,onSelectTab:l,onCloseTab:c,onCloseAllTabs:r,onShowGitHistory:i}){const{t:h}=ie(["terminal"]),[o,d]=s.useState(null),g=s.useCallback((v,N)=>{d({isOpen:!0,position:{x:v.clientX,y:v.clientY},tab:N})},[]),b=s.useCallback(()=>d(null),[]),p=s.useMemo(()=>{if(!o)return[];const v=o.tab,N=!!i&&yr(v),F=[{id:"git-history",label:h("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!N,onClick:()=>{N&&i(v.path)}}];return r&&F.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:h("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),F},[o,i,r,h]);return t.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:t.map(v=>e.jsx(xr,{tab:v,isActive:n===v.path,onSelect:l,onClose:c,onContextMenu:g},v.path))}),o&&e.jsx(lt,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:p,onClose:b})]})}const hn=s.memo(br,(t,n)=>{if(t.activeTabPath!==n.activeTabPath||t.tabs.length!==n.tabs.length||t.onShowGitHistory!==n.onShowGitHistory||t.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let l=0;l<t.tabs.length;l++)if(t.tabs[l].path!==n.tabs[l].path)return!1;return!0});hn.displayName="FileTabs";const jr=s.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:c,onMerge:r,onCompare:i,onPullConflicts:h}){const{t:o}=ie(["terminal","common"]),[d,g]=s.useState(!1),[b,p]=s.useState(""),[v,N]=s.useState(!1),[F,y]=s.useState(""),[k,f]=s.useState(!1),[j,C]=s.useState(null),[D,H]=s.useState(null),G=s.useRef(null),K=s.useRef(null),w=s.useRef(null),{branches:re,loading:_,operationInProgress:R,loadBranches:P,checkoutBranch:X,createBranch:Q,pullFromRemote:ne,pushToRemote:ue}=ls();s.useEffect(()=>{d&&n&&(P(n),setTimeout(()=>{var S;return(S=K.current)==null?void 0:S.focus()},50)),d||(p(""),N(!1),y(""),C(null))},[d,n,P]),s.useEffect(()=>{if(j){const S=j.type==="error"?8e3:3e3,te=setTimeout(()=>C(null),S);return()=>clearTimeout(te)}},[j]),s.useEffect(()=>{v&&setTimeout(()=>{var S;return(S=w.current)==null?void 0:S.focus()},50)},[v]),s.useEffect(()=>{if(!d)return;const S=ae=>{const pe=ae.target;!pe.closest(".branch-widget-selector")&&!pe.closest(".branch-widget-dropdown")&&g(!1)},te=ae=>{ae.key==="Escape"&&(ae.preventDefault(),ae.stopPropagation(),g(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",te,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",te,!0)}},[d]);const U=s.useCallback(async S=>{if(!n||R||S.isCurrent)return;const te=await X(n,S.name);te.success?(C({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:te.branch||S.name})}),c(),P(n)):C({type:"error",text:te.error||o("terminal:fileExplorer.checkoutFailed")})},[n,R,X,c,P]),se=s.useCallback(async()=>{if(!n||!F.trim()||R)return;const S=await Q(n,F.trim());S.success?(C({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),N(!1),y(""),c(),P(n)):C({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,F,R,Q,c,P]),I=s.useCallback(async()=>{if(!n||R)return;const S=await ne(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(C({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),h==null||h(S.stashConflicts),g(!1)):S.stashed?C({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):C({type:"success",text:o("terminal:fileExplorer.pullComplete")}),c(),P(n)):S.conflicts&&S.conflicts.length>0?(C({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),h==null||h(S.conflicts),g(!1)):C({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,R,ne,c,P,h]),B=s.useCallback(async()=>{if(!n||R)return;const S=await ue(n);S.success?C({type:"success",text:o("terminal:fileExplorer.pushComplete")}):C({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,R,ue]),[Z,L]=s.useState(!1),we=s.useCallback(async()=>{if(!(!n||R||Z)){L(!0);try{const S=await V(A("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)C({type:"success",text:"Fetch complete"}),c(),P(n);else{const te=await S.json().catch(()=>({error:"Fetch failed"}));C({type:"error",text:te.error||"Fetch failed"})}}catch{C({type:"error",text:"Fetch failed"})}finally{L(!1)}}},[n,R,Z,c,P]),ee=(l==null?void 0:l.branch)||"unknown",m=!!R,Y=s.useCallback((S,te)=>{te.isCurrent||(S.preventDefault(),S.stopPropagation(),H({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:te.name}))},[]),le=s.useMemo(()=>{if(!D)return[];const S=!!R||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:D.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!R,onClick:()=>{i==null||i(D.branch),g(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:D.branch,target:ee}),icon:"⤵",disabled:!!S,onClick:()=>{r&&r(D.branch),g(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:D.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!R,onClick:()=>{const te=re.find(ae=>ae.name===D.branch);te&&U(te)}}]},[D,R,l==null?void 0:l.mergeInProgress,ee,r,i,re,U]),me=s.useMemo(()=>{const S=re.filter(ae=>!ae.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(ae=>ae.name.toLowerCase().includes(te))},[re,b]),T=s.useMemo(()=>{const S=re.filter(ae=>ae.isRemote);if(!b)return S;const te=b.toLowerCase();return S.filter(ae=>ae.name.toLowerCase().includes(te))},[re,b]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),g(!d)},title:`Branch: ${ee}`,children:[e.jsx("svg",{className:"branch-widget-icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M5 3.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Zm0 2.122a2.25 2.25 0 1 0-1 0v1.836A2.25 2.25 0 0 0 5.75 9.5h1.378a2.251 2.251 0 1 0 0-1H5.75a1.25 1.25 0 0 1-1.25-1.25V5.372Zm7.75 4.878a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3-8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"})}),e.jsx("span",{className:"branch-widget-name",children:ee}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),d&&e.jsxs("div",{className:"branch-widget-dropdown",ref:G,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:K,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:b,onChange:S=>p(S.target.value),onKeyDown:S=>S.stopPropagation()})}),j&&e.jsx("div",{className:`branch-widget-status ${j.type}`,children:j.text}),e.jsx("div",{className:"branch-widget-section-header",children:o("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${m||Z?"disabled":""}`,onClick:we,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 13l-3-3h2V6h2v4h2l-3 3zM8 3l3 3h-2v4H7V6H5l3-3z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:Z?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:I,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 12l-4-4h2.5V3h3v5H12L8 12z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(R==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:B,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(R==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||N(!v)},children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 2v5H3v2h5v5h2V9h5V7H10V2H8z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o("terminal:fileExplorer.newBranch")})]})]}),v&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:w,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:F,onChange:S=>y(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&se(),S.key==="Escape"&&(N(!1),y(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:se,disabled:!F.trim()||m,children:R==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),_&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[me.length===0&&!_&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),me.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>U(S),onContextMenu:te=>Y(te,S),title:S.lastMessage||S.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[S.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),S.name]}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))]}),T.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>f(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:T.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:T.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>U(S),onContextMenu:te=>Y(te,S),title:S.lastMessage||S.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:S.name}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))})]})]}),D&&e.jsx(lt,{isOpen:D.isOpen,position:D.position,worldPosition:{x:0,z:0},actions:le,onClose:()=>H(null)})]})});function vr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function $t(t,n){if(!t)return"";const l=Us.languages[n];return l?Us.highlight(t,l,n):vr(t)}function wr(t){const n=[],l=t.split(`
|
|
9
|
-
`);let c=[],r=!1,i=[],h=[],o=!1;for(const d of l)d.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
|
|
10
|
-
`)}),c=[]),r=!0,o=!1,i=[],h=[]):d.startsWith("=======")&&r?o=!0:d.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
|
|
11
|
-
`),theirs:h.join(`
|
|
12
|
-
`),resolved:null}),r=!1,o=!1):r?o?h.push(d):i.push(d):c.push(d);return c.length>0&&n.push({type:"unchanged",content:c.join(`
|
|
13
|
-
`)}),n}const Cr=s.memo(function({file:n,versions:l,loading:c,onResolve:r,onClose:i,currentBranch:h,mergingBranch:o}){const{t:d}=ie(["terminal"]),g=s.useMemo(()=>{var P;if(!(l!=null&&l.filename))return"plaintext";const R="."+((P=l.filename.split(".").pop())==null?void 0:P.toLowerCase());return Ut(R)},[l==null?void 0:l.filename]),b=s.useMemo(()=>l!=null&&l.merged?wr(l.merged):[],[l==null?void 0:l.merged]),[p,v]=s.useState(b),[N,F]=s.useState(!1);s.useMemo(()=>{v(b)},[b]);const y=s.useRef(null),[k,f]=s.useState(0),j=s.useMemo(()=>p.map((R,P)=>R.type==="conflict"?P:-1).filter(R=>R!==-1),[p]),C=j.length,D=s.useCallback(R=>{const P=y.current;if(!P||R<0||R>=j.length)return;const X=j[R],Q=P.querySelector(`[data-section-idx="${X}"]`);Q&&(Q.scrollIntoView({behavior:"smooth",block:"center"}),f(R))},[j]),H=s.useCallback(()=>{D(k>0?k-1:j.length-1)},[k,j.length,D]),G=s.useCallback(()=>{D(k<j.length-1?k+1:0)},[k,j.length,D]);s.useEffect(()=>{if(j.length>0&&y.current){const R=setTimeout(()=>D(0),100);return()=>clearTimeout(R)}},[j.length,D]);const K=s.useMemo(()=>{const R=p.filter(P=>P.type==="conflict");return R.length>0&&R.every(P=>P.resolved!==null)},[p]),w=s.useCallback((R,P)=>{v(X=>X.map((Q,ne)=>ne!==R||Q.type!=="conflict"?Q:{...Q,resolved:P}))},[]),re=s.useCallback(R=>{v(P=>P.map(X=>X.type!=="conflict"?X:{...X,resolved:R}))},[]),_=s.useCallback(async()=>{F(!0);try{const R=p.map(P=>P.type==="unchanged"?P.content:P.resolved==="ours"?P.ours:P.resolved==="theirs"?P.theirs:P.resolved==="both"?P.ours+`
|
|
14
|
-
`+P.theirs:`<<<<<<< ${h}
|
|
15
|
-
${P.ours}
|
|
16
|
-
=======
|
|
17
|
-
${P.theirs}
|
|
18
|
-
>>>>>>> ${o}`).join(`
|
|
19
|
-
`);await r(R)}finally{F(!1)}},[p,r,h,o]);return e.jsxs("div",{className:"conflict-resolver",children:[e.jsxs("div",{className:"conflict-header",children:[e.jsx("span",{className:"conflict-header-title",children:d("terminal:fileExplorer.resolveFile",{filename:l==null?void 0:l.filename})}),C>0&&e.jsxs("div",{className:"conflict-nav",children:[e.jsx("button",{className:"conflict-nav-btn",onClick:H,title:d("terminal:fileExplorer.prevConflict"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsxs("span",{className:"conflict-nav-counter",children:[k+1," / ",C]}),e.jsx("button",{className:"conflict-nav-btn",onClick:G,title:d("terminal:fileExplorer.nextConflict"),children:e.jsx(M,{name:"caret-down",size:10})})]}),e.jsx("button",{className:"conflict-close-btn",onClick:i,children:"×"})]}),c||!l?e.jsx("div",{className:"conflict-loading",children:d("terminal:fileExplorer.loadingConflictData")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"conflict-pane-headers",children:[e.jsx("div",{className:"conflict-pane-header current",children:d("terminal:fileExplorer.currentBranchLabel",{branch:h})}),e.jsx("div",{className:"conflict-pane-header incoming",children:d("terminal:fileExplorer.incomingBranchLabel",{branch:o})})]}),e.jsx("div",{className:"conflict-content",ref:y,children:p.map((R,P)=>R.type==="unchanged"?e.jsx("div",{className:"conflict-section-unchanged",children:e.jsxs("div",{className:"conflict-panes",children:[e.jsx("div",{className:"conflict-pane ours",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:$t(R.content,g)}})}),e.jsx("div",{className:"conflict-pane theirs",children:e.jsx("pre",{dangerouslySetInnerHTML:{__html:$t(R.content,g)}})})]})},P):e.jsxs("div",{"data-section-idx":P,className:`conflict-section-conflict ${R.resolved?"resolved":""}`,children:[e.jsxs("div",{className:"conflict-panes",children:[e.jsxs("div",{className:`conflict-pane ours ${R.resolved==="ours"||R.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:$t(R.ours,g)}}),e.jsx("button",{className:"conflict-accept-btn ours",onClick:()=>w(P,"ours"),disabled:R.resolved==="ours",children:R.resolved==="ours"?d("terminal:fileExplorer.accepted"):d("terminal:fileExplorer.acceptCurrent")})]}),e.jsxs("div",{className:`conflict-pane theirs ${R.resolved==="theirs"||R.resolved==="both"?"accepted":""}`,children:[e.jsx("pre",{dangerouslySetInnerHTML:{__html:$t(R.theirs,g)}}),e.jsx("button",{className:"conflict-accept-btn theirs",onClick:()=>w(P,"theirs"),disabled:R.resolved==="theirs",children:R.resolved==="theirs"?d("terminal:fileExplorer.accepted"):d("terminal:fileExplorer.acceptIncoming")})]})]}),e.jsx("button",{className:`conflict-accept-both-btn ${R.resolved==="both"?"accepted":""}`,onClick:()=>w(P,"both"),disabled:R.resolved==="both",children:R.resolved==="both"?d("terminal:fileExplorer.accepted"):d("terminal:fileExplorer.acceptBoth")})]},P))}),e.jsxs("div",{className:"conflict-actions",children:[e.jsx("button",{className:"conflict-action-btn accept-all-current",onClick:()=>re("ours"),children:d("terminal:fileExplorer.acceptAllCurrent")}),e.jsx("button",{className:"conflict-action-btn accept-all-incoming",onClick:()=>re("theirs"),children:d("terminal:fileExplorer.acceptAllIncoming")}),e.jsx("button",{className:"conflict-action-btn accept-all-both",onClick:()=>re("both"),children:d("terminal:fileExplorer.acceptAllBoth")}),e.jsx("button",{className:"conflict-action-btn save-resolved",onClick:_,disabled:!K||N,children:d(N?"terminal:fileExplorer.saving":"terminal:fileExplorer.saveAndResolve")})]})]})]})}),Nr=16,kr=s.memo(function t({node:n,depth:l,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h}){const{t:o}=ie(["terminal"]),d=l*Nr;if(!n.isDirectory){const b=n.file.status,p=jt[b],v=b==="deleted",N=n.file.name.includes(".")?"."+n.file.name.split(".").pop():"";return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>!v&&h(n.file.path,b),style:{paddingLeft:`${d+4}px`,cursor:v?"not-allowed":"pointer"},title:n.file.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:bt(N),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:p.color},children:p.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.file.oldPath.split("/").pop()]})]})}const g=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${g?"expanded":""}`,style:{paddingLeft:`${d+4}px`},onClick:()=>r(n.path),children:[e.jsx("span",{className:`tree-arrow ${g?"expanded":""}`,children:"►"}),e.jsx("img",{className:"tree-folder-icon",src:g?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:o("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),g&&e.jsx("div",{className:"tree-children",children:n.children.map(b=>e.jsx(t,{node:b,depth:l+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h},b.path))})]})}),Er=s.memo(function({file:n,isSelected:l,onSelect:c}){const r=jt[n.status],i=n.status==="deleted",h=n.name.includes(".")?"."+n.name.split(".").pop():"",o=n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!i&&c(n.path,n.status),style:{cursor:i?"not-allowed":"pointer"},title:n.path,children:[e.jsx("span",{className:"tree-arrow-spacer"}),e.jsx("img",{className:"tree-icon",src:bt(h),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,o&&e.jsx("span",{className:"git-file-dir",children:o})]}),e.jsx("span",{className:"git-file-status",style:{color:r.color},children:r.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:["← ",n.oldPath.split("/").pop()]})]})});function Sr({compareResult:t,loading:n,onFileSelect:l,selectedPath:c,onClose:r}){const{t:i}=ie(["terminal"]),[h,o]=s.useState("tree"),[d,g]=s.useState(new Set),b=s.useMemo(()=>!t||t.files.length===0?[]:Ht(t.files),[t]),p=s.useMemo(()=>{const C=new Set;return At(b,C),C},[b]);s.useEffect(()=>{g(p)},[p]);const v=s.useCallback(C=>{g(D=>{const H=new Set(D);return H.has(C)?H.delete(C):H.add(C),H})},[]),N=s.useMemo(()=>t?[...t.files].sort((C,D)=>C.path.toLowerCase().localeCompare(D.path.toLowerCase())):[],[t]);if(n)return e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsx("span",{className:"branch-comparison-title",children:i("terminal:fileExplorer.comparingBranches")}),e.jsx("button",{className:"branch-comparison-close",onClick:r,title:i("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-empty",children:e.jsx("div",{className:"branch-comparison-empty-text",children:i("terminal:fileExplorer.comparingBranches")})})]});if(!t)return null;const{files:F,counts:y,baseBranch:k,currentBranch:f}=t,j=F.length;return j===0?e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:[f," vs ",k]}),e.jsx("button",{className:"branch-comparison-close",onClick:r,title:i("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsxs("div",{className:"branch-comparison-empty",children:[e.jsx("div",{className:"branch-comparison-empty-icon",children:"✨"}),e.jsx("div",{className:"branch-comparison-empty-text",children:i("terminal:fileExplorer.noDifferences")})]})]}):e.jsxs("div",{className:"branch-comparison",children:[e.jsxs("div",{className:"branch-comparison-header",children:[e.jsxs("span",{className:"branch-comparison-title",children:["⇔ ",f," vs ",k]}),e.jsx("span",{className:"branch-comparison-file-count",children:i("terminal:fileExplorer.fileCount",{count:j})}),e.jsxs("div",{className:"git-changes-summary",children:[y.modified>0&&e.jsxs("span",{className:"git-count modified",children:[y.modified,"M"]}),y.added>0&&e.jsxs("span",{className:"git-count added",children:[y.added,"A"]}),y.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[y.deleted,"D"]}),y.renamed>0&&e.jsxs("span",{className:"git-count renamed",children:[y.renamed,"R"]}),(y.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[y.conflict,"C"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${h==="flat"?"active":""}`,onClick:()=>o("flat"),title:i("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${h==="tree"?"active":""}`,onClick:()=>o("tree"),title:i("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"branch-comparison-close",onClick:r,title:i("terminal:fileExplorer.closeComparison"),children:"×"})]}),e.jsx("div",{className:"branch-comparison-list",children:h==="tree"?b.map(C=>e.jsx(kr,{node:C,depth:0,expandedDirs:d,onToggleDir:v,selectedPath:c,onSelect:l},C.path)):N.map(C=>e.jsx(Er,{file:C,isSelected:c===C.path,onSelect:l},C.path))})]})}const mn=s.memo(Sr);mn.displayName="BranchComparison";function Tr(t){const n=new Date(t);if(isNaN(n.getTime()))return t||"—";const c=Date.now()-n.getTime(),r=Math.floor(c/6e4),i=Math.floor(r/60),h=Math.floor(i/24);if(h<4)return r<1?"just now":r<60?`${r}m ago`:i<24?`${i}h ago`:`${h}d ago`;const o=n.getFullYear(),d=String(n.getMonth()+1).padStart(2,"0"),g=String(n.getDate()).padStart(2,"0"),b=String(n.getHours()).padStart(2,"0"),p=String(n.getMinutes()).padStart(2,"0");return`${o}-${d}-${g} ${b}:${p}`}const Dr=s.memo(function({commit:n,isSelected:l,onSelect:c}){return e.jsxs("div",{className:`gh-row ${l?"selected":""}`,onClick:()=>c(n),children:[e.jsx("span",{className:"gh-col-hash",children:n.shortHash}),e.jsxs("span",{className:"gh-col-message",children:[e.jsx("span",{className:"gh-subject",children:n.subject}),n.refs.isHead&&e.jsx("span",{className:"gh-badge gh-badge-head",children:"HEAD"}),n.refs.branches.map(r=>e.jsx("span",{className:"gh-badge gh-badge-branch",children:r},r)),n.refs.tags.map(r=>e.jsx("span",{className:"gh-badge gh-badge-tag",children:r},r))]}),e.jsx("span",{className:"gh-col-author",children:n.author}),e.jsx("span",{className:"gh-col-date",children:Tr(n.date)})]})}),Mr=s.memo(function({files:n,loading:l,selectedFilePath:c,onSelectFile:r}){const{t:i}=ie(["common"]);return l?e.jsx("div",{className:"gh-files-loading",children:i("common:status.loading")}):n.length===0?e.jsx("div",{className:"gh-files-empty",children:"No changed files"}):e.jsx("div",{className:"gh-files-list",children:n.map(h=>{const o=h.path.split("/").pop()||h.path,d=h.path.includes("/")?h.path.substring(0,h.path.lastIndexOf("/")):"",g=jt[h.status],b=o.includes(".")?"."+o.split(".").pop():"";return e.jsxs("div",{className:`gh-file-row ${c===h.path?"selected":""}`,onClick:()=>r==null?void 0:r(h.path),title:h.path,children:[e.jsx("span",{className:"gh-file-status",style:{color:g.color},children:g.icon}),e.jsx("img",{className:"gh-file-icon",src:bt(b),alt:""}),e.jsx("span",{className:"gh-file-name",children:o}),d&&e.jsx("span",{className:"gh-file-dir",children:d})]},h.path)})})}),Rr=s.memo(function({history:n,currentFolder:l,onFileSelect:c}){const{t:r}=ie(["terminal","common"]),i=s.useRef(null),[h,o]=s.useState(null),[d,g]=s.useState(!1),{commits:b,loading:p,loadingMore:v,error:N,hasMore:F,total:y,filters:k,setFilter:f,resetFilters:j,selectedCommit:C,selectCommit:D,commitFiles:H,commitFilesLoading:G,loadHistory:K,loadMore:w,authors:re,loadAuthors:_}=n,{branches:R,loadBranches:P}=ls();s.useEffect(()=>{l&&(K(l),_(l),P(l))},[l,K,_,P]);const X=sa({count:b.length,getScrollElement:()=>i.current,estimateSize:()=>28,overscan:20}),Q=s.useCallback(()=>{const I=i.current;if(!I||v||!F||!l)return;const{scrollTop:B,scrollHeight:Z,clientHeight:L}=I;Z-B-L<200&&w(l)},[v,F,l,w]),ne=s.useCallback(I=>{o(I),c&&C&&c(I,C.hash)},[c,C]),ue=s.useMemo(()=>R.filter(I=>!I.isRemote).map(I=>I.name),[R]),U=!!(k.branch||k.author||k.since||k.until||k.searchPath||k.search),se=X.getVirtualItems();return e.jsxs("div",{className:"gh-panel",children:[e.jsxs("div",{className:"gh-toolbar",children:[e.jsx("span",{className:"gh-toolbar-title",children:r("terminal:fileExplorer.gitHistory.title")}),e.jsx("span",{className:"gh-toolbar-count",children:p?"...":y>0?y:b.length}),e.jsx("input",{type:"text",className:"gh-search-input",placeholder:r("terminal:fileExplorer.gitHistory.searchPlaceholder"),value:k.search,onChange:I=>f("search",I.target.value)}),e.jsx("button",{className:`gh-filter-toggle ${d?"active":""} ${U?"has-filters":""}`,onClick:()=>g(!d),title:"Filters",children:e.jsx(M,{name:"gear",size:12})}),U&&e.jsx("button",{className:"gh-reset-btn",onClick:j,children:r("terminal:fileExplorer.gitHistory.resetFilters")})]}),d&&e.jsxs("div",{className:"gh-filters-row",children:[e.jsxs("select",{className:"gh-filter-select",value:k.branch,onChange:I=>f("branch",I.target.value),children:[e.jsx("option",{value:"",children:r("terminal:fileExplorer.gitHistory.allBranches")}),ue.map(I=>e.jsx("option",{value:I,children:I},I))]}),e.jsxs("select",{className:"gh-filter-select",value:k.author,onChange:I=>f("author",I.target.value),children:[e.jsx("option",{value:"",children:r("terminal:fileExplorer.gitHistory.allAuthors")}),re.map(I=>e.jsx("option",{value:I,children:I},I))]}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.since,onChange:I=>f("since",I.target.value),title:r("terminal:fileExplorer.gitHistory.since")}),e.jsx("input",{type:"date",className:"gh-filter-input gh-date-input",value:k.until,onChange:I=>f("until",I.target.value),title:r("terminal:fileExplorer.gitHistory.until")}),e.jsx("input",{type:"text",className:"gh-filter-input",placeholder:r("terminal:fileExplorer.gitHistory.pathFilter"),value:k.searchPath,onChange:I=>f("searchPath",I.target.value)})]}),e.jsxs("div",{className:"gh-body",children:[e.jsxs("div",{className:"gh-commits-section",children:[e.jsxs("div",{className:"gh-header-row",children:[e.jsx("span",{className:"gh-col-hash",children:"Hash"}),e.jsx("span",{className:"gh-col-message",children:"Message"}),e.jsx("span",{className:"gh-col-author",children:"Author"}),e.jsx("span",{className:"gh-col-date",children:"Date"})]}),p&&b.length===0?e.jsx("div",{className:"gh-state-msg",children:r("common:status.loading")}):N?e.jsx("div",{className:"gh-state-msg gh-error",children:N}):b.length===0?e.jsx("div",{className:"gh-state-msg",children:r("terminal:fileExplorer.gitHistory.noCommits")}):e.jsxs("div",{className:"gh-commit-scroll",ref:i,onScroll:Q,children:[e.jsx("div",{style:{height:`${X.getTotalSize()}px`,width:"100%",position:"relative"},children:se.map(I=>e.jsx("div",{"data-index":I.index,ref:X.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${I.start}px)`},children:e.jsx(Dr,{commit:b[I.index],isSelected:(C==null?void 0:C.hash)===b[I.index].hash,onSelect:D})},I.key))}),v&&e.jsx("div",{className:"gh-loading-more",children:r("common:status.loading")})]})]}),C&&e.jsxs("div",{className:"gh-files-section",children:[e.jsxs("div",{className:"gh-files-header",children:[e.jsxs("span",{className:"gh-files-title",children:[H.length," ",H.length===1?"file":"files"]}),e.jsx("span",{className:"gh-files-commit-info",children:C.shortHash})]}),e.jsx(Mr,{files:H,loading:G,selectedFilePath:h,onSelectFile:ne})]})]})]})});async function Fr({path:t,cwd:n,limit:l}){const c=new URLSearchParams({path:t,cwd:n});Number.isFinite(l)&&c.set("limit",String(l));const r=await V(A(`/api/files/git-file-history?${c.toString()}`));if(!r.ok){const h=await r.json().catch(()=>({}));throw new Error(h.error||`Failed to load file git history: ${r.statusText}`)}const i=await r.json();return{commits:Array.isArray(i.commits)?i.commits:[]}}async function Pr({path:t,cwd:n,sha:l}){const c=new URLSearchParams({path:t,cwd:n,sha:l}),r=await V(A(`/api/files/git-file-commit-diff?${c.toString()}`));if(!r.ok){const h=await r.json().catch(()=>({}));throw new Error(h.error||`Failed to load commit diff: ${r.statusText}`)}const i=await r.json();return i.binary===!0?{binary:!0,filename:i.filename??"",changeType:i.changeType??"modified"}:{binary:!1,filename:i.filename??"",language:i.language??"plaintext",changeType:i.changeType??"modified",originalContent:typeof i.originalContent=="string"?i.originalContent:"",modifiedContent:typeof i.modifiedContent=="string"?i.modifiedContent:""}}const Ir=100;function Lr(t){if(!t)return"";const n=Date.parse(t);if(Number.isNaN(n))return t;const l=Date.now()-n,c=Math.round(l/1e3);if(c<60)return`${c}s ago`;const r=Math.round(c/60);if(r<60)return`${r}m ago`;const i=Math.round(r/60);if(i<24)return`${i}h ago`;const h=Math.round(i/24);if(h<30)return`${h}d ago`;const o=Math.round(h/30);return o<12?`${o}mo ago`:`${Math.round(o/12)}y ago`}function $r(t){if(!t)return"";const n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function zr({isOpen:t,onClose:n,filePath:l,cwd:c}){const{t:r}=ie(["terminal","common"]),[i,h]=s.useState([]),[o,d]=s.useState(!1),[g,b]=s.useState(null),[p,v]=s.useState(null),[N,F]=s.useState(null),[y,k]=s.useState(!1),[f,j]=s.useState(null);s.useEffect(()=>{if(!t)return;let G=!1;return h([]),v(null),F(null),j(null),b(null),d(!0),(async()=>{try{const K=await Fr({path:l,cwd:c,limit:Ir});if(G)return;h(K.commits),K.commits.length>0&&v(K.commits[0].sha)}catch(K){if(G)return;b(K instanceof Error?K.message:r("terminal:fileGitHistory.error"))}finally{G||d(!1)}})(),()=>{G=!0}},[t,l,c,r]),s.useEffect(()=>{if(!t||!p){F(null);return}let G=!1;return k(!0),j(null),F(null),(async()=>{try{const K=await Pr({path:l,cwd:c,sha:p});if(G)return;F(K)}catch(K){if(G)return;j(K instanceof Error?K.message:r("terminal:fileGitHistory.error"))}finally{G||k(!1)}})(),()=>{G=!0}},[t,p,l,c,r]);const C=s.useCallback(G=>{G.key==="Escape"&&(G.preventDefault(),n())},[n]),D=s.useMemo(()=>$r(l),[l]),H=()=>y?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:r("terminal:fileGitHistory.loading")})]}):f?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:20}),e.jsx("p",{children:f})]}):N?N.binary?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"file",size:20}),e.jsx("p",{children:r("terminal:fileGitHistory.binaryFile")})]}):e.jsx(as,{originalContent:N.originalContent,modifiedContent:N.modifiedContent,filename:N.filename||D,filePath:l,language:N.language}):e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:r("terminal:fileGitHistory.selectCommit")})});return t?e.jsx(na,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"git-file-history-modal",onClick:G=>G.stopPropagation(),onKeyDown:C,tabIndex:-1,children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("div",{className:"git-file-history-title",children:[e.jsx("h2",{children:r("terminal:fileGitHistory.title")}),e.jsx("span",{className:"git-file-history-filepath",title:l,children:D})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(M,{name:"close",size:16})})]}),e.jsxs("div",{className:"git-file-history-body",children:[e.jsx("aside",{className:"git-file-history-commit-list","aria-label":r("terminal:fileGitHistory.title"),children:o?e.jsxs("div",{className:"git-file-history-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:r("terminal:fileGitHistory.loading")})]}):g?e.jsxs("div",{className:"git-file-history-empty",children:[e.jsx(M,{name:"warn",size:18}),e.jsx("p",{children:g})]}):i.length===0?e.jsx("div",{className:"git-file-history-empty",children:e.jsx("p",{children:r("terminal:fileGitHistory.empty")})}):e.jsx("ul",{className:"git-file-history-commits",role:"listbox",children:i.map(G=>{const K=G.sha===p;return e.jsxs("li",{className:`git-file-history-commit ${K?"selected":""}`,role:"option","aria-selected":K,onClick:()=>v(G.sha),children:[e.jsxs("div",{className:"git-file-history-commit-row",children:[e.jsx("span",{className:"git-file-history-sha",children:G.shortSha}),e.jsx("span",{className:"git-file-history-date",title:G.date,children:Lr(G.date)})]}),e.jsx("div",{className:"git-file-history-subject",title:G.subject,children:G.subject}),e.jsx("div",{className:"git-file-history-author",title:G.email,children:G.author})]},G.sha)})})}),e.jsx("section",{className:"git-file-history-diff","aria-live":"polite",children:H()})]})]})})}):null}function Ur({isOpen:t,areaId:n,onClose:l,onChangeArea:c,folderPath:r}){const{t:i}=ie(["terminal","common"]),h=aa(),o=en(),d=ra(),g=ia(),b=!!r&&!n,p=!b&&n?h.get(n):null,v=b?[r]:(p==null?void 0:p.directories)||[],N=Array.from(h.values()),[F,y]=s.useState(0),[k,f]=s.useState(null),[j,C]=s.useState(!1),[D,H]=s.useState(""),G=s.useRef(null),K=v[F]||v[0]||null,w=K?K.replace(/\\/g,"/"):null,re=w?Lt(w):"";s.useEffect(()=>{y(0)},[r,b]),s.useEffect(()=>{!b&&r&&f(r)},[b,r]),s.useEffect(()=>{if(t)try{b&&r?localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"folder",path:r})):n&&localStorage.setItem("file-explorer-last-opened",JSON.stringify({type:"area",areaId:n}))}catch{}},[t,b,r,n]);const _=s.useMemo(()=>{const a=[];for(const u of N)for(const x of u.directories)a.push({path:x,areaId:u.id,areaName:u.name,areaColor:u.color});return a},[N]),R=s.useMemo(()=>{const a=D.trim().toLowerCase();return a?_.filter(u=>{const x=(u.path.split("/").pop()||u.path).toLowerCase();return u.path.toLowerCase().includes(a)||x.includes(a)}):_},[_,D]);s.useEffect(()=>{var a;j?(a=G.current)==null||a.focus():H("")},[j]);const{tree:P,loading:X,expandedPaths:Q,loadTree:ne,reloadDirectory:ue,renamePathInTree:U,togglePath:se,expandToPath:I,restoreExpandedPaths:B,setExpandedPaths:Z}=la(w),{gitStatus:L,loading:we,loadGitStatus:ee}=fa(w),{mergeBranch:m,mergeAbort:Y,mergeContinue:le}=ls(),me=La(),{showToast:T}=an(),{file:S,loading:te,error:ae,loadFile:pe,clearFile:oe,setFile:W}=wa(),{treePanelWidth:ye,handleResizeStart:Ge,isResizing:_e}=Ta(),{mobileTreeHeight:vt,handleResizeMouseDown:He,handleResizeTouchStart:Gt}=Fa(),{loadProjectState:dt,saveProjectState:We,loadRecentProjects:ut,pushRecentProject:wt}=Sa(),[ht,_t]=s.useState(()=>ut()),Je=s.useMemo(()=>{const a=new Map(_.map(x=>[x.path.replace(/\\/g,"/"),x])),u=[];for(const x of ht){const z=a.get(x);if(z&&u.push(z),u.length>=5)break}return u},[ht,_]),[Ce,ce]=s.useState(null),[Ne,ke]=s.useState("files"),[Ae,E]=s.useState(""),[$,O]=s.useState([]),[Ee,Se]=s.useState([]),[Ct,qe]=s.useState(!1),[De,Me]=s.useState(null),[pn,Fe]=s.useState(null),[ds,Nt]=s.useState(!1),[Pe,Bt]=s.useState(!1),[mt,fn]=s.useState(!1),[gn,us]=s.useState(new Set),[hs]=s.useState(!1),[Vt,xn]=s.useState(!1),[Kt,yn]=s.useState(250),pt=s.useRef(null),[Oe,kt]=s.useState(null),[bn,ms]=s.useState(!1),[Ye,ps]=s.useState(null),[Xe,fs]=s.useState(null),[Qe,jn]=s.useState(null),[Wt,Jt]=s.useState({open:!1,path:"",cwd:""}),[fe,Be]=s.useState({isOpen:!1,node:null,value:"",submitting:!1}),[be,Ze]=s.useState({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1}),[Te,gs]=s.useState(null),vn=oa(),Et=ca(vn),wn=da(),[Ie,Ue]=s.useState([]),[he,Re]=s.useState(null),[,qt]=s.useState(void 0),[xs,et]=s.useState(null),[ft,gt]=s.useState(null),[Cn,tt]=s.useState(null),[Nn,ys]=s.useState(!1),[St,Yt]=s.useState(null),[bs,Xt]=s.useState(!1),[Tt,Dt]=s.useState(null),js=s.useRef(null),Qt=s.useRef(null),vs=s.useRef(null),xt=s.useRef(null),ws=s.useRef(w);s.useEffect(()=>{ws.current=w},[w]);const Mt=s.useRef(!1);s.useEffect(()=>{Mt.current=!1},[n,r]),s.useEffect(()=>{if(!t||Mt.current)return;if(b){Mt.current=!0,y(0);return}if(v.length===0)return;if(Mt.current=!0,k){const x=v.indexOf(k);y(x>=0?x:0),f(null);return}const a=v.map(x=>x.replace(/\\/g,"/")),u=ut().find(x=>a.includes(x));y(u?a.indexOf(u):0)},[t,b,v,k,ut]),s.useEffect(()=>{if(!t||!w)return;const a=setTimeout(()=>_t(wt(w)),250);return()=>clearTimeout(a)},[t,w,wt]),s.useEffect(()=>{if(!t||Pe||!w)return;const a=w;(async()=>{const x=await dt(a);ws.current===a&&(x?(Ue(x.tabs),Re(x.activeTabPath),ke(x.viewMode),Z(x.expandedPaths),xt.current=x.expandedPaths,Nt(!0),x.activeTabPath?(ce(x.activeTabPath),pe(x.activeTabPath)):(ce(null),oe())):(Ue([]),Re(null),ce(null),oe(),xt.current=null),Bt(!0))})()},[t,Pe,w,dt,Z,pe,oe]),s.useEffect(()=>{if(xt.current&&!X&&P.length>0){const a=xt.current;xt.current=null,B(a)}},[X,P,Pe,B]);const Cs=s.useRef(null);s.useEffect(()=>{Cs.current=Pe&&w?{key:w,state:{tabs:Ie,activeTabPath:he,viewMode:Ne,expandedPaths:Q}}:null},[Pe,w,Ie,he,Ne,Q]);const yt=s.useCallback(()=>{const a=Cs.current;a&&We(a.key,a.state)},[We]);s.useEffect(()=>{if(!t||!Pe||!w)return;const a=w,u=setTimeout(()=>{We(a,{tabs:Ie,activeTabPath:he,viewMode:Ne,expandedPaths:Q})},500);return()=>clearTimeout(u)},[t,Pe,w,Ie,he,Ne,Q,We]),s.useEffect(()=>()=>yt(),[yt]);const Ns=s.useRef(t);s.useEffect(()=>{Ns.current&&!t&&yt(),Ns.current=t},[t,yt]),s.useEffect(()=>{Bt(!1)},[w]),s.useEffect(()=>{if(!fe.isOpen)return;const a=window.setTimeout(()=>{var u,x;(u=Qt.current)==null||u.focus(),(x=Qt.current)==null||x.select()},0);return()=>window.clearTimeout(a)},[fe.isOpen]),s.useEffect(()=>{if(!be.isOpen)return;const a=window.setTimeout(()=>{var u;(u=vs.current)==null||u.focus()},0);return()=>window.clearTimeout(a)},[be.isOpen]);const Le=s.useMemo(()=>{const a=Ae.trim(),u=a.match(/^(.+):(\d+)$/);return u?{query:u[1],lineNumber:parseInt(u[2],10)}:{query:a,lineNumber:void 0}},[Ae]);s.useEffect(()=>{if(!Le.query||!w){O([]),Se([]),qe(!1);return}qe(!0);const a=new AbortController,{signal:u}=a,x=setTimeout(async()=>{try{const z=Le.query,q=(o.fileSearchExcludeDirs??[...ua]).join(","),J=`&exclude=${encodeURIComponent(q)}`,je=V(A(`/api/files/search?path=${encodeURIComponent(w)}&q=${encodeURIComponent(z)}&limit=200${J}`),{signal:u}).then(ve=>ve.json()).catch(()=>({results:[]})),de=z.length>=2&&!Le.lineNumber?V(A(`/api/files/search-content?path=${encodeURIComponent(w)}&q=${encodeURIComponent(z)}&limit=200${J}`),{signal:u}).then(ve=>ve.json()).catch(()=>({results:[]})):Promise.resolve({results:[]}),[ge,xe]=await Promise.all([je,de]);if(u.aborted)return;O(ge.results||[]),Se(xe.results||[])}catch(z){if(u.aborted)return;console.error("[FileExplorer] Search failed:",z),O([]),Se([])}u.aborted||qe(!1)},300);return()=>{clearTimeout(x),a.abort()}},[Le.query,Le.lineNumber,w,o.fileSearchExcludeDirs]),s.useEffect(()=>{t&&w&&(oe(),ce(null),Me(null),Fe(null),Nt(!1),ne(),ee())},[t,w,ne,ee,oe]),s.useEffect(()=>{if(d&&t){const a=d;if(g){const u=Lt(a),x=a.substring(a.lastIndexOf(".")).toLowerCase();Rt(a,u,x),Ft(a)}else pe(a),ce(a);Ve.clearFileViewerPath()}},[d,g,t,pe]),s.useEffect(()=>{Pe&&!ds&&L&&Nt(!0)},[L,ds,Pe,Ne]),s.useEffect(()=>{if(n&&(oe(),ce(null),E(""),Se([]),O([]),Me(null),Fe(null),Nt(!1),Bt(!1),k)){const a=h.get(n);a!=null&&a.directories.includes(k)||f(null)}},[n,k,h,oe]),s.useEffect(()=>{const a=x=>{var q;if(!t)return;if(x.altKey&&x.key==="e"){x.preventDefault(),x.stopPropagation(),l();return}if(x.key==="Escape"){if(fe.isOpen){x.preventDefault(),x.stopPropagation(),fe.submitting||Be({isOpen:!1,node:null,value:"",submitting:!1});return}if(hs)return;if(j){x.preventDefault(),x.stopPropagation(),C(!1);return}x.preventDefault(),x.stopPropagation(),l();return}(x.metaKey||x.ctrlKey)&&x.key==="p"&&(x.preventDefault(),(q=js.current)==null||q.focus());const z=Ve.getShortcuts().find(J=>J.id==="file-explorer-close-tab");if(pa(x,z)){if(x.repeat)return;x.preventDefault(),x.stopPropagation(),he&&Ts(he)}},u=x=>{const z=x.target;j&&!z.closest(".file-explorer-folder-selector")&&!z.closest(".file-explorer-folder-dropdown")&&C(!1)};return document.addEventListener("keydown",a,!0),document.addEventListener("click",u),()=>{document.removeEventListener("keydown",a,!0),document.removeEventListener("click",u)}},[t,l,j,he,hs,fe]);const ks=s.useMemo(()=>{const a=new Map;if(L!=null&&L.files)for(const u of L.files)a.set(u.path,u.status);return a},[L==null?void 0:L.files]),Zt=s.useMemo(()=>{const a=new Map;if(!(L!=null&&L.files))return a;const u={conflict:0,modified:1,added:2,deleted:3,untracked:4,renamed:5};for(const x of L.files){let z=x.path.replace(/\\/g,"/");for(;;){const q=z.lastIndexOf("/");if(q<=0)break;z=z.substring(0,q);const J=a.get(z);J?u[x.status]<u[J]&&a.set(z,x.status):a.set(z,x.status)}}return a},[L==null?void 0:L.files]),Es=s.useMemo(()=>{const a=u=>({...u,gitStatus:u.isDirectory?Zt.get(u.path):ks.get(u.path),hasGitChanges:u.isDirectory&&Zt.has(u.path)||void 0,children:u.children?u.children.map(a):void 0});return P.map(a)},[P,ks,Zt]),Rt=(a,u,x,z)=>{if(!Ie.find(J=>J.path===a)){const J={path:a,filename:u,extension:x};Ue(je=>[...je,J])}Re(a),ce(a),qt(z),pe(a)},Ss=async a=>{if(a.isDirectory){ke("files"),E(""),await I(a.path),ce(a.path),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let u=a.path,x=document.querySelector(`[data-path="${u}"]`);for(;!x&&u.includes("/");)u=u.substring(0,u.lastIndexOf("/")),x=document.querySelector(`[data-path="${u}"]`);x instanceof HTMLElement&&x.scrollIntoView({behavior:"smooth",block:"center"})})});return}Fe(null),Me(null),Rt(a.path,a.name,a.extension,Le.lineNumber)},kn=(a,u)=>{Fe(null),Me(null);const x=Lt(a),z=a.substring(a.lastIndexOf(".")).toLowerCase();Rt(a,x,z,u)},En=async(a,u)=>{Fe(u),Me(null);const x=Lt(a),z=a.substring(a.lastIndexOf(".")).toLowerCase();if(Rt(a,x,z),u==="modified"){const{content:q}=await ga(a);q!==null&&Me(q)}},Sn=a=>{Re(a),ce(a),Fe(null),Me(null),qt(void 0);const u=Ie.find(x=>x.path===a);u!=null&&u.data||pe(a)},Ts=a=>{Ue(u=>{var q;const x=u.filter(J=>J.path!==a),z=u.findIndex(J=>J.path===a);if(z!==-1&&((q=u[z])==null?void 0:q.path)===a&&(he===a||u.find(J=>J.path===he)),x.length>0){if(!x.some(je=>je.path===he)){const je=u.findIndex(xe=>xe.path===a),de=Math.max(0,Math.min(je,x.length-1)),ge=x[de];ge&&(Re(ge.path),ce(ge.path),pe(ge.path))}}else Re(null),ce(null),oe();return x})},Tn=s.useCallback(()=>{Ue([]),Re(null),ce(null),oe()},[oe]),es=a=>{if(C(!1),a.path.replace(/\\/g,"/")!==w)if(yt(),a.areaId!==n)f(a.path),c&&c(a.areaId);else{const u=v.indexOf(a.path);y(u>=0?u:0)}},$e=s.useCallback(a=>{const u=a.lastIndexOf("/");return u<=0?"/":a.slice(0,u)},[]),st=s.useCallback((a,u,x)=>a===u?x:a.startsWith(`${u}/`)?`${x}${a.slice(u.length)}`:a,[]),Dn=s.useCallback((a,u)=>{ce(u.path),ps({isOpen:!0,position:{x:a.clientX,y:a.clientY},node:u})},[]),Mn=s.useCallback(a=>{a.defaultPrevented||w&&(a.preventDefault(),fs({isOpen:!0,position:{x:a.clientX,y:a.clientY},parentDir:w}))},[w]),Ds=s.useCallback(a=>{Be({isOpen:!0,node:a,value:a.name,submitting:!1})},[]),nt=s.useCallback(()=>{Be({isOpen:!1,node:null,value:"",submitting:!1})},[]),at=s.useCallback((a,u)=>{a&&Ze({isOpen:!0,parentDir:a,isDirectory:u,value:"",submitting:!1})},[]),rt=s.useCallback(()=>{Ze({isOpen:!1,parentDir:"",isDirectory:!1,value:"",submitting:!1})},[]),Ms=s.useCallback(a=>{gs({node:a})},[]),Rn=s.useCallback(async()=>{const a=Te==null?void 0:Te.node;if(a)try{const u=await V(A("/api/files/delete"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,recursive:a.isDirectory})}),x=await u.json().catch(()=>({}));if(!u.ok){T("error","Delete Failed",x.error||"Unable to delete item");return}Ue(q=>q.filter(J=>J.path!==a.path&&!J.path.startsWith(`${a.path}/`))),(he===a.path||he!=null&&he.startsWith(`${a.path}/`))&&(Re(null),oe()),(Ce===a.path||Ce!=null&&Ce.startsWith(`${a.path}/`))&&ce(null);const z=$e(a.path);await ue(z),await ee(),T("success",a.isDirectory?"Folder Deleted":"File Deleted",a.name)}catch(u){console.error("[FileExplorer] Delete failed:",u),T("error","Delete Failed","Unable to delete item")}},[Te,he,Ce,$e,ue,ee,T,oe]),Rs=s.useCallback(async()=>{const{parentDir:a,isDirectory:u,value:x}=be,z=x.trim();if(!a||!z){rt();return}if(z.includes("/")||z.includes("\\")){T("error","Invalid Name","Name must not contain path separators");return}Ze(q=>({...q,submitting:!0}));try{const q=await V(A("/api/files/create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({parentDir:a,name:z,isDirectory:u})}),J=await q.json();if(!q.ok){T("error","Create Failed",J.error||"Unable to create item"),Ze(ge=>({...ge,submitting:!1}));return}const je=J.path,de=new Set(Q);de.add(a),await ue(a),Z(de),await ee(),ce(je),T("success",u?"Folder Created":"File Created",z),rt()}catch(q){console.error("[FileExplorer] Create failed:",q),T("error","Create Failed","Unable to create item"),Ze(J=>({...J,submitting:!1}))}},[be,Q,ue,Z,ee,T,rt]),Fs=s.useCallback(async()=>{const a=fe.node;if(!a)return;const u=fe.value.trim();if(!u||u===a.name){nt();return}Be(x=>({...x,submitting:!0}));try{const x=await V(A("/api/files/rename"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a.path,newName:u})}),z=await x.json();if(!x.ok){T("error","Rename Failed",z.error||"Unable to rename item"),Be(xe=>({...xe,submitting:!1}));return}const q=z.newPath,J=a.path,je=new Set(Array.from(Q).map(xe=>st(xe,J,q))),de=$e(J),ge=$e(q);if(Ue(xe=>xe.map(ve=>{if(!ve.path.startsWith(J))return ve;const it=st(ve.path,J,q),Pt=it.split("/").pop()||it,Os=Pt.includes(".")?`.${Pt.split(".").pop()}`:"";return{...ve,path:it,filename:Pt,extension:Os.toLowerCase(),data:ve.data?{...ve.data,path:it,filename:Pt,extension:Os.toLowerCase()}:ve.data}})),he&&Re(st(he,J,q)),Ce&&ce(st(Ce,J,q)),S!=null&&S.path){const xe=st(S.path,J,q);if(xe!==S.path){const ve=xe.split("/").pop()||xe,it=ve.includes(".")?`.${ve.split(".").pop()}`:"";W({...S,path:xe,filename:ve,extension:it.toLowerCase()})}}U(J,q),Z(je),await ue(de),ge!==de&&await ue(ge),await ee(),T("success","Renamed",`${a.name} renamed`),nt()}catch(x){console.error("[FileExplorer] Rename failed:",x),T("error","Rename Failed","Unable to rename item"),Be(z=>({...z,submitting:!1}))}},[fe,nt,he,Ce,S,Q,st,$e,U,Z,ue,ee,T,W]),Ps=s.useCallback(a=>{jn({sourcePath:a.path,isDirectory:a.isDirectory,name:a.name}),T("info","Copied",`${a.name} ready to paste`)},[T]),Is=s.useCallback(async a=>{if(!Qe)return;const u=a.isDirectory?a.path:$e(a.path),x=new Set(Q);x.add(u);try{const z=await V(A("/api/files/paste"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourcePath:Qe.sourcePath,targetDir:u})}),q=await z.json();if(!z.ok){T("error","Paste Failed",q.error||"Unable to paste item");return}await ue(u),Z(x),await ee(),q.destinationPath&&ce(q.destinationPath),T("success","Pasted",`${Qe.name} pasted`)}catch(z){console.error("[FileExplorer] Paste failed:",z),T("error","Paste Failed","Unable to paste item")}},[Qe,$e,Q,ue,Z,ee,T]),Ls=s.useCallback(async a=>{try{await navigator.clipboard.writeText(a.path),T("success","Copied","Full path copied")}catch(u){console.error("[FileExplorer] Copy path failed:",u),T("error","Copy Failed","Could not copy path")}},[T]),$s=s.useCallback(a=>{a.isDirectory||!w||Jt({open:!0,path:a.path,cwd:w})},[w]),Fn=s.useCallback(a=>{!w||!a||Jt({open:!0,path:a,cwd:w})},[w]),zs=s.useCallback(async a=>{try{await Ve.runTests(a.path)}catch(u){T("error","Run Tests Failed",u instanceof Error?u.message:"Unable to start tests")}},[T]),Pn=s.useMemo(()=>{if(!Ye)return[];const a=Ye.node,u=a.isDirectory?a.path:$e(a.path),x=[{id:"create-file",label:a.isDirectory?"New File...":"New File Here...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>at(u,!1)},{id:"create-folder",label:a.isDirectory?"New Folder...":"New Folder Here...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>at(u,!0)},{id:"divider-create",label:"",divider:!0,onClick:()=>{}},{id:"rename",label:a.isDirectory?"Rename Folder":"Rename File",icon:e.jsx(M,{name:"edit",size:14}),onClick:()=>Ds(a)},{id:"copy",label:a.isDirectory?"Copy Folder":"Copy File",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>Ps(a)},{id:"paste",label:a.isDirectory?"Paste Into Folder":"Paste Here",icon:e.jsx(M,{name:"clipboard",size:14}),disabled:!Qe,onClick:()=>{Is(a)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"copy-full-path",label:"Copy Full Path",icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{Ls(a)}}];return a.runnerType&&x.push({id:"divider-run-tests",label:"",divider:!0,onClick:()=>{}},{id:"run-tests",label:a.isDirectory?"Run Tests":"Run This Test",icon:e.jsx(M,{name:"flask",size:14}),onClick:()=>{zs(a)}}),a.isDirectory||x.push({id:"divider-git-history",label:"",divider:!0,onClick:()=>{}},{id:"git-history",label:i("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),onClick:()=>$s(a)}),x.push({id:"divider-delete",label:"",divider:!0,onClick:()=>{}},{id:"delete",label:a.isDirectory?"Delete Folder":"Delete File",icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>Ms(a)}),x},[Ye,Qe,$e,at,Ds,Ps,Is,Ls,$s,Ms,zs,i]),In=s.useMemo(()=>{if(!Xe)return[];const a=Xe.parentDir;return[{id:"create-file-root",label:"New File...",icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>at(a,!1)},{id:"create-folder-root",label:"New Folder...",icon:e.jsx(M,{name:"folder",size:14}),onClick:()=>at(a,!0)}]},[Xe,at]),Ft=s.useCallback(async a=>{ke("files"),E(""),await I(a),ce(a),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let u=a,x=document.querySelector(`[data-path="${u}"]`);for(;!x&&u.includes("/");)u=u.substring(0,u.lastIndexOf("/")),x=document.querySelector(`[data-path="${u}"]`);x instanceof HTMLElement&&x.scrollIntoView({behavior:"smooth",block:"center"})})})},[I]),Ln=s.useCallback(async a=>{if(!(!w||a.length===0)){us(u=>{const x=new Set(u);for(const z of a)x.add(z);return x});try{const u=await V(A("/api/files/git-add"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paths:a,directory:w})});if(u.ok)await ee();else{const x=await u.json();console.error("[FileExplorer] Git add failed:",x.error)}}catch(u){console.error("[FileExplorer] Git add failed:",u)}finally{us(u=>{const x=new Set(u);for(const z of a)x.delete(z);return x})}}},[w,ee]),$n=s.useCallback(async a=>{if(!w)return;et(a);const u=await m(w,a);if(await ee(),u.success)et(null),T("success","Merge Complete",`Merged '${a}' successfully`),ne();else if(u.conflicts&&u.conflicts.length>0){const x=u.conflicts.length;T("warning","Merge Conflicts",`${x} conflict${x>1?"s":""} found — resolve to continue`),ke("git")}else et(null),T("error","Merge Failed",u.error||"Merge failed")},[w,m,ee,ne,T]),zn=s.useCallback(async a=>{et("remote"),await ee();const u=a.length;T("warning","Pull Conflicts",`${u} conflict${u>1?"s":""} found — resolve to continue`),ke("git")},[ee,T]),Hn=s.useCallback(async a=>{if(w){gt(a),ys(!0),tt(null);try{const u=await V(A(`/api/files/git-conflict-file?path=${encodeURIComponent(w)}&file=${encodeURIComponent(a)}`)),x=await u.json();u.ok?tt(x):console.error("[FileExplorer] Failed to load conflict file:",x.error)}catch(u){console.error("[FileExplorer] Failed to load conflict file:",u)}finally{ys(!1)}}},[w]),An=s.useCallback(async a=>{if(!(!w||!ft))try{const u=await V(A("/api/files/git-resolve-conflict"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:w,file:ft,content:a})}),x=await u.json();u.ok&&x.success?(gt(null),tt(null),await ee()):console.error("[FileExplorer] Failed to resolve conflict:",x.error)}catch(u){console.error("[FileExplorer] Failed to resolve conflict:",u)}},[w,ft,ee]),On=s.useCallback(async()=>{if(!w)return;const a=await le(w);a.success?(et(null),gt(null),tt(null),T("success","Merge Complete","Merge completed successfully"),await ee(),ne()):T("error","Merge Failed",a.error||"Merge continue failed")},[w,le,ee,ne,T]),Un=s.useCallback(async()=>{if(!w)return;const a=await Y(w);a.success?(et(null),gt(null),tt(null),T("info","Merge Aborted","Merge has been aborted"),await ee(),ne()):T("error","Abort Failed",a.error||"Failed to abort merge")},[w,Y,ee,ne,T]),Gn=s.useCallback(async a=>{if(w){Dt(a),Xt(!0),Yt(null),ke("compare");try{const u=await V(A(`/api/files/git-branch-compare?directory=${encodeURIComponent(w)}&branch=${encodeURIComponent(a)}`)),x=await u.json();u.ok?Yt(x):(T("error","Compare Failed",x.error||"Failed to compare branches"),ke("files"),Dt(null))}catch(u){console.error("[FileExplorer] Branch compare failed:",u),T("error","Compare Failed","Network error during comparison"),ke("files"),Dt(null)}finally{Xt(!1)}}},[w,T]),_n=s.useCallback(async(a,u)=>{if(!w||!Tt)return;const x=a.split("/").pop()||a,z=a.substring(a.lastIndexOf(".")).toLowerCase();Ie.find(de=>de.path===a)||Ue(de=>[...de,{path:a,filename:x,extension:z}]),Re(a),ce(a),qt(void 0);const J=async de=>{try{const ge=await V(A(`/api/files/git-show?path=${encodeURIComponent(a)}&ref=${encodeURIComponent(de)}`)),xe=await ge.json();return ge.ok?xe.content??"":""}catch{return""}},je=de=>({path:a,filename:x,extension:z,content:de,fileType:"text",size:de.length,modified:""});if(u==="modified"||u==="renamed"){const[de,ge]=await Promise.all([J(Tt),J("HEAD")]);Me(de),W(je(ge)),Fe("modified")}else if(u==="deleted"){const de=await J(Tt);Me(de),W(je("")),Fe("modified")}else if(u==="added"){const de=await J("HEAD");Me(""),W(je(de)),Fe("modified")}},[w,Tt,Ie]),Hs=s.useCallback(()=>{ke("files"),Yt(null),Dt(null),Xt(!1)},[]),Bn=s.useCallback(async(a,u)=>{if(w){ms(!0);try{const x=new URLSearchParams({path:w,hash:u,file:a}),z=await V(A(`/api/files/git-commit-file-diff?${x}`)),q=await z.json();z.ok?kt(q):kt(null)}catch(x){console.error("[FileExplorer] commit diff fetch error:",x),kt(null)}finally{ms(!1)}}},[w]),Vn=s.useCallback(()=>{kt(null)},[]),Kn=s.useCallback(a=>{a.preventDefault(),pt.current={startY:a.clientY,startHeight:Kt};const u=z=>{if(!pt.current)return;const q=pt.current.startY-z.clientY,J=Math.max(120,Math.min(600,pt.current.startHeight+q));yn(J)},x=()=>{pt.current=null,document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",x)};document.addEventListener("mousemove",u),document.addEventListener("mouseup",x)},[Kt]);if(!t||!p&&!b)return null;const As=(L==null?void 0:L.files.length)||0;return e.jsxs("div",{className:"file-explorer-panel ide-style",children:[e.jsxs("div",{className:"file-explorer-panel-header",children:[e.jsxs("div",{className:"file-explorer-panel-header-row",children:[e.jsxs("div",{className:"file-explorer-panel-title",children:[w&&e.jsxs("div",{className:"file-explorer-folder-selector",onClick:()=>_.length>0&&C(!j),style:{cursor:_.length>0?"pointer":"default"},title:w,children:[e.jsx("span",{className:"file-explorer-panel-dot",style:{background:(p==null?void 0:p.color)||"#ffd700"}}),e.jsx("span",{className:"file-explorer-folder-name",children:re}),e.jsx("span",{className:"file-explorer-folder-path-hint",children:w}),_.length>1&&e.jsx("span",{className:"file-explorer-folder-dropdown-icon",children:e.jsx(M,{name:"caret-down",size:10})})]}),(L==null?void 0:L.isGitRepo)&&w&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"file-explorer-path-separator",children:"/"}),e.jsx(jr,{currentFolder:w,gitStatus:L,onBranchChanged:()=>{ee(),ne()},onMerge:$n,onCompare:Gn,onPullConflicts:zn})]}),S&&e.jsxs("span",{className:"file-explorer-current-file",children:["/ ",S.filename]}),j&&_.length>0&&e.jsxs("div",{className:"file-explorer-folder-dropdown",onWheel:a=>{a.preventDefault(),a.currentTarget.scrollTop+=a.deltaY*.35},children:[e.jsx("div",{className:"file-explorer-folder-dropdown-search",onClick:a=>a.stopPropagation(),children:e.jsx("input",{ref:G,type:"text",className:"file-explorer-folder-dropdown-search-input",placeholder:"Filter folders…",value:D,onChange:a=>H(a.target.value),onKeyDown:a=>{a.key==="Enter"&&R.length>0&&(a.preventDefault(),es(R[0]))},spellCheck:!1,autoComplete:"off","aria-label":"Filter folders"})}),R.length===0?e.jsx("div",{className:"file-explorer-folder-dropdown-empty",children:"No matching folders"}):R.map(a=>e.jsxs("div",{className:`file-explorer-folder-option ${a.path===w?"active":""}`,onClick:u=>{u.stopPropagation(),es(a)},children:[e.jsxs("span",{className:"file-explorer-folder-option-name",children:[e.jsx("span",{className:"file-explorer-folder-option-dot",style:{background:a.areaColor}}),a.path.split("/").pop()||a.path]}),(a.path.split("/").pop()||a.path)!==a.path&&e.jsx("span",{className:"file-explorer-folder-option-path",children:a.path}),e.jsx("span",{className:"file-explorer-folder-option-area",children:a.areaName})]},`${a.areaId}-${a.path}`))]})]}),(L==null?void 0:L.isGitRepo)&&e.jsx("button",{className:`file-explorer-history-toggle ${Vt?"active":""}`,onClick:()=>xn(!Vt),title:i("terminal:fileExplorer.gitHistory.title"),children:e.jsx(M,{name:"status-waiting-input",size:14})}),Et&&!wn&&e.jsxs("button",{className:`file-explorer-test-results-toggle status-${Et.status}`,onClick:()=>Ve.openTestResults(),title:Et.status==="running"?"Tests running — open results":"Open last test results",children:[e.jsx(M,{name:"flask",size:14}),Et.status==="running"&&e.jsx("span",{className:"fe-test-run-dot"})]}),e.jsx("button",{className:"file-explorer-panel-close",onClick:l,children:"×"})]}),Je.length>1&&e.jsx("div",{className:"file-explorer-recent-projects",role:"group","aria-label":"Recent projects",children:Je.map(a=>{const u=a.path.split("/").pop()||a.path,x=a.path.replace(/\\/g,"/")===w;return e.jsxs("button",{type:"button",className:`file-explorer-recent-chip ${x?"active":""}`,onClick:()=>es(a),title:a.path,children:[e.jsx("span",{className:"file-explorer-recent-chip-dot",style:{background:a.areaColor}}),e.jsx("span",{className:"file-explorer-recent-chip-name",children:u})]},`${a.areaId}-${a.path}`)})})]}),e.jsxs("div",{className:"file-explorer-main",style:vt>0?{"--fe-mobile-tree-height":`${vt}px`}:void 0,children:[e.jsxs("div",{className:`file-explorer-tree-panel ${mt?"collapsed":""}`,style:{width:ye},children:[e.jsxs("div",{className:"file-explorer-tabs",children:[e.jsx("button",{className:"file-explorer-tree-toggle",onClick:()=>fn(!mt),title:i(mt?"terminal:fileExplorer.expandTree":"terminal:fileExplorer.collapseTree"),children:e.jsx(M,{name:mt?"caret-down":"caret-up",size:12})}),e.jsxs("button",{className:`file-explorer-tab ${Ne==="files"?"active":""}`,onClick:()=>ke("files"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"folder",size:14})}),i("terminal:spotlight.files")]}),e.jsxs("button",{className:`file-explorer-tab ${Ne==="git"?"active":""}`,onClick:()=>ke("git"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"git-branch",size:14})}),i("terminal:fileExplorer.gitChanges"),As>0&&e.jsx("span",{className:"tab-badge",children:As})]}),(St||bs)&&e.jsxs("button",{className:`file-explorer-tab ${Ne==="compare"?"active":""}`,onClick:()=>ke("compare"),children:[e.jsx("span",{className:"tab-icon",children:e.jsx(M,{name:"arrows-horizontal",size:14})}),i("terminal:fileExplorer.diffView"),St&&e.jsx("span",{className:"tab-badge",children:St.files.length}),e.jsx("span",{className:"tab-close-btn",onClick:a=>{a.stopPropagation(),Hs()},children:"×"})]})]}),Ne==="files"&&e.jsxs("div",{className:"file-explorer-toolbar",children:[e.jsxs("div",{className:"file-explorer-search",children:[e.jsx("span",{className:"file-explorer-search-icon",children:e.jsx(M,{name:"search",size:14})}),e.jsx("input",{ref:js,type:"text",className:"file-explorer-search-input",placeholder:i("terminal:fileExplorer.searchPlaceholder"),value:Ae,onChange:a=>E(a.target.value)}),Ae&&e.jsx("button",{className:"file-explorer-search-clear",onClick:()=>E(""),children:"×"})]}),e.jsxs("div",{className:"file-explorer-toolbar-buttons",children:[e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>Z(new Set),title:i("terminal:fileExplorer.collapseAll"),children:"⊟"}),he&&e.jsx("button",{className:"file-explorer-toolbar-btn",onClick:()=>Ft(he),title:i("terminal:fileExplorer.revealInTree"),children:e.jsx(M,{name:"target",size:14})})]})]}),e.jsx("div",{className:"file-explorer-tree-content",onContextMenu:Ne==="files"?Mn:void 0,children:Ne==="compare"?e.jsx(mn,{compareResult:St,loading:bs,onFileSelect:_n,selectedPath:Ce,onClose:Hs}):Ne==="files"?X?e.jsx("div",{className:"tree-loading",children:i("common:status.loading")}):Le.query?Ct?e.jsx("div",{className:"tree-loading",children:i("terminal:fileExplorer.searching")}):e.jsx(dn,{filenameResults:$,contentResults:Ee,onSelectFile:Ss,onSelectContent:kn,selectedPath:Ce,query:Le.query,lineNumber:Le.lineNumber}):e.jsx("div",{className:"file-tree",children:Es.length===0?e.jsx("div",{className:"tree-empty",children:i("terminal:fileExplorer.noDirectoriesLinked")}):Es.map(a=>e.jsx(ha,{node:a,depth:0,selectedPath:Ce,expandedPaths:Q,onSelect:Ss,onToggle:se,onContextMenu:Dn,searchQuery:""},a.path))}):e.jsx(un,{gitStatus:L,loading:we,onFileSelect:En,selectedPath:Ce,onRefresh:ee,onStageFiles:Ln,stagingPaths:gn,currentFolder:w,onCommitComplete:()=>{ee(),ne()},mergeInProgress:L==null?void 0:L.mergeInProgress,mergingBranch:xs,onMergeContinue:On,onMergeAbort:Un,onConflictOpen:Hn,onRevealInTree:Ft})})]}),e.jsx("div",{className:`file-explorer-resize-handle ${_e?"active":""}`,onMouseDown:Ge}),!mt&&e.jsx("div",{className:"fe-mobile-resize-handle",onMouseDown:He,onTouchStart:Gt}),e.jsx("div",{className:"file-explorer-viewer-panel",children:ft?e.jsx(Cr,{file:ft,versions:Cn,loading:Nn,onResolve:An,onClose:()=>{gt(null),tt(null)},currentBranch:(L==null?void 0:L.branch)||"HEAD",mergingBranch:xs||"incoming"}):Oe?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"commit-diff-header",children:[e.jsx("span",{className:"commit-diff-file",children:Oe.filePath}),e.jsx("span",{className:"commit-diff-hash",children:Oe.hash.slice(0,8)}),e.jsx("button",{className:"commit-diff-close",onClick:Vn,children:"×"})]}),e.jsx(as,{originalContent:Oe.beforeContent,modifiedContent:Oe.afterContent,filename:Oe.filename,filePath:Oe.filePath,language:Gs[Oe.extension]||"plaintext"})]}):bn?e.jsx("div",{className:"commit-diff-loading",children:i("common:status.loading")}):e.jsxs(e.Fragment,{children:[e.jsx(hn,{tabs:Ie,activeTabPath:he,onSelectTab:Sn,onCloseTab:Ts,onCloseAllTabs:Tn,onShowGitHistory:Fn}),pn==="modified"&&De!==null&&S?e.jsx(as,{originalContent:De,modifiedContent:S.content,filename:S.filename,filePath:S.path,language:Gs[S.extension]||"plaintext"}):e.jsx(on,{file:S,loading:te,error:ae,onRevealInTree:Ft,onFileEdited:pe})]})})]}),Vt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"git-history-resize-handle",onMouseDown:Kn}),e.jsx("div",{className:"git-history-bottom-panel",style:{height:Kt},children:e.jsx(Rr,{history:me,currentFolder:w,onFileSelect:Bn})})]}),fe.isOpen&&fe.node&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:nt,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["Rename ",fe.node.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:fe.node.path,children:fe.node.path}),e.jsx("input",{ref:Qt,type:"text",className:"file-explorer-rename-input",value:fe.value,onChange:a=>Be(u=>({...u,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Fs()):a.key==="Escape"&&(a.preventDefault(),nt())},disabled:fe.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:nt,disabled:fe.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Fs()},disabled:fe.submitting||!fe.value.trim(),children:fe.submitting?"Renaming...":"Rename"})]})]})}),Ye&&e.jsx(lt,{isOpen:Ye.isOpen,position:Ye.position,worldPosition:{x:0,z:0},actions:Pn,onClose:()=>ps(null)}),Xe&&e.jsx(lt,{isOpen:Xe.isOpen,position:Xe.position,worldPosition:{x:0,z:0},actions:In,onClose:()=>fs(null)}),be.isOpen&&e.jsx("div",{className:"file-explorer-rename-overlay",onClick:rt,children:e.jsxs("div",{className:"file-explorer-rename-dialog",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"file-explorer-rename-title",children:["New ",be.isDirectory?"Folder":"File"]}),e.jsx("div",{className:"file-explorer-rename-path",title:be.parentDir,children:be.parentDir}),e.jsx("input",{ref:vs,type:"text",className:"file-explorer-rename-input",placeholder:be.isDirectory?"folder name":"file name",value:be.value,onChange:a=>Ze(u=>({...u,value:a.target.value})),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Rs()):a.key==="Escape"&&(a.preventDefault(),rt())},disabled:be.submitting}),e.jsxs("div",{className:"file-explorer-rename-actions",children:[e.jsx("button",{className:"file-explorer-rename-btn",onClick:rt,disabled:be.submitting,children:"Cancel"}),e.jsx("button",{className:"file-explorer-rename-btn primary",onClick:()=>{Rs()},disabled:be.submitting||!be.value.trim(),children:be.submitting?"Creating...":"Create"})]})]})}),e.jsx(zr,{isOpen:Wt.open,filePath:Wt.path,cwd:Wt.cwd,onClose:()=>Jt(a=>({...a,open:!1}))}),e.jsx(ma,{isOpen:!!Te,title:Te!=null&&Te.node.isDirectory?"Delete Folder":"Delete File",message:Te?e.jsxs(e.Fragment,{children:["Permanently delete ",e.jsx("strong",{children:Te.node.name}),"?"]}):"",note:Te!=null&&Te.node.isDirectory?"The folder and everything inside it will be removed from disk.":"The file will be removed from disk.",confirmLabel:"Delete",cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Rn()},onClose:()=>gs(null)})]})}export{Ur as FileExplorerPanel};
|